]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Python API and example plugin are corrected to perform basic actions without crashes
authorSergey BELASH <belash.sergey@opencascade.com>
Mon, 17 Nov 2014 12:33:28 +0000 (15:33 +0300)
committerSergey BELASH <belash.sergey@opencascade.com>
Mon, 17 Nov 2014 12:33:28 +0000 (15:33 +0300)
src/ConstructionPlugin/ConstructionPlugin_Plugin.h
src/ExchangePlugin/ExchangePlugin_Plugin.h
src/FeaturesPlugin/FeaturesPlugin_Plugin.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/PartSetPlugin/PartSetPlugin_Plugin.h
src/PythonFeaturesPlugin/PythonFeaturesPlugin.py
src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py
src/SketchPlugin/SketchPlugin_Plugin.h

index 143b786e55d931542e4350dd2b0ab72753680755..79f48abe5cd6e375891d1b573ed9565d1c9c5e6d 100644 (file)
@@ -16,7 +16,6 @@ class CONSTRUCTIONPLUGIN_EXPORT ConstructionPlugin_Plugin : public ModelAPI_Plug
   virtual FeaturePtr createFeature(std::string theFeatureID);
 
  public:
-  /// Is needed for python wrapping by swig
   ConstructionPlugin_Plugin();
 };
 
index 5cb5f20f0ac5793fea1fb08f9703f4f2f70d4fe9..d614028f1296f5b8ea3eca822af3fea11dbcc8a1 100644 (file)
@@ -16,7 +16,6 @@ class EXCHANGEPLUGIN_EXPORT ExchangePlugin_Plugin : public ModelAPI_Plugin
   virtual FeaturePtr createFeature(std::string theFeatureID);
 
  public:
-  /// Is needed for python wrapping by swig
   ExchangePlugin_Plugin();
 };
 
index 560a2242a88e73a25f8747e802a716ac2029be75..e56ac83ea77c79afc93639bfa4a2af8c994c871b 100644 (file)
@@ -16,7 +16,6 @@ class FEATURESPLUGIN_EXPORT FeaturesPlugin_Plugin : public ModelAPI_Plugin
   virtual FeaturePtr createFeature(std::string theFeatureID);
 
  public:
-  /// Is needed for python wrapping by swig
   FeaturesPlugin_Plugin();
 };
 
index 8dff4fb3ff564001a1272210c1950f09a6028002..54c0b472d50b63e5ab420220f97435c5950fbb76 100644 (file)
@@ -47,7 +47,9 @@ SET(PROJECT_LIBRARIES
     Config
 )
 
-ADD_DEFINITIONS(-DMODELAPI_EXPORTS)
+SET(CMAKE_SWIG_FLAGS "-Wall")
+ADD_DEFINITIONS(-DMODELAPI_EXPORTS -DSWIG_TYPE_TABLE=ModelAPI)
+
 ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX)
 TARGET_LINK_LIBRARIES(ModelAPI ${PROJECT_LIBRARIES})
@@ -59,7 +61,6 @@ INCLUDE_DIRECTORIES(
   ../GeomAlgoAPI
 )
 
-SET(CMAKE_SWIG_FLAGS "-Wall")
 
 SET_SOURCE_FILES_PROPERTIES(ModelAPI.i PROPERTIES CPLUSPLUS ON)
 # "-includeall" is not needed: it starts to follow the standard inludes (like "string") without success
index 711c77aacf038b46394428768ea01ca433590f0b..4d0ebb256d4a17aeb7179ec0f092ca6c26dd41e5 100644 (file)
@@ -1,5 +1,13 @@
 /* ModelAPI.i */
 %module(directors="1") ModelAPI
