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);
}
const CurveCreator::Coordinates& theNewCoords );
//! Set coordinates of specified points from different sections
- virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords);
+ virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
+ const bool theIsToSaveDiff = true );
//! For internal use only! Undo/Redo are not used here.
virtual bool removePointsInternal( const SectionToPointList &thePoints );
*/
virtual bool canPointsBeSorted();
+ /**
+ * Saves points coordinates difference.
+ * \param theOldCoords the old points coordinates
+ */
+ virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords );
+
/***********************************************/
/*** Presentation methods ***/
/***********************************************/
// 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);
}
return isOK;
}
+bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
+ const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList)
+{
+ bool isOK = false;
+
+ 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;
+}
+
//=======================================================================
// function: applyUndo
// purpose:
const CurveCreator_Operation::Type theType,
const CurveCreator_ICurve::SectionToPointCoordsList &theParamList);
+ /**
+ * This method initializes the difference with an operation with
+ * list of pairs of integer parameters with point coordinates.
+ * \param theCurve the modified curve
+ * \param theOldParamList the old parameters (to be saved for undo)
+ */
+ bool init(const CurveCreator_Curve *theCurve,
+ const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList);
+
/**
* This method applies undo operation to theCurve.
*/
const std::deque<float>& theNewCoords ) = 0;
//! Set coordinates of specified points from different sections
- virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords) = 0;
+ virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
+ const bool theIsToSaveDiff = true ) = 0;
//! Remove point with given id
virtual bool removePoint( const int theISection, const int theIPnt = -1 ) = 0;
*/
virtual bool canPointsBeSorted() = 0;
+ /**
+ * Saves points coordinates difference.
+ * \param theOldCoords the old points coordinates
+ */
+ virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords ) = 0;
+
/***********************************************/
/*** Presentation methods ***/
/***********************************************/
if ( myDragStarted ) {
bool isDragged = myDragged;
CurveCreator_ICurve::SectionToPointList aDraggedPoints;
- if ( myDragged )
+ CurveCreator_ICurve::SectionToPointCoordsList anInitialDragPointsCoords;
+ if ( myDragged ) {
aDraggedPoints = myDragPoints;
+ anInitialDragPointsCoords = myInitialDragPointsCoords;
+ }
setDragStarted( false );
int aSectionId = anIt->first;
int aPointId = anIt->second;
std::deque<float> aPos = myCurve->getPoint( aSectionId, aPointId );
-
+
aCoordList.push_back(
std::make_pair( std::make_pair( aSectionId, aPointId ), aPos ) );
}
- myCurve->setSeveralPoints( aCoordList );
+ myCurve->setSeveralPoints( aCoordList, false );
finishCurveModification( aDraggedPoints );
} else {
END_MEASURE_TIME( "drop" );
}
}
+
+ // Save drag difference
+ myCurve->saveCoordDiff( anInitialDragPointsCoords );
}
}
else // check whether the segment is clicked an a new point should be added to the segment
aChangedPos = myCurve->getPoint( aSectionId, aPointId );
if ( aChangedPos.size() < 2 )
continue;
+
+ // Remember drag points coordinates
+ if ( !myDragged ) {
+ myInitialDragPointsCoords.push_back(
+ std::make_pair(std::make_pair( aSectionId, aPointId ),
+ aChangedPos ));
+ }
+
aChangedPos[0] = aChangedPos[0] - aXDelta;
aChangedPos[1] = aChangedPos[1] - anYDelta;
std::make_pair(std::make_pair( aSectionId, aPointId ),
aChangedPos ));
}
- myCurve->setSeveralPoints( aCoordList );
+ myCurve->setSeveralPoints( aCoordList, false );
myDragged = true;
finishCurveModification( myDragPoints );
changeInteractionStyle( myDragInteractionStyle );
myDragStarted = false;
myDragPoints.clear();
+ myInitialDragPointsCoords.clear();
}
myDragged = false;
}
QPoint myDragStartPosition;
int myDragInteractionStyle;
CurveCreator_ICurve::SectionToPointList myDragPoints;
+ CurveCreator_ICurve::SectionToPointCoordsList myInitialDragPointsCoords;
bool myDragged;
QByteArray myGuiState;
};