From: dbv Date: Tue, 9 Aug 2016 14:01:40 +0000 (+0300) Subject: Issue #1648: Dump Python in the High Level Parameterized Geometry API X-Git-Tag: V_2.5.0~137^2~82 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b14509ad3125cceca22d2dfa1619cd6ecdaa7fd1;p=modules%2Fshaper.git Issue #1648: Dump Python in the High Level Parameterized Geometry API 1. Empty constructor for ModelHighAPI_Selection (for not obligatory attributes); 2. Overloaded operator<< for ModelHighAPI_Dumper which takes ModelAPI_AttributeSelectionList; 3. Dump for FeaturesAPI_Extrusion. --- diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp index d79749b5f..f2dd6e6d7 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.cpp @@ -7,6 +7,7 @@ #include "FeaturesAPI_Extrusion.h" #include +#include #include //================================================================================================== @@ -160,6 +161,36 @@ void FeaturesAPI_Extrusion::setPlanesAndOffsets(const ModelHighAPI_Selection& th execute(); } +//================================================================================================== +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()); + + theDumper << aBase << " = model.addExtrusion(" << aDocName << ", " << anObjects << ", " << aDirection; + + 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; + } + + theDumper << ")" << std::endl; +} + //================================================================================================== ExtrusionPtr addExtrusion(const std::shared_ptr& thePart, const std::list& theBaseObjects, diff --git a/src/FeaturesAPI/FeaturesAPI_Extrusion.h b/src/FeaturesAPI/FeaturesAPI_Extrusion.h index 2c569802f..f2ca23485 100644 --- a/src/FeaturesAPI/FeaturesAPI_Extrusion.h +++ b/src/FeaturesAPI/FeaturesAPI_Extrusion.h @@ -111,6 +111,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 Extrusion object. diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index ee7894f50..72d4623cc 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -395,18 +396,57 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theAttrSelect) { + myDumpBuffer << "model.selection("; + + if(!theAttrSelect->isInitialized()) { + myDumpBuffer << ")"; + return *this; + } + GeomShapePtr aShape = theAttrSelect->value(); if(!aShape.get()) { aShape = theAttrSelect->context()->shape(); } if(!aShape.get()) { + myDumpBuffer << ")"; return *this; } - std::string aShapeTypeStr = aShape->shapeTypeStr(); + myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \"" << theAttrSelect->namingName() << "\")"; + return *this; +} + +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( + const std::shared_ptr& theAttrSelList) +{ + myDumpBuffer << "["; + + GeomShapePtr aShape; + std::string aShapeTypeStr; + + bool isAdded = false; + + for(int anIndex = 0; anIndex < theAttrSelList->size(); ++anIndex) { + AttributeSelectionPtr anAttribute = theAttrSelList->value(anIndex); + aShape = anAttribute->value(); + if(!aShape.get()) { + aShape = anAttribute->context()->shape(); + } + + if(!aShape.get()) { + continue; + } + + if(isAdded) { + myDumpBuffer << ", "; + } else { + isAdded = true; + } + myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")"; + } - myDumpBuffer << "model.selection(\"" << aShapeTypeStr << "\", \"" << theAttrSelect->namingName() << "\")"; + myDumpBuffer << "]"; return *this; } diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 200262fdb..30cdce088 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -27,6 +27,7 @@ class ModelAPI_AttributeDouble; class ModelAPI_AttributeInteger; class ModelAPI_AttributeRefAttr; class ModelAPI_AttributeSelection; +class ModelAPI_AttributeSelectionList; class ModelAPI_AttributeString; class ModelAPI_CompositeFeature; class ModelAPI_Document; @@ -154,6 +155,9 @@ public: /// Dump AttributeSelection MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theAttrSelect); + /// Dump AttributeSelectionList + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theAttrSelList); /// Clear dump buffer MODELHIGHAPI_EXPORT diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index 1a7e90cc0..c2540b8f5 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -12,6 +12,11 @@ //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- +ModelHighAPI_Selection::ModelHighAPI_Selection() +: myVariantType(VT_Empty) +{ +} + ModelHighAPI_Selection::ModelHighAPI_Selection(const std::shared_ptr& theContext, const std::shared_ptr& theSubShape) : myVariantType(VT_ResultSubShapePair) @@ -35,6 +40,7 @@ void ModelHighAPI_Selection::fillAttribute( const std::shared_ptr & theAttribute) const { switch(myVariantType) { + case VT_Empty: return; case VT_ResultSubShapePair: theAttribute->setValue(myResultSubShapePair.first, myResultSubShapePair.second); return; case VT_TypeSubShapeNamePair: theAttribute->selectSubShape(myTypeSubShapeNamePair.first, myTypeSubShapeNamePair.second); return; } @@ -45,6 +51,7 @@ void ModelHighAPI_Selection::appendToList( const std::shared_ptr & theAttribute) const { switch(myVariantType) { + case VT_Empty: return; case VT_ResultSubShapePair: theAttribute->append(myResultSubShapePair.first, myResultSubShapePair.second); return; case VT_TypeSubShapeNamePair: // Note: the reverse order (first - type, second - sub-shape name) diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h index 2a7273319..e559228b6 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.h +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -30,14 +30,19 @@ class ModelHighAPI_Selection { public: enum VariantType { + VT_Empty, VT_ResultSubShapePair, VT_TypeSubShapeNamePair }; public: + /// Default constructor with empty selection. + MODELHIGHAPI_EXPORT + ModelHighAPI_Selection(); + /// Constructor for result and sub-shape MODELHIGHAPI_EXPORT - ModelHighAPI_Selection(const std::shared_ptr& theContext = std::shared_ptr(), + ModelHighAPI_Selection(const std::shared_ptr& theContext, const std::shared_ptr& theSubShape = std::shared_ptr()); /// Constructor for sub-shape by the textual Name MODELHIGHAPI_EXPORT