From: akl Date: Tue, 19 Nov 2013 17:09:58 +0000 (+0000) Subject: Add a new 'moveSection' operation to change position of section in the list. X-Git-Tag: BR_hydro_v_0_3_1~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=297574150f5c46ad0196e3e9b459fbc67a13fdd5;p=modules%2Fhydro.git Add a new 'moveSection' operation to change position of section in the list. --- diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.cxx b/src/HYDROCurveCreator/CurveCreator_Curve.cxx index 69b0c38d..f27cfb2e 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.cxx @@ -347,6 +347,48 @@ void CurveCreator_Curve::redisplayCurve() } } +//! For internal use only! Undo/Redo are not used here. +bool CurveCreator_Curve::moveSectionInternal(const int theISection, + const int theNewIndex) +{ + bool res = false; + if (theISection != theNewIndex) { + CurveCreator_Section *aSection = mySections.at(theISection); + + // Remove section + CurveCreator::Sections::iterator anIter = mySections.begin() + theISection; + + mySections.erase(anIter); + + // Insert section. + anIter = mySections.begin() + theNewIndex; + mySections.insert(anIter, aSection); + res = true; + } + return res; +} + +//======================================================================= +// function: moveSection +// purpose: +//======================================================================= +bool CurveCreator_Curve::moveSection(const int theISection, + const int theNewIndex) +{ + bool res = false; + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(this, CurveCreator_Operation::MoveSection, + theISection, theNewIndex); + } + + // Update the curve. + res = moveSectionInternal(theISection, theNewIndex); + finishOperation(); + return res; +} + /************ Implementation of INTERFACE methods ************/ /***********************************************/ diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.hxx b/src/HYDROCurveCreator/CurveCreator_Curve.hxx index 551fc973..f9e41588 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.hxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.hxx @@ -91,6 +91,13 @@ public: ListAISObjects constructSection( int theISection ) const; + //! For internal use only! Undo/Redo are not used here. + virtual bool moveSectionInternal(const int theISection, + const int theNewIndex); + //! Move section to new position in list + virtual bool moveSection(const int theISection, + const int theNewIndex); + protected: /** This method updates all undo/redo information required to be updated * after curve modification operation. It returns false if undo/redo diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.cxx b/src/HYDROCurveCreator/CurveCreator_Operation.cxx index 7e87af79..ce73d1cc 100644 --- a/src/HYDROCurveCreator/CurveCreator_Operation.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Operation.cxx @@ -321,6 +321,9 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) case CurveCreator_Operation::SetClosed: theCurve->setClosedInternal((pInt[0] != 0), pInt[1]); break; + case CurveCreator_Operation::MoveSection: + theCurve->moveSectionInternal(pInt[0], pInt[1]); + break; case CurveCreator_Operation::Join: if (myPData == NULL) { theCurve->joinInternal();