]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fixed the problem with several parts creation.
authormpv <mikhail.ponikarov@opencascade.com>
Tue, 20 May 2014 08:57:25 +0000 (12:57 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Tue, 20 May 2014 08:57:25 +0000 (12:57 +0400)
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/ModelAPI/ModelAPI_Document.h
src/SketchPlugin/SketchPlugin_Feature.cpp

index 619e05c01804e7daa39317fc785b82f6894539fd..8208461788b13859e6d1d7f4f0d13ce9d4f4dbf2 100644 (file)
@@ -355,7 +355,7 @@ boost::shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID
 }
 
 boost::shared_ptr<ModelAPI_Feature> 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<ModelAPI_Feature> Model_Document::feature(
       TDF_Label aFeatureLab = aRefs->Value(theIndex);
       boost::shared_ptr<ModelAPI_Feature> 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<ModelAPI_Feature> 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<string> aGroups;
+  aGroups.push_back(FEATURES_GROUP);
+  if (!theFeature->isInHistory()) {
+    aGroups.push_back(theFeature->getGroup());
   }
-  // generate candidate name
-  stringstream aNameStream;
-  aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
-  string aName = aNameStream.str();
-  // check this is unique, if not, increase index by 1
-  for(a = 0; a < aSize;) {
-    if (feature(FEATURES_GROUP, a)->data()->getName() == aName) {
-      aNumObjects++;
-      stringstream aNameStream;
-      aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
-      // reinitialize iterator to make sure a new name is unique
-      a = 0;
-    } else a++;
+  for(list<string>::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<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+    aName = aNameStream.str();
+    // check this is unique, if not, increase index by 1
+    for(a = 0; a < aSize;) {
+      if (feature(*aGIter, a, true)->data()->getName() == aName) {
+        aNumObjects++;
+        stringstream aNameStream;
+        aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+        // reinitialize iterator to make sure a new name is unique
+        a = 0;
+      } else a++;
+    }
   }
-
   theFeature->data()->setName(aName);
 }
 
index 218ea615bf88cdc004b6c5f8ece6bae4b2acdcc9..ce16a5de7b9874df9af7fe58d63758d26d2add71 100644 (file)
@@ -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<ModelAPI_Feature> 
-    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);
index cc188d9d4d6b366daefb0a2b90d3edf6b95eb866..bed11f88617854a642e8676659ade04bb3dda2c8 100644 (file)
@@ -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<ModelAPI_Feature> 
-    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;
index 6f8f41af8d3d86e28279af7e43b3ae04e3931c1e..ae771b5567b1dff3cc71ac5f52d9c4b15ff95969 100644 (file)
@@ -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<ModelAPI_Object> anObj = 
-        boost::dynamic_pointer_cast<ModelAPI_Object>(document()->feature("Construction", a));
-      if (anObj) {
-        boost::shared_ptr<SketchPlugin_Sketch> aSketch = 
-          boost::dynamic_pointer_cast<SketchPlugin_Sketch>(anObj->featureRef());
-        if (aSketch) {
-          std::list<boost::shared_ptr<ModelAPI_Feature> > aList = 
-            aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
-          std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
-          for(; aSub != aList.end(); aSub++) {
-            if ((*aSub)->data()->isEqual(data())) {
-              mySketch = aSketch.get();
-              break;
-            }
+      boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::
+        dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
+      if (aSketch) {
+        std::list<boost::shared_ptr<ModelAPI_Feature> > aList = 
+          aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
+        std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
+        for(; aSub != aList.end(); aSub++) {
+          if ((*aSub)->data()->isEqual(data())) {
+            mySketch = aSketch.get();
+            break;
           }
         }
       }