1 // Copyright (C) 2013-2016 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, 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>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Wire.hxx>
40 #include <Prs3d_PointAspect.hxx>
42 #define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
46 //=======================================================================
47 // function: Constructor
49 //=======================================================================
50 CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimension )
52 myDimension (theDimension),
60 myPointAspectColor (Quantity_NOC_ROYALBLUE4),
61 myCurveColor (Quantity_NOC_RED),
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 CurveCreator_Section* aSection;
92 for( int i = 0 ; i < 1000000 ; i++ ){
94 sprintf( aBuffer, "Section_%d", i+1 );
95 std::string aName(aBuffer);
97 for( j = 0 ; j < mySections.size() ; j++ ){
98 aSection = (CurveCreator_Section*)getSection( j );
99 if ( aSection && aSection->myName == aName )
102 if( j == mySections.size() )
108 //=======================================================================
109 // function: setDisplayer
110 // purpose: set curve changes Displayer
111 //=======================================================================
112 void CurveCreator_Curve::setDisplayer( CurveCreator_Displayer* theDisplayer )
114 myDisplayer = theDisplayer;
117 //=======================================================================
118 // function: getDisplayer
119 // purpose: get curve changes Displayer
120 //=======================================================================
121 CurveCreator_Displayer* CurveCreator_Curve::getDisplayer()
126 //=======================================================================
127 // function: removeDisplayer
128 // purpose: remove the attached Displayer
129 //=======================================================================
130 void CurveCreator_Curve::removeDisplayer()
135 //=======================================================================
138 //=======================================================================
139 bool CurveCreator_Curve::addEmptyDiff()
141 bool isEnabled = false;
143 if (myUndoDepth != 0) {
144 // Forget all Redos after the current one.
147 myListDiffs.erase(myCurrenPos, myListDiffs.end());
150 if (myUndoDepth == -1 || myNbUndos < myUndoDepth) {
151 // Increase the number of undos.
154 // If there are too many differences, remove the first one.
155 myListDiffs.pop_front();
158 // Add new difference.
159 myListDiffs.push_back(CurveCreator_Diff());
160 myCurrenPos = myListDiffs.end();
167 void CurveCreator_Curve::startOperation()
172 void CurveCreator_Curve::finishOperation()
177 //=======================================================================
178 // function: toICoord
180 //=======================================================================
181 int CurveCreator_Curve::toICoord(const int theIPnt) const
183 return theIPnt * myDimension;
186 //=======================================================================
187 // function: setUndoDepth
189 //=======================================================================
190 void CurveCreator_Curve::setUndoDepth(const int theDepth)
193 // Reset all undo/redo data.
197 myCurrenPos = myListDiffs.end();
199 } else if (theDepth == -1) {
200 // There is nothing to do as the depth become unlimited.
202 } else if (theDepth > 0) {
203 // The new "real" depth is set.
204 if (theDepth < myNbRedos) {
205 // The new depth is less then number of redos. Remove the latest redos.
206 int aShift = (myNbRedos - theDepth);
207 ListDiff::iterator aFromPos = myListDiffs.end();
213 myListDiffs.erase(aFromPos, myListDiffs.end());
214 myNbRedos = theDepth;
217 if (theDepth < myNbUndos + myNbRedos) {
218 // The new depth is less then the total number of differences.
219 // Remove the first undos.
220 int aShift = (myNbUndos + myNbRedos - theDepth);
221 ListDiff::iterator aToPos = myListDiffs.begin();
227 myListDiffs.erase(myListDiffs.begin(), aToPos);
228 myNbUndos = theDepth - myNbRedos;
231 myUndoDepth = theDepth;
235 //=======================================================================
236 // function: getUndoDepth
238 //=======================================================================
239 int CurveCreator_Curve::getUndoDepth() const
244 void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const
246 CurveCreator::Coordinates aCoords = getPoint( theISection, theIPoint );
250 if( getDimension() == CurveCreator::Dim3d ){
255 void CurveCreator_Curve::redisplayCurve(bool preEraseAllObjects)
257 //DEBTRACE("redisplayCurve");
260 if (preEraseAllObjects)
261 myDisplayer->eraseAll( false );
263 myDisplayer->erase( myAISShape, false);
265 myDisplayer->display( getAISObject( true ), true );
269 //! For internal use only! Undo/Redo are not used here.
270 bool CurveCreator_Curve::moveSectionInternal(const int theISection,
271 const int theNewIndex)
274 int aMovedSectionId = theISection >= 0 ? theISection : mySections.size()-1;
276 if (aMovedSectionId != theNewIndex) {
277 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( aMovedSectionId );
280 CurveCreator::Sections::iterator anIter = mySections.begin() + aMovedSectionId;
282 mySections.erase(anIter);
285 anIter = mySections.begin() + theNewIndex;
286 mySections.insert(anIter, aSection);
292 //=======================================================================
293 // function: moveSection
295 //=======================================================================
296 bool CurveCreator_Curve::moveSection(const int theISection,
297 const int theNewIndex)
300 // Set the difference.
302 if (addEmptyDiff()) {
303 myListDiffs.back().init(this, CurveCreator_Operation::MoveSection,
304 theISection, theNewIndex);
308 res = moveSectionInternal(theISection, theNewIndex);
313 /************ Implementation of INTERFACE methods ************/
315 /***********************************************/
316 /*** Undo/Redo methods ***/
317 /***********************************************/
319 //! Get number of available undo operations
320 int CurveCreator_Curve::getNbUndo() const
325 //! Undo previous operation
326 bool CurveCreator_Curve::undo()
333 myCurrenPos->applyUndo(this);
339 //! Get number of available redo operations
340 int CurveCreator_Curve::getNbRedo() const
345 //! Redo last previously "undone" operation
346 bool CurveCreator_Curve::redo()
350 myCurrenPos->applyRedo(this);
359 /***********************************************/
360 /*** Section methods ***/
361 /***********************************************/
362 //! For internal use only! Undo/Redo are not used here.
363 bool CurveCreator_Curve::clearInternal()
365 // erase curve from the viewer
367 myDisplayer->eraseAll( true );
370 // Delete all allocated data.
372 const int aNbSections = getNbSections();
374 CurveCreator_Section* aSection;
375 for (; i < aNbSections; i++) {
376 aSection = (CurveCreator_Section*)getSection( i );
386 //=======================================================================
389 //=======================================================================
390 bool CurveCreator_Curve::clear()
394 // Set the difference.
395 if (addEmptyDiff()) {
396 myListDiffs.back().init(this);
398 res = clearInternal();
403 //! For internal use only! Undo/Redo are not used here.
404 bool CurveCreator_Curve::joinInternal( const std::list<int>& theSections )
407 if ( theSections.empty() )
410 int anISectionMain = theSections.front();
411 CurveCreator_Section* aSectionMain =
412 (CurveCreator_Section*)getSection( anISectionMain );
414 std::list <int> aSectionsToJoin = theSections;
415 aSectionsToJoin.erase( aSectionsToJoin.begin() ); // skip the main section
416 // it is important to sort and reverse the section ids in order to correctly remove them
417 aSectionsToJoin.sort();
418 aSectionsToJoin.reverse();
420 std::list<int>::const_iterator anIt = aSectionsToJoin.begin(), aLast = aSectionsToJoin.end();
421 CurveCreator_Section* aSection;
422 for (; anIt != aLast; anIt++) {
423 aSection = (CurveCreator_Section*)getSection( *anIt );
424 aSectionMain->myPoints.insert(aSectionMain->myPoints.end(), aSection->myPoints.begin(),
425 aSection->myPoints.end());
426 res = removeSectionInternal(*anIt);
431 redisplayCurve(false);
435 bool CurveCreator_Curve::join( const std::list<int>& theSections )
439 if ( !theSections.empty() )
443 myListDiffs.back().init(this, CurveCreator_Operation::Join, theSections);
445 res = joinInternal( theSections );
452 //! Get number of sections
453 int CurveCreator_Curve::getNbSections() const
455 return mySections.size();
458 //! For internal use only! Undo/Redo are not used here.
459 int CurveCreator_Curve::addSectionInternal
460 (const std::string& theName, const CurveCreator::SectionType theType,
461 const bool theIsClosed, const CurveCreator::Coordinates &thePoints)
463 CurveCreator_Section *aSection = new CurveCreator_Section;
465 std::string aName = theName;
467 aName = getUniqSectionName();
469 aSection->myName = aName;
470 aSection->myType = theType;
471 aSection->myIsClosed = theIsClosed;
472 aSection->myPoints = thePoints;
473 mySections.push_back(aSection);
474 redisplayCurve(false);
475 return mySections.size()-1;
478 //=======================================================================
479 // function: addSection
480 // purpose: adds an empty section
481 //=======================================================================
482 int CurveCreator_Curve::addSection
483 (const std::string& theName, const CurveCreator::SectionType theType,
484 const bool theIsClosed)
486 int resISection = -1;
487 // Set the difference.
489 CurveCreator::Coordinates aCoords; //empty list
490 if (addEmptyDiff()) {
491 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
492 theName, aCoords, theType, theIsClosed);
495 resISection = addSectionInternal(theName, theType, theIsClosed, aCoords);
500 //=======================================================================
501 // function: addSection
502 // purpose: adds a section with the given points
503 //=======================================================================
504 int CurveCreator_Curve::addSection
505 (const std::string& theName, const CurveCreator::SectionType theType,
506 const bool theIsClosed, const CurveCreator::Coordinates &thePoints)
508 int resISection = -1;
509 // Set the difference.
511 if (addEmptyDiff()) {
512 myListDiffs.back().init(this, CurveCreator_Operation::AddSection,
513 theName, thePoints, theType, theIsClosed);
516 resISection = addSectionInternal(theName, theType, theIsClosed, thePoints);
522 //! For internal use only! Undo/Redo are not used here.
523 bool CurveCreator_Curve::removeSectionInternal( const int theISection )
525 if (theISection == -1) {
526 delete mySections.back();
527 mySections.pop_back();
529 CurveCreator::Sections::iterator anIterRm = mySections.begin() + theISection;
532 mySections.erase(anIterRm);
534 redisplayCurve(false);
538 //! Removes the given sections.
539 bool CurveCreator_Curve::removeSection( const int theISection )
542 // Set the difference.
545 myListDiffs.back().init(this, CurveCreator_Operation::RemoveSection, theISection);
547 res = removeSectionInternal( theISection );
554 * Get number of points in specified section or (the total number of points
555 * in Curve if theISection is equal to -1).
557 int CurveCreator_Curve::getNbPoints( const int theISection ) const
561 CurveCreator_Section* aSection;
562 if (theISection == -1) {
564 const int aNbSections = getNbSections();
566 for (; i < aNbSections; i++) {
567 aSection = (CurveCreator_Section*)getSection( i );
569 aNbCoords += aSection->myPoints.size();
572 aSection = (CurveCreator_Section*)getSection( theISection );
574 aNbCoords = aSection->myPoints.size();
577 return aNbCoords/myDimension;
580 void CurveCreator_Curve::setSkipSorting( const bool theIsToSkip )
582 mySkipSorting = theIsToSkip;
585 bool CurveCreator_Curve::canPointsBeSorted()
591 * Saves points coordinates difference.
592 * \param theOldCoords the old points coordinates
594 void CurveCreator_Curve::saveCoordDiff( const SectionToPointCoordsList &theOldCoords )
596 // Set the difference.
598 if (addEmptyDiff()) {
599 myListDiffs.back().init(this, theOldCoords);
604 //! Get "closed" flag of the specified section
605 bool CurveCreator_Curve::isClosed( const int theISection ) const
607 const CurveCreator_Section* aSection =
608 (CurveCreator_Section*)getSection( theISection );
609 return aSection ? aSection->myIsClosed : false;
612 //! For internal use only! Undo/Redo are not used here.
613 bool CurveCreator_Curve::setClosedInternal( const int theISection,
614 const bool theIsClosed )
616 CurveCreator_Section* aSection = 0;
617 if (theISection == -1) {
618 int aSize = mySections.size();
621 for (i = 0; i < aSize; i++) {
622 aSection = (CurveCreator_Section*)getSection( i );
624 aSection->myIsClosed = theIsClosed;
625 redisplayCurve(false);
629 aSection = (CurveCreator_Section*)getSection( theISection );
631 aSection->myIsClosed = theIsClosed;
632 redisplayCurve(false);
639 * Set "closed" flag of the specified section (all sections if
640 * \a theISection is -1).
642 bool CurveCreator_Curve::setClosed( const int theISection,
643 const bool theIsClosed )
646 // Set the difference.
648 if (addEmptyDiff()) {
649 myListDiffs.back().init(this, CurveCreator_Operation::SetClosed,
650 theIsClosed, theISection);
652 res = setClosedInternal( theISection, theIsClosed );
657 //! Returns specified section name
658 std::string CurveCreator_Curve::getSectionName( const int theISection ) const
660 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
661 return aSection ? aSection->myName : "";
664 //! For internal use only! Undo/Redo are not used here.
665 bool CurveCreator_Curve::setSectionNameInternal( const int theISection,
666 const std::string& theName )
669 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
671 aSection->myName = theName;
677 /** Set name of the specified section */
678 bool CurveCreator_Curve::setSectionName( const int theISection,
679 const std::string& theName )
682 // Set the difference.
684 if (addEmptyDiff()) {
685 myListDiffs.back().init(this, CurveCreator_Operation::RenameSection,
686 theName, theISection);
688 res = setSectionNameInternal( theISection, theName );
693 //! Get type of the specified section
694 CurveCreator::SectionType CurveCreator_Curve::getSectionType
695 ( const int theISection ) const
697 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
698 return aSection ? aSection->myType : CurveCreator::Polyline;
701 //! For internal use only! Undo/Redo are not used here.
702 bool CurveCreator_Curve::setSectionTypeInternal( const int theISection,
703 const CurveCreator::SectionType theType )
705 CurveCreator_Section* aSection;
706 if (theISection == -1) {
708 const int aNbSections = getNbSections();
710 for (; i < aNbSections; i++) {
711 aSection = (CurveCreator_Section*)getSection( i );
713 aSection->myType = theType;
715 redisplayCurve(false);
717 aSection = (CurveCreator_Section*)getSection( theISection );
718 if ( aSection && aSection->myType != theType ){
719 aSection->myType = theType;
720 redisplayCurve(false);
727 * Set type of the specified section (or all sections
728 * if \a theISection is -1).
730 bool CurveCreator_Curve::setSectionType( const int theISection,
731 const CurveCreator::SectionType theType )
735 // Set the difference.
736 if (addEmptyDiff()) {
737 myListDiffs.back().init(this, CurveCreator_Operation::SetType,
738 theType, theISection);
741 res = setSectionTypeInternal( theISection, theType );
748 /***********************************************/
749 /*** Point methods ***/
750 /***********************************************/
752 //! For internal use only! Undo/Redo are not used here.
753 bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
756 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
757 CurveCreator_Section *aSection = 0;
758 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
759 int anISection = anIt->first;
760 aSection = (CurveCreator_Section*)getSection( anISection );
762 CurveCreator::PosPointsList aSectionPoints = anIt->second;
763 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
764 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
765 int anIPnt = (*aPntIt)->myID;
766 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
767 CurveCreator::Coordinates::iterator anIterPosition;
769 anIterPosition = aSection->myPoints.end();
771 anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt);
772 CurveCreator::Coordinates::const_iterator aFirstPosition =
774 aSection->myPoints.insert(anIterPosition,
775 aCoords.begin(), aCoords.end());
781 redisplayCurve(false);
786 * Add one point to the specified section starting from the given theIPnt index
787 * (or at the end of points if \a theIPnt is -1).
789 bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords,
790 const int theISection,
793 //DEBTRACE("addPoints");
795 CurveCreator::Coordinates aCoords = theCoords;
796 // Set the difference.
798 if (addEmptyDiff()) {
799 CurveCreator_ICurve::SectionToPointCoordsList aList;
800 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords));
801 myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints,
804 CurveCreator::SectionsMap aSectionsMap;
805 CurveCreator::PosPointsList aPoints;
806 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords );
807 aPoints.push_back( aPosPoint );
808 aSectionsMap[theISection] = aPoints;
810 res = addPointsInternal( aSectionsMap );
816 //! For internal use only! Undo/Redo are not used here.
817 bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
821 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
822 CurveCreator_Section *aSection = 0;
823 for ( ; anIt != theSectionsMap.end(); anIt++ ) {
824 int anISection = anIt->first;
825 aSection = (CurveCreator_Section*)getSection( anISection );
827 CurveCreator::PosPointsList aSectionPoints = anIt->second;
828 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
829 for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
830 int anIPnt = (*aPntIt)->myID;
831 CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
832 for ( int i = 0; i < myDimension; i++)
833 aSection->myPoints.at(toICoord(anIPnt) + i) = aCoords[i];
839 redisplayCurve(false);
844 //! Set coordinates of specified point
845 bool CurveCreator_Curve::setPoint( const int theISection,
847 const CurveCreator::Coordinates& theNewCoords )
849 //DEBTRACE("setPoint");
851 // Set the difference.
853 if (addEmptyDiff()) {
854 CurveCreator_ICurve::SectionToPointCoordsList aList;
855 aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords));
856 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
859 CurveCreator::SectionsMap aSectionsMap;
860 CurveCreator::PosPointsList aPoints;
861 CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords );
862 aPoints.push_back( aPosPoint );
863 aSectionsMap[theISection] = aPoints;
865 int aSize1 = getNbPoints( theISection );
866 res = setPointInternal( aSectionsMap );
867 int aSize2 = getNbPoints( theISection );
874 //! Set coordinates of specified points from different sections
875 bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
876 const bool theIsToSaveDiff )
878 //DEBTRACE("setSeveralPoints");
880 // Set the difference.
882 if (theIsToSaveDiff && addEmptyDiff()) {
883 myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
884 theSectionToPntCoords);
886 CurveCreator::SectionsMap aSectionsMap;
887 CurveCreator::PosPointsList aPosPoints;
888 CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
889 theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end();
890 int aSectionId, aPointId;
891 for ( ; anIt != aLast; anIt++ ) {
893 aSectionId = anIt->first.first;
894 aPointId = anIt->first.second;
895 CurveCreator::Coordinates aNewCoords = anIt->second;
896 CurveCreator_PosPoint* aPosPoint =
897 new CurveCreator_PosPoint( aPointId, aNewCoords );
898 if( aSectionsMap.find(aSectionId) != aSectionsMap.end() )
899 aPosPoints = aSectionsMap[aSectionId];
900 aPosPoints.push_back( aPosPoint );
901 aSectionsMap[aSectionId] = aPosPoints;
904 res = setPointInternal( aSectionsMap );
910 //! For internal use only! Undo/Redo are not used here.
911 bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints )
914 std::map<int, std::list<int> > aConvPoints;
915 convert( thePoints, aConvPoints );
916 std::map<int, std::list<int> >::const_iterator anIt = aConvPoints.begin(),
917 aLast = aConvPoints.end();
918 for ( ; anIt != aLast; anIt++ ) {
919 int aSectionId = anIt->first;
920 aRes = removeSectionPoints(aSectionId, anIt->second);
923 redisplayCurve(false);
928 //! Remove point with given id
929 bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt )
932 // Set the difference.
934 SectionToPointList aListOfSectionsToPoints;
935 aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
936 if (addEmptyDiff()) {
937 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
938 aListOfSectionsToPoints);
940 res = removePointsInternal( aListOfSectionsToPoints );
945 //! Remove several points from different sections with given ids
946 bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs)
949 // Set the difference.
951 if (addEmptyDiff()) {
952 myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
955 res = removePointsInternal( theSectionToPntIDs );
960 //=======================================================================
961 // function: getCoordinates
963 //=======================================================================
964 CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection,
965 const int theIPnt) const
967 //DEBTRACE("getPoint");
968 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
969 CurveCreator::Coordinates::const_iterator
970 anIter = aSection->myPoints.begin() + toICoord(theIPnt);
971 CurveCreator::Coordinates aResult(anIter, anIter + myDimension);
976 //=======================================================================
977 // function: getPoints
979 //=======================================================================
980 CurveCreator::Coordinates CurveCreator_Curve::getCoords( int theISection ) const
982 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
983 return aSection ? aSection->myPoints : CurveCreator::Coordinates();
986 Handle(TColgp_HArray1OfPnt) CurveCreator_Curve::GetDifferentPoints( int theISection ) const
988 //DEBTRACE("getPoints");
989 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection );
990 return aSection ? aSection->GetDifferentPoints( (int)myDimension ) : Handle(TColgp_HArray1OfPnt)();
993 void CurveCreator_Curve::constructAISObject()
995 //DEBTRACE("constructAISObject");
997 CurveCreator_Utils::constructShape( this, aShape );
998 myAISShape = new AIS_Shape( aShape );
999 myAISShape->SetColor( myCurveColor );
1000 myAISShape->SetWidth( myLineWidth );
1001 Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect();
1002 anAspect->SetScale( 3.0 );
1003 anAspect->SetTypeOfMarker(Aspect_TOM_O_POINT);
1004 anAspect->SetColor(myPointAspectColor);
1005 myAISShape->Attributes()->SetPointAspect( anAspect );
1008 Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const
1010 //DEBTRACE("getAISObject");
1011 if ( !myAISShape && theNeedToBuild )
1013 CurveCreator_Curve* aCurve = (CurveCreator_Curve*)this;
1014 aCurve->constructAISObject();
1019 bool CurveCreator_Curve::removeSectionPoints( const int theSectionId,
1020 const std::list<int>& thePointIds )
1024 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theSectionId );
1028 std::list<int> aSectionPoints = thePointIds;
1029 aSectionPoints.sort();
1030 std::list<int>::const_reverse_iterator aPntIt = aSectionPoints.rbegin();
1031 for ( ; aPntIt != aSectionPoints.rend(); aPntIt++ ) {
1032 int aPntIndx = *aPntIt;
1033 CurveCreator::Coordinates::iterator aFirstPosition;
1034 if ( aPntIndx == -1 )
1035 aFirstPosition = aSection->myPoints.end() - getDimension();
1037 aFirstPosition = aSection->myPoints.begin() + toICoord( aPntIndx );
1038 aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() );
1044 void CurveCreator_Curve::convert( const SectionToPointList& thePoints,
1045 std::map< int, std::list<int> >& theConvPoints )
1047 theConvPoints.clear();
1049 SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
1050 std::list<int> aPoints;
1051 int aSectionId, aPointId;
1052 for ( ; anIt != aLast; anIt++ ) {
1053 aSectionId = anIt->first;
1054 aPointId = anIt->second;
1056 if ( theConvPoints.find( aSectionId ) != theConvPoints.end() )
1057 aPoints = theConvPoints[aSectionId];
1058 aPoints.push_back( aPointId );
1059 theConvPoints[aSectionId] = aPoints;