From: akl Date: Thu, 21 Nov 2013 16:55:08 +0000 (+0000) Subject: Implementation of Undo/Redo of 'SetPoints', 'AddPoints', 'RemovePoints'. X-Git-Tag: BR_hydro_v_0_3_1~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b39007a5784e9dcbbae250bea4bca432f12244b9;p=modules%2Fhydro.git Implementation of Undo/Redo of 'SetPoints', 'AddPoints', 'RemovePoints'. --- diff --git a/src/HYDROCurveCreator/CMakeLists.txt b/src/HYDROCurveCreator/CMakeLists.txt index e225ade5..b2aaec5b 100644 --- a/src/HYDROCurveCreator/CMakeLists.txt +++ b/src/HYDROCurveCreator/CMakeLists.txt @@ -75,6 +75,7 @@ SET(_other_HEADERS CurveCreator_Operation.hxx CurveCreator_Section.hxx CurveCreator_Utils.h + CurveCreator_PosPoint.hxx ) # header files / to install diff --git a/src/HYDROCurveCreator/CurveCreator.hxx b/src/HYDROCurveCreator/CurveCreator.hxx index 031f7a5b..9cd7ec72 100644 --- a/src/HYDROCurveCreator/CurveCreator.hxx +++ b/src/HYDROCurveCreator/CurveCreator.hxx @@ -24,8 +24,11 @@ #define _CurveCreator_HeaderFile #include +#include +#include struct CurveCreator_Section; +struct CurveCreator_PosPoint; namespace CurveCreator { @@ -41,6 +44,10 @@ namespace CurveCreator //! List of sections typedef std::deque Sections; + // List of positioned points (points with coordinates) + typedef std::list PosPointsList; + //! Map of sections with positioned points + typedef std::map SectionsMap; }; #endif diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.cxx b/src/HYDROCurveCreator/CurveCreator_Curve.cxx index 51cf063e..c95d151b 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.cxx @@ -23,6 +23,7 @@ #include "CurveCreator_Curve.hxx" #include "CurveCreator.hxx" +#include "CurveCreator_PosPoint.hxx" #include "CurveCreator_Section.hxx" #include "CurveCreator_Displayer.h" @@ -398,6 +399,25 @@ bool CurveCreator_Curve::moveSection(const int theISection, return res; } +void CurveCreator_Curve::convert( const SectionToPointList& thePoints, + std::map>& theConvPoints ) +{ + theConvPoints.clear(); + + SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end(); + std::list aPoints; + int aSectionId, aPointId; + for ( ; anIt != aLast; anIt++ ) { + aSectionId = anIt->first; + aPointId = anIt->second; + aPoints.clear(); + if ( theConvPoints.find( aSectionId ) != theConvPoints.end() ) + aPoints = theConvPoints[aSectionId]; + aPoints.push_back( aPointId ); + theConvPoints[aSectionId] = aPoints; + } +} + /************ Implementation of INTERFACE methods ************/ /***********************************************/ @@ -775,35 +795,35 @@ bool CurveCreator_Curve::setSectionType( const int theISection, /***********************************************/ //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::addPointsInternal( const CurveCreator::Coordinates& theCoords, - const std::vector &theISections, - const std::vector &theIPnts ) +bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ) { bool res = false; - if( (theCoords.size()/getDimension()) == theISections.size() == theIPnts.size() ) { - for( int ind = 0; ind < theISections.size(); ind++ ) { - int anISection = theISections.at(ind); - CurveCreator_Section *aSection = - (anISection == -1 ? mySections.back() : mySections.at(anISection)); - - if( aSection ) { - int anIPnt = theIPnts.at(ind); + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + CurveCreator_Section *aSection = 0; + for ( ; anIt != theSectionsMap.end(); anIt++ ) { + int anISection = anIt->first; + aSection = mySections.at(anISection); + if( aSection ) { + CurveCreator::PosPointsList aSectionPoints = anIt->second; + CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); + for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){ + int anIPnt = (*aPntIt)->myID; + CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords; CurveCreator::Coordinates::iterator anIterPosition; if(anIPnt == -1) anIterPosition = aSection->myPoints.end(); else anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt); CurveCreator::Coordinates::const_iterator aFirstPosition = - theCoords.begin() + toICoord(ind); + aCoords.begin(); aSection->myPoints.insert(anIterPosition, - aFirstPosition, - aFirstPosition + getDimension()); - res = true; + aCoords.begin(), aCoords.end()); } + res = true; } - if(res) - redisplayCurve(); } + if(res) + redisplayCurve(); return res; } @@ -820,34 +840,47 @@ bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords, // Set the difference. startOperation(); if (addEmptyDiff()) { + CurveCreator_ICurve::SectionToPointCoordsList aList; + aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords)); myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints, - theCoords, theISection, theIPnt); + aList); } - std::vector anISections, anIPnts; - anISections.push_back( theISection ); - anIPnts.push_back( theIPnt ); - res = addPointsInternal( theCoords, anISections, anIPnts ); + CurveCreator::SectionsMap aSectionsMap; + CurveCreator::PosPointsList aPoints; + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords ); + aPoints.push_back( aPosPoint ); + aSectionsMap[theISection] = aPoints; + + res = addPointsInternal( aSectionsMap ); + finishOperation(); return res; } //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setPointInternal( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theNewCoords ) +bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ) { bool res = false; // Update the curve. - if (theNewCoords.size() == myDimension) { - CurveCreator_Section *aSection = mySections.at(theISection); - int i; - for (i = 0; i < myDimension; i++) { - aSection->myPoints.at(toICoord(theIPnt) + i) = theNewCoords[i]; + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + CurveCreator_Section *aSection = 0; + for ( ; anIt != theSectionsMap.end(); anIt++ ) { + int anISection = anIt->first; + aSection = mySections.at(anISection); + if( aSection ) { + CurveCreator::PosPointsList aSectionPoints = anIt->second; + CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); + for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){ + int anIPnt = (*aPntIt)->myID; + CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords; + aSection->myPoints.assign(aCoords.begin(), aCoords.end()); + } + res = true; } - redisplayCurve(); - - res = true; } + if(res) + redisplayCurve(); + return res; } @@ -860,10 +893,18 @@ bool CurveCreator_Curve::setPoint( const int theISection, // Set the difference. startOperation(); if (addEmptyDiff()) { + CurveCreator_ICurve::SectionToPointCoordsList aList; + aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords)); myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates, - theNewCoords, theISection, theIPnt); + aList); } - res = setPointInternal( theISection, theIPnt, theNewCoords ); + CurveCreator::SectionsMap aSectionsMap; + CurveCreator::PosPointsList aPoints; + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords ); + aPoints.push_back( aPosPoint ); + aSectionsMap[theISection] = aPoints; + + res = setPointInternal( aSectionsMap ); finishOperation(); return res; @@ -876,28 +917,35 @@ bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSe } //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::removePointsInternal( const std::vector &theISections, - const std::vector &theIPnts ) +bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints ) { bool res = false; - if( theISections.size() == theIPnts.size() ) { - for( int ind = 0; ind < theISections.size(); ind++ ) { - int anISection = theISections.at(ind); - CurveCreator_Section *aSection = mySections.at(anISection); - if( aSection ) { - int anIPnt = theIPnts.at(ind); + std::map > aConvPoints; + convert( thePoints, aConvPoints ); + std::map >::const_iterator anIt = aConvPoints.begin(), + aLast = aConvPoints.end(); + CurveCreator_Section *aSection = 0; + for ( ; anIt != aLast; anIt++ ) { + int aSectionId = anIt->first; + aSection = mySections.at(aSectionId); + if( aSection ) { + std::list aSectionPoints = anIt->second; + aSectionPoints.sort(); + std::list::const_reverse_iterator aPntIt = aSectionPoints.rbegin(); + for( ; aPntIt != aSectionPoints.rend(); aPntIt++ ){ + int aPntIndx = *aPntIt; CurveCreator::Coordinates::iterator aFirstPosition; - if(anIPnt == -1) - aFirstPosition = aSection->myPoints.end(); + if(aPntIndx == -1) + aFirstPosition = aSection->myPoints.end() - getDimension(); else - aFirstPosition = aSection->myPoints.begin() + toICoord(anIPnt); + aFirstPosition = aSection->myPoints.begin() + toICoord(aPntIndx); aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() ); res = true; } } - if(res) - redisplayCurve(); } + if(res) + redisplayCurve(); return res; } @@ -911,10 +959,9 @@ bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt ) myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints, theISection, theIPnt); } - std::vector anISections, anIPnts; - anISections.push_back( theISection ); - anIPnts.push_back( theIPnt ); - res = removePointsInternal( anISections, anIPnts ); + SectionToPointList aListOfSectionsToPoints; + aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt)); + res = removePointsInternal( aListOfSectionsToPoints ); finishOperation(); return res; } @@ -922,7 +969,16 @@ bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt ) //! Remove several points from different sections with given ids bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) { - return false; + bool res = false; + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints, + theSectionToPntIDs); + } + res = removePointsInternal( theSectionToPntIDs ); + finishOperation(); + return res; } //======================================================================= diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.hxx b/src/HYDROCurveCreator/CurveCreator_Curve.hxx index cc6d97b2..5747dd8b 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.hxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.hxx @@ -34,6 +34,7 @@ #include #include +#include struct CurveCreator_Section; class CurveCreator_Displayer; @@ -114,6 +115,9 @@ protected: void redisplayCurve(); + void convert( const SectionToPointList &thePoints, + std::map > &theConvPoints ); + public: /************ Implementation of INTERFACE methods ************/ @@ -215,9 +219,7 @@ public: /***********************************************/ //! For internal use only! Undo/Redo are not used here. - virtual bool addPointsInternal( const CurveCreator::Coordinates &theCoords, - const std::vector &theISections, - const std::vector &theIPnts ); + virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ); /** * Add one point to the specified section starting from the given theIPnt index * (or at the end of points if \a theIPnt is -1). @@ -227,9 +229,7 @@ public: const int theIPnt = -1 ); //! For internal use only! Undo/Redo are not used here. - virtual bool setPointInternal( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theNewCoords ); + virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ); //! Set coordinates of specified point virtual bool setPoint( const int theISection, const int theIPnt, @@ -239,8 +239,7 @@ public: virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords); //! For internal use only! Undo/Redo are not used here. - virtual bool removePointsInternal( const std::vector &theISections, - const std::vector &theIPnts ); + virtual bool removePointsInternal( const SectionToPointList &thePoints ); /** Remove point with given id */ virtual bool removePoint( const int theISection, const int theIPnt = -1 ); diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.cxx b/src/HYDROCurveCreator/CurveCreator_Diff.cxx index 1e21a31c..fba15d13 100644 --- a/src/HYDROCurveCreator/CurveCreator_Diff.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Diff.cxx @@ -203,25 +203,6 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, } } break; - case CurveCreator_Operation::RemovePoints: - { - // Construct undo for RemovePoints command. - const CurveCreator::Dimension aDim = theCurve->getDimension(); - const CurveCreator::Coordinates &aPoints = - theCurve->getPoints(theIntParam1); - CurveCreator::Coordinates::const_iterator anIterBegin = - aPoints.begin() + (aDim*theIntParam2); - CurveCreator::Coordinates::const_iterator anIterEnd = - anIterBegin + aDim; - - CurveCreator::Coordinates aPointsToAdd; - - setNbUndos(1); - aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd); - isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints, - aPointsToAdd, theIntParam1, theIntParam2); - } - break; default: break; } @@ -336,15 +317,33 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, return isOK; } -//======================================================================= -// function: init -// purpose: -//======================================================================= bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, const CurveCreator_Operation::Type theType, - const CurveCreator::Coordinates &theCoords, - const int theIntParam1, - const int theIntParam2) + const std::string &theName, + const int theIntParam1 ) +{ + bool isOK = false; + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theName, theIntParam1 )) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::RenameSection: + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection, + theCurve->getSectionName(theIntParam1), theIntParam1); + break; + } + } + if( !isOK ){ + clear(); + } + return isOK; +} + +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator_ICurve::SectionToPointList &theParamList1) { bool isOK = false; @@ -354,35 +353,34 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, // Set redo. myPRedo = new CurveCreator_Operation; - if (myPRedo->init(theType, theCoords, theIntParam1, theIntParam2)) { + if (myPRedo->init(theType, theParamList1)) { // Construct undo for different commands. switch (theType) { - case CurveCreator_Operation::InsertPoints: + case CurveCreator_Operation::RemovePoints: { + // Construct undo for RemovePoints command. + CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointCoords; + CurveCreator::Coordinates aPointsToAdd; const CurveCreator::Dimension aDim = theCurve->getDimension(); - const int aNbPoints = (theCoords.size()/aDim); - const int aSectionInd = getSectionIndex(theCurve, theIntParam1); - int aPointInd; - - if (theIntParam2 == -1) { - aPointInd = theCurve->getNbPoints(aSectionInd); - } else { - aPointInd = theIntParam2; + CurveCreator_ICurve::SectionToPointList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end(); + std::list aPoints; + int aSectionId, aPointId; + for ( ; anIt != aLast; anIt++ ) { + aPointsToAdd.clear(); + aSectionId = anIt->first; + aPointId = anIt->second; + const CurveCreator::Coordinates &aPoints = + theCurve->getPoints(aSectionId); + CurveCreator::Coordinates::const_iterator anIterBegin = + aPoints.begin() + (aDim*aPointId); + CurveCreator::Coordinates::const_iterator anIterEnd = + anIterBegin + aDim; + aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd); + aSectionToPointCoords.push_back(std::make_pair(*anIt, aPointsToAdd)); } - - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, - aSectionInd, aPointInd); - } - break; - case CurveCreator_Operation::SetCoordinates: - { - const CurveCreator::Coordinates anOldCoords = - theCurve->getPoint(theIntParam1, theIntParam2); - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates, - anOldCoords, theIntParam1, theIntParam2); + isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints, + aSectionToPointCoords); } break; default: @@ -400,25 +398,58 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, const CurveCreator_Operation::Type theType, - const std::string &theName, - const int theIntParam1 ) + const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1) { bool isOK = false; - myPRedo = new CurveCreator_Operation; - if (myPRedo->init(theType, theName, theIntParam1 )) { - // Construct undo for different commands. - switch (theType) { - case CurveCreator_Operation::RenameSection: - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection, - theCurve->getSectionName(theIntParam1), theIntParam1); - break; - } - } - if( !isOK ){ + if (theCurve != NULL) { clear(); + + // Set redo. + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theParamList1)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::InsertPoints: + { + // Construct undo for RemovePoints command. + CurveCreator_ICurve::SectionToPointList aSectionToPointList; + CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end(); + int aSectionId, aPointId; + for ( ; anIt != aLast; anIt++ ) { + aSectionToPointList.push_back(anIt->first); + } + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, + aSectionToPointList); + } + break; + case CurveCreator_Operation::SetCoordinates: + { + // Construct undo for SetCoordinates command. + CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointOldCoords; + CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end(); + for ( ; anIt != aLast; anIt++ ) { + CurveCreator::Coordinates anOldCoords = theCurve->getPoint(anIt->first.first, anIt->first.second); + aSectionToPointOldCoords.push_back(std::make_pair(anIt->first, anOldCoords)); + } + + setNbUndos(1); + isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates, + aSectionToPointOldCoords); + } + break; + default: + break; + } + } + + if (!isOK) { + clear(); + } } + return isOK; } diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.hxx b/src/HYDROCurveCreator/CurveCreator_Diff.hxx index 291aaee3..b94dadaf 100644 --- a/src/HYDROCurveCreator/CurveCreator_Diff.hxx +++ b/src/HYDROCurveCreator/CurveCreator_Diff.hxx @@ -116,46 +116,55 @@ public: /** * This method initializes the difference with an operation with one - * CurveCreator::Coordinates parameter and two integer parameters. + * Name, one CurveCreator::Coordinates parameter and two integer parameters. * It is applicable to the following operations: *
    - *
  • InsertPoints
  • - *
  • SetCoordinates
  • + *
  • AddSection
  • *
