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})
FILE(GLOB CampvisScriptingSources
*.cpp
glue/*.cpp
luagen/*.cpp
luagen/properties/*.cpp
)
FILE(GLOB CampvisScriptingHeaders
*.h
glue/*.h
luagen/*.h
luagen/properties/*.h
)
IF(WIN32)
......@@ -123,4 +127,9 @@ ADD_LIBRARY(campvis-scripting ${CampvisSharedStaticModulesFix}
)
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"
// 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 {
......
......@@ -30,7 +30,7 @@ namespace campvis {
: _property(property)
, _dataContainer(dataContainer)
{
_ignorePropertyUpdates = 0;
//_ignorePropertyUpdates = 0;
}
AbstractPropertyLua::~AbstractPropertyLua() {
......
......@@ -63,7 +63,7 @@ namespace campvis {
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.
tbb::atomic<int> _ignorePropertyUpdates;
//tbb::atomic<int> _ignorePropertyUpdates;
};
}
......
......@@ -36,9 +36,8 @@ namespace campvis {
std::string BoolPropertyLua::getLuaScript() {
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(" + StringUtils::toString<bool>( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
std::printf(ret.c_str());
ret += "getProperty(\"" + _property->getName() + "\"):setValue("
+ StringUtils::toString( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
return ret;
}
}
\ No newline at end of file
......@@ -22,45 +22,52 @@
//
// ================================================================================================
#include "camerapropertywidget.h"
#include "camerapropertylua.h"
#include <QGridLayout>
#include <QLabel>
#include "core/tools/stringutils.h"
namespace campvis {
CameraPropertyWidget::CameraPropertyWidget(CameraProperty* property, DataContainer* dataContainer, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, true, dataContainer, parent)
, _lblCameraPosition(0)
, _lblLookDirection(0)
, _lblUpVector(0)
CameraPropertyLua::CameraPropertyLua(CameraProperty* property, DataContainer* dataContainer)
: AbstractPropertyLua(property, true, dataContainer)
{
_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() {
CameraProperty* prop = static_cast<CameraProperty*>(_property);
_lblCameraPosition->setText("Position: " + QString::fromStdString(StringUtils::toString(prop->getValue().getPosition())));
_lblFocusPosition->setText("Focus: " + QString::fromStdString(StringUtils::toString(prop->getValue().getFocus())));
_lblLookDirection->setText("Look Direction: " + QString::fromStdString(StringUtils::toString(prop->getValue().getLook())));
_lblUpVector->setText("Up Vector: " + QString::fromStdString(StringUtils::toString(prop->getValue().getUpVector())));
//void CameraPropertyLua::updateLuaFromProperty() {
// CameraProperty* prop = static_cast<CameraProperty*>(_property);
// _lblCameraPosition->setText("Position: " + QString::fromStdString(StringUtils::toString(prop->getValue().getPosition())));
// _lblFocusPosition->setText("Focus: " + QString::fromStdString(StringUtils::toString(prop->getValue().getFocus())));
// _lblLookDirection->setText("Look Direction: " + QString::fromStdString(StringUtils::toString(prop->getValue().getLook())));
// _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 @@
//
// ================================================================================================
#ifndef CAMERAPROPERTYWIDGET_H__
#define CAMERAPROPERTYWIDGET_H__
#ifndef CAMERAPROPERTYLUA_H__
#define CAMERAPROPERTYLUA_H__
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
#include "core/properties/cameraproperty.h"
class QLabel;
namespace campvis {
/**
* Widget for a Camera.
* Lua for a Camera.
* For now just offering read-access.
*/
class CameraPropertyWidget : public AbstractPropertyWidget {
Q_OBJECT;
class CameraPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new CameraPropertyWidget for the property \a property.
* \param property The property the widget shall handle
* Creates a new CameraPropertyLua for the property \a property.
* \param property The property the lua shall handle
* \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
*/
virtual ~CameraPropertyWidget();
virtual ~CameraPropertyLua();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
std::string getLuaScript();
private:
QWidget* _widget;
QLabel* _lblCameraPosition;
QLabel* _lblFocusPosition;
QLabel* _lblLookDirection;
......@@ -69,8 +62,8 @@ namespace campvis {
};
// 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 @@
//
// ================================================================================================
#include "colorpropertywidget.h"
#include "colorpropertylua.h"
#include "core/properties/colorproperty.h"
#include "core/tools/stringutils.h"
namespace campvis {
ColorPropertyWidget::ColorPropertyWidget(ColorProperty* property, DataContainer* dataContainer, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, false, dataContainer, parent)
//, _lblColorPicker(0)
, _colorPicker(0)
ColorPropertyLua::ColorPropertyLua(ColorProperty* property, DataContainer* dataContainer)
: AbstractPropertyLua(property, false, dataContainer)
{
//_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) {
++_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;
ColorPropertyLua::~ColorPropertyLua() {
}
void ColorPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0)
emit s_propertyChanged(property);
std::string ColorPropertyLua::getLuaScript() {
tgt::vec4 value = static_cast<ColorProperty*>(_property)->getValue();
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 @@
//
// ================================================================================================
#ifndef COLORPROPERTYWIDGET_H__
#define COLORPROPERTYWIDGET_H__
#ifndef COLORPROPERTYLUA_H__
#define COLORPROPERTYLUA_H__
#include "application/gui/adjusterwidgets/doubleadjusterwidget.h"
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/colorproperty.h"
#include "application/gui/qtcolortools.h"
namespace campvis {
/**
* Widget for a ColorProperty
* Lua for a ColorProperty
*/
class ColorPropertyWidget : public AbstractPropertyWidget {
Q_OBJECT
class ColorPropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new FloatPropertyWidget for the property \a property.
* \param property The property the widget shall handle
* Creates a new FloatPropertyLua for the property \a property.
* \param property The property the lua shall handle
* \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
*/
virtual ~ColorPropertyWidget();
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
virtual ~ColorPropertyLua();
std::string getLuaScript();
};
// ================================================================================================
// 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 @@
//
// ================================================================================================
#include "datanamepropertywidget.h"
#include "datanamepropertylua.h"
#include "core/datastructures/datacontainer.h"
#include "core/properties/datanameproperty.h"
#include <QComboBox>
#include <QLineEdit>
#include "core/tools/stringutils.h"
namespace campvis {
DataNamePropertyWidget::DataNamePropertyWidget(DataNameProperty* property, DataContainer* dc, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, false, dc, parent)
, _lineEdit(0)
, _combobox(0)
DataNamePropertyLua::DataNamePropertyLua(DataNameProperty* property, DataContainer* dc)
: AbstractPropertyLua(property, false, dc)
{
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() {
if (_dataContainer != 0 && static_cast<DataNameProperty*>(_property)->getAccessInfo() == DataNameProperty::READ)
_dataContainer->s_dataAdded.disconnect(this);
}
void DataNamePropertyWidget::updateWidgetFromProperty() {
DataNameProperty* prop = static_cast<DataNameProperty*>(_property);
QString qs = QString::fromStdString(prop->getValue());
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);
DataNamePropertyLua::~DataNamePropertyLua() {
}
std::string DataNamePropertyLua::getLuaScript() {
const std::string value = static_cast<DataNameProperty*>(_property)->getValue();
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(\"" + value + "\")";
return ret;
}
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 @@
//
// ================================================================================================
#ifndef DATANAMEPROPERTYWIDGET_H__
#define DATANAMEPROPERTYWIDGET_H__
#ifndef DATANAMEPROPERTYLUA_H__
#define DATANAMEPROPERTYLUA_H__
#include "sigslot/sigslot.h"
#include "core/properties/datanameproperty.h"
#include "application/gui/qtdatahandle.h"
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "abstractpropertylua.h"
#include "propertyluafactory.h"
class QComboBox;
class QLineEdit;
......@@ -40,58 +38,28 @@ namespace campvis {
class DataHandle;
/**
* Widget for a DataNameProperty
* Lua for a DataNameProperty
*/
class DataNamePropertyWidget : public AbstractPropertyWidget {
Q_OBJECT
class DataNamePropertyLua : public AbstractPropertyLua {
public:
/**
* Creates a new PropertyWidget for the property \a property.
* \param property The property the widget shall handle
* Creates a new PropertyLua for the property \a property.
* \param property The property the lua shall handle
* \param dc DataContainer this property uses to populate the combo box (may be 0).
* \param parent Parent Qt widget
* \param parent Parent Qt lua
*/
DataNamePropertyWidget(DataNameProperty* property, DataContainer* dc, QWidget* parent = 0);
DataNamePropertyLua(DataNameProperty* property, DataContainer* dc);
/**
* Destructor
*/
virtual ~DataNamePropertyWidget();
protected:
/**
* Gets called when the property has changed, so that widget can update its state.
*/
virtual void updateWidgetFromProperty();
void onDataAdded(std::string key, DataHandle dh);
private slots:
void onTextChanged(const QString& text);
void onDataAddedQt(const QString& key, QtDataHandle dh);
signals:
void s_dataAddedQt(const QString& key, QtDataHandle dh);
private:
/**
* Set the combo box's current text to the provided value.
*
* If \c text can already be found in the combo box, the corresponding item is made active. Otherwise, \c text
* is set as the contents of the combo box's text edit.
*
* \param text text to be set in the combo box
*/
void setCurrentComboBoxText(const QString& text);
QLineEdit* _lineEdit;
QComboBox* _combobox;
virtual ~DataNamePropertyLua();
std::string getLuaScript();
};
// explicitly instantiate template, so that it gets registered also over DLL boundaries.
template class PropertyWidgetRegistrar<DataNamePropertyWidget, DataNameProperty, 10>;
template class PropertyLuaRegistrar<DataNamePropertyLua, DataNameProperty, 10>;
}
#endif // DATANAMEPROPERTYWIDGET_H__
#endif // DATANAMEPROPERTYLUA_H__
......@@ -37,9 +37,8 @@ namespace campvis {
std::string FloatPropertyLua::getLuaScript() {
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(" + StringUtils::toString( static_cast<FloatProperty*>(_property)->getValue() ) + ")";
std::printf(ret.c_str());
ret += "getProperty(\"" + _property->getName() + "\"):setValue("
+ StringUtils::toString( static_cast<FloatProperty*>(_property)->getValue() ) + ")";
return ret;
}
}
......@@ -127,8 +127,6 @@ namespace campvis {
std::string campvis::VecPropertyLua<SIZE>::getLuaScript() {
std::string ret = "-- NOT IMPLEMENTED VecProperty";
//ret += "getProperty(" + _property->getName() + "):setValue(" + StringUtils::toString<bool>( static_cast<BoolProperty*>(_property)->getValue() ) + ")";
std::printf(ret.c_str());
return ret;
}
// ================================================================================================
......@@ -145,8 +143,6 @@ namespace campvis {
std::string ret = "";
ret += "getProperty(\"" + _property->getName() + "\"):setValue(tgt.vec2("
+ StringUtils::toString(value.x) +", " + StringUtils::toString(value.y) + "))";
std::printf(ret.c_str());
return ret;
}