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 //#define AIS_CURVE_DISPLAY
48 //=======================================================================
49 // function: Constructor
51 //=======================================================================
52 CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimension )
54 myDimension (theDimension),
61 #ifdef AIS_CURVE_DISPLAY
62 myAISCurve = new CurveCreator_AISCurve( this );
66 //=======================================================================
67 // function: Destructor
69 //=======================================================================
70 CurveCreator_Curve::~CurveCreator_Curve()
72 // Delete all allocated data.
76 //=======================================================================
77 // function: getDimension
79 //=======================================================================
80 CurveCreator::Dimension CurveCreator_Curve::getDimension() const
85 //=======================================================================
86 // function: getUniqSectionName
87 // purpose: return unique section name
88 //=======================================================================
89 std::string CurveCreator_Curve::getUniqSectionName() const
91 for( int i = 0 ; i < 1000000 ; i++ ){
93 sprintf( aBuffer, "Section_%d", i+1 );
94 std::string aName(aBuffer);
96 for( j = 0 ; j < mySections.size() ; j++ ){
97 if( mySections[j]->myName == aName )
100 if( j == mySections.size() )
106 //=======================================================================
107 // function: setDisplayer
108 // purpose: set curve changes Displayer
109 //=======================================================================
110 void CurveCreator_Curve::setDisplayer( CurveCreator_Displayer* theDisplayer )
112 myDisplayer = theDisplayer;
114 #ifdef AIS_CURVE_DISPLAY
115 myDisplayer->displayAIS( myAISCurve, false );
119 //=======================================================================
120 // function: getDisplayer
121 // purpose: get curve changes Displayer
122 //=======================================================================
123 CurveCreator_Displayer* CurveCreator_Curve::getDisplayer()
128 //=======================================================================
129 // function: removeDisplayer
130 // purpose: remove the attached Displayer
131 //=======================================================================
132 void CurveCreator_Curve::removeDisplayer()
137 //=======================================================================
140 //=======================================================================
141 bool CurveCreator_Curve::addEmptyDiff()
143 bool isEnabled = false;
145 if (myUndoDepth != 0) {
146 // Forget all Redos after the current one.
149 myListDiffs.erase(myCurrenPos, myListDiffs.end());
152 if (myUndoDepth == -1 || myNbUndos < myUndoDepth) {
153 // Increase the number of undos.
156 // If there are too many differences, remove the first one.
157 myListDiffs.pop_front();
160 // Add new difference.
161 myListDiffs.push_back(CurveCreator_Diff());
162 myCurrenPos = myListDiffs.end();
169 void CurveCreator_Curve::startOperation()
174 void CurveCreator_Curve::finishOperation()
179 //=======================================================================
180 // function: toICoord
182 //=======================================================================
183 int CurveCreator_Curve::toICoord(const int theIPnt) const
185 return theIPnt * myDimension;
188 #include <TopoDS_Compound.hxx>
189 #include <BRep_Builder.hxx>
190 #include <BRepBuilderAPI_MakeVertex.hxx>
191 #include <BRepBuilderAPI_MakeEdge.hxx>
192 //#define USE_COMPOUND
193 std::vector<Handle_AIS_InteractiveObject> CurveCreator_Curve::constructSection( int theISection ) const
195 std::vector<Handle_AIS_InteractiveObject> aSectionRepresentation;
197 CurveCreator::SectionType aSectType = getSectionType( theISection );
198 int aPointSize = getNbPoints( theISection );
199 bool aSectIsClosed = isClosed( theISection );
200 if( aSectType == CurveCreator::Polyline )
203 BRep_Builder aBuilder;
204 TopoDS_Compound aComp;
205 aBuilder.MakeCompound(aComp);
208 gp_Pnt aPrevPoint, aPoint;
209 if ( aPointSize == 1 ) {
210 getPoint( theISection, iPoint, aPrevPoint );
211 TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
212 aBuilder.Add( aComp, aVertex );
214 else if ( aPointSize > 1 ) {
215 TopoDS_Edge aPointEdge;
216 TopoDS_Vertex aVertex;
217 getPoint( theISection, iPoint, aPrevPoint );
218 aVertex = BRepBuilderAPI_MakeVertex( aPrevPoint ).Vertex();
219 aBuilder.Add( aComp, aVertex );
221 for( ; iPoint < aPointSize; iPoint++ ) {
222 getPoint( theISection, iPoint, aPoint );
223 aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
224 aBuilder.Add( aComp, aVertex );
225 aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
226 aBuilder.Add( aComp, aPointEdge );
229 if( isClosed( theISection ) && ( aPointSize > 2 ) ) {
230 getPoint( theISection, 0, aPoint );
231 aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
232 aBuilder.Add( aComp, aVertex );
233 aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
234 aBuilder.Add( aComp, aPointEdge );
236 AIS_Shape* aShape = new AIS_Shape( aComp );
237 //aShape->SetSelectionMode( AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX ) );
238 aSectionRepresentation.push_back( aShape );
242 for( ; iPoint < ( aPointSize - 1 ) ; iPoint++ ){
243 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
244 aSectionRepresentation.push_back( anAISPnt );
245 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, iPoint+1 );
246 aSectionRepresentation.push_back( aLine );
248 if( aPointSize != 0 ){
249 Handle_AIS_Point anAISPnt = getAISPoint(theISection, iPoint);
250 aSectionRepresentation.push_back( anAISPnt );
251 if( isClosed(theISection) && ( aPointSize > 1 ) ){
252 Handle_AIS_Line aLine = getAISLine( theISection, iPoint, 0 );
253 aSectionRepresentation.push_back( aLine );
258 else if( aSectType == CurveCreator::Spline )
263 std::vector<double> aPoints;
264 for( int iPoint = 0; iPoint < aPointSize; iPoint++ )
266 Handle_AIS_Point anAISPnt = getAISPoint( theISection, iPoint );
267 aSectionRepresentation.push_back( anAISPnt );
269 CurveCreator::Coordinates aCoords = getPoint( theISection, iPoint );
270 double aX = aCoords[0];
271 double aY = aCoords[1];
272 double aZ = aCoords[2];
273 aPoints.push_back( aX );
274 aPoints.push_back( aY );
279 Handle(Geom_BSplineCurve) aBSplineCurve;
280 // fill array for algorithm by the received coordinates
281 int aLen = aPoints.size() / 2;
282 Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aLen);
283 std::vector<double>::const_iterator aListIter = aPoints.begin();
284 for (int ind = 1; ind <= aLen; ind++) {
285 gp_Pnt aPnt(gp::Origin());
286 aPnt.SetX(*aListIter);
288 aPnt.SetY(*aListIter);
291 aHCurvePoints->SetValue(ind, aPnt);
294 GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
297 aBSplineCurve = aGBC.Curve();
299 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
301 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
303 Handle(AIS_Shape) aShape = new AIS_Shape( aWire );
304 aSectionRepresentation.push_back( aShape );
308 return aSectionRepresentation;
311 //=======================================================================
312 // function: setUndoDepth
314 //=======================================================================
315 void CurveCreator_Curve::setUndoDepth(const int theDepth)
318 // Reset all undo/redo data.
322 myCurrenPos = myListDiffs.end();
324 } else if (theDepth == -1) {
325 // There is nothing to do as the depth become unlimited.
327 } else if (theDepth > 0) {
328 // The new "real" depth is set.
329 if (theDepth < myNbRedos) {
330 // The new depth is less then number of redos. Remove the latest redos.
331 int aShift = (myNbRedos - theDepth);
332 ListDiff::iterator aFromPos = myListDiffs.end();
338 myListDiffs.erase(aFromPos, myListDiffs.end());
339 myNbRedos = theDepth;
342 if (theDepth < myNbUndos + myNbRedos) {
343 // The new depth is less then the total number of differences.
344 // Remove the first undos.
345 int aShift = (myNbUndos + myNbRedos - theDepth);
346 ListDiff::iterator aToPos = myListDiffs.begin();
352 myListDiffs.erase(myListDiffs.begin(), aToPos);
353 myNbUndos = theDepth - myNbRedos;
356 myUndoDepth = theDepth;
360 //=======================================================================
361 // function: getUndoDepth
363 //=======================================================================
364 int CurveCreator_Curve::getUndoDepth() const
369 Handle_AIS_Point CurveCreator_Curve::getAISPoint( int theISection, int theIPoint ) const
372 getCoordinates( theISection, theIPoint, anX, anY, aZ );
373 gp_Pnt aPoint( anX, anY, aZ);
375 AIS_Point* aPnt = new AIS_Point( new Geom_CartesianPoint(aPoint));
379 Handle_AIS_Line CurveCreator_Curve::getAISLine( int theISection, int theIPoint1, int theIPoint2 ) const
382 getCoordinates( theISection, theIPoint1, anX, anY, aZ );
383 gp_Pnt aPoint1( anX, anY, aZ);
385 double anX2, anY2, aZ2;
386 getCoordinates( theISection, theIPoint2, anX2, anY2, aZ2 );
387 //MTN to avoid crash during line construction
388 if( ( anX == anX2 ) && ( anY == anY2 ) && (aZ == aZ2 ) ){
392 gp_Pnt aPoint2( anX2, anY2, aZ2 );
394 AIS_Line* aLine = new AIS_Line( new Geom_CartesianPoint(aPoint1), new Geom_CartesianPoint(aPoint2) );
398 void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const
400 CurveCreator::Coordinates aCoords = getPoint( theISection, theIPoint );
404 if( getDimension() == CurveCreator::Dim3d ){
409 void CurveCreator_Curve::redisplayCurve()
412 #ifdef AIS_CURVE_DISPLAY
413 myDisplayer->redisplayAIS(myAISCurve, false);
415 myDisplayer->erase( false );
416 //#ifndef USE_COMPOUND
417 myDisplayer->display( constructWire(), true );
419 /*std::vector<Handle_AIS_InteractiveObject> anAISObjects = constructWire();
420 int aSelMode = AIS_Shape::SelectionMode( (TopAbs_ShapeEnum)TopAbs_VERTEX );
421 Handle(AIS_InteractiveContext) aContext = myDisplayer->getAISContext();
422 for( int i = 0 ; i < anAISObjects.size() ; i++ ){
423 Handle_AIS_InteractiveObject anAISObject = anAISObjects[i];
424 //anAISObject->SetSelectionMode( aSelMode );
425 aContext->Display( anAISObject, Standard_False );
426 //aContext->Display( anAISObject, 0, aSelMode, Standard_False, Standard_True );
428 aContext->UpdateCurrentViewer();
435 //! For internal use only! Undo/Redo are not used here.
436 bool CurveCreator_Curve::moveSectionInternal(const int theISection,
437 const int theNewIndex)
440 if (theISection != theNewIndex) {
441 CurveCreator_Section *aSection = mySections.at(theISection);
444 CurveCreator::Sections::iterator anIter = mySections.begin() + theISection;
446 mySections.erase(anIter);
449 anIter = mySections.begin() + theNewIndex;
450 mySections.insert(anIter, aSection);
456 //=======================================================================
457 // function: moveSection
459 //=======================================================================
460 bool CurveCreator_Curve::moveSection(const int theISection,
461 const int theNewIndex)
464 // Set the difference.
466 if (addEmptyDiff()) {
467 myListDiffs.back().init(this, CurveCreator_Operation::MoveSection,
468 theISection, theNewIndex);
472 res = moveSectionInternal(theISection, theNewIndex);
477 void CurveCreator_Curve::convert( const SectionToPointList& thePoints,
478 std::map< int, std::list<int> >& theConvPoints )
480 theConvPoints.clear();
482 SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
483 std::list<int> aPoints;
484 int aSectionId, aPointId;
485 for ( ; anIt != aLast; anIt++ ) {
486 aSectionId = anIt->first;
487 aPointId = anIt->second;
489 if ( theConvPoints.find( aSectionId ) != theConvPoints.end() )
490 aPoints = theConvPoints[aSectionId];
491 aPoints.push_back( aPointId );
492 theConvPoints[aSectionId] = aPoints;
496 /************ Implementation of INTERFACE methods ************/
498 /***********************************************/
499 /*** Undo/Redo methods ***/
500 /***********************************************/
502 //! Get number of available undo operations
503 int CurveCreator_Curve::getNbUndo() const
508 //! Undo previous operation
509 bool CurveCreator_Curve::undo()
516 myCurrenPos->applyUndo(this);
522 //! Get number of available redo operations
523 int CurveCreator_Curve::getNbRedo() const
528 //! Redo last previously "undone" operation
529 bool CurveCreator_Curve::redo()
533 myCurrenPos->applyRedo(this);
542 /***********************************************/
543 /*** Section methods ***/
544 /***********************************************/
545 //! For internal use only! Undo/Redo are not used here.
546 bool CurveCreator_Curve::clearInternal()
548 // erase curve from the viewer
550 myDisplayer->erase( true );
551 // Delete all allocated data.
553 const int aNbSections = getNbSections();
555 for (; i < aNbSections; i++) {
556 delete mySections[i];
564 //=======================================================================
567 //=======================================================================
568 bool CurveCreator_Curve::clear()
572 // Set the difference.
573 if (addEmptyDiff()) {
574 myListDiffs.back().init(this, CurveCreator_Operation::Clear);
576 res = clearInternal();
581 //! For internal use only! Undo/Redo are not used here.
582 bool CurveCreator_Curve::joinInternal( const int theISectionTo,
583 const int theISectionFrom )
586 CurveCreator_Section *aSection1 = mySections.at(theISectionTo);
587 CurveCreator_Section *aSection2 = mySections.at(theISectionFrom);
589 aSection1->myPoints.insert(aSection1->myPoints.end(),
590 aSection2->myPoints.begin(),
591 aSection2->myPoints.end());
593 res = removeSection(theISectionFrom);
598 //! Join range of sections to one section (join all sections if -1 is passed in theISectionFrom argument)
599 bool CurveCreator_Curve::join( const int theISectionTo,
600 const int theISectionFrom )
604 if ( theISectionTo != theISectionFrom ) {
607 myListDiffs.back().init(this, CurveCreator_Operation::Join, theISectionTo, theISectionFrom);
609 res = joinInternal( theISectionTo, theISectionFrom );
616 //! Get number of sections
617 int CurveCreator_Curve::getNbSections() const
619 return mySections.size();
622 //! For internal use only! Undo/Redo are not used here.
623 int CurveCreator_Curve::addSectionInternal
624 (const std::string& theName, const CurveCreator::SectionType theType,
625 const bool theIsClosed, const CurveCreator::Coordinates &thePoints)
627 CurveCreator_Section *aSection = new CurveCreator_Section;
629 std::string aName = theName;
631 aName = getUniqSectionName();
633 aSection->myName = aName;
634 aSection->myType = theType;
635 aSection->myIsClosed = theIsClosed;
636 aSection->myPoints = thePoints;
637 mySections.push_back(aSection);
639 return mySections.size()-1;
642 //=======================================================================
643 // function: addSection
644 // purpose: adds an empty section
645 //=======================================================================
646 int CurveCreator_Curve::addSection
647 (const std::string& theName, const CurveCreator::SectionType theType,
648 const bool theIsClosed)
650 int resISection = -1;
651 // Set the difference.
653 CurveCreator::Coordinates aCoords; //empty list
654 if (addEmptyDiff()) {
655 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
656 theName, aCoords, theType, theIsClosed);
659 resISection = addSectionInternal(theName, theType, theIsClosed, aCoords);
664 //=======================================================================
665 // function: addSection
666 // purpose: adds a section with the given points
667 //=======================================================================
668 int CurveCreator_Curve::addSection
669 (const std::string& theName, const CurveCreator::SectionType theType,
670 const bool theIsClosed, const CurveCreator::Coordinates &thePoints)
672 int resISection = -1;
673 // Set the difference.
675 if (addEmptyDiff()) {
676 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
677 theName, thePoints, theType, theIsClosed);
680 resISection = addSectionInternal(theName, theType, theIsClosed, thePoints);
686 //! For internal use only! Undo/Redo are not used here.
687 bool CurveCreator_Curve::removeSectionInternal( const int theISection )
689 if (theISection == -1) {
690 delete mySections.back();
691 mySections.pop_back();
693 CurveCreator::Sections::iterator anIterRm = mySections.begin() + theISection;
696 mySections.erase(anIterRm);
702 //! Removes the given sections.
703 bool CurveCreator_Curve::removeSection( const int theISection )
706 // Set the difference.
709 myListDiffs.back().init(this, CurveCreator_Operation::RemoveSection, theISection);
711 res = removeSectionInternal( theISection );
718 * Get number of points in specified section or (the total number of points
719 * in Curve if theISection is equal to -1).
721 int CurveCreator_Curve::getNbPoints( const int theISection ) const
725 if (theISection == -1) {
727 const int aNbSections = getNbSections();
729 for (; i < aNbSections; i++) {
730 aNbCoords += mySections[i]->myPoints.size();
733 if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) )
734 aNbCoords = mySections.at(theISection)->myPoints.size();
737 return aNbCoords/myDimension;
740 //! Get "closed" flag of the specified section
741 bool CurveCreator_Curve::isClosed( const int theISection ) const
743 return mySections.at(theISection)->myIsClosed;
746 //! For internal use only! Undo/Redo are not used here.
747 bool CurveCreator_Curve::setClosedInternal( const int theISection,
748 const bool theIsClosed )
750 if (theISection == -1) {
751 int aSize = mySections.size();
754 for (i = 0; i < aSize; i++) {
755 mySections[i]->myIsClosed = theIsClosed;
759 mySections.at(theISection)->myIsClosed = theIsClosed;
766 * Set "closed" flag of the specified section (all sections if
767 * \a theISection is -1).
769 bool CurveCreator_Curve::setClosed( const int theISection,
770 const bool theIsClosed )
773 // Set the difference.
775 if (addEmptyDiff()) {
776 myListDiffs.back().init(this, CurveCreator_Operation::SetClosed,
777 theIsClosed, theISection);
779 res = setClosedInternal( theISection, theIsClosed );
784 //! Returns specified section name
785 std::string CurveCreator_Curve::getSectionName( const int theISection ) const
787 if( ( theISection >= 0 ) && ( theISection < mySections.size() ))
788 return mySections.at(theISection)->myName;
792 //! For internal use only! Undo/Redo are not used here.
793 bool CurveCreator_Curve::setSectionNameInternal( const int theISection,
794 const std::string& theName )
797 if( ( theISection >= 0 ) && ( theISection < mySections.size() )){
798 mySections.at(theISection)->myName = theName;
804 /** Set name of the specified section */
805 bool CurveCreator_Curve::setSectionName( const int theISection,
806 const std::string& theName )
809 // Set the difference.
811 if (addEmptyDiff()) {
812 myListDiffs.back().init(this, CurveCreator_Operation::RenameSection,
813 theName, theISection);
815 res = setSectionNameInternal( theISection, theName );
820 //! Get type of the specified section
821 CurveCreator::SectionType CurveCreator_Curve::getSectionType
822 ( const int theISection ) const
824 return mySections.at(theISection)->myType;
827 //! For internal use only! Undo/Redo are not used here.
828 bool CurveCreator_Curve::setSectionTypeInternal( const int theISection,
829 const CurveCreator::SectionType theType )
831 if (theISection == -1) {
833 const int aNbSections = getNbSections();
835 for (; i < aNbSections; i++) {
836 mySections[i]->myType = theType;
840 if( mySections.at(theISection)->myType != theType ){
841 mySections.at(theISection)->myType = theType;
849 * Set type of the specified section (or all sections
850 * if \a theISection is -1).
852 bool CurveCreator_Curve::setSectionType( const int theISection,
853 const CurveCreator::SectionType theType )
857 // Set the difference.
858 if (addEmptyDiff()) {
859 myListDiffs.back().init(this, CurveCreator_Operation::SetType,
860 theType, theISection);
863 res = setSectionTypeInternal( theISection, theType );
870 /***********************************************/
871 /*** Point methods ***/
872 /***********************************************/
874 //! For internal use only! Undo/Redo are not used here.
875 bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
878 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
879 CurveCreator_Section *aSection = 0;
880 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
881 int anISection = anIt->first;
882 aSection = mySections.at(anISection);
884 CurveCreator::PosPointsList aSectionPoints = anIt->second;
885 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
886 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
887 int anIPnt = (*aPntIt)->myID;
888 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
889 CurveCreator::Coordinates::iterator anIterPosition;
891 anIterPosition = aSection->myPoints.end();
893 anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt);
894 CurveCreator::Coordinates::const_iterator aFirstPosition =
896 aSection->myPoints.insert(anIterPosition,
897 aCoords.begin(), aCoords.end());
908 * Add one point to the specified section starting from the given theIPnt index
909 * (or at the end of points if \a theIPnt is -1).
911 bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords,
912 const int theISection,
916 CurveCreator::Coordinates aCoords = theCoords;
917 // Set the difference.
919 if (addEmptyDiff()) {
920 CurveCreator_ICurve::SectionToPointCoordsList aList;
921 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords));
922 myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints,
925 CurveCreator::SectionsMap aSectionsMap;
926 CurveCreator::PosPointsList aPoints;
927 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords );
928 aPoints.push_back( aPosPoint );
929 aSectionsMap[theISection] = aPoints;
931 res = addPointsInternal( aSectionsMap );
937 //! For internal use only! Undo/Redo are not used here.
938 bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
942 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
943 CurveCreator_Section *aSection = 0;
944 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
945 int anISection = anIt->first;
946 aSection = mySections.at(anISection);
948 CurveCreator::PosPointsList aSectionPoints = anIt->second;
949 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
950 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
951 int anIPnt = (*aPntIt)->myID;
952 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
953 for ( int i = 0; i < myDimension; i++)
954 aSection->myPoints.at(toICoord(anIPnt) + i) = aCoords[i];
965 //! Set coordinates of specified point
966 bool CurveCreator_Curve::setPoint( const int theISection,
968 const CurveCreator::Coordinates& theNewCoords )
971 // Set the difference.
973 if (addEmptyDiff()) {
974 CurveCreator_ICurve::SectionToPointCoordsList aList;
975 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords));
976 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
979 CurveCreator::SectionsMap aSectionsMap;
980 CurveCreator::PosPointsList aPoints;
981 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords );
982 aPoints.push_back( aPosPoint );
983 aSectionsMap[theISection] = aPoints;
985 int aSize1 = getNbPoints( theISection );
986 res = setPointInternal( aSectionsMap );
987 int aSize2 = getNbPoints( theISection );
994 //! Set coordinates of specified points from different sections
995 bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords)
998 // Set the difference.
1000 if (addEmptyDiff()) {
1001 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
1002 theSectionToPntCoords);
1004 CurveCreator::SectionsMap aSectionsMap;
1005 CurveCreator::PosPointsList aPosPoints;
1006 CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
1007 theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end();
1008 int aSectionId, aPointId;
1009 for ( ; anIt != aLast; anIt++ ) {
1011 aSectionId = anIt->first.first;
1012 aPointId = anIt->first.second;
1013 CurveCreator::Coordinates aNewCoords = anIt->second;
1014 CurveCreator_PosPoint* aPosPoint =
1015 new CurveCreator_PosPoint( aPointId, aNewCoords );
1016 if( aSectionsMap.find(aSectionId) != aSectionsMap.end() )
1017 aPosPoints = aSectionsMap[aSectionId];
1018 aPosPoints.push_back( aPosPoint );
1019 aSectionsMap[aSectionId] = aPosPoints;
1022 res = setPointInternal( aSectionsMap );
1028 //! For internal use only! Undo/Redo are not used here.
1029 bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints )
1032 std::map<int, std::list<int> > aConvPoints;
1033 convert( thePoints, aConvPoints );
1034 std::map<int, std::list<int> >::const_iterator anIt = aConvPoints.begin(),
1035 aLast = aConvPoints.end();
1036 CurveCreator_Section *aSection = 0;
1037 for ( ; anIt != aLast; anIt++ ) {
1038 int aSectionId = anIt->first;
1039 aSection = mySections.at(aSectionId);
1041 std::list<int> aSectionPoints = anIt->second;
1042 aSectionPoints.sort();
1043 std::list<int>::const_reverse_iterator aPntIt = aSectionPoints.rbegin();
1044 for( ; aPntIt != aSectionPoints.rend(); aPntIt++ ){
1045 int aPntIndx = *aPntIt;
1046 CurveCreator::Coordinates::iterator aFirstPosition;
1048 aFirstPosition = aSection->myPoints.end() - getDimension();
1050 aFirstPosition = aSection->myPoints.begin() + toICoord(aPntIndx);
1051 aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() );
1061 //! Remove point with given id
1062 bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt )
1065 // Set the difference.
1067 if (addEmptyDiff()) {
1068 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
1069 theISection, theIPnt);
1071 SectionToPointList aListOfSectionsToPoints;
1072 aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
1073 res = removePointsInternal( aListOfSectionsToPoints );
1078 //! Remove several points from different sections with given ids
1079 bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs)
1082 // Set the difference.
1084 if (addEmptyDiff()) {
1085 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
1086 theSectionToPntIDs);
1088 res = removePointsInternal( theSectionToPntIDs );
1093 //=======================================================================
1094 // function: getCoordinates
1096 //=======================================================================
1097 CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection,
1098 const int theIPnt) const
1100 CurveCreator_Section *aSection = mySections.at(theISection);
1101 CurveCreator::Coordinates::const_iterator
1102 anIter = aSection->myPoints.begin() + toICoord(theIPnt);
1103 CurveCreator::Coordinates aResult(anIter, anIter + myDimension);
1108 //=======================================================================
1109 // function: getPoints
1111 //=======================================================================
1112 CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const
1114 CurveCreator::Coordinates aCoords;
1115 if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) )
1117 aCoords = mySections.at(theISection)->myPoints;
1123 /***********************************************/
1124 /*** Presentation methods ***/
1125 /***********************************************/
1126 std::vector<Handle_AIS_InteractiveObject> CurveCreator_Curve::constructWire() const
1128 std::vector<Handle_AIS_InteractiveObject> aCurveRepresentation;
1129 std::vector<Handle_AIS_InteractiveObject> aSectionObjects;
1130 for( int iSection = 0 ; iSection < getNbSections() ; iSection++ ){
1131 aSectionObjects = constructSection( iSection );
1132 for( int iObject = 0 ; iObject < aSectionObjects.size() ; iObject++ ){
1133 aCurveRepresentation.push_back( aSectionObjects.at(iObject) );
1136 return aCurveRepresentation;
1139 void CurveCreator_Curve::getPoint( const int theISection, const int theIPoint,
1140 gp_Pnt& thePoint ) const
1142 double anX, anY, aZ;
1143 getCoordinates( theISection, theIPoint, anX, anY, aZ );
1144 thePoint = gp_Pnt( anX, anY, aZ);