From: azv Date: Wed, 10 Aug 2016 10:37:40 +0000 (+0300) Subject: Dump Python in the High Level Parameterized Geometry API (issue #1648) X-Git-Tag: V_2.5.0~137^2~79 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dfd8991c975a7493c1e7be200503a5c9456ad2da;p=modules%2Fshaper.git Dump Python in the High Level Parameterized Geometry API (issue #1648) * Dump Mirror constraint * Specific dump methods for AttributeRefList and AttributeRefAttrList * Bug with Mirror constraint processing has been fixed (PlaneGCS solver) --- diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index d92154841..dbecf0c6b 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -55,11 +55,13 @@ SET(SWIG_LINK_LIBRARIES ) INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomDataAPI ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/PartSetPlugin + ${PROJECT_SOURCE_DIR}/src/SketchPlugin ${CAS_INCLUDE_DIRS} ) diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 72d4623cc..d50d9652a 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include #include @@ -30,6 +32,8 @@ #include +#include + #include #include @@ -171,8 +175,15 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptrnumberOfSubs(); for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) { FeaturePtr aFeature = theComposite->subFeature(anIndex); - if (!isDumped(aFeature)) - dumpFeature(aFeature, true); + if (isDumped(aFeature)) + continue; + bool isForce = true; + // check the feature is a sketch entity and a copy of another entity + std::shared_ptr aSketchEntity = + std::dynamic_pointer_cast(aFeature); + if (aSketchEntity && aSketchEntity->isCopy()) + isForce = false; + dumpFeature(aFeature, isForce); } // dump command to update model myDumpBuffer << "model.do()" << std::endl; @@ -239,6 +250,7 @@ void ModelHighAPI_Dumper::dumpEntitySetName() myDumpBuffer << ".feature()"; myDumpBuffer << ".data().setName(\"" << aName << "\")" << std::endl; #endif + myNames[myLastEntityWithName].second = false; // don't dump "setName" for the entity twice myLastEntityWithName = EntityPtr(); } @@ -370,7 +382,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( return *this; } -ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const EntityPtr& theEntity) +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity) { myDumpBuffer << name(theEntity); if (myNames[theEntity].second) @@ -379,16 +391,85 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const EntityPtr& theEntity) return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ObjectPtr& theObject) +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + myDumpBuffer << name(aFeature); + return *this; +} + +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr) +{ + FeaturePtr anOwner = ModelAPI_Feature::feature(theAttr->owner()); + myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, theAttr->id()) << "()"; + return *this; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theRefAttr) { - if (theRefAttr->isObject()) { - FeaturePtr aFeature = ModelAPI_Feature::feature(theRefAttr->object()); - myDumpBuffer << name(aFeature); + if (theRefAttr->isObject()) + *this << theRefAttr->object(); + else + *this << theRefAttr->attr(); + return *this; +} + +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( + const std::shared_ptr& theRefAttrList) +{ + myDumpBuffer << "["; + std::list > aList = theRefAttrList->list(); + bool isAdded = false; + std::list >::const_iterator anIt = aList.begin(); + for (; anIt != aList.end(); ++anIt) { + if (isAdded) + myDumpBuffer << ", "; + else + isAdded = true; + if (anIt->first) + *this << anIt->first; + else if (anIt->second) + * this << anIt->second; + } + myDumpBuffer << "]"; + return *this; +} + +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( + const std::shared_ptr& theRefList) +{ + static const int aThreshold = 2; + // if number of elements in the list if greater than a threshold, + // dump it in a separate line with specific name + std::string aDumped = myDumpBuffer.str(); + if (aDumped.empty() || theRefList->size() <= aThreshold) { + myDumpBuffer << "["; + std::list aList = theRefList->list(); + bool isAdded = false; + std::list::const_iterator anIt = aList.begin(); + for (; anIt != aList.end(); ++anIt) { + if (isAdded) + myDumpBuffer << ", "; + else + isAdded = true; + + *this << *anIt; + } + myDumpBuffer << "]"; } else { - AttributePtr anAttr = theRefAttr->attr(); - FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner()); - myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, anAttr->id()) << "()"; + // clear buffer and store list "as is" + myDumpBuffer = std::ostringstream(); + *this << theRefList; + // save buffer and clear it again + std::string aDumpedList = myDumpBuffer.str(); + myDumpBuffer = std::ostringstream(); + // obtain name of list + FeaturePtr anOwner = ModelAPI_Feature::feature(theRefList->owner()); + std::string aListName = name(anOwner) + "_objects"; + // store all previous data + myDumpBuffer << aListName << " = " << aDumpedList << std::endl + << aDumped << aListName; } return *this; } diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 30cdce088..161e9e61a 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -22,10 +22,13 @@ class GeomDataAPI_Dir; class GeomDataAPI_Point; class GeomDataAPI_Point2D; +class ModelAPI_Attribute; class ModelAPI_AttributeBoolean; class ModelAPI_AttributeDouble; class ModelAPI_AttributeInteger; class ModelAPI_AttributeRefAttr; +class ModelAPI_AttributeRefAttrList; +class ModelAPI_AttributeRefList; class ModelAPI_AttributeSelection; class ModelAPI_AttributeSelectionList; class ModelAPI_AttributeString; @@ -33,6 +36,7 @@ class ModelAPI_CompositeFeature; class ModelAPI_Document; class ModelAPI_Entity; class ModelAPI_Feature; +class ModelAPI_Object; typedef std::shared_ptr EntityPtr; typedef std::shared_ptr FeaturePtr; @@ -147,11 +151,26 @@ public: ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theAttrStr); /// Dump name of entity and remember to dump "setName" if the entity has user-defined name MODELHIGHAPI_EXPORT - ModelHighAPI_Dumper& operator<<(const EntityPtr& theEntity); + ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity); + + /// Dump Attribute + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theAttr); + /// Dump Object + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theObject); /// Dump AttributeRefAttr MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theRefAttr); + /// Dump AttributeRefAttrList as follows: + /// "[obj1, obj2, obj3, ...]" + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theRefAttrList); + /// Dump AttributeRefList as follows: + /// "[obj1, obj2, obj3, ...]" + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theRefList); /// Dump AttributeSelection MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theAttrSelect); diff --git a/src/SketchAPI/SketchAPI_Constraint.cpp b/src/SketchAPI/SketchAPI_Constraint.cpp index 150c73e93..6870cc63d 100644 --- a/src/SketchAPI/SketchAPI_Constraint.cpp +++ b/src/SketchAPI/SketchAPI_Constraint.cpp @@ -127,7 +127,8 @@ static std::string angleTypeToString(int theAngleType) void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const { - ConstraintPtr aConstraint = std::dynamic_pointer_cast(feature()); + FeaturePtr aBase = feature(); + ConstraintPtr aConstraint = std::dynamic_pointer_cast(aBase); if (!aConstraint) return; // dump constraints only @@ -141,7 +142,7 @@ void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const SketchPlugin_ConstraintAngle::TYPE_ID())->value()); const std::string& aSketchName = theDumper.parentName(aConstraint); - theDumper << aConstraint << " = " << aSketchName << "." << aSetter << aSetterSuffix << "("; + theDumper << aBase << " = " << aSketchName << "." << aSetter << aSetterSuffix << "("; bool isFirstAttr = true; for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { diff --git a/src/SketchAPI/SketchAPI_Mirror.cpp b/src/SketchAPI/SketchAPI_Mirror.cpp index d6166e79c..32abfc90b 100644 --- a/src/SketchAPI/SketchAPI_Mirror.cpp +++ b/src/SketchAPI/SketchAPI_Mirror.cpp @@ -7,12 +7,13 @@ //-------------------------------------------------------------------------------------- #include "SketchAPI_Mirror.h" //-------------------------------------------------------------------------------------- +#include #include #include //-------------------------------------------------------------------------------------- SketchAPI_Mirror::SketchAPI_Mirror( const std::shared_ptr & theFeature) -: SketchAPI_SketchEntity(theFeature) +: ModelHighAPI_Interface(theFeature) { initialize(); } @@ -21,7 +22,7 @@ SketchAPI_Mirror::SketchAPI_Mirror( const std::shared_ptr & theFeature, const ModelHighAPI_RefAttr & theMirrorLine, const std::list > & theObjects) -: SketchAPI_SketchEntity(theFeature) +: ModelHighAPI_Interface(theFeature) { if (initialize()) { fillAttribute(theMirrorLine, mirrorLine()); @@ -37,3 +38,14 @@ SketchAPI_Mirror::~SketchAPI_Mirror() } //-------------------------------------------------------------------------------------- + +void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aSketchName = theDumper.parentName(aBase); + + AttributeRefAttrPtr aMirrorLine = mirrorLine(); + AttributeRefListPtr aMirrorObjects = mirrorList(); + theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", " + << aMirrorObjects << ")" << std::endl; +} diff --git a/src/SketchAPI/SketchAPI_Mirror.h b/src/SketchAPI/SketchAPI_Mirror.h index 9cd2d5488..ab77061ea 100644 --- a/src/SketchAPI/SketchAPI_Mirror.h +++ b/src/SketchAPI/SketchAPI_Mirror.h @@ -14,7 +14,8 @@ #include -#include "SketchAPI_SketchEntity.h" +#include +#include //-------------------------------------------------------------------------------------- class ModelAPI_Object; class ModelHighAPI_RefAttr; @@ -23,7 +24,7 @@ class ModelHighAPI_RefAttr; * \ingroup CPPHighAPI * \brief Interface for Mirror feature */ -class SketchAPI_Mirror : public SketchAPI_SketchEntity +class SketchAPI_Mirror : public ModelHighAPI_Interface { public: /// Constructor without values @@ -45,6 +46,8 @@ public: mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */ ) + /// Dump wrapped feature + virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; //! Pointer on Mirror object diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp index 5e101d240..b73391a91 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp @@ -1204,5 +1204,12 @@ void adjustMirror(ConstraintWrapperPtr theConstraint) if (aPoints.size() == 2) makeMirrorPoints(aPoints[0], aPoints[1], aMirrorLine); + + // update scales of constraints + std::shared_ptr aGCSConstraint = + std::dynamic_pointer_cast(theConstraint); + std::list::const_iterator aCIt = aGCSConstraint->constraints().begin(); + for (; aCIt != aGCSConstraint->constraints().end(); ++aCIt) + (*aCIt)->rescale(); }