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 <AIS_Point.hxx>
28 #include <AIS_Line.hxx>
29 #include <AIS_Shape.hxx>
30 #include <BRepBuilderAPI_MakeEdge.hxx>
31 #include <BRepBuilderAPI_MakeWire.hxx>
32 #include <Geom_CartesianPoint.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Wire.hxx>
38 #include <TColgp_HArray1OfPnt.hxx>
39 #include <GeomAPI_Interpolate.hxx>
43 CurveCreator_Profile::CurveCreator_Profile()
44 : CurveCreator_Curve( CurveCreator::Dim2d )
46 CurveCreator_Section *aSection = new CurveCreator_Section;
47 aSection->myName = getUniqSectionName();
48 aSection->myType = CurveCreator::Polyline;
49 aSection->myIsClosed = false;
51 mySections.push_back( aSection );
54 CurveCreator_Profile::~CurveCreator_Profile()
58 bool CurveCreator_Profile::moveSectionInternal( const int theISection,
59 const int theNewIndex )
64 bool CurveCreator_Profile::moveSection( const int theISection,
65 const int theNewIndex )
70 bool CurveCreator_Profile::clearInternal()
72 // erase curve from the viewer
76 // Delete all allocated data.
77 mySections[ 0 ]->myPoints.clear();
82 bool CurveCreator_Profile::joinInternal( const int theISectionTo,
83 const int theISectionFrom )
88 bool CurveCreator_Profile::join( const int theISectionTo,
89 const int theISectionFrom )
94 int CurveCreator_Profile::addSectionInternal( const std::string& theName,
95 const CurveCreator::SectionType theType,
96 const bool theIsClosed,
97 const CurveCreator::Coordinates& thePoints )
102 int CurveCreator_Profile::addSection( const std::string& theName,
103 const CurveCreator::SectionType theType,
104 const bool theIsClosed )
109 int CurveCreator_Profile::addSection( const std::string& theName,
110 const CurveCreator::SectionType theType,
111 const bool theIsClosed,
112 const CurveCreator::Coordinates& thePoints )
117 bool CurveCreator_Profile::removeSectionInternal( const int theISection )
122 bool CurveCreator_Profile::removeSection( const int theISection )
127 bool CurveCreator_Profile::setClosedInternal( const int theISection,
128 const bool theIsClosed )
133 bool CurveCreator_Profile::setClosed( const int theISection,
134 const bool theIsClosed )
139 bool CurveCreator_Profile::setSectionTypeInternal( const int theISection,
140 const CurveCreator::SectionType theType )
145 bool CurveCreator_Profile::setSectionType( const int theISection,
146 const CurveCreator::SectionType theType )
151 bool CurveCreator_Profile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
155 CurveCreator_Section* aSection = mySections.at( 0 );
159 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
160 for ( ; anIt != theSectionsMap.end(); anIt++ )
162 int anISection = anIt->first;
163 if( anISection != 0 )
166 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
168 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
169 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
171 const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords;
172 CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin();
173 for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ )
175 const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++;
176 if ( aNewPntIt == aNewCoords.end() )
179 const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt;
181 CurveCreator::TypeCoord aC = aCoordU - 1;
182 if ( !aSection->myPoints.empty() )
183 aC = *(aSection->myPoints.end() - 2);
185 if ( aSection->myPoints.empty() || aCoordU > aC )
187 aSection->myPoints.push_back( aCoordU );
188 aSection->myPoints.push_back( aCoordZ );
190 else if ( aCoordU < aSection->myPoints.front() )
192 aSection->myPoints.push_front( aCoordZ );
193 aSection->myPoints.push_front( aCoordU );
197 CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin();
198 for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ )
200 const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++;
201 if ( aCoordU < aRefCoordU )
205 aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 );
219 //! For internal use only! Undo/Redo are not used here.
220 bool CurveCreator_Profile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
224 CurveCreator_Section* aSection = mySections.at( 0 );
228 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
229 for ( ; anIt != theSectionsMap.end(); anIt++ )
231 int anISection = anIt->first;
232 if( anISection != 0 )
235 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
237 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
238 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
240 int anIPnt = (*aPntIt)->myID;
241 aSection->myPoints.erase( aSection->myPoints.begin() + toICoord( anIPnt ),
242 aSection->myPoints.begin() + toICoord( anIPnt ) + 2 );
246 res = addPointsInternal( theSectionsMap );