1 // Copyright (C) 2013-2024 CEA, EDF, 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, or (at your option) any later version.
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.hxx"
29 #include "CurveCreator_Utils.hxx"
31 #include <AIS_Shape.hxx>
32 #include <AIS_InteractiveObject.hxx>
33 #include <Geom_CartesianPoint.hxx>
34 #include <TopoDS_Iterator.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Wire.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <AIS_ColoredShape.hxx>
43 #include <Prs3d_PointAspect.hxx>
45 #define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
49 //=======================================================================
50 // function: Constructor
52 //=======================================================================
53 CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimension )
54 : mySkipSorting (false),
56 myDimension (theDimension),
58 myPointAspectColor (Quantity_NOC_ROYALBLUE4),
59 //myCurveColor (Quantity_NOC_RED),
70 //=======================================================================
71 // function: Destructor
73 //=======================================================================
74 CurveCreator_Curve::~CurveCreator_Curve()
76 // Delete all allocated data.
80 //=======================================================================
81 // function: getDimension
83 //=======================================================================
84 CurveCreator::Dimension CurveCreator_Curve::getDimension() const
89 //=======================================================================
90 // function: getUniqSectionName
91 // purpose: return unique section name
92 //=======================================================================
93 std::string CurveCreator_Curve::getUniqSectionName() const
95 CurveCreator_Section* aSection;
96 for( int i = 0 ; i < 1000000 ; i++ ){
98 sprintf( aBuffer, "Section_%d", i+1 );
99 std::string aName(aBuffer);
101 for( j = 0 ; j < (int)mySections.size() ; j++ ){
102 aSection = (CurveCreator_Section*)getSection( j );
103 if ( aSection && aSection->myName == aName )
106 if( j == (int)mySections.size() )
112 //=======================================================================
113 // function: setDisplayer
114 // purpose: set curve changes Displayer
115 //=======================================================================
116 void CurveCreator_Curve::setDisplayer( CurveCreator_Displayer* theDisplayer )
118 myDisplayer = theDisplayer;
121 //=======================================================================
122 // function: getDisplayer
123 // purpose: get curve changes Displayer
124 //=======================================================================
125 CurveCreator_Displayer* CurveCreator_Curve::getDisplayer()
130 //=======================================================================
131 // function: removeDisplayer
132 // purpose: remove the attached Displayer
133 //=======================================================================
134 void CurveCreator_Curve::removeDisplayer()
139 //=======================================================================
142 //=======================================================================
143 bool CurveCreator_Curve::addEmptyDiff()
145 bool isEnabled = false;
147 if (myUndoDepth != 0) {
148 // Forget all Redos after the current one.
151 myListDiffs.erase(myCurrenPos, myListDiffs.end());
154 if (myUndoDepth == -1 || myNbUndos < myUndoDepth) {
155 // Increase the number of undos.
158 // If there are too many differences, remove the first one.
159 myListDiffs.pop_front();
162 // Add new difference.
163 myListDiffs.push_back(CurveCreator_Diff());
164 myCurrenPos = myListDiffs.end();
171 void CurveCreator_Curve::startOperation()
176 void CurveCreator_Curve::finishOperation()
181 //=======================================================================
182 // function: toICoord
184 //=======================================================================
185 int CurveCreator_Curve::toICoord(const int theIPnt) const
187 return theIPnt * myDimension;
190 //=======================================================================
191 // function: setUndoDepth
193 //=======================================================================
194 void CurveCreator_Curve::setUndoDepth(const int theDepth)
197 // Reset all undo/redo data.
201 myCurrenPos = myListDiffs.end();
203 } else if (theDepth == -1) {
204 // There is nothing to do as the depth become unlimited.
206 } else if (theDepth > 0) {
207 // The new "real" depth is set.
208 if (theDepth < myNbRedos) {
209 // The new depth is less then number of redos. Remove the latest redos.
210 int aShift = (myNbRedos - theDepth);
211 ListDiff::iterator aFromPos = myListDiffs.end();
217 myListDiffs.erase(aFromPos, myListDiffs.end());
218 myNbRedos = theDepth;
221 if (theDepth < myNbUndos + myNbRedos) {
222 // The new depth is less then the total number of differences.
223 // Remove the first undos.
224 int aShift = (myNbUndos + myNbRedos - theDepth);
225 ListDiff::iterator aToPos = myListDiffs.begin();
231 myListDiffs.erase(myListDiffs.begin(), aToPos);
232 myNbUndos = theDepth - myNbRedos;
235 myUndoDepth = theDepth;
239 //=======================================================================
240 // function: getUndoDepth
242 //=======================================================================
243 int CurveCreator_Curve::getUndoDepth() const
248 void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const
250 CurveCreator::Coordinates aCoords = getPoint( theISection, theIPoint );
254 if( getDimension() == CurveCreator::Dim3d ){
259 void CurveCreator_Curve::redisplayCurve(bool preEraseAllObjects)
261 //DEBTRACE("redisplayCurve");
264 if (preEraseAllObjects)
265 myDisplayer->eraseAll( false );
267 myDisplayer->erase( myAISShape, false);
269 myDisplayer->display( getAISObject( true ), true );
273 //! For internal use only! Undo/Redo are not used here.
274 bool CurveCreator_Curve::moveSectionInternal(const int theISection,
275 const int theNewIndex)
278 int aMovedSectionId = theISection >= 0 ? theISection : mySections.size()-1;
280 if (aMovedSectionId != theNewIndex) {
281 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( aMovedSectionId );
284 CurveCreator::Sections::iterator anIter = mySections.begin() + aMovedSectionId;
286 mySections.erase(anIter);
289 anIter = mySections.begin() + theNewIndex;
290 mySections.insert(anIter, aSection);
296 //=======================================================================
297 // function: moveSection
299 //=======================================================================
300 bool CurveCreator_Curve::moveSection(const int theISection,
301 const int theNewIndex)
304 // Set the difference.
306 if (addEmptyDiff()) {
307 myListDiffs.back().init(this, CurveCreator_Operation::MoveSection,
308 theISection, theNewIndex);
312 res = moveSectionInternal(theISection, theNewIndex);
317 /************ Implementation of INTERFACE methods ************/
319 /***********************************************/
320 /*** Undo/Redo methods ***/
321 /***********************************************/
323 //! Get number of available undo operations
324 int CurveCreator_Curve::getNbUndo() const
329 //! Undo previous operation
330 bool CurveCreator_Curve::undo()
337 myCurrenPos->applyUndo(this);
343 //! Get number of available redo operations
344 int CurveCreator_Curve::getNbRedo() const
349 //! Redo last previously "undone" operation
350 bool CurveCreator_Curve::redo()
354 myCurrenPos->applyRedo(this);
363 /***********************************************/
364 /*** Section methods ***/
365 /***********************************************/
366 //! For internal use only! Undo/Redo are not used here.
367 bool CurveCreator_Curve::clearInternal()
369 // erase curve from the viewer
373 myDisplayer->eraseAll( true );
375 myDisplayer->erase(myAISShape, false);
378 // Delete all allocated data.
380 const int aNbSections = getNbSections();
382 CurveCreator_Section* aSection;
383 for (; i < aNbSections; i++) {
384 aSection = (CurveCreator_Section*)getSection( i );
394 //=======================================================================
397 //=======================================================================
398 bool CurveCreator_Curve::clear()
402 // Set the difference.
403 if (addEmptyDiff()) {
404 myListDiffs.back().init(this);
406 res = clearInternal();
411 //=======================================================================
414 //=======================================================================
415 void CurveCreator_Curve::SetEraseAllState(bool toEraseAll)
417 myEraseAll = toEraseAll;
419 //=======================================================================
422 //=======================================================================
423 bool CurveCreator_Curve::GetEraseAllState() const
428 //! For internal use only! Undo/Redo are not used here.
429 bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
432 if ( theSections.empty() )
435 int anISectionMain = theSections.front();
436 CurveCreator_Section* aSectionMain =
437 (CurveCreator_Section*)getSection( anISectionMain );
439 std::list <int> aSectionsToJoin = theSections;
440 aSectionsToJoin.erase( aSectionsToJoin.begin() ); // skip the main section
441 // it is important to sort and reverse the section ids in order to correctly remove them
442 aSectionsToJoin.sort();
443 aSectionsToJoin.reverse();
445 std::list<int>::const_iterator anIt = aSectionsToJoin.begin(), aLast = aSectionsToJoin.end();
446 CurveCreator_Section* aSection;
447 for (; anIt != aLast; anIt++) {
448 aSection = (CurveCreator_Section*)getSection( *anIt );
449 aSectionMain->myPoints.insert(aSectionMain->myPoints.end(), aSection->myPoints.begin(),
450 aSection->myPoints.end());
451 res = removeSectionInternal(*anIt);
456 redisplayCurve(false);
460 bool CurveCreator_Curve::join( const std::list<int>& theSections )
464 if ( !theSections.empty() )
468 myListDiffs.back().init(this, CurveCreator_Operation::Join, theSections);
470 res = joinInternal( theSections );
477 //! Get number of sections
478 int CurveCreator_Curve::getNbSections() const
480 return mySections.size();
483 //! For internal use only! Undo/Redo are not used here.
484 int CurveCreator_Curve::addSectionInternal
485 (const std::string& theName, const CurveCreator::SectionType theType,
486 const bool theIsClosed, const CurveCreator::Coordinates &thePoints,
487 const Quantity_Color& aColor)
489 CurveCreator_Section *aSection = new CurveCreator_Section;
491 std::string aName = theName;
493 aName = getUniqSectionName();
495 aSection->myName = aName;
496 aSection->myType = theType;
497 aSection->myIsClosed = theIsClosed;
498 aSection->myPoints = thePoints;
499 aSection->myColor = aColor;//getRandColor(); //TODO temp
500 mySections.push_back(aSection);
501 redisplayCurve(false);
502 return mySections.size()-1;
505 //=======================================================================
506 // function: addSection
507 // purpose: adds an empty section
508 //=======================================================================
509 int CurveCreator_Curve::addSection
510 (const std::string& theName, const CurveCreator::SectionType theType,
511 const bool theIsClosed)
513 int resISection = -1;
514 // Set the difference.
516 CurveCreator::Coordinates aCoords; //empty list
517 if (addEmptyDiff()) {
518 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
519 theName, aCoords, theType, theIsClosed);
522 Quantity_Color aRColor = CurveCreator_Utils::getRandColor();
524 resISection = addSectionInternal(theName, theType, theIsClosed, aCoords, aRColor);
529 //=======================================================================
530 // function: addSection
531 // purpose: adds a section with the given points
532 //=======================================================================
533 int CurveCreator_Curve::addSection
534 (const std::string& theName, const CurveCreator::SectionType theType,
535 const bool theIsClosed, const CurveCreator::Coordinates &thePoints)
537 int resISection = -1;
538 // Set the difference.
540 if (addEmptyDiff()) {
541 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
542 theName, thePoints, theType, theIsClosed);
545 resISection = addSectionInternal(theName, theType, theIsClosed, thePoints, Quantity_NOC_YELLOW);
551 //! For internal use only! Undo/Redo are not used here.
552 bool CurveCreator_Curve::removeSectionInternal( const int theISection )
554 if (theISection == -1) {
555 myRemColors.push_back(mySections.back()->myColor);
556 delete mySections.back();
557 mySections.pop_back();
559 CurveCreator::Sections::iterator anIterRm = mySections.begin() + theISection;
561 myRemColors.push_back((*anIterRm)->myColor);
564 mySections.erase(anIterRm);
566 redisplayCurve(false);
570 //! Removes the given sections.
571 bool CurveCreator_Curve::removeSection( const int theISection )
574 // Set the difference.
577 myListDiffs.back().init(this, CurveCreator_Operation::RemoveSection, theISection);
579 res = removeSectionInternal( theISection );
585 bool CurveCreator_Curve::setColorSection( int SectInd, Quantity_Color theNewColor )
588 // Set the difference.
591 int ColorParam[3] = { (int)( theNewColor.Red() * 255 ),
592 (int)( theNewColor.Green() * 255 ),
593 (int)( theNewColor.Blue() * 255 ) };
596 myListDiffs.back().init(this, CurveCreator_Operation::SetColorSection, SectInd, ColorParam);
598 setColorSectionInternal(SectInd, theNewColor);
604 void CurveCreator_Curve::setColorSectionInternal( int SectInd, Quantity_Color theNewColor )
606 CurveCreator_Section* aSec = (CurveCreator_Section*)(getSection(SectInd));
607 aSec->myColor = theNewColor;
609 redisplayCurve(false);
612 Quantity_Color CurveCreator_Curve::getColorSection( int SectInd ) const
614 CurveCreator_Section* aSec = (CurveCreator_Section*)(getSection(SectInd));
615 return aSec->myColor;
618 Quantity_Color CurveCreator_Curve::getLastRemovedColor() const
620 return myRemColors.empty() ? Quantity_NOC_BLACK : myRemColors.back();
623 void CurveCreator_Curve::popLastRemovedColor()
625 myRemColors.pop_back();
629 * Get number of points in specified section or (the total number of points
630 * in Curve if theISection is equal to -1).
632 int CurveCreator_Curve::getNbPoints( const int theISection ) const
636 CurveCreator_Section* aSection;
637 if (theISection == -1) {
639 const int aNbSections = getNbSections();
641 for (; i < aNbSections; i++) {
642 aSection = (CurveCreator_Section*)getSection( i );
644 aNbCoords += aSection->myPoints.size();
647 aSection = (CurveCreator_Section*)getSection( theISection );
649 aNbCoords = aSection->myPoints.size();
652 return aNbCoords/myDimension;
655 void CurveCreator_Curve::setSkipSorting( const bool theIsToSkip )
657 mySkipSorting = theIsToSkip;
660 bool CurveCreator_Curve::canPointsBeSorted()
666 * Saves points coordinates difference.
667 * \param theOldCoords the old points coordinates
669 void CurveCreator_Curve::saveCoordDiff( const SectionToPointCoordsList &theOldCoords )
671 // Set the difference.
673 if (addEmptyDiff()) {
674 myListDiffs.back().init(this, theOldCoords);
679 //! Get "closed" flag of the specified section
680 bool CurveCreator_Curve::isClosed( const int theISection ) const
682 const CurveCreator_Section* aSection =
683 (CurveCreator_Section*)getSection( theISection );
684 return aSection ? aSection->myIsClosed : false;
687 //! For internal use only! Undo/Redo are not used here.
688 bool CurveCreator_Curve::setClosedInternal( const int theISection,
689 const bool theIsClosed )
691 CurveCreator_Section* aSection = 0;
692 if (theISection == -1) {
693 int aSize = mySections.size();
696 for (i = 0; i < aSize; i++) {
697 aSection = (CurveCreator_Section*)getSection( i );
699 aSection->myIsClosed = theIsClosed;
700 redisplayCurve(false);
704 aSection = (CurveCreator_Section*)getSection( theISection );
706 aSection->myIsClosed = theIsClosed;
707 redisplayCurve(false);
714 * Set "closed" flag of the specified section (all sections if
715 * \a theISection is -1).
717 bool CurveCreator_Curve::setClosed( const int theISection,
718 const bool theIsClosed )
721 // Set the difference.
723 if (addEmptyDiff()) {
724 myListDiffs.back().init(this, CurveCreator_Operation::SetClosed,
725 theIsClosed, theISection);
727 res = setClosedInternal( theISection, theIsClosed );
732 //! Returns specified section name
733 std::string CurveCreator_Curve::getSectionName( const int theISection ) const
735 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
736 return aSection ? aSection->myName : "";
739 //! For internal use only! Undo/Redo are not used here.
740 bool CurveCreator_Curve::setSectionNameInternal( const int theISection,
741 const std::string& theName )
744 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
746 aSection->myName = theName;
752 /** Set name of the specified section */
753 bool CurveCreator_Curve::setSectionName( const int theISection,
754 const std::string& theName )
757 // Set the difference.
759 if (addEmptyDiff()) {
760 myListDiffs.back().init(this, CurveCreator_Operation::RenameSection,
761 theName, theISection);
763 res = setSectionNameInternal( theISection, theName );
768 //! Get type of the specified section
769 CurveCreator::SectionType CurveCreator_Curve::getSectionType
770 ( const int theISection ) const
772 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
773 return aSection ? aSection->myType : CurveCreator::Polyline;
776 //! For internal use only! Undo/Redo are not used here.
777 bool CurveCreator_Curve::setSectionTypeInternal( const int theISection,
778 const CurveCreator::SectionType theType )
780 CurveCreator_Section* aSection;
781 if (theISection == -1) {
783 const int aNbSections = getNbSections();
785 for (; i < aNbSections; i++) {
786 aSection = (CurveCreator_Section*)getSection( i );
788 aSection->myType = theType;
790 redisplayCurve(false);
792 aSection = (CurveCreator_Section*)getSection( theISection );
793 if ( aSection && aSection->myType != theType ){
794 aSection->myType = theType;
795 redisplayCurve(false);
802 * Set type of the specified section (or all sections
803 * if \a theISection is -1).
805 bool CurveCreator_Curve::setSectionType( const int theISection,
806 const CurveCreator::SectionType theType )
810 // Set the difference.
811 if (addEmptyDiff()) {
812 myListDiffs.back().init(this, CurveCreator_Operation::SetType,
813 theType, theISection);
816 res = setSectionTypeInternal( theISection, theType );
823 /***********************************************/
824 /*** Point methods ***/
825 /***********************************************/
827 //! For internal use only! Undo/Redo are not used here.
828 bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
831 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
832 CurveCreator_Section *aSection = 0;
833 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
834 int anISection = anIt->first;
835 aSection = (CurveCreator_Section*)getSection( anISection );
837 CurveCreator::PosPointsList aSectionPoints = anIt->second;
838 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
839 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
840 int anIPnt = (*aPntIt)->myID;
841 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
842 CurveCreator::Coordinates::iterator anIterPosition;
844 anIterPosition = aSection->myPoints.end();
846 anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt);
847 /*CurveCreator::Coordinates::const_iterator aFirstPosition =
849 aSection->myPoints.insert(anIterPosition,
850 aCoords.begin(), aCoords.end());
856 redisplayCurve(false);
861 * Add one point to the specified section starting from the given theIPnt index
862 * (or at the end of points if \a theIPnt is -1).
864 bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords,
865 const int theISection,
868 //DEBTRACE("addPoints");
870 CurveCreator::Coordinates aCoords = theCoords;
871 // Set the difference.
873 if (addEmptyDiff()) {
874 CurveCreator_ICurve::SectionToPointCoordsList aList;
875 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords));
876 myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints,
879 CurveCreator::SectionsMap aSectionsMap;
880 CurveCreator::PosPointsList aPoints;
881 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords );
882 aPoints.push_back( aPosPoint );
883 aSectionsMap[theISection] = aPoints;
885 res = addPointsInternal( aSectionsMap );
891 //! For internal use only! Undo/Redo are not used here.
892 bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
896 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
897 CurveCreator_Section *aSection = 0;
898 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
899 int anISection = anIt->first;
900 aSection = (CurveCreator_Section*)getSection( anISection );
902 CurveCreator::PosPointsList aSectionPoints = anIt->second;
903 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
904 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
905 int anIPnt = (*aPntIt)->myID;
906 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
907 for ( int i = 0; i < myDimension; i++)
908 aSection->myPoints.at(toICoord(anIPnt) + i) = aCoords[i];
914 redisplayCurve(false);
919 //! Set coordinates of specified point
920 bool CurveCreator_Curve::setPoint( const int theISection,
922 const CurveCreator::Coordinates& theNewCoords )
924 //DEBTRACE("setPoint");
926 // Set the difference.
928 if (addEmptyDiff()) {
929 CurveCreator_ICurve::SectionToPointCoordsList aList;
930 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords));
931 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
934 CurveCreator::SectionsMap aSectionsMap;
935 CurveCreator::PosPointsList aPoints;
936 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords );
937 aPoints.push_back( aPosPoint );
938 aSectionsMap[theISection] = aPoints;
940 /*int aSize1 = */getNbPoints( theISection ); // todo: unused variable
941 res = setPointInternal( aSectionsMap );
942 /*int aSize2 = */getNbPoints( theISection ); // todo: unused variable
949 //! Set coordinates of specified points from different sections
950 bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
951 const bool theIsToSaveDiff )
953 //DEBTRACE("setSeveralPoints");
955 // Set the difference.
957 if (theIsToSaveDiff && addEmptyDiff()) {
958 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
959 theSectionToPntCoords);
961 CurveCreator::SectionsMap aSectionsMap;
962 CurveCreator::PosPointsList aPosPoints;
963 CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
964 theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end();
965 int aSectionId, aPointId;
966 for ( ; anIt != aLast; anIt++ ) {
968 aSectionId = anIt->first.first;
969 aPointId = anIt->first.second;
970 CurveCreator::Coordinates aNewCoords = anIt->second;
971 CurveCreator_PosPoint* aPosPoint =
972 new CurveCreator_PosPoint( aPointId, aNewCoords );
973 if( aSectionsMap.find(aSectionId) != aSectionsMap.end() )
974 aPosPoints = aSectionsMap[aSectionId];
975 aPosPoints.push_back( aPosPoint );
976 aSectionsMap[aSectionId] = aPosPoints;
979 res = setPointInternal( aSectionsMap );
985 //! For internal use only! Undo/Redo are not used here.
986 bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints )
989 std::map<int, std::list<int> > aConvPoints;
990 convert( thePoints, aConvPoints );
991 std::map<int, std::list<int> >::const_iterator anIt = aConvPoints.begin(),
992 aLast = aConvPoints.end();
993 for ( ; anIt != aLast; anIt++ ) {
994 int aSectionId = anIt->first;
995 aRes = removeSectionPoints(aSectionId, anIt->second);
998 redisplayCurve(false);
1003 //! Remove point with given id
1004 bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt )
1007 // Set the difference.
1009 SectionToPointList aListOfSectionsToPoints;
1010 aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
1011 if (addEmptyDiff()) {
1012 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
1013 aListOfSectionsToPoints);
1015 res = removePointsInternal( aListOfSectionsToPoints );
1020 //! Remove several points from different sections with given ids
1021 bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs)
1024 // Set the difference.
1026 if (addEmptyDiff()) {
1027 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
1028 theSectionToPntIDs);
1030 res = removePointsInternal( theSectionToPntIDs );
1035 //=======================================================================
1036 // function: getCoordinates
1038 //=======================================================================
1039 CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection,
1040 const int theIPnt) const
1042 //DEBTRACE("getPoint");
1043 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
1044 CurveCreator::Coordinates::const_iterator
1045 anIter = aSection->myPoints.begin() + toICoord(theIPnt);
1046 CurveCreator::Coordinates aResult(anIter, anIter + myDimension);
1051 //=======================================================================
1052 // function: getPoints
1054 //=======================================================================
1055 CurveCreator::Coordinates CurveCreator_Curve::getCoords( int theISection ) const
1057 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
1058 return aSection ? aSection->myPoints : CurveCreator::Coordinates();
1061 Handle(TColgp_HArray1OfPnt) CurveCreator_Curve::GetDifferentPoints( int theISection ) const
1063 //DEBTRACE("getPoints");
1064 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
1065 return aSection ? aSection->GetDifferentPoints( (int)myDimension ) : Handle(TColgp_HArray1OfPnt)();
1068 void CurveCreator_Curve::constructAISObject()
1070 //DEBTRACE("constructAISObject");
1071 TopoDS_Shape aShape;
1072 mySect2Shape.Clear();
1073 CurveCreator_Utils::constructShape( this, aShape, &mySect2Shape );
1074 myAISShape = new AIS_ColoredShape( aShape );
1075 AIS_ColoredShape* AISColoredShape = dynamic_cast<AIS_ColoredShape*>(myAISShape);
1077 std::map<int, TopoDS_Shape>::iterator it;
1079 //for ( it = mySect2Shape.begin(); it != mySect2Shape.end(); it++ )
1080 for (int i = 1; i <= mySect2Shape.Extent(); i++ )
1082 CurveCreator_Section* aSect = (CurveCreator_Section*)getSection(mySect2Shape.FindKey(i));
1083 Quantity_Color aColor = aSect->myColor;
1084 const TopoDS_Shape& aShape = mySect2Shape.FindFromIndex(i); //should contain: one wire + vertices
1085 TopoDS_Iterator it(aShape);
1086 for (;it.More();it.Next())
1088 if (it.Value().ShapeType() == TopAbs_WIRE)
1089 AISColoredShape->SetCustomColor(it.Value(), aColor);
1093 // myAISShape->SetColor( myCurveColor );
1094 myAISShape->SetWidth( myLineWidth );
1095 Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect();
1096 anAspect->SetScale( 3.0 );
1097 anAspect->SetTypeOfMarker(Aspect_TOM_O_POINT);
1098 anAspect->SetColor(myPointAspectColor);
1099 myAISShape->Attributes()->SetPointAspect( anAspect );
1102 Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const
1104 //DEBTRACE("getAISObject");
1105 if ( !myAISShape && theNeedToBuild )
1107 CurveCreator_Curve* aCurve = (CurveCreator_Curve*)this;
1108 aCurve->constructAISObject();
1113 bool CurveCreator_Curve::removeSectionPoints( const int theSectionId,
1114 const std::list<int>& thePointIds )
1118 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theSectionId );
1122 std::list<int> aSectionPoints = thePointIds;
1123 aSectionPoints.sort();
1124 std::list<int>::const_reverse_iterator aPntIt = aSectionPoints.rbegin();
1125 for ( ; aPntIt != aSectionPoints.rend(); aPntIt++ ) {
1126 int aPntIndx = *aPntIt;
1127 CurveCreator::Coordinates::iterator aFirstPosition;
1128 if ( aPntIndx == -1 )
1129 aFirstPosition = aSection->myPoints.end() - getDimension();
1131 aFirstPosition = aSection->myPoints.begin() + toICoord( aPntIndx );
1132 aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() );
1138 void CurveCreator_Curve::convert( const SectionToPointList& thePoints,
1139 std::map< int, std::list<int> >& theConvPoints )
1141 theConvPoints.clear();
1143 SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
1144 std::list<int> aPoints;
1145 int aSectionId, aPointId;
1146 for ( ; anIt != aLast; anIt++ ) {
1147 aSectionId = anIt->first;
1148 aPointId = anIt->second;
1150 if ( theConvPoints.find( aSectionId ) != theConvPoints.end() )
1151 aPoints = theConvPoints[aSectionId];
1152 aPoints.push_back( aPointId );
1153 theConvPoints[aSectionId] = aPoints;