1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <HYDROGUI_CurveCreatorProfile.h>
24 #include <CurveCreator_Displayer.hxx>
25 #include <CurveCreator_Section.hxx>
27 HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile()
28 : CurveCreator_Curve( CurveCreator::Dim2d )
30 CurveCreator_Section *aSection = new CurveCreator_Section;
31 aSection->myName = getUniqSectionName();
32 aSection->myType = CurveCreator::Polyline;
33 aSection->myIsClosed = false;
35 mySections.push_back( aSection );
38 HYDROGUI_CurveCreatorProfile::~HYDROGUI_CurveCreatorProfile()
42 bool HYDROGUI_CurveCreatorProfile::moveSectionInternal( const int theISection,
43 const int theNewIndex )
48 bool HYDROGUI_CurveCreatorProfile::moveSection( const int theISection,
49 const int theNewIndex )
54 bool HYDROGUI_CurveCreatorProfile::clearInternal()
56 // erase curve from the viewer
58 myDisplayer->eraseAll( true );
60 // Delete all allocated data.
61 CurveCreator_Section* aSection = getSection( 0 );
63 aSection->myPoints.clear();
68 bool HYDROGUI_CurveCreatorProfile::joinInternal( const std::list<int>& theSections )
73 bool HYDROGUI_CurveCreatorProfile::join( const std::list<int>& theSections )
78 int HYDROGUI_CurveCreatorProfile::addSectionInternal( const std::string& theName,
79 const CurveCreator::SectionType theType,
80 const bool theIsClosed,
81 const CurveCreator::Coordinates& thePoints )
86 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
87 const CurveCreator::SectionType theType,
88 const bool theIsClosed )
93 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
94 const CurveCreator::SectionType theType,
95 const bool theIsClosed,
96 const CurveCreator::Coordinates& thePoints )
101 bool HYDROGUI_CurveCreatorProfile::removeSectionInternal( const int theISection )
106 bool HYDROGUI_CurveCreatorProfile::removeSection( const int theISection )
111 bool HYDROGUI_CurveCreatorProfile::setClosedInternal( const int theISection, const bool theIsClosed )
116 bool HYDROGUI_CurveCreatorProfile::setClosed( const int theISection, const bool theIsClosed )
121 bool HYDROGUI_CurveCreatorProfile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
125 CurveCreator_Section* aSection = getSection( 0 );
129 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
130 for ( ; anIt != theSectionsMap.end(); anIt++ )
132 int anISection = anIt->first;
133 if( anISection != 0 )
136 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
138 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
139 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
141 const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords;
142 CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin();
143 for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ )
145 const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++;
146 if ( aNewPntIt == aNewCoords.end() )
149 const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt;
151 CurveCreator::TypeCoord aC = aCoordU - 1;
152 if ( !aSection->myPoints.empty() )
153 aC = *(aSection->myPoints.end() - 2);
155 if ( aSection->myPoints.empty() || aCoordU >= aC )
157 aSection->myPoints.push_back( aCoordU );
158 aSection->myPoints.push_back( aCoordZ );
160 else if ( aCoordU < aSection->myPoints.front() )
162 aSection->myPoints.push_front( aCoordZ );
163 aSection->myPoints.push_front( aCoordU );
167 CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin();
168 for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ )
170 const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++;
171 if ( aCoordU < aRefCoordU )
175 aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 );
189 //! For internal use only! Undo/Redo are not used here.
190 bool HYDROGUI_CurveCreatorProfile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
194 if ( mySkipSorting ) {
195 return CurveCreator_Curve::setPointInternal( theSectionsMap );
199 CurveCreator_Section* aSection = getSection( anISection );
203 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
204 if ( anIt == theSectionsMap.end() )
207 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
209 std::list<int> aConvPoints;
210 convert( aSectionPoints, aConvPoints );
211 removeSectionPoints( anISection, aConvPoints );
213 aRes = addPointsInternal( theSectionsMap );
220 void HYDROGUI_CurveCreatorProfile::convert( const CurveCreator::PosPointsList& thePoints,
221 std::list<int>& theConvPoints )
223 theConvPoints.clear();
225 CurveCreator::PosPointsList::const_iterator aPntIt = thePoints.begin(),
226 aPntLast = thePoints.end();
227 for( ; aPntIt != aPntLast; aPntIt++ )
229 int anIPnt = (*aPntIt)->myID;
230 theConvPoints.push_back( anIPnt );
234 bool HYDROGUI_CurveCreatorProfile::canPointsBeSorted()
240 * Add one point to the specified section starting from the given theIPnt index
241 * (or at the end of points if \a theIPnt is -1).
243 bool HYDROGUI_CurveCreatorProfile::addPoints( const CurveCreator::Coordinates& theCoords,
244 const int theISection,
247 int anIPnt = theIPnt;
249 if ( anIPnt == - 1 && theCoords.size() > 1 ) {
250 CurveCreator::Coordinates aCoords;
251 for ( int i = 0, aNb = getNbPoints( theISection ); i < aNb; i++ ) {
252 aCoords = getPoint( theISection, i );
253 if ( aCoords.size() < 2 ) {
257 if ( theCoords[0] < aCoords[0] ) {
264 return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt );