Commit 3f5c197c authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'python-support' into 'master'

The VSI Plugin now works with python instead of qtscript

See merge request !4
parents 30fd0665 d2a5d594
include (plugin)
openflipper_plugin (DIRS config parser scene types types/objectId INSTALLDATA Icons VsiMetadata)
openflipper_plugin (PYTHONINTERFACE
DIRS config parser scene types types/objectId
INSTALLDATA Icons VsiMetadata)
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#include <pybind11/include/pybind11/pybind11.h>
#include <pybind11/include/pybind11/embed.h>
#include <vsiPlugin.hh>
#include <OpenFlipper/BasePlugin/PythonFunctions.hh>
#include <OpenFlipper/PythonInterpreter/PythonTypeConversions.hh>
namespace py = pybind11;
PYBIND11_EMBEDDED_MODULE(VisualScripting, m) {
QObject* pluginPointer = getPluginPointer("VisualScripting");
if (!pluginPointer) {
std::cerr << "Error Getting plugin pointer for Plugin-VSI" << std::endl;
return;
}
VsiPlugin* plugin = qobject_cast<VsiPlugin*>(pluginPointer);
if (!plugin) {
std::cerr << "Error converting plugin pointer for Plugin-VSI" << std::endl;
return;
}
// Export our core. Make sure that the c++ worlds core object is not deleted if
// the python side gets deleted!!
py::class_< VsiPlugin,std::unique_ptr<VsiPlugin, py::nodelete> > vsi(m, "VisualScripting");
// On the c++ side we will just return the existing core instance
// and prevent the system to recreate a new core as we need
// to work on the existing one.
vsi.def(py::init([plugin]() { return plugin; }));
vsi.def("askForInputs", &VsiPlugin::askForInputs,
QCoreApplication::translate("PythonDocVsi","Shows a popup and asks for inputs").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocVsi","Element").toLatin1().data()),
py::arg(QCoreApplication::translate("PythonDocVsi","Inputs").toLatin1().data()));
vsi.def("messageBox", &VsiPlugin::messageBox,
QCoreApplication::translate("PythonDocVsi","Shows a popup with text").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocVsi","text to display").toLatin1().data()));
vsi.def("questionBox", &VsiPlugin::questionBox,
QCoreApplication::translate("PythonDocVsi","Shows a question box with text").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocVsi","text to display").toLatin1().data()));
vsi.def("continueBox", &VsiPlugin::continueBox,
QCoreApplication::translate("PythonDocVsi","Shows a continue box with text").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocVsi","text to display").toLatin1().data()));
}
......@@ -55,10 +55,10 @@
</input>
</inputs>
<code>
if ([input="visible"])
datacontrol.showObject([input="obj"]);
else
datacontrol.hideObject([input="obj"]);
if ([input="visible"]):
datacontrol.showObject([input="obj"]);
else:
datacontrol.hideObject([input="obj"]);
</code>
</element>
<element name="datacontrol_objectdelete">
......@@ -73,7 +73,7 @@
</input>
</inputs>
<code>
datacontrol.objectDelete([input="obj"]);
datacontrol.objectDelete([input="obj"]);
</code>
</element>
<element name="datacontrol_objectcopy">
......
......@@ -79,36 +79,34 @@
<short>Independent Sets</short>
</input>
</inputs>
<precode>
var decimater_constraints
</precode>
<code>
decimater_constraints = new Object ();
if ([is_set="decimation_order"])
decimater_constraints["decimation_order"] = [input="decimation_order"];
if ([is_set="decimater_type"])
decimater_constraints["decimater_type"] = [input="decimater_type"];
if ([is_set="random_samples"])
decimater_constraints["random_samples"] = [input="random_samples"];
if ([is_set="incremental_percentage"])
decimater_constraints["incremental_percentage"] = [input="incremental_percentage"];
if ([is_set="vertices"])
decimater_constraints["vertices"] = [input="vertices"];
if ([is_set="triangles"])
decimater_constraints["triangles"] = [input="triangles"];
if ([is_set="distance"])
decimater_constraints["distance"] = [input="distance"];
if ([is_set="edge_length"])
decimater_constraints["edge_length"] = [input="edge_length"];
if ([is_set="normal_deviation"])
decimater_constraints["normal_deviation"] = [input="normal_deviation"];
if ([is_set="roundness"])
decimater_constraints["roundness"] = [input="roundness"];
if ([is_set="aspect_ratio"])
decimater_constraints["aspect_ratio"] = [input="aspect_ratio"];
if ([is_set="independent_sets"])
decimater_constraints["independent_sets"] = [input="independent_sets"];
decimater.decimate ([input="obj"],decimater_constraints);
decimater_constraints = "";
if ([is_set="decimation_order"]):
decimater_constraints = decimater_constraints + ";decimater_order=" + str([input="decimation_order"]);
if ([is_set="decimater_type"]):
decimater_constraints = decimater_constraints + ";decimater_type=" + str([input="decimater_type"]);
if ([is_set="random_samples"]):
decimater_constraints = decimater_constraints + ";random_samples=" + str([input="random_samples"]);
if ([is_set="incremental_percentage"]):
decimater_constraints = decimater_constraints + ";incremental_percentage=" + str([input="incremental_percentage"]);
if ([is_set="vertices"]):
decimater_constraints = decimater_constraints + ";vertices=" + str([input="vertices"]);
if ([is_set="triangles"]):
decimater_constraints = decimater_constraints + ";triangles=" + str([input="triangles"]);
if ([is_set="distance"]):
decimater_constraints = decimater_constraints + ";distance=" + str([input="distance"]);
if ([is_set="edge_length"]):
decimater_constraints = decimater_constraints + ";edge_length=" + str([input="edge_length"]);
if ([is_set="normal_deviation"]):
decimater_constraints = decimater_constraints + ";normal_deviation=" + str([input="normal_deviation"]);
if ([is_set="roundness"]):
decimater_constraints = decimater_constraints + ";roundness=" + str([input="roundness"]);
if ([is_set="aspect_ratio"]):
decimater_constraints = decimater_constraints + ";aspect_ratio=" + str([input="aspect_ratio"]);
if ([is_set="independent_sets"]):
decimater_constraints = decimater_constraints + ";independent_sets=" + str([input="independent_sets"]);
decimater.decimate ([input="obj"],decimater_constraints[1:]);
</code>
</element>
</OpenFlipper>
\ No newline at end of file
......@@ -25,11 +25,11 @@
</input>
</inputs>
<code>
var message = [input="message"];
message = [input="message"];
message = message.replace(/\$1/g, [input="in1"]);
message = message.replace(/\$2/g, [input="in2"]);
message = message.replace(/\$3/g, [input="in3"]);
message = message.replace("$1", str([input="in1"]));
message = message.replace("$2", str([input="in2"]));
message = message.replace("$3", str([input="in3"]));
visualscripting.messageBox (message);
</code>
......@@ -89,11 +89,11 @@
</output>
</outputs>
<code>
var message = [input="message"];
message = [input="message"];
message = message.replace(/\$1/g, [input="in1"]);
message = message.replace(/\$2/g, [input="in2"]);
message = message.replace(/\$3/g, [input="in3"]);
message = message.replace("$1", str([input="in1"]));
message = message.replace("$2", str([input="in2"]));
message = message.replace("$3", str([input="in3"]));
[output="ret"] = visualscripting.questionBox (message);
</code>
......@@ -136,7 +136,7 @@
</output>
</outputs>
<code>
var dialog_stop_box_message = [input="message"];
dialog_stop_box_message = [input="message"];
[output="continue"] = visualscripting.continueBox(dialog_stop_box_message);
</code>
......
......@@ -33,15 +33,15 @@
</output>
</outputs>
<code>
if ([is_connected="nVert"])
if ([is_connected="nVert"]):
[output="nVert"] = infomeshobject.vertexCount([input="obj"]);
if ([is_connected="nEdge"])
if ([is_connected="nEdge"]):
[output="nEdge"] = infomeshobject.edgeCount([input="obj"]);
if ([is_connected="nFace"])
if ([is_connected="nFace"]):
[output="nFace"] = infomeshobject.faceCount([input="obj"]);
if ([is_connected="nBound"])
if ([is_connected="nBound"]):
[output="nBound"] = infomeshobject.boundaryCount([input="obj"]);
if ([is_connected="nComp"])
if ([is_connected="nComp"]):
[output="nComp"] = infomeshobject.componentCount([input="obj"]);
</code>
</element>
......@@ -72,11 +72,11 @@
</output>
</outputs>
<code>
if ([is_connected="minEdgeLength"])
if ([is_connected="minEdgeLength"]):
[output="minEdgeLength"] = infomeshobject.minEdgeLength([input="obj"]);
if ([is_connected="maxEdgeLength"])
if ([is_connected="maxEdgeLength"]):
[output="maxEdgeLength"] = infomeshobject.maxEdgeLength([input="obj"]);
if ([is_connected="meanEdgeLength"])
if ([is_connected="meanEdgeLength"]):
[output="meanEdgeLength"] = infomeshobject.meanEdgeLength([input="obj"]);
</code>
</element>
......@@ -111,13 +111,13 @@
</output>
</outputs>
<code>
if ([is_connected="min"])
if ([is_connected="min"]):
[output="min"] = infomeshobject.boundingBoxMin([input="obj"]);
if ([is_connected="max"])
if ([is_connected="max"]):
[output="max"] = infomeshobject.boundingBoxMax([input="obj"]);
if ([is_connected="size"])
if ([is_connected="size"]):
[output="size"] = infomeshobject.boundingBoxSize([input="obj"]);
if ([is_connected="cog"])
if ([is_connected="cog"]):
[output="cog"] = infomeshobject.cog([input="obj"]);
</code>
</element>
......
......@@ -18,7 +18,7 @@
</function>
</functions>
<code>
while ([function="condition"]().out)
while ([function="condition"]()["out"]):
[function="content"]();
</code>
</element>
......@@ -42,9 +42,9 @@
</function>
</functions>
<code>
if ([input="condition"])
if ([input="condition"]):
[function="true"]();
else
else:
[function="false"]();
</code>
</element>
......
......@@ -32,16 +32,16 @@
</output>
</outputs>
<code>
if ([is_connected="add"])
[output="add"] = Number([input="a"]) + Number([input="b"]);
if ([is_connected="sub"])
if ([is_connected="add"]):
[output="add"] = [input="a"] + [input="b"];
if ([is_connected="sub"]):
[output="sub"] = [input="a"] - [input="b"];
if ([is_connected="mul"])
if ([is_connected="mul"]):
[output="mul"] = [input="a"] * [input="b"];
if ([is_connected="div"])
if ([is_connected="div"]):
[output="div"] = [input="a"] / [input="b"];
if ([is_connected="pow"])
[output="pow"] = Math.pow ([input="a"],[input="b"]);
if ([is_connected="pow"]):
[output="pow"] = pow ([input="a"], [input="b"]);
</code>
</element>
<element name="minmax">
......@@ -69,10 +69,10 @@
</output>
</outputs>
<code>
if ([is_connected="min"])
[output="min"] = Math.min ([input="a"], [input="b"]);
if ([is_connected="max"])
[output="max"] = Math.max ([input="a"], [input="b"]);
if ([is_connected="min"]):
[output="min"] = min ([input="a"], [input="b"]);
if ([is_connected="max"]):
[output="max"] = max ([input="a"], [input="b"]);
</code>
</element>
<element name="round">
......@@ -103,15 +103,18 @@
<long>Returns the smallest integer greater than or equal to X. (round up).</long>
</output>
</outputs>
<precode>
import math
</precode>
<code>
if ([is_connected="abs"])
[output="abs"] = Math.abs ([input="x"]);
if ([is_connected="round"])
[output="round"] = Math.round ([input="x"]);
if ([is_connected="floor"])
[output="floor"] = Math.floor ([input="x"]);
if ([is_connected="ceil"])
[output="ceil"] = Math.ceil ([input="x"]);
if ([is_connected="abs"]):
[output="abs"] = abs ([input="x"]);
if ([is_connected="round"]):
[output="round"] = round ([input="x"]);
if ([is_connected="floor"]):
[output="floor"] = math.floor ([input="x"]);
if ([is_connected="ceil"]):
[output="ceil"] = math.ceil ([input="x"]);
</code>
</element>
<element name="random">
......@@ -124,8 +127,11 @@
<long>Returns a pseudorandom number between 0 and 1.</long>
</output>
</outputs>
<precode>
import random
</precode>
<code>
[output="random"] = Math.random ();
[output="random"] = random.random ();
</code>
</element>
<element name="trig">
......@@ -172,23 +178,26 @@
<long>Converts radians to degrees.</long>
</output>
</outputs>
<precode>
import math
</precode>
<code>
if ([is_connected="sin"])
[output="sin"] = Math.sin([input="x"]);
if ([is_connected="cos"])
[output="cos"] = Math.cos([input="x"]);
if ([is_connected="tan"])
[output="tan"] = Math.tan([input="x"]);
if ([is_connected="asin"])
[output="asin"] = Math.asin([input="x"]);
if ([is_connected="acos"])
[output="acos"] = Math.acos([input="x"]);
if ([is_connected="atan"])
[output="atan"] = Math.atan([input="x"]);
if ([is_connected="deg2rad"])
[output="deg2rad"] = [input="x"] * (Math.PI / 180.0);
if ([is_connected="rad2deg"])
[output="rad2deg"] = [input="x"] * (180.0 / Math.PI);
if ([is_connected="sin"]):
[output="sin"] = math.sin([input="x"]);
if ([is_connected="cos"]):
[output="cos"] = math.cos([input="x"]);
if ([is_connected="tan"]):
[output="tan"] = math.tan([input="x"]);
if ([is_connected="asin"]):
[output="asin"] = math.asin([input="x"]);
if ([is_connected="acos"]):
[output="acos"] = math.acos([input="x"]);
if ([is_connected="atan"]):
[output="atan"] = math.atan([input="x"]);
if ([is_connected="deg2rad"]):
[output="deg2rad"] = [input="x"] * (math.pi / 180.0);
if ([is_connected="rad2deg"]):
[output="rad2deg"] = [input="x"] * (180.0 / math.pi);
</code>
</element>
<element name="logarithm">
......@@ -211,11 +220,14 @@
</output>
</outputs>
<precode>
import math
</precode>
<code>
if ([is_connected="ln"])
[output="ln"] = Math.log([input="x"]);
if ([is_connected="exp"])
[output="exp"] = Math.exp([input="x"]);
if ([is_connected="ln"]):
[output="ln"] = math.log([input="x"]);
if ([is_connected="exp"]):
[output="exp"] = math.exp([input="x"]);
</code>
</element>
......@@ -278,15 +290,27 @@
<long>Square root of 2.</long>
</output>
</outputs>
<precode>
import math
MathConstants = {}
MathConstants["SQRT2"] = math.sqrt(2)
MathConstants["SQRT1_2"] = math.sqrt(0.5)
MathConstants["PI"] = math.pi
MathConstants["LOG10E"] = math.log10(math.e)
MathConstants["LOG2E"] = math.log2(math.e)
MathConstants["LN10"] = math.log(10)
MathConstants["LN2"] = math.log(2)
MathConstants["E"] = math.e
</precode>
<code>
[output="e"] = Math.E;
[output="ln2"] = Math.LN2;
[output="ln10"] = Math.LN10;
[output="log2E"] = Math.LOG2E;
[output="log10E"] = Math.LOG10E;
[output="pi"] = Math.PI;
[output="sqrt1_2"] = Math.SQRT1_2;
[output="sqrt2"] = Math.SQRT2;
[output="e"] = MathConstants["E"];
[output="ln2"] = MathConstants["LN2"];
[output="ln10"] = MathConstants["LN10"];
[output="log2E"] = MathConstants["LOG2E"];
[output="log10E"] = MathConstants["LOG10E"];
[output="pi"] = MathConstants["PI"];
[output="sqrt1_2"] = MathConstants["SQRT1_2"];
[output="sqrt2"] = MathConstants["SQRT2"];
</code>
</element>
......@@ -305,8 +329,8 @@
</output>
</outputs>
<code>
[output="out_true"] = true;
[output="out_false"] = false;
[output="out_true"] = True;
[output="out_false"] = False;
</code>
</element>
......@@ -335,7 +359,7 @@
</input>
</inputs>
<code>
[output="out_vec"] = Vector([input="x"],[input="y"],[input="z"]);
[output="out_vec"] = [[input="x"],[input="y"],[input="z"]];
</code>
</element>
......@@ -368,7 +392,7 @@