2 #include "HYDROData_PolylineXY.h"
4 #include "HYDROData_BSplineOperation.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_ShapesTool.h"
7 #include "HYDROData_Tool.h"
9 #include <BRep_Builder.hxx>
10 #include <BRepBuilderAPI_MakeEdge.hxx>
11 #include <BRepBuilderAPI_MakeWire.hxx>
12 #include <BRepBuilderAPI_MakePolygon.hxx>
13 #include <BRepBuilderAPI_MakeFace.hxx>
14 #include <BRepOffsetAPI_NormalProjection.hxx>
18 #include <GeomAPI_ProjectPointOnCurve.hxx>
19 #include <GeomAdaptor_Curve.hxx>
20 #include <Geom_Line.hxx>
21 #include <Geom_BSplineCurve.hxx>
23 #include <GCPnts_AbscissaPoint.hxx>
25 #include <ImageComposer_MetaTypes.h>
31 #include <NCollection_Map.hxx>
33 #include <TCollection_ExtendedString.hxx>
35 #include <TDataStd_ListIteratorOfListOfByte.hxx>
36 #include <TColStd_ListIteratorOfListOfInteger.hxx>
37 #include <TColStd_ListIteratorOfListOfReal.hxx>
39 #include <TColStd_Array1OfReal.hxx>
41 #include <TDataStd_AsciiString.hxx>
42 #include <TDataStd_BooleanList.hxx>
43 #include <TDataStd_ExtStringList.hxx>
44 #include <TDataStd_IntegerList.hxx>
45 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
46 #include <TDataStd_RealList.hxx>
47 #include <TDataStd_UAttribute.hxx>
49 #include <TopoDS_Iterator.hxx>
50 #include <TopTools_ListIteratorOfListOfShape.hxx>
51 #include <TopTools_HSequenceOfShape.hxx>
52 #include <TopExp_Explorer.hxx>
53 #include <ShapeAnalysis_FreeBounds.hxx>
57 #include <QPainterPath>
60 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
62 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
64 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
66 NCollection_Map<TCollection_AsciiString> aNamesMap;
68 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
70 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
71 aNamesMap.Add( aSectName );
74 TCollection_AsciiString aResName;
79 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
82 while ( aNamesMap.Contains( aResName ) );
87 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
89 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
91 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
92 for ( ; aNamesIter.More(); aNamesIter.Next() )
93 aNamesSeq.Append( aNamesIter.Value() );
95 return getUniqueSectionName( aNamesSeq );
98 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
99 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
101 HYDROData_PolylineXY::HYDROData_PolylineXY()
102 : HYDROData_IPolyline()
106 HYDROData_PolylineXY::~HYDROData_PolylineXY()
110 QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
112 QStringList aResList = dumpObjectCreation( theTreatedObjects );
113 QString aPolylineName = GetObjPyName();
115 // Set the wire color
116 QStringList aWireColorDef;
118 QColor aWireColor = GetWireColor();
119 setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" );
121 if ( !aWireColorDef.isEmpty() )
123 aResList << aWireColorDef;
124 aResList << QString( "" );
127 bool anIsEditable = IsEditable();
130 // If polyline is not editable we try to import the shape from geom
131 TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry();
132 if ( !aGeomObjectEntry.IsEmpty() )
134 QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "polyline_sobj" );
135 aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" );" )
136 .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
138 aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" )
139 .arg( aPolylineName ).arg( aSalomeObjName );
141 aResList << QString( "%1.SetGeomObjectEntry( \"%2\" );" )
142 .arg( aPolylineName ).arg( aGeomObjectEntry.ToCString() );
148 NCollection_Sequence<TCollection_AsciiString> aSectNames;
149 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
150 NCollection_Sequence<bool> aSectClosures;
151 GetSections( aSectNames, aSectTypes, aSectClosures );
153 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
155 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
156 const SectionType& aSectType = aSectTypes.Value( i );
157 bool aSectClosure = aSectClosures.Value( i );
159 aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName )
160 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
162 HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 );
163 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
165 const Point& aSectPoint = aSectPointsList.Value( k );
167 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName )
168 .arg( i - 1 ).arg( aSectPoint.X() ).arg( aSectPoint.Y() );
172 aResList << QString( "" );
173 aResList << QString( "%1.Update();" ).arg( aPolylineName );
174 aResList << QString( "" );
179 QVariant HYDROData_PolylineXY::GetDataVariant()
181 QPainterPath aPath = GetPainterPath();
184 aVarData.setValue<QPainterPath>( aPath );
189 QColor HYDROData_PolylineXY::DefaultWireColor()
191 return QColor( Qt::red );
194 bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
196 if ( theIOR.IsEmpty() )
199 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
200 if ( aShape.IsNull() )
203 return ImportShape( aShape );
206 void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
208 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
211 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
213 TCollection_AsciiString aRes;
215 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
216 if ( !aLabel.IsNull() )
218 Handle(TDataStd_AsciiString) anAsciiStr;
219 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
220 aRes = anAsciiStr->Get();
226 TopoDS_Shape HYDROData_PolylineXY::GetShape() const
228 return getPolylineShape();
231 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
232 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
233 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
234 NCollection_Sequence<bool>& theSectClosures,
235 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
236 const bool theIsCanBeClosed )
238 Standard_Real aFirst = 0.0, aLast = 0.0;
239 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
240 if ( anEdgeGeomCurve.IsNull() )
243 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
244 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
246 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
247 HYDROData_PolylineXY::PointsList aPointsList;
249 if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
251 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
253 gp_Pnt aFirstPoint, aLastPoint;
254 aGeomLine->D0( aFirst, aFirstPoint );
255 aGeomLine->D0( aLast, aLastPoint );
257 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
258 aPointsList.Append( aSectFirstPoint );
260 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
261 aPointsList.Append( aSectLastPoint );
263 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
265 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
267 Handle(Geom_BSplineCurve) aGeomSpline =
268 Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
270 int aNbKnots = aGeomSpline->NbKnots();
272 TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
273 aGeomSpline->Knots( aSplineKnots );
275 // Decrease the number of imported knots because of last one
276 // knot is the closing point which are the start point
277 if ( anIsEdgeClosed ) aNbKnots--;
279 for ( int i = 1; i <= aNbKnots; ++i )
281 const Standard_Real& aKnot = aSplineKnots.Value( i );
284 aGeomSpline->D0( aKnot, aPoint );
286 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
287 aPointsList.Append( aSectPoint );
292 // Other curve types are not supported
296 if ( aPointsList.IsEmpty() )
299 theSectNames.Append( aSectName );
300 theSectTypes.Append( aSectionType );
301 theSectClosures.Append( anIsEdgeClosed );
302 theSectPoints.Append( aPointsList );
307 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
309 if ( theShape.IsNull() )
314 bool anIsCanBeImported = false;
316 NCollection_Sequence<TCollection_AsciiString> aSectNames;
317 NCollection_Sequence<SectionType> aSectTypes;
318 NCollection_Sequence<bool> aSectClosures;
319 NCollection_Sequence<PointsList> aSectPoints;
321 if ( theShape.ShapeType() == TopAbs_EDGE )
323 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
324 anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
326 else if ( theShape.ShapeType() == TopAbs_WIRE )
328 TopTools_SequenceOfShape anEdges;
329 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
331 anIsCanBeImported = !anEdges.IsEmpty();
332 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
334 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
335 anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
339 if ( anIsCanBeImported )
341 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
343 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
344 const SectionType& aSectType = aSectTypes.Value( i );
345 bool anIsSectionClosed = aSectClosures.Value( i );
346 const PointsList& aSectPointsList = aSectPoints( i );
348 AddSection( aSectName, aSectType, anIsSectionClosed );
349 SetPoints( i - 1, aSectPointsList );
354 TopoDS_Shape aShape = theShape;
356 if ( theShape.ShapeType() == TopAbs_EDGE )
358 // We make the wire from incoming edge because of other algorithms
359 // are waiting at least the wire from polyline
360 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
361 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
363 if ( aMakeWire.IsDone() )
364 aShape = aMakeWire.Wire();
367 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
368 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
370 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
373 TopoDS_Shape aResult;
375 aResult = aProj.Shape();
377 setPolylineShape( aResult );
380 setEditable( anIsCanBeImported );
385 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
386 const bool& theIsClosed,
387 const NCollection_Sequence<gp_XYZ>& thePoints )
390 if( theType == SECTION_POLYLINE )
392 int aNbPoints = thePoints.Length();
393 BRepBuilderAPI_MakePolygon aMakeWire;
394 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
396 gp_XYZ aPoint = thePoints.Value( i );
397 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
398 aMakeWire.Add( aPnt );
400 if( theIsClosed && ( aNbPoints > 2 ) )
403 if ( aMakeWire.IsDone() )
404 aWire = aMakeWire.Wire();
406 else //if( theType == PolylineSection::SECTION_SPLINE )
408 BRepBuilderAPI_MakeWire aMakeWire;
410 if ( thePoints.Size() > 1 )
412 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
414 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
415 aMakeWire.Add( anEdge );
418 if ( aMakeWire.IsDone() )
425 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
426 const SectionType& theType,
427 const bool& theIsClosed,
428 const NCollection_Sequence<gp_XYZ>& thePoints )
430 if ( thePoints.IsEmpty() )
433 if ( theType == SECTION_POLYLINE )
435 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
436 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
438 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
440 const gp_XYZ& aSectPoint = thePoints.Value( i );
442 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
446 thePath.closeSubpath();
450 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
451 aBSpline.ComputePath( thePath );
455 void HYDROData_PolylineXY::Update()
459 // If polyline is not editable we no need to update it wire
460 SetToUpdate( false );
464 HYDROData_IPolyline::Update();
466 NCollection_Sequence<TCollection_AsciiString> aSectNames;
467 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
468 NCollection_Sequence<bool> aSectClosures;
469 GetSections( aSectNames, aSectTypes, aSectClosures );
471 BRepBuilderAPI_MakeWire aMakeWire;
473 TopTools_ListOfShape aSectionWiresList;
475 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
477 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
478 SectionType aSectionType = aSectTypes.Value( aSectionId );
479 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
481 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
482 if ( aSectPointsList.IsEmpty() )
485 NCollection_Sequence<gp_XYZ> aPoints;
486 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
488 const Point& aSectPoint = aSectPointsList.Value( i );
490 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
491 aPoints.Append( aPoint );
494 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
495 if ( !aSectionWire.IsNull() ) {
496 aSectionWiresList.Append( aSectionWire );
497 aMakeWire.Add( aSectionWire );
500 // all input wires in the <aSectionWiresList>
501 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
502 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
503 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
504 for(;it.More();it.Next())
506 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
507 for(;it2.More();it2.Next())
508 aSeqEdges->Append(it2.Current());
512 TopoDS_Compound aCmp;
513 TopoDS_Shape aResult;
514 aBB.MakeCompound(aCmp);
515 if(aSeqEdges->Length() >1)
517 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
519 if( aSeqWires->Length()==1 )
520 aResult = aSeqWires->Value( 1 );
523 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
525 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
531 else if (aSeqEdges->Length() == 1)
533 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
535 aResult = mkWire.Wire();
538 setPolylineShape( aResult );
541 bool HYDROData_PolylineXY::IsHas2dPrs() const
546 bool HYDROData_PolylineXY::IsEditable() const
548 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
551 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
553 if ( !theIsEditable )
554 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
556 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
560 * Returns true if polyline is closed
562 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
564 bool anIsClosed = false;
566 TopoDS_Shape aShape = GetShape();
567 if ( aShape.IsNull() )
570 TopTools_SequenceOfShape aWires;
571 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
573 int aNbWires = aWires.Length();
574 if ( theIsSimpleCheck )
576 anIsClosed = aNbWires > 0;
577 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
579 const TopoDS_Shape& aWire = aWires.Value( i );
580 anIsClosed = BRep_Tool::IsClosed( aWire );
585 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
591 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
592 const int thePointIndex ) const
594 double aResDistance = -1;
595 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
598 if ( thePointIndex == 0 )
601 SectionType aSectionType = GetSectionType( theSectionIndex );
602 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
603 PointsList aSectPointsList = GetPoints( theSectionIndex );
604 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
607 if ( aSectionType == SECTION_POLYLINE )
611 Point aPrevPoint = aSectPointsList.Value( 1 );
612 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
614 const Point& aSectPoint = aSectPointsList.Value( i );
615 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
616 aPrevPoint = aSectPoint;
618 if ( thePointIndex == i - 1 )
626 int aSectNbPoints = aSectPointsList.Size();
627 NCollection_Sequence<gp_XYZ> aPoints;
628 for( int i = 1 ; i <= aSectNbPoints; ++i )
630 const Point& aSectPoint = aSectPointsList.Value( i );
632 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
633 aPoints.Append( aPoint );
635 if ( thePointIndex == i - 1 )
636 aPointToTest = aPoint;
639 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
641 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
642 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
644 if ( thePointIndex != aSectNbPoints - 1 )
646 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
647 aSecondParam = aProject.LowerDistanceParameter();
650 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
652 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
658 int HYDROData_PolylineXY::NbSections() const
660 Handle(TDataStd_ExtStringList) aNamesList;
661 Handle(TDataStd_IntegerList) aTypesList;
662 Handle(TDataStd_BooleanList) aClosuresList;
663 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
665 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
668 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
669 const SectionType theSectionType,
670 const bool theIsClosed )
672 Handle(TDataStd_ExtStringList) aNamesList;
673 Handle(TDataStd_IntegerList) aTypesList;
674 Handle(TDataStd_BooleanList) aClosuresList;
675 getSectionsLists( aNamesList, aTypesList, aClosuresList );
677 TCollection_ExtendedString aSectName( theSectName );
678 if ( aSectName.Length() <= 0 )
679 aSectName = getUniqueSectionName( aNamesList );
681 aNamesList->Append( aSectName );
682 aTypesList->Append( theSectionType );
683 aClosuresList->Append( theIsClosed );
688 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
690 TCollection_AsciiString aResName;
692 Handle(TDataStd_ExtStringList) aNamesList;
693 Handle(TDataStd_IntegerList) aTypesList;
694 Handle(TDataStd_BooleanList) aClosuresList;
695 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
696 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
699 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
700 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
702 if ( aNamesIter.More() )
703 aResName = aNamesIter.Value();
708 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
709 const TCollection_AsciiString& theSectionName )
711 Handle(TDataStd_ExtStringList) aNamesList;
712 Handle(TDataStd_IntegerList) aTypesList;
713 Handle(TDataStd_BooleanList) aClosuresList;
714 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
715 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
718 TDataStd_ListOfExtendedString anOldNamesList;
719 anOldNamesList = aNamesList->List();
721 // Refill the existing list
724 TCollection_ExtendedString aNewSectName = theSectionName;
726 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
727 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
728 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
733 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
735 Handle(TDataStd_ExtStringList) aNamesList;
736 Handle(TDataStd_IntegerList) aTypesList;
737 Handle(TDataStd_BooleanList) aClosuresList;
738 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
739 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
740 return SECTION_POLYLINE;
742 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
743 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
745 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
748 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
749 const SectionType theSectionType )
751 Handle(TDataStd_ExtStringList) aNamesList;
752 Handle(TDataStd_IntegerList) aTypesList;
753 Handle(TDataStd_BooleanList) aClosuresList;
754 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
755 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
758 TColStd_ListOfInteger anOldTypesList;
759 anOldTypesList = aTypesList->List();
761 // Refill the existing list
764 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
765 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
766 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
771 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
773 Handle(TDataStd_ExtStringList) aNamesList;
774 Handle(TDataStd_IntegerList) aTypesList;
775 Handle(TDataStd_BooleanList) aClosuresList;
776 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
777 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
780 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
781 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
783 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
786 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
787 const bool theIsClosed )
789 Handle(TDataStd_ExtStringList) aNamesList;
790 Handle(TDataStd_IntegerList) aTypesList;
791 Handle(TDataStd_BooleanList) aClosuresList;
792 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
793 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
796 TDataStd_ListOfByte anOldClosuresList;
797 anOldClosuresList = aClosuresList->List();
799 // Refill the existing list
800 aClosuresList->Clear();
802 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
803 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
804 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
809 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
810 NCollection_Sequence<SectionType>& theSectTypes,
811 NCollection_Sequence<bool>& theSectClosures ) const
813 theSectNames.Clear();
814 theSectTypes.Clear();
815 theSectClosures.Clear();
817 Handle(TDataStd_ExtStringList) aNamesList;
818 Handle(TDataStd_IntegerList) aTypesList;
819 Handle(TDataStd_BooleanList) aClosuresList;
820 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
821 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
824 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
825 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
826 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
827 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
828 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
830 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
831 SectionType aSectType = (SectionType)aTypesIter.Value();
832 bool aSectClosures = aClosuresIter.Value();
834 theSectNames.Append( aSectName );
835 theSectTypes.Append( aSectType );
836 theSectClosures.Append( aSectClosures );
840 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
842 Handle(TDataStd_ExtStringList) aNamesList;
843 Handle(TDataStd_IntegerList) aTypesList;
844 Handle(TDataStd_BooleanList) aClosuresList;
845 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
846 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
849 if ( aNamesList->Extent() == 1 )
851 removeSectionsLists();
856 TDataStd_ListOfExtendedString anOldNamesList;
857 anOldNamesList = aNamesList->List();
859 TColStd_ListOfInteger anOldTypesList;
860 anOldTypesList = aTypesList->List();
862 TDataStd_ListOfByte anOldClosuresList;
863 anOldClosuresList = aClosuresList->List();
865 // Refill the existing lists
868 aClosuresList->Clear();
870 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
871 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
872 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
873 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
874 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
876 if ( i == theSectionIndex )
877 continue; // skip index to remove
879 aNamesList->Append( aNamesIter.Value() );
880 aTypesList->Append( aTypesIter.Value() );
881 aClosuresList->Append( (bool)aClosuresIter.Value() );
884 // Remove points that belongs to removed section
885 removePointsLists( theSectionIndex );
891 void HYDROData_PolylineXY::RemoveSections()
893 removeSectionsLists();
898 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
899 const Point& thePoint,
900 const int thePointIndex )
902 Handle(TDataStd_RealList) aListX, aListY;
903 getPointsLists( theSectionIndex, aListX, aListY );
905 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
907 aListX->Append( thePoint.X() );
908 aListY->Append( thePoint.Y() );
912 TColStd_ListOfReal anOldListX;
913 anOldListX = aListX->List();
915 TColStd_ListOfReal anOldListY;
916 anOldListY = aListY->List();
918 // Refill the existing lists
922 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
923 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
924 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
926 double aCoordX = anIterX.Value();
927 double aCoordY = anIterY.Value();
929 if ( i == thePointIndex )
931 // Insert our new point
932 aListX->Append( thePoint.X() );
933 aListY->Append( thePoint.Y() );
936 aListX->Append( aCoordX );
937 aListY->Append( aCoordY );
944 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
945 const Point& thePoint,
946 const int thePointIndex )
948 Handle(TDataStd_RealList) aListX, aListY;
949 getPointsLists( theSectionIndex, aListX, aListY );
951 if ( thePointIndex < 0 )
953 aListX->Prepend( thePoint.X() );
954 aListY->Prepend( thePoint.Y() );
956 else if ( thePointIndex >= aListX->Extent() )
958 aListX->Append( thePoint.X() );
959 aListY->Append( thePoint.Y() );
963 TColStd_ListOfReal anOldListX;
964 anOldListX = aListX->List();
966 TColStd_ListOfReal anOldListY;
967 anOldListY = aListY->List();
969 // Refill the existing lists
973 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
974 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
975 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
977 double aCoordX = anIterX.Value();
978 double aCoordY = anIterY.Value();
980 if ( i == thePointIndex )
982 // Insert our new point instead of old one
983 aCoordX = thePoint.X();
984 aCoordY = thePoint.Y();
987 aListX->Append( aCoordX );
988 aListY->Append( aCoordY );
995 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
996 const PointsList& thePoints )
998 Handle(TDataStd_RealList) aListX, aListY;
999 getPointsLists( theSectionIndex, aListX, aListY );
1004 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1006 const Point& aPoint = thePoints.Value( i );
1007 aListX->Append( aPoint.X() );
1008 aListY->Append( aPoint.Y() );
1012 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1013 const int thePointIndex )
1015 Handle(TDataStd_RealList) aListX, aListY;
1016 getPointsLists( theSectionIndex, aListX, aListY, false );
1017 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1020 if ( aListX->Extent() == 1 )
1022 removePointsLists( theSectionIndex );
1026 TColStd_ListOfReal anOldListX;
1027 anOldListX = aListX->List();
1029 TColStd_ListOfReal anOldListY;
1030 anOldListY = aListY->List();
1032 // Refill the existing lists
1036 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1037 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1038 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1040 if ( i == thePointIndex )
1041 continue; // skip index to remove
1043 aListX->Append( anIterX.Value() );
1044 aListY->Append( anIterY.Value() );
1048 SetToUpdate( true );
1051 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
1053 PointsList aResList;
1055 Handle(TDataStd_RealList) aListX, aListY;
1056 getPointsLists( theSectionIndex, aListX, aListY, false );
1057 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1060 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1061 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1062 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1064 Point aPoint( anIterX.Value(), anIterY.Value() );
1065 aResList.Append( aPoint );
1071 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1075 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1076 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1077 NCollection_Sequence<bool> aSectClosures;
1078 GetSections( aSectNames, aSectTypes, aSectClosures );
1080 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1082 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1083 SectionType aSectionType = aSectTypes.Value( aSectionId );
1084 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1086 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1087 if ( aSectPointsList.IsEmpty() )
1090 NCollection_Sequence<gp_XYZ> aPoints;
1091 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1093 const Point& aSectPoint = aSectPointsList.Value( i );
1095 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1096 aPoints.Append( aPoint );
1099 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );