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 <HYDROGUI_CurveCreatorProfile.h>
21 #include <CurveCreator_Displayer.hxx>
22 #include <CurveCreator_Section.hxx>
24 HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile()
25 : CurveCreator_Curve( CurveCreator::Dim2d )
27 CurveCreator_Section *aSection = new CurveCreator_Section;
28 aSection->myName = getUniqSectionName();
29 aSection->myType = CurveCreator::Polyline;
30 aSection->myIsClosed = false;
32 mySections.push_back( aSection );
35 HYDROGUI_CurveCreatorProfile::~HYDROGUI_CurveCreatorProfile()
39 bool HYDROGUI_CurveCreatorProfile::moveSectionInternal( const int theISection,
40 const int theNewIndex )
45 bool HYDROGUI_CurveCreatorProfile::moveSection( const int theISection,
46 const int theNewIndex )
51 bool HYDROGUI_CurveCreatorProfile::clearInternal()
53 // erase curve from the viewer
55 myDisplayer->eraseAll( true );
57 // Delete all allocated data.
58 CurveCreator_Section* aSection = getSection( 0 );
60 aSection->myPoints.clear();
65 bool HYDROGUI_CurveCreatorProfile::joinInternal( const std::list<int>& theSections )
70 bool HYDROGUI_CurveCreatorProfile::join( const std::list<int>& theSections )
75 int HYDROGUI_CurveCreatorProfile::addSectionInternal( const std::string& theName,
76 const CurveCreator::SectionType theType,
77 const bool theIsClosed,
78 const CurveCreator::Coordinates& thePoints )
83 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
84 const CurveCreator::SectionType theType,
85 const bool theIsClosed )
90 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
91 const CurveCreator::SectionType theType,
92 const bool theIsClosed,
93 const CurveCreator::Coordinates& thePoints )
98 bool HYDROGUI_CurveCreatorProfile::removeSectionInternal( const int theISection )
103 bool HYDROGUI_CurveCreatorProfile::removeSection( const int theISection )
108 bool HYDROGUI_CurveCreatorProfile::setClosedInternal( const int theISection, const bool theIsClosed )
113 bool HYDROGUI_CurveCreatorProfile::setClosed( const int theISection, const bool theIsClosed )
118 bool HYDROGUI_CurveCreatorProfile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
122 CurveCreator_Section* aSection = getSection( 0 );
126 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
127 for ( ; anIt != theSectionsMap.end(); anIt++ )
129 int anISection = anIt->first;
130 if( anISection != 0 )
133 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
135 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
136 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
138 const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords;
139 CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin();
140 for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ )
142 const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++;
143 if ( aNewPntIt == aNewCoords.end() )
146 const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt;
148 CurveCreator::TypeCoord aC = aCoordU - 1;
149 if ( !aSection->myPoints.empty() )
150 aC = *(aSection->myPoints.end() - 2);
152 if ( aSection->myPoints.empty() || aCoordU >= aC )
154 aSection->myPoints.push_back( aCoordU );
155 aSection->myPoints.push_back( aCoordZ );
157 else if ( aCoordU < aSection->myPoints.front() )
159 aSection->myPoints.push_front( aCoordZ );
160 aSection->myPoints.push_front( aCoordU );
164 CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin();
165 for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ )
167 const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++;
168 if ( aCoordU < aRefCoordU )
172 aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 );
186 //! For internal use only! Undo/Redo are not used here.
187 bool HYDROGUI_CurveCreatorProfile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
191 if ( mySkipSorting ) {
192 return CurveCreator_Curve::setPointInternal( theSectionsMap );
196 CurveCreator_Section* aSection = getSection( anISection );
200 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
201 if ( anIt == theSectionsMap.end() )
204 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
206 std::list<int> aConvPoints;
207 convert( aSectionPoints, aConvPoints );
208 removeSectionPoints( anISection, aConvPoints );
210 aRes = addPointsInternal( theSectionsMap );
217 void HYDROGUI_CurveCreatorProfile::convert( const CurveCreator::PosPointsList& thePoints,
218 std::list<int>& theConvPoints )
220 theConvPoints.clear();
222 CurveCreator::PosPointsList::const_iterator aPntIt = thePoints.begin(),
223 aPntLast = thePoints.end();
224 for( ; aPntIt != aPntLast; aPntIt++ )
226 int anIPnt = (*aPntIt)->myID;
227 theConvPoints.push_back( anIPnt );
231 bool HYDROGUI_CurveCreatorProfile::canPointsBeSorted()
237 * Add one point to the specified section starting from the given theIPnt index
238 * (or at the end of points if \a theIPnt is -1).
240 bool HYDROGUI_CurveCreatorProfile::addPoints( const CurveCreator::Coordinates& theCoords,
241 const int theISection,
244 int anIPnt = theIPnt;
246 if ( anIPnt == - 1 && theCoords.size() > 1 ) {
247 CurveCreator::Coordinates aCoords;
248 for ( int i = 0, aNb = getNbPoints( theISection ); i < aNb; i++ ) {
249 aCoords = getPoint( theISection, i );
250 if ( aCoords.size() < 2 ) {
254 if ( theCoords[0] < aCoords[0] ) {
261 return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt );