2 #include "HYDROData_ProfileUZ.h"
4 #include "HYDROData_Tool.h"
7 #include <gp_Pnt2d.hxx>
9 #include <TColStd_ListIteratorOfListOfReal.hxx>
11 #include <TDataStd_BooleanList.hxx>
12 #include <TDataStd_ExtStringList.hxx>
13 #include <TDataStd_IntegerList.hxx>
14 #include <TDataStd_RealList.hxx>
16 #include <TopoDS_Shape.hxx>
19 IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline)
20 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ProfileUZ, HYDROData_IPolyline)
22 HYDROData_ProfileUZ::HYDROData_ProfileUZ()
23 : HYDROData_IPolyline()
27 HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
31 QStringList HYDROData_ProfileUZ::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
33 QStringList aResList = dumpObjectCreation( theTreatedObjects );
34 QString aName = GetObjPyName();
37 const TCollection_AsciiString& aSectName = GetSectionName( 0 );
38 const SectionType& aSectType = GetSectionType( 0 );
39 bool aSectClosure = IsClosedSection( 0 );
41 aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aName )
42 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
44 HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( 0 );
45 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
47 const Point& aSectPoint = aSectPointsList.Value( k );
49 aResList << QString( "%1.AddPoint( 0, gp_XY( %2, %3 ) );" ).arg( aName )
50 .arg( aSectPoint.X() ).arg( aSectPoint.Y() );
53 aResList << QString( "" );
54 aResList << QString( "%1.Update();" ).arg( aName );
55 aResList << QString( "" );
60 TopoDS_Shape HYDROData_ProfileUZ::GetShape() const
63 return TopoDS_Shape();
66 double HYDROData_ProfileUZ::GetDepthFromDistance( const PointsList& thePoints,
67 const double& theDistance )
69 double aResDepth = 0.0;
71 int aNbPoints = thePoints.Size();
75 double aCompDist = 0.0;
76 HYDROData_IPolyline::Point aPrevPoint = thePoints.First();
77 for ( int i = 2; i <= aNbPoints; ++i )
79 const Point& aCurPoint = thePoints.Value( i );
81 double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) );
83 aCompDist += aPntDist;
85 if ( theDistance < aCompDist )
87 double aComPntDist = gp_Pnt2d( thePoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) );
89 double aFindDist = theDistance - aComPntDist;
90 double aRatio = aFindDist / ( aPntDist - aFindDist );
92 aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio );
96 aPrevPoint = aCurPoint;
102 int HYDROData_ProfileUZ::NbSections() const
107 void HYDROData_ProfileUZ::AddSection( const TCollection_AsciiString& /*theSectName*/,
108 const SectionType /*theSectionType*/,
109 const bool /*theIsClosed*/ )
113 TCollection_AsciiString HYDROData_ProfileUZ::GetSectionName( const int /*theSectionIndex*/ ) const
118 void HYDROData_ProfileUZ::SetSectionName( const int /*theSectionIndex*/,
119 const TCollection_AsciiString& /*theSectionName*/ )
123 HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const
125 Handle(TDataStd_ExtStringList) aNamesList;
126 Handle(TDataStd_IntegerList) aTypesList;
127 Handle(TDataStd_BooleanList) aClosuresList;
128 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
129 if ( aTypesList.IsNull() || aTypesList->IsEmpty() )
130 return SECTION_POLYLINE;
132 return (SectionType)aTypesList->First();
135 void HYDROData_ProfileUZ::SetSectionType( const int /*theSectionIndex*/,
136 const SectionType theSectionType )
138 Handle(TDataStd_ExtStringList) aNamesList;
139 Handle(TDataStd_IntegerList) aTypesList;
140 Handle(TDataStd_BooleanList) aClosuresList;
141 getSectionsLists( aNamesList, aTypesList, aClosuresList );
142 if ( aTypesList.IsNull() )
145 // Refill the existing list
147 aTypesList->Append( theSectionType );
150 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
155 void HYDROData_ProfileUZ::SetSectionClosed( const int /*theSectionIndex*/,
156 const bool /*theIsClosed*/ )
160 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
165 void HYDROData_ProfileUZ::RemoveSections()
167 removePointsLists( 0 );
170 void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/,
171 const Point& thePoint,
172 const int thePointIndex )
174 double aNewCoordU = thePoint.X();
175 double aNewCoordZ = thePoint.Y();
177 Handle(TDataStd_RealList) aListU, aListZ;
178 getPointsLists( 0, aListU, aListZ );
180 if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
182 aListU->Append( aNewCoordU );
183 aListZ->Append( aNewCoordZ );
186 else if ( aNewCoordU < aListU->First() )
188 aListU->Prepend( aNewCoordU );
189 aListZ->Prepend( aNewCoordZ );
193 TColStd_ListOfReal anOldListU;
194 anOldListU = aListU->List();
196 TColStd_ListOfReal anOldListZ;
197 anOldListZ = aListZ->List();
200 removePointsLists( 0 );
201 getPointsLists( 0, aListU, aListZ );
203 bool anIsInserted = false;
204 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
205 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
206 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
208 double aCoordU = anIterU.Value();
209 double aCoordZ = anIterZ.Value();
213 if ( ValuesEquals( aNewCoordU, aCoordU ) )
215 // Just update Z value
216 aCoordZ = aNewCoordZ;
219 else if ( aNewCoordU < aCoordU )
222 aListU->Append( aNewCoordU );
223 aListZ->Append( aNewCoordZ );
228 aListU->Append( aCoordU );
229 aListZ->Append( aCoordZ );
233 void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex,
234 const Point& thePoint,
235 const int /*thePointIndex*/ )
237 AddPoint( theSectionIndex, thePoint );
240 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
241 const int thePointIndex )
243 Handle(TDataStd_RealList) aListU, aListZ;
244 getPointsLists( 0, aListU, aListZ, false );
245 if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
248 TColStd_ListOfReal anOldListU;
249 anOldListU = aListU->List();
251 TColStd_ListOfReal anOldListZ;
252 anOldListZ = aListZ->List();
255 removePointsLists( 0 );
256 getPointsLists( 0, aListU, aListZ );
258 bool anIsInserted = false;
259 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
260 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
261 for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
263 if ( i == thePointIndex )
264 continue; // skip index to remove
266 aListU->Append( anIterU.Value() );
267 aListZ->Append( anIterZ.Value() );
271 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
275 Handle(TDataStd_RealList) aListU, aListZ;
276 getPointsLists( 0, aListU, aListZ, false );
277 if ( aListU.IsNull() || aListZ.IsNull() )
280 TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
281 TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
282 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
284 Point aPoint( anIterU.Value(), anIterZ.Value() );
285 aResList.Append( aPoint );