From: dbv Date: Thu, 11 Aug 2016 12:47:46 +0000 (+0300) Subject: Issue #1648: Dump Python in the High Level Parameterized Geometry API X-Git-Tag: V_2.5.0~137^2~68 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b0cfab38f4947872f05d09ee458ab078aa117ae6;p=modules%2Fshaper.git Issue #1648: Dump Python in the High Level Parameterized Geometry API Dump for FeaturesAPI_ExtrusionCut and FeaturesAPI_ExtrusionFuse --- diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp index 8f437310f..d3808bb26 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp @@ -210,6 +210,7 @@ void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const } } +//================================================================================================== void FeaturesAPI_Extrusion::execIfBaseNotEmpty() { if(mybaseObjects->size() > 0) { diff --git a/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp b/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp index 357421b6e..bc37de7c1 100644 --- a/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp +++ b/src/FeaturesAPI/FeaturesAPI_ExtrusionBoolean.cpp @@ -7,6 +7,8 @@ #include "FeaturesAPI_ExtrusionBoolean.h" #include +#include +#include #include //================================================================================================== @@ -20,12 +22,24 @@ FeaturesAPI_ExtrusionBoolean::~FeaturesAPI_ExtrusionBoolean() { } +//================================================================================================== +void FeaturesAPI_ExtrusionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch) +{ + mysketch->setValue(theSketch.feature()); + mybaseObjects->clear(); + mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr()); + + execIfBaseNotEmpty(); +} + //================================================================================================== void FeaturesAPI_ExtrusionBoolean::setBase(const std::list& theBaseObjects) { + mysketch->setValue(ObjectPtr()); + mybaseObjects->clear(); fillAttribute(theBaseObjects, mybaseObjects); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -33,7 +47,7 @@ void FeaturesAPI_ExtrusionBoolean::setDirection(const ModelHighAPI_Selection& th { fillAttribute(theDirection, mydirection); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -44,7 +58,7 @@ void FeaturesAPI_ExtrusionBoolean::setSizes(const ModelHighAPI_Double& theToSize fillAttribute(theToSize, mytoSize); fillAttribute(theFromSize, myfromSize); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -54,7 +68,7 @@ void FeaturesAPI_ExtrusionBoolean::setSize(const ModelHighAPI_Double& theSize) fillAttribute(theSize, mytoSize); fillAttribute(ModelHighAPI_Double(), myfromSize); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -69,7 +83,7 @@ void FeaturesAPI_ExtrusionBoolean::setPlanesAndOffsets(const ModelHighAPI_Select fillAttribute(theFromObject, myfromObject); fillAttribute(theFromOffset, myfromOffset); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -77,9 +91,62 @@ void FeaturesAPI_ExtrusionBoolean::setBooleanObjects(const std::listdocument()); + + AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_CompositeSketch::SKETCH_ID()); + AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Extrusion::BASE_OBJECTS_ID()); + AttributeSelectionPtr anAttrDirection = aBase->selection(FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID()); + + theDumper << aBase << " = model.addExtrusion"; + if(aBase->getKind() == FeaturesPlugin_ExtrusionCut::ID()) { + theDumper << "Cut"; + } else if(aBase->getKind() == FeaturesPlugin_ExtrusionFuse::ID()) { + theDumper << "Fuse"; + } + theDumper << "(" << aDocName << ", "; + anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects; + theDumper << ", " << anAttrDirection; + + std::string aCreationMethod = aBase->string(FeaturesPlugin_Extrusion::CREATION_METHOD())->value(); + + if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_SIZES()) { + AttributeDoublePtr anAttrToSize = aBase->real(FeaturesPlugin_Extrusion::TO_SIZE_ID()); + AttributeDoublePtr anAttrFromSize = aBase->real(FeaturesPlugin_Extrusion::FROM_SIZE_ID()); + + theDumper << ", " << anAttrToSize << ", " << anAttrFromSize; + } else if(aCreationMethod == FeaturesPlugin_Extrusion::CREATION_METHOD_BY_PLANES()) { + AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Extrusion::TO_OBJECT_ID()); + AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Extrusion::TO_OFFSET_ID()); + AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Extrusion::FROM_OBJECT_ID()); + AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Extrusion::FROM_OFFSET_ID()); + + theDumper << ", " << anAttrToObject << ", " << anAttrToOffset << ", " << anAttrFromObject << ", " << anAttrFromOffset; + } + + AttributeSelectionListPtr anAttrBoolObjects = aBase->selectionList(FeaturesPlugin_CompositeBoolean::OBJECTS_ID()); + theDumper << ", " << anAttrBoolObjects << ")" << std::endl; + + if(anAttrSketch->isInitialized()) { + theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl; + } } +//================================================================================================== +void FeaturesAPI_ExtrusionBoolean::execIfBaseNotEmpty() +{ + if(mybaseObjects->size() > 0) { + execute(); + } +} + + //================================================================================================== FeaturesAPI_ExtrusionCut::FeaturesAPI_ExtrusionCut(const std::shared_ptr& theFeature) : FeaturesAPI_ExtrusionBoolean(theFeature) @@ -96,6 +163,7 @@ FeaturesAPI_ExtrusionCut::FeaturesAPI_ExtrusionCut(const std::shared_ptr #include #include @@ -17,6 +16,7 @@ #include class ModelHighAPI_Double; +class ModelHighAPI_Reference; class ModelHighAPI_Selection; /// \class FeaturesAPI_ExtrusionBoolean @@ -30,7 +30,7 @@ public: virtual ~FeaturesAPI_ExtrusionBoolean(); INTERFACE_11("", - sketchLauncher, FeaturesPlugin_Extrusion::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */, + sketch, FeaturesPlugin_Extrusion::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */, baseObjects, FeaturesPlugin_Extrusion::BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Base objects */, direction, FeaturesPlugin_Extrusion::DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection, /** Direction */, creationMethod, FeaturesPlugin_Extrusion::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, @@ -42,6 +42,10 @@ public: fromOffset, FeaturesPlugin_Extrusion::FROM_OFFSET_ID(), ModelAPI_AttributeDouble, /** From offset */, booleanObjects, FeaturesPlugin_CompositeBoolean::OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Boolean objects */) + /// 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); @@ -69,19 +73,30 @@ public: FEATURESAPI_EXPORT void setBooleanObjects(const std::list& theBooleanObjects); + /// Dump wrapped feature + FEATURESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; + protected: /// Constructor without values. FEATURESAPI_EXPORT explicit FeaturesAPI_ExtrusionBoolean(const std::shared_ptr& theFeature); + +private: + void execIfBaseNotEmpty(); }; class FeaturesAPI_ExtrusionCut: public FeaturesAPI_ExtrusionBoolean { public: - FEATURESAPI_EXPORT - virtual std::string getID() { - return FeaturesPlugin_ExtrusionCut::ID(); - } + + static std::string ID() { return FeaturesPlugin_ExtrusionCut::ID(); } + virtual std::string getID() { return ID(); } + + //FEATURESAPI_EXPORT + //virtual std::string getID() { + // return FeaturesPlugin_ExtrusionCut::ID(); + //} /// Constructor without values. FEATURESAPI_EXPORT