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 #include "CurveCreator_Profile.hxx"
22 #include "CurveCreator.hxx"
23 #include "CurveCreator_PosPoint.hxx"
24 #include "CurveCreator_Section.hxx"
25 #include "CurveCreator_Displayer.h"
27 #include <BRepBuilderAPI_MakeEdge.hxx>
28 #include <BRepBuilderAPI_MakeWire.hxx>
29 #include <Geom_CartesianPoint.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Wire.hxx>
35 #include <TColgp_HArray1OfPnt.hxx>
36 #include <GeomAPI_Interpolate.hxx>
40 CurveCreator_Profile::CurveCreator_Profile()
41 : CurveCreator_Curve( CurveCreator::Dim2d )
43 CurveCreator_Section *aSection = new CurveCreator_Section;
44 aSection->myName = getUniqSectionName();
45 aSection->myType = CurveCreator::Polyline;
46 aSection->myIsClosed = false;
48 mySections.push_back( aSection );
51 CurveCreator_Profile::~CurveCreator_Profile()
55 bool CurveCreator_Profile::moveSectionInternal( const int theISection,
56 const int theNewIndex )
61 bool CurveCreator_Profile::moveSection( const int theISection,
62 const int theNewIndex )
67 bool CurveCreator_Profile::clearInternal()
69 // erase curve from the viewer
71 myDisplayer->erase( true );
73 // Delete all allocated data.
74 mySections[ 0 ]->myPoints.clear();
79 bool CurveCreator_Profile::joinInternal( const int theISectionTo,
80 const int theISectionFrom )
85 bool CurveCreator_Profile::join( const int theISectionTo,
86 const int theISectionFrom )
91 int CurveCreator_Profile::addSectionInternal( const std::string& theName,
92 const CurveCreator::SectionType theType,
93 const bool theIsClosed,
94 const CurveCreator::Coordinates& thePoints )
99 int CurveCreator_Profile::addSection( const std::string& theName,
100 const CurveCreator::SectionType theType,
101 const bool theIsClosed )
106 int CurveCreator_Profile::addSection( const std::string& theName,
107 const CurveCreator::SectionType theType,
108 const bool theIsClosed,
109 const CurveCreator::Coordinates& thePoints )
114 bool CurveCreator_Profile::removeSectionInternal( const int theISection )
119 bool CurveCreator_Profile::removeSection( const int theISection )
124 bool CurveCreator_Profile::setClosedInternal( const int theISection,
125 const bool theIsClosed )
130 bool CurveCreator_Profile::setClosed( const int theISection,
131 const bool theIsClosed )
136 bool CurveCreator_Profile::setSectionTypeInternal( const int theISection,
137 const CurveCreator::SectionType theType )
139 return CurveCreator_Curve::setSectionTypeInternal( theISection, theType );
142 bool CurveCreator_Profile::setSectionType( const int theISection,
143 const CurveCreator::SectionType theType )
145 return CurveCreator_Curve::setSectionType( theISection, theType );
148 bool CurveCreator_Profile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
152 CurveCreator_Section* aSection = mySections.at( 0 );
156 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
157 for ( ; anIt != theSectionsMap.end(); anIt++ )
159 int anISection = anIt->first;
160 if( anISection != 0 )
163 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
165 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
166 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
168 const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords;
169 CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin();
170 for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ )
172 const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++;
173 if ( aNewPntIt == aNewCoords.end() )
176 const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt;
178 CurveCreator::TypeCoord aC = aCoordU - 1;
179 if ( !aSection->myPoints.empty() )
180 aC = *(aSection->myPoints.end() - 2);
182 if ( aSection->myPoints.empty() || aCoordU > aC )
184 aSection->myPoints.push_back( aCoordU );
185 aSection->myPoints.push_back( aCoordZ );
187 else if ( aCoordU < aSection->myPoints.front() )
189 aSection->myPoints.push_front( aCoordZ );
190 aSection->myPoints.push_front( aCoordU );
194 CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin();
195 for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ )
197 const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++;
198 if ( aCoordU < aRefCoordU )
202 aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 );
216 //! For internal use only! Undo/Redo are not used here.
217 bool CurveCreator_Profile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
221 CurveCreator_Section* aSection = mySections.at( 0 );
225 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
226 for ( ; anIt != theSectionsMap.end(); anIt++ )
228 int anISection = anIt->first;
229 if( anISection != 0 )
232 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
234 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
235 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
237 int anIPnt = (*aPntIt)->myID;
238 aSection->myPoints.erase( aSection->myPoints.begin() + toICoord( anIPnt ),
239 aSection->myPoints.begin() + toICoord( anIPnt ) + 2 );
243 res = addPointsInternal( theSectionsMap );