# Create a sketch with circle to extrude
#=========================================================================
aSession.startOperation()
-aCircleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX"))
# Create a sketch with triangle to extrude
#=========================================================================
aSession.startOperation()
-aTriangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
# Create a sketch circle to extrude
#=========================================================================
aSession.startOperation()
-aSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
# Create a sketch with triangle and extrude it
#=========================================================================
aSession.startOperation()
-aTriangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch"))
+aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
{
return std::dynamic_pointer_cast<T1>(theObject);
}
-
+
%}
// to avoid error on this
#define MODELAPI_EXPORT
// standard definitions
-%include "typemaps.i"
%include "GeomAPI.i"
+%include "typemaps.i"
%include "std_string.i"
%include "std_list.i"
%include "std_shared_ptr.i"
// std::dynamic_pointer_cast
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>;
+%template(featureToCompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
+%template(objectToFeature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
+%template(compositeFeatureToFeature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_CompositeFeature>;
%template(modelAPI_Result) shared_ptr_cast<ModelAPI_Result, ModelAPI_Object>;
%template(modelAPI_ResultConstruction) shared_ptr_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
+"""
+"""
+
import ModelAPI
from PythonFeaturesPlugin_Box import PythonFeaturesPlugin_Box
def __init__(self):
ModelAPI.ModelAPI_Plugin.__init__(self)
+ aSession = ModelAPI.ModelAPI_Session.get()
+ aSession.registerPlugin(self)
pass
def createFeature(self, theFeatureID):
+ aFeature = None
if theFeatureID == PythonFeaturesPlugin_Box.ID():
- return PythonFeaturesPlugin_Box().__disown__()
+ aCompositeFeature = PythonFeaturesPlugin_Box().__disown__()
+ aFeature = ModelAPI.compositeFeatureToFeature(aCompositeFeature)
else:
raise StandardError("No such feature %s" % theFeatureID)
+ return aFeature
+
plugin = PythonFeaturesPlugin()
-aSession = ModelAPI.ModelAPI_Session.get()
-print "Module loaded. Session", aSession
-aSession.registerPlugin(plugin)
+plugin.__disown__()
import sketch
-class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature):
-
- "Feature to create a box by drawing a sketch and extruding it"
+class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_CompositeFeature):
+ """Feature to create a box by drawing a sketch and extruding it
+ """
def __init__(self):
- ModelAPI.ModelAPI_Feature.__init__(self)
+ ModelAPI.ModelAPI_CompositeFeature.__init__(self)
@staticmethod
def ID():
aSession.validators().registerNotObligatory(self.getKind(), self.LENGTH_REF_ID())
aSession.validators().registerNotObligatory(self.getKind(), self.HEIGHT_REF_ID())
aSession.validators().registerConcealment(self.getKind(), self.HEIGHT_REF_ID())
- self.mySketch = None # not yet initialized
- self.myExtrusion = None # not yet initialized
+ self.mySketch = None # not yet initialized
+ self.myExtrusion = None # not yet initialized
def execute(self):
aWidth = self.real(self.WIDTH_ID()).value()
aResult = extrusion.getBody(self.makeBox(aLength, aWidth, aHeight))
else:
aHeightProxyResult = ModelAPI.modelAPI_Result(aHeightRefValue)
- aWidthFeature = ModelAPI.modelAPI_Feature(aWidthRefValue)
- aLengthFeature = ModelAPI.modelAPI_Feature(aLengthRefValue)
+ aWidthFeature = ModelAPI.objectToFeature(aWidthRefValue)
+ aLengthFeature = ModelAPI.objectToFeature(aLengthRefValue)
aHeightResult = ModelAPI.modelAPI_ResultBody(aHeightProxyResult)
aWidthFeature.real("ConstraintValue").setValue(aWidth)
aLengthFeature.real("ConstraintValue").setValue(aLength)
# create a new result with copied shape from extrusion
aResultBody = self.document().createBody(self.data())
if not aResult is None:
- aResultBody.store(aResult.shape())
- self.setResult(aResultBody)
+ aResultBody.store(aResult.shape())
+ self.setResult(aResultBody)
pass
def makeBox(self, aWidth, aLength, aHeight):
aPart = aSession.activeDocument()
# Starting the Sketch
aSketch = sketch.addTo(aPart)
- self.mySketch = sketch
+ self.mySketch = aSketch
sketch.setXOYPlane(aSketch)
# Creating the lines
l1 = sketch.addLine(10, 10, 10, 60, aSketch)
self.reference(self.HEIGHT_REF_ID()).setValue(aHeightFeature.firstResult())
return aHeightFeature
+ def addFeature(self, theID):
+ pass
+
+ def numberOfSubs(self):
+ subsCount = 0
+ if not self.mySketch is None:
+ subsCount += 1
+ if not self.myExtrusion is None:
+ subsCount += 1
+ # extrusion and sketch
+ return subsCount
+
+ def subFeature(self, theIndex):
+ if theIndex == 1: # sketch
+ return ModelAPI.compositeFeatureToFeature(self.mySketch)
+ return self.myExtrusion
+
+ def subFeatureId(self, theIndex):
+ return 0
+
+ def isSub(self, theFeature):
+ return theFeature == self.mySketch or theFeature == self.myExtrusion
# TEST
"""
# ----------------------------
def addTo(doc):
- return modelAPI_CompositeFeature(doc.addFeature("Sketch"))
+ return featureToCompositeFeature(doc.addFeature("Sketch"))
def setXOYPlane(sketch):
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
aSession.startOperation()
#aSketchFeature = aDocument.addFeature("Sketch")
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
assert (aSketchFeature.getKind() == "Sketch")
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
#=========================================================================
aSession.startOperation()
aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))