From fc67007cbda9644264a9a98f970803b593401cec Mon Sep 17 00:00:00 2001 From: spo Date: Wed, 16 Dec 2015 11:43:27 +0300 Subject: [PATCH] [PythonAPI] Remove module modeler which remains after merging with PythonAPI branch --- src/PythonAPI/modeler/boolean.py | 53 ------ src/PythonAPI/modeler/extrusion.py | 44 ----- src/PythonAPI/modeler/part.py | 21 --- src/PythonAPI/modeler/roots.py | 50 ------ src/PythonAPI/modeler/sketcher.py | 265 ----------------------------- 5 files changed, 433 deletions(-) delete mode 100644 src/PythonAPI/modeler/boolean.py delete mode 100644 src/PythonAPI/modeler/extrusion.py delete mode 100644 src/PythonAPI/modeler/part.py delete mode 100644 src/PythonAPI/modeler/roots.py delete mode 100644 src/PythonAPI/modeler/sketcher.py diff --git a/src/PythonAPI/modeler/boolean.py b/src/PythonAPI/modeler/boolean.py deleted file mode 100644 index 23b83a42b..000000000 --- a/src/PythonAPI/modeler/boolean.py +++ /dev/null @@ -1,53 +0,0 @@ -"""Boolean operations Interface -Author: Daniel Brunier-Coulin -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from ModelAPI import * -from GeomAlgoAPI import * - - -class Boolean(): - """Abstract root class of Boolean Features.""" - def __init__(self, part, object, tool, type): - """Constructor""" - ### Create a feature - self.my = part.addFeature("Boolean") - self.my.data().reference("main_object").setValue(object) - self.my.data().reference("tool_object").setValue(tool) - self.my.data().integer("bool_type").setValue(type) - - if ModelAPI_Session.get().validators().validate(self.my): - self.my.execute() - else: - raise Exception("cannot make the Boolean") - - -class Addition(Boolean): - """Inserts an addition to the given Part and executes the operation. - This operation adds tool to the given object. - """ - - def __init__(self, part, object, tool): - """Constructor""" - Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_FUSE) - - -class Subtraction(Boolean): - """Inserts a subtraction to the given Part and executes the operation. - This operation subtracts tool to the given object. - """ - - def __init__(self, part, object, tool): - """Constructor""" - Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_CUT) - - -class Intersection(Boolean): - """Inserts an intersection to the given Part and executes the operation. - This operation intersects tool to the given object. - """ - - def __init__(self, part, object, tool): - """Constructor""" - Boolean.__init__(self, part, object, tool, GeomAlgoAPI_Boolean.BOOL_COMMON) \ No newline at end of file diff --git a/src/PythonAPI/modeler/extrusion.py b/src/PythonAPI/modeler/extrusion.py deleted file mode 100644 index 4fcc37106..000000000 --- a/src/PythonAPI/modeler/extrusion.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Extrusion Interface -Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from ModelAPI import * - - -class Extrusion(): - """Class for Extrusion feature""" - def __init__ (self, part, sketch, size): - """Inserts an extrusion of the given Sketch to the given Part and executes the operation.""" - ### Create the feature - self.my = part.addFeature("Extrusion") - self.my.string("CreationMethod").setValue("BySizes") - self.my.data().selectionList("base").append(sketch.result(), sketch.buildShape()) - if size < 0: - self.my.data().real("from_size").setValue(-size) - self.my.data().real("to_size").setValue(0) - else: - self.my.data().real("to_size").setValue(size) - self.my.data().real("from_size").setValue(0) - - - if ModelAPI_Session.get().validators().validate(self.my): - self.my.execute() - else: - raise Exception("cannot make the Extrusion") - - - def setSize (self, size): - """Modifies the size of this extrusion according to the given size.""" - if size < 0: - self.my.data().real("from_size").setValue(-size) - self.my.data().real("to_size").setValue(0) - else: - self.my.data().real("to_size").setValue(size) - self.my.data().real("from_size").setValue(0) - - self.my.execute() - - def result (self): - """Returns the result data of this Feature.""" - return self.my.firstResult() diff --git a/src/PythonAPI/modeler/part.py b/src/PythonAPI/modeler/part.py deleted file mode 100644 index 52632c3c6..000000000 --- a/src/PythonAPI/modeler/part.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Part Feature Interface -Author: Daniel Brunier-Coulin -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -import modeler # Required by the temporary implementation of result member function - - -class Part(): - """Class for Part feature""" - - def __init__ (self, partset): - """Adds a new Part to the given Partset and activates the Part.""" - ### Create the feature - self.my = partset.addFeature("Part") - self.my.execute() - - def document (self): - """Returns the Part document created by this feature.""" - #TODO: Get the document referenced by this feature - return modeler.activeDocument() \ No newline at end of file diff --git a/src/PythonAPI/modeler/roots.py b/src/PythonAPI/modeler/roots.py deleted file mode 100644 index 181fd7efc..000000000 --- a/src/PythonAPI/modeler/roots.py +++ /dev/null @@ -1,50 +0,0 @@ -"""Abstract root classes of user-defined Python features producing a Body -Author: Daniel Brunier-Coulin -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from ModelAPI import * - - -class Feature(ModelAPI_Feature): - """Base class of user-defined Python features.""" - - def __init__(self): - """Constructor""" - ModelAPI_Feature.__init__(self) - - def addRealInput (self, inputid): - """Add double input""" - self.data().addAttribute(inputid, ModelAPI_AttributeDouble_typeId()) - - def getRealInput (self, inputid): - """Returns double input""" - return self.data().real(inputid).value() - - def addResult (self, result): - """Add result""" - shape = result.shape() - body = self.document().createBody( self.data() ) - body.store(shape) - self.setResult(body) - - -class Interface(): - """Base class of hight level Python interfaces to features.""" - - def __init__(self, container, fid): - """Constructor""" - ### Create the feature - self.my = container.addFeature(fid) - - def setRealInput (self, inputid, value): - """Set real value""" - self.my.data().real(inputid).setValue(value) - - def areInputValid (self): - """Returns True if the input is valid""" - return ModelAPI_Session.get().validators().validate(self.my) - - def execute (self): - """Build the feature result""" - self.my.execute() \ No newline at end of file diff --git a/src/PythonAPI/modeler/sketcher.py b/src/PythonAPI/modeler/sketcher.py deleted file mode 100644 index c3bad7c5c..000000000 --- a/src/PythonAPI/modeler/sketcher.py +++ /dev/null @@ -1,265 +0,0 @@ -"""Sketch Feature Interface -Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -from ModelAPI import * -from GeomDataAPI import * -from GeomAlgoAPI import * - - -class Sketch(): - """ A class of Sketcher""" - - def __init__(self, doc, plane): - """Initializes a 2D Sketch on the given plane and adds the Sketch to the given Part or Partset. - The plane can be defined either by: - - a 3D axis system (geom.Ax3), - - an existing face identified by its topological name. - """ - ### Create a feature object - self.my = featureToCompositeFeature( doc.addFeature("Sketch") ) - ### Entities used for building the result shape - self.selection = None -# self.resultype ="Face" # Type of Sketch result - if isinstance(plane, str): - self.__sketchOnFace(doc, plane) - else: - self.__sketchOnPlane(doc, plane) - - def __sketchOnPlane (self, doc, plane): - o = plane.location() - d = plane.direction() - dx = plane.xDirection() - geomDataAPI_Point( self.my.data().attribute("Origin") ).setValue( o.x(), o.y(), o.z() ) - geomDataAPI_Dir( self.my.data().attribute("DirX") ).setValue( dx.x(), dx.y(), dx.z() ) - geomDataAPI_Dir( self.my.data().attribute("Norm") ).setValue( d.x(), d.y(), d.z() ) - - def __sketchOnFace (self, doc, plane): - self.my.data().selection("External").selectSubShape("FACE", plane) - - -# Creation of Geometries - - def addPoint (self, *args): - """Adds a point to this Sketch.""" - return Point(self.my, *args) - - def addLine (self, *args): - """Adds a line to this Sketch.""" - return Line(self.my, *args) - - def addPolyline (self, *coords): - """Adds a poly-line to this Sketch. - The end of consecutive segments are defined as coincident. - """ - c0 = coords[0] - c1 = coords[1] - pl = [] - l1 = self.addLine(c0, c1) - pl.append(l1) - # Adding and connecting next lines - for c2 in coords[2:]: - l2 = self.addLine(c1, c2) - self.setCoincident( l1.endPointData(), l2.startPointData() ) - pl.append(l2) - c1 = c2 - l1 = l2 - return pl - - def addPolygon (self, *coords): - """Adds 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] - ln = self.addLine(cn, c0) - 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.""" - return Circle(self.my, *args) - - -# Creation of Geometrical and Dimensional Constraints - - def setCoincident (self, p1, p2): - """Sets coincident the two given points and adds the corresponding constraint to this Sketch.""" - constraint = self.my.addFeature("SketchConstraintCoincidence") - constraint.data().refattr("ConstraintEntityA").setAttr(p1) - constraint.data().refattr("ConstraintEntityB").setAttr(p2) - return constraint - - def setParallel (self, l1, l2): - """Sets parallel the two given lines and adds the corresponding constraint to this Sketch.""" - constraint = self.my.addFeature("SketchConstraintParallel") - constraint.data().refattr("ConstraintEntityA").setObject(l1) - constraint.data().refattr("ConstraintEntityB").setObject(l2) - return constraint - - def setPerpendicular (self, l1, l2): - """Sets perpendicular the two given lines and adds the corresponding constraint to this Sketch.""" - constraint = self.my.addFeature("SketchConstraintPerpendicular") - constraint.data().refattr("ConstraintEntityA").setObject(l1) - constraint.data().refattr("ConstraintEntityB").setObject(l2) - return constraint - - def setDistance (self, point, line, length): - """Sets the distance between the given point and line, and adds the corresponding constraint to this Sketch.""" - constraint = self.my.addFeature("SketchConstraintDistance") - if isinstance(line, str): - line = self.addLine(line).result() # Adds the edge identified by the given topological name to this Sketch - constraint.data().refattr("ConstraintEntityA").setAttr(point) - constraint.data().refattr("ConstraintEntityB").setObject(line) - constraint.data().real("ConstraintValue").setValue(length) - self.my.execute() - return constraint - - def setLength (self, line, length): - """Sets the length of the given line and adds the corresponding constraint to this Sketch.""" - constraint = self.my.addFeature("SketchConstraintLength") - constraint.data().refattr("ConstraintEntityA").setObject(line) - constraint.data().real("ConstraintValue").setValue(length) - self.my.execute() - return constraint - - def setRadius (self, circle, radius): - """Sets the radius of the given circle and adds the corresponding constraint to this Sketch.""" - constraint = self.my.addFeature("SketchConstraintRadius") - constraint.data().refattr("ConstraintEntityA").setObject(circle) - constraint.data().real("ConstraintValue").setValue(radius) - return constraint - - -# Edition of Dimensional Constraints - - def setValue (self, constraint, value): - """Modifies the value of the given dimensional constraint.""" - constraint.data().real("ConstraintValue").setValue(value) - - -# Getters - - def selectFace (self, *args): - """Selects the geometrical entities of this Sketch on which the result Face must be built. - When no entity is given, the face is based on all existing geometry of this Sketch. - """ - #self.resultype ="Face" - if len(args) == 0: - self.selection = modelAPI_ResultConstruction( self.my.firstResult() ).shape() - elif len(args) == 1: - self.selection = args[0].shape() - else: - raise Exception("not yet implemented") - return self - - def buildShape (self): - """Builds the result Shape of this Sketch according to the selected geometrical entities.""" - o = geomDataAPI_Point( self.my.data().attribute("Origin") ).pnt() - dx = geomDataAPI_Dir( self.my.data().attribute("DirX") ).dir() - n = geomDataAPI_Dir( self.my.data().attribute("Norm") ).dir() - - faces = ShapeList() # The faces are kept otherwise they are destroyed at exit - GeomAlgoAPI_SketchBuilder.createFaces(o, dx, n, self.selection, faces) -#TODO: Deal with several faces - return faces[0] - - def result (self): - """Returns the result data of this Feature.""" - return self.my.firstResult() - - -# Class definitions of Sketch features - -class Point(): - """A class which represents a Point object""" - - def __init__(self, sketch, x, y): - """Constructor""" - ### Create the feature - self.my = sketch.addFeature("SketchPoint") - geomDataAPI_Point2D( self.my.data().attribute("PointCoordindates") ).setValue(x, y) - self.my.execute() - - def pointData (self): - """Returns points attribute""" - return geomDataAPI_Point2D( self.my.data().attribute("PointCoordindates") ) - - def result (self): - """Returns result object""" - return self.my.firstResult() - - -class Line(): - """A class which represents a Line object""" - - def __init__(self, sketch, *args): - """Constructor""" - ### Create the feature - self.my = sketch.addFeature("SketchLine") - 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): - """Initialise the feature by coordinates""" - geomDataAPI_Point2D( self.my.data().attribute("StartPoint") ).setValue(x1, y1) - geomDataAPI_Point2D( self.my.data().attribute("EndPoint") ).setValue(x2, y2) - self.my.execute() - - def __createByPoints(self, p1, p2): - """Initialise the feature by point objects""" - geomDataAPI_Point2D( self.my.data().attribute("StartPoint") ).setValue(p1.x(), p1.y()) - geomDataAPI_Point2D( self.my.data().attribute("EndPoint") ).setValue(p2.x(), p2.y()) - self.my.execute() - - def __createByName(self, sketch, name): - """Initialise the feature by name of edge""" - self.my.data().selection("External").selectSubShape("EDGE", name) - self.my.execute() - rigid = sketch.addFeature("SketchConstraintRigid") - rigid.refattr("ConstraintEntityA").setObject( self.my.firstResult() ) - - def startPointData (self): - """Returns start point""" - return geomDataAPI_Point2D( self.my.data().attribute("StartPoint") ) - - def endPointData (self): - """Returns end point""" - return geomDataAPI_Point2D( self.my.data().attribute("EndPoint") ) - - def result (self): - """Returns result""" - return self.my.firstResult() - - -class Circle(): - """A class which represents a Circle object""" - - def __init__(self, sketch, x, y, r): - """Constructor""" - ### Create the feature - self.my = sketch.addFeature("SketchCircle") - geomDataAPI_Point2D( self.my.data().attribute("CircleCenter") ).setValue(x, y) - self.my.data().real("CircleRadius").setValue(r) - self.my.execute() - - def centerData (self): - """Returns center point""" - return geomDataAPI_Point2D( self.my.data().attribute("CircleCenter") ) - - def result (self): - """Returns result""" - return self.my.lastResult() # Returns the circular line attribute - - -- 2.39.2