]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementation of Box python feature as a Composite feature again
authorsbh <sergey.belash@opencascade.com>
Wed, 18 Mar 2015 14:11:56 +0000 (17:11 +0300)
committersbh <sergey.belash@opencascade.com>
Wed, 18 Mar 2015 14:11:56 +0000 (17:11 +0300)
18 files changed:
src/FeaturesPlugin/Test/TestBoolean.py
src/FeaturesPlugin/Test/TestExtrusion.py
src/FeaturesPlugin/Test/TestGroup.py
src/ModelAPI/ModelAPI.i
src/PythonFeaturesPlugin/PythonFeaturesPlugin.py
src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py
src/PythonFeaturesPlugin/sketch.py
src/SketchPlugin/Test/TestConstraintConcidence.py
src/SketchPlugin/Test/TestConstraintDistance.py
src/SketchPlugin/Test/TestConstraintLength.py
src/SketchPlugin/Test/TestConstraintParallel.py
src/SketchPlugin/Test/TestConstraintPerpendicular.py
src/SketchPlugin/Test/TestConstraintRadius.py
src/SketchPlugin/Test/TestConstraintRigid.py
src/SketchPlugin/Test/TestHighload.py
src/SketchPlugin/Test/TestSketchArcCircle.py
src/SketchPlugin/Test/TestSketchPointLine.py
src/SketchPlugin/Test/TestSnowflake.py

index ab00fa3f45e954ec0c72ecdb5b98982d9c39471d..525b08cda515f08cddeb13834955b33f8754e2ff 100644 (file)
@@ -32,7 +32,7 @@ aSession.finishOperation()
 # Create a sketch with circle to extrude
 #=========================================================================
 aSession.startOperation()
-aCircleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
 origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
@@ -51,7 +51,7 @@ aSession.finishOperation()
 # Create a sketch with triangle to extrude
 #=========================================================================
 aSession.startOperation()
-aTriangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
index 9edca8a3bc611b180bdceb96df9a6d05463c7049..4714bcfccc489d8619698cefa7f7fdaf325c97c7 100644 (file)
@@ -37,7 +37,7 @@ aPart = aPartResult.partDoc()
 # Create a sketch circle to extrude
 #=========================================================================
 aSession.startOperation()
-aSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index e888ff654f8b0ad599d1ab507b82dcafcacf2af3..6a773ce1bd6785a4997a0fb1329d66b9598ef157 100644 (file)
@@ -28,7 +28,7 @@ aSession.finishOperation()
 # Create a sketch with triangle and extrude it
 #=========================================================================
 aSession.startOperation()
-aTriangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
 origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
index 77a0f42e09d794b5b2151713114e69ee153cbc7c..bd8cc724a39efec30c605993c166a9373e7bea5c 100644 (file)
   { 
     return std::dynamic_pointer_cast<T1>(theObject); 
   }
-  
+
 %}
 
 // to avoid error on this
 #define MODELAPI_EXPORT
 
 // standard definitions
-%include "typemaps.i"
 %include "GeomAPI.i"
+%include "typemaps.i"
 %include "std_string.i"
 %include "std_list.i"
 %include "std_shared_ptr.i"
 
 // std::dynamic_pointer_cast
 template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr<T2> theObject);
