2 #include "HYDROData_ProfileUZ.h"
4 #include "HYDROData_Tool.h"
8 #include <TColStd_ListIteratorOfListOfReal.hxx>
10 #include <TDataStd_RealList.hxx>
12 #include <TopoDS_Wire.hxx>
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ProfileUZ, HYDROData_IPolyline)
18 HYDROData_ProfileUZ::HYDROData_ProfileUZ()
19 : HYDROData_IPolyline()
23 HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
27 CurveCreator_ICurve::ListAISObjects HYDROData_ProfileUZ::constructWire() const
30 ListAISObjects aProfileObjects;
31 return aProfileObjects;
34 bool HYDROData_ProfileUZ::clear()
40 bool HYDROData_ProfileUZ::join( const int theISectionTo,
41 const int theISectionFrom )
46 int HYDROData_ProfileUZ::getNbSections() const
51 int HYDROData_ProfileUZ::addSection( const std::string& theName,
52 const CurveCreator::SectionType theType,
53 const bool theIsClosed )
58 bool HYDROData_ProfileUZ::removeSection( const int theISection )
63 bool HYDROData_ProfileUZ::isClosed( const int theISection ) const
68 bool HYDROData_ProfileUZ::setClosed( const int theISection,
69 const bool theIsClosed )
74 std::string HYDROData_ProfileUZ::getSectionName( const int theISection ) const
79 bool HYDROData_ProfileUZ::setSectionName( const int theISection,
80 const std::string& theName )
85 CurveCreator::SectionType HYDROData_ProfileUZ::getSectionType( const int theISection ) const
87 return CurveCreator::Polyline;
90 bool HYDROData_ProfileUZ::setSectionType( const int theISection,
91 const CurveCreator::SectionType theType )
96 bool HYDROData_ProfileUZ::addPoints( const CurveCreator::Coordinates& theCoords,
97 const int theISection,
100 bool anIsOperation = myIsOperation;
101 if ( !anIsOperation )
106 int anAfterPnt = theIPnt;
108 CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin();
109 CurveCreator::Coordinates::const_iterator anEndIter = theCoords.end();
110 while ( aBegIter != anEndIter )
112 const CurveCreator::TypeCoord& aCoordX = *aBegIter++;
113 if ( aBegIter == anEndIter )
116 const CurveCreator::TypeCoord& aCoordY = *aBegIter++;
118 aRes = addPoint( aCoordX, aCoordY, theISection, anAfterPnt ) && aRes;
120 if ( anAfterPnt != -1 )
124 if ( !anIsOperation )
130 bool HYDROData_ProfileUZ::addPoint( const CurveCreator::TypeCoord& theCoordX,
131 const CurveCreator::TypeCoord& theCoordY,
132 const int theISection,
135 CurveCreator::TypeCoord aNewCoordU = theCoordX;
136 CurveCreator::TypeCoord aNewCoordZ = theCoordY;
138 Handle(TDataStd_RealList) aListU, aListZ;
139 getPointsLists( 0, aListU, aListZ );
141 if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
143 aListU->Append( aNewCoordU );
144 aListZ->Append( aNewCoordZ );
146 else if ( aNewCoordU < aListU->First() )
148 aListU->Prepend( aNewCoordU );
149 aListZ->Prepend( aNewCoordZ );
153 TColStd_ListOfReal anOldListU;
154 anOldListU = aListU->List();
156 TColStd_ListOfReal anOldListZ;
157 anOldListZ = aListZ->List();
159 // Refill the existing lists
163 bool anIsInserted = false;
164 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
165 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
166 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
168 double aCoordU = anIterU.Value();
169 double aCoordZ = anIterZ.Value();
173 if ( ValuesEquals( aNewCoordU, aCoordU ) )
175 // Just update Z value
176 aCoordZ = aNewCoordZ;
179 else if ( aNewCoordU < aCoordU )
182 aListU->Append( aNewCoordU );
183 aListZ->Append( aNewCoordZ );
188 aListU->Append( aCoordU );
189 aListZ->Append( aCoordZ );
196 bool HYDROData_ProfileUZ::removePoint( const int /*theISection*/,
199 Handle(TDataStd_RealList) aListU, aListZ;
200 getPointsLists( 0, aListU, aListZ, false );
201 if ( aListU.IsNull() || aListZ.IsNull() ||
202 theIPnt < 0 || theIPnt >= aListU->Extent() )
205 bool anIsOperation = myIsOperation;
206 if ( !anIsOperation )
209 TColStd_ListOfReal anOldListU;
210 anOldListU = aListU->List();
212 TColStd_ListOfReal anOldListZ;
213 anOldListZ = aListZ->List();
215 // Refill the existing lists
219 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
220 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
221 for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
224 continue; // skip index to remove
226 aListU->Append( anIterU.Value() );
227 aListZ->Append( anIterZ.Value() );
230 if ( !anIsOperation )
236 //! Remove several points from different sections with given ids
237 bool HYDROData_ProfileUZ::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs)
242 bool HYDROData_ProfileUZ::setPoint( const int /*theISection*/,
244 const CurveCreator::Coordinates& theNewCoords )
246 bool anIsOperation = myIsOperation;
247 if ( !anIsOperation )
250 // At first we remove point
251 removePoint( 0, theIPoint );
253 // And then we insert it to correct place
254 bool aRes = addPoints( theNewCoords, 0 );
256 if ( !anIsOperation )
262 //! Set coordinates of specified points from different sections
263 bool HYDROData_ProfileUZ::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords)
268 CurveCreator::Coordinates HYDROData_ProfileUZ::getPoints( const int /*theISection*/ ) const
270 CurveCreator::Coordinates aResList;
272 Handle(TDataStd_RealList) aListU, aListZ;
273 getPointsLists( 0, aListU, aListZ, false );
274 if ( aListU.IsNull() || aListZ.IsNull() )
277 TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
278 TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
279 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
281 const double& aCoordU = anIterU.Value();
282 const double& aCoordZ = anIterZ.Value();
284 aResList.push_back( aCoordU );
285 aResList.push_back( aCoordZ );