]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added "move feature" document action.
authormpv <mpv@opencascade.com>
Mon, 6 Jul 2015 12:36:36 +0000 (15:36 +0300)
committermpv <mpv@opencascade.com>
Mon, 6 Jul 2015 12:36:36 +0000 (15:36 +0300)
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_Objects.cpp
src/Model/Model_Objects.h
src/ModelAPI/ModelAPI_Document.h

index 19cf104f701b09eccab650d8223ef8fa557e8c64..1c61d4f7c1047ebb53f5e53c48de7556fec1b505 100644 (file)
@@ -585,6 +585,11 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
   myObjs->removeFeature(theFeature);
 }
 
+void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
+{
+  myObjs->moveFeature(theMoved, theAfterThis);
+}
+
 void Model_Document::updateHistory(const std::shared_ptr<ModelAPI_Object> theObject)
 {
   myObjs->updateHistory(theObject);
index ba7ecb7afdc1561b35aa31d500e04f52ec4ea1e0..70cfcf6189ab71e0d46ec3fd81be246e29f7e66a 100644 (file)
@@ -88,6 +88,9 @@ class Model_Document : public ModelAPI_Document
   //! \param theFeature a removed feature
   MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
 
+  //! Moves the feature to make it after the given one in the history.
+  MODEL_EXPORT virtual void moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis);
+
   //! Returns the first found object in the group by the object name
   //! \param theGroupID group that contains an object
   //! \param theName name of the object to search
index 224d9d9dbf9039cf65e175116b66c1ce1eb5cafd..c815aa12db909c281e8bc02a7c038822250dd125 100644 (file)
@@ -243,6 +243,56 @@ void Model_Objects::removeFeature(FeaturePtr theFeature)
   }
 }
 
+void Model_Objects::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
+{
+  TDF_Label aFeaturesLab = featuresLabel();
+  Handle(TDataStd_ReferenceArray) aRefs;
+  if (!aFeaturesLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
+    return;
+  TDF_Label anAfterLab, aMovedLab = 
+    std::dynamic_pointer_cast<Model_Data>(theMoved->data())->label().Father();
+  if (theAfterThis.get())
+    anAfterLab = std::dynamic_pointer_cast<Model_Data>(theAfterThis->data())->label().Father();
+
+  Handle(TDataStd_HLabelArray1) aNewArray = 
+    new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper());
+  int aPassedMovedFrom = 0; // the prev feature location is found and passed
+  int aPassedMovedTo = 0; // the feature is added and this location is passed
+  if (!theAfterThis.get()) { // null means that inserted feature must be the first
+    aNewArray->SetValue(aRefs->Lower(), aMovedLab);
+    aPassedMovedTo = 1;
+  }
+  for (int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
+    if (aPassedMovedTo == 0 && aRefs->Value(a) == anAfterLab) { // add two
+      aPassedMovedTo++;
+      aNewArray->SetValue(a - aPassedMovedFrom, anAfterLab);
+      if (a + 1 - aPassedMovedFrom <= aRefs->Upper())
+        aNewArray->SetValue(a + 1 - aPassedMovedFrom, aMovedLab);
+    } else if (aPassedMovedFrom == 0 && aRefs->Value(a) == aMovedLab) { // skip
+      aPassedMovedFrom++;
+    } else { // just copy one
+      if (a - aPassedMovedFrom + aPassedMovedTo <= aRefs->Upper())
+        aNewArray->SetValue(a - aPassedMovedFrom + aPassedMovedTo, aRefs->Value(a));
+    }
+  }
+  if (!aPassedMovedFrom || !aPassedMovedTo) {// not found: unknown situation
+    if (!aPassedMovedFrom) {
+      static std::string aMovedFromError("The moved feature is not found");
+      Events_Error::send(aMovedFromError);
+    } else {
+      static std::string aMovedToError("The 'after' feature for movement is not found");
+      Events_Error::send(aMovedToError);
+    }
+    return;
+  }
+  // store the new array
+  aRefs->SetInternalArray(aNewArray);
+  // update the feature and the history
+  clearHistory(theMoved);
+  static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
+  ModelAPI_EventCreator::get()->sendUpdated(theMoved, EVENT_UPD);
+}
+
 void Model_Objects::clearHistory(ObjectPtr theObj)
 {
   if (theObj) {
index 9bab83b67c38f4c87e7fc155b008e8aadf11c4e4..52df4520097e57b15770b8137f0c9d5281b5ad61 100644 (file)
@@ -51,6 +51,9 @@ class Model_Objects
   //! \param theFeature a removed feature
   void removeFeature(FeaturePtr theFeature);
 
+  //! Moves the feature to make it after the given one in the history.
+  void moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis);
+
   //! Returns the existing feature by the label
   //! \param theLabel base label of the feature
   FeaturePtr feature(TDF_Label theLabel) const;
index 6d778360fbde1d611fc4ffb12711237d8d3431d2..4c06461fac45ac6384b899bb1d8f36eb728e968b 100644 (file)
@@ -60,6 +60,10 @@ public:
   //! \param theFeature a feature to be removed
   virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
 
+  //! Moves the feature to make it after the given one in the history.
+  virtual void moveFeature(std::shared_ptr<ModelAPI_Feature> theMoved, 
+                           std::shared_ptr<ModelAPI_Feature> theAfterThis) = 0;
+
   ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
   virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID) = 0;