From: sbh Date: Wed, 18 Mar 2015 14:11:56 +0000 (+0300) Subject: Implementation of Box python feature as a Composite feature again X-Git-Tag: V_1.0.2~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6b415e1bff151319a42beadc4931f388322d310d;p=modules%2Fshaper.git Implementation of Box python feature as a Composite feature again --- diff --git a/src/FeaturesPlugin/Test/TestBoolean.py b/src/FeaturesPlugin/Test/TestBoolean.py index ab00fa3f4..525b08cda 100644 --- a/src/FeaturesPlugin/Test/TestBoolean.py +++ b/src/FeaturesPlugin/Test/TestBoolean.py @@ -32,7 +32,7 @@ aSession.finishOperation() # 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")) @@ -51,7 +51,7 @@ aSession.finishOperation() # 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")) diff --git a/src/FeaturesPlugin/Test/TestExtrusion.py b/src/FeaturesPlugin/Test/TestExtrusion.py index 9edca8a3b..4714bcfcc 100644 --- a/src/FeaturesPlugin/Test/TestExtrusion.py +++ b/src/FeaturesPlugin/Test/TestExtrusion.py @@ -37,7 +37,7 @@ aPart = aPartResult.partDoc() # 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")) diff --git a/src/FeaturesPlugin/Test/TestGroup.py b/src/FeaturesPlugin/Test/TestGroup.py index e888ff654..6a773ce1b 100644 --- a/src/FeaturesPlugin/Test/TestGroup.py +++ b/src/FeaturesPlugin/Test/TestGroup.py @@ -28,7 +28,7 @@ aSession.finishOperation() # 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")) diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 77a0f42e0..bd8cc724a 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -47,15 +47,15 @@ { return std::dynamic_pointer_cast(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" @@ -134,8 +134,9 @@ // std::dynamic_pointer_cast template std::shared_ptr shared_ptr_cast(std::shared_ptr theObject); -%template(modelAPI_CompositeFeature) shared_ptr_cast; -%template(modelAPI_Feature) shared_ptr_cast; +%template(featureToCompositeFeature) shared_ptr_cast; +%template(objectToFeature) shared_ptr_cast; +%template(compositeFeatureToFeature) shared_ptr_cast; %template(modelAPI_Result) shared_ptr_cast; %template(modelAPI_ResultConstruction) shared_ptr_cast; diff --git a/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py b/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py index ca671e144..890b3ae15 100644 --- a/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py +++ b/src/PythonFeaturesPlugin/PythonFeaturesPlugin.py @@ -1,3 +1,6 @@ +""" +""" + import ModelAPI from PythonFeaturesPlugin_Box import PythonFeaturesPlugin_Box @@ -6,15 +9,19 @@ class PythonFeaturesPlugin(ModelAPI.ModelAPI_Plugin): 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__() diff --git a/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py b/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py index a8b79c9ea..2487a6ee8 100644 --- a/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py +++ b/src/PythonFeaturesPlugin/PythonFeaturesPlugin_Box.py @@ -5,12 +5,12 @@ import extrusion 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(): @@ -57,8 +57,8 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature): 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() @@ -72,8 +72,8 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature): 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) @@ -84,8 +84,8 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature): # 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): @@ -93,7 +93,7 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature): 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) @@ -123,6 +123,28 @@ class PythonFeaturesPlugin_Box(ModelAPI.ModelAPI_Feature): 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 """ diff --git a/src/PythonFeaturesPlugin/sketch.py b/src/PythonFeaturesPlugin/sketch.py index ca13a707d..39475c048 100644 --- a/src/PythonFeaturesPlugin/sketch.py +++ b/src/PythonFeaturesPlugin/sketch.py @@ -6,7 +6,7 @@ from GeomDataAPI import * # ---------------------------- def addTo(doc): - return modelAPI_CompositeFeature(doc.addFeature("Sketch")) + return featureToCompositeFeature(doc.addFeature("Sketch")) def setXOYPlane(sketch): diff --git a/src/SketchPlugin/Test/TestConstraintConcidence.py b/src/SketchPlugin/Test/TestConstraintConcidence.py index 5256acb2d..79589ac4c 100644 --- a/src/SketchPlugin/Test/TestConstraintConcidence.py +++ b/src/SketchPlugin/Test/TestConstraintConcidence.py @@ -31,7 +31,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index f57728799..13aeada6f 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -45,7 +45,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestConstraintLength.py b/src/SketchPlugin/Test/TestConstraintLength.py index 12915b42e..4dc391889 100644 --- a/src/SketchPlugin/Test/TestConstraintLength.py +++ b/src/SketchPlugin/Test/TestConstraintLength.py @@ -24,7 +24,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestConstraintParallel.py b/src/SketchPlugin/Test/TestConstraintParallel.py index ce2dcea47..965193b4e 100644 --- a/src/SketchPlugin/Test/TestConstraintParallel.py +++ b/src/SketchPlugin/Test/TestConstraintParallel.py @@ -24,7 +24,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestConstraintPerpendicular.py b/src/SketchPlugin/Test/TestConstraintPerpendicular.py index 435b7d8c4..64e15c899 100644 --- a/src/SketchPlugin/Test/TestConstraintPerpendicular.py +++ b/src/SketchPlugin/Test/TestConstraintPerpendicular.py @@ -31,7 +31,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestConstraintRadius.py b/src/SketchPlugin/Test/TestConstraintRadius.py index 8adb6082d..175823e1e 100644 --- a/src/SketchPlugin/Test/TestConstraintRadius.py +++ b/src/SketchPlugin/Test/TestConstraintRadius.py @@ -33,7 +33,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestConstraintRigid.py b/src/SketchPlugin/Test/TestConstraintRigid.py index 47dfadf51..e00acda2c 100644 --- a/src/SketchPlugin/Test/TestConstraintRigid.py +++ b/src/SketchPlugin/Test/TestConstraintRigid.py @@ -31,7 +31,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestHighload.py b/src/SketchPlugin/Test/TestHighload.py index f8fed6087..819cb00a5 100644 --- a/src/SketchPlugin/Test/TestHighload.py +++ b/src/SketchPlugin/Test/TestHighload.py @@ -90,7 +90,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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")) diff --git a/src/SketchPlugin/Test/TestSketchArcCircle.py b/src/SketchPlugin/Test/TestSketchArcCircle.py index 9835bf2cc..9927598a6 100644 --- a/src/SketchPlugin/Test/TestSketchArcCircle.py +++ b/src/SketchPlugin/Test/TestSketchArcCircle.py @@ -32,7 +32,7 @@ aDocument = aSession.moduleDocument() 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")) diff --git a/src/SketchPlugin/Test/TestSketchPointLine.py b/src/SketchPlugin/Test/TestSketchPointLine.py index df3f7cd64..cbf0d05bf 100644 --- a/src/SketchPlugin/Test/TestSketchPointLine.py +++ b/src/SketchPlugin/Test/TestSketchPointLine.py @@ -13,7 +13,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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) diff --git a/src/SketchPlugin/Test/TestSnowflake.py b/src/SketchPlugin/Test/TestSnowflake.py index 65b421354..4a0a31e53 100644 --- a/src/SketchPlugin/Test/TestSnowflake.py +++ b/src/SketchPlugin/Test/TestSnowflake.py @@ -104,7 +104,7 @@ aDocument = aSession.moduleDocument() #========================================================================= 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"))