+%feature("director:except") {
+    if ($error != NULL) {
+      PyErr_Print();
+      std::cerr << std::endl;
+      throw Swig::DirectorMethodException();
+    }
+}
+
 %{
   #include "GeomAPI_Interface.h"
   #include "GeomAPI_Shape.h"
 
 // directors
 %feature("director") ModelAPI_Plugin;
-// %feature("director") ModelAPI_Object;
-// %feature("director") ModelAPI_Feature;
-// %feature("director") ModelAPI_CompositeFeature;
+%feature("director") ModelAPI_Object;
+%feature("director") ModelAPI_Feature;
 
 // boost pointers
-%include <boost_shared_ptr.i>
+%include "boost_shared_ptr.i"
 // For ModelAPI_ResultConstruction.shape()
 %shared_ptr(GeomAPI_Interface)
 %shared_ptr(GeomAPI_Shape)
 %shared_ptr(ModelAPI_Document)
 %shared_ptr(ModelAPI_Session)
+%shared_ptr(ModelAPI_Plugin)
 %shared_ptr(ModelAPI_Object)
-// %shared_ptr(ModelAPI_Plugin)
 %shared_ptr(ModelAPI_Feature)
 %shared_ptr(ModelAPI_CompositeFeature)
 %shared_ptr(ModelAPI_Data)
 %shared_ptr(ModelAPI_ResultBody)
 %shared_ptr(ModelAPI_ResultPart)
 
+// Don't create default constructors
+// %nodefaultctor ModelAPI_Plugin;
+// %nodefaultctor ModelAPI_Session;
+
 // all supported interfaces
 %include "GeomAPI_Interface.h"
 %include "GeomAPI_Shape.h"
 %include "ModelAPI_Document.h"
 %include "ModelAPI_Session.h"
-%include "ModelAPI_Object.h"
-// %nodefaultctor ModelAPI_Plugin;
 %include "ModelAPI_Plugin.h"
+%include "ModelAPI_Object.h"
 %include "ModelAPI_Feature.h"
 %include "ModelAPI_CompositeFeature.h"
 %include "ModelAPI_Data.h"
 %template(ResultList) std::list<boost::shared_ptr<ModelAPI_Result> >;
 
 template<class T1, class T2> boost::shared_ptr<T1> boost_cast(boost::shared_ptr<T2> theObject);
+
+// Feature casts
+%template(modelAPI_Feature)          boost_cast<ModelAPI_Feature, ModelAPI_Object>;
 %template(modelAPI_CompositeFeature) boost_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
-%template(modelAPI_ResultConstruction) boost_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
-%template(modelAPI_ResultBody) boost_cast<ModelAPI_ResultBody, ModelAPI_Result>;
-%template(modelAPI_ResultPart) boost_cast<ModelAPI_ResultPart, ModelAPI_Result>;
 
+// Result casts
+%template(modelAPI_ResultConstruction) boost_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
+%template(modelAPI_ResultBody)         boost_cast<ModelAPI_ResultBody, ModelAPI_Result>;
+%template(modelAPI_ResultPart)         boost_cast<ModelAPI_ResultPart, ModelAPI_Result>;
 
+// Attribute casts
+%template(modelAPI_AttributeDocRef)        boost_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;
+%template(modelAPI_AttributeDouble)        boost_cast<ModelAPI_AttributeDouble, ModelAPI_Attribute>;
+%template(modelAPI_AttributeInteger)       boost_cast<ModelAPI_AttributeInteger, ModelAPI_Attribute>;
+%template(modelAPI_AttributeString)        boost_cast<ModelAPI_AttributeString, ModelAPI_Attribute>;
+%template(modelAPI_AttributeReference)     boost_cast<ModelAPI_AttributeReference, ModelAPI_Attribute>;
+%template(modelAPI_AttributeRefAttr)       boost_cast<ModelAPI_AttributeRefAttr, ModelAPI_Attribute>;
+%template(modelAPI_AttributeBoolean)       boost_cast<ModelAPI_AttributeBoolean, ModelAPI_Attribute>;
+%template(modelAPI_AttributeSelection)     boost_cast<ModelAPI_AttributeSelection, ModelAPI_Attribute>;
+%template(modelAPI_AttributeSelectionList) boost_cast<ModelAPI_AttributeSelectionList, ModelAPI_Attribute>;
+%template(modelAPI_AttributeRefList)       boost_cast<ModelAPI_AttributeRefList, ModelAPI_Attribute>;
index e8e9e702b405575131d7604756660c5b2052972e..5d91f7d46fb0b44cbcf183ed501ba6950d6b44ab 100644 (file)
@@ -16,7 +16,6 @@ class PARTSETPLUGIN_EXPORT PartSetPlugin_Plugin : public ModelAPI_Plugin
   virtual FeaturePtr createFeature(std::string theFeatureID);
 
  public:
-  /// Is needed for python wrapping by swig
   PartSetPlugin_Plugin();
 };
 
