From: Renaud NEDELEC Date: Tue, 20 Oct 2015 09:27:06 +0000 (+0200) Subject: Merge branch 'python_parametric_api' of https://git.salome-platform.org/git/modules... X-Git-Tag: V_2.1.0~206^2~87 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=659f615574a9d3e4bf72ccc053e1a1d45d88e116;p=modules%2Fshaper.git Merge branch 'python_parametric_api' of https://git.salome-platform.org/git/modules/shaper into python_parametric_api --- 659f615574a9d3e4bf72ccc053e1a1d45d88e116 diff --cc src/PythonAPI/model/sketcher/arc.py index 000000000,8e1bb1a50..b025c4636 mode 000000,100644..100644 --- a/src/PythonAPI/model/sketcher/arc.py +++ b/src/PythonAPI/model/sketcher/arc.py @@@ -1,0 -1,65 +1,69 @@@ + """Sketch circle feature interface.""" + + from GeomDataAPI import geomDataAPI_Point2D + from model.errors import WrongNumberOfArguments + + class Arc(): ++ """Interface for editing a sketch arc feature.""" + def __init__(self, arc_feature, *args): + self._feature = arc_feature + self._center = geomDataAPI_Point2D( + self._feature.data().attribute("ArcCenter") + ) + self._start_point = geomDataAPI_Point2D( + self._feature.data().attribute("ArcStartPoint") + ) + self._end_point = geomDataAPI_Point2D( + self._feature.data().attribute("ArcEndPoint") + ) + if len(args) == 6: + self.__createByCoordinates(*args) + elif len(args) == 3: + self.__createByPoints(*args) + else: + raise WrongNumberOfArguments( + "Arc takes 3 or 6 arguments (%s given)" % len(args) + ) + - def centerData (self): ++ def centerData(self): ++ """Return the center point data.""" + return self._center + - def startPointData (self): ++ def startPointData(self): ++ """Return the start point data.""" + return self._start_point + - def endPointData (self): ++ def endPointData(self): ++ """Return the end point data.""" + return self._end_point + - def result (self): ++ def result(self): ++ """Return the arc circular line attribute.""" + return self._feature.lastResult() + + ######## + # + # Private methods + # + ######## + - def __createByCoordinates(self, - center_x, center_y, - start_x, start_y, - end_x, end_y): ++ def __createByCoordinates(self, center_x, center_y, ++ start_x, start_y, ++ end_x, end_y): + """Create an arc by point coordinates.""" + self._center.setValue(center_x, center_y) + self._start_point.setValue(start_x, start_y) + self._end_point.setValue(end_x, end_y) + self._feature.execute() + + def __createByPoints(self, center, start, end): + """Create an arc with point objects.""" + self._center.setValue(center.x(), center.y()) + self._start_point.setValue(start.x(), start.y()) + self._end_point.setValue(end.x(), end.y()) + self._feature.execute() + + + + + diff --cc src/PythonAPI/model/sketcher/circle.py index 000000000,56a0e9418..a6a0134cb mode 000000,100644..100644 --- a/src/PythonAPI/model/sketcher/circle.py +++ b/src/PythonAPI/model/sketcher/circle.py @@@ -1,0 -1,23 +1,28 @@@ + """Sketch circle feature interface.""" + + from GeomDataAPI import geomDataAPI_Point2D + + class Circle(): ++ """Interface for circle feature data manipulation.""" ++ + def __init__(self, circle_feature, x, y, r): + self._feature = circle_feature + self._center = geomDataAPI_Point2D( + self._feature.data().attribute("CircleCenter") + ) + self._radius = self._feature.data().real("CircleRadius") + self._center.setValue(x, y) + self._radius.setValue(r) + self._feature.execute() + - def centerData (self): ++ def centerData(self): ++ """Return center data.""" + return self._center - - def radiusData (self): ++ ++ def radiusData(self): ++ """Return radius data.""" + return self._radius + - def result (self): - return self._feature.lastResult() # Returns the circular line attribute ++ def result(self): ++ """Return the cicular line attribute.""" ++ return self._feature.lastResult() diff --cc src/PythonAPI/model/sketcher/line.py index 000000000,99d794c9b..dfe8a1c93 mode 000000,100644..100644 --- a/src/PythonAPI/model/sketcher/line.py +++ b/src/PythonAPI/model/sketcher/line.py @@@ -1,0 -1,45 +1,45 @@@ + from GeomDataAPI import geomDataAPI_Point2D + + class Line(): + """Interface for editing of a sketch line feature.""" + def __init__(self, line_feature, *args): + self._feature = line_feature + self._start_point = geomDataAPI_Point2D( + self._feature.data().attribute("StartPoint") + ) + self._end_point = geomDataAPI_Point2D( + self._feature.data().attribute("EndPoint") + ) + if len(args) == 4: + self.__createByCoordinates(*args) + elif len(args) == 2: + self.__createByPoints(*args) + elif len(args) == 1: + self.__createByName(sketch, *args) + else: + raise Exception("cannot create the Line") + + def __createByCoordinates(self, x1, y1, x2, y2): + self._start_point.setValue(x1, y1) + self._end_point.setValue(x2, y2) + self._feature.execute() + + def __createByPoints(self, p1, p2): + self._start_point.setValue(p1.x(), p1.y()) + self._end_point.setValue(p2.x(), p2.y()) + self._feature.execute() + + def __createByName(self, sketch, name): + self._feature.data().selection("External").selectSubShape("EDGE", name) + self._feature.execute() + rigid = sketch.addFeature("SketchConstraintRigid") - rigid.refattr("ConstraintEntityA").setObject( self._feature.firstResult() ) ++ rigid.refattr("ConstraintEntityA").setObject(self._feature.firstResult()) + - def startPointData (self): ++ def startPointData(self): + return self._start_point + - def endPointData (self): ++ def endPointData(self): + return self._end_point + - def result (self): ++ def result(self): + return self._feature.firstResult()