From b01527efd489b4a03d3ae26fdc20d3f24f29dec1 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 16 Aug 2016 10:40:14 +0300 Subject: [PATCH] Issue #1648: Dump Python in the High Level Parameterized Geometry API Dump for FeaturesAPI_RevolutionCut and FeaturesAPI_RevolutionFuse --- .../FeaturesAPI_RevolutionBoolean.cpp | 84 +++++++++++++++++-- .../FeaturesAPI_RevolutionBoolean.h | 29 +++++-- 2 files changed, 98 insertions(+), 15 deletions(-) diff --git a/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp b/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp index 3ca6f2b7d..097fbfbdb 100644 --- a/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp +++ b/src/FeaturesAPI/FeaturesAPI_RevolutionBoolean.cpp @@ -7,6 +7,8 @@ #include "FeaturesAPI_RevolutionBoolean.h" #include +#include +#include #include //================================================================================================== @@ -20,12 +22,24 @@ FeaturesAPI_RevolutionBoolean::~FeaturesAPI_RevolutionBoolean() { } +//================================================================================================== +void FeaturesAPI_RevolutionBoolean::setNestedSketch(const ModelHighAPI_Reference& theSketch) +{ + mysketch->setValue(theSketch.feature()); + mybaseObjects->clear(); + mybaseObjects->append(theSketch.feature()->firstResult(), GeomShapePtr()); + + execIfBaseNotEmpty(); +} + //================================================================================================== void FeaturesAPI_RevolutionBoolean::setBase(const std::list& theBaseObjects) { + mysketch->setValue(ObjectPtr()); + mybaseObjects->clear(); fillAttribute(theBaseObjects, mybaseObjects); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -33,7 +47,7 @@ void FeaturesAPI_RevolutionBoolean::setAxis(const ModelHighAPI_Selection& theAxi { fillAttribute(theAxis, myaxis); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -44,7 +58,7 @@ void FeaturesAPI_RevolutionBoolean::setAngles(const ModelHighAPI_Double& theToAn fillAttribute(theToAngle, mytoAngle); fillAttribute(theFromAngle, myfromAngle); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -54,7 +68,7 @@ void FeaturesAPI_RevolutionBoolean::setAngle(const ModelHighAPI_Double& theAngle fillAttribute(theAngle, mytoAngle); fillAttribute(ModelHighAPI_Double(), myfromAngle); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -69,7 +83,7 @@ void FeaturesAPI_RevolutionBoolean::setPlanesAndOffsets(const ModelHighAPI_Selec fillAttribute(theFromObject, myfromObject); fillAttribute(theFromOffset, myfromOffset); - execute(); + execIfBaseNotEmpty(); } //================================================================================================== @@ -77,7 +91,59 @@ void FeaturesAPI_RevolutionBoolean::setBooleanObjects(const std::listdocument()); + + AttributeReferencePtr anAttrSketch = aBase->reference(FeaturesPlugin_Revolution::SKETCH_ID()); + AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID()); + AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID()); + + theDumper << aBase << " = model.addRevolution"; + if(aBase->getKind() == FeaturesPlugin_RevolutionCut::ID()) { + theDumper << "Cut"; + } else if(aBase->getKind() == FeaturesPlugin_RevolutionFuse::ID()) { + theDumper << "Fuse"; + } + theDumper << "(" << aDocName << ", "; + anAttrSketch->isInitialized() ? theDumper << "[]" : theDumper << anAttrObjects; + theDumper << ", " << anAttrAxis; + + std::string aCreationMethod = aBase->string(FeaturesPlugin_Revolution::CREATION_METHOD())->value(); + + if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_ANGLES()) { + AttributeDoublePtr anAttrToAngle = aBase->real(FeaturesPlugin_Revolution::TO_ANGLE_ID()); + AttributeDoublePtr anAttrFromAngle = aBase->real(FeaturesPlugin_Revolution::FROM_ANGLE_ID()); + + theDumper << ", " << anAttrToAngle << ", " << anAttrFromAngle; + } else if(aCreationMethod == FeaturesPlugin_Revolution::CREATION_METHOD_BY_PLANES()) { + AttributeSelectionPtr anAttrToObject = aBase->selection(FeaturesPlugin_Revolution::TO_OBJECT_ID()); + AttributeDoublePtr anAttrToOffset = aBase->real(FeaturesPlugin_Revolution::TO_OFFSET_ID()); + AttributeSelectionPtr anAttrFromObject = aBase->selection(FeaturesPlugin_Revolution::FROM_OBJECT_ID()); + AttributeDoublePtr anAttrFromOffset = aBase->real(FeaturesPlugin_Revolution::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_RevolutionBoolean::execIfBaseNotEmpty() +{ + if(mybaseObjects->size() > 0) { + execute(); + } } //================================================================================================== @@ -98,6 +164,7 @@ FeaturesAPI_RevolutionCut::FeaturesAPI_RevolutionCut(const std::shared_ptr class ModelHighAPI_Double; +class ModelHighAPI_Dumper; +class ModelHighAPI_Reference; class ModelHighAPI_Selection; /// \class FeaturesAPI_RevolutionBoolean @@ -30,7 +32,7 @@ public: virtual ~FeaturesAPI_RevolutionBoolean(); INTERFACE_11("", - sketchLauncher, FeaturesPlugin_Revolution::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */, + sketch, FeaturesPlugin_Revolution::SKETCH_ID(), ModelAPI_AttributeReference, /** Sketch launcher */, baseObjects, FeaturesPlugin_Revolution::BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList, /** Base objects */, axis, FeaturesPlugin_Revolution::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection, /** Axis */, creationMethod, FeaturesPlugin_Revolution::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, @@ -42,6 +44,10 @@ public: fromOffset, FeaturesPlugin_Revolution::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 +75,25 @@ 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_RevolutionBoolean(const std::shared_ptr& theFeature); + +private: + void execIfBaseNotEmpty(); }; class FeaturesAPI_RevolutionCut: public FeaturesAPI_RevolutionBoolean { public: - FEATURESAPI_EXPORT - virtual std::string getID() { - return FeaturesPlugin_RevolutionCut::ID(); - } + + static std::string ID() { return FeaturesPlugin_RevolutionCut::ID(); } + virtual std::string getID() { return ID(); } /// Constructor without values. FEATURESAPI_EXPORT @@ -153,10 +165,9 @@ RevolutionCutPtr addRevolutionCut(const std::shared_ptr& theP class FeaturesAPI_RevolutionFuse: public FeaturesAPI_RevolutionBoolean { public: - FEATURESAPI_EXPORT - virtual std::string getID() { - return FeaturesPlugin_RevolutionFuse::ID(); - } + + static std::string ID() { return FeaturesPlugin_RevolutionFuse::ID(); } + virtual std::string getID() { return ID(); } /// Constructor without values. FEATURESAPI_EXPORT -- 2.39.2