index dc4219d11d91cf038268998b30f87653127fa066..4795eaf033032519414191338b30199cc52af178 100644 (file)
@@ -9,7 +9,7 @@ class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin):
 
   def createFeature(self, theFeatureID):
     if theFeatureID == PythonFeaturesPlugin_Box.ID():
-      return PythonFeaturesPlugin_Box()
+      return PythonFeaturesPlugin_Box().__disown__()
     else:
       raise StandardError("No such feature %s"%theFeatureID)
 
index e67278b2204b68547fdc441482813d312fe52b9b..b08f98b412d439c9a3885f88167fdb589b719bb7 100644 (file)
@@ -1,9 +1,9 @@
-from ModelAPI import *
+import ModelAPI
 
-class PythonFeaturesPlugin_Box(ModelAPI_Feature):
+class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
   "Feature to create a box by drawing a sketch and extruding it"
   def __init__(self):
-    pass
+    ModelAPI.ModelAPI_Feature.__init__(self)
 
   @staticmethod
   def ID():
@@ -21,20 +21,24 @@ class PythonFeaturesPlugin_Box(ModelAPI_Feature):
   def HEIGHT_ID():
     return "box_height"
 
+  def getKind(self):
+    return PythonFeaturesPlugin_Box.ID()
+
   def initAttributes(self):
-    self.data().addAttribute(PythonFeaturesPlugin_Box.WIDTH_ID(), ModelAPI_AttributeDouble.type())
-    self.data().addAttribute(PythonFeaturesPlugin_Box.LENGTH_ID(), ModelAPI_AttributeDouble.type())
-    self.data().addAttribute(PythonFeaturesPlugin_Box.HEIGHT_ID(), ModelAPI_AttributeDouble.type())
+    # C++ static methods (in example Type() of ModelAPI_AttributeDouble
+    # should be called like this: moduleName.ClassName_StaticMethod()
+    self.data().addAttribute(PythonFeaturesPlugin_Box.WIDTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+    self.data().addAttribute(PythonFeaturesPlugin_Box.LENGTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+    self.data().addAttribute(PythonFeaturesPlugin_Box.HEIGHT_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
 
   def execute(self):
-    aWidth  = self.attribute(PythonFeaturesPlugin_Box.WIDTH_ID()).value()
-    aLength = self.attribute(PythonFeaturesPlugin_Box.LENGTH_ID()).value()
-    aHeight = self.attribute(PythonFeaturesPlugin_Box.HEIGHT_ID()).value()
-
-    aResult = document().createBody(data())
-    #aResult.store(UserPackage.makeBox(aLength, aWidth, aHeight)
-
-    #self.setResult(aResult)
+    aWidth  = self.real(PythonFeaturesPlugin_Box.WIDTH_ID()).value()
+    aLength = self.real(PythonFeaturesPlugin_Box.LENGTH_ID()).value()
+    aHeight = self.real(PythonFeaturesPlugin_Box.HEIGHT_ID()).value()
+    print ("Box W:{0} L:{1} H:{2}".format(aWidth, aLength, aHeight))
+    # aResult = document().createBody(data())
+    # aResult.store(UserPackage.makeBox(aLength, aWidth, aHeight)
+    # self.setResult(aResult)
 
 
     
index bb81ba781212d882e113cd32646eda725832af99..3b480410b8b169b23ccdbddfb98faf7455e59dc6 100644 (file)
@@ -16,7 +16,6 @@ class SKETCHPLUGIN_EXPORT SketchPlugin_Plugin : public ModelAPI_Plugin
   virtual FeaturePtr createFeature(std::string theFeatureID);
 
  public:
-  /// Is needed for python wrapping by swig
   SketchPlugin_Plugin();
 };