From: Renaud NEDELEC Date: Mon, 19 Oct 2015 12:16:54 +0000 (+0200) Subject: [PythonAPI] small modifications in sketcher API to follow Daniel's remarks X-Git-Tag: V_2.1.0~206^2~91 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5ccedcde9973f7c5f40fb4e30d68fb4101ca4232;p=modules%2Fshaper.git [PythonAPI] small modifications in sketcher API to follow Daniel's remarks --- diff --git a/src/PythonAPI/modeler/sketcher/circle.py b/src/PythonAPI/modeler/sketcher/circle.py index 08c890bec..56a0e9418 100644 --- a/src/PythonAPI/modeler/sketcher/circle.py +++ b/src/PythonAPI/modeler/sketcher/circle.py @@ -2,11 +2,7 @@ from GeomDataAPI import geomDataAPI_Point2D -def addCircle(sketch, x, y, r): - feature = sketch.addFeature("SketchCircle") - return CircleInterface(feature, x, y, r) - -class CircleInterface(): +class Circle(): def __init__(self, circle_feature, x, y, r): self._feature = circle_feature self._center = geomDataAPI_Point2D( diff --git a/src/PythonAPI/modeler/sketcher/line.py b/src/PythonAPI/modeler/sketcher/line.py index 543051b29..99d794c9b 100644 --- a/src/PythonAPI/modeler/sketcher/line.py +++ b/src/PythonAPI/modeler/sketcher/line.py @@ -1,11 +1,6 @@ from GeomDataAPI import geomDataAPI_Point2D -def addLine(sketch, *args): - sketch_feature = sketch.addFeature("SketchLine") - return LineInterface(sketch_feature, *args) - - -class LineInterface(): +class Line(): """Interface for editing of a sketch line feature.""" def __init__(self, line_feature, *args): self._feature = line_feature diff --git a/src/PythonAPI/modeler/sketcher/point.py b/src/PythonAPI/modeler/sketcher/point.py index 2a99aa7a1..5ba47e784 100644 --- a/src/PythonAPI/modeler/sketcher/point.py +++ b/src/PythonAPI/modeler/sketcher/point.py @@ -2,17 +2,7 @@ from GeomDataAPI import geomDataAPI_Point2D -def addPoint(sketch, x, y): - """Add a sketch point feature to the sketch. - - :return: Interface object on this feature - :rtype: sketcher.Point - """ - sketch_point_feature = sketch.addFeature("SketchPoint") - return PointInterface(sketch_feature, x, y) - - -class PointInterface(): +class Point(): """Interface on point feature for data manipulation.""" def __init__(self, point_feature, x, y): self._point_feature = point_feature diff --git a/src/PythonAPI/modeler/sketcher/sketch.py b/src/PythonAPI/modeler/sketcher/sketch.py index 479bb8c44..1ec03ca03 100644 --- a/src/PythonAPI/modeler/sketcher/sketch.py +++ b/src/PythonAPI/modeler/sketcher/sketch.py @@ -6,9 +6,9 @@ Copyright (C) 2014-20xx CEA/DEN, EDF R&D from ModelAPI import * from GeomDataAPI import * from GeomAlgoAPI import * -import modeler.sketcher.point as sk_point -import modeler.sketcher.line as sk_line -import modeler.sketcher.circle as sk_circle +from modeler.sketcher.point import Point +from modeler.sketcher.line import Line +from modeler.sketcher.circle import Circle def addSketch(doc, plane): """Add a Sketch feature to the Part or PartSet and return an interface @@ -18,7 +18,7 @@ def addSketch(doc, plane): it provides an interface for manipulation of the feature data. :return: interface on the feature :rtype: Sketch object""" - feature = featureToCompositeFeature( doc.addFeature("Sketch") ) + feature = featureToCompositeFeature(doc.addFeature("Sketch")) return Sketch(feature, plane) class Sketch(): @@ -58,14 +58,19 @@ class Sketch(): # Creation of Geometries def addPoint (self, *args): - """Adds a point to this Sketch.""" - point_interface = sk_point.addPoint(self._feature, *args) - return point_interface + """Add a point to this Sketch.""" + point_feature = self._feature.addFeature("SketchPoint") + return Point(point_feature, *args) def addLine (self, *args): - """Adds a line to this Sketch.""" - line_interface = sk_line.addLine(self._feature, *args) - return line_interface + """Add a line to this Sketch.""" + line_feature = self._feature.addFeature("SketchLine") + return Line(line_feature, *args) + + def addCircle (self, *args): + """Add a circle to this Sketch.""" + circle_feature = self._feature.addFeature("SketchCircle") + return Circle(circle_feature, *args) def addPolyline (self, *coords): """Adds a poly-line to this Sketch. @@ -88,23 +93,23 @@ class Sketch(): def addPolygon (self, *coords): """Add a polygon to this Sketch. + The end of consecutive segments are defined as coincident. """ pg = self.addPolyline(*coords) # Closing the poly-line supposed being defined by at least 3 points c0 = coords[0] - cn = coords[len(coords)-1] + cn = coords[len(coords) - 1] ln = self.addLine(cn, c0) - self.setCoincident( pg[len(coords)-2].endPointData(), ln.startPointData() ) - self.setCoincident( ln.endPointData(), pg[0].startPointData() ) + self.setCoincident( + pg[len(coords) - 2].endPointData(), ln.startPointData() + ) + self.setCoincident( + ln.endPointData(), pg[0].startPointData() + ) pg.append(ln) return pg - def addCircle (self, *args): - """Adds a circle to this Sketch.""" - circle_interface = sk_circle.addCircle(self._feature, *args) - return circle_interface - # Creation of Geometrical and Dimensional Constraints