Commit 3d6b7db5 authored by Hossain Mahmud's avatar Hossain Mahmud
Browse files

nestedGetProp, writing pipeline and processor get method while saving the script. loading from file

Conflicts:
	core/bindings/campvis.i
parent d4790c70
......@@ -218,7 +218,7 @@ namespace campvis {
PropertyCollectionLua *_pcLua = new PropertyCollectionLua();
_pcLua->updatePropCollection(_canvas, _dataContainer);
std::cout << _pcLua->getLuaScript();
std::cout << _pcLua->getLuaScript("");
_infoWidgetLayout->addWidget(_pipelinePropertiesScrollArea, 6, 0, 1, 2);
......
......@@ -295,25 +295,26 @@ namespace campvis {
QString filename = QFileDialog::getOpenFileName(QWidget::parentWidget(), dialogCaption, directory, fileFilter);
if (filename != nullptr && _application->getLuaVmState() != nullptr) {
std::ifstream file;
file.open(filename.toStdString());
if (!file.fail()) {
_application->getLuaVmState()->execString("local proc = pipelines[\"" +_selectedPipeline->getName()+"\"]");
std::string script;
while (!file.eof()) {
script = "";
std::getline(file, script);
if (script == "")
continue;
printf("%s\n", script.c_str());
//if (_application->getLuaVmState() != nullptr) {
_application->getLuaVmState()->execString(script.c_str());
//}
}
printf("Load lua script");
}
_application->getLuaVmState()->execFile(filename.toStdString());
//std::ifstream file;
//file.open(filename.toStdString());
//if (!file.fail()) {
// _application->getLuaVmState()->execString("proc = pipelines[\"" +_selectedPipeline->getName()+"\"]");
//
// std::string script;
// while (!file.eof()) {
// script = "";
// std::getline(file, script);
// if (script == "")
// continue;
//
// printf("%s\n", script.c_str());
// //if (_application->getLuaVmState() != nullptr) {
// _application->getLuaVmState()->execString(script.c_str());
// //}
// }
// printf("Load lua script");
//}
}
#endif
}
......@@ -327,17 +328,26 @@ namespace campvis {
QString filename = QFileDialog::getSaveFileName(QWidget::parentWidget(), dialogCaption, directory, fileFilter);
if (filename != nullptr) {
PropertyCollectionLua *_pcLua = new PropertyCollectionLua();
if (_selectedProcessor != 0 && _selectedPipeline != 0) {
_pcLua->updatePropCollection(_selectedProcessor, &_selectedPipeline->getDataContainer());
std::string script = _pcLua->getLuaScript();
if (script != "") {
PropertyCollectionLua *_pcLua = new PropertyCollectionLua();
std::string pipeScript = "pipeline = pipelines[\"" + _selectedPipeline->getName()+"\"]\n\n";
for (int i = 0; i < _selectedPipeline->getProcessors().size(); i++) {
pipeScript += "proc = pipeline:getProcessor(" + StringUtils::toString(i) + ")\n";
AbstractProcessor *proc = _selectedPipeline->getProcessor(i);
_pcLua->updatePropCollection(proc, &_selectedPipeline->getDataContainer());
pipeScript += _pcLua->getLuaScript("");
}
if (pipeScript != "pipeline = pipelines[\"" + _selectedPipeline->getName()+"\"]\n\n") {
std::ofstream file;
file.open(filename.toStdString());
file << script.c_str();
file << pipeScript.c_str();
file.close();
printf("Saved Lua script");
}
delete _pcLua;
}
}
#endif
......
......@@ -362,10 +362,11 @@ namespace campvis {
const DataContainer& getDataContainer() const;
DataContainer& getDataContainer();
virtual void addProcessor(AbstractProcessor* processor);
virtual void executePipeline() = 0;
AbstractProcessor* getProcessor(const std::string& name) const;
AbstractProcessor* getProcessor(int index) const;
sigslot::signal0 s_init;
sigslot::signal0 s_deinit;
......
......@@ -286,6 +286,12 @@ namespace campvis {
return nullptr;
}
AbstractProcessor* AbstractPipeline::getProcessor( int index ) const {
if (index < 0 || index >= _processors.size())
return nullptr;
return _processors[index];
}
}
......@@ -155,6 +155,13 @@ namespace campvis {
*/
AbstractProcessor* getProcessor(const std::string& name) const;
/**
* Returns the first processor of this pipeline whose name matches \a name.
* \param index The index of the processor to get
* \return The first processor whose name matches \a name, 0 if no such processor exists.
*/
AbstractProcessor* getProcessor(int index) const;
/**
* Gets the flag whether this pipeline is currently enabled.
* \return _enabled
......
......@@ -44,6 +44,9 @@ namespace cgt {
%template(svec3) Vector3<size_t>;
typedef Vector3<size_t> svec3;
%template(ivec3) Vector3<int>;
typedef Vector3<int> ivec3;
/* Vector4 */
......
......@@ -56,7 +56,7 @@ namespace campvis {
*/
virtual ~AbstractPropertyLua();
public:
virtual std::string getLuaScript() = 0;
virtual std::string getLuaScript(std::string prefix = "") = 0;
protected:
AbstractProperty* _property; ///< The property this widget handles
......
......@@ -34,9 +34,9 @@ namespace campvis {
BoolPropertyLua::~BoolPropertyLua() {
}
std::string BoolPropertyLua::getLuaScript() {
std::string BoolPropertyLua::getLuaScript(std::string prefix) {
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue("
ret += "getNestedProperty(\"" + prefix +_property->getName() + "\"):setValue("
+ StringUtils::toString( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
return ret;
}
......
......@@ -47,7 +47,7 @@ namespace campvis {
*/
virtual ~BoolPropertyLua();
std::string getLuaScript();
std::string getLuaScript(std::string prefix);
};
// explicitly instantiate template, so that it gets registered also over DLL boundaries.
......
......@@ -35,7 +35,7 @@ namespace campvis {
ButtonPropertyLua::~ButtonPropertyLua() {
}
std::string ButtonPropertyLua::getLuaScript() {
std::string ButtonPropertyLua::getLuaScript(std::string prefix) {
return "-- Not necessary ButtonProperty";
}
}
\ No newline at end of file
......@@ -50,7 +50,7 @@ namespace campvis {
*/
virtual ~ButtonPropertyLua();
std::string getLuaScript();
std::string getLuaScript(std::string prefix);
};
// explicitly instantiate template, so that it gets registered also over DLL boundaries.
......
......@@ -43,7 +43,7 @@ namespace campvis {
// _lblUpVector->setText("Up Vector: " + QString::fromStdString(StringUtils::toString(prop->getValue().getUpVector())));
//}
std::string CameraPropertyLua::getLuaScript() {
std::string CameraPropertyLua::getLuaScript(std::string prefix) {
std::string ret = "";
tgt::Camera cam = static_cast<CameraProperty*>(_property)->getValue();
tgt::vec3 pos = cam.getPosition();
......@@ -55,7 +55,7 @@ namespace campvis {
float distf = cam.getFarDist();
int pm = cam.getProjectionMode();
ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.Camera("
ret += "getNestedProperty(\"" + prefix+ _property->getName() + "\"):setValue(tgt.Camera("
+ "tgt.vec3(" + StringUtils::toString(pos.x) + "," + StringUtils::toString(pos.y) + "," + StringUtils::toString(pos.z) + ")"
+ "," + "tgt.vec3(" + StringUtils::toString(focus.x) + "," + StringUtils::toString(focus.y) + "," + StringUtils::toString(focus.z) + ")"
+ "," + "tgt.vec3(" + StringUtils::toString(up.x) + "," + StringUtils::toString(up.y) + "," + StringUtils::toString(up.z) + ")"
......
......@@ -51,7 +51,7 @@ namespace campvis {
*/
virtual ~CameraPropertyLua();
std::string getLuaScript();
std::string getLuaScript(std::string prefix);
private:
QLabel* _lblCameraPosition;
......
......@@ -35,10 +35,10 @@ namespace campvis {
ColorPropertyLua::~ColorPropertyLua() {
}
std::string ColorPropertyLua::getLuaScript() {
std::string ColorPropertyLua::getLuaScript(std::string prefix) {
tgt::vec4 value = static_cast<ColorProperty*>(_property)->getValue();
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec4("
ret += "getNestedProperty(\"" + prefix + _property->getName() + "\"):setValue(tgt.vec4("
+ StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) +", "
+ StringUtils::toString(value.z) +", " + StringUtils::toString(value.w) + "))";
return ret;
......
......@@ -50,7 +50,7 @@ namespace campvis {
*/
virtual ~ColorPropertyLua();
std::string getLuaScript();
std::string getLuaScript(std::string prefix);
};
// ================================================================================================
......
......@@ -35,10 +35,10 @@ namespace campvis {
DataNamePropertyLua::~DataNamePropertyLua() {
}
std::string DataNamePropertyLua::getLuaScript() {
std::string DataNamePropertyLua::getLuaScript(std::string prefix) {
const std::string value = static_cast<DataNameProperty*>(_property)->getValue();
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(\"" + value + "\")";
ret += "getNestedProperty(\"" + prefix + _property->getName() + "\"):setValue(\"" + value + "\")";
return ret;
}
}
......@@ -55,7 +55,7 @@ namespace campvis {
*/
virtual ~DataNamePropertyLua();
std::string getLuaScript();
std::string getLuaScript(std::string prefix);
};
// explicitly instantiate template, so that it gets registered also over DLL boundaries.
......
......@@ -35,9 +35,9 @@ namespace campvis {
FloatProperty* property = static_cast<FloatProperty*>(_property);
}
std::string FloatPropertyLua::getLuaScript() {
std::string FloatPropertyLua::getLuaScript(std::string prefix) {
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue("
ret += "getNestedProperty(\"" + prefix + _property->getName() + "\"):setValue("
+ StringUtils::toString( static_cast<FloatProperty*>(_property)->getValue() ) + ")";
return ret;
}
......
......@@ -49,7 +49,7 @@ namespace campvis {
*/
virtual ~FloatPropertyLua();
std::string getLuaScript();
std::string getLuaScript(std::string prefix);
};
......@@ -106,7 +106,7 @@ namespace campvis {
*/
virtual ~VecPropertyLua();
virtual std::string getLuaScript();
virtual std::string getLuaScript(std::string prefix);
};
......@@ -124,9 +124,9 @@ namespace campvis {
}
template<size_t SIZE>
std::string campvis::VecPropertyLua<SIZE>::getLuaScript() {
std::string campvis::VecPropertyLua<SIZE>::getLuaScript(std::string prefix) {
std::string ret = "-- NOT IMPLEMENTED VecProperty";
//ret += "getProperty(" + _property->getName() + "):setValue(" + StringUtils::toString<bool>( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
//ret += "getNestedProperty(" + prefix + _property->getName() + "):setValue(" + StringUtils::toString<bool>( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
return ret;
}
// ================================================================================================
......@@ -138,10 +138,10 @@ namespace campvis {
{
}
std::string campvis::Vec2PropertyLua::getLuaScript() {
std::string campvis::Vec2PropertyLua::getLuaScript(std::string prefix) {
tgt::vec2 value = static_cast<Vec2Property*>(_property)->getValue();
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec2("
ret += "getNestedProperty(\"" + prefix + _property->getName() + "\"):setValue(tgt.vec2("
+ StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) + "))";
return ret;
}
......@@ -155,10 +155,10 @@ namespace campvis {
: VecPropertyLua<3>(property, dataContainer)
{
}
std::string campvis::Vec3PropertyLua::getLuaScript() {
std::string campvis::Vec3PropertyLua::getLuaScript(std::string prefix) {
tgt::vec3 value = static_cast<Vec3Property*>(_property)->getValue();
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec3("
ret += "getNestedProperty(\"" + prefix + _property->getName() + "\"):setValue(tgt.vec3("
+ StringUtils::toString(value.x) +", " + StringUtils::toString(value.y)
+", " + StringUtils::toString(value.z) + "))";
return ret;
......@@ -174,10 +174,10 @@ namespace campvis {
{
}
std::string campvis::Vec4PropertyLua::getLuaScript() {
std::string campvis::Vec4PropertyLua::getLuaScript(std::string prefix) {
tgt::vec4 value = static_cast<Vec4Property*>(_property)->getValue();
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec4("
ret += "getNestedProperty(\"" + prefix + _property->getName() + "\"):setValue(tgt.vec4("
+ StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) +", "
+ StringUtils::toString(value.z) +", " + StringUtils::toString(value.w) + "))";
return ret;
......
......@@ -34,9 +34,9 @@ namespace campvis {
IntPropertyLua::~IntPropertyLua() {
}
std::string IntPropertyLua::getLuaScript() {
std::string IntPropertyLua::getLuaScript(std::string prefix) {
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue("
ret += "getNestedProperty(\"" + prefix + _property->getName() + "\"):setValue("
+ StringUtils::toString( static_cast<IntProperty*>(_property)->getValue() ) + ")";
return ret;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment