#include "CurveCreator_Curve.hxx"
#include "CurveCreator.hxx"
+#include "CurveCreator_PosPoint.hxx"
#include "CurveCreator_Section.hxx"
#include "CurveCreator_Displayer.h"
myDisplayer = theDisplayer;
}
+//=======================================================================
+// function: getDisplayer
+// purpose: get curve changes Displayer
+//=======================================================================
+CurveCreator_Displayer* CurveCreator_Curve::getDisplayer()
+{
+ return myDisplayer;
+}
+
//=======================================================================
// function: removeDisplayer
// purpose: remove the attached Displayer
return res;
}
+void CurveCreator_Curve::convert( const SectionToPointList& thePoints,
+ std::map< int, std::list<int> >& theConvPoints )
+{
+ theConvPoints.clear();
+
+ SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
+ std::list<int> aPoints;
+ int aSectionId, aPointId;
+ for ( ; anIt != aLast; anIt++ ) {
+ aSectionId = anIt->first;
+ aPointId = anIt->second;
+ aPoints.clear();
+ if ( theConvPoints.find( aSectionId ) != theConvPoints.end() )
+ aPoints = theConvPoints[aSectionId];
+ aPoints.push_back( aPointId );
+ theConvPoints[aSectionId] = aPoints;
+ }
+}
+
/************ Implementation of INTERFACE methods ************/
/***********************************************/
const int theISectionFrom )
{
bool res = false;
- if (theISectionTo != theISectionFrom) {
+ if (mySections.size() >= 2 &&
+ ( theISectionTo != theISectionFrom || (theISectionTo == -1 && theISectionFrom == -1) )) {
startOperation();
+ int aISectionTo = getNbSections()-1;
+ int aISectionFrom = 0;
if (addEmptyDiff())
- myListDiffs.back().init(this, CurveCreator_Operation::Join, theISectionTo, theISectionFrom);
+ myListDiffs.back().init(this, CurveCreator_Operation::Join, aISectionTo, aISectionFrom);
- res = joinInternal( theISectionTo, theISectionFrom );
+ res = joinInternal( aISectionTo, aISectionFrom );
finishOperation();
}
aNbCoords += mySections[i]->myPoints.size();
}
} else {
- aNbCoords = mySections.at(theISection)->myPoints.size();
+ if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) )
+ aNbCoords = mySections.at(theISection)->myPoints.size();
}
return aNbCoords/myDimension;
/***********************************************/
//! For internal use only! Undo/Redo are not used here.
-bool CurveCreator_Curve::addPointsInternal( const CurveCreator::Coordinates& theCoords,
- const std::vector<int> &theISections,
- const std::vector<int> &theIPnts )
+bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
{
bool res = false;
- if( (theCoords.size()/getDimension()) == theISections.size() == theIPnts.size() ) {
- for( int ind = 0; ind < theISections.size(); ind++ ) {
- int anISection = theISections.at(ind);
- CurveCreator_Section *aSection =
- (anISection == -1 ? mySections.back() : mySections.at(anISection));
-
- if( aSection ) {
- int anIPnt = theIPnts.at(ind);
+ CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
+ CurveCreator_Section *aSection = 0;
+ for ( ; anIt != theSectionsMap.end(); anIt++ ) {
+ int anISection = anIt->first;
+ aSection = mySections.at(anISection);
+ if( aSection ) {
+ CurveCreator::PosPointsList aSectionPoints = anIt->second;
+ CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
+ for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
+ int anIPnt = (*aPntIt)->myID;
+ CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
CurveCreator::Coordinates::iterator anIterPosition;
if(anIPnt == -1)
anIterPosition = aSection->myPoints.end();
else
anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt);
CurveCreator::Coordinates::const_iterator aFirstPosition =
- theCoords.begin() + toICoord(ind);
+ aCoords.begin();
aSection->myPoints.insert(anIterPosition,
- aFirstPosition,
- aFirstPosition + getDimension());
- res = true;
+ aCoords.begin(), aCoords.end());
}
+ res = true;
}
- if(res)
- redisplayCurve();
}
+ if(res)
+ redisplayCurve();
return res;
}
// Set the difference.
startOperation();
if (addEmptyDiff()) {
+ CurveCreator_ICurve::SectionToPointCoordsList aList;
+ aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords));
myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints,
- theCoords, theISection, theIPnt);
+ aList);
}
- std::vector<int> anISections, anIPnts;
- anISections.push_back( theISection );
- anIPnts.push_back( theIPnt );
- res = addPointsInternal( theCoords, anISections, anIPnts );
+ CurveCreator::SectionsMap aSectionsMap;
+ CurveCreator::PosPointsList aPoints;
+ CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords );
+ aPoints.push_back( aPosPoint );
+ aSectionsMap[theISection] = aPoints;
+
+ res = addPointsInternal( aSectionsMap );
+
finishOperation();
return res;
}
//! For internal use only! Undo/Redo are not used here.
-bool CurveCreator_Curve::setPointInternal( const int theISection,
- const int theIPnt,
- const CurveCreator::Coordinates& theNewCoords )
+bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
{
bool res = false;
// Update the curve.
- if (theNewCoords.size() == myDimension) {
- CurveCreator_Section *aSection = mySections.at(theISection);
- int i;
- for (i = 0; i < myDimension; i++) {
- aSection->myPoints.at(toICoord(theIPnt) + i) = theNewCoords[i];
+ CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
+ CurveCreator_Section *aSection = 0;
+ for ( ; anIt != theSectionsMap.end(); anIt++ ) {
+ int anISection = anIt->first;
+ aSection = mySections.at(anISection);
+ if( aSection ) {
+ CurveCreator::PosPointsList aSectionPoints = anIt->second;
+ CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
+ for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
+ int anIPnt = (*aPntIt)->myID;
+ CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
+ for ( int i = 0; i < myDimension; i++)
+ aSection->myPoints.at(toICoord(anIPnt) + i) = aCoords[i];
+ }
+ res = true;
}
- redisplayCurve();
-
- res = true;
}
+ if(res)
+ redisplayCurve();
+
return res;
}
// Set the difference.
startOperation();
if (addEmptyDiff()) {
+ CurveCreator_ICurve::SectionToPointCoordsList aList;
+ aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords));
myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
- theNewCoords, theISection, theIPnt);
+ aList);
}
- res = setPointInternal( theISection, theIPnt, theNewCoords );
+ CurveCreator::SectionsMap aSectionsMap;
+ CurveCreator::PosPointsList aPoints;
+ CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords );
+ aPoints.push_back( aPosPoint );
+ aSectionsMap[theISection] = aPoints;
+
+ int aSize1 = getNbPoints( theISection );
+ res = setPointInternal( aSectionsMap );
+ int aSize2 = getNbPoints( theISection );
+
finishOperation();
return res;
//! Set coordinates of specified points from different sections
bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords)
{
- return false;
+ bool res = false;
+ // Set the difference.
+ startOperation();
+ if (addEmptyDiff()) {
+ myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
+ theSectionToPntCoords);
+ }
+ CurveCreator::SectionsMap aSectionsMap;
+ CurveCreator::PosPointsList aPosPoints;
+ CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
+ theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end();
+ int aSectionId, aPointId;
+ for ( ; anIt != aLast; anIt++ ) {
+ aPosPoints.clear();
+ aSectionId = anIt->first.first;
+ aPointId = anIt->first.second;
+ CurveCreator::Coordinates aNewCoords = anIt->second;
+ CurveCreator_PosPoint* aPosPoint =
+ new CurveCreator_PosPoint( aPointId, aNewCoords );
+ if( aSectionsMap.find(aSectionId) != aSectionsMap.end() )
+ aPosPoints = aSectionsMap[aSectionId];
+ aPosPoints.push_back( aPosPoint );
+ aSectionsMap[aSectionId] = aPosPoints;
+
+ }
+ res = setPointInternal( aSectionsMap );
+ finishOperation();
+
+ return res;
}
//! For internal use only! Undo/Redo are not used here.
-bool CurveCreator_Curve::removePointsInternal( const std::vector<int> &theISections,
- const std::vector<int> &theIPnts )
+bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints )
{
bool res = false;
- if( theISections.size() == theIPnts.size() ) {
- for( int ind = 0; ind < theISections.size(); ind++ ) {
- int anISection = theISections.at(ind);
- CurveCreator_Section *aSection = mySections.at(anISection);
- if( aSection ) {
- int anIPnt = theIPnts.at(ind);
+ std::map<int, std::list<int> > aConvPoints;
+ convert( thePoints, aConvPoints );
+ std::map<int, std::list<int> >::const_iterator anIt = aConvPoints.begin(),
+ aLast = aConvPoints.end();
+ CurveCreator_Section *aSection = 0;
+ for ( ; anIt != aLast; anIt++ ) {
+ int aSectionId = anIt->first;
+ aSection = mySections.at(aSectionId);
+ if( aSection ) {
+ std::list<int> aSectionPoints = anIt->second;
+ aSectionPoints.sort();
+ std::list<int>::const_reverse_iterator aPntIt = aSectionPoints.rbegin();
+ for( ; aPntIt != aSectionPoints.rend(); aPntIt++ ){
+ int aPntIndx = *aPntIt;
CurveCreator::Coordinates::iterator aFirstPosition;
- if(anIPnt == -1)
- aFirstPosition = aSection->myPoints.end();
+ if(aPntIndx == -1)
+ aFirstPosition = aSection->myPoints.end() - getDimension();
else
- aFirstPosition = aSection->myPoints.begin() + toICoord(anIPnt);
+ aFirstPosition = aSection->myPoints.begin() + toICoord(aPntIndx);
aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() );
res = true;
}
}
- if(res)
- redisplayCurve();
}
+ if(res)
+ redisplayCurve();
return res;
}
myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
theISection, theIPnt);
}
- std::vector<int> anISections, anIPnts;
- anISections.push_back( theISection );
- anIPnts.push_back( theIPnt );
- res = removePointsInternal( anISections, anIPnts );
+ SectionToPointList aListOfSectionsToPoints;
+ aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
+ res = removePointsInternal( aListOfSectionsToPoints );
finishOperation();
return res;
}
//! Remove several points from different sections with given ids
bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs)
{
- return false;
+ bool res = false;
+ // Set the difference.
+ startOperation();
+ if (addEmptyDiff()) {
+ myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
+ theSectionToPntIDs);
+ }
+ res = removePointsInternal( theSectionToPntIDs );
+ finishOperation();
+ return res;
}
//=======================================================================
//=======================================================================
CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const
{
- return mySections.at(theISection)->myPoints;
+ CurveCreator::Coordinates aCoords;
+ if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) )
+ {
+ aCoords = mySections.at(theISection)->myPoints;
+ }
+ return aCoords;
}