]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
BoxFeature is rewritten + small corrections in APIs
authorsbh <sergey.belash@opencascade.com>
Tue, 25 Nov 2014 09:13:45 +0000 (12:13 +0300)
committersbh <sergey.belash@opencascade.com>
Tue, 25 Nov 2014 09:13:45 +0000 (12:13 +0300)
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_AttributeRefAttr.h
src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py
src/PythonFeaturesPlugin/box_widget.xml
src/PythonFeaturesPlugin/examples.py
src/PythonFeaturesPlugin/extrusion.py
src/PythonFeaturesPlugin/sketch.py

index 5df84da6a5185d7ad0027cc0fcf07d3b6bc505c4..87a43a2b7dabb8855acc59c42685b38ea9473c1f 100644 (file)
@@ -48,7 +48,7 @@ SET(PROJECT_LIBRARIES
     Config
 )
 SET(CMAKE_SWIG_FLAGS -threads -Wall)
-ADD_DEFINITIONS(-DMODELAPI_EXPORTS -DSWIG_TYPE_TABLE=ModelAPI)
+ADD_DEFINITIONS(-DMODELAPI_EXPORT)
 
 ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
 SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX)
index d1ffd5643561aae44863ce92451cad2ad1f295ca..5043bcfe13d17a8d232191b42989f6be83e3cabd 100644 (file)
 %template(ObjectList) std::list<std::shared_ptr<ModelAPI_Object> >;
 %template(ResultList) std::list<std::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)          shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