-%template(modelAPI_CompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
-%template(modelAPI_Feature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
+%template(featureToCompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
+%template(objectToFeature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
+%template(compositeFeatureToFeature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_CompositeFeature>;
 
 %template(modelAPI_Result) shared_ptr_cast<ModelAPI_Result, ModelAPI_Object>;
 %template(modelAPI_ResultConstruction) shared_ptr_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
index ca671e1449df5c7d037c81d73b1bbe8d3e9d5b75..890b3ae152b1c3e4ffaff284da036d7031a7b4ce 100644 (file)
@@ -1,3 +1,6 @@
+"""
+"""
+
 import ModelAPI
 from PythonFeaturesPlugin_Box import PythonFeaturesPlugin_Box
 
@@ -6,15 +9,19 @@ class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin):
 
     def __init__(self):
         ModelAPI.ModelAPI_Plugin.__init__(self)
+        aSession = ModelAPI.ModelAPI_Session.get()
+        aSession.registerPlugin(self)
         pass
 
     def createFeature(self, theFeatureID):
+        aFeature = None
         if theFeatureID == PythonFeaturesPlugin_Box.ID():
-            return PythonFeaturesPlugin_Box().__disown__()
+            aCompositeFeature = PythonFeaturesPlugin_Box().__disown__()
+            aFeature = ModelAPI.compositeFeatureToFeature(aCompositeFeature)
         else:
             raise StandardError("No such feature %s" % theFeatureID)
+        return aFeature
+
 
 plugin = PythonFeaturesPlugin()
-aSession = ModelAPI.ModelAPI_Session.get()
-print "Module loaded. Session", aSession
-aSession.registerPlugin(plugin)
+plugin.__disown__()
index a8b79c9ea39a014347daca5e17a60ed1ed6aeb2e..2487a6ee882133ac23c0a13f6168674cc49757e4 100644 (file)
@@ -5,12 +5,12 @@ import extrusion
 import sketch
 
 
-class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
-
-    "Feature to create a box by drawing a sketch and extruding it"
+class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_CompositeFeature):
+    """Feature to create a box by drawing a sketch and extruding it
+    """
 
     def __init__(self):
-        ModelAPI.ModelAPI_Feature.__init__(self)
+        ModelAPI.ModelAPI_CompositeFeature.__init__(self)
 
     @staticmethod
     def ID():
@@ -57,8 +57,8 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
         aSession.validators().registerNotObligatory(self.getKind(), self.LENGTH_REF_ID())
         aSession.validators().registerNotObligatory(self.getKind(), self.HEIGHT_REF_ID())
         aSession.validators().registerConcealment(self.getKind(), self.HEIGHT_REF_ID())
-        self.mySketch = None # not yet initialized
-        self.myExtrusion = None # not yet initialized
+        self.mySketch = None  # not yet initialized
+        self.myExtrusion = None  # not yet initialized
 
     def execute(self):
         aWidth = self.real(self.WIDTH_ID()).value()
@@ -72,8 +72,8 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
             aResult = extrusion.getBody(self.makeBox(aLength, aWidth, aHeight))
         else:
             aHeightProxyResult = ModelAPI.modelAPI_Result(aHeightRefValue)
-            aWidthFeature = ModelAPI.modelAPI_Feature(aWidthRefValue)
-            aLengthFeature = ModelAPI.modelAPI_Feature(aLengthRefValue)
+            aWidthFeature = ModelAPI.objectToFeature(aWidthRefValue)
+            aLengthFeature = ModelAPI.objectToFeature(aLengthRefValue)
             aHeightResult = ModelAPI.modelAPI_ResultBody(aHeightProxyResult)
             aWidthFeature.real("ConstraintValue").setValue(aWidth)
             aLengthFeature.real("ConstraintValue").setValue(aLength)
@@ -84,8 +84,8 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
         # create a new result with copied shape from extrusion
         aResultBody = self.document().createBody(self.data())
         if not aResult is None:
-          aResultBody.store(aResult.shape())
-          self.setResult(aResultBody)
+            aResultBody.store(aResult.shape())
+            self.setResult(aResultBody)
         pass
 
     def makeBox(self, aWidth, aLength, aHeight):
@@ -93,7 +93,7 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
         aPart = aSession.activeDocument()
         # Starting the Sketch
         aSketch = sketch.addTo(aPart)
-        self.mySketch = sketch
+        self.mySketch = aSketch
         sketch.setXOYPlane(aSketch)
         # Creating the lines
         l1 = sketch.addLine(10, 10, 10, 60, aSketch)
@@ -123,6 +123,28 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
         self.reference(self.HEIGHT_REF_ID()).setValue(aHeightFeature.firstResult())
         return aHeightFeature
 
+    def addFeature(self, theID):
+        pass
+
+    def numberOfSubs(self):
+        subsCount = 0
+        if not self.mySketch is None:
+            subsCount += 1
+        if not self.myExtrusion is None:
+            subsCount += 1
+        # extrusion and sketch
+        return subsCount
+
+    def subFeature(self, theIndex):
+        if theIndex == 1: # sketch
+            return ModelAPI.compositeFeatureToFeature(self.mySketch)
+        return self.myExtrusion
+
+    def subFeatureId(self, theIndex):
+        return 0
+
+    def isSub(self, theFeature):
+        return theFeature == self.mySketch or theFeature == self.myExtrusion
 
 # TEST
 """
index ca13a707da20a641a351fa21169ae94c3bf65ac1..39475c048a0ffeab07e274d13aeea5702a5575b3 100644 (file)
@@ -6,7 +6,7 @@ from GeomDataAPI import *
 # ----------------------------
 
 def addTo(doc):
-    return modelAPI_CompositeFeature(doc.addFeature("Sketch"))
+    return featureToCompositeFeature(doc.addFeature("Sketch"))
 
 
 def setXOYPlane(sketch):
index 5256acb2d1346fa9243190bca17e7fdba5001937..79589ac4c6fa840149bf2d0f68bb6891a0eccc17 100644 (file)
@@ -31,7 +31,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index f57728799eac37b5ab6549787d2eff8e98430937..13aeada6f9f4fd19c766a85a48a363509d28aa8e 100644 (file)
@@ -45,7 +45,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index 12915b42ea92bd87afdef79186337a0b80820f14..4dc391889ed59c437751b40b12dcb0cf26386b88 100644 (file)
@@ -24,7 +24,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index ce2dcea47d5ebe5533872863ad42f23c1e3204ba..965193b4e4ac188a5fdd787314204390ee8017e3 100644 (file)
@@ -24,7 +24,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index 435b7d8c426df88cf1a34bba70bb84b41478e192..64e15c899af7b1d0195aa9d8b7d9ec99618e05f0 100644 (file)
@@ -31,7 +31,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index 8adb6082d863cd14e2c12a4598e95a44b150c392..175823e1e1e775cce2692e439ebbda784be54171 100644 (file)
@@ -33,7 +33,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index 47dfadf51a9a54f14601bfd89e1b0a8b584c2950..e00acda2ca37e6a7a1952c1b4f8cb373a82c8ead 100644 (file)
@@ -31,7 +31,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index f8fed6087f82e0ddf6147a1696b4aecdb97ab8b7..819cb00a566eff2a53d1b522a4c1445ba2691612 100644 (file)
@@ -90,7 +90,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index 9835bf2cc2bdd5589c0aa7dff7ffac1610e6a6ef..9927598a6882632ae357d43412826b4bb6bf6eca 100644 (file)
@@ -32,7 +32,7 @@ aDocument = aSession.moduleDocument()
 aSession.startOperation()
 #aSketchFeature = aDocument.addFeature("Sketch")
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
index df3f7cd64b6ab67a7ce2803a59d3c9409402f28a..cbf0d05bf40f07f4d0f3fd332aac5eb178e70335 100644 (file)
@@ -13,7 +13,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 assert (aSketchFeature.getKind() == "Sketch")
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
index 65b421354c8758b9d10523d5f5fa1bfb4273b086..4a0a31e53c0c8df2ca94a0fcdb0c5e8df1e380f1 100644 (file)
@@ -104,7 +104,7 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))