]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix tests MakeBrick2 & MakeBrick3. Fix Box macro feature.
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 14 Jun 2016 13:54:09 +0000 (16:54 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:08 +0000 (14:41 +0300)
src/ModelHighAPI/ModelHighAPI_Interface.cpp
src/PythonAPI/examples/MakeBrick1.py
src/PythonAPI/examples/MakeBrick2.py
src/PythonAPI/model/sketcher/__init__.py
src/PythonAPI/model/sketcher/tools.py [new file with mode: 0644]
src/PythonAddons/macros/box/feature.py
src/SketchAPI/SketchAPI_Sketch.cpp

index caa3d7acebe5c1d8f8573e28ff5a998f141da3e1..4fd119a3a9f384e9bba7eb682fb596a7fcbfe231 100644 (file)
@@ -42,6 +42,9 @@ void ModelHighAPI_Interface::execute()
 
 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::result() const
 {
+  // TODO(spo): should I use more common function for the whole model to prepare results?
+  const_cast<ModelHighAPI_Interface*>(this)->execute();
+
   std::list<ModelHighAPI_Selection> aSelectionList;
 
   std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
index 1d44618134517b0ae4550cf361d2e2b99fb046b1..4efed0b1508de9d7a315805b86454cafb367b963 100644 (file)
@@ -38,8 +38,6 @@ mybase.setPerpendicular(l1, l4)
 mywidth = mybase.setLength(l1, 50)
 mylength = mybase.setDistance(l1.startPoint(), l3, 50)
 
-mybase.execute()
-
 # Creating the extrusion
 
 mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
index 279509caeab36568086c090696806e01f26a268c..2086b83c0c5775334e4c4da3647be42bdd7de2f2 100644 (file)
@@ -26,14 +26,14 @@ p2 = geom.Pnt2d(0, 1)
 p3 = geom.Pnt2d(1, 1)
 p4 = geom.Pnt2d(1, 0)
 
-line = mybase.addPolygon(p1, p2, p3, p4)
+line = model.addPolygon(mybase, p1, p2, p3, p4)
 
-mybase.setParallel(line[0].result(), line[2].result())
-mybase.setParallel(line[1].result(), line[3].result())
-mybase.setPerpendicular(line[0].result(), line[3].result())
+mybase.setParallel(line[0], line[2])
+mybase.setParallel(line[1], line[3])
+mybase.setPerpendicular(line[0], line[3])
 
-mywidth = mybase.setLength(line[0].result(), 50)
-mylength = mybase.setDistance(line[0].startPoint(), line[2].result(), 50)
+mywidth = mybase.setLength(line[0], 50)
+mylength = mybase.setDistance(line[0].startPoint(), line[2], 50)
 
 
 # Creating the extrusion
@@ -49,15 +49,15 @@ thiszmax = "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1_1"
 
 mystand = model.addSketch(mypart, thisface)
 circle = mystand.addCircle(0, 25, 5)
-mystand.setDistance(circle.center(), thisxmin, 10)
-mystand.setDistance(circle.center(), thiszmax, 10)
+mystand.setDistance(circle.center(), mystand.addLine(thisxmin), 10)
+mystand.setDistance(circle.center(), mystand.addLine(thiszmax), 10)
 
 myboss = model.addExtrusion(mypart, mystand.selectFace(), -5)
 
 
 # Subtracting the cylinder to the box
 
-model.addSubtraction(mypart, mybox.result(), myboss.result())
+model.addCut(mypart, mybox.result(), myboss.result())
 model.end()
 
 
index ca52438730f3b8e1c5c6a6f0653ad7eeafefe127..7aa9934344907a8229d5091b0bcc5fc7edc7680f 100644 (file)
@@ -1,4 +1,5 @@
 """Package for Sketch plugin for the Parametric Geometry API of the Modeler.
 """
 
-from SketchAPI import addSketch
\ No newline at end of file
+from SketchAPI import addSketch
+from tools import addPolyline, addPolygon
diff --git a/src/PythonAPI/model/sketcher/tools.py b/src/PythonAPI/model/sketcher/tools.py
new file mode 100644 (file)
index 0000000..fc0e39a
--- /dev/null
@@ -0,0 +1,42 @@
+# Author: Sergey Pokhodenko
+# Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+def addPolyline(sketch, *coords):
+    """Add a poly-line to sketch.
+
+    The end of consecutive segments are defined as coincident.
+    """
+    c0 = coords[0]
+    c1 = coords[1]
+    polyline = []
+    line_1 = sketch.addLine(c0, c1)
+    polyline.append(line_1)
+    # Adding and connecting next lines
+    for c2 in coords[2:]:
+        line_2 = sketch.addLine(c1, c2)
+        sketch.setCoincident(line_1.endPoint(), line_2.startPoint())
+        polyline.append(line_2)
+        c1 = c2
+        line_1 = line_2
+    return polyline
+
+
+def addPolygon(sketch, *coords):
+    """Add a polygon to sketch.
+
+    The end of consecutive segments are defined as coincident.
+    """
+    pg = addPolyline(sketch, *coords)
+    # Closing the poly-line supposed being defined by at least 3 points
+    c0 = coords[0]
+    cn = coords[len(coords) - 1]
+    ln = sketch.addLine(cn, c0)
+    sketch.setCoincident(
+        pg[len(coords) - 2].endPoint(), ln.startPoint()
+        )
+    sketch.setCoincident(
+        ln.endPoint(), pg[0].startPoint()
+        )
+    pg.append(ln)
+    return pg
\ No newline at end of file
index 8651ac5ea308677bc68b8edc9261fdc93ee2aef3..6be8f29edddfb3d3097db4ff03aa255c8d5b8717 100644 (file)
@@ -65,17 +65,17 @@ class BoxFeature(model.Feature):
         p3 = geom.Pnt2d(1, 1)
         p4 = geom.Pnt2d(1, 0)
 
-        line = self.base.addPolygon(p1, p2, p3, p4)
+        line = model.addPolygon(self.base, p1, p2, p3, p4)
 
-        self.base.setParallel(line[0].result(), line[2].result())
-        self.base.setParallel(line[1].result(), line[3].result())
-        self.base.setPerpendicular(line[0].result(), line[3].result())
+        self.base.setParallel(line[0], line[2])
+        self.base.setParallel(line[1], line[3])
+        self.base.setPerpendicular(line[0], line[3])
 
         # Setting the size of the base with default values
         # Width
-        self.width = self.base.setLength(line[0].result(), 50)  # Keeps the constraint for edition
+        self.width = self.base.setLength(line[0], 50)  # Keeps the constraint for edition
         # Length
-        self.length = self.base.setLength(line[3].result(), 50)  # Keeps the constraint for edition
+        self.length = self.base.setLength(line[3], 50)  # Keeps the constraint for edition
 
         # Creating the extrusion (the box) at default size
         # A box result
@@ -86,26 +86,25 @@ class BoxFeature(model.Feature):
     def execute(self):
         """F.execute() -- execute the feature"""
         # Retrieving the user inputs
-        width = self.getRealInput(self.WIDTH_ID())
-        length = self.getRealInput(self.LENGTH_ID())
-        height = self.getRealInput(self.HEIGHT_ID())
-
-        width_text = self.getTextInput(self.WIDTH_ID())
-        length_text = self.getTextInput(self.LENGTH_ID())
-        height_text = self.getTextInput(self.HEIGHT_ID())
+        width = self.real(self.WIDTH_ID())
+        length = self.real(self.LENGTH_ID())
+        height = self.real(self.HEIGHT_ID())
 
         # Editing the box
-        if width_text == "":
-            self.base.setValue(self.width, width)
+        if width.text() == "":
+            self.base.setValue(self.width, width.value())
         else:
-            self.base.setText(self.width, width_text)
+            self.base.setValue(self.width, width.text())
 
-        if length_text == "":
-            self.base.setValue(self.length, length)
+        if length.text() == "":
+            self.base.setValue(self.length, length.value())
         else:
-            self.base.setText(self.length, length_text)
+            self.base.setValue(self.length, length.text())
 
-        self.box.setSize(height, height_text)
+        if (height.text() == ""):
+            self.box.setSize(height.value())
+        else:
+            self.box.setSize(height.text())
 
         # Publishing the result: not needed for Macro feature
         # self.addResult( self.box.result() )
index e478339f24d9d1f71fbc8ceb4991e2217ae686b3..27ba10f6332f3a2cb93d1020ddbb0ea2fb1fb6af 100644 (file)
@@ -97,12 +97,14 @@ void SketchAPI_Sketch::setValue(
   // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
   fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
 
-  theConstraint->execute();
+//  theConstraint->execute();
 }
 
 //--------------------------------------------------------------------------------------
 std::list<ModelHighAPI_Selection> SketchAPI_Sketch::selectFace() const
 {
+  const_cast<SketchAPI_Sketch*>(this)->execute();
+
   std::list<ModelHighAPI_Selection> aSelectionList;
 
   ResultConstructionPtr aResultConstruction =