From: mpv Date: Mon, 6 Jul 2015 12:36:36 +0000 (+0300) Subject: Added "move feature" document action. X-Git-Tag: V_1.3.0~99 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=35eb7e3038b8ca841f6fc6f43b715b32799d81c4;p=modules%2Fshaper.git Added "move feature" document action. --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 19cf104f7..1c61d4f7c 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -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 theObject) { myObjs->updateHistory(theObject); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index ba7ecb7af..70cfcf618 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -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 diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 224d9d9db..c815aa12d 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -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(theMoved->data())->label().Father(); + if (theAfterThis.get()) + anAfterLab = std::dynamic_pointer_cast(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) { diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index 9bab83b67..52df45200 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -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; diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 6d778360f..4c06461fa 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -60,6 +60,10 @@ public: //! \param theFeature a feature to be removed virtual void removeFeature(std::shared_ptr theFeature) = 0; + //! Moves the feature to make it after the given one in the history. + virtual void moveFeature(std::shared_ptr theMoved, + std::shared_ptr theAfterThis) = 0; + ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist virtual std::shared_ptr subDocument(std::string theDocID) = 0;