1 // Copyright (C) 2013-2023 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 #include "CurveCreator_UtilsICurve.hxx"
22 #include "CurveCreator.hxx"
24 #include <TopoDS_Shape.hxx>
26 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
28 int CurveCreator_UtilsICurve::findLocalPointIndex( const CurveCreator_ICurve* theCurve,
29 int theSectionId, double theX, double theY )
35 CurveCreator::Coordinates aCoords;
36 for ( int i = 0, aNb = theCurve->getNbPoints( theSectionId ); i < aNb && aPntIndex < 0; i++ ) {
37 aCoords = theCurve->getPoint( theSectionId, i );
38 if ( aCoords.size() < 2 )
40 if ( fabs( aCoords[0] - theX ) < LOCAL_SELECTION_TOLERANCE &&
41 fabs( aCoords[1] - theY ) < LOCAL_SELECTION_TOLERANCE )
48 void CurveCreator_UtilsICurve::findSectionsToPoints( const CurveCreator_ICurve* theCurve,
49 const double theX, const double theY,
50 CurveCreator_ICurve::SectionToPointList& thePoints )
55 for ( int i = 0, aNb = theCurve->getNbSections(); i < aNb; i++ ) {
56 aPointId = CurveCreator_UtilsICurve::findLocalPointIndex( theCurve, i, theX, theY );
59 CurveCreator_ICurve::SectionToPoint aPoint = std::make_pair( i, aPointId );
60 if ( !CurveCreator_UtilsICurve::contains( thePoints, aPoint ) )
61 thePoints.push_back( aPoint );
65 void CurveCreator_UtilsICurve::convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
66 QMap<int, QList<int> >& theConvPoints )
68 theConvPoints.clear();
70 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
71 aLast = thePoints.end();
73 int aSectionId, aPointId;
74 for ( ; anIt != aLast; anIt++ ) {
75 aSectionId = anIt->first;
76 aPointId = anIt->second;
78 if ( theConvPoints.contains( aSectionId ) )
79 aPoints = theConvPoints[aSectionId];
80 if ( aPoints.contains( aPointId ) )
82 aPoints.append( aPointId );
83 theConvPoints[aSectionId] = aPoints;
87 #include "CurveCreator_Curve.hxx" // TODO
88 void CurveCreator_UtilsICurve::getPoint( const CurveCreator_ICurve* theCurve, const int theISection,
89 const int theIPoint, gp_Pnt& thePoint )
93 const CurveCreator_Curve* aCurve = dynamic_cast<const CurveCreator_Curve*>( theCurve );
95 aCurve->getCoordinates( theISection, theIPoint, anX, anY, aZ );
96 thePoint = gp_Pnt( anX, anY, aZ);
99 std::string CurveCreator_UtilsICurve::getUniqSectionName( CurveCreator_ICurve* theCurve )
101 for( int i = 0 ; i < 1000000 ; i++ ){
103 sprintf( aBuffer, "Section_%d", i+1 );
104 std::string aName(aBuffer);
106 for( j = 0 ; j < theCurve->getNbSections() ; j++ ){
107 if( theCurve->getSectionName(j) == aName )
110 if( j == theCurve->getNbSections() )
116 bool CurveCreator_UtilsICurve::contains( const CurveCreator_ICurve::SectionToPointList& theList,
117 const CurveCreator_ICurve::SectionToPoint& theValue )
119 bool isFound = false;
121 CurveCreator_ICurve::SectionToPointList::const_iterator anIt = theList.begin(),
122 aLast = theList.end();
123 for ( ; anIt != aLast && !isFound; anIt++ )
124 isFound = anIt->first == theValue.first && anIt->second == theValue.second;