From: mpv Date: Tue, 20 May 2014 08:57:25 +0000 (+0400) Subject: Fixed the problem with several parts creation. X-Git-Tag: V_0.2~35^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5dfed65281f80488610fa9817350611277c6b0aa;p=modules%2Fshaper.git Fixed the problem with several parts creation. --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 619e05c01..820846178 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -355,7 +355,7 @@ boost::shared_ptr Model_Document::subDocument(string theDocID } boost::shared_ptr Model_Document::feature( - const string& theGroupID, const int theIndex) + const string& theGroupID, const int theIndex, const bool isOperation) { TDF_Label aGroupLab = groupLabel(theGroupID); Handle(TDataStd_ReferenceArray) aRefs; @@ -364,7 +364,7 @@ boost::shared_ptr Model_Document::feature( TDF_Label aFeatureLab = aRefs->Value(theIndex); boost::shared_ptr aFeature = feature(aFeatureLab); - if (theGroupID == FEATURES_GROUP) { // just returns the feature from the history + if (theGroupID == FEATURES_GROUP || isOperation) { // just returns the feature from the history return aFeature; } else { // create a new object from the group to return it Handle(TDataStd_Name) aName; // name of the object @@ -418,28 +418,36 @@ TDF_Label Model_Document::groupLabel(const string theGroup) void Model_Document::setUniqueName(boost::shared_ptr theFeature) { - // first count all objects of such kind to start with index = count + 1 - int a, aNumObjects = 0; - int aSize = size(FEATURES_GROUP); - for(a = 0; a < aSize; a++) { - if (feature(FEATURES_GROUP, a)->getKind() == theFeature->getKind()) - aNumObjects++; + string aName; // result + // iterate all features but also iterate group of this feature if object is not in history + list aGroups; + aGroups.push_back(FEATURES_GROUP); + if (!theFeature->isInHistory()) { + aGroups.push_back(theFeature->getGroup()); } - // generate candidate name - stringstream aNameStream; - aNameStream<getKind()<<"_"<data()->getName() == aName) { - aNumObjects++; - stringstream aNameStream; - aNameStream<getKind()<<"_"<::iterator aGIter = aGroups.begin(); aGIter != aGroups.end(); aGIter++) { + // first count all objects of such kind to start with index = count + 1 + int a, aNumObjects = 0; + int aSize = size(*aGIter); + for(a = 0; a < aSize; a++) { + if (feature(*aGIter, a)->getKind() == theFeature->getKind()) + aNumObjects++; + } + // generate candidate name + stringstream aNameStream; + aNameStream<getKind()<<"_"<data()->getName() == aName) { + aNumObjects++; + stringstream aNameStream; + aNameStream<getKind()<<"_"<data()->setName(aName); } diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 218ea615b..ce16a5de7 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -74,8 +74,11 @@ public: MODEL_EXPORT virtual const std::string& id() const {return myID;} //! Returns the feature in the group by the index (started from zero) + //! \param theGroupID group that contains a feature + //! \param theIndex zero-based index of feature in the group + //! \param isOperation if it is true, returns feature (not Object) MODEL_EXPORT virtual boost::shared_ptr - feature(const std::string& theGroupID, const int theIndex); + feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false); //! Returns the number of features in the group MODEL_EXPORT virtual int size(const std::string& theGroupID); diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index cc188d9d4..bed11f886 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -76,8 +76,11 @@ public: MODELAPI_EXPORT virtual const std::string& id() const = 0; //! Returns the feature in the group by the index (started from zero) + //! \param theGroupID group that contains a feature + //! \param theIndex zero-based index of feature in the group + //! \param isOperation if it is true, returns feature (not Object) MODELAPI_EXPORT virtual boost::shared_ptr - feature(const std::string& theGroupID, const int theIndex) = 0; + feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false) = 0; //! Returns the number of features in the group MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0; diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 6f8f41af8..ae771b556 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -26,20 +26,16 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch() // find sketch that references to this feature int aSketches = document()->size("Construction"); for(int a = 0; a < aSketches && !mySketch; a++) { - boost::shared_ptr anObj = - boost::dynamic_pointer_cast(document()->feature("Construction", a)); - if (anObj) { - boost::shared_ptr aSketch = - boost::dynamic_pointer_cast(anObj->featureRef()); - if (aSketch) { - std::list > aList = - aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list(); - std::list >::iterator aSub = aList.begin(); - for(; aSub != aList.end(); aSub++) { - if ((*aSub)->data()->isEqual(data())) { - mySketch = aSketch.get(); - break; - } + boost::shared_ptr aSketch = boost:: + dynamic_pointer_cast(document()->feature("Construction", a, true)); + if (aSketch) { + std::list > aList = + aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list(); + std::list >::iterator aSub = aList.begin(); + for(; aSub != aList.end(); aSub++) { + if ((*aSub)->data()->isEqual(data())) { + mySketch = aSketch.get(); + break; } } }