1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: CurveCreator_Curve.cxx
21 // Author: Sergey KHROMOV
23 #include "CurveCreator_Curve.hxx"
25 #include "CurveCreator.hxx"
26 #include "CurveCreator_PosPoint.hxx"
27 #include "CurveCreator_Section.hxx"
28 #include "CurveCreator_Displayer.h"
30 #include <AIS_Point.hxx>
31 #include <AIS_Line.hxx>
32 #include <AIS_Shape.hxx>
33 #include <BRepBuilderAPI_MakeEdge.hxx>
34 #include <BRepBuilderAPI_MakeWire.hxx>
35 #include <Geom_CartesianPoint.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Wire.hxx>
41 #include <TColgp_HArray1OfPnt.hxx>
42 #include <GeomAPI_Interpolate.hxx>
46 //=======================================================================
47 // function: Constructor
49 //=======================================================================
50 CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimension )
52 myDimension (theDimension),
61 //=======================================================================
62 // function: Destructor
64 //=======================================================================
65 CurveCreator_Curve::~CurveCreator_Curve()
67 // Delete all allocated data.
71 //=======================================================================
72 // function: getDimension
74 //=======================================================================
75 CurveCreator::Dimension CurveCreator_Curve::getDimension() const
80 //=======================================================================
81 // function: getUniqSectionName
82 // purpose: return unique section name
83 //=======================================================================
84 std::string CurveCreator_Curve::getUniqSectionName() const
86 for( int i = 0 ; i < 1000000 ; i++ ){
88 sprintf( aBuffer, "Section_%d", i+1 );
89 std::string aName(aBuffer);
91 for( j = 0 ; j < mySections.size() ; j++ ){
92 if( mySections[j]->myName == aName )
95 if( j == mySections.size() )
101 //=======================================================================
102 // function: setDisplayer
103 // purpose: set curve changes Displayer
104 //=======================================================================
105 void CurveCreator_Curve::setDisplayer( CurveCreator_Displayer* theDisplayer )
107 myDisplayer = theDisplayer;
110 //=======================================================================
111 // function: getDisplayer
112 // purpose: get curve changes Displayer
113 //=======================================================================
114 CurveCreator_Displayer* CurveCreator_Curve::getDisplayer()
119 //=======================================================================
120 // function: removeDisplayer
121 // purpose: remove the attached Displayer
122 //=======================================================================
123 void CurveCreator_Curve::removeDisplayer()
128 //=======================================================================
131 //=======================================================================
132 bool CurveCreator_Curve::addEmptyDiff()
134 bool isEnabled = false;
136 if (myUndoDepth != 0) {
137 // Forget all Redos after the current one.
140 myListDiffs.erase(myCurrenPos, myListDiffs.end());
143 if (myUndoDepth == -1 || myNbUndos < myUndoDepth) {
144 // Increase the number of undos.
147 // If there are too many differences, remove the first one.
148 myListDiffs.pop_front();
151 // Add new difference.
152 myListDiffs.push_back(CurveCreator_Diff());
153 myCurrenPos = myListDiffs.end();
160 void CurveCreator_Curve::startOperation()
165 void CurveCreator_Curve::finishOperation()
170 //=======================================================================
171 // function: toICoord
173 //=======================================================================
174 int CurveCreator_Curve::toICoord(const int theIPnt) const
176 return theIPnt * myDimension;
179 std::vector<Handle_AIS_InteractiveObject> CurveCreator_Curve::constructSection( int theISection ) const
181 std::vector<Handle_AIS_InteractiveObject> aSectionRepresentation;
183 CurveCreator::SectionType aSectType = getSectionType( theISection );
184 int aSectSize = getNbPoints( theISection );
185 bool aSectIsClosed = isClosed( theISection );
187 if( aSectType == CurveCreator::Polyline )
190 for( ; iPoint < ( aSectSize - 1 ) ; iPoint++ ){
191 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
192 aSectionRepresentation.push_back( anAISPnt );
193 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, iPoint+1 );
194 aSectionRepresentation.push_back( aLine );
196 if( aSectSize != 0 ){
197 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
198 aSectionRepresentation.push_back( anAISPnt );
199 if( isClosed(theISection) && ( aSectSize > 1 ) ){
200 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, 0 );
201 aSectionRepresentation.push_back( aLine );
205 else if( aSectType == CurveCreator::Spline )
207 std::vector<double> aPoints;
208 for( int iPoint = 0; iPoint < aSectSize; iPoint++ )
210 Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
211 aSectionRepresentation.push_back( anAISPnt );
213 CurveCreator::Coordinates aCoords = getPoint( theISection, iPoint );
214 double aX = aCoords[0];
215 double aY = aCoords[1];
216 double aZ = aCoords[2];
217 aPoints.push_back( aX );
218 aPoints.push_back( aY );
223 Handle(Geom_BSplineCurve) aBSplineCurve;
224 // fill array for algorithm by the received coordinates
225 int aLen = aPoints.size() / 2;
226 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
227 std::vector<double>::const_iterator aListIter = aPoints.begin();
228 for (int ind = 1; ind <= aLen; ind++) {
229 gp_Pnt aPnt(gp::Origin());
230 aPnt.SetX(*aListIter);
232 aPnt.SetY(*aListIter);
235 aHCurvePoints->SetValue(ind, aPnt);
238 GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
241 aBSplineCurve = aGBC.Curve();
243 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
245 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
247 Handle(AIS_Shape) aShape = new AIS_Shape( aWire );
248 aSectionRepresentation.push_back( aShape );
251 return aSectionRepresentation;
254 //=======================================================================
255 // function: setUndoDepth
257 //=======================================================================
258 void CurveCreator_Curve::setUndoDepth(const int theDepth)
261 // Reset all undo/redo data.
265 myCurrenPos = myListDiffs.end();
267 } else if (theDepth == -1) {
268 // There is nothing to do as the depth become unlimited.
270 } else if (theDepth > 0) {
271 // The new "real" depth is set.
272 if (theDepth < myNbRedos) {
273 // The new depth is less then number of redos. Remove the latest redos.
274 int aShift = (myNbRedos - theDepth);
275 ListDiff::iterator aFromPos = myListDiffs.end();
281 myListDiffs.erase(aFromPos, myListDiffs.end());
282 myNbRedos = theDepth;
285 if (theDepth < myNbUndos + myNbRedos) {
286 // The new depth is less then the total number of differences.
287 // Remove the first undos.
288 int aShift = (myNbUndos + myNbRedos - theDepth);
289 ListDiff::iterator aToPos = myListDiffs.begin();
295 myListDiffs.erase(myListDiffs.begin(), aToPos);
296 myNbUndos = theDepth - myNbRedos;
299 myUndoDepth = theDepth;
303 //=======================================================================
304 // function: getUndoDepth
306 //=======================================================================
307 int CurveCreator_Curve::getUndoDepth() const
312 Handle_AIS_Point CurveCreator_Curve::getAISPoint( int theISection, int theIPoint ) const
315 getCoordinates( theISection, theIPoint, anX, anY, aZ );
316 gp_Pnt aPoint( anX, anY, aZ);
318 AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint));
322 Handle_AIS_Line CurveCreator_Curve::getAISLine( int theISection, int theIPoint1, int theIPoint2 ) const
325 getCoordinates( theISection, theIPoint1, anX, anY, aZ );
326 gp_Pnt aPoint1( anX, anY, aZ);
328 double anX2, anY2, aZ2;
329 getCoordinates( theISection, theIPoint2, anX2, anY2, aZ2 );
330 //MTN to avoid crash during line construction
331 if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){
335 gp_Pnt aPoint2( anX2, anY2, aZ2 );
337 AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) );
341 void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const
343 CurveCreator::Coordinates aCoords = getPoint( theISection, theIPoint );
347 if( getDimension() == CurveCreator::Dim3d ){
352 void CurveCreator_Curve::redisplayCurve()
355 myDisplayer->erase();
356 myDisplayer->display( constructWire() );
360 //! For internal use only! Undo/Redo are not used here.
361 bool CurveCreator_Curve::moveSectionInternal(const int theISection,
362 const int theNewIndex)
365 if (theISection != theNewIndex) {
366 CurveCreator_Section *aSection = mySections.at(theISection);
369 CurveCreator::Sections::iterator anIter = mySections.begin() + theISection;
371 mySections.erase(anIter);
374 anIter = mySections.begin() + theNewIndex;
375 mySections.insert(anIter, aSection);
381 //=======================================================================
382 // function: moveSection
384 //=======================================================================
385 bool CurveCreator_Curve::moveSection(const int theISection,
386 const int theNewIndex)
389 // Set the difference.
391 if (addEmptyDiff()) {
392 myListDiffs.back().init(this, CurveCreator_Operation::MoveSection,
393 theISection, theNewIndex);
397 res = moveSectionInternal(theISection, theNewIndex);
402 void CurveCreator_Curve::convert( const SectionToPointList& thePoints,
403 std::map< int, std::list<int> >& theConvPoints )
405 theConvPoints.clear();
407 SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
408 std::list<int> aPoints;
409 int aSectionId, aPointId;
410 for ( ; anIt != aLast; anIt++ ) {
411 aSectionId = anIt->first;
412 aPointId = anIt->second;
414 if ( theConvPoints.find( aSectionId ) != theConvPoints.end() )
415 aPoints = theConvPoints[aSectionId];
416 aPoints.push_back( aPointId );
417 theConvPoints[aSectionId] = aPoints;
421 /************ Implementation of INTERFACE methods ************/
423 /***********************************************/
424 /*** Undo/Redo methods ***/
425 /***********************************************/
427 //! Get number of available undo operations
428 int CurveCreator_Curve::getNbUndo() const
433 //! Undo previous operation
434 bool CurveCreator_Curve::undo()
441 myCurrenPos->applyUndo(this);
447 //! Get number of available redo operations
448 int CurveCreator_Curve::getNbRedo() const
453 //! Redo last previously "undone" operation
454 bool CurveCreator_Curve::redo()
458 myCurrenPos->applyRedo(this);
467 /***********************************************/
468 /*** Section methods ***/
469 /***********************************************/
470 //! For internal use only! Undo/Redo are not used here.
471 bool CurveCreator_Curve::clearInternal()
473 // erase curve from the viewer
475 myDisplayer->erase();
476 // Delete all allocated data.
478 const int aNbSections = getNbSections();
480 for (; i < aNbSections; i++) {
481 delete mySections[i];
489 //=======================================================================
492 //=======================================================================
493 bool CurveCreator_Curve::clear()
497 // Set the difference.
498 if (addEmptyDiff()) {
499 myListDiffs.back().init(this, CurveCreator_Operation::Clear);
501 res = clearInternal();
506 //! For internal use only! Undo/Redo are not used here.
507 bool CurveCreator_Curve::joinInternal( const int theISectionTo,
508 const int theISectionFrom )
511 CurveCreator_Section *aSection1 = mySections.at(theISectionTo);
512 CurveCreator_Section *aSection2 = mySections.at(theISectionFrom);
514 aSection1->myPoints.insert(aSection1->myPoints.end(),
515 aSection2->myPoints.begin(),
516 aSection2->myPoints.end());
518 res = removeSection(theISectionFrom);
523 //! Join range of sections to one section (join all sections if -1 is passed in one of arguments)
524 bool CurveCreator_Curve::join( const int theISectionTo,
525 const int theISectionFrom )
528 if (mySections.size() >= 2 &&
529 ( theISectionTo != theISectionFrom || (theISectionTo == -1 && theISectionFrom == -1) )) {
531 int aISectionTo = getNbSections()-1;
532 int aISectionFrom = 0;
534 myListDiffs.back().init(this, CurveCreator_Operation::Join, aISectionTo, aISectionFrom);
536 res = joinInternal( aISectionTo, aISectionFrom );
543 //! Get number of sections
544 int CurveCreator_Curve::getNbSections() const
546 return mySections.size();
549 //! For internal use only! Undo/Redo are not used here.
550 int CurveCreator_Curve::addSectionInternal
551 (const std::string& theName, const CurveCreator::SectionType theType,
552 const bool theIsClosed, const CurveCreator::Coordinates &thePoints)
554 CurveCreator_Section *aSection = new CurveCreator_Section;
556 std::string aName = theName;
558 aName = getUniqSectionName();
560 aSection->myName = aName;
561 aSection->myType = theType;
562 aSection->myIsClosed = theIsClosed;
563 aSection->myPoints = thePoints;
564 mySections.push_back(aSection);
566 return mySections.size()-1;
569 //=======================================================================
570 // function: addSection
571 // purpose: adds an empty section
572 //=======================================================================
573 int CurveCreator_Curve::addSection
574 (const std::string& theName, const CurveCreator::SectionType theType,
575 const bool theIsClosed)
577 int resISection = -1;
578 // Set the difference.
580 CurveCreator::Coordinates aCoords; //empty list
581 if (addEmptyDiff()) {
582 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
583 theName, aCoords, theType, theIsClosed);
586 resISection = addSectionInternal(theName, theType, theIsClosed, aCoords);
591 //=======================================================================
592 // function: addSection
593 // purpose: adds a section with the given points
594 //=======================================================================
595 int CurveCreator_Curve::addSection
596 (const std::string& theName, const CurveCreator::SectionType theType,
597 const bool theIsClosed, const CurveCreator::Coordinates &thePoints)
599 int resISection = -1;
600 // Set the difference.
602 if (addEmptyDiff()) {
603 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
604 theName, thePoints, theType, theIsClosed);
607 resISection = addSectionInternal(theName, theType, theIsClosed, thePoints);
613 //! For internal use only! Undo/Redo are not used here.
614 bool CurveCreator_Curve::removeSectionInternal( const int theISection )
616 if (theISection == -1) {
617 delete mySections.back();
618 mySections.pop_back();
620 CurveCreator::Sections::iterator anIterRm = mySections.begin() + theISection;
623 mySections.erase(anIterRm);
629 //! Removes the given sections.
630 bool CurveCreator_Curve::removeSection( const int theISection )
633 // Set the difference.
636 myListDiffs.back().init(this, CurveCreator_Operation::RemoveSection, theISection);
638 res = removeSectionInternal( theISection );
645 * Get number of points in specified section or (the total number of points
646 * in Curve if theISection is equal to -1).
648 int CurveCreator_Curve::getNbPoints( const int theISection ) const
652 if (theISection == -1) {
654 const int aNbSections = getNbSections();
656 for (; i < aNbSections; i++) {
657 aNbCoords += mySections[i]->myPoints.size();
660 if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) )
661 aNbCoords = mySections.at(theISection)->myPoints.size();
664 return aNbCoords/myDimension;
667 //! Get "closed" flag of the specified section
668 bool CurveCreator_Curve::isClosed( const int theISection ) const
670 return mySections.at(theISection)->myIsClosed;
673 //! For internal use only! Undo/Redo are not used here.
674 bool CurveCreator_Curve::setClosedInternal( const int theISection,
675 const bool theIsClosed )
677 if (theISection == -1) {
678 int aSize = mySections.size();
681 for (i = 0; i < aSize; i++) {
682 mySections[i]->myIsClosed = theIsClosed;
686 mySections.at(theISection)->myIsClosed = theIsClosed;
693 * Set "closed" flag of the specified section (all sections if
694 * \a theISection is -1).
696 bool CurveCreator_Curve::setClosed( const int theISection,
697 const bool theIsClosed )
700 // Set the difference.
702 if (addEmptyDiff()) {
703 myListDiffs.back().init(this, CurveCreator_Operation::SetClosed,
704 theIsClosed, theISection);
706 res = setClosedInternal( theISection, theIsClosed );
711 //! Returns specified section name
712 std::string CurveCreator_Curve::getSectionName( const int theISection ) const
714 if( ( theISection >= 0 ) && ( theISection < mySections.size() ))
715 return mySections.at(theISection)->myName;
719 //! For internal use only! Undo/Redo are not used here.
720 bool CurveCreator_Curve::setSectionNameInternal( const int theISection,
721 const std::string& theName )
724 if( ( theISection >= 0 ) && ( theISection < mySections.size() )){
725 mySections.at(theISection)->myName = theName;
731 /** Set name of the specified section */
732 bool CurveCreator_Curve::setSectionName( const int theISection,
733 const std::string& theName )
736 // Set the difference.
738 if (addEmptyDiff()) {
739 myListDiffs.back().init(this, CurveCreator_Operation::RenameSection,
740 theName, theISection);
742 res = setSectionNameInternal( theISection, theName );
747 //! Get type of the specified section
748 CurveCreator::SectionType CurveCreator_Curve::getSectionType
749 ( const int theISection ) const
751 return mySections.at(theISection)->myType;
754 //! For internal use only! Undo/Redo are not used here.
755 bool CurveCreator_Curve::setSectionTypeInternal( const int theISection,
756 const CurveCreator::SectionType theType )
758 if (theISection == -1) {
760 const int aNbSections = getNbSections();
762 for (; i < aNbSections; i++) {
763 mySections[i]->myType = theType;
767 if( mySections.at(theISection)->myType != theType ){
768 mySections.at(theISection)->myType = theType;
776 * Set type of the specified section (or all sections
777 * if \a theISection is -1).
779 bool CurveCreator_Curve::setSectionType( const int theISection,
780 const CurveCreator::SectionType theType )
784 // Set the difference.
785 if (addEmptyDiff()) {
786 myListDiffs.back().init(this, CurveCreator_Operation::SetType,
787 theType, theISection);
790 res = setSectionTypeInternal( theISection, theType );
797 /***********************************************/
798 /*** Point methods ***/
799 /***********************************************/
801 //! For internal use only! Undo/Redo are not used here.
802 bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
805 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
806 CurveCreator_Section *aSection = 0;
807 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
808 int anISection = anIt->first;
809 aSection = mySections.at(anISection);
811 CurveCreator::PosPointsList aSectionPoints = anIt->second;
812 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
813 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
814 int anIPnt = (*aPntIt)->myID;
815 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
816 CurveCreator::Coordinates::iterator anIterPosition;
818 anIterPosition = aSection->myPoints.end();
820 anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt);
821 CurveCreator::Coordinates::const_iterator aFirstPosition =
823 aSection->myPoints.insert(anIterPosition,
824 aCoords.begin(), aCoords.end());
835 * Add one point to the specified section starting from the given theIPnt index
836 * (or at the end of points if \a theIPnt is -1).
838 bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords,
839 const int theISection,
843 CurveCreator::Coordinates aCoords = theCoords;
844 // Set the difference.
846 if (addEmptyDiff()) {
847 CurveCreator_ICurve::SectionToPointCoordsList aList;
848 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords));
849 myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints,
852 CurveCreator::SectionsMap aSectionsMap;
853 CurveCreator::PosPointsList aPoints;
854 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords );
855 aPoints.push_back( aPosPoint );
856 aSectionsMap[theISection] = aPoints;
858 res = addPointsInternal( aSectionsMap );
864 //! For internal use only! Undo/Redo are not used here.
865 bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
869 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
870 CurveCreator_Section *aSection = 0;
871 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
872 int anISection = anIt->first;
873 aSection = mySections.at(anISection);
875 CurveCreator::PosPointsList aSectionPoints = anIt->second;
876 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
877 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
878 int anIPnt = (*aPntIt)->myID;
879 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
880 for ( int i = 0; i < myDimension; i++)
881 aSection->myPoints.at(toICoord(anIPnt) + i) = aCoords[i];
892 //! Set coordinates of specified point
893 bool CurveCreator_Curve::setPoint( const int theISection,
895 const CurveCreator::Coordinates& theNewCoords )
898 // Set the difference.
900 if (addEmptyDiff()) {
901 CurveCreator_ICurve::SectionToPointCoordsList aList;
902 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords));
903 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
906 CurveCreator::SectionsMap aSectionsMap;
907 CurveCreator::PosPointsList aPoints;
908 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords );
909 aPoints.push_back( aPosPoint );
910 aSectionsMap[theISection] = aPoints;
912 int aSize1 = getNbPoints( theISection );
913 res = setPointInternal( aSectionsMap );
914 int aSize2 = getNbPoints( theISection );
921 //! Set coordinates of specified points from different sections
922 bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords)
925 // Set the difference.
927 if (addEmptyDiff()) {
928 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
929 theSectionToPntCoords);
931 CurveCreator::SectionsMap aSectionsMap;
932 CurveCreator::PosPointsList aPosPoints;
933 CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
934 theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end();
935 int aSectionId, aPointId;
936 for ( ; anIt != aLast; anIt++ ) {
938 aSectionId = anIt->first.first;
939 aPointId = anIt->first.second;
940 CurveCreator::Coordinates aNewCoords = anIt->second;
941 CurveCreator_PosPoint* aPosPoint =
942 new CurveCreator_PosPoint( aPointId, aNewCoords );
943 if( aSectionsMap.find(aSectionId) != aSectionsMap.end() )
944 aPosPoints = aSectionsMap[aSectionId];
945 aPosPoints.push_back( aPosPoint );
946 aSectionsMap[aSectionId] = aPosPoints;
949 res = setPointInternal( aSectionsMap );
955 //! For internal use only! Undo/Redo are not used here.
956 bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints )
959 std::map<int, std::list<int> > aConvPoints;
960 convert( thePoints, aConvPoints );
961 std::map<int, std::list<int> >::const_iterator anIt = aConvPoints.begin(),
962 aLast = aConvPoints.end();
963 CurveCreator_Section *aSection = 0;
964 for ( ; anIt != aLast; anIt++ ) {
965 int aSectionId = anIt->first;
966 aSection = mySections.at(aSectionId);
968 std::list<int> aSectionPoints = anIt->second;
969 aSectionPoints.sort();
970 std::list<int>::const_reverse_iterator aPntIt = aSectionPoints.rbegin();
971 for( ; aPntIt != aSectionPoints.rend(); aPntIt++ ){
972 int aPntIndx = *aPntIt;
973 CurveCreator::Coordinates::iterator aFirstPosition;
975 aFirstPosition = aSection->myPoints.end() - getDimension();
977 aFirstPosition = aSection->myPoints.begin() + toICoord(aPntIndx);
978 aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() );
988 //! Remove point with given id
989 bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt )
992 // Set the difference.
994 if (addEmptyDiff()) {
995 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
996 theISection, theIPnt);
998 SectionToPointList aListOfSectionsToPoints;
999 aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
1000 res = removePointsInternal( aListOfSectionsToPoints );
1005 //! Remove several points from different sections with given ids
1006 bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs)
1009 // Set the difference.
1011 if (addEmptyDiff()) {
1012 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
1013 theSectionToPntIDs);
1015 res = removePointsInternal( theSectionToPntIDs );
1020 //=======================================================================
1021 // function: getCoordinates
1023 //=======================================================================
1024 CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection,
1025 const int theIPnt) const
1027 CurveCreator_Section *aSection = mySections.at(theISection);
1028 CurveCreator::Coordinates::const_iterator
1029 anIter = aSection->myPoints.begin() + toICoord(theIPnt);
1030 CurveCreator::Coordinates aResult(anIter, anIter + myDimension);
1035 //=======================================================================
1036 // function: getPoints
1038 //=======================================================================
1039 CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const
1041 CurveCreator::Coordinates aCoords;
1042 if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) )
1044 aCoords = mySections.at(theISection)->myPoints;
1050 /***********************************************/
1051 /*** Presentation methods ***/
1052 /***********************************************/
1053 std::vector<Handle_AIS_InteractiveObject> CurveCreator_Curve::constructWire() const
1055 std::vector<Handle_AIS_InteractiveObject> aCurveRepresentation;
1056 std::vector<Handle_AIS_InteractiveObject> aSectionObjects;
1057 for( int iSection = 0 ; iSection < getNbSections() ; iSection++ ){
1058 aSectionObjects = constructSection( iSection );
1059 for( int iObject = 0 ; iObject < aSectionObjects.size() ; iObject++ ){
1060 aCurveRepresentation.push_back( aSectionObjects.at(iObject) );
1063 return aCurveRepresentation;