1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_CurveCreatorProfile.h>
20 #include <CurveCreator_Displayer.hxx>
21 #include <CurveCreator_Section.hxx>
23 HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile()
24 : CurveCreator_Curve( CurveCreator::Dim2d )
26 CurveCreator_Section *aSection = new CurveCreator_Section;
27 aSection->myName = getUniqSectionName();
28 aSection->myType = CurveCreator::Polyline;
29 aSection->myIsClosed = false;
31 mySections.push_back( aSection );
34 HYDROGUI_CurveCreatorProfile::~HYDROGUI_CurveCreatorProfile()
38 bool HYDROGUI_CurveCreatorProfile::moveSectionInternal( const int theISection,
39 const int theNewIndex )
44 bool HYDROGUI_CurveCreatorProfile::moveSection( const int theISection,
45 const int theNewIndex )
50 bool HYDROGUI_CurveCreatorProfile::clearInternal()
52 // erase curve from the viewer
54 myDisplayer->eraseAll( true );
56 // Delete all allocated data.
57 CurveCreator_Section* aSection = getSection( 0 );
59 aSection->myPoints.clear();
64 bool HYDROGUI_CurveCreatorProfile::joinInternal( const std::list<int>& theSections )
69 bool HYDROGUI_CurveCreatorProfile::join( const std::list<int>& theSections )
74 int HYDROGUI_CurveCreatorProfile::addSectionInternal( const std::string& theName,
75 const CurveCreator::SectionType theType,
76 const bool theIsClosed,
77 const CurveCreator::Coordinates& thePoints )
82 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
83 const CurveCreator::SectionType theType,
84 const bool theIsClosed )
89 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
90 const CurveCreator::SectionType theType,
91 const bool theIsClosed,
92 const CurveCreator::Coordinates& thePoints )
97 bool HYDROGUI_CurveCreatorProfile::removeSectionInternal( const int theISection )
102 bool HYDROGUI_CurveCreatorProfile::removeSection( const int theISection )
107 bool HYDROGUI_CurveCreatorProfile::setClosedInternal( const int theISection, const bool theIsClosed )
112 bool HYDROGUI_CurveCreatorProfile::setClosed( const int theISection, const bool theIsClosed )
117 bool HYDROGUI_CurveCreatorProfile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
121 CurveCreator_Section* aSection = getSection( 0 );
125 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
126 for ( ; anIt != theSectionsMap.end(); anIt++ )
128 int anISection = anIt->first;
129 if( anISection != 0 )
132 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
134 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
135 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
137 const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords;
138 CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin();
139 for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ )
141 const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++;
142 if ( aNewPntIt == aNewCoords.end() )
145 const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt;
147 CurveCreator::TypeCoord aC = aCoordU - 1;
148 if ( !aSection->myPoints.empty() )
149 aC = *(aSection->myPoints.end() - 2);
151 if ( aSection->myPoints.empty() || aCoordU >= aC )
153 aSection->myPoints.push_back( aCoordU );
154 aSection->myPoints.push_back( aCoordZ );
156 else if ( aCoordU < aSection->myPoints.front() )
158 aSection->myPoints.push_front( aCoordZ );
159 aSection->myPoints.push_front( aCoordU );
163 CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin();
164 for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ )
166 const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++;
167 if ( aCoordU < aRefCoordU )
171 aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 );
185 //! For internal use only! Undo/Redo are not used here.
186 bool HYDROGUI_CurveCreatorProfile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
190 if ( mySkipSorting ) {
191 return CurveCreator_Curve::setPointInternal( theSectionsMap );
195 CurveCreator_Section* aSection = getSection( anISection );
199 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
200 if ( anIt == theSectionsMap.end() )
203 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
205 std::list<int> aConvPoints;
206 convert( aSectionPoints, aConvPoints );
207 removeSectionPoints( anISection, aConvPoints );
209 aRes = addPointsInternal( theSectionsMap );
216 void HYDROGUI_CurveCreatorProfile::convert( const CurveCreator::PosPointsList& thePoints,
217 std::list<int>& theConvPoints )
219 theConvPoints.clear();
221 CurveCreator::PosPointsList::const_iterator aPntIt = thePoints.begin(),
222 aPntLast = thePoints.end();
223 for( ; aPntIt != aPntLast; aPntIt++ )
225 int anIPnt = (*aPntIt)->myID;
226 theConvPoints.push_back( anIPnt );
230 bool HYDROGUI_CurveCreatorProfile::canPointsBeSorted()
236 * Add one point to the specified section starting from the given theIPnt index
237 * (or at the end of points if \a theIPnt is -1).
239 bool HYDROGUI_CurveCreatorProfile::addPoints( const CurveCreator::Coordinates& theCoords,
240 const int theISection,
243 int anIPnt = theIPnt;
245 if ( anIPnt == - 1 && theCoords.size() > 1 ) {
246 CurveCreator::Coordinates aCoords;
247 for ( int i = 0, aNb = getNbPoints( theISection ); i < aNb; i++ ) {
248 aCoords = getPoint( theISection, i );
249 if ( aCoords.size() < 2 ) {
253 if ( theCoords[0] < aCoords[0] ) {
260 return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt );