X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Diff.cxx;h=128deb7c10727e90b85192a5af5a90df032d2232;hb=8edd427af3997521bda72ca3c416cc1d490565d5;hp=1e21a31c6cd1c3cdda2fdf5cc0fe65a0704274f0;hpb=cab84b2968166d7b7b8673765307403b1f571a5b;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.cxx b/src/HYDROCurveCreator/CurveCreator_Diff.cxx index 1e21a31c..128deb7c 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; } @@ -494,12 +525,13 @@ bool CurveCreator_Diff::addSectionToUndo const int theIndex, CurveCreator_Operation &theOperation) const { + const std::string aName = theCurve->getSectionName(theIndex); const CurveCreator::Coordinates &aPnts = theCurve->getPoints(theIndex); const CurveCreator::SectionType aType = theCurve->getSectionType(theIndex); const bool isClosed = theCurve->isClosed(theIndex); bool isOK = theOperation.init(CurveCreator_Operation::AddSection, - aPnts, aType, isClosed); + aName, aPnts, aType, isClosed); return isOK; }