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 #include <TopoDS_Shape.hxx>
24 #include <CurveCreator_Utils.hxx>
25 #include <AIS_Shape.hxx>
26 #include <Prs3d_PointAspect.hxx>
28 HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile()
29 : CurveCreator_Curve( CurveCreator::Dim2d )
31 CurveCreator_Section *aSection = new CurveCreator_Section;
32 aSection->myName = getUniqSectionName();
33 aSection->myType = CurveCreator::Polyline;
34 aSection->myIsClosed = false;
35 myCurveColor = Quantity_NOC_RED;
37 mySections.push_back( aSection );
41 HYDROGUI_CurveCreatorProfile::~HYDROGUI_CurveCreatorProfile()
45 bool HYDROGUI_CurveCreatorProfile::moveSectionInternal( const int theISection,
46 const int theNewIndex )
51 bool HYDROGUI_CurveCreatorProfile::moveSection( const int theISection,
52 const int theNewIndex )
57 bool HYDROGUI_CurveCreatorProfile::clearInternal()
59 // erase curve from the viewer
61 myDisplayer->eraseAll( true );
63 // Delete all allocated data.
64 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( 0 );
66 aSection->myPoints.clear();
71 bool HYDROGUI_CurveCreatorProfile::joinInternal( const std::list<int>& theSections )
76 bool HYDROGUI_CurveCreatorProfile::join( const std::list<int>& theSections )
81 int HYDROGUI_CurveCreatorProfile::addSectionInternal( const std::string& theName,
82 const CurveCreator::SectionType theType,
83 const bool theIsClosed,
84 const CurveCreator::Coordinates& thePoints )
89 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
90 const CurveCreator::SectionType theType,
91 const bool theIsClosed )
96 int HYDROGUI_CurveCreatorProfile::addSection( const std::string& theName,
97 const CurveCreator::SectionType theType,
98 const bool theIsClosed,
99 const CurveCreator::Coordinates& thePoints )
104 bool HYDROGUI_CurveCreatorProfile::removeSectionInternal( const int theISection )
109 bool HYDROGUI_CurveCreatorProfile::removeSection( const int theISection )
114 bool HYDROGUI_CurveCreatorProfile::setClosedInternal( const int theISection, const bool theIsClosed )
119 bool HYDROGUI_CurveCreatorProfile::setClosed( const int theISection, const bool theIsClosed )
124 bool HYDROGUI_CurveCreatorProfile::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
128 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( 0 );
132 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
133 for ( ; anIt != theSectionsMap.end(); anIt++ )
135 int anISection = anIt->first;
136 if( anISection != 0 )
139 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
141 CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
142 for( ; aPntIt != aSectionPoints.end(); aPntIt++ )
144 const CurveCreator::Coordinates& aNewCoords = (*aPntIt)->myCoords;
145 CurveCreator::Coordinates::const_iterator aNewPntIt = aNewCoords.begin();
146 for( ; aNewPntIt != aNewCoords.end(); aNewPntIt++ )
148 const CurveCreator::TypeCoord& aCoordU = *aNewPntIt++;
149 if ( aNewPntIt == aNewCoords.end() )
152 const CurveCreator::TypeCoord& aCoordZ = *aNewPntIt;
154 CurveCreator::TypeCoord aC = aCoordU - 1;
155 if ( !aSection->myPoints.empty() )
156 aC = *(aSection->myPoints.end() - 2);
158 if ( aSection->myPoints.empty() || aCoordU >= aC )
160 aSection->myPoints.push_back( aCoordU );
161 aSection->myPoints.push_back( aCoordZ );
163 else if ( aCoordU < aSection->myPoints.front() )
165 aSection->myPoints.push_front( aCoordZ );
166 aSection->myPoints.push_front( aCoordU );
170 CurveCreator::Coordinates::iterator aRefPntIt = aSection->myPoints.begin();
171 for( ; aRefPntIt != aSection->myPoints.end(); aRefPntIt++ )
173 const CurveCreator::TypeCoord& aRefCoordU = *aRefPntIt++;
174 if ( aCoordU < aRefCoordU )
178 aSection->myPoints.insert( aRefPntIt - 1, aNewPntIt - 1, aNewPntIt + 1 );
187 redisplayCurve(false);
192 //! For internal use only! Undo/Redo are not used here.
193 bool HYDROGUI_CurveCreatorProfile::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
197 if ( mySkipSorting ) {
198 return CurveCreator_Curve::setPointInternal( theSectionsMap );
202 CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( anISection );
206 CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
207 if ( anIt == theSectionsMap.end() )
210 const CurveCreator::PosPointsList& aSectionPoints = anIt->second;
212 std::list<int> aConvPoints;
213 convert( aSectionPoints, aConvPoints );
214 removeSectionPoints( anISection, aConvPoints );
216 aRes = addPointsInternal( theSectionsMap );
218 redisplayCurve(false);
223 void HYDROGUI_CurveCreatorProfile::convert( const CurveCreator::PosPointsList& thePoints,
224 std::list<int>& theConvPoints )
226 theConvPoints.clear();
228 CurveCreator::PosPointsList::const_iterator aPntIt = thePoints.begin(),
229 aPntLast = thePoints.end();
230 for( ; aPntIt != aPntLast; aPntIt++ )
232 int anIPnt = (*aPntIt)->myID;
233 theConvPoints.push_back( anIPnt );
237 bool HYDROGUI_CurveCreatorProfile::canPointsBeSorted()
243 * Add one point to the specified section starting from the given theIPnt index
244 * (or at the end of points if \a theIPnt is -1).
246 bool HYDROGUI_CurveCreatorProfile::addPoints( const CurveCreator::Coordinates& theCoords,
247 const int theISection,
250 int anIPnt = theIPnt;
252 if ( anIPnt == - 1 && theCoords.size() > 1 ) {
253 CurveCreator::Coordinates aCoords;
254 for ( int i = 0, aNb = getNbPoints( theISection ); i < aNb; i++ ) {
255 aCoords = getPoint( theISection, i );
256 if ( aCoords.size() < 2 ) {
260 if ( theCoords[0] < aCoords[0] ) {
267 return CurveCreator_Curve::addPoints( theCoords, theISection, anIPnt );
270 bool ULess( const gp_Pnt& p1, const gp_Pnt& p2 )
272 return p1.X() < p2.X();
275 Handle(TColgp_HArray1OfPnt) HYDROGUI_CurveCreatorProfile::GetDifferentPoints( int theISection ) const
277 Handle(TColgp_HArray1OfPnt) points = CurveCreator_Curve::GetDifferentPoints( theISection );
278 if( points.IsNull() )
281 QVector<gp_Pnt> vpoints( points->Size() );
282 for( int i=points->Lower(), j=0, n=points->Upper(); i<=n; i++, j++ )
283 vpoints[j] = points->Value( i );
285 qSort( vpoints.begin(), vpoints.end(), ULess );
287 for( int i=points->Lower(), j=0, n=points->Upper(); i<=n; i++, j++ )
288 points->SetValue( i, vpoints[j] );
293 void HYDROGUI_CurveCreatorProfile::constructAISObject()
296 CurveCreator_Utils::constructShape( this, aShape );
297 myAISShape = new AIS_Shape( aShape );
298 myAISShape->SetColor( myCurveColor );
299 myAISShape->SetWidth( myLineWidth );
300 Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect();
301 anAspect->SetScale( 3.0 );
302 anAspect->SetTypeOfMarker(Aspect_TOM_O_POINT);
303 anAspect->SetColor(myPointAspectColor);
304 myAISShape->Attributes()->SetPointAspect( anAspect );