//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;
};
"""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 )
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)
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)
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
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())
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()
"""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)
"""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
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.
- 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)
# 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)
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
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():
return aFeature
-
+### The plugin object
plugin = PythonFeaturesPlugin()
plugin.__disown__()
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() )
mypart = modeler.activeDocument()
xoy = modeler.defaultPlane("XOY")
+ ### A base of the geometry
self.base = modeler.addSketch( mypart, xoy )
p1 = geom.Pnt2d( 0, 0 )
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() )
#self.addResult( self.box.result() )
def isMacro(self):
+ """Returns True"""
# Box feature is macro: removes itself on the creation transaction finish
return True