CurveCreator_Operation.hxx
CurveCreator_Section.hxx
CurveCreator_Utils.h
+ CurveCreator_PosPoint.hxx
)
# header files / to install
#define _CurveCreator_HeaderFile
#include <deque>
+#include <map>
+#include <list>
struct CurveCreator_Section;
+struct CurveCreator_PosPoint;
namespace CurveCreator
{
//! List of sections
typedef std::deque<CurveCreator_Section *> Sections;
+ // List of positioned points (points with coordinates)
+ typedef std::list<CurveCreator_PosPoint*> PosPointsList;
+ //! Map of sections with positioned points
+ typedef std::map<int,PosPointsList> SectionsMap;
};
#endif
#include "CurveCreator_Curve.hxx"
#include "CurveCreator.hxx"
+#include "CurveCreator_PosPoint.hxx"
#include "CurveCreator_Section.hxx"
#include "CurveCreator_Displayer.h"
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 ************/
/***********************************************/
/***********************************************/
//! 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;
+ aSection->myPoints.assign(aCoords.begin(), aCoords.end());
+ }
+ 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;
+
+ 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;
}
//=======================================================================
#include <AIS_InteractiveObject.hxx>
#include <list>
+#include <map>
struct CurveCreator_Section;
class CurveCreator_Displayer;
void redisplayCurve();
+ void convert( const SectionToPointList &thePoints,
+ std::map<int, std::list<int> > &theConvPoints );
+
public:
/************ Implementation of INTERFACE methods ************/
/***********************************************/
//! For internal use only! Undo/Redo are not used here.
- virtual bool addPointsInternal( const CurveCreator::Coordinates &theCoords,
- const std::vector<int> &theISections,
- const std::vector<int> &theIPnts );
+ virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap );
/**
* Add one point to the specified section starting from the given theIPnt index
* (or at the end of points if \a theIPnt is -1).
const int theIPnt = -1 );
//! For internal use only! Undo/Redo are not used here.
- virtual bool setPointInternal( const int theISection,
- const int theIPnt,
- const CurveCreator::Coordinates& theNewCoords );
+ virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap );
//! Set coordinates of specified point
virtual bool setPoint( const int theISection,
const int theIPnt,
virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords);
//! For internal use only! Undo/Redo are not used here.
- virtual bool removePointsInternal( const std::vector<int> &theISections,
- const std::vector<int> &theIPnts );
+ virtual bool removePointsInternal( const SectionToPointList &thePoints );
/** Remove point with given id */
virtual bool removePoint( const int theISection, const int theIPnt = -1 );
}
}
break;
- case CurveCreator_Operation::RemovePoints:
- {
- // 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 =
- anIterBegin + aDim;
-
- CurveCreator::Coordinates aPointsToAdd;
-
- setNbUndos(1);
- aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd);
- isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints,
- aPointsToAdd, theIntParam1, theIntParam2);
- }
- 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;
+ }
+ }
+ 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->getPoints(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::RemovePoints,
- aSectionInd, aPointInd);
- }
- break;
- case CurveCreator_Operation::SetCoordinates:
- {
- const CurveCreator::Coordinates anOldCoords =
- theCurve->getPoint(theIntParam1, theIntParam2);
-
setNbUndos(1);
- isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates,
- anOldCoords, theIntParam1, theIntParam2);
+ isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints,
+ aSectionToPointCoords);
}
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 &theParamList1)
{
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) {
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();
+ int aSectionId, aPointId;
+ for ( ; anIt != aLast; anIt++ ) {
+ aSectionToPointList.push_back(anIt->first);
+ }
+ setNbUndos(1);
+ isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
+ aSectionToPointList);
+ }
+ break;
+ case CurveCreator_Operation::SetCoordinates:
+ {
+ // 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,
+ aSectionToPointOldCoords);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (!isOK) {
+ clear();
+ }
}
+
return isOK;
}
/**
* This method initializes the difference with an operation with one
- * CurveCreator::Coordinates parameter and two integer parameters.
+ * Name, one CurveCreator::Coordinates parameter and two integer parameters.
* It is applicable to the following operations:
* <UL>
- * <LI>InsertPoints</LI>
- * <LI>SetCoordinates</LI>
+ * <LI>AddSection</LI>
* </UL>
*/
bool init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
+ const std::string& theName,
const CurveCreator::Coordinates &theCoords,
const int theIntParam1,
const int theIntParam2);
/**
* This method initializes the difference with an operation with one
- * Name, one CurveCreator::Coordinates parameter and two integer parameters.
+ * string and one integer parameters.
* It is applicable to the following operations:
* <UL>
- * <LI>AddSection</LI>
+ * <LI>RenameSection</LI>
* </UL>
*/
bool init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
- const std::string& theName,
- const CurveCreator::Coordinates &theCoords,
- const int theIntParam1,
- const int theIntParam2);
+ const std::string &theName,
+ const int theIntParam1 );
/**
- * This method initializes the difference with an operation with one
- * string and one integer parameters.
+ * This method initializes the difference with an operation with
+ * list of pairs of integer parameters.
* It is applicable to the following operations:
* <UL>
- * <LI>RenameSection</LI>
+ * <LI>RemovePoints</LI>
* </UL>
*/
bool init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
- const std::string &theName,
- const int theIntParam1 );
+ const CurveCreator_ICurve::SectionToPointList &theParamList);
+
+ /**
+ * This method initializes the difference with an operation with
+ * list of pairs of integer parameters with point coordinates.
+ * It is applicable to the following operations:
+ * <UL>
+ * <LI>RemovePoints</LI>
+ * </UL>
+ */
+ bool init(const CurveCreator_Curve *theCurve,
+ const CurveCreator_Operation::Type theType,
+ const CurveCreator_ICurve::SectionToPointCoordsList &theParamList);
/**
* This method applies undo operation to theCurve.
#include "CurveCreator_Operation.hxx"
#include "CurveCreator_Curve.hxx"
+#include "CurveCreator.hxx"
#include <string>
#include <stdlib.h>
clear();
}
+bool compId(CurveCreator_PosPoint* p1, CurveCreator_PosPoint* p2)
+{
+ return p1->myID < p2->myID;
+}
+
//=======================================================================
// function: Constructor
// purpose:
{
bool isOK = false;
- if (theType == CurveCreator_Operation::AddSection ||
- theType == CurveCreator_Operation::InsertPoints ||
- theType == CurveCreator_Operation::SetCoordinates) {
+ if (theType == CurveCreator_Operation::AddSection) {
const int aNbCoords = theCoords.size();
const size_t aSize =
3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord);
return false;
}
+bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
+ const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1)
+{
+ bool isOK = false;
+
+ if (theType == CurveCreator_Operation::InsertPoints ||
+ theType == CurveCreator_Operation::SetCoordinates ) {
+
+ const int aNbPoints = theParamList1.size();
+
+ CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
+ theParamList1.begin();
+ const int aNbCoords = anIt->second.size();
+
+ const size_t aSize =
+ sizeof(aNbPoints) + sizeof(aNbCoords) +
+ aNbPoints * (3*sizeof(int) + aNbCoords*sizeof(CurveCreator::TypeCoord));
+ int *pIntData = (int *)allocate(aSize);
+
+ *pIntData++ = aNbPoints;
+ *pIntData++ = aNbCoords;
+ int aSectionId, aPointId;
+ for ( ; anIt != theParamList1.end(); anIt++ ) {
+ aSectionId = anIt->first.first;
+ aPointId = anIt->first.second;
+
+ *pIntData++ = aSectionId;
+ *pIntData++ = aPointId;
+ *pIntData++ = aNbCoords;
+
+ const CurveCreator::Coordinates &aCoords = anIt->second;
+ CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData;
+ for (int i = 0; i < aNbCoords; i++) {
+ *pRealData++ = aCoords[i];
+ }
+ pIntData = (int *)pRealData;
+ }
+
+ myType = theType;
+ isOK = true;
+ }
+
+ return isOK;
+}
+
+bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
+ const CurveCreator_ICurve::SectionToPointList &theParamList1)
+{
+ bool isOK = false;
+
+ if (theType == CurveCreator_Operation::RemovePoints) {
+ const int aNbPoints = theParamList1.size();
+
+ CurveCreator_ICurve::SectionToPointList::const_iterator anIt =
+ theParamList1.begin();
+
+ const size_t aSize =
+ sizeof(aNbPoints) +
+ aNbPoints * (2*sizeof(int));
+ int *pIntData = (int *)allocate(aSize);
+
+ *pIntData++ = aNbPoints;
+ int aSectionId, aPointId;
+ for ( ; anIt != theParamList1.end(); anIt++ ) {
+ aSectionId = anIt->first;
+ aPointId = anIt->second;
+
+ *pIntData++ = aSectionId;
+ *pIntData++ = aPointId;
+ }
+
+ myType = theType;
+ isOK = true;
+ }
+
+ return isOK;
+}
+
//=======================================================================
// function: apply
// purpose:
switch (myType) {
case CurveCreator_Operation::AddPoints:
case CurveCreator_Operation::InsertPoints:
+ case CurveCreator_Operation::SetCoordinates:
{
+ int aSectionId, aPointId;
+ CurveCreator::SectionsMap aSectionsMap;
+ CurveCreator::PosPointsList aPoints;
CurveCreator::Coordinates aCoords;
- getCoords(&pInt[2], aCoords);
- std::vector<int> anISections, anIPnts;
- anISections.push_back( pInt[0] );
- anIPnts.push_back( pInt[1] );
- theCurve->addPointsInternal(aCoords, anISections, anIPnts);
+ int nbPoints = pInt[0];
+ int nbCoords = pInt[1];
+ int nbParams = 3+nbCoords;
+ for (int i = 0; i < nbPoints*nbParams; i=i+nbParams) {
+ aCoords.clear();
+ aPoints.clear();
+ getCoords(&pInt[4+i], aCoords);
+ aSectionId = pInt[2+i];
+ aPointId = pInt[3+i];
+ if ( aSectionsMap.find( aSectionId ) != aSectionsMap.end() )
+ aPoints = aSectionsMap[aSectionId];
+ CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( aPointId, aCoords );
+ aPoints.push_back( aPosPoint );
+ aPoints.sort(compId);
+ aSectionsMap[aSectionId] = aPoints;
+ }
+ switch (myType) {
+ case CurveCreator_Operation::AddPoints:
+ case CurveCreator_Operation::InsertPoints:
+ theCurve->addPointsInternal( aSectionsMap );
+ break;
+ case CurveCreator_Operation::SetCoordinates:
+ theCurve->setPointInternal( aSectionsMap );
+ break;
+ }
}
break;
case CurveCreator_Operation::RemovePoints:
{
- std::vector<int> anISections, anIPnts;
- anISections.push_back( pInt[0] );
- anIPnts.push_back( pInt[1] );
- theCurve->removePointsInternal(anISections, anIPnts);
+ CurveCreator_ICurve::SectionToPointList aListOfSectionsToPoints;
+ int nbPoints = pInt[0];
+ for (int i = 1; i < nbPoints*2; i=i+2) {
+ aListOfSectionsToPoints.push_back(std::make_pair(pInt[i], pInt[i+1]));
+ }
+ theCurve->removePointsInternal(aListOfSectionsToPoints);
}
break;
case CurveCreator_Operation::SetType:
case CurveCreator_Operation::Clear:
theCurve->clearInternal();
break;
- case CurveCreator_Operation::SetCoordinates:
- {
- CurveCreator::Coordinates aCoords;
-
- getCoords(&pInt[2], aCoords);
- theCurve->setPointInternal(pInt[0], pInt[1], aCoords);
- }
- break;
case CurveCreator_Operation::SetClosed:
theCurve->setClosedInternal((pInt[0] != 0), pInt[1]);
break;
#define _CurveCreator_Operation_HeaderFile
#include "CurveCreator.hxx"
+#include "CurveCreator_ICurve.hxx"
+#include "CurveCreator_PosPoint.hxx"
#include <string>
+#include <vector>
class CurveCreator_Curve;
bool init(const Type theType, const int theIntParam1,
const int theIntParam2);
+ /**
+ * This method initializes the object with an operation with
+ * list of pairs of integer parameters.
+ * It is applicable to the following operations:
+ * <UL>
+ * <LI>RemovePoints</LI>
+ * </UL>
+ * @return true in case of success; false otherwise.
+ */
+ bool init(const Type theType,
+ const CurveCreator_ICurve::SectionToPointList &theParamList1);
+
/**
* This method initializes the object with an operation with three integer
* parameters. It is applicable to the following operations:
*/
bool init(const Type theType, const CurveCreator::Coordinates &theCoords,
const int theIntParam1, const int theIntParam2);
+ /**
+ * This method initializes the object with an operation with
+ * list of pairs of integer parameters and CurveCreator::Coordinates parameters.
+ * It is applicable to the following operations:
+ * <UL>
+ * <LI>InsertPoints</LI>
+ * </UL>
+ * @return true in case of success; false otherwise.
+ */
+ bool init(const Type theType,
+ const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1);
/**
* This method initializes the object with an operation with one
const int SCENE_PIXEL_TOLERANCE = 10;
-//#define USE_SEVERAL_POINTS
-
CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
CurveCreator_ICurve *theCurve,
Qt::WindowFlags fl)
SectionToPointList aSelPoints;
startCurveModification( aSelPoints, false );
-#ifdef USE_SEVERAL_POINTS
myCurve->removeSeveralPoints( aPoints );
-#else
- // the points should be removed in a decreased order
- QMap<int, QList<int> > aConvPoints;
- convert( aPoints, aConvPoints );
- QMap<int, QList<int> >::const_iterator anIt = aConvPoints.begin(),
- aLast = aConvPoints.end();
- for ( ; anIt != aLast; anIt++ ) {
- int aSectionId = anIt.key();
-
- QList<int> aSectionPoints = anIt.value();
- qSort( aSectionPoints );
- for( int i = aSectionPoints.size()-1; i >= 0; i-- ){
- int aPntIndx = aSectionPoints[i];
- myCurve->removePoint( aSectionId, aPntIndx );
- mySectionView->pointsRemoved( aSectionId, aPntIndx );
- }
- }
-#endif
finishCurveModification( SectionToPointList() );
}
continue;
aChangedPos[0] = aChangedPos[0] - aXDelta;
aChangedPos[1] = aChangedPos[1] - anYDelta;
-#ifndef USE_SEVERAL_POINTS
- myCurve->setPoint( anIt->first, anIt->second, aChangedPos );
-#endif
}
-#ifdef USE_SEVERAL_POINTS
myCurve->setSeveralPoints( aCoordList );
-#endif
myDragged = true;
finishCurveModification( myDragPoints );