Commit 4ac8964c authored by Hossain Mahmud's avatar Hossain Mahmud
Browse files

probably only except transferfunction

Conflicts:
	scripting/CMakeLists.txt
parent a5c6a2e7
...@@ -12,11 +12,15 @@ INCLUDE(${SWIG_USE_FILE}) ...@@ -12,11 +12,15 @@ INCLUDE(${SWIG_USE_FILE})
FILE(GLOB CampvisScriptingSources FILE(GLOB CampvisScriptingSources
*.cpp *.cpp
glue/*.cpp glue/*.cpp
luagen/*.cpp
luagen/properties/*.cpp
) )
FILE(GLOB CampvisScriptingHeaders FILE(GLOB CampvisScriptingHeaders
*.h *.h
glue/*.h glue/*.h
luagen/*.h
luagen/properties/*.h
) )
IF(WIN32) IF(WIN32)
...@@ -123,4 +127,9 @@ ADD_LIBRARY(campvis-scripting ${CampvisSharedStaticModulesFix} ...@@ -123,4 +127,9 @@ ADD_LIBRARY(campvis-scripting ${CampvisSharedStaticModulesFix}
) )
ADD_DEPENDENCIES(campvis-scripting ${CampvisLuaModules}) ADD_DEPENDENCIES(campvis-scripting ${CampvisLuaModules})
TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules cgt ${CampvisGlobalExternalLibs}) TARGET_LINK_LIBRARIES(campvis-scripting campvis-core campvis-modules tgt ${CampvisGlobalExternalLibs})
IF(CAMPVIS_GROUP_SOURCE_FILES)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisScriptingSources ${CampvisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(CampvisScriptingHeaders ${CampvisHome} "")
ENDIF()
#include "regularluatable.h" #include "regularluatable.h"
// Add property luas to ensure build
// TODO: find a better way
#include "scripting/luagen/properties/boolpropertylua.h"
#include "scripting/luagen/properties/buttonpropertylua.h"
#include "scripting/luagen/properties/floatpropertylua.h"
#include "scripting/luagen/properties/intpropertylua.h"
#include "scripting/luagen/properties/optionpropertylua.h"
#include "scripting/luagen/properties/stringpropertylua.h"
#include "scripting/luagen/properties/camerapropertylua.h"
#include "scripting/luagen/properties/colorpropertylua.h"
#include "scripting/luagen/properties/datanamepropertylua.h"
#include "scripting/luagen/properties/metapropertylua.h"
#include "scripting/luagen/properties/propertycollectionlua.h"
namespace campvis { namespace campvis {
......
...@@ -30,7 +30,7 @@ namespace campvis { ...@@ -30,7 +30,7 @@ namespace campvis {
: _property(property) : _property(property)
, _dataContainer(dataContainer) , _dataContainer(dataContainer)
{ {
_ignorePropertyUpdates = 0; //_ignorePropertyUpdates = 0;
} }
AbstractPropertyLua::~AbstractPropertyLua() { AbstractPropertyLua::~AbstractPropertyLua() {
......
...@@ -63,7 +63,7 @@ namespace campvis { ...@@ -63,7 +63,7 @@ namespace campvis {
DataContainer* _dataContainer; ///< DataContainer to use (e.g. to populate GUI), may be 0! DataContainer* _dataContainer; ///< DataContainer to use (e.g. to populate GUI), may be 0!
/// Semaphore acts as flag whether the widget shall ignore incoming signals from properties being updated. /// Semaphore acts as flag whether the widget shall ignore incoming signals from properties being updated.
tbb::atomic<int> _ignorePropertyUpdates; //tbb::atomic<int> _ignorePropertyUpdates;
}; };
} }
......
...@@ -36,9 +36,8 @@ namespace campvis { ...@@ -36,9 +36,8 @@ namespace campvis {
std::string BoolPropertyLua::getLuaScript() { std::string BoolPropertyLua::getLuaScript() {
std::string ret = ""; std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(" + StringUtils::toString<bool>( static_cast<BoolProperty*>(_property)->getValue() ) + ")"; ret += "getProperty(\"" + _property->getName() + "\"):setValue("
+ StringUtils::toString( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
std::printf(ret.c_str());
return ret; return ret;
} }
} }
\ No newline at end of file
...@@ -22,45 +22,52 @@ ...@@ -22,45 +22,52 @@
// //
// ================================================================================================ // ================================================================================================
#include "camerapropertywidget.h" #include "camerapropertylua.h"
#include <QGridLayout>
#include <QLabel>
#include "core/tools/stringutils.h" #include "core/tools/stringutils.h"
namespace campvis { namespace campvis {
CameraPropertyWidget::CameraPropertyWidget(CameraProperty* property, DataContainer* dataContainer, QWidget* parent /*= 0*/) CameraPropertyLua::CameraPropertyLua(CameraProperty* property, DataContainer* dataContainer)
: AbstractPropertyWidget(property, true, dataContainer, parent) : AbstractPropertyLua(property, true, dataContainer)
, _lblCameraPosition(0)
, _lblLookDirection(0)
, _lblUpVector(0)
{ {
_widget = new QWidget(this);
QGridLayout* gridLayout = new QGridLayout(_widget);
_widget->setLayout(gridLayout);
_lblCameraPosition = new QLabel("Position: ", _widget);
gridLayout->addWidget(_lblCameraPosition, 0, 0);
_lblFocusPosition = new QLabel("Focus: ", _widget);
gridLayout->addWidget(_lblFocusPosition, 1, 0);
_lblLookDirection = new QLabel("Look Direction: ", _widget);
gridLayout->addWidget(_lblLookDirection, 2, 0);
_lblUpVector = new QLabel("Up Vector: ", _widget);
gridLayout->addWidget(_lblUpVector, 3, 0);
addWidget(_widget);
updateWidgetFromProperty();
} }
CameraPropertyWidget::~CameraPropertyWidget() { CameraPropertyLua::~CameraPropertyLua() {
} }
void CameraPropertyWidget::updateWidgetFromProperty() { //void CameraPropertyLua::updateLuaFromProperty() {
CameraProperty* prop = static_cast<CameraProperty*>(_property); // CameraProperty* prop = static_cast<CameraProperty*>(_property);
_lblCameraPosition->setText("Position: " + QString::fromStdString(StringUtils::toString(prop->getValue().getPosition()))); // _lblCameraPosition->setText("Position: " + QString::fromStdString(StringUtils::toString(prop->getValue().getPosition())));
_lblFocusPosition->setText("Focus: " + QString::fromStdString(StringUtils::toString(prop->getValue().getFocus()))); // _lblFocusPosition->setText("Focus: " + QString::fromStdString(StringUtils::toString(prop->getValue().getFocus())));
_lblLookDirection->setText("Look Direction: " + QString::fromStdString(StringUtils::toString(prop->getValue().getLook()))); // _lblLookDirection->setText("Look Direction: " + QString::fromStdString(StringUtils::toString(prop->getValue().getLook())));
_lblUpVector->setText("Up Vector: " + QString::fromStdString(StringUtils::toString(prop->getValue().getUpVector()))); // _lblUpVector->setText("Up Vector: " + QString::fromStdString(StringUtils::toString(prop->getValue().getUpVector())));
//}
std::string CameraPropertyLua::getLuaScript() {
std::string ret = "";
tgt::Camera cam = static_cast<CameraProperty*>(_property)->getValue();
tgt::vec3 pos = cam.getPosition();
tgt::vec3 focus = cam.getFocus();
tgt::vec3 up = cam.getUpVector();
float fovy = cam.getFovy();
float ratio = cam.getRatio();
float distn = cam.getNearDist();
float distf = cam.getFarDist();
int pm = cam.getProjectionMode();
ret += "getProperty(\"" + _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) + ")"
+ "," + StringUtils::toString(fovy)
+ "," + StringUtils::toString(ratio)
+ "," + StringUtils::toString(distn)
+ "," + StringUtils::toString(distf)
+ "," + StringUtils::toString(pm)
+"))";
//ret = "-- If required need to implement lua interface for tgt:Camera";
return ret;
} }
} }
\ No newline at end of file
...@@ -22,45 +22,38 @@ ...@@ -22,45 +22,38 @@
// //
// ================================================================================================ // ================================================================================================
#ifndef CAMERAPROPERTYWIDGET_H__ #ifndef CAMERAPROPERTYLUA_H__
#define CAMERAPROPERTYWIDGET_H__ #define CAMERAPROPERTYLUA_H__
#include "application/gui/properties/abstractpropertywidget.h" #include "abstractpropertylua.h"
#include "application/gui/properties/propertywidgetfactory.h" #include "propertyluafactory.h"
#include "core/properties/cameraproperty.h" #include "core/properties/cameraproperty.h"
class QLabel; class QLabel;
namespace campvis { namespace campvis {
/** /**
* Widget for a Camera. * Lua for a Camera.
* For now just offering read-access. * For now just offering read-access.
*/ */
class CameraPropertyWidget : public AbstractPropertyWidget { class CameraPropertyLua : public AbstractPropertyLua {
Q_OBJECT;
public: public:
/** /**
* Creates a new CameraPropertyWidget for the property \a property. * Creates a new CameraPropertyLua for the property \a property.
* \param property The property the widget shall handle * \param property The property the lua shall handle
* \param dataContainer DataContainer to use (optional), defaults to nullptr. * \param dataContainer DataContainer to use (optional), defaults to nullptr.
* \param parent Parent Qt widget * \param parent Parent Qt lua
*/ */
CameraPropertyWidget(CameraProperty* property, DataContainer* dataContainer, QWidget* parent = 0); CameraPropertyLua(CameraProperty* property, DataContainer* dataContainer);
/** /**
* Destructor * Destructor
*/ */
virtual ~CameraPropertyWidget(); virtual ~CameraPropertyLua();
protected: std::string getLuaScript();
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
private: private:
QWidget* _widget;
QLabel* _lblCameraPosition; QLabel* _lblCameraPosition;
QLabel* _lblFocusPosition; QLabel* _lblFocusPosition;
QLabel* _lblLookDirection; QLabel* _lblLookDirection;
...@@ -69,8 +62,8 @@ namespace campvis { ...@@ -69,8 +62,8 @@ namespace campvis {
}; };
// explicitly instantiate template, so that it gets registered also over DLL boundaries. // explicitly instantiate template, so that it gets registered also over DLL boundaries.
template class PropertyWidgetRegistrar<CameraPropertyWidget, CameraProperty>; template class PropertyLuaRegistrar<CameraPropertyLua, CameraProperty>;
} }
#endif // CAMERAPROPERTYWIDGET_H__ #endif // CAMERAPROPERTYLUA_H__
...@@ -22,46 +22,25 @@ ...@@ -22,46 +22,25 @@
// //
// ================================================================================================ // ================================================================================================
#include "colorpropertywidget.h" #include "colorpropertylua.h"
#include "core/properties/colorproperty.h" #include "core/properties/colorproperty.h"
#include "core/tools/stringutils.h"
namespace campvis { namespace campvis {
ColorPropertyWidget::ColorPropertyWidget(ColorProperty* property, DataContainer* dataContainer, QWidget* parent /*= 0*/) ColorPropertyLua::ColorPropertyLua(ColorProperty* property, DataContainer* dataContainer)
: AbstractPropertyWidget(property, false, dataContainer, parent) : AbstractPropertyLua(property, false, dataContainer)
//, _lblColorPicker(0)
, _colorPicker(0)
{ {
//_lblColorPicker = new QLabel("Change color: ", this);
_colorPicker = new ColorPickerWidget(QtColorTools::toQColor(property->getValue()), this);
addWidget(_colorPicker);
//connect(_colorPicker, SIGNAL(valueChanged(tgt::vec4)), this, SLOT(onColorChanged(tgt::vec4)));
connect(_colorPicker, SIGNAL(colorChanged(const QColor&)), this, SLOT(onColorChanged(const QColor&)));
}
ColorPropertyWidget::~ColorPropertyWidget() {
}
void ColorPropertyWidget::updateWidgetFromProperty() {
_colorPicker->blockSignals(true);
const tgt::vec4 val = static_cast<ColorProperty*>(_property)->getValue();
_colorPicker->setColor(QtColorTools::toQColor(tgt::vec4(val.x *255, val.y*255, val.z*255, val.w*255)));
_colorPicker->blockSignals(false);
} }
void ColorPropertyWidget::onColorChanged(const QColor& value) { ColorPropertyLua::~ColorPropertyLua() {
++_ignorePropertyUpdates;
ColorProperty* prop = static_cast<ColorProperty*>(_property);
tgt::vec4 val = QtColorTools::toTgtColor(_colorPicker->color());
prop->setValue(tgt::vec4(val.x/val.w, val.y/val.w, val.z/val.w, 1));
--_ignorePropertyUpdates;
} }
void ColorPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) { std::string ColorPropertyLua::getLuaScript() {
if (_ignorePropertyUpdates == 0) tgt::vec4 value = static_cast<ColorProperty*>(_property)->getValue();
emit s_propertyChanged(property); std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec4("
+ StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) +", "
+ StringUtils::toString(value.z) +", " + StringUtils::toString(value.w) + "))";
return ret;
} }
} }
...@@ -22,63 +22,42 @@ ...@@ -22,63 +22,42 @@
// //
// ================================================================================================ // ================================================================================================
#ifndef COLORPROPERTYWIDGET_H__ #ifndef COLORPROPERTYLUA_H__
#define COLORPROPERTYWIDGET_H__ #define COLORPROPERTYLUA_H__
#include "application/gui/adjusterwidgets/doubleadjusterwidget.h" #include "abstractpropertylua.h"
#include "application/gui/properties/abstractpropertywidget.h" #include "propertyluafactory.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "core/properties/floatingpointproperty.h" #include "core/properties/floatingpointproperty.h"
#include "core/properties/colorproperty.h" #include "core/properties/colorproperty.h"
#include "application/gui/qtcolortools.h"
namespace campvis { namespace campvis {
/** /**
* Widget for a ColorProperty * Lua for a ColorProperty
*/ */
class ColorPropertyWidget : public AbstractPropertyWidget { class ColorPropertyLua : public AbstractPropertyLua {
Q_OBJECT
public: public:
/** /**
* Creates a new FloatPropertyWidget for the property \a property. * Creates a new FloatPropertyLua for the property \a property.
* \param property The property the widget shall handle * \param property The property the lua shall handle
* \param dataContainer DataContainer to use (optional), defaults to nullptr. * \param dataContainer DataContainer to use (optional), defaults to nullptr.
* \param parent Parent Qt widget * \param parent Parent Qt lua
*/ */
ColorPropertyWidget(ColorProperty* property, DataContainer* dataContainer, QWidget* parent = 0); ColorPropertyLua(ColorProperty* property, DataContainer* dataContainer);
/** /**
* Destructor * Destructor
*/ */
virtual ~ColorPropertyWidget(); virtual ~ColorPropertyLua();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
private slots:
/// Slot getting called when the adjuster's value changes
void onColorChanged(const QColor&);
private:
/// Slot getting called when the property's min or max value has changed, so that the widget can be updated.
virtual void onPropertyMinMaxChanged(const AbstractProperty* property);
//QLabel *_lblColorPicker;
ColorPickerWidget * _colorPicker; ///< color picker widget allowing to change color
std::string getLuaScript();
}; };
// ================================================================================================ // ================================================================================================
// explicitly instantiate template, so that it gets registered also over DLL boundaries. // explicitly instantiate template, so that it gets registered also over DLL boundaries.
template class PropertyWidgetRegistrar<ColorPropertyWidget, ColorProperty>; template class PropertyLuaRegistrar<ColorPropertyLua, ColorProperty>;
} }
#endif // COLORPROPERTYWIDGET_H__ #endif // COLORPROPERTYLUA_H__
...@@ -22,92 +22,23 @@ ...@@ -22,92 +22,23 @@
// //
// ================================================================================================ // ================================================================================================
#include "datanamepropertywidget.h" #include "datanamepropertylua.h"
#include "core/datastructures/datacontainer.h" #include "core/datastructures/datacontainer.h"
#include "core/properties/datanameproperty.h" #include "core/properties/datanameproperty.h"
#include "core/tools/stringutils.h"
#include <QComboBox>
#include <QLineEdit>
namespace campvis { namespace campvis {
DataNamePropertyWidget::DataNamePropertyWidget(DataNameProperty* property, DataContainer* dc, QWidget* parent /*= 0*/) DataNamePropertyLua::DataNamePropertyLua(DataNameProperty* property, DataContainer* dc)
: AbstractPropertyWidget(property, false, dc, parent) : AbstractPropertyLua(property, false, dc)
, _lineEdit(0)
, _combobox(0)
{ {
if (property->getAccessInfo() == DataNameProperty::READ) {
_combobox = new QComboBox(this);
_combobox->setEditable(true);
if (dc != 0) {
std::vector< std::pair<std::string, DataHandle> > tmp = dc->getDataHandlesCopy();
QStringList sl;
for (size_t i = 0; i < tmp.size(); ++i)
sl.append(QString::fromStdString(tmp[i].first));
_combobox->addItems(sl);
dc->s_dataAdded.connect(this, &DataNamePropertyWidget::onDataAdded);
connect(this, SIGNAL(s_dataAddedQt(const QString&, QtDataHandle)), this, SLOT(onDataAddedQt(const QString&, QtDataHandle)));
setCurrentComboBoxText(QString::fromStdString(property->getValue()));
}
addWidget(_combobox);
connect(_combobox, SIGNAL(editTextChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
}
else {
_lineEdit = new QLineEdit(this);
_lineEdit->setText(QString::fromStdString(property->getValue()));
addWidget(_lineEdit);
connect(_lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
}
} }
DataNamePropertyWidget::~DataNamePropertyWidget() { DataNamePropertyLua::~DataNamePropertyLua() {
if (_dataContainer != 0 && static_cast<DataNameProperty*>(_property)->getAccessInfo() == DataNameProperty::READ)
_dataContainer->s_dataAdded.disconnect(this);
} }
std::string DataNamePropertyLua::getLuaScript() {
void DataNamePropertyWidget::updateWidgetFromProperty() { const std::string value = static_cast<DataNameProperty*>(_property)->getValue();
DataNameProperty* prop = static_cast<DataNameProperty*>(_property); std::string ret = "";
QString qs = QString::fromStdString(prop->getValue()); ret += "getProperty(\"" + _property->getName() + "\"):setValue(\"" + value + "\")";
return ret;
if (prop->getAccessInfo() == DataNameProperty::READ) {
_combobox->blockSignals(true);
setCurrentComboBoxText(qs);
_combobox->blockSignals(false);
}
else if (_lineEdit->text() != qs) {
_lineEdit->blockSignals(true);
_lineEdit->setText(qs);
_lineEdit->blockSignals(false);
}
}
void DataNamePropertyWidget::setCurrentComboBoxText(const QString& text) {
int idx = _combobox->findText(text);
if (idx != -1)
_combobox->setCurrentIndex(idx);
else
_combobox->setEditText(text);
} }
void DataNamePropertyWidget::onTextChanged(const QString& text) {
DataNameProperty* prop = static_cast<DataNameProperty*>(_property);
++_ignorePropertyUpdates;
prop->setValue(text.toStdString());
--_ignorePropertyUpdates;
}
void DataNamePropertyWidget::onDataAdded(std::string key, DataHandle dh) {
emit s_dataAddedQt(QString::fromStdString(key), dh);
}
void DataNamePropertyWidget::onDataAddedQt(const QString& key, QtDataHandle dh) {
if (_combobox->findText(key) == -1) {
_combobox->addItem(key);
}
}
} }
...@@ -22,14 +22,12 @@ ...@@ -22,14 +22,12 @@
// //
// ================================================================================================ // ================================================================================================
#ifndef DATANAMEPROPERTYWIDGET_H__ #ifndef DATANAMEPROPERTYLUA_H__
#define DATANAMEPROPERTYWIDGET_H__ #define DATANAMEPROPERTYLUA_H__
#include "sigslot/sigslot.h"
#include "core/properties/datanameproperty.h" #include "core/properties/datanameproperty.h"
#include "application/gui/qtdatahandle.h" #include "abstractpropertylua.h"
#include "application/gui/properties/abstractpropertywidget.h" #include "propertyluafactory.h"
#include "application/gui/properties/propertywidgetfactory.h"
class QComboBox; class QComboBox;