Commit b8f8a6eb authored by Martin Heistermann's avatar Martin Heistermann

Make some propVis settings accessible from script.

Only implemented for bool and double properties, extending
it to other property types is trivial.
parent 50408cdf
include (plugin)
openflipper_plugin (INSTALLDATA Icons
DIRS OpenMesh OpenVolumeMesh Widgets
DIRS OpenMesh OpenVolumeMesh Widgets ScriptObjects
DEPS OpenMesh
OPTDEPS OpenVolumeMesh
OPT_TYPES SKELETON BSPLINECURVE POLYHEDRALMESH HEXAHEDRALMESH TETRAHEDRALMESH
......
......@@ -58,6 +58,7 @@
#include "PropertyVisPlugin.hh"
#include "PropertyModelFactory.hh"
#include "SingleObjectPropertyModel.hh"
#ifdef ENABLE_POLYHEDRALMESH_SUPPORT
#include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
......@@ -141,7 +142,30 @@ void PropertyVisPlugin::slotVisualizeProperty( int _id, const QString& _propname
emit updateView();
emit updatedObject( _id, UPDATE_COLOR );
}
}
}
}
QScriptValue PropertyVisPlugin::getPropertyVisualizer(int _id, const QString &_propname)
{
PropertyModel* model = PropertyModelFactory::Instance().getModel(_id);
if (model == nullptr) { return QScriptValue::SpecialValue::NullValue; }
model->gatherProperties();
QModelIndex idx = model->indexFromPlainPropName(_propname);
if (!idx.isValid()) { return QScriptValue::SpecialValue::NullValue; }
QScriptEngine *engine;
emit getScriptingEngine (engine);
if (engine == nullptr) { return QScriptValue::SpecialValue::NullValue; }
QScriptContext *ctx = engine->currentContext();
if (ctx == nullptr) { return QScriptValue::SpecialValue::NullValue; }
auto sopm = dynamic_cast<SingleObjectPropertyModel*>(model);
if (!sopm) { return QScriptValue::SpecialValue::NullValue; }
return sopm->getScriptObject(idx, ctx);
}
//-----------------------------------------------------------------------------
......
......@@ -112,9 +112,9 @@ signals:
//PickingInterface
void addHiddenPickMode( const std::string& _mode );
public slots:
void slotVisualizeProperty( int _id, const QString& _propname );
// Script Interface
void getScriptingEngine( QScriptEngine*& _engine ) override;
private slots:
......@@ -154,8 +154,13 @@ private slots:
void slotLog(Logtype _type, QString _message){ emit log(_type, _message); }
void slotLog(QString _message){ emit log(_message); }
public :
public slots:
void slotVisualizeProperty( int _id, const QString& _propname );
QScriptValue getPropertyVisualizer( int _id, const QString& _propname );
public :
PropertyVisPlugin();
~PropertyVisPlugin() {}
......
#include "ScriptObject.hh"
#include <QScriptContext>
#include <QScriptEngine>
#include <QWidget>
#include "Widgets/BooleanWidget.hh"
#include "ScriptSettingsBoolean.hh"
#include "ScriptSettingsDouble.hh"
QScriptValue createSettingsScriptObject(
QScriptContext *ctx,
QWidget *widget)
{
QScriptEngine *engine = ctx->engine();
auto bw = dynamic_cast<BooleanWidget*>(widget);
if (bw) {return engine->newQObject(new ScriptSettingsBoolean(bw)); }
auto dw = dynamic_cast<DoubleWidget*>(widget);
if (dw) {return engine->newQObject(new ScriptSettingsDouble(dw)); }
// not implemented:
return QScriptValue::SpecialValue::NullValue;
}
#ifndef SCRIPTOBJECT_HH
#define SCRIPTOBJECT_HH
#include <QScriptValue>
class QScriptContext;
class QWidget;
QScriptValue createSettingsScriptObject(QScriptContext *ctx, QWidget *widget);
#endif // SCRIPTOBJECT_HH
#include "ScriptSettingsBoolean.hh"
#include "ACG/Utils/ColorConversion.hh"
ScriptSettingsBoolean::ScriptSettingsBoolean()
: widget_(nullptr)
{}
ScriptSettingsBoolean::ScriptSettingsBoolean(BooleanWidget *widget)
: widget_(widget)
{}
ScriptSettingsBoolean::ScriptSettingsBoolean(const ScriptSettingsBoolean &other)
: QObject(),
widget_(other.widget_)
{}
ScriptSettingsBoolean::~ScriptSettingsBoolean() {}
const Vector4 ScriptSettingsBoolean::colorTrue() const
{
return ACG::to_Vec4d(widget_->colorTrue ->color());
}
const Vector4 ScriptSettingsBoolean::colorFalse() const
{
return ACG::to_Vec4d(widget_->colorFalse->color());
}
void ScriptSettingsBoolean::setColorTrue(const Vector4 &color)
{
widget_->colorTrue ->setColor(ACG::to_QColor(color));
}
void ScriptSettingsBoolean::setColorFalse(const Vector4 &color)
{
widget_->colorFalse->setColor(ACG::to_QColor(color));
}
#ifndef SCRIPTSETTINGSBOOLEAN_HH
#define SCRIPTSETTINGSBOOLEAN_HH
#include <QObject>
#include "Widgets/BooleanWidget.hh"
#include "ACG/Math/VectorT.hh"
#include "OpenFlipper/common/DataTypes.hh"
class ScriptSettingsBoolean : public QObject {
Q_OBJECT
// We use Vector4 instead of a proper color type as those are not (yet)
// exposed to the scripting environment.
Q_PROPERTY(Vector4 colorTrue READ colorTrue WRITE setColorTrue )
Q_PROPERTY(Vector4 colorFalse READ colorFalse WRITE setColorFalse)
public:
explicit ScriptSettingsBoolean();
explicit ScriptSettingsBoolean(BooleanWidget *widget);
explicit ScriptSettingsBoolean(const ScriptSettingsBoolean &other);
virtual ~ScriptSettingsBoolean();
const Vector4 colorTrue() const;
const Vector4 colorFalse() const;
public slots:
void setColorTrue (const Vector4 &color);
void setColorFalse(const Vector4 &color);
private:
BooleanWidget *widget_;
};
Q_DECLARE_METATYPE(ScriptSettingsBoolean)
#endif // SCRIPTSETTINGSBOOLEAN_HH
#include "ScriptSettingsDouble.hh"
#include "ACG/Utils/ColorConversion.hh"
ScriptSettingsDouble::ScriptSettingsDouble()
: widget_(nullptr)
{}
ScriptSettingsDouble::ScriptSettingsDouble(
DoubleWidget *widget)
: widget_(widget)
{}
ScriptSettingsDouble::ScriptSettingsDouble(
const ScriptSettingsDouble &other)
: QObject(),
widget_(other.widget_)
{}
ScriptSettingsDouble::~ScriptSettingsDouble()
{}
double ScriptSettingsDouble::rangeMin() const
{
return widget_->doubleFixedRangeMin->value();
}
double ScriptSettingsDouble::rangeMax() const
{
return widget_->doubleFixedRangeMax->value();
}
const Vector4 ScriptSettingsDouble::colorMin() const
{
return ACG::to_Vec4d( widget_->doubleMin->color());
}
const Vector4 ScriptSettingsDouble::colorMax() const
{
return ACG::to_Vec4d( widget_->doubleMax->color());
}
void ScriptSettingsDouble::setColorMin(const Vector4 &color)
{
widget_->doubleMin->setColor(ACG::to_QColor(color));
}
void ScriptSettingsDouble::setColorMax(const Vector4 &color)
{
widget_->doubleMax->setColor(ACG::to_QColor(color));
}
bool ScriptSettingsDouble::useFixedRange() const
{
return widget_->doubleFixedRange->isChecked();
}
bool ScriptSettingsDouble::mapOutsideRange() const
{
return widget_->doubleMapOutsideRange->isChecked();
}
bool ScriptSettingsDouble::absolute() const
{
return widget_->doubleAbsolute->isChecked();
}
void ScriptSettingsDouble::setUseColorCoder(bool useColorCoder)
{
return widget_->doubleColorCoder->setChecked(useColorCoder);
}
void ScriptSettingsDouble::setUseFixedRange(bool useFixedRange)
{
return widget_->doubleFixedRange->setChecked(useFixedRange);
}
void ScriptSettingsDouble::setRangeMin(double val)
{
return widget_->doubleFixedRangeMin->setValue(val);
}
void ScriptSettingsDouble::setRangeMax(double val)
{
return widget_->doubleFixedRangeMax->setValue(val);
}
void ScriptSettingsDouble::setMapOutsideRange(bool mapOutsideRange)
{
return widget_->doubleMapOutsideRange->setChecked(mapOutsideRange);
}
void ScriptSettingsDouble::setAbsolute(bool absolute)
{
return widget_->doubleAbsolute->setChecked(absolute);
}
bool ScriptSettingsDouble::useColorCoder() const
{
return widget_->doubleColorCoder->isChecked();
}
#ifndef SCRIPTSETTINGSDOUBLE_HH
#define SCRIPTSETTINGSDOUBLE_HH
#include <QObject>
#include "Widgets/DoubleWidget.hh"
#include "ACG/Math/VectorT.hh"
#include "OpenFlipper/common/DataTypes.hh"
class ScriptSettingsDouble : public QObject {
Q_OBJECT
// We use Vector4 instead of a proper color type as those are not (yet)
// exposed to the scripting environment.
Q_PROPERTY(bool useColorCoder READ useColorCoder WRITE setUseColorCoder)
Q_PROPERTY(Vector4 colorMin READ colorMin WRITE setColorMin)
Q_PROPERTY(Vector4 colorMax READ colorMax WRITE setColorMax)
Q_PROPERTY(bool useFixedRange READ useFixedRange WRITE setUseFixedRange)
Q_PROPERTY(double rangeMin READ rangeMin WRITE setRangeMin)
Q_PROPERTY(double rangeMax READ rangeMax WRITE setRangeMax)
Q_PROPERTY(bool mapOutsideRange READ mapOutsideRange WRITE setMapOutsideRange)
Q_PROPERTY(bool absolute READ absolute WRITE setAbsolute)
public:
explicit ScriptSettingsDouble();
explicit ScriptSettingsDouble(DoubleWidget *widget);
explicit ScriptSettingsDouble(const ScriptSettingsDouble &other);
virtual ~ScriptSettingsDouble();
bool useColorCoder() const;
const Vector4 colorMin() const;
const Vector4 colorMax() const;
bool useFixedRange() const;
double rangeMin() const;
double rangeMax() const;
bool mapOutsideRange() const;
bool absolute() const;
public slots:
void setUseColorCoder(bool useColorCoder);
void setColorMin(const Vector4 &color);
void setColorMax(const Vector4 &color);
void setUseFixedRange(bool useFixedRange);
void setRangeMin(double val);
void setRangeMax(double val);
void setMapOutsideRange(bool mapOutsideRange);
void setAbsolute(bool absolute);
private:
DoubleWidget *widget_;
};
Q_DECLARE_METATYPE(ScriptSettingsDouble)
#endif // SCRIPTSETTINGSDOUBLE_HH
......@@ -48,6 +48,7 @@
\*===========================================================================*/
#include "SingleObjectPropertyModel.hh"
#include "ScriptObjects/ScriptObject.hh"
SingleObjectPropertyModel::SingleObjectPropertyModel(QObject *parent)
: PropertyModel(parent),
......@@ -377,5 +378,11 @@ bool SingleObjectPropertyModel::isPropertyFree(QString propName, PropertyInfo::E
PropertyInfo SingleObjectPropertyModel::getPropertyInfo(const QModelIndex index) const
{
return propertyVisualizers[index.row()]->getPropertyInfo();
return propertyVisualizers[index.row()]->getPropertyInfo();
}
QScriptValue SingleObjectPropertyModel::getScriptObject(const QModelIndex index, QScriptContext *ctx)
{
PropertyVisualizer* vis = propertyVisualizers[index.row()];
return createSettingsScriptObject(ctx, vis->getWidget());
}
......@@ -63,6 +63,8 @@
#include <typeinfo>
#include <QPushButton>
#include <QScriptValue>
#include <QScriptContext>
#include <Widgets/VectorWidget.hh>
......@@ -130,8 +132,11 @@ public:
/// Connects the PropertyVisualizer log signals with the log slot.
void connectLogs(PropertyVisualizer* propViz);
/// Returns the property info for the property with the given index.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const;
/// Returns the property info for the property with the given index.
virtual PropertyInfo getPropertyInfo(const QModelIndex index) const;
/// Returns a qscript object that can be used to access visualisation parameters
virtual QScriptValue getScriptObject(const QModelIndex index, QScriptContext *ctx);
protected:
......
Markdown is supported
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