2 #include "HYDROData_PolylineXY.h"
4 #include "HYDROData_Tool.h"
6 #include <NCollection_Map.hxx>
8 #include <TCollection_ExtendedString.hxx>
10 #include <TDataStd_ListIteratorOfListOfByte.hxx>
11 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
12 #include <TColStd_ListIteratorOfListOfInteger.hxx>
13 #include <TColStd_ListIteratorOfListOfReal.hxx>
15 #include <TDataStd_BooleanList.hxx>
16 #include <TDataStd_ExtStringList.hxx>
17 #include <TDataStd_Integer.hxx>
18 #include <TDataStd_IntegerList.hxx>
19 #include <TDataStd_RealList.hxx>
21 #include <TopoDS_Wire.hxx>
24 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
25 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
27 HYDROData_PolylineXY::HYDROData_PolylineXY()
28 : HYDROData_IPolyline()
32 HYDROData_PolylineXY::~HYDROData_PolylineXY()
36 CurveCreator_ICurve::ListAISObjects HYDROData_PolylineXY::constructWire() const
39 ListAISObjects aProfileObjects;
40 return aProfileObjects;
43 bool HYDROData_PolylineXY::clear()
45 bool anIsOperation = myIsOperation;
49 removeSectionsLists();
58 bool HYDROData_PolylineXY::join( const int theISectionTo,
59 const int theISectionFrom )
61 Handle(TDataStd_ExtStringList) aNamesList;
62 Handle(TDataStd_IntegerList) aTypesList;
63 Handle(TDataStd_BooleanList) aClosuresList;
64 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
65 if ( aNamesList.IsNull() || aNamesList->Extent() <= 1 )
68 bool anIsOperation = myIsOperation;
70 if ( theISectionTo == -1 || theISectionFrom == -1 )
72 // Join all sections to one
76 TCollection_ExtendedString aSectName = aNamesList->First();
77 CurveCreator::SectionType aSectType = (CurveCreator::SectionType)aTypesList->First();
78 bool anIsClosed = aClosuresList->First();
82 aClosuresList->Clear();
84 aNamesList->Append( aSectName );
85 aTypesList->Append( aSectType );
86 aClosuresList->Append( anIsClosed );
88 CurveCreator::Coordinates anAllPoints = getPoints();
91 addPoints( anAllPoints, 0 );
95 // Join selected range of sections to one
96 if ( theISectionFrom >= theISectionTo )
102 TDataStd_ListOfExtendedString anOldNamesList;
103 anOldNamesList = aNamesList->List();
105 TColStd_ListOfInteger anOldTypesList;
106 anOldTypesList = aTypesList->List();
108 TDataStd_ListOfByte anOldClosuresList;
109 anOldClosuresList = aClosuresList->List();
111 // Refill the existing lists
114 aClosuresList->Clear();
116 Handle(TDataStd_RealList) aJoinListX, aJoinListY;
118 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
119 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
120 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
123 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
124 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++aNbSect )
126 if ( aNbSect < theISectionFrom || aNbSect > theISectionTo )
128 aNamesList->Append( aNamesIter.Value() );
129 aTypesList->Append( aTypesIter.Value() );
130 aClosuresList->Append( (bool)aClosuresIter.Value() );
134 if ( aNbSect == theISectionFrom )
136 aNamesList->Append( aNamesIter.Value() );
137 aTypesList->Append( aTypesIter.Value() );
138 aClosuresList->Append( (bool)aClosuresIter.Value() );
140 getPointsLists( aNbSect, aJoinListX, aJoinListY );
144 Handle(TDataStd_RealList) aListX, aListY;
145 getPointsLists( aNbSect, aListX, aListY );
147 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
148 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
149 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
151 aJoinListX->Append( anIterX.Value() );
152 aJoinListY->Append( anIterY.Value() );
155 removePointsLists( aNbSect );
159 // Move the list which are after theISectionTo to correct place
160 for ( int i = theISectionTo + 1, j = theISectionFrom + 1; i < aNbSect; ++i, j++ )
162 CurveCreator::Coordinates aPoints = getPoints( i );
163 removePointsLists( i );
164 addPoints( aPoints, j );
169 if ( !anIsOperation )
175 int HYDROData_PolylineXY::getNbSections() const
177 Handle(TDataStd_ExtStringList) aNamesList;
178 Handle(TDataStd_IntegerList) aTypesList;
179 Handle(TDataStd_BooleanList) aClosuresList;
180 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
182 return aNamesList.IsNull() ? 0 : aNamesList->Extent();
185 TCollection_ExtendedString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
187 NCollection_Map<TCollection_ExtendedString> aNamesMap;
189 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
190 for ( ; aNamesIter.More(); aNamesIter.Next() )
191 aNamesMap.Add( aNamesIter.Value() );
193 TCollection_ExtendedString aResName;
198 aResName = "Section_" + aPrefIdx;
201 while ( aNamesMap.Contains( aResName ) );
206 int HYDROData_PolylineXY::addSection( const std::string& theName,
207 const CurveCreator::SectionType theType,
208 const bool theIsClosed )
210 bool anIsOperation = myIsOperation;
211 if ( !anIsOperation )
214 Handle(TDataStd_ExtStringList) aNamesList;
215 Handle(TDataStd_IntegerList) aTypesList;
216 Handle(TDataStd_BooleanList) aClosuresList;
217 getSectionsLists( aNamesList, aTypesList, aClosuresList );
219 TCollection_ExtendedString aSectName = theName.c_str();
220 if ( aSectName.Length() <= 0 )
221 aSectName = getUniqueSectionName( aNamesList );
223 aNamesList->Append( aSectName );
224 aTypesList->Append( theType );
225 aClosuresList->Append( theIsClosed );
227 int aSectId = aNamesList->Extent() - 1;
229 // Just to create empty data
230 Handle(TDataStd_RealList) aListX, aListY;
231 getPointsLists( aSectId, aListX, aListY );
233 if ( !anIsOperation )
239 bool HYDROData_PolylineXY::removeSection( const int theISection )
241 Handle(TDataStd_ExtStringList) aNamesList;
242 Handle(TDataStd_IntegerList) aTypesList;
243 Handle(TDataStd_BooleanList) aClosuresList;
244 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
245 if ( aNamesList.IsNull() || aNamesList->IsEmpty() )
248 bool anIsOperation = myIsOperation;
249 if ( !anIsOperation )
252 if ( aNamesList->Extent() == 1 )
254 removeSectionsLists();
259 TDataStd_ListOfExtendedString anOldNamesList;
260 anOldNamesList = aNamesList->List();
262 TColStd_ListOfInteger anOldTypesList;
263 anOldTypesList = aTypesList->List();
265 TDataStd_ListOfByte anOldClosuresList;
266 anOldClosuresList = aClosuresList->List();
268 // Refill the existing lists
271 aClosuresList->Clear();
273 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
274 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
275 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
276 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
277 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
279 if ( i == theISection )
280 continue; // skip index to remove
282 aNamesList->Append( aNamesIter.Value() );
283 aTypesList->Append( aTypesIter.Value() );
284 aClosuresList->Append( (bool)aClosuresIter.Value() );
287 // Remove points that belong to removed section
288 removePointsLists( theISection );
291 if ( !anIsOperation )
297 bool HYDROData_PolylineXY::isClosed( const int theISection ) const
299 Handle(TDataStd_ExtStringList) aNamesList;
300 Handle(TDataStd_IntegerList) aTypesList;
301 Handle(TDataStd_BooleanList) aClosuresList;
302 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
303 if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() )
306 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
307 for ( int i = 0; aClosuresIter.More() && i != theISection; aClosuresIter.Next(), ++i );
309 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
312 bool HYDROData_PolylineXY::setClosed( const int theISection,
313 const bool theIsClosed )
315 Handle(TDataStd_ExtStringList) aNamesList;
316 Handle(TDataStd_IntegerList) aTypesList;
317 Handle(TDataStd_BooleanList) aClosuresList;
318 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
319 if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() )
322 bool anIsOperation = myIsOperation;
323 if ( !anIsOperation )
326 TDataStd_ListOfByte anOldClosuresList;
327 anOldClosuresList = aClosuresList->List();
329 // Refill the existing list
330 aClosuresList->Clear();
332 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
333 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
334 aClosuresList->Append( i == theISection ? theIsClosed : (bool)aClosuresIter.Value() );
336 if ( !anIsOperation )
342 std::string HYDROData_PolylineXY::getSectionName( const int theISection ) const
344 Handle(TDataStd_ExtStringList) aNamesList;
345 Handle(TDataStd_IntegerList) aTypesList;
346 Handle(TDataStd_BooleanList) aClosuresList;
347 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
348 if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() )
351 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
352 for ( int i = 0; aNamesIter.More() && i != theISection; aNamesIter.Next(), ++i );
354 TCollection_AsciiString aResName;
355 if ( aNamesIter.More() )
356 aResName = aNamesIter.Value();
358 return aResName.ToCString();
361 bool HYDROData_PolylineXY::setSectionName( const int theISection,
362 const std::string& theName )
364 Handle(TDataStd_ExtStringList) aNamesList;
365 Handle(TDataStd_IntegerList) aTypesList;
366 Handle(TDataStd_BooleanList) aClosuresList;
367 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
368 if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() )
371 bool anIsOperation = myIsOperation;
372 if ( !anIsOperation )
375 TDataStd_ListOfExtendedString anOldNamesList;
376 anOldNamesList = aNamesList->List();
378 // Refill the existing list
381 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
382 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
383 aNamesList->Append( i == theISection ? theName.c_str() : aNamesIter.Value() );
385 if ( !anIsOperation )
391 CurveCreator::SectionType HYDROData_PolylineXY::getSectionType( const int theISection ) const
393 Handle(TDataStd_ExtStringList) aNamesList;
394 Handle(TDataStd_IntegerList) aTypesList;
395 Handle(TDataStd_BooleanList) aClosuresList;
396 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
397 if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() )
398 return CurveCreator::Polyline;
400 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
401 for ( int i = 0; aTypesIter.More() && i != theISection; aTypesIter.Next(), ++i );
403 return aTypesIter.More() ? (CurveCreator::SectionType)aTypesIter.Value() : CurveCreator::Polyline;
406 bool HYDROData_PolylineXY::setSectionType( const int theISection,
407 const CurveCreator::SectionType theType )
409 Handle(TDataStd_ExtStringList) aNamesList;
410 Handle(TDataStd_IntegerList) aTypesList;
411 Handle(TDataStd_BooleanList) aClosuresList;
412 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
413 if ( aNamesList.IsNull() || theISection >= aNamesList->Extent() )
416 bool anIsOperation = myIsOperation;
417 if ( !anIsOperation )
420 TColStd_ListOfInteger anOldTypesList;
421 anOldTypesList = aTypesList->List();
423 // Refill the existing list
426 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
427 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
428 aTypesList->Append( i == theISection ? theType : aTypesIter.Value() );
430 if ( !anIsOperation )
436 void addPointsToLists( const CurveCreator::Coordinates& theCoords,
437 Handle(TDataStd_RealList)& theListX,
438 Handle(TDataStd_RealList)& theListY,
439 const bool theIsAppend )
441 CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin();
442 CurveCreator::Coordinates::const_iterator anEndIter = theCoords.end();
443 while ( aBegIter != anEndIter )
445 const CurveCreator::TypeCoord& aCoordX = *aBegIter++;
446 if ( aBegIter == anEndIter )
449 const CurveCreator::TypeCoord& aCoordY = *aBegIter++;
453 theListX->Append( aCoordX );
454 theListY->Append( aCoordY );
458 theListX->Prepend( aCoordX );
459 theListY->Prepend( aCoordY );
464 bool HYDROData_PolylineXY::addPoints( const CurveCreator::Coordinates& theCoords,
465 const int theISection,
468 bool anIsOperation = myIsOperation;
469 if ( !anIsOperation )
472 Handle(TDataStd_RealList) aListX, aListY;
473 getPointsLists( theISection, aListX, aListY );
475 if ( theIPnt < 0 || theIPnt >= aListX->Extent() )
477 addPointsToLists( theCoords, aListX, aListY, true );
481 TColStd_ListOfReal anOldListX;
482 anOldListX = aListX->List();
484 TColStd_ListOfReal anOldListY;
485 anOldListY = aListY->List();
487 // Refill the existing lists
491 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
492 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
493 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
495 double aCoordX = anIterX.Value();
496 double aCoordY = anIterY.Value();
500 // Insert our new points
501 addPointsToLists( theCoords, aListX, aListY, true );
504 aListX->Append( aCoordX );
505 aListY->Append( aCoordY );
509 if ( !anIsOperation )
515 bool HYDROData_PolylineXY::setPoint( const int theISection,
517 const CurveCreator::Coordinates& theCoords )
519 if ( theCoords.size() < 2 )
522 bool anIsOperation = myIsOperation;
523 if ( !anIsOperation )
526 Handle(TDataStd_RealList) aListX, aListY;
527 getPointsLists( theISection, aListX, aListY );
531 addPointsToLists( theCoords, aListX, aListY, false );
533 else if ( theIPnt >= aListX->Extent() )
535 addPointsToLists( theCoords, aListX, aListY, true );
539 CurveCreator::Coordinates::const_iterator aBegIter = theCoords.begin();
540 const CurveCreator::TypeCoord& aNewCoordX = *aBegIter++;
541 const CurveCreator::TypeCoord& aNewCoordY = *aBegIter++;
543 TColStd_ListOfReal anOldListX;
544 anOldListX = aListX->List();
546 TColStd_ListOfReal anOldListY;
547 anOldListY = aListY->List();
549 // Refill the existing lists
553 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
554 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
555 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
557 double aCoordX = anIterX.Value();
558 double aCoordY = anIterY.Value();
562 // Insert our new points instead of old one
563 aCoordX = aNewCoordX;
564 aCoordY = aNewCoordY;
567 aListX->Append( aCoordX );
568 aListY->Append( aCoordY );
572 if ( !anIsOperation )
578 bool HYDROData_PolylineXY::removePoint( const int theISection,
581 Handle(TDataStd_RealList) aListX, aListY;
582 getPointsLists( theISection, aListX, aListY, false );
583 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
586 bool anIsOperation = myIsOperation;
587 if ( !anIsOperation )
590 if ( aListX->Extent() == 1 )
592 removePointsLists( theISection );
596 TColStd_ListOfReal anOldListX;
597 anOldListX = aListX->List();
599 TColStd_ListOfReal anOldListY;
600 anOldListY = aListY->List();
602 // Refill the existing lists
606 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
607 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
608 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
611 continue; // skip index to remove
613 aListX->Append( anIterX.Value() );
614 aListY->Append( anIterY.Value() );
618 if ( !anIsOperation )
624 CurveCreator::Coordinates HYDROData_PolylineXY::getPoints( const int theISection ) const
626 CurveCreator::Coordinates aResList;
628 if ( theISection < 0 )
630 int aNbSections = getNbSections();
631 for ( int i = 0; i < aNbSections; ++i )
633 CurveCreator::Coordinates aSectCoords = getPoints( i );
634 aResList.insert( aResList.end(), aSectCoords.begin(), aSectCoords.end());
639 Handle(TDataStd_RealList) aListX, aListY;
640 getPointsLists( theISection, aListX, aListY, false );
641 if ( !aListX.IsNull() && !aListY.IsNull() )
643 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
644 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
645 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
647 const double& aCoordX = anIterX.Value();
648 const double& aCoordY = anIterY.Value();
650 aResList.push_back( aCoordX );
651 aResList.push_back( aCoordY );