const int theNewIndex)
{
bool res = false;
- if (theISection != theNewIndex) {
- CurveCreator_Section *aSection = mySections.at(theISection);
+ int aMovedSectionId = theISection >= 0 ? theISection : mySections.size()-1;
+
+ if (aMovedSectionId != theNewIndex) {
+ CurveCreator_Section *aSection = mySections.at(aMovedSectionId);
// Remove section
- CurveCreator::Sections::iterator anIter = mySections.begin() + theISection;
+ CurveCreator::Sections::iterator anIter = mySections.begin() + aMovedSectionId;
mySections.erase(anIter);
startOperation();
// Set the difference.
if (addEmptyDiff()) {
- myListDiffs.back().init(this, CurveCreator_Operation::Clear);
+ myListDiffs.back().init(this);
}
res = clearInternal();
finishOperation();
}
//! For internal use only! Undo/Redo are not used here.
-bool CurveCreator_Curve::joinInternal( const int theISectionTo,
- const int theISectionFrom )
+bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
{
bool res = false;
- CurveCreator_Section *aSection1 = mySections.at(theISectionTo);
- CurveCreator_Section *aSection2 = mySections.at(theISectionFrom);
-
- aSection1->myPoints.insert(aSection1->myPoints.end(),
- aSection2->myPoints.begin(),
- aSection2->myPoints.end());
+ if ( theSections.empty() )
+ return res;
+
+ int anISectionMain = theSections.front();
+ CurveCreator_Section* aSectionMain = mySections.at( anISectionMain );
+ std::list <int> aSectionsToJoin = theSections;
+ aSectionsToJoin.erase( aSectionsToJoin.begin() ); // skip the main section
+ // it is important to sort and reverse the section ids in order to correctly remove them
+ aSectionsToJoin.sort();
+ aSectionsToJoin.reverse();
+
+ std::list<int>::const_iterator anIt = aSectionsToJoin.begin(), aLast = aSectionsToJoin.end();
+ CurveCreator_Section* aSection;
+ for (; anIt != aLast; anIt++) {
+ aSection = mySections.at(*anIt);
+ aSectionMain->myPoints.insert(aSectionMain->myPoints.end(), aSection->myPoints.begin(),
+ aSection->myPoints.end());
+ res = removeSectionInternal(*anIt);
+ if ( !res )
+ break;
+ }
- res = removeSection(theISectionFrom);
redisplayCurve();
return res;
}
-//! Join range of sections to one section (join all sections if -1 is passed in theISectionFrom argument)
-bool CurveCreator_Curve::join( const int theISectionTo,
- const int theISectionFrom )
+bool CurveCreator_Curve::join( const std::list<int>& theSections )
{
- //TODO
bool res = false;
- if ( theISectionTo != theISectionFrom ) {
+
+ if ( !theSections.empty() )
+ {
startOperation();
if (addEmptyDiff())
- myListDiffs.back().init(this, CurveCreator_Operation::Join, theISectionTo, theISectionFrom);
+ myListDiffs.back().init(this, CurveCreator_Operation::Join, theSections);
- res = joinInternal( theISectionTo, theISectionFrom );
+ res = joinInternal( theSections );
finishOperation();
}
return false;
}
+/**
+ * Saves points coordinates difference.
+ * \param theOldCoords the old points coordinates
+ */
+void CurveCreator_Curve::saveCoordDiff( const SectionToPointCoordsList &theOldCoords )
+{
+ // Set the difference.
+ startOperation();
+ if (addEmptyDiff()) {
+ myListDiffs.back().init(this, theOldCoords);
+ }
+ finishOperation();
+}
+
//! Get "closed" flag of the specified section
bool CurveCreator_Curve::isClosed( const int theISection ) const
{
}
//! Set coordinates of specified points from different sections
-bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords)
+bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
+ const bool theIsToSaveDiff )
{
bool res = false;
// Set the difference.
startOperation();
- if (addEmptyDiff()) {
+ if (theIsToSaveDiff && addEmptyDiff()) {
myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
theSectionToPntCoords);
}
bool res = false;
// Set the difference.
startOperation();
+ SectionToPointList aListOfSectionsToPoints;
+ aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
if (addEmptyDiff()) {
myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
- theISection, theIPnt);
+ aListOfSectionsToPoints);
}
- SectionToPointList aListOfSectionsToPoints;
- aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
res = removePointsInternal( aListOfSectionsToPoints );
finishOperation();
return res;