]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Patch by Renaud: a test plugin written in python
authorSergey BELASH <belash.sergey@opencascade.com>
Wed, 29 Oct 2014 14:54:02 +0000 (17:54 +0300)
committerSergey BELASH <belash.sergey@opencascade.com>
Wed, 29 Oct 2014 14:54:02 +0000 (17:54 +0300)
CMakeLists.txt
linux_env.sh
src/Config/plugins.xml
src/FeaturesPlugin/CMakeLists.txt
src/Model/Model_Session.cpp
src/ModelAPI/ModelAPI.i
src/PythonFeaturesPlugin/CMakeLists.txt [new file with mode: 0644]
src/PythonFeaturesPlugin/PythonFeaturesPlugin.py [new file with mode: 0644]
src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py [new file with mode: 0644]
src/PythonFeaturesPlugin/box_widget.xml [new file with mode: 0644]
src/PythonFeaturesPlugin/plugin-PythonFeatures.xml [new file with mode: 0644]

index ac61b73e91351b4921c509d6fe95ab9003fbf18f..116d25f5b47946578ffbbd001d8aad19806d50a6 100644 (file)
@@ -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)
index f6bdf5dcecbfab0e09bbe355b1dd50e154061db9..becdc6db68f19fd2b113d7cb19a84b4576338315 100644 (file)
@@ -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
index 396f565a9f20fdf8a5c3f866270fa508a8056e51..9ae5ca51f6a9584d5797ac2e26dc4b8beb658033 100644 (file)
@@ -3,6 +3,7 @@
   <plugin library="SketchPlugin" configuration="plugin-Sketch.xml"/>
   <plugin library="ConstructionPlugin" configuration="plugin-Construction.xml"/>
   <plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
+  <plugin library="PythonFeaturesPlugin" configuration="plugin-PythonFeatures.xml"/>
   <plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
   <plugin library="SketchSolver"/>
   <plugin library="GeomValidators"/>
index 024b9593b35bb7cef050fcffa0f06aa6fc417b06..cfdbb28189202f52cd9b687ddf9a4aa66ddb9f14 100644 (file)
@@ -4,7 +4,7 @@ SET(PROJECT_HEADERS
     FeaturesPlugin.h
     FeaturesPlugin_Plugin.h
     FeaturesPlugin_Extrusion.h
-       FeaturesPlugin_Boolean.h
+    FeaturesPlugin_Boolean.h
 )
 
 SET(PROJECT_SOURCES
index e63c97cabb2a1cb06744d8f8d8b5307a0be294c7..26c337e525de8663d092c2045aaf7244af06cc54 100644 (file)
@@ -21,6 +21,9 @@
 #include <TDF_RelocationTable.hxx>
 #include <TDF_ClosureTool.hxx>
 
+// TEST
+#include <Python.h>
+
 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);
index a5bb73ebd96102e84d687941a16517edbd75e7f2..65f4b5ae539250b7bf024f5a34c75711a337f4d2 100644 (file)
@@ -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 (file)
index 0000000..bbfe436
--- /dev/null
@@ -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 (file)
index 0000000..e7a2808
--- /dev/null
@@ -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 (file)
index 0000000..800fbbe
--- /dev/null
@@ -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 (file)
index 0000000..f352315
--- /dev/null
@@ -0,0 +1,11 @@
+<source>
+  <doublevalue id="box_width" label="Width" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set width of the box">
+    <validator id="GeomValidators_Positive"/>
+  </doublevalue>
+  <doublevalue id="box_length" label="Length" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set length of the box">
+    <validator id="GeomValidators_Positive"/>
+  </doublevalue>
+  <doublevalue id="box_height" label="Height" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set height of the box">
+    <validator id="GeomValidators_Positive"/>
+  </doublevalue>
+</source>
diff --git a/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml b/src/PythonFeaturesPlugin/plugin-PythonFeatures.xml
new file mode 100644 (file)
index 0000000..679cd22
--- /dev/null
@@ -0,0 +1,9 @@
+<plugin>
+  <workbench id="Features" document="Part">
+    <group id="Basic">
+      <feature id="Box" title="Box" tooltip="Create a box" icon="">
+          <source path="box_widget.xml"/>
+      </feature>
+    </group>
+  </workbench>  
+</plugin>