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 QString anXStr = QString::number( aSectPoint.X(), 'f', 2 );
168 QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 );
169 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName )
170 .arg( i - 1 ).arg( anXStr ).arg( anYStr );
174 aResList << QString( "" );
175 aResList << QString( "%1.Update();" ).arg( aPolylineName );
176 aResList << QString( "" );
181 QVariant HYDROData_PolylineXY::GetDataVariant()
183 QPainterPath aPath = GetPainterPath();
186 aVarData.setValue<QPainterPath>( aPath );
191 QColor HYDROData_PolylineXY::DefaultWireColor()
193 return QColor( Qt::red );
196 bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
198 if ( theIOR.IsEmpty() )
201 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
202 if ( aShape.IsNull() )
205 return ImportShape( aShape );
208 void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
210 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
213 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
215 TCollection_AsciiString aRes;
217 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
218 if ( !aLabel.IsNull() )
220 Handle(TDataStd_AsciiString) anAsciiStr;
221 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
222 aRes = anAsciiStr->Get();
228 TopoDS_Shape HYDROData_PolylineXY::GetShape() const
230 return getPolylineShape();
233 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
234 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
235 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
236 NCollection_Sequence<bool>& theSectClosures,
237 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
238 const bool theIsCanBeClosed )
240 Standard_Real aFirst = 0.0, aLast = 0.0;
241 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
242 if ( anEdgeGeomCurve.IsNull() )
245 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
246 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
248 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
249 HYDROData_PolylineXY::PointsList aPointsList;
251 if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
253 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
255 gp_Pnt aFirstPoint, aLastPoint;
256 aGeomLine->D0( aFirst, aFirstPoint );
257 aGeomLine->D0( aLast, aLastPoint );
259 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
260 aPointsList.Append( aSectFirstPoint );
262 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
263 aPointsList.Append( aSectLastPoint );
265 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
267 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
269 Handle(Geom_BSplineCurve) aGeomSpline =
270 Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
272 int aNbKnots = aGeomSpline->NbKnots();
274 TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
275 aGeomSpline->Knots( aSplineKnots );
277 // Decrease the number of imported knots because of last one
278 // knot is the closing point which are the start point
279 if ( anIsEdgeClosed ) aNbKnots--;
281 for ( int i = 1; i <= aNbKnots; ++i )
283 const Standard_Real& aKnot = aSplineKnots.Value( i );
286 aGeomSpline->D0( aKnot, aPoint );
288 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
289 aPointsList.Append( aSectPoint );
294 // Other curve types are not supported
298 if ( aPointsList.IsEmpty() )
301 theSectNames.Append( aSectName );
302 theSectTypes.Append( aSectionType );
303 theSectClosures.Append( anIsEdgeClosed );
304 theSectPoints.Append( aPointsList );
309 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
311 if ( theShape.IsNull() )
316 bool anIsCanBeImported = false;
318 NCollection_Sequence<TCollection_AsciiString> aSectNames;
319 NCollection_Sequence<SectionType> aSectTypes;
320 NCollection_Sequence<bool> aSectClosures;
321 NCollection_Sequence<PointsList> aSectPoints;
323 if ( theShape.ShapeType() == TopAbs_EDGE )
325 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
326 anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
328 else if ( theShape.ShapeType() == TopAbs_WIRE )
330 TopTools_SequenceOfShape anEdges;
331 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
333 anIsCanBeImported = !anEdges.IsEmpty();
334 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
336 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
337 anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
341 if ( anIsCanBeImported )
343 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
345 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
346 const SectionType& aSectType = aSectTypes.Value( i );
347 bool anIsSectionClosed = aSectClosures.Value( i );
348 const PointsList& aSectPointsList = aSectPoints( i );
350 AddSection( aSectName, aSectType, anIsSectionClosed );
351 SetPoints( i - 1, aSectPointsList );
356 TopoDS_Shape aShape = theShape;
358 if ( theShape.ShapeType() == TopAbs_EDGE )
360 // We make the wire from incoming edge because of other algorithms
361 // are waiting at least the wire from polyline
362 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
363 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
365 if ( aMakeWire.IsDone() )
366 aShape = aMakeWire.Wire();
369 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
370 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
372 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
375 TopoDS_Shape aResult;
377 aResult = aProj.Shape();
379 setPolylineShape( aResult );
382 setEditable( anIsCanBeImported );
387 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
388 const bool& theIsClosed,
389 const NCollection_Sequence<gp_XYZ>& thePoints )
392 if( theType == SECTION_POLYLINE )
394 int aNbPoints = thePoints.Length();
395 BRepBuilderAPI_MakePolygon aMakeWire;
396 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
398 gp_XYZ aPoint = thePoints.Value( i );
399 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
400 aMakeWire.Add( aPnt );
402 if( theIsClosed && ( aNbPoints > 2 ) )
405 if ( aMakeWire.IsDone() )
406 aWire = aMakeWire.Wire();
408 else //if( theType == PolylineSection::SECTION_SPLINE )
410 BRepBuilderAPI_MakeWire aMakeWire;
412 if ( thePoints.Size() > 1 )
414 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
416 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
417 aMakeWire.Add( anEdge );
420 if ( aMakeWire.IsDone() )
427 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
428 const SectionType& theType,
429 const bool& theIsClosed,
430 const NCollection_Sequence<gp_XYZ>& thePoints )
432 if ( thePoints.IsEmpty() )
435 if ( theType == SECTION_POLYLINE )
437 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
438 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
440 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
442 const gp_XYZ& aSectPoint = thePoints.Value( i );
444 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
448 thePath.closeSubpath();
452 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
453 aBSpline.ComputePath( thePath );
457 void HYDROData_PolylineXY::Update()
461 // If polyline is not editable we no need to update it wire
462 SetToUpdate( false );
466 HYDROData_IPolyline::Update();
468 NCollection_Sequence<TCollection_AsciiString> aSectNames;
469 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
470 NCollection_Sequence<bool> aSectClosures;
471 GetSections( aSectNames, aSectTypes, aSectClosures );
473 BRepBuilderAPI_MakeWire aMakeWire;
475 TopTools_ListOfShape aSectionWiresList;
477 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
479 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
480 SectionType aSectionType = aSectTypes.Value( aSectionId );
481 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
483 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
484 if ( aSectPointsList.IsEmpty() )
487 NCollection_Sequence<gp_XYZ> aPoints;
488 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
490 const Point& aSectPoint = aSectPointsList.Value( i );
492 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
493 aPoints.Append( aPoint );
496 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
497 if ( !aSectionWire.IsNull() ) {
498 aSectionWiresList.Append( aSectionWire );
499 aMakeWire.Add( aSectionWire );
502 // all input wires in the <aSectionWiresList>
503 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
504 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
505 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
506 for(;it.More();it.Next())
508 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
509 for(;it2.More();it2.Next())
510 aSeqEdges->Append(it2.Current());
514 TopoDS_Compound aCmp;
515 TopoDS_Shape aResult;
516 aBB.MakeCompound(aCmp);
517 if(aSeqEdges->Length() >1)
519 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
521 if( aSeqWires->Length()==1 )
522 aResult = aSeqWires->Value( 1 );
525 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
527 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
533 else if (aSeqEdges->Length() == 1)
535 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
537 aResult = mkWire.Wire();
540 setPolylineShape( aResult );
543 bool HYDROData_PolylineXY::IsHas2dPrs() const
548 bool HYDROData_PolylineXY::IsEditable() const
550 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
553 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
555 if ( !theIsEditable )
556 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
558 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
562 * Returns true if polyline is closed
564 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
566 bool anIsClosed = false;
568 TopoDS_Shape aShape = GetShape();
569 if ( aShape.IsNull() )
572 TopTools_SequenceOfShape aWires;
573 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
575 int aNbWires = aWires.Length();
576 if ( theIsSimpleCheck )
578 anIsClosed = aNbWires > 0;
579 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
581 const TopoDS_Shape& aWire = aWires.Value( i );
582 anIsClosed = BRep_Tool::IsClosed( aWire );
587 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
593 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
594 const int thePointIndex ) const
596 double aResDistance = -1;
597 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
600 if ( thePointIndex == 0 )
603 SectionType aSectionType = GetSectionType( theSectionIndex );
604 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
605 PointsList aSectPointsList = GetPoints( theSectionIndex );
606 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
609 if ( aSectionType == SECTION_POLYLINE )
613 Point aPrevPoint = aSectPointsList.Value( 1 );
614 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
616 const Point& aSectPoint = aSectPointsList.Value( i );
617 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
618 aPrevPoint = aSectPoint;
620 if ( thePointIndex == i - 1 )
628 int aSectNbPoints = aSectPointsList.Size();
629 NCollection_Sequence<gp_XYZ> aPoints;
630 for( int i = 1 ; i <= aSectNbPoints; ++i )
632 const Point& aSectPoint = aSectPointsList.Value( i );
634 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
635 aPoints.Append( aPoint );
637 if ( thePointIndex == i - 1 )
638 aPointToTest = aPoint;
641 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
643 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
644 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
646 if ( thePointIndex != aSectNbPoints - 1 )
648 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
649 aSecondParam = aProject.LowerDistanceParameter();
652 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
654 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
660 int HYDROData_PolylineXY::NbSections() const
662 Handle(TDataStd_ExtStringList) aNamesList;
663 Handle(TDataStd_IntegerList) aTypesList;
664 Handle(TDataStd_BooleanList) aClosuresList;
665 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
667 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
670 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
671 const SectionType theSectionType,
672 const bool theIsClosed )
674 Handle(TDataStd_ExtStringList) aNamesList;
675 Handle(TDataStd_IntegerList) aTypesList;
676 Handle(TDataStd_BooleanList) aClosuresList;
677 getSectionsLists( aNamesList, aTypesList, aClosuresList );
679 TCollection_ExtendedString aSectName( theSectName );
680 if ( aSectName.Length() <= 0 )
681 aSectName = getUniqueSectionName( aNamesList );
683 aNamesList->Append( aSectName );
684 aTypesList->Append( theSectionType );
685 aClosuresList->Append( theIsClosed );
690 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
692 TCollection_AsciiString aResName;
694 Handle(TDataStd_ExtStringList) aNamesList;
695 Handle(TDataStd_IntegerList) aTypesList;
696 Handle(TDataStd_BooleanList) aClosuresList;
697 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
698 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
701 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
702 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
704 if ( aNamesIter.More() )
705 aResName = aNamesIter.Value();
710 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
711 const TCollection_AsciiString& theSectionName )
713 Handle(TDataStd_ExtStringList) aNamesList;
714 Handle(TDataStd_IntegerList) aTypesList;
715 Handle(TDataStd_BooleanList) aClosuresList;
716 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
717 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
720 TDataStd_ListOfExtendedString anOldNamesList;
721 anOldNamesList = aNamesList->List();
723 // Refill the existing list
726 TCollection_ExtendedString aNewSectName = theSectionName;
728 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
729 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
730 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
735 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
737 Handle(TDataStd_ExtStringList) aNamesList;
738 Handle(TDataStd_IntegerList) aTypesList;
739 Handle(TDataStd_BooleanList) aClosuresList;
740 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
741 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
742 return SECTION_POLYLINE;
744 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
745 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
747 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
750 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
751 const SectionType theSectionType )
753 Handle(TDataStd_ExtStringList) aNamesList;
754 Handle(TDataStd_IntegerList) aTypesList;
755 Handle(TDataStd_BooleanList) aClosuresList;
756 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
757 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
760 TColStd_ListOfInteger anOldTypesList;
761 anOldTypesList = aTypesList->List();
763 // Refill the existing list
766 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
767 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
768 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
773 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
775 Handle(TDataStd_ExtStringList) aNamesList;
776 Handle(TDataStd_IntegerList) aTypesList;
777 Handle(TDataStd_BooleanList) aClosuresList;
778 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
779 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
782 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
783 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
785 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
788 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
789 const bool theIsClosed )
791 Handle(TDataStd_ExtStringList) aNamesList;
792 Handle(TDataStd_IntegerList) aTypesList;
793 Handle(TDataStd_BooleanList) aClosuresList;
794 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
795 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
798 TDataStd_ListOfByte anOldClosuresList;
799 anOldClosuresList = aClosuresList->List();
801 // Refill the existing list
802 aClosuresList->Clear();
804 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
805 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
806 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
811 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
812 NCollection_Sequence<SectionType>& theSectTypes,
813 NCollection_Sequence<bool>& theSectClosures ) const
815 theSectNames.Clear();
816 theSectTypes.Clear();
817 theSectClosures.Clear();
819 Handle(TDataStd_ExtStringList) aNamesList;
820 Handle(TDataStd_IntegerList) aTypesList;
821 Handle(TDataStd_BooleanList) aClosuresList;
822 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
823 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
826 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
827 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
828 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
829 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
830 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
832 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
833 SectionType aSectType = (SectionType)aTypesIter.Value();
834 bool aSectClosures = aClosuresIter.Value();
836 theSectNames.Append( aSectName );
837 theSectTypes.Append( aSectType );
838 theSectClosures.Append( aSectClosures );
842 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
844 Handle(TDataStd_ExtStringList) aNamesList;
845 Handle(TDataStd_IntegerList) aTypesList;
846 Handle(TDataStd_BooleanList) aClosuresList;
847 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
848 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
851 if ( aNamesList->Extent() == 1 )
853 removeSectionsLists();
858 TDataStd_ListOfExtendedString anOldNamesList;
859 anOldNamesList = aNamesList->List();
861 TColStd_ListOfInteger anOldTypesList;
862 anOldTypesList = aTypesList->List();
864 TDataStd_ListOfByte anOldClosuresList;
865 anOldClosuresList = aClosuresList->List();
867 // Refill the existing lists
870 aClosuresList->Clear();
872 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
873 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
874 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
875 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
876 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
878 if ( i == theSectionIndex )
879 continue; // skip index to remove
881 aNamesList->Append( aNamesIter.Value() );
882 aTypesList->Append( aTypesIter.Value() );
883 aClosuresList->Append( (bool)aClosuresIter.Value() );
886 // Remove points that belongs to removed section
887 removePointsLists( theSectionIndex );
893 void HYDROData_PolylineXY::RemoveSections()
895 removeSectionsLists();
900 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
901 const Point& thePoint,
902 const int thePointIndex )
904 Handle(TDataStd_RealList) aListX, aListY;
905 getPointsLists( theSectionIndex, aListX, aListY );
907 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
909 aListX->Append( thePoint.X() );
910 aListY->Append( thePoint.Y() );
914 TColStd_ListOfReal anOldListX;
915 anOldListX = aListX->List();
917 TColStd_ListOfReal anOldListY;
918 anOldListY = aListY->List();
920 // Refill the existing lists
924 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
925 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
926 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
928 double aCoordX = anIterX.Value();
929 double aCoordY = anIterY.Value();
931 if ( i == thePointIndex )
933 // Insert our new point
934 aListX->Append( thePoint.X() );
935 aListY->Append( thePoint.Y() );
938 aListX->Append( aCoordX );
939 aListY->Append( aCoordY );
946 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
947 const Point& thePoint,
948 const int thePointIndex )
950 Handle(TDataStd_RealList) aListX, aListY;
951 getPointsLists( theSectionIndex, aListX, aListY );
953 if ( thePointIndex < 0 )
955 aListX->Prepend( thePoint.X() );
956 aListY->Prepend( thePoint.Y() );
958 else if ( thePointIndex >= aListX->Extent() )
960 aListX->Append( thePoint.X() );
961 aListY->Append( thePoint.Y() );
965 TColStd_ListOfReal anOldListX;
966 anOldListX = aListX->List();
968 TColStd_ListOfReal anOldListY;
969 anOldListY = aListY->List();
971 // Refill the existing lists
975 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
976 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
977 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
979 double aCoordX = anIterX.Value();
980 double aCoordY = anIterY.Value();
982 if ( i == thePointIndex )
984 // Insert our new point instead of old one
985 aCoordX = thePoint.X();
986 aCoordY = thePoint.Y();
989 aListX->Append( aCoordX );
990 aListY->Append( aCoordY );
997 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
998 const PointsList& thePoints )
1000 Handle(TDataStd_RealList) aListX, aListY;
1001 getPointsLists( theSectionIndex, aListX, aListY );
1006 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1008 const Point& aPoint = thePoints.Value( i );
1009 aListX->Append( aPoint.X() );
1010 aListY->Append( aPoint.Y() );
1014 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1015 const int thePointIndex )
1017 Handle(TDataStd_RealList) aListX, aListY;
1018 getPointsLists( theSectionIndex, aListX, aListY, false );
1019 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1022 if ( aListX->Extent() == 1 )
1024 removePointsLists( theSectionIndex );
1028 TColStd_ListOfReal anOldListX;
1029 anOldListX = aListX->List();
1031 TColStd_ListOfReal anOldListY;
1032 anOldListY = aListY->List();
1034 // Refill the existing lists
1038 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1039 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1040 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1042 if ( i == thePointIndex )
1043 continue; // skip index to remove
1045 aListX->Append( anIterX.Value() );
1046 aListY->Append( anIterY.Value() );
1050 SetToUpdate( true );
1053 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
1055 PointsList aResList;
1057 Handle(TDataStd_RealList) aListX, aListY;
1058 getPointsLists( theSectionIndex, aListX, aListY, false );
1059 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1062 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1063 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1064 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1066 Point aPoint( anIterX.Value(), anIterY.Value() );
1067 aResList.Append( aPoint );
1073 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1077 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1078 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1079 NCollection_Sequence<bool> aSectClosures;
1080 GetSections( aSectNames, aSectTypes, aSectClosures );
1082 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1084 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1085 SectionType aSectionType = aSectTypes.Value( aSectionId );
1086 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1088 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1089 if ( aSectPointsList.IsEmpty() )
1092 NCollection_Sequence<gp_XYZ> aPoints;
1093 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1095 const Point& aSectPoint = aSectPointsList.Value( i );
1097 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1098 aPoints.Append( aPoint );
1101 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );
1107 void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
1109 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1110 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1111 NCollection_Sequence<bool> aSectClosures;
1112 GetSections( aSectNames, aSectTypes, aSectClosures );
1114 gp_XY aDelta( theDx, theDy );
1115 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
1117 PointsList aPoints = GetPoints( i );
1118 for( int j = 1, n = aPoints.Size(); j <= n; ++j )
1120 Point& aPoint = aPoints.ChangeValue( j );
1123 SetPoints( i, aPoints );
1125 SetToUpdate( true );