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();
mywidth = mybase.setLength(l1, 50)
mylength = mybase.setDistance(l1.startPoint(), l3, 50)
-mybase.execute()
-
# Creating the extrusion
mybox = model.addExtrusion(mypart, mybase.selectFace(), 50)
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
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()
"""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
--- /dev/null
+# 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
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
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() )
// 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 =