-// Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2023 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include "CurveCreator_Diff.hxx"
#include "CurveCreator_Curve.hxx"
+#include "CurveCreator_Section.hxx"
+#include "CurveCreator_Utils.hxx"
#include <list>
// 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) {
// 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]);
}
}
}
if (myPRedo->init(theType, theIntParam)) {
// Construct undo for RemoveSection command.
// If the last section is removed, one AddSection command is enough.
- // If not last section is removed, two commands are requred: AddSection
+ // If not last section is removed, two commands are required: AddSection
// and MoveSection.
const int aLastIndex = theCurve->getNbSections() - 1;
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);
- }
-
- 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;
}
return isOK;
}
-//=======================================================================
-// function: init
-// purpose:
-//=======================================================================
bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
const int theIntParam1,
- const int theIntParam2,
- const int theIntParam3)
+ const int theIntParam2[3])
{
bool isOK = false;
- if (theCurve != NULL) {
+ if (theCurve != NULL)
+ {
clear();
-
- // Set redo.
myPRedo = new CurveCreator_Operation;
- if (myPRedo->init(theType, theIntParam1, theIntParam2, theIntParam3)) {
- // 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;
-
- if (theIntParam3 == -1) {
- anIterEnd = aPoints.end();
- } else {
- anIterEnd = anIterBegin + (aDim*theIntParam3);
- }
-
- CurveCreator::Coordinates aPointsToAdd;
+ if (myPRedo->init(theType, theIntParam1, theIntParam2))
+ {
+ Quantity_Color aColor = theCurve->getColorSection(theIntParam1);
setNbUndos(1);
- aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd);
- isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints,
- aPointsToAdd, theIntParam1, theIntParam2);
+ QColor aQColor = CurveCreator_Utils::colorConv(aColor);
+ int colorArr[3] = {aQColor.red(),aQColor.green(), aQColor.blue()};
+
+ isOK = myPUndo[0].init(theType, theIntParam1, colorArr);
}
- if (!isOK) {
+ if (!isOK)
clear();
- }
}
return isOK;
//=======================================================================
bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
- const CurveCreator::Coordinates &theCoords,
- const int theIntParam)
+ const std::list<int>& theParams)
{
bool isOK = false;
- if (theCurve != NULL) {
+ if (theCurve != NULL || theParams.empty()) {
clear();
// Set redo.
myPRedo = new CurveCreator_Operation;
- 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);
+ 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<int> 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<int>::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 );
- setNbUndos(1);
- isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
- aSectionInd, aNbPoints, -1);
+ int aJoinedSize = aNbPointsMain + aNbPointsInJoined;
+ CurveCreator_ICurve::SectionToPointList aSectionToPointList;
+ for (int anIPoint = aNbPointsMain; anIPoint < aJoinedSize; anIPoint++)
+ aSectionToPointList.push_back(std::make_pair(aSectionMain, anIPoint));
+
+ isOK = myPUndo[aNbUndos-1].init(CurveCreator_Operation::RemovePoints, aSectionToPointList);
+ }
+ }
+ break;
+ default:
+ break;
+ }
}
if (!isOK) {
setNbUndos(1);
isOK = myPUndo[0].init(CurveCreator_Operation::RemoveSection, -1);
break;
+ default:
+ break;
}
}
}
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;
+ default:
+ 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;
// 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<int> aPoints;
+ int aSectionId, aPointId;
+ for ( ; anIt != aLast; anIt++ ) {
+ aPointsToAdd.clear();
+ aSectionId = anIt->first;
+ aPointId = anIt->second;
+ const CurveCreator::Coordinates &aPoints =
+ theCurve->getCoords(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::InsertPoints,
+ aSectionToPointCoords);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if (!isOK) {
+ clear();
+ }
+ }
+
+ return isOK;
+}
+
+bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
+ const CurveCreator_Operation::Type theType,
+ const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1)
+{
+ bool isOK = false;
+
+ 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();
+ for ( ; anIt != aLast; anIt++ ) {
+ aSectionToPointList.push_back(anIt->first);
+ }
setNbUndos(1);
isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
- aSectionInd, aPointInd, aNbPoints);
+ aSectionToPointList);
}
break;
case CurveCreator_Operation::SetCoordinates:
{
- const CurveCreator::Coordinates anOldCoords =
- theCurve->getCoordinates(theIntParam1, theIntParam2);
+ // 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,
- anOldCoords, theIntParam1, theIntParam2);
+ aSectionToPointOldCoords);
}
break;
default:
}
bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
- const CurveCreator_Operation::Type theType,
- const std::string &theName,
- const int theIntParam1 )
+ const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList)
{
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 && theOldParamList.size() > 0) {
clear();
+
+ // Set redo.
+ myPRedo = new CurveCreator_Operation;
+
+ // Construct redo for SetCoordinates command.
+ CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointActualCoords;
+ CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
+ theOldParamList.begin(), aLast = theOldParamList.end();
+ for ( ; anIt != aLast; anIt++ ) {
+ CurveCreator::Coordinates anActualCoords = theCurve->getPoint(anIt->first.first, anIt->first.second);
+ aSectionToPointActualCoords.push_back(std::make_pair(anIt->first, anActualCoords));
+ }
+
+ if (myPRedo->init(CurveCreator_Operation::SetCoordinates, aSectionToPointActualCoords)) {
+ // Undo for SetCoordinates command.
+ setNbUndos(1);
+ isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates,
+ theOldParamList);
+ }
+
+ if (!isOK) {
+ clear();
+ }
}
+
return isOK;
}
const int theIndex,
CurveCreator_Operation &theOperation) const
{
- const CurveCreator::Coordinates &aPnts = theCurve->getPoints(theIndex);
- const CurveCreator::Type aType = theCurve->getType(theIndex);
+ const std::string aName = theCurve->getSectionName(theIndex);
+ const CurveCreator::Coordinates &aPnts = theCurve->getCoords(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;
}
// Get sections to be modified.
for (i = 0; i < aNbSections; i++) {
if (isSetType) {
- aValue = theCurve->getType(i);
+ aValue = theCurve->getSectionType(i);
} else {
aValue = theCurve->isClosed(i);
}
// There is only particular section modified.
// Check if there is a real modification required.
if (isSetType) {
- aValue = theCurve->getType(theIntParam2);
+ aValue = theCurve->getSectionType(theIntParam2);
} else {
aValue = theCurve->isClosed(theIntParam2);
}
std::list<int>::iterator anIter = aListOfInd.begin();
if (isSetType) {
- aValue = theCurve->getType(*anIter);
+ aValue = theCurve->getSectionType(*anIter);
} else {
aValue = theCurve->isClosed(*anIter);
}