X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Diff.cxx;h=d1a7dc3222e43426504b79b637fea80197b35ce0;hb=09d10e66ba0fac5353c8d1f138055fc6fe86fb65;hp=797cc68b18d7fdc797bb1f9f74ca6b4b268151ff;hpb=2d5ca9ab4332bedb9fc8b193c9f0b4f6d3fa8ce7;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.cxx b/src/HYDROCurveCreator/CurveCreator_Diff.cxx index 797cc68b..d1a7dc32 100644 --- a/src/HYDROCurveCreator/CurveCreator_Diff.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Diff.cxx @@ -49,9 +49,9 @@ CurveCreator_Diff::~CurveCreator_Diff() // function: init // purpose: //======================================================================= -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType) +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve) { + CurveCreator_Operation::Type aType = CurveCreator_Operation::Clear; bool isOK = false; if (theCurve != NULL) { @@ -60,36 +60,18 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, // Set redo. myPRedo = new CurveCreator_Operation; - if (myPRedo->init(theType)) { + if (myPRedo->init(aType)) { isOK = true; const int aNbSections = theCurve->getNbSections(); - if (theType == CurveCreator_Operation::Clear) { - // Construct undo for Clear command. - if (aNbSections > 0) { - setNbUndos(aNbSections); + // Construct undo for Clear command. + if (aNbSections > 0) { + setNbUndos(aNbSections); - for (int i = 0; i < aNbSections && isOK; i++) { - // Add AddSection command. - isOK = addSectionToUndo(theCurve, i, myPUndo[i]); - } - } - } else { // theType == CurveCreator_Operation::Join - // Construct undo for Join command. - if (aNbSections > 1) { - // Add the RemovePoints command to remove points of - // the second section fron the first one. - const int aNbPoints = theCurve->getNbPoints(0); - - setNbUndos(aNbSections); - isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, - 0, aNbPoints, -1); - - for (int i = 1; i < aNbSections && isOK; i++) { - // Add AddSection command. - isOK = addSectionToUndo(theCurve, i, myPUndo[i]); - } + for (int i = 0; i < aNbSections && isOK; i++) { + // Add AddSection command. + isOK = addSectionToUndo(theCurve, i, myPUndo[i]); } } } @@ -176,43 +158,6 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, setNbUndos(1); isOK = myPUndo[0].init(theType, theIntParam2, theIntParam1); break; - case CurveCreator_Operation::Join: - { - // If the last section is removed, one AddSection command is - // enough. If not last section is removed, two commands are - // requred: AddSection and MoveSection. - const int aLastIndex = theCurve->getNbSections() - 1; - const int aNbPoints = theCurve->getNbPoints(theIntParam1); - - if (theIntParam2 == aLastIndex) { - setNbUndos(2); - } else { - setNbUndos(3); - } - - // Construct undo for RemovePoints command. - int anISection = theIntParam1; - const int aNbPoints2 = theCurve->getNbPoints(theIntParam2); - CurveCreator_ICurve::SectionToPointList aSectionToPointList; - int aJoinedSize = aNbPoints + aNbPoints2; - for (int anIPoint = aNbPoints; anIPoint < aJoinedSize; anIPoint++) - aSectionToPointList.push_back(std::make_pair( anISection, anIPoint ) ); - isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, - aSectionToPointList); - - //isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, - // theIntParam1, aNbPoints, -1); - - if (isOK) { - isOK = addSectionToUndo(theCurve, theIntParam2, myPUndo[1]); - - if (isOK && theIntParam2 != aLastIndex) { - isOK = myPUndo[2].init(CurveCreator_Operation::MoveSection, - aLastIndex, theIntParam2); - } - } - } - break; default: break; } @@ -232,57 +177,68 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, //======================================================================= bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, const CurveCreator_Operation::Type theType, - const int theIntParam1, - const int theIntParam2, - const int theIntParam3) + const std::list& theParams) { bool isOK = false; - if (theCurve != NULL) { + if (theCurve != NULL || theParams.empty()) { clear(); // Set redo. myPRedo = new CurveCreator_Operation; - if (myPRedo->init(theType, theIntParam1, theIntParam2, theIntParam3)) { - } - - if (!isOK) { - clear(); - } - } - - return isOK; -} - -//======================================================================= -// function: init -// purpose: -//======================================================================= -bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, - const CurveCreator_Operation::Type theType, - const CurveCreator::Coordinates &theCoords, - const int theIntParam) -{ - bool isOK = false; - - if (theCurve != NULL) { - clear(); - - // Set redo. - myPRedo = new CurveCreator_Operation; + if (myPRedo->init(theType, theParams)) { + // Construct undo for different commands. + switch (theType) { + case CurveCreator_Operation::Join: + { + int aSectionMain = theParams.front(); + const int aNbPointsMain = theCurve->getNbPoints(aSectionMain); + + std::list aSectionsToJoin = theParams; + aSectionsToJoin.erase( aSectionsToJoin.begin() ); + // it is important to sort the section indices in order to correct perform undo + // for the move sections to the previous positions + aSectionsToJoin.sort(); + // 1rst undo for remove points from the main and n-1 undoes to contain joined sections + int aSectionsToJoinNb = aSectionsToJoin.size(); + int aNbUndos = 2*aSectionsToJoinNb + 1; + setNbUndos( aNbUndos ); + + // Add joined sections to undo + std::list::const_iterator anIt = aSectionsToJoin.begin(), + aLast = aSectionsToJoin.end(); + anIt = aSectionsToJoin.begin(); + int aLastSectionId = -1; + for (int i = 0; anIt != aLast && i < aSectionsToJoinNb; anIt++, i++) { + int anISection = *anIt; + isOK = addSectionToUndo( theCurve, anISection, myPUndo[i*2] ); + if (isOK) { + isOK = myPUndo[i*2+1].init(CurveCreator_Operation::MoveSection, + aLastSectionId, anISection); + if (!isOK) + break; + } + } + // Construct undo for RemovePoints command. + if (isOK) { + int aNbPointsInJoined = 0; + anIt = aSectionsToJoin.begin(); + for ( ; anIt != aLast; anIt++ ) + aNbPointsInJoined += theCurve->getNbPoints( *anIt ); - if (myPRedo->init(theType, theCoords, theIntParam)) { - // Construct undo for AddPoints command. - const int aSectionInd = getSectionIndex(theCurve, theIntParam); - const CurveCreator::Dimension aDim = theCurve->getDimension(); - const CurveCreator::Coordinates &aPoints = - theCurve->getPoints(aSectionInd); - const int aNbPoints = (aPoints.size()/aDim); + int aJoinedSize = aNbPointsMain + aNbPointsInJoined; + CurveCreator_ICurve::SectionToPointList aSectionToPointList; + for (int anIPoint = aNbPointsMain; anIPoint < aJoinedSize; anIPoint++) + aSectionToPointList.push_back(std::make_pair(aSectionMain, anIPoint)); - setNbUndos(1); - isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints, - aSectionInd, aNbPoints, -1); + isOK = myPUndo[aNbUndos-1].init(CurveCreator_Operation::RemovePoints, aSectionToPointList); + } + } + break; + default: + break; + } } if (!isOK) {