From: Sergey BELASH Date: Wed, 29 Oct 2014 14:54:02 +0000 (+0300) Subject: Patch by Renaud: a test plugin written in python X-Git-Tag: V_0.7.0_rc1~57^2~3^2~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=355e36702c9bdfc5316e9dc86a4eaf4a1e004be2;p=modules%2Fshaper.git Patch by Renaud: a test plugin written in python --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ac61b73e9..116d25f5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ ADD_SUBDIRECTORY (src/GeomDataAPI) ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) ADD_SUBDIRECTORY (src/FeaturesPlugin) +ADD_SUBDIRECTORY (src/PythonFeaturesPlugin) ADD_SUBDIRECTORY (src/SketchPlugin) ADD_SUBDIRECTORY (src/SketchSolver) ADD_SUBDIRECTORY (src/ModuleBase) diff --git a/linux_env.sh b/linux_env.sh index f6bdf5dce..becdc6db6 100644 --- a/linux_env.sh +++ b/linux_env.sh @@ -37,7 +37,7 @@ export PATH=${CASROOT}:${PATH} #------ NewGEOM ------ export NEW_GEOM_ROOT_DIR=${ROOT_DIR}/install export PATH=${NEW_GEOM_ROOT_DIR}/bin:${NEW_GEOM_ROOT_DIR}/plugins:${PATH} -export PYTHONPATH=${NEW_GEOM_ROOT_DIR}/swig:${PYTHONPATH} +export PYTHONPATH=${NEW_GEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${PYTHONPATH} export LD_LIBRARY_PATH=${NEW_GEOM_ROOT_DIR}/bin:${NEW_GEOM_ROOT_DIR}/swig:${NEW_GEOM_ROOT_DIR}/plugins:${LD_LIBRARY_PATH} export NEW_GEOM_CONFIG_FILE=${NEW_GEOM_ROOT_DIR}/plugins export NewGeomResources=${NEW_GEOM_ROOT_DIR}/resources diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml index 396f565a9..9ae5ca51f 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml @@ -3,6 +3,7 @@ + diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 024b9593b..cfdbb2818 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -4,7 +4,7 @@ SET(PROJECT_HEADERS FeaturesPlugin.h FeaturesPlugin_Plugin.h FeaturesPlugin_Extrusion.h - FeaturesPlugin_Boolean.h + FeaturesPlugin_Boolean.h ) SET(PROJECT_SOURCES diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index e63c97cab..26c337e52 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -21,6 +21,9 @@ #include #include +// TEST +#include + using namespace std; static Model_Session* myImpl = new Model_Session(); @@ -91,8 +94,9 @@ void Model_Session::redo() FeaturePtr Model_Session::createFeature(string theFeatureID) { - if (this != myImpl) + if (this != myImpl) { return myImpl->createFeature(theFeatureID); + } LoadPluginsInfo(); if (myPlugins.find(theFeatureID) != myPlugins.end()) { @@ -106,7 +110,14 @@ FeaturePtr Model_Session::createFeature(string theFeatureID) myCurrentPluginName = aPlugin.first; if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) { // load plugin library if not yet done - Config_ModuleReader::loadLibrary(myCurrentPluginName); + //TODO: Get info from Config about python libraries + if (myCurrentPluginName.compare(string("PythonFeaturesPlugin")) == 0) { + Py_Initialize(); + PyObject* module = PyImport_ImportModule(myCurrentPluginName.c_str()); + assert(module != NULL); + } else { + Config_ModuleReader::loadLibrary(myCurrentPluginName); + } } if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) { FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID); diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index a5bb73ebd..65f4b5ae5 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -1,5 +1,5 @@ /* ModelAPI.i */ -%module ModelAPI +%module(directors="1") ModelAPI %{ #include "GeomAPI_Interface.h" #include "GeomAPI_Shape.h" @@ -8,6 +8,7 @@ #include "ModelAPI_Session.h" #include "ModelAPI_Object.h" #include "ModelAPI_Feature.h" + #include "ModelAPI_Plugin.h" #include "ModelAPI_Data.h" #include "ModelAPI_Attribute.h" #include "ModelAPI_AttributeDocRef.h" @@ -49,6 +50,7 @@ %shared_ptr(ModelAPI_Document) %shared_ptr(ModelAPI_Session) %shared_ptr(ModelAPI_Object) +// %shared_ptr(ModelAPI_Plugin) %shared_ptr(ModelAPI_Feature) %shared_ptr(ModelAPI_Data) %shared_ptr(ModelAPI_Attribute) @@ -64,6 +66,7 @@ %shared_ptr(ModelAPI_ResultConstruction) %shared_ptr(ModelAPI_ResultBody) %shared_ptr(ModelAPI_ResultPart) +%feature("director") ModelAPI_Plugin; // all supported interfaces %include "GeomAPI_Interface.h" @@ -71,6 +74,7 @@ %include "ModelAPI_Document.h" %include "ModelAPI_Session.h" %include "ModelAPI_Object.h" +%include "ModelAPI_Plugin.h" %include "ModelAPI_Feature.h" %include "ModelAPI_Data.h" %include "ModelAPI_Attribute.h" diff --git a/src/PythonFeaturesPlugin/CMakeLists.txt b/src/PythonFeaturesPlugin/CMakeLists.txt new file mode 100644 index 000000000..bbfe436ea --- /dev/null +++ b/src/PythonFeaturesPlugin/CMakeLists.txt @@ -0,0 +1,13 @@ +INCLUDE(Common) + +SET(PYTHON_FILES + PythonFeaturesPlugin_Box.py + PythonFeaturesPlugin.py +) + +SET(XML_RESSOURCES + plugin-PythonFeatures.xml + box_widget.xml +) + +INSTALL(FILES ${PYTHON_FILES} ${XML_RESSOURCES} DESTINATION plugins) diff --git a/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py b/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py new file mode 100644 index 000000000..e7a280805 --- /dev/null +++ b/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py @@ -0,0 +1,17 @@ +from ModelAPI import * +import PythonFeaturesPlugin_Box + +class PythonFeaturesPlugin(ModelAPI_Plugin): + def __init__(self): + ModelAPI_Plugin.__init__(self) + pass + + def createFeature(self, theFeatureID): + if theFeatureID == PythonFeaturesPlugin_Box.ID(): + return PythonFeaturesPlugin_Box() + else: + raise StandardError("No such feature %s"%theFeatureID) + +plugin = PythonFeaturesPlugin() +ModelAPI_Session_get().registerPlugin(plugin) + diff --git a/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py b/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py new file mode 100644 index 000000000..800fbbeb8 --- /dev/null +++ b/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py @@ -0,0 +1,38 @@ +from ModelAPI import * + +class PythonFeaturesPlugin_Box(ModelAPI_Feature): + "Feature to create a box by drawing a sketch and extruding it" + def __init__(self): + pass + + def ID(self): + return "Box" + + def WIDTH_ID(self): + return "box_width" + + def LENGTH_ID(self): + return "box_length" + + def HEIGHT_ID(self): + return "box_height" + + def initAttributes(self): + self.data().addAttribute(self.WIDTH_ID(), ModelAPI_AttributeDouble.type()) + self.data().addAttribute(self.LENGTH_ID(), ModelAPI_AttributeDouble.type()) + self.data().addAttribute(self.HEIGHT_ID(), ModelAPI_AttributeDouble.type()) + + def execute(self): + aWidth = self.data().attribute(self.WIDTH_ID()).value() + aLength = self.data().attribute(self.LENGTH_ID()).value() + aHeight = self.data().attribute(self.HEIGHT_ID()).value() + + aResult = document().createBody(data()) + #aResult.store(UserPackage.makeBox(aLength, aWidth, aHeight) + + #self.setResult(aResult) + + + + + diff --git a/src/PythonFeaturesPlugin/box_widget.xml b/src/PythonFeaturesPlugin/box_widget.xml new file mode 100644 index 000000000..f35231580 --- /dev/null +++ b/src/PythonFeaturesPlugin/box_widget.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml b/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml new file mode 100644 index 000000000..679cd22aa --- /dev/null +++ b/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml @@ -0,0 +1,9 @@ + + + + + + + + +