From 8e3305186cf4d250f01e08cdc412f3476da11e8d Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 10 Aug 2016 15:04:44 +0300 Subject: [PATCH] Issue #1648: Dump Python in the High Level Parameterized Geometry API Added dump for FeaturesAPI_Revolution and FeaturesAPI_Boolean --- src/FeaturesAPI/FeaturesAPI_Boolean.cpp | 26 ++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Boolean.h | 4 +++ src/FeaturesAPI/FeaturesAPI_Extrusion.h | 2 +- src/FeaturesAPI/FeaturesAPI_Revolution.cpp | 31 ++++++++++++++++++++++ src/FeaturesAPI/FeaturesAPI_Revolution.h | 4 +++ 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/FeaturesAPI/FeaturesAPI_Boolean.cpp b/src/FeaturesAPI/FeaturesAPI_Boolean.cpp index 4ee728c6c..062731c89 100644 --- a/src/FeaturesAPI/FeaturesAPI_Boolean.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Boolean.cpp @@ -6,6 +6,7 @@ #include "FeaturesAPI_Boolean.h" +#include #include #include #include @@ -63,6 +64,31 @@ void FeaturesAPI_Boolean::setToolObjects(const std::list execute(); } +//================================================================================================== +void FeaturesAPI_Boolean::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + + FeaturesPlugin_Boolean::OperationType aType = + (FeaturesPlugin_Boolean::OperationType)aBase->integer(FeaturesPlugin_Boolean::TYPE_ID())->value(); + + theDumper << aBase << " = model.add"; + + switch(aType) { + case FeaturesPlugin_Boolean::BOOL_CUT: theDumper << "Cut"; break; + case FeaturesPlugin_Boolean::BOOL_FUSE: theDumper << "Fuse"; break; + case FeaturesPlugin_Boolean::BOOL_COMMON: theDumper << "Common"; break; + case FeaturesPlugin_Boolean::BOOL_FILL: theDumper << "Fill"; break; + case FeaturesPlugin_Boolean::BOOL_SMASH: theDumper << "Smash"; break; + } + + const std::string& aDocName = theDumper.name(aBase->document()); + AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID()); + AttributeSelectionListPtr aTools = aBase->selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID()); + + theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools << ")" << std::endl; +} + //================================================================================================== BooleanPtr addCut(const std::shared_ptr& thePart, const std::list& theMainObjects, diff --git a/src/FeaturesAPI/FeaturesAPI_Boolean.h b/src/FeaturesAPI/FeaturesAPI_Boolean.h index 9ad38f4bc..f314158cd 100644 --- a/src/FeaturesAPI/FeaturesAPI_Boolean.h +++ b/src/FeaturesAPI/FeaturesAPI_Boolean.h @@ -54,6 +54,10 @@ public: /// Set tool objects. FEATURESAPI_EXPORT void setToolObjects(const std::list& theToolObjects); + + /// Dump wrapped feature + FEATURESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; /// Pointer on Boolean object. diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.h b/src/FeaturesAPI/FeaturesAPI_Extrusion.h index f2ca23485..456da2c04 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.h +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.h @@ -112,7 +112,7 @@ public: const ModelHighAPI_Selection& theFromObject, const ModelHighAPI_Double& theFromOffset); - /// Dump wrapped feature + /// Dump wrapped feature FEATURESAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; diff --git a/src/FeaturesAPI/FeaturesAPI_Revolution.cpp b/src/FeaturesAPI/FeaturesAPI_Revolution.cpp index fc982e9c1..d54b660fb 100644 --- a/src/FeaturesAPI/FeaturesAPI_Revolution.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Revolution.cpp @@ -7,6 +7,7 @@ #include "FeaturesAPI_Revolution.h" #include +#include #include //================================================================================================== @@ -120,6 +121,36 @@ void FeaturesAPI_Revolution::setPlanesAndOffsets(const ModelHighAPI_Selection& t execute(); } +//================================================================================================== +void FeaturesAPI_Revolution::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeSelectionListPtr anObjects = aBase->selectionList(FeaturesPlugin_Revolution::BASE_OBJECTS_ID()); + AttributeSelectionPtr anAxis = aBase->selection(FeaturesPlugin_Revolution::AXIS_OBJECT_ID()); + + theDumper << aBase << " = model.addRevolution(" << aDocName << ", " << anObjects << ", " << anAxis; + + 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; + } + + theDumper << ")" << std::endl; +} + //================================================================================================== RevolutionPtr addRevolution(const std::shared_ptr& thePart, const std::list& theBaseObjects, diff --git a/src/FeaturesAPI/FeaturesAPI_Revolution.h b/src/FeaturesAPI/FeaturesAPI_Revolution.h index a8e4bc6dd..5b296ba6c 100644 --- a/src/FeaturesAPI/FeaturesAPI_Revolution.h +++ b/src/FeaturesAPI/FeaturesAPI_Revolution.h @@ -90,6 +90,10 @@ public: const ModelHighAPI_Double& theToOffset, const ModelHighAPI_Selection& theFromObject, const ModelHighAPI_Double& theFromOffset); + + /// Dump wrapped feature + FEATURESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; /// Pointer on Revolution object. -- 2.39.2