From: dbv Date: Wed, 10 Aug 2016 14:23:14 +0000 (+0300) Subject: Issue #1648: Dump Python in the High Level Parameterized Geometry API X-Git-Tag: V_2.5.0~137^2~76 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=52d0316f10282e32d25503cd3e26fd7cc6e3450d;p=modules%2Fshaper.git Issue #1648: Dump Python in the High Level Parameterized Geometry API Dump for FeaturesAPI_Extrusion with nested sketch --- diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp index f2dd6e6d7..75635c73d 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp @@ -8,6 +8,7 @@ #include #include +#include #include //================================================================================================== @@ -106,15 +107,26 @@ FeaturesAPI_Extrusion::FeaturesAPI_Extrusion(const std::shared_ptrsetValue(theSketch.feature()); + mybaseObjects->clear(); + mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr()); + + execIfBaseNotEmpty(); } //================================================================================================== void FeaturesAPI_Extrusion::setBase(const std::list& theBaseObjects) { + mysketch->setValue(ObjectPtr()); + mybaseObjects->clear(); fillAttribute(theBaseObjects, mybaseObjects); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -122,7 +134,7 @@ void FeaturesAPI_Extrusion::setDirection(const ModelHighAPI_Selection& theDirect { fillAttribute(theDirection, mydirection); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -133,7 +145,7 @@ void FeaturesAPI_Extrusion::setSizes(const ModelHighAPI_Double& theToSize, fillAttribute(theToSize, mytoSize); fillAttribute(theFromSize, myfromSize); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -143,7 +155,7 @@ void FeaturesAPI_Extrusion::setSize(const ModelHighAPI_Double& theSize) fillAttribute(theSize, mytoSize); fillAttribute(ModelHighAPI_Double(), myfromSize); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -158,7 +170,7 @@ void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& th fillAttribute(theFromObject, myfromObject); fillAttribute(theFromOffset, myfromOffset); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -167,10 +179,10 @@ void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const FeaturePtr aBase = feature(); const std::string& aDocName = theDumper.name(aBase->document()); - AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID()); - AttributeSelectionPtr aDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID()); + AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID()); + AttributeSelectionPtr anAttrDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID()); - theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anObjects << ", " << aDirection; + theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anAttrObjects << ", " << anAttrDirection; std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value(); @@ -189,6 +201,18 @@ void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const } theDumper << ")" << std::endl; + + AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_CompositeSketch::SKETCH_ID()); + if(anAttrSketch->isInitialized()) { + theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")"; + } +} + +void FeaturesAPI_Extrusion::execIfBaseNotEmpty() +{ + if(mybaseObjects->size() > 0) { + execute(); + } } //================================================================================================== diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.h b/src/FeaturesAPI/FeaturesAPI_Extrusion.h index 456da2c04..e4a31b18c 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.h +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.h @@ -15,6 +15,7 @@ #include class ModelHighAPI_Double; +class ModelHighAPI_Reference; class ModelHighAPI_Selection; /// \class FeaturesAPI_Extrusion @@ -77,7 +78,8 @@ public: FEATURESAPI_EXPORT virtual ~FeaturesAPI_Extrusion(); - INTERFACE_10(FeaturesPlugin_Extrusion::ID(), + INTERFACE_11(FeaturesPlugin_Extrusion::ID(), + sketch, FeaturesPlugin_Extrusion::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch object */, baseObjects, FeaturesPlugin_Extrusion::BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Base objects */, creationMethod, FeaturesPlugin_Extrusion::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, toSize, FeaturesPlugin_Extrusion::TO_SIZE_ID(), ModelAPI_AttributeDouble, /** To size */, @@ -89,6 +91,10 @@ public: direction, FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection, /** Direction */, sketchLauncher, FeaturesPlugin_Extrusion::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */) + /// Modify base attribute of the feature. + FEATURESAPI_EXPORT + void setNestedSketch(const ModelHighAPI_Reference& theSketch); + /// Modify base attribute of the feature. FEATURESAPI_EXPORT void setBase(const std::list& theBaseObjects); @@ -115,6 +121,9 @@ public: /// Dump wrapped feature FEATURESAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; + +private: + void execIfBaseNotEmpty(); }; /// Pointer on Extrusion object. diff --git a/src/ModelHighAPI/ModelHighAPI_Reference.cpp b/src/ModelHighAPI/ModelHighAPI_Reference.cpp index 3e13a0b46..20a07f53b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Reference.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Reference.cpp @@ -44,3 +44,9 @@ void ModelHighAPI_Reference::appendToList( { theAttribute->append(myObject); } + +//-------------------------------------------------------------------------------------- +std::shared_ptr ModelHighAPI_Reference::feature() const +{ + return ModelAPI_Feature::feature(myObject); +} diff --git a/src/ModelHighAPI/ModelHighAPI_Reference.h b/src/ModelHighAPI/ModelHighAPI_Reference.h index 71a6f2aca..f960791ce 100644 --- a/src/ModelHighAPI/ModelHighAPI_Reference.h +++ b/src/ModelHighAPI/ModelHighAPI_Reference.h @@ -16,6 +16,7 @@ class ModelAPI_Attribute; class ModelAPI_AttributeReference; class ModelAPI_AttributeRefList; +class ModelAPI_Feature; class ModelAPI_Object; class ModelHighAPI_Interface; //-------------------------------------------------------------------------------------- @@ -47,6 +48,10 @@ public: MODELHIGHAPI_EXPORT virtual void appendToList(const std::shared_ptr & theAttribute) const; + /// Returns feature for this object. + MODELHIGHAPI_EXPORT + virtual std::shared_ptr feature() const; + private: std::shared_ptr myObject; };