*/ bool init(const CurveCreator_Curve *theCurve, const CurveCreator_Operation::Type theType, + const std::string& theName, const CurveCreator::Coordinates &theCoords, const int theIntParam1, const int theIntParam2); /** * This method initializes the difference with an operation with one - * Name, one CurveCreator::Coordinates parameter and two integer parameters. + * string and one integer parameters. * It is applicable to the following operations: *
    - *
  • AddSection
  • + *
  • RenameSection
  • *
*/ bool init(const CurveCreator_Curve *theCurve, const CurveCreator_Operation::Type theType, - const std::string& theName, - const CurveCreator::Coordinates &theCoords, - const int theIntParam1, - const int theIntParam2); + const std::string &theName, + const int theIntParam1 ); /** - * This method initializes the difference with an operation with one - * string and one integer parameters. + * This method initializes the difference with an operation with + * list of pairs of integer parameters. * It is applicable to the following operations: *
    - *
  • RenameSection
  • + *
  • RemovePoints
  • *
*/ bool init(const CurveCreator_Curve *theCurve, const CurveCreator_Operation::Type theType, - const std::string &theName, - const int theIntParam1 ); + const CurveCreator_ICurve::SectionToPointList &theParamList); + + /** + * This method initializes the difference with an operation with + * list of pairs of integer parameters with point coordinates. + * It is applicable to the following operations: + *
    + *
  • RemovePoints
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const CurveCreator_ICurve::SectionToPointCoordsList &theParamList); /** * This method applies undo operation to theCurve. diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.cxx b/src/HYDROCurveCreator/CurveCreator_Operation.cxx index ce73d1cc..fa9cdb07 100644 --- a/src/HYDROCurveCreator/CurveCreator_Operation.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Operation.cxx @@ -22,6 +22,7 @@ #include "CurveCreator_Operation.hxx" #include "CurveCreator_Curve.hxx" +#include "CurveCreator.hxx" #include #include @@ -46,6 +47,11 @@ CurveCreator_Operation::~CurveCreator_Operation() clear(); } +bool compId(CurveCreator_PosPoint* p1, CurveCreator_PosPoint* p2) +{ + return p1->myID < p2->myID; +} + //======================================================================= // function: Constructor // purpose: @@ -178,9 +184,7 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, { bool isOK = false; - if (theType == CurveCreator_Operation::AddSection || - theType == CurveCreator_Operation::InsertPoints || - theType == CurveCreator_Operation::SetCoordinates) { + if (theType == CurveCreator_Operation::AddSection) { const int aNbCoords = theCoords.size(); const size_t aSize = 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord); @@ -270,6 +274,84 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, return false; } +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::InsertPoints || + theType == CurveCreator_Operation::SetCoordinates ) { + + const int aNbPoints = theParamList1.size(); + + CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = + theParamList1.begin(); + const int aNbCoords = anIt->second.size(); + + const size_t aSize = + sizeof(aNbPoints) + sizeof(aNbCoords) + + aNbPoints * (3*sizeof(int) + aNbCoords*sizeof(CurveCreator::TypeCoord)); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = aNbPoints; + *pIntData++ = aNbCoords; + int aSectionId, aPointId; + for ( ; anIt != theParamList1.end(); anIt++ ) { + aSectionId = anIt->first.first; + aPointId = anIt->first.second; + + *pIntData++ = aSectionId; + *pIntData++ = aPointId; + *pIntData++ = aNbCoords; + + const CurveCreator::Coordinates &aCoords = anIt->second; + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; + for (int i = 0; i < aNbCoords; i++) { + *pRealData++ = aCoords[i]; + } + pIntData = (int *)pRealData; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator_ICurve::SectionToPointList &theParamList1) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::RemovePoints) { + const int aNbPoints = theParamList1.size(); + + CurveCreator_ICurve::SectionToPointList::const_iterator anIt = + theParamList1.begin(); + + const size_t aSize = + sizeof(aNbPoints) + + aNbPoints * (2*sizeof(int)); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = aNbPoints; + int aSectionId, aPointId; + for ( ; anIt != theParamList1.end(); anIt++ ) { + aSectionId = anIt->first; + aPointId = anIt->second; + + *pIntData++ = aSectionId; + *pIntData++ = aPointId; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + //======================================================================= // function: apply // purpose: @@ -282,22 +364,48 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) switch (myType) { case CurveCreator_Operation::AddPoints: case CurveCreator_Operation::InsertPoints: + case CurveCreator_Operation::SetCoordinates: { + int aSectionId, aPointId; + CurveCreator::SectionsMap aSectionsMap; + CurveCreator::PosPointsList aPoints; CurveCreator::Coordinates aCoords; - getCoords(&pInt[2], aCoords); - std::vector anISections, anIPnts; - anISections.push_back( pInt[0] ); - anIPnts.push_back( pInt[1] ); - theCurve->addPointsInternal(aCoords, anISections, anIPnts); + int nbPoints = pInt[0]; + int nbCoords = pInt[1]; + int nbParams = 3+nbCoords; + for (int i = 0; i < nbPoints*nbParams; i=i+nbParams) { + aCoords.clear(); + aPoints.clear(); + getCoords(&pInt[4+i], aCoords); + aSectionId = pInt[2+i]; + aPointId = pInt[3+i]; + if ( aSectionsMap.find( aSectionId ) != aSectionsMap.end() ) + aPoints = aSectionsMap[aSectionId]; + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( aPointId, aCoords ); + aPoints.push_back( aPosPoint ); + aPoints.sort(compId); + aSectionsMap[aSectionId] = aPoints; + } + switch (myType) { + case CurveCreator_Operation::AddPoints: + case CurveCreator_Operation::InsertPoints: + theCurve->addPointsInternal( aSectionsMap ); + break; + case CurveCreator_Operation::SetCoordinates: + theCurve->setPointInternal( aSectionsMap ); + break; + } } break; case CurveCreator_Operation::RemovePoints: { - std::vector anISections, anIPnts; - anISections.push_back( pInt[0] ); - anIPnts.push_back( pInt[1] ); - theCurve->removePointsInternal(anISections, anIPnts); + CurveCreator_ICurve::SectionToPointList aListOfSectionsToPoints; + int nbPoints = pInt[0]; + for (int i = 1; i < nbPoints*2; i=i+2) { + aListOfSectionsToPoints.push_back(std::make_pair(pInt[i], pInt[i+1])); + } + theCurve->removePointsInternal(aListOfSectionsToPoints); } break; case CurveCreator_Operation::SetType: @@ -310,14 +418,6 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) case CurveCreator_Operation::Clear: theCurve->clearInternal(); break; - case CurveCreator_Operation::SetCoordinates: - { - CurveCreator::Coordinates aCoords; - - getCoords(&pInt[2], aCoords); - theCurve->setPointInternal(pInt[0], pInt[1], aCoords); - } - break; case CurveCreator_Operation::SetClosed: theCurve->setClosedInternal((pInt[0] != 0), pInt[1]); break; diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.hxx b/src/HYDROCurveCreator/CurveCreator_Operation.hxx index 0c84c468..be8ceef6 100644 --- a/src/HYDROCurveCreator/CurveCreator_Operation.hxx +++ b/src/HYDROCurveCreator/CurveCreator_Operation.hxx @@ -24,8 +24,11 @@ #define _CurveCreator_Operation_HeaderFile #include "CurveCreator.hxx" +#include "CurveCreator_ICurve.hxx" +#include "CurveCreator_PosPoint.hxx" #include +#include class CurveCreator_Curve; @@ -104,6 +107,18 @@ public: bool init(const Type theType, const int theIntParam1, const int theIntParam2); + /** + * This method initializes the object with an operation with + * list of pairs of integer parameters. + * It is applicable to the following operations: + *
    + *
  • RemovePoints
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, + const CurveCreator_ICurve::SectionToPointList &theParamList1); + /** * This method initializes the object with an operation with three integer * parameters. It is applicable to the following operations: @@ -140,6 +155,17 @@ public: */ bool init(const Type theType, const CurveCreator::Coordinates &theCoords, const int theIntParam1, const int theIntParam2); + /** + * This method initializes the object with an operation with + * list of pairs of integer parameters and CurveCreator::Coordinates parameters. + * It is applicable to the following operations: + *
    + *
  • InsertPoints
  • + *
+ * @return true in case of success; false otherwise. + */ + bool init(const Type theType, + const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1); /** * This method initializes the object with an operation with one diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index b054e983..fa6ae3d1 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -75,8 +75,6 @@ const int POINT_INDEX_COLUMN_WIDTH = 40; const int SCENE_PIXEL_TOLERANCE = 10; -//#define USE_SEVERAL_POINTS - CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, CurveCreator_ICurve *theCurve, Qt::WindowFlags fl) @@ -1026,26 +1024,7 @@ void CurveCreator_Widget::removePoint() SectionToPointList aSelPoints; startCurveModification( aSelPoints, false ); -#ifdef USE_SEVERAL_POINTS myCurve->removeSeveralPoints( aPoints ); -#else - // the points should be removed in a decreased order - QMap > aConvPoints; - convert( aPoints, aConvPoints ); - QMap >::const_iterator anIt = aConvPoints.begin(), - aLast = aConvPoints.end(); - for ( ; anIt != aLast; anIt++ ) { - int aSectionId = anIt.key(); - - QList aSectionPoints = anIt.value(); - qSort( aSectionPoints ); - for( int i = aSectionPoints.size()-1; i >= 0; i-- ){ - int aPntIndx = aSectionPoints[i]; - myCurve->removePoint( aSectionId, aPntIndx ); - mySectionView->pointsRemoved( aSectionId, aPntIndx ); - } - } -#endif finishCurveModification( SectionToPointList() ); } @@ -1150,13 +1129,8 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, continue; aChangedPos[0] = aChangedPos[0] - aXDelta; aChangedPos[1] = aChangedPos[1] - anYDelta; -#ifndef USE_SEVERAL_POINTS - myCurve->setPoint( anIt->first, anIt->second, aChangedPos ); -#endif } -#ifdef USE_SEVERAL_POINTS myCurve->setSeveralPoints( aCoordList ); -#endif myDragged = true; finishCurveModification( myDragPoints );