]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Resolve cast and import errors in Box.py BR_PYTHON_PLUGIN
authorsbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 09:02:37 +0000 (12:02 +0300)
committersbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 09:02:37 +0000 (12:02 +0300)
src/Config/Config_ModuleReader.cpp
src/ModelAPI/ModelAPI.i
src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py

index 27a03156c95d0f55abd2fad3ff2469acf590b93d..0cfe432467368dcaa718c57bd889eaea81eccbab 100644 (file)
@@ -134,13 +134,12 @@ void Config_ModuleReader::loadPlugin(const std::string thePluginName)
 
 void Config_ModuleReader::loadScript(const std::string theFileName)
 {
-  std::string aPythonFile = theFileName + ".py";
   /* aquire python thread */
   PyGILState_STATE gstate = PyGILState_Ensure();
-  PyObject* module = PyImport_ImportModule(aPythonFile.c_str());
+  PyObject* module = PyImport_ImportModule(theFileName.c_str());
 
   if (!module) {
-    std::string anErrorMsg = "An error occured while loading " + aPythonFile;
+    std::string anErrorMsg = "An error occured while importing " + theFileName;
     //Get detailed error message:
     if (PyErr_Occurred()) {
       PyObject *ptype, *pvalue, *ptraceback;
index 5043bcfe13d17a8d232191b42989f6be83e3cabd..5c97aeb4cbab2f1931fa902a411d4eba68f7b1b6 100644 (file)
@@ -135,6 +135,7 @@ template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr
 %template(modelAPI_CompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
 %template(modelAPI_Feature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
 // Result casts
+%template(modelAPI_Result) shared_ptr_cast<ModelAPI_Result, ModelAPI_Object>;
 %template(modelAPI_ResultConstruction) shared_ptr_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
 %template(modelAPI_ResultBody) shared_ptr_cast<ModelAPI_ResultBody, ModelAPI_Result>;
 %template(modelAPI_ResultPart) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_Result>;
index d08cf3d95c67e787f5bb8c9fc447da94db972db0..b150690dedec1cf5250100e98a2f531de59575d5 100644 (file)
@@ -62,20 +62,23 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
         aWidth = self.real(self.WIDTH_ID()).value()
         aLength = self.real(self.LENGTH_ID()).value()
         aHeight = self.real(self.HEIGHT_ID()).value()
-        aHeightFeature = None
-        aHeightFeatureResult = ModelAPI.modelAPI_ResultBody(self.reference(self.HEIGHT_REF_ID()).value())
-        if aHeightFeatureResult is not None:
-            aHeightFeature = aHeightFeatureResult.document().feature(aHeightFeatureResult)
-        aWidthFeature = ModelAPI.modelAPI_Feature(self.reference(self.WIDTH_REF_ID()).value())
-        aLengthFeature = ModelAPI.modelAPI_Feature(self.reference(self.LENGTH_REF_ID()).value())
+        aWidthRefValue = self.reference(self.WIDTH_REF_ID()).value()
+        aLengthRefValue = self.reference(self.LENGTH_REF_ID()).value()
+        aHeightRefValue = self.reference(self.HEIGHT_REF_ID()).value()
         aResult = None
-        if not all((aWidthFeature, aLengthFeature, aLengthFeature)):
+        if not all((aWidthRefValue, aLengthRefValue, aHeightRefValue)):
             aResult = extrusion.getBody(self.makeBox(aLength, aWidth, aHeight))
         else:
+            aHeightProxyResult = ModelAPI.modelAPI_Result(aHeightRefValue)
+            aWidthFeature = ModelAPI.modelAPI_Feature(aWidthRefValue)
+            aLengthFeature = ModelAPI.modelAPI_Feature(aLengthRefValue)
+            aHeightResult = ModelAPI.modelAPI_ResultBody(aHeightProxyResult)
             aWidthFeature.real("ConstraintValue").setValue(aWidth)
             aLengthFeature.real("ConstraintValue").setValue(aLength)
-            aHeightFeature.real("extrusion_size").setValue(aHeight)
-            aResult = extrusion.getBody(aHeightFeature)
+            if aHeightResult is not None:
+                aHeightFeature = aHeightResult.document().feature(aHeightResult)
+                aHeightFeature.real("extrusion_size").setValue(aHeight)
+                aResult = extrusion.getBody(aHeightFeature)
         self.setResult(aResult)
 
     def makeBox(self, aWidth, aLength, aHeight):