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 "HYDROData_Polyline3D.h"
25 #include "HYDROData_IAltitudeObject.h"
26 #include "HYDROData_Document.h"
27 #include "HYDROData_PolylineXY.h"
28 #include "HYDROData_Profile.h"
29 #include "HYDROData_ProfileUZ.h"
30 #include "HYDROData_Tool.h"
32 #include <gp_Pnt2d.hxx>
37 #include <TopoDS_Wire.hxx>
40 #include <QStringList>
42 IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object)
43 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object)
46 HYDROData_Polyline3D::HYDROData_Polyline3D()
51 HYDROData_Polyline3D::~HYDROData_Polyline3D()
55 QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
57 QStringList aResList = dumpObjectCreation( theTreatedObjects );
58 QString aPolylineName = GetObjPyName();
60 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolylineXY();
61 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" );
63 Handle(HYDROData_ProfileUZ) aRefProfileUZ = GetProfileUZ();
64 if ( !aRefProfileUZ.IsNull() )
66 Handle(HYDROData_Profile) aProfile =
67 Handle(HYDROData_Profile)::DownCast( aRefProfileUZ->GetFatherObject() );
68 if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) )
70 QString aProfileName = aProfile->GetObjPyName();
71 if ( !aProfileName.isEmpty() )
73 aResList << QString( "%1.SetProfileUZ( %2.GetProfileUZ() );" )
74 .arg( aPolylineName ).arg( aProfileName );
80 Handle(HYDROData_IAltitudeObject) aRefBathymetry = GetAltitudeObject();
81 if ( !aRefBathymetry.IsNull() )
83 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
84 if ( !aChildProfileUZ.IsNull() )
86 Handle(HYDROData_Profile) aProfile =
87 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
88 if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) )
90 QString aProfileName = aProfile->GetObjPyName();
91 if ( !aProfileName.isEmpty() )
93 aResList << QString( "%1.SetChildProfileUZ( %2.GetProfileUZ() );" )
94 .arg( aPolylineName ).arg( aProfileName );
99 setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" );
103 aResList << QString( "" );
104 aResList << QString( "%1.Update();" ).arg( aPolylineName );
105 aResList << QString( "" );
110 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
112 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
114 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
115 if ( !aPolylineXY.IsNull() )
116 aResSeq.Append( aPolylineXY );
118 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
119 if ( !aProfileUZ.IsNull() )
120 aResSeq.Append( aProfileUZ );
122 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
123 if ( !aChildProfileUZ.IsNull() )
124 aResSeq.Append( aChildProfileUZ );
129 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
131 return getTopShape();
134 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
139 void HYDROData_Polyline3D::Update()
141 HYDROData_Object::Update();
143 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
144 if ( aPolylineXY.IsNull() )
147 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
148 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
149 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
150 if ( aPolylinePoints.IsEmpty() )
153 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
155 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
156 if ( !anAltitude.IsNull() )
157 aProfileUZ = GetChildProfileUZ();
159 if ( aProfileUZ.IsNull() )
162 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
163 if ( aProfilePoints.IsEmpty() )
166 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
167 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
169 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
170 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
172 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
173 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
175 NCollection_Sequence<Polyline3DPoint> aResPoints;
177 // Add first point as is
178 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
180 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
182 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
184 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
186 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
187 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
189 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
190 aResPoints.Append( aCompPoint );
193 // Add last point as is
194 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
196 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
197 SetTopShape( aResWire );
198 SetShape3D( aResWire );
201 QColor HYDROData_Polyline3D::DefaultFillingColor()
203 return QColor( Qt::transparent );
206 QColor HYDROData_Polyline3D::DefaultBorderColor()
208 return QColor( Qt::red );
211 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
213 return DefaultFillingColor();
216 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
218 return DefaultBorderColor();
221 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
222 const bool theIsUpdateProfile )
224 if ( thePolyline.IsNull() )
227 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
228 if ( IsEqual( aPrevPolyline, thePolyline ) )
231 SetReferenceObject( thePolyline, DataTag_PolylineXY );
233 // Update the child profile object
234 if ( theIsUpdateProfile )
235 updateChildProfilePoints();
237 // Indicate model of the need to update the polyline presentation
243 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
245 return Handle(HYDROData_PolylineXY)::DownCast(
246 GetReferenceObject( DataTag_PolylineXY ) );
249 void HYDROData_Polyline3D::RemovePolylineXY()
251 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
252 if ( aPrevPolyline.IsNull() )
255 ClearReferenceObjects( DataTag_PolylineXY );
257 // Indicate model of the need to update the polyline presentation
261 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
263 if ( theProfile.IsNull() )
266 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
267 if ( IsEqual( aPrevProfile, theProfile ) )
270 SetReferenceObject( theProfile, DataTag_ProfileUZ );
272 // Remove the bathymetry, because one altitude object can be presented at time
273 RemoveAltitudeObject();
275 // Indicate model of the need to update the polyline presentation
281 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
283 return Handle(HYDROData_ProfileUZ)::DownCast(
284 GetReferenceObject( DataTag_ProfileUZ ) );
287 void HYDROData_Polyline3D::RemoveProfileUZ()
289 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
290 if ( aPrevProfile.IsNull() )
293 ClearReferenceObjects( DataTag_ProfileUZ );
295 // Indicate model of the need to update the polyline presentation
299 bool HYDROData_Polyline3D::SetAltitudeObject(
300 const Handle(HYDROData_IAltitudeObject)& theAltitude )
302 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
304 if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
307 if ( IsEqual( aPrevAltitude, theAltitude ) )
310 // Remove the u,z profile, because one altitude object can be presented at time
313 // Create the child profile object
314 updateChildProfilePoints();
320 void HYDROData_Polyline3D::RemoveAltitudeObject()
322 HYDROData_Object::RemoveAltitudeObject();
324 // Remove the child profile object
325 removeChildProfileUZ();
328 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
330 Handle(HYDROData_ProfileUZ) aProfileUZ =
331 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
332 if ( !theIsCreate || !aProfileUZ.IsNull() )
335 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
336 if ( aDocument.IsNull() )
339 Handle(HYDROData_Profile) aProfile =
340 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
342 QString aProfilePref = GetName() + "_Profile";
343 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
345 aProfile->SetName( aProfileName );
347 aProfileUZ = aProfile->GetProfileUZ();
349 HYDROData_Polyline3D* me = const_cast<HYDROData_Polyline3D*>( this ); // Temporary to be revised
350 me->SetChildProfileUZ( aProfileUZ );
355 void HYDROData_Polyline3D::SetChildProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
357 SetReferenceObject( theProfile, DataTag_ChildProfileUZ );
360 HYDROData_IPolyline::PointsList generateProfileUZPoints(
361 const Handle(HYDROData_PolylineXY)& thePolyline,
362 const Handle(HYDROData_IAltitudeObject)& theAltitude )
364 HYDROData_IPolyline::PointsList aPointsList;
365 if ( thePolyline.IsNull() || theAltitude.IsNull() )
368 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
369 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
370 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
371 if ( aPolylinePoints.IsEmpty() )
374 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
376 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
378 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
379 double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
380 if( aPointDepth == theAltitude->GetInvalidAltitude() )
383 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
384 aPointsList.Append( anAltitudePoint );
390 void HYDROData_Polyline3D::updateChildProfilePoints()
392 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
393 if ( anAltitude.IsNull() )
396 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
397 if ( aChildProfileUZ.IsNull() )
400 Handle(HYDROData_Profile) aProfile =
401 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
402 if ( aProfile.IsNull() )
405 HYDROData_IPolyline::PointsList aProfilePoints =
406 generateProfileUZPoints( GetPolylineXY(), anAltitude );
407 aProfile->SetParametricPoints( aProfilePoints );
412 void HYDROData_Polyline3D::removeChildProfileUZ()
414 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
415 if ( aChildProfileUZ.IsNull() )
418 ClearReferenceObjects( DataTag_ChildProfileUZ );
420 /* Uncomment if removing is requested
421 Handle(HYDROData_Profile) aProfile =
422 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
423 if ( !aProfile.IsNull() )