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>
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 );
36 HYDROGUI_CurveCreatorProfile::~HYDROGUI_CurveCreatorProfile()
40 bool HYDROGUI_CurveCreatorProfile::moveSectionInternal( const int theISection,
41 const int theNewIndex )
46 bool HYDROGUI_CurveCreatorProfile::moveSection( const int theISection,
47 const int theNewIndex )
52 bool HYDROGUI_CurveCreatorProfile::clearInternal()
54 // erase curve from the viewer
56 myDisplayer->eraseAll( true );
58 // Delete all allocated data.
59 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( 0 );
61 aSection->myPoints.clear();
66 bool HYDROGUI_CurveCreatorProfile::joinInternal( const std::list<int>& theSections )
71 bool HYDROGUI_CurveCreatorProfile::join( const std::list<int>& theSections )
76 int HYDROGUI_CurveCreatorProfile::addSectionInternal( const std::string& theName,
77 const CurveCreator::SectionType theType,
78 const bool theIsClosed,
79 const CurveCreator::Coordinates& thePoints )
84 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
85 const CurveCreator::SectionType theType,
86 const bool theIsClosed )
91 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
92 const CurveCreator::SectionType theType,
93 const bool theIsClosed,
94 const CurveCreator::Coordinates& thePoints )
99 bool HYDROGUI_CurveCreatorProfile::removeSectionInternal( const int theISection )
104 bool HYDROGUI_CurveCreatorProfile::removeSection( const int theISection )
109 bool HYDROGUI_CurveCreatorProfile::setClosedInternal( const int theISection, const bool theIsClosed )
114 bool HYDROGUI_CurveCreatorProfile::setClosed( const int theISection, const bool theIsClosed )
119 bool HYDROGUI_CurveCreatorProfile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
123 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( 0 );
127 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
128 for ( ; anIt != theSectionsMap.end(); anIt++ )
130 int anISection = anIt->first;
131 if( anISection != 0 )
134 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
136 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
137 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
139 const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords;
140 CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin();
141 for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ )
143 const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++;
144 if ( aNewPntIt == aNewCoords.end() )
147 const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt;
149 CurveCreator::TypeCoord aC = aCoordU - 1;
150 if ( !aSection->myPoints.empty() )
151 aC = *(aSection->myPoints.end() - 2);
153 if ( aSection->myPoints.empty() || aCoordU >= aC )
155 aSection->myPoints.push_back( aCoordU );
156 aSection->myPoints.push_back( aCoordZ );
158 else if ( aCoordU < aSection->myPoints.front() )
160 aSection->myPoints.push_front( aCoordZ );
161 aSection->myPoints.push_front( aCoordU );
165 CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin();
166 for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ )
168 const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++;
169 if ( aCoordU < aRefCoordU )
173 aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 );
187 //! For internal use only! Undo/Redo are not used here.
188 bool HYDROGUI_CurveCreatorProfile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
192 if ( mySkipSorting ) {
193 return CurveCreator_Curve::setPointInternal( theSectionsMap );
197 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( anISection );
201 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
202 if ( anIt == theSectionsMap.end() )
205 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
207 std::list<int> aConvPoints;
208 convert( aSectionPoints, aConvPoints );
209 removeSectionPoints( anISection, aConvPoints );
211 aRes = addPointsInternal( theSectionsMap );
218 void HYDROGUI_CurveCreatorProfile::convert( const CurveCreator::PosPointsList& thePoints,
219 std::list<int>& theConvPoints )
221 theConvPoints.clear();
223 CurveCreator::PosPointsList::const_iterator aPntIt = thePoints.begin(),
224 aPntLast = thePoints.end();
225 for( ; aPntIt != aPntLast; aPntIt++ )
227 int anIPnt = (*aPntIt)->myID;
228 theConvPoints.push_back( anIPnt );
232 bool HYDROGUI_CurveCreatorProfile::canPointsBeSorted()
238 * Add one point to the specified section starting from the given theIPnt index
239 * (or at the end of points if \a theIPnt is -1).
241 bool HYDROGUI_CurveCreatorProfile::addPoints( const CurveCreator::Coordinates& theCoords,
242 const int theISection,
245 int anIPnt = theIPnt;
247 if ( anIPnt == - 1 && theCoords.size() > 1 ) {
248 CurveCreator::Coordinates aCoords;
249 for ( int i = 0, aNb = getNbPoints( theISection ); i < aNb; i++ ) {
250 aCoords = getPoint( theISection, i );
251 if ( aCoords.size() < 2 ) {
255 if ( theCoords[0] < aCoords[0] ) {
262 return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt );
265 bool ULess( const gp_Pnt& p1, const gp_Pnt& p2 )
267 return p1.X() < p2.X();
270 Handle(TColgp_HArray1OfPnt) HYDROGUI_CurveCreatorProfile::GetDifferentPoints( int theISection ) const
272 Handle(TColgp_HArray1OfPnt) points = CurveCreator_Curve::GetDifferentPoints( theISection );
273 if( points.IsNull() )
276 QVector<gp_Pnt> vpoints( points->Size() );
277 for( int i=points->Lower(), j=0, n=points->Upper(); i<=n; i++, j++ )
278 vpoints[j] = points->Value( i );
280 qSort( vpoints.begin(), vpoints.end(), ULess );
282 for( int i=points->Lower(), j=0, n=points->Upper(); i<=n; i++, j++ )
283 points->SetValue( i, vpoints[j] );