From: spo Date: Tue, 14 Jun 2016 13:54:09 +0000 (+0300) Subject: Fix tests MakeBrick2 & MakeBrick3. Fix Box macro feature. X-Git-Tag: V_2.4.0~91^2~50 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a3d6ec71bc857eb6e67d0bf9bc3fd841e7c73efe;p=modules%2Fshaper.git Fix tests MakeBrick2 & MakeBrick3. Fix Box macro feature. --- diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp index caa3d7ace..4fd119a3a 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -42,6 +42,9 @@ void ModelHighAPI_Interface::execute() std::list ModelHighAPI_Interface::result() const { + // TODO(spo): should I use more common function for the whole model to prepare results? + const_cast(this)->execute(); + std::list aSelectionList; std::list > aResults = feature()->results(); diff --git a/src/PythonAPI/examples/MakeBrick1.py b/src/PythonAPI/examples/MakeBrick1.py index 1d4461813..4efed0b15 100644 --- a/src/PythonAPI/examples/MakeBrick1.py +++ b/src/PythonAPI/examples/MakeBrick1.py @@ -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) diff --git a/src/PythonAPI/examples/MakeBrick2.py b/src/PythonAPI/examples/MakeBrick2.py index 279509cae..2086b83c0 100644 --- a/src/PythonAPI/examples/MakeBrick2.py +++ b/src/PythonAPI/examples/MakeBrick2.py @@ -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() diff --git a/src/PythonAPI/model/sketcher/__init__.py b/src/PythonAPI/model/sketcher/__init__.py index ca5243873..7aa993434 100644 --- a/src/PythonAPI/model/sketcher/__init__.py +++ b/src/PythonAPI/model/sketcher/__init__.py @@ -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 index 000000000..fc0e39a25 --- /dev/null +++ b/src/PythonAPI/model/sketcher/tools.py @@ -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 diff --git a/src/PythonAddons/macros/box/feature.py b/src/PythonAddons/macros/box/feature.py index 8651ac5ea..6be8f29ed 100644 --- a/src/PythonAddons/macros/box/feature.py +++ b/src/PythonAddons/macros/box/feature.py @@ -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() ) diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index e478339f2..27ba10f63 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -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 SketchAPI_Sketch::selectFace() const { + const_cast(this)->execute(); + std::list aSelectionList; ResultConstructionPtr aResultConstruction =