From: vsv Date: Wed, 23 Sep 2015 12:43:16 +0000 (+0300) Subject: Documenting of Python code X-Git-Tag: 1.4.0_demo1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5cab19d5cfb4ff1491c09b6b67b93470fe5d2470;p=modules%2Fshaper.git Documenting of Python code --- diff --git a/src/GeomAlgoImpl/GEOMAlgo_Splitter.hxx b/src/GeomAlgoImpl/GEOMAlgo_Splitter.hxx index 0796e5579..234765aa2 100644 --- a/src/GeomAlgoImpl/GEOMAlgo_Splitter.hxx +++ b/src/GeomAlgoImpl/GEOMAlgo_Splitter.hxx @@ -48,51 +48,66 @@ //class : GEOMAlgo_Splitter //purpose : //======================================================================= -class GEOMAlgo_Splitter : public BOPAlgo_Builder +/*! + * \class GEOMAlgo_Splitter + * \ingroup DataAlgo + * A class for shapes partitioning + */ + class GEOMAlgo_Splitter : public BOPAlgo_Builder { public: - - GEOMALGOIMPL_EXPORT - GEOMAlgo_Splitter(); + /// Constructor + GEOMALGOIMPL_EXPORT GEOMAlgo_Splitter(); - GEOMALGOIMPL_EXPORT - GEOMAlgo_Splitter(const Handle(NCollection_BaseAllocator)& theAllocator); + /// Constructor + /// \param theAllocator an allocator object + GEOMALGOIMPL_EXPORT GEOMAlgo_Splitter(const Handle(NCollection_BaseAllocator)& theAllocator); - GEOMALGOIMPL_EXPORT - virtual ~GEOMAlgo_Splitter(); + GEOMALGOIMPL_EXPORT virtual ~GEOMAlgo_Splitter(); - GEOMALGOIMPL_EXPORT - void AddTool(const TopoDS_Shape& theShape); + /// Add a tool shape + /// \param theShape a tool shape + GEOMALGOIMPL_EXPORT void AddTool(const TopoDS_Shape& theShape); - GEOMALGOIMPL_EXPORT - const BOPCol_ListOfShape& Tools()const; + /// Returns list of tool shapes + GEOMALGOIMPL_EXPORT const BOPCol_ListOfShape& Tools()const; - GEOMALGOIMPL_EXPORT - void SetLimit(const TopAbs_ShapeEnum aLimit); + /// Set type of used shapes + /// \param aLimit a shape type + GEOMALGOIMPL_EXPORT void SetLimit(const TopAbs_ShapeEnum aLimit); - GEOMALGOIMPL_EXPORT - TopAbs_ShapeEnum Limit()const; + /// Returns defined limit type + GEOMALGOIMPL_EXPORT TopAbs_ShapeEnum Limit()const; - GEOMALGOIMPL_EXPORT - void SetLimitMode(const Standard_Integer aMode); + /// Set mode (0 or 1) of limit + /// \param aMode the mode value + GEOMALGOIMPL_EXPORT void SetLimitMode(const Standard_Integer aMode); - GEOMALGOIMPL_EXPORT - Standard_Integer LimitMode()const; + /// Returns mode of limit + GEOMALGOIMPL_EXPORT Standard_Integer LimitMode()const; - GEOMALGOIMPL_EXPORT - virtual void Clear(); + /// Clears all tool shapes + GEOMALGOIMPL_EXPORT virtual void Clear(); protected: - GEOMALGOIMPL_EXPORT - virtual void BuildResult(const TopAbs_ShapeEnum theType); + /// Build result. + /// \param theType a type of limit + GEOMALGOIMPL_EXPORT virtual void BuildResult(const TopAbs_ShapeEnum theType); - GEOMALGOIMPL_EXPORT - virtual void PostTreat(); + /// Post processing of the calculation + GEOMALGOIMPL_EXPORT virtual void PostTreat(); protected: + /// List of tools BOPCol_ListOfShape myTools; + + /// Map of tools BOPCol_MapOfShape myMapTools; + + /// A limit type TopAbs_ShapeEnum myLimit; + + /// A limit mode Standard_Integer myLimitMode; }; diff --git a/src/PythonAPI/extension/box.py b/src/PythonAPI/extension/box.py index 957da5412..3a6b641a5 100644 --- a/src/PythonAPI/extension/box.py +++ b/src/PythonAPI/extension/box.py @@ -11,6 +11,7 @@ class Box(modeler.Interface): """Executes the macro-feature Box. """ def __init__(self, part, dx, dy, dz): + """Constructor""" modeler.Interface.__init__(self, part, MY.ID()) self.setRealInput( MY.WIDTH_ID(), dx ) diff --git a/src/PythonAPI/geom/missed.py b/src/PythonAPI/geom/missed.py index 0aa6db1e3..f5a6cfca8 100644 --- a/src/PythonAPI/geom/missed.py +++ b/src/PythonAPI/geom/missed.py @@ -6,20 +6,29 @@ from GeomAPI import * class Ax3: + """A class to represent a Coordinate system object""" def __init__(self, origin, normal, dirx): + """Constructor""" + ### Create an origin point self.o = origin + ### Create a normal vector self.n = normal + ### Create X axis direction self.dx = dirx def location (self): + """Returns origin point""" return self.o def direction (self): + """Returns normal direction""" return self.n def xDirection (self): + """Returns direction of X axis""" return self.dx def yDirection (self): + """Returns direction of Y axis""" return self.n.cross(self.dx) diff --git a/src/PythonAPI/modeler/boolean.py b/src/PythonAPI/modeler/boolean.py index adc8d6613..23b83a42b 100644 --- a/src/PythonAPI/modeler/boolean.py +++ b/src/PythonAPI/modeler/boolean.py @@ -10,6 +10,8 @@ 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) @@ -22,27 +24,30 @@ class 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): - """Inserts an addition to the given Part and executes the operation. - This operation adds tool to the given object. - """ + """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): - """Inserts a subtraction to the given Part and executes the operation. - This operation subtracts tool to the given object. - """ + """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): - """Inserts an intersection to the given Part and executes the operation. - This operation intersects tool to the given object. - """ + """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 index 9b9b6de32..4fcc37106 100644 --- a/src/PythonAPI/modeler/extrusion.py +++ b/src/PythonAPI/modeler/extrusion.py @@ -7,9 +7,10 @@ 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()) diff --git a/src/PythonAPI/modeler/part.py b/src/PythonAPI/modeler/part.py index 597d1cc75..52632c3c6 100644 --- a/src/PythonAPI/modeler/part.py +++ b/src/PythonAPI/modeler/part.py @@ -7,9 +7,11 @@ import modeler # Required by the temporary implementation of result member f 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() diff --git a/src/PythonAPI/modeler/roots.py b/src/PythonAPI/modeler/roots.py index 62288ebb3..181fd7efc 100644 --- a/src/PythonAPI/modeler/roots.py +++ b/src/PythonAPI/modeler/roots.py @@ -10,15 +10,19 @@ 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) @@ -29,13 +33,18 @@ 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 index c9737224e..c3bad7c5c 100644 --- a/src/PythonAPI/modeler/sketcher.py +++ b/src/PythonAPI/modeler/sketcher.py @@ -9,6 +9,7 @@ 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. @@ -16,8 +17,10 @@ class Sketch(): - a 3D axis system (geom.Ax3), - an existing face identified by its topological name. """ + ### Create a feature object self.my = featureToCompositeFeature( doc.addFeature("Sketch") ) - self.selection = None # Entities used for building the result shape + ### 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) @@ -174,22 +177,30 @@ class Sketch(): # 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) @@ -201,43 +212,54 @@ class Line(): 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 diff --git a/src/PythonAddons/addons_Features.py b/src/PythonAddons/addons_Features.py index 90b23b9a9..0c92f1be1 100644 --- a/src/PythonAddons/addons_Features.py +++ b/src/PythonAddons/addons_Features.py @@ -6,14 +6,17 @@ from macros.box.feature import BoxFeature class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin): +"""Implementation of features plugin""" def __init__(self): + """Constructor""" ModelAPI.ModelAPI_Plugin.__init__(self) aSession = ModelAPI.ModelAPI_Session.get() aSession.registerPlugin(self) pass def createFeature(self, theFeatureID): + """Create a feature by its Id""" aFeature = None if theFeatureID == BoxFeature.ID(): @@ -24,6 +27,6 @@ class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin): return aFeature - +### The plugin object plugin = PythonFeaturesPlugin() plugin.__disown__() diff --git a/src/PythonAddons/macros/box/feature.py b/src/PythonAddons/macros/box/feature.py index d5d5e8e07..1f581be4a 100644 --- a/src/PythonAddons/macros/box/feature.py +++ b/src/PythonAddons/macros/box/feature.py @@ -8,37 +8,43 @@ import geom class BoxFeature(modeler.Feature): - + """An example of Box feature implementation""" # Initializations def __init__(self): + """Constructor""" modeler.Feature.__init__(self) @staticmethod def ID(): + """Return Id of the feature""" return "Box" @staticmethod def WIDTH_ID(): + """Returns ID of Width parameter""" return "width" @staticmethod def LENGTH_ID(): + """Returns ID of Length parameter""" return "length" @staticmethod def HEIGHT_ID(): + """Returns ID of Height parameter""" return "height" def getKind(self): + """Returns ID of еру ауфегку""" return BoxFeature.ID() # Creation of the box at default size def initAttributes(self): - + """Initialise attributes of the feature""" # Creating the input arguments of the feature self.addRealInput( self.WIDTH_ID() ) self.addRealInput( self.LENGTH_ID() ) @@ -48,6 +54,7 @@ class BoxFeature(modeler.Feature): mypart = modeler.activeDocument() xoy = modeler.defaultPlane("XOY") + ### A base of the geometry self.base = modeler.addSketch( mypart, xoy ) p1 = geom.Pnt2d( 0, 0 ) @@ -62,16 +69,20 @@ class BoxFeature(modeler.Feature): self.base.setPerpendicular( line[0].result(), line[3].result() ) # Setting the size of the base with default values + ### Width self.width = self.base.setLength( line[0].result(), 50 ) # Keeps the constraint for edition + ### Length self.length = self.base.setLength( line[3].result(), 50 ) # Keeps the constraint for edition # Creating the extrusion (the box) at default size + ### A box result self.box = modeler.addExtrusion( mypart, self.base.selectFace(), 50 ) # Edition of the box at user size def execute(self): + """Compute the feature result""" # Retrieving the user inputs width = self.getRealInput( self.WIDTH_ID() ) length = self.getRealInput( self.LENGTH_ID() ) @@ -86,5 +97,6 @@ class BoxFeature(modeler.Feature): #self.addResult( self.box.result() ) def isMacro(self): + """Returns True""" # Box feature is macro: removes itself on the creation transaction finish return True