Config
)
SET(CMAKE_SWIG_FLAGS -threads -Wall)
-ADD_DEFINITIONS(-DMODELAPI_EXPORTS -DSWIG_TYPE_TABLE=ModelAPI)
+ADD_DEFINITIONS(-DMODELAPI_EXPORT)
ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX)
%template(ObjectList) std::list<std::shared_ptr<ModelAPI_Object> >;
%template(ResultList) std::list<std::shared_ptr<ModelAPI_Result> >;
-template<class T1, class T2> boost::shared_ptr<T1> boost_cast(boost::shared_ptr<T2> theObject);
-
-// Feature casts
-%template(modelAPI_Feature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
-%template(modelAPI_CompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr<T2> theObject);
%template(modelAPI_CompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
+%template(modelAPI_Feature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
+// Result casts
%template(modelAPI_ResultConstruction) shared_ptr_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
%template(modelAPI_ResultBody) shared_ptr_cast<ModelAPI_ResultBody, ModelAPI_Result>;
%template(modelAPI_ResultPart) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_Result>;
-// Result casts
-%template(modelAPI_ResultConstruction) boost_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
-%template(modelAPI_ResultBody) boost_cast<ModelAPI_ResultBody, ModelAPI_Result>;
-%template(modelAPI_ResultPart) boost_cast<ModelAPI_ResultPart, ModelAPI_Result>;
-
// Attribute casts
-%template(modelAPI_AttributeDocRef) boost_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;
-%template(modelAPI_AttributeDouble) boost_cast<ModelAPI_AttributeDouble, ModelAPI_Attribute>;
-%template(modelAPI_AttributeInteger) boost_cast<ModelAPI_AttributeInteger, ModelAPI_Attribute>;
-%template(modelAPI_AttributeString) boost_cast<ModelAPI_AttributeString, ModelAPI_Attribute>;
-%template(modelAPI_AttributeReference) boost_cast<ModelAPI_AttributeReference, ModelAPI_Attribute>;
-%template(modelAPI_AttributeRefAttr) boost_cast<ModelAPI_AttributeRefAttr, ModelAPI_Attribute>;
-%template(modelAPI_AttributeBoolean) boost_cast<ModelAPI_AttributeBoolean, ModelAPI_Attribute>;
-%template(modelAPI_AttributeSelection) boost_cast<ModelAPI_AttributeSelection, ModelAPI_Attribute>;
-%template(modelAPI_AttributeSelectionList) boost_cast<ModelAPI_AttributeSelectionList, ModelAPI_Attribute>;
-%template(modelAPI_AttributeRefList) boost_cast<ModelAPI_AttributeRefList, ModelAPI_Attribute>;
+%template(modelAPI_AttributeDocRef) shared_ptr_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;
+%template(modelAPI_AttributeDouble) shared_ptr_cast<ModelAPI_AttributeDouble, ModelAPI_Attribute>;
+%template(modelAPI_AttributeInteger) shared_ptr_cast<ModelAPI_AttributeInteger, ModelAPI_Attribute>;
+%template(modelAPI_AttributeString) shared_ptr_cast<ModelAPI_AttributeString, ModelAPI_Attribute>;
+%template(modelAPI_AttributeReference) shared_ptr_cast<ModelAPI_AttributeReference, ModelAPI_Attribute>;
+%template(modelAPI_AttributeRefAttr) shared_ptr_cast<ModelAPI_AttributeRefAttr, ModelAPI_Attribute>;
+%template(modelAPI_AttributeBoolean) shared_ptr_cast<ModelAPI_AttributeBoolean, ModelAPI_Attribute>;
+%template(modelAPI_AttributeSelection) shared_ptr_cast<ModelAPI_AttributeSelection, ModelAPI_Attribute>;
+%template(modelAPI_AttributeSelectionList) shared_ptr_cast<ModelAPI_AttributeSelectionList, ModelAPI_Attribute>;
+%template(modelAPI_AttributeRefList) shared_ptr_cast<ModelAPI_AttributeRefList, ModelAPI_Attribute>;
MODELAPI_EXPORT virtual bool isObject() = 0;
/// Defines the reference to the attribute
- MODELAPI_EXPORT virtual void setAttr(std::shared_ptr<ModelAPI_Attribute> theAttr) = 0;
+ MODELAPI_EXPORT virtual void setAttr(AttributePtr theAttr) = 0;
/// Returns attribute referenced from this attribute
- MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attr() = 0;
+ MODELAPI_EXPORT virtual AttributePtr attr() = 0;
/// Defines the reference to the object
MODELAPI_EXPORT virtual void setObject(ObjectPtr theFeature) = 0;
import ModelAPI
-import examples
+import sketch
+import extrusion
+from SketchResult import SketchResult
class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
def HEIGHT_ID():
return "box_height"
+ @staticmethod
+ def WIDTH_REF_ID():
+ return "box_ref_width"
+
+ @staticmethod
+ def LENGTH_REF_ID():
+ return "box_ref_length"
+
+ @staticmethod
+ def HEIGHT_REF_ID():
+ return "box_ref_height"
+
def getKind(self):
return PythonFeaturesPlugin_Box.ID()
def initAttributes(self):
# C++ static methods (in example "type()" of the ModelAPI_AttributeDouble
# should be called like this: moduleName.ClassName_staticMethod()
- self.data().addAttribute(PythonFeaturesPlugin_Box.WIDTH_ID(),
- ModelAPI.ModelAPI_AttributeDouble_type())
- self.data().addAttribute(PythonFeaturesPlugin_Box.LENGTH_ID(),
- ModelAPI.ModelAPI_AttributeDouble_type())
- self.data().addAttribute(PythonFeaturesPlugin_Box.HEIGHT_ID(),
- ModelAPI.ModelAPI_AttributeDouble_type())
+ self.data().addAttribute(self.WIDTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+ self.data().addAttribute(self.LENGTH_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+ self.data().addAttribute(self.HEIGHT_ID(), ModelAPI.ModelAPI_AttributeDouble_type())
+ self.data().addAttribute(self.WIDTH_REF_ID(), ModelAPI.ModelAPI_AttributeReference_type())
+ self.data().addAttribute(self.LENGTH_REF_ID(), ModelAPI.ModelAPI_AttributeReference_type())
+ self.data().addAttribute(self.HEIGHT_REF_ID(), ModelAPI.ModelAPI_AttributeReference_type())
+ aSession = ModelAPI.ModelAPI_Session.get()
+ aSession.validators().registerNotObligatory(self.getKind(), self.WIDTH_REF_ID());
+ aSession.validators().registerNotObligatory(self.getKind(), self.LENGTH_REF_ID());
+ aSession.validators().registerNotObligatory(self.getKind(), self.HEIGHT_REF_ID());
def execute(self):
- aWidth = self.real(PythonFeaturesPlugin_Box.WIDTH_ID()).value()
- aLength = self.real(PythonFeaturesPlugin_Box.LENGTH_ID()).value()
- aHeight = self.real(PythonFeaturesPlugin_Box.HEIGHT_ID()).value()
- print ("Box W:{0} L:{1} H:{2}".format(aWidth, aLength, aHeight))
- aResultBody = self.document().createBody(self.data())
- aResult = examples.makeBox(aLength, aWidth, aHeight)
- #aShape = modelAPI_ResultConstruction(aResult).shape()
- # aResultBody.store(aShape)
- self.setResult(aResultBody)
+ aWidth = self.real(self.WIDTH_ID()).value()
+ aLength = self.real(self.LENGTH_ID()).value()
+ aHeight = self.real(self.HEIGHT_ID()).value()
+ aWidthFeature = ModelAPI.modelAPI_Feature(self.reference(self.WIDTH_REF_ID()).value())
+ aLengthFeature = ModelAPI.modelAPI_Feature(self.reference(self.LENGTH_REF_ID()).value())
+ aHeightFeature = ModelAPI.modelAPI_Feature(self.reference(self.HEIGHT_REF_ID()).value())
+ aResult = None
+ if not all((aWidthFeature, aLengthFeature, aLengthFeature)):
+ aResult = extrusion.getBody(self.makeBox(aLength, aWidth, aHeight))
+ else:
+ aWidthFeature.real("ConstraintValue").setValue(aWidth)
+ aLengthFeature.real("ConstraintValue").setValue(aLength)
+ aHeightFeature.real("extrusion_size").setValue(aHeight)
+ aResult = extrusion.getBody(aHeightFeature)
+ self.setResult(aResult)
+
+ def makeBox(self, aWidth, aLength, aHeight):
+ aSession = ModelAPI.ModelAPI_Session.get()
+ aPart = aSession.activeDocument()
+ # Starting the Sketch
+ aSketch = sketch.addTo(aPart)
+ sketch.setXOYPlane(aSketch)
+ # Creating the lines
+ l1 = sketch.addLine(10, 10, 10, 50, aSketch)
+ l2 = sketch.addLine(10, 50, 60, 60, aSketch)
+ l3 = sketch.addLine(60, 60, 50, 10, aSketch)
+ l4 = sketch.addLine(50, 10, 10, 10, aSketch)
+ aSketch.execute()
+ # Creating the constraints
+ sketch.makeCoincident(sketch.getEndPoint(l1), sketch.getStartPoint(l2), aSketch)
+ sketch.makeCoincident(sketch.getEndPoint(l2), sketch.getStartPoint(l3), aSketch)
+ sketch.makeCoincident(sketch.getEndPoint(l3), sketch.getStartPoint(l4), aSketch)
+ sketch.makeCoincident(sketch.getEndPoint(l4), sketch.getStartPoint(l1), aSketch)
+ sketch.makeParallel(sketch.getGeometry(l1), sketch.getGeometry(l3), aSketch)
+ sketch.makeParallel(sketch.getGeometry(l2), sketch.getGeometry(l4), aSketch)
+ sketch.makePerpendicular(sketch.getGeometry(l1), sketch.getGeometry(l4), aSketch)
+ # Set to 0X and 0Y lines defined length
+ aWidthFeature = sketch.makeConstantLength(sketch.getGeometry(l4), aWidth, aSketch)
+ aLengthFeature = sketch.makeConstantLength(sketch.getGeometry(l1), aLength, aSketch)
+ # Finalisation of the operation
+ builder = SketchResult(aSketch)
+ # Creating a feature Extrusion
+ aHeightFeature = extrusion.addNew(builder, aHeight, aPart)
+ # Store features...
+ self.reference(self.WIDTH_REF_ID()).setValue(aWidthFeature)
+ self.reference(self.LENGTH_REF_ID()).setValue(aLengthFeature)
+ self.reference(self.HEIGHT_REF_ID()).setValue(aHeightFeature)
+ return aHeightFeature
+
# TEST
"""
<source>
- <doublevalue id="box_width" label="Width" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set width of the box">
+ <doublevalue id="box_width" label="Width" min="0" step="1.0" default="50" icon=":icons/dimension_v.png" tooltip="Set width of the box">
<validator id="GeomValidators_Positive"/>
</doublevalue>
- <doublevalue id="box_length" label="Length" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set length of the box">
+ <doublevalue id="box_length" label="Length" min="0" step="1.0" default="50" icon=":icons/dimension_v.png" tooltip="Set length of the box">
<validator id="GeomValidators_Positive"/>
</doublevalue>
- <doublevalue id="box_height" label="Height" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set height of the box">
+ <doublevalue id="box_height" label="Height" min="0" step="1.0" default="50" icon=":icons/dimension_v.png" tooltip="Set height of the box">
<validator id="GeomValidators_Positive"/>
</doublevalue>
</source>
base.execute()
# Creating the constraints
- # NOTE : the following lines are currently not working in BR_PYTHON_PLUGIN
- # branch
- # sketch.makeCoincident(sketch.getEndPoint(l1), sketch.getStartPoint(l2), base)
- # sketch.makeCoincident(sketch.getEndPoint(l2), sketch.getStartPoint(l3), base)
- # sketch.makeCoincident(sketch.getEndPoint(l3), sketch.getStartPoint(l4), base)
- # sketch.makeCoincident(sketch.getEndPoint(l4), sketch.getStartPoint(l1), base)
- #
- # sketch.makeParallel(sketch.getGeometry(l1), sketch.getGeometry(l3))
- # sketch.makeParallel(sketch.getGeometry(l2), sketch.getGeometry(l4))
- #
- # sketch.makePerpendicular(sketch.getGeometry(l1), sketch.getGeometry(l4))
+ sketch.makeCoincident(sketch.getEndPoint(l1),
+ sketch.getStartPoint(l2), base)
+ sketch.makeCoincident(sketch.getEndPoint(l2),
+ sketch.getStartPoint(l3), base)
+ sketch.makeCoincident(sketch.getEndPoint(l3),
+ sketch.getStartPoint(l4), base)
+ sketch.makeCoincident(sketch.getEndPoint(l4),
+ sketch.getStartPoint(l1), base)
+
+ sketch.makeParallel(sketch.getGeometry(l1), sketch.getGeometry(l3), base)
+ sketch.makeParallel(sketch.getGeometry(l2), sketch.getGeometry(l4), base)
+
+ sketch.makePerpendicular(sketch.getGeometry(l1),
+ sketch.getGeometry(l4), base)
+ # Set to 0X and 0Y lines defined length
+ sketch.makeConstantLength(sketch.getGeometry(l1), aLength, base)
+ sketch.makeConstantLength(sketch.getGeometry(l4), aWidth, base)
# Finalisation of the operation
builder = SketchResult(base)
# Creating a feature Extrusion
- box = extrusion.addNew(builder, 50, part)
+ box = extrusion.addNew(builder, aHeight, part)
# return base.lastResult()
return extrusion.getBody(box)
def getBody(extrusion):
- return extrusion.firstResult()
+ return modelAPI_ResultBody(extrusion.firstResult())
constraint = sketch.addFeature("SketchConstraintCoincidence")
constraint.refattr("ConstraintEntityA").setAttr(p1)
constraint.refattr("ConstraintEntityB").setAttr(p2)
+ return constraint
def makeParallel(l1, l2, sketch):
constraint = sketch.addFeature("SketchConstraintParallel")
constraint.refattr("ConstraintEntityA").setObject(l1)
constraint.refattr("ConstraintEntityB").setObject(l2)
+ return constraint
def makePerpendicular(l1, l2, sketch):
constraint = sketch.addFeature("SketchConstraintPerpendicular")
constraint.refattr("ConstraintEntityA").setObject(l1)
constraint.refattr("ConstraintEntityB").setObject(l2)
+ return constraint
def makeConstantLength(line, length, sketch):
constraint = sketch.addFeature("SketchConstraintLength")
constraint.refattr("ConstraintEntityA").setObject(line)
constraint.real("ConstraintValue").setValue(length)
+ return constraint