-%template(modelAPI_CompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
 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>;
+// Result casts
 %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>;
 
-// 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>;
+%template(modelAPI_AttributeDocRef)        shared_ptr_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;
+%template(modelAPI_AttributeDouble)        shared_ptr_cast<ModelAPI_AttributeDouble, ModelAPI_Attribute>;
+%template(modelAPI_AttributeInteger)       shared_ptr_cast<ModelAPI_AttributeInteger, ModelAPI_Attribute>;
+%template(modelAPI_AttributeString)        shared_ptr_cast<ModelAPI_AttributeString, ModelAPI_Attribute>;
+%template(modelAPI_AttributeReference)     shared_ptr_cast<ModelAPI_AttributeReference, ModelAPI_Attribute>;
+%template(modelAPI_AttributeRefAttr)       shared_ptr_cast<ModelAPI_AttributeRefAttr, ModelAPI_Attribute>;
+%template(modelAPI_AttributeBoolean)       shared_ptr_cast<ModelAPI_AttributeBoolean, ModelAPI_Attribute>;
+%template(modelAPI_AttributeSelection)     shared_ptr_cast<ModelAPI_AttributeSelection, ModelAPI_Attribute>;
+%template(modelAPI_AttributeSelectionList) shared_ptr_cast<ModelAPI_AttributeSelectionList, ModelAPI_Attribute>;
+%template(modelAPI_AttributeRefList)       shared_ptr_cast<ModelAPI_AttributeRefList, ModelAPI_Attribute>;
index 5644cc47f8a8381cccae40c87a5c0086ac037f68..b1e9ad2332337c43954d59ca752b4b13423c5e91 100644 (file)
@@ -21,10 +21,10 @@ class ModelAPI_AttributeRefAttr : public ModelAPI_Attribute
   MODELAPI_EXPORT virtual bool isObject() = 0;
 
   /// Defines the reference to the attribute
-  MODELAPI_EXPORT virtual void setAttr(std::shared_ptr<ModelAPI_Attribute> theAttr) = 0;
+  MODELAPI_EXPORT virtual void setAttr(AttributePtr theAttr) = 0;
 
   /// Returns attribute referenced from this attribute
-  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attr() = 0;
+  MODELAPI_EXPORT virtual AttributePtr attr() = 0;
 
   /// Defines the reference to the object
   MODELAPI_EXPORT virtual void setObject(ObjectPtr theFeature) = 0;
index 05f6460d6f502f857a8010ae7663ef2669dbfdf3..4dbf89abc78571f8874950f9d8f18f056cf56cb3 100644 (file)
@@ -1,5 +1,7 @@
 import ModelAPI
-import examples
+import sketch
+import extrusion
+from SketchResult import SketchResult
 
 
 class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
@@ -25,29 +27,85 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
     def HEIGHT_ID():
         return "box_height"
 
+    @staticmethod
+    def WIDTH_REF_ID():
+        return "box_ref_width"
+
+    @staticmethod
+    def LENGTH_REF_ID():
+        return "box_ref_length"
+
+    @staticmethod
+    def HEIGHT_REF_ID():
+        return "box_ref_height"
+
     def getKind(self):
         return PythonFeaturesPlugin_Box.ID()
 
     def initAttributes(self):
         # C++ static methods (in example "type()" of the 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())
+        self.data().addAttribute(self.WIDTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+        self.data().addAttribute(self.LENGTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+        self.data().addAttribute(self.HEIGHT_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+        self.data().addAttribute(self.WIDTH_REF_ID(), ModelAPI.ModelAPI_AttributeReference_type())
+        self.data().addAttribute(self.LENGTH_REF_ID(), ModelAPI.ModelAPI_AttributeReference_type())
+        self.data().addAttribute(self.HEIGHT_REF_ID(), ModelAPI.ModelAPI_AttributeReference_type())
+        aSession = ModelAPI.ModelAPI_Session.get()
+        aSession.validators().registerNotObligatory(self.getKind(), self.WIDTH_REF_ID());
+        aSession.validators().registerNotObligatory(self.getKind(), self.LENGTH_REF_ID());
+        aSession.validators().registerNotObligatory(self.getKind(), self.HEIGHT_REF_ID());
 
     def execute(self):
-        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))
-        aResultBody = self.document().createBody(self.data())
-        aResult = examples.makeBox(aLength, aWidth, aHeight)
-        #aShape = modelAPI_ResultConstruction(aResult).shape()
-        # aResultBody.store(aShape)
-        self.setResult(aResultBody)
+        aWidth = self.real(self.WIDTH_ID()).value()
+        aLength = self.real(self.LENGTH_ID()).value()
+        aHeight = self.real(self.HEIGHT_ID()).value()
+        aWidthFeature = ModelAPI.modelAPI_Feature(self.reference(self.WIDTH_REF_ID()).value())
+        aLengthFeature = ModelAPI.modelAPI_Feature(self.reference(self.LENGTH_REF_ID()).value())
+        aHeightFeature = ModelAPI.modelAPI_Feature(self.reference(self.HEIGHT_REF_ID()).value())
+        aResult = None
+        if not all((aWidthFeature, aLengthFeature, aLengthFeature)):
+            aResult = extrusion.getBody(self.makeBox(aLength, aWidth, aHeight))
+        else:
+            aWidthFeature.real("ConstraintValue").setValue(aWidth)
+            aLengthFeature.real("ConstraintValue").setValue(aLength)
+            aHeightFeature.real("extrusion_size").setValue(aHeight)
+            aResult = extrusion.getBody(aHeightFeature)
+        self.setResult(aResult)
+
+    def makeBox(self, aWidth, aLength, aHeight):
+        aSession = ModelAPI.ModelAPI_Session.get()
+        aPart = aSession.activeDocument()
+        # Starting the Sketch
+        aSketch = sketch.addTo(aPart)
+        sketch.setXOYPlane(aSketch)
+        # Creating the lines
+        l1 = sketch.addLine(10, 10, 10, 50, aSketch)
+        l2 = sketch.addLine(10, 50, 60, 60, aSketch)
+        l3 = sketch.addLine(60, 60, 50, 10, aSketch)
+        l4 = sketch.addLine(50, 10, 10, 10, aSketch)
+        aSketch.execute()
+        # Creating the constraints
+        sketch.makeCoincident(sketch.getEndPoint(l1), sketch.getStartPoint(l2), aSketch)
+        sketch.makeCoincident(sketch.getEndPoint(l2), sketch.getStartPoint(l3), aSketch)
+        sketch.makeCoincident(sketch.getEndPoint(l3), sketch.getStartPoint(l4), aSketch)
+        sketch.makeCoincident(sketch.getEndPoint(l4), sketch.getStartPoint(l1), aSketch)
+        sketch.makeParallel(sketch.getGeometry(l1), sketch.getGeometry(l3), aSketch)
+        sketch.makeParallel(sketch.getGeometry(l2), sketch.getGeometry(l4), aSketch)
+        sketch.makePerpendicular(sketch.getGeometry(l1), sketch.getGeometry(l4), aSketch)
+        # Set to 0X and 0Y lines defined length
+        aWidthFeature = sketch.makeConstantLength(sketch.getGeometry(l4), aWidth, aSketch)
+        aLengthFeature = sketch.makeConstantLength(sketch.getGeometry(l1), aLength, aSketch)
+        # Finalisation of the operation
+        builder = SketchResult(aSketch)
+        # Creating a feature Extrusion
+        aHeightFeature = extrusion.addNew(builder, aHeight, aPart)
+        # Store features...
+        self.reference(self.WIDTH_REF_ID()).setValue(aWidthFeature)
+        self.reference(self.LENGTH_REF_ID()).setValue(aLengthFeature)
+        self.reference(self.HEIGHT_REF_ID()).setValue(aHeightFeature)
+        return aHeightFeature
+
 
 # TEST
 """
index f352315809e5daed96a0b44a70979f2c9e30ddb2..7c1a2c553a852f5046358265a6a7eb278148ce43 100644 (file)
@@ -1,11 +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">
+  <doublevalue id="box_width" label="Width" min="0" step="1.0" default="50" 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">
+  <doublevalue id="box_length" label="Length" min="0" step="1.0" default="50" 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">
+  <doublevalue id="box_height" label="Height" min="0" step="1.0" default="50" icon=":icons/dimension_v.png" tooltip="Set height of the box">
     <validator id="GeomValidators_Positive"/>
   </doublevalue>
 </source>
index 3da0d6f57bf5375974eaed14ffbb5504b247b4be..9f68e92342c7ad9753f8acac379d77a45a5d3c6c 100644 (file)
@@ -23,23 +23,29 @@ def makeBox(aLength, aWidth, aHeight):
     base.execute()
 
     # Creating the constraints
-    # NOTE : the following lines are currently not working in BR_PYTHON_PLUGIN
-    # branch
-    # sketch.makeCoincident(sketch.getEndPoint(l1), sketch.getStartPoint(l2), base)
-    # sketch.makeCoincident(sketch.getEndPoint(l2), sketch.getStartPoint(l3), base)
-    # sketch.makeCoincident(sketch.getEndPoint(l3), sketch.getStartPoint(l4), base)
-    # sketch.makeCoincident(sketch.getEndPoint(l4), sketch.getStartPoint(l1), base)
-    #
-    # sketch.makeParallel(sketch.getGeometry(l1), sketch.getGeometry(l3))
-    # sketch.makeParallel(sketch.getGeometry(l2), sketch.getGeometry(l4))
-    #
-    # sketch.makePerpendicular(sketch.getGeometry(l1), sketch.getGeometry(l4))
+    sketch.makeCoincident(sketch.getEndPoint(l1),
+                          sketch.getStartPoint(l2), base)
+    sketch.makeCoincident(sketch.getEndPoint(l2),
+                          sketch.getStartPoint(l3), base)
+    sketch.makeCoincident(sketch.getEndPoint(l3),
+                          sketch.getStartPoint(l4), base)
+    sketch.makeCoincident(sketch.getEndPoint(l4),
+                          sketch.getStartPoint(l1), base)
+
+    sketch.makeParallel(sketch.getGeometry(l1), sketch.getGeometry(l3), base)
+    sketch.makeParallel(sketch.getGeometry(l2), sketch.getGeometry(l4), base)
+
+    sketch.makePerpendicular(sketch.getGeometry(l1),
+                             sketch.getGeometry(l4), base)
+    # Set to 0X and 0Y lines defined length
+    sketch.makeConstantLength(sketch.getGeometry(l1), aLength, base)
+    sketch.makeConstantLength(sketch.getGeometry(l4), aWidth, base)
 
     # Finalisation of the operation
     builder = SketchResult(base)
 
     # Creating a feature Extrusion
-    box = extrusion.addNew(builder, 50, part)
+    box = extrusion.addNew(builder, aHeight, part)
 
     # return base.lastResult()
     return extrusion.getBody(box)
index 2ce035dca33ad01dd7a6c562f93565ec1ffe862e..9008479a07d13146e63599860b7e1050b6b6014b 100644 (file)
@@ -12,4 +12,4 @@ def addNew(builder, length, part, edges=None, reverse=False):
 
 
 def getBody(extrusion):
-    return extrusion.firstResult()
+    return modelAPI_ResultBody(extrusion.firstResult())
index f60fbc16e98c8b503a144f7a87b8e7b47a55a80b..ca13a707da20a641a351fa21169ae94c3bf65ac1 100644 (file)
@@ -110,21 +110,25 @@ def makeCoincident(p1, p2, sketch):
     constraint = sketch.addFeature("SketchConstraintCoincidence")
     constraint.refattr("ConstraintEntityA").setAttr(p1)
     constraint.refattr("ConstraintEntityB").setAttr(p2)
+    return constraint
 
 
 def makeParallel(l1, l2, sketch):
     constraint = sketch.addFeature("SketchConstraintParallel")
     constraint.refattr("ConstraintEntityA").setObject(l1)
     constraint.refattr("ConstraintEntityB").setObject(l2)
+    return constraint
 
 
 def makePerpendicular(l1, l2, sketch):
     constraint = sketch.addFeature("SketchConstraintPerpendicular")
     constraint.refattr("ConstraintEntityA").setObject(l1)
     constraint.refattr("ConstraintEntityB").setObject(l2)
+    return constraint
 
 
 def makeConstantLength(line, length, sketch):
     constraint = sketch.addFeature("SketchConstraintLength")
     constraint.refattr("ConstraintEntityA").setObject(line)
     constraint.real("ConstraintValue").setValue(length)
+    return constraint