1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_PolylineXY.h"
25 #include "HYDROData_BSplineOperation.h"
26 #include "HYDROData_Document.h"
27 #include "HYDROData_ShapesTool.h"
28 #include "HYDROData_Tool.h"
30 #include <BRep_Builder.hxx>
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <BRepBuilderAPI_MakeWire.hxx>
33 #include <BRepBuilderAPI_MakePolygon.hxx>
34 #include <BRepBuilderAPI_MakeFace.hxx>
35 #include <BRepOffsetAPI_NormalProjection.hxx>
39 #include <GeomAPI_ProjectPointOnCurve.hxx>
40 #include <GeomAdaptor_Curve.hxx>
41 #include <Geom_Line.hxx>
42 #include <Geom_BSplineCurve.hxx>
44 #include <GCPnts_AbscissaPoint.hxx>
46 #include <ImageComposer_MetaTypes.h>
52 #include <NCollection_Map.hxx>
54 #include <TCollection_ExtendedString.hxx>
56 #include <TDataStd_ListIteratorOfListOfByte.hxx>
57 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <TColStd_ListIteratorOfListOfReal.hxx>
60 #include <TColStd_Array1OfReal.hxx>
62 #include <TDataStd_AsciiString.hxx>
63 #include <TDataStd_BooleanList.hxx>
64 #include <TDataStd_ExtStringList.hxx>
65 #include <TDataStd_IntegerList.hxx>
66 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
67 #include <TDataStd_RealList.hxx>
68 #include <TDataStd_UAttribute.hxx>
70 #include <TopoDS_Iterator.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <TopTools_HSequenceOfShape.hxx>
73 #include <TopExp_Explorer.hxx>
74 #include <ShapeAnalysis_FreeBounds.hxx>
78 #include <QPainterPath>
81 static const Standard_GUID GUID_IS_UNEDITABLE("e5799736-9030-4051-91a4-2e58321fa153");
83 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
85 TCollection_AsciiString getUniqueSectionName( const NCollection_Sequence<TCollection_AsciiString>& theNamesSeq )
87 NCollection_Map<TCollection_AsciiString> aNamesMap;
89 for ( int i = 1, n = theNamesSeq.Size(); i <= n; ++i )
91 const TCollection_AsciiString& aSectName = theNamesSeq.Value( i );
92 aNamesMap.Add( aSectName );
95 TCollection_AsciiString aResName;
100 aResName = TCollection_AsciiString( "Section_" ) + aPrefIdx;
103 while ( aNamesMap.Contains( aResName ) );
108 TCollection_AsciiString getUniqueSectionName( const Handle(TDataStd_ExtStringList)& theNamesList )
110 NCollection_Sequence<TCollection_AsciiString> aNamesSeq;
112 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( theNamesList->List() );
113 for ( ; aNamesIter.More(); aNamesIter.Next() )
114 aNamesSeq.Append( aNamesIter.Value() );
116 return getUniqueSectionName( aNamesSeq );
119 IMPLEMENT_STANDARD_HANDLE(HYDROData_PolylineXY, HYDROData_IPolyline)
120 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_PolylineXY, HYDROData_IPolyline)
122 HYDROData_PolylineXY::HYDROData_PolylineXY()
123 : HYDROData_IPolyline()
127 HYDROData_PolylineXY::~HYDROData_PolylineXY()
131 QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
133 QStringList aResList = dumpObjectCreation( theTreatedObjects );
134 QString aPolylineName = GetObjPyName();
136 // Set the wire color
137 QStringList aWireColorDef;
139 QColor aWireColor = GetWireColor();
140 setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" );
142 if ( !aWireColorDef.isEmpty() )
144 aResList << aWireColorDef;
145 aResList << QString( "" );
148 bool anIsEditable = IsEditable();
151 // If polyline is not editable we try to import the shape from geom
152 TCollection_AsciiString aGeomObjectEntry = GetGeomObjectEntry();
153 if ( !aGeomObjectEntry.IsEmpty() )
155 QString aSalomeObjName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "polyline_sobj" );
156 aResList << QString( "%1 = salome.myStudy.FindObjectID( \"%2\" );" )
157 .arg( aSalomeObjName ).arg( aGeomObjectEntry.ToCString() );
159 aResList << QString( "%1.ImportFromGeomIOR( %2.GetIOR() );" )
160 .arg( aPolylineName ).arg( aSalomeObjName );
162 aResList << QString( "%1.SetGeomObjectEntry( \"%2\" );" )
163 .arg( aPolylineName ).arg( aGeomObjectEntry.ToCString() );
169 NCollection_Sequence<TCollection_AsciiString> aSectNames;
170 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
171 NCollection_Sequence<bool> aSectClosures;
172 GetSections( aSectNames, aSectTypes, aSectClosures );
174 for ( int i = 1, n = aSectNames.Size(); i <= n; ++i )
176 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
177 const SectionType& aSectType = aSectTypes.Value( i );
178 bool aSectClosure = aSectClosures.Value( i );
180 aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aPolylineName )
181 .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
183 HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( i - 1 );
184 for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
186 const Point& aSectPoint = aSectPointsList.Value( k );
188 QString anXStr = QString::number( aSectPoint.X(), 'f', 2 );
189 QString anYStr = QString::number( aSectPoint.Y(), 'f', 2 );
190 aResList << QString( "%1.AddPoint( %2, gp_XY( %3, %4 ) );" ).arg( aPolylineName )
191 .arg( i - 1 ).arg( anXStr ).arg( anYStr );
195 aResList << QString( "" );
196 aResList << QString( "%1.Update();" ).arg( aPolylineName );
197 aResList << QString( "" );
202 QVariant HYDROData_PolylineXY::GetDataVariant()
204 QPainterPath aPath = GetPainterPath();
207 aVarData.setValue<QPainterPath>( aPath );
212 QColor HYDROData_PolylineXY::DefaultWireColor()
214 return QColor( Qt::red );
217 bool HYDROData_PolylineXY::ImportFromGeomIOR( const TCollection_AsciiString& theIOR )
219 if ( theIOR.IsEmpty() )
222 TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( theIOR.ToCString() );
223 if ( aShape.IsNull() )
226 return ImportShape( aShape );
229 void HYDROData_PolylineXY::SetGeomObjectEntry( const TCollection_AsciiString& theEntry )
231 TDataStd_AsciiString::Set( myLab.FindChild( DataTag_GeomObjectEntry ), theEntry );
234 TCollection_AsciiString HYDROData_PolylineXY::GetGeomObjectEntry() const
236 TCollection_AsciiString aRes;
238 TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
239 if ( !aLabel.IsNull() )
241 Handle(TDataStd_AsciiString) anAsciiStr;
242 if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
243 aRes = anAsciiStr->Get();
249 TopoDS_Shape HYDROData_PolylineXY::GetShape() const
251 return getPolylineShape();
254 bool convertEdgeToSection( const TopoDS_Edge& theEdge,
255 NCollection_Sequence<TCollection_AsciiString>& theSectNames,
256 NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
257 NCollection_Sequence<bool>& theSectClosures,
258 NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
259 const bool theIsCanBeClosed )
261 Standard_Real aFirst = 0.0, aLast = 0.0;
262 Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
263 if ( anEdgeGeomCurve.IsNull() )
266 TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
267 bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
269 HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
270 HYDROData_PolylineXY::PointsList aPointsList;
272 if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
274 Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
276 gp_Pnt aFirstPoint, aLastPoint;
277 aGeomLine->D0( aFirst, aFirstPoint );
278 aGeomLine->D0( aLast, aLastPoint );
280 HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
281 aPointsList.Append( aSectFirstPoint );
283 HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
284 aPointsList.Append( aSectLastPoint );
286 else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) )
288 aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
290 Handle(Geom_BSplineCurve) aGeomSpline =
291 Handle(Geom_BSplineCurve)::DownCast( anEdgeGeomCurve );
293 int aNbKnots = aGeomSpline->NbKnots();
295 TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
296 aGeomSpline->Knots( aSplineKnots );
298 // Decrease the number of imported knots because of last one
299 // knot is the closing point which are the start point
300 if ( anIsEdgeClosed ) aNbKnots--;
302 for ( int i = 1; i <= aNbKnots; ++i )
304 const Standard_Real& aKnot = aSplineKnots.Value( i );
307 aGeomSpline->D0( aKnot, aPoint );
309 HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
310 aPointsList.Append( aSectPoint );
315 // Other curve types are not supported
319 if ( aPointsList.IsEmpty() )
322 theSectNames.Append( aSectName );
323 theSectTypes.Append( aSectionType );
324 theSectClosures.Append( anIsEdgeClosed );
325 theSectPoints.Append( aPointsList );
330 bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape )
332 if ( theShape.IsNull() )
337 bool anIsCanBeImported = false;
339 NCollection_Sequence<TCollection_AsciiString> aSectNames;
340 NCollection_Sequence<SectionType> aSectTypes;
341 NCollection_Sequence<bool> aSectClosures;
342 NCollection_Sequence<PointsList> aSectPoints;
344 if ( theShape.ShapeType() == TopAbs_EDGE )
346 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
347 anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, true );
349 else if ( theShape.ShapeType() == TopAbs_WIRE )
351 TopTools_SequenceOfShape anEdges;
352 HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
354 anIsCanBeImported = !anEdges.IsEmpty();
355 for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
357 TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
358 anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes, aSectClosures, aSectPoints, false );
362 if ( anIsCanBeImported )
364 for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
366 const TCollection_AsciiString& aSectName = aSectNames.Value( i );
367 const SectionType& aSectType = aSectTypes.Value( i );
368 bool anIsSectionClosed = aSectClosures.Value( i );
369 const PointsList& aSectPointsList = aSectPoints( i );
371 AddSection( aSectName, aSectType, anIsSectionClosed );
372 SetPoints( i - 1, aSectPointsList );
377 TopoDS_Shape aShape = theShape;
379 if ( theShape.ShapeType() == TopAbs_EDGE )
381 // We make the wire from incoming edge because of other algorithms
382 // are waiting at least the wire from polyline
383 TopoDS_Edge anEdge = TopoDS::Edge( theShape );
384 BRepBuilderAPI_MakeWire aMakeWire( anEdge );
386 if ( aMakeWire.IsDone() )
387 aShape = aMakeWire.Wire();
390 gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
391 BRepBuilderAPI_MakeFace aMakeFace( aPlane );
393 BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
396 TopoDS_Shape aResult;
398 aResult = aProj.Shape();
400 setPolylineShape( aResult );
403 setEditable( anIsCanBeImported );
408 TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
409 const bool& theIsClosed,
410 const NCollection_Sequence<gp_XYZ>& thePoints )
413 if( theType == SECTION_POLYLINE )
415 int aNbPoints = thePoints.Length();
416 BRepBuilderAPI_MakePolygon aMakeWire;
417 for ( int i = 1, n = aNbPoints; i <= n ; ++i )
419 gp_XYZ aPoint = thePoints.Value( i );
420 gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
421 aMakeWire.Add( aPnt );
423 if( theIsClosed && ( aNbPoints > 2 ) )
426 if ( aMakeWire.IsDone() )
427 aWire = aMakeWire.Wire();
429 else //if( theType == PolylineSection::SECTION_SPLINE )
431 BRepBuilderAPI_MakeWire aMakeWire;
433 if ( thePoints.Size() > 1 )
435 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
437 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge();
438 aMakeWire.Add( anEdge );
441 if ( aMakeWire.IsDone() )
448 void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
449 const SectionType& theType,
450 const bool& theIsClosed,
451 const NCollection_Sequence<gp_XYZ>& thePoints )
453 if ( thePoints.IsEmpty() )
456 if ( theType == SECTION_POLYLINE )
458 const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
459 thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
461 for( int i = 2, n = thePoints.Size(); i <= n; ++i )
463 const gp_XYZ& aSectPoint = thePoints.Value( i );
465 thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
469 thePath.closeSubpath();
473 HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
474 aBSpline.ComputePath( thePath );
478 void HYDROData_PolylineXY::Update()
482 // If polyline is not editable we no need to update it wire
483 SetToUpdate( false );
487 HYDROData_IPolyline::Update();
489 NCollection_Sequence<TCollection_AsciiString> aSectNames;
490 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
491 NCollection_Sequence<bool> aSectClosures;
492 GetSections( aSectNames, aSectTypes, aSectClosures );
494 BRepBuilderAPI_MakeWire aMakeWire;
496 TopTools_ListOfShape aSectionWiresList;
498 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
500 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
501 SectionType aSectionType = aSectTypes.Value( aSectionId );
502 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
504 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
505 if ( aSectPointsList.IsEmpty() )
508 NCollection_Sequence<gp_XYZ> aPoints;
509 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
511 const Point& aSectPoint = aSectPointsList.Value( i );
513 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
514 aPoints.Append( aPoint );
517 TopoDS_Wire aSectionWire = BuildWire( aSectionType, anIsSectionClosed, aPoints );
518 if ( !aSectionWire.IsNull() ) {
519 aSectionWiresList.Append( aSectionWire );
520 aMakeWire.Add( aSectionWire );
523 // all input wires in the <aSectionWiresList>
524 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
525 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
526 TopTools_ListIteratorOfListOfShape it(aSectionWiresList);
527 for(;it.More();it.Next())
529 TopExp_Explorer it2(it.Value(), TopAbs_EDGE);
530 for(;it2.More();it2.Next())
531 aSeqEdges->Append(it2.Current());
535 TopoDS_Compound aCmp;
536 TopoDS_Shape aResult;
537 aBB.MakeCompound(aCmp);
538 if(aSeqEdges->Length() >1)
540 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,1E-5,Standard_False,aSeqWires);
542 if( aSeqWires->Length()==1 )
543 aResult = aSeqWires->Value( 1 );
546 for (Standard_Integer i = 1; i <= aSeqWires->Length();i++)
548 const TopoDS_Shape& aS1 = aSeqWires->Value(i);
554 else if (aSeqEdges->Length() == 1)
556 BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
558 aResult = mkWire.Wire();
561 setPolylineShape( aResult );
564 bool HYDROData_PolylineXY::IsHas2dPrs() const
569 bool HYDROData_PolylineXY::IsEditable() const
571 return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
574 void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
576 if ( !theIsEditable )
577 TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
579 myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
583 * Returns true if polyline is closed
585 bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
587 bool anIsClosed = false;
589 TopoDS_Shape aShape = GetShape();
590 if ( aShape.IsNull() )
593 TopTools_SequenceOfShape aWires;
594 HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
596 int aNbWires = aWires.Length();
597 if ( theIsSimpleCheck )
599 anIsClosed = aNbWires > 0;
600 for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
602 const TopoDS_Shape& aWire = aWires.Value( i );
603 anIsClosed = BRep_Tool::IsClosed( aWire );
608 anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
614 double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
615 const int thePointIndex ) const
617 double aResDistance = -1;
618 if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
621 if ( thePointIndex == 0 )
624 SectionType aSectionType = GetSectionType( theSectionIndex );
625 bool anIsSectionClosed = IsClosedSection( theSectionIndex );
626 PointsList aSectPointsList = GetPoints( theSectionIndex );
627 if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
630 if ( aSectionType == SECTION_POLYLINE )
634 Point aPrevPoint = aSectPointsList.Value( 1 );
635 for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
637 const Point& aSectPoint = aSectPointsList.Value( i );
638 aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
639 aPrevPoint = aSectPoint;
641 if ( thePointIndex == i - 1 )
649 int aSectNbPoints = aSectPointsList.Size();
650 NCollection_Sequence<gp_XYZ> aPoints;
651 for( int i = 1 ; i <= aSectNbPoints; ++i )
653 const Point& aSectPoint = aSectPointsList.Value( i );
655 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
656 aPoints.Append( aPoint );
658 if ( thePointIndex == i - 1 )
659 aPointToTest = aPoint;
662 HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
664 Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
665 Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
667 if ( thePointIndex != aSectNbPoints - 1 )
669 GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
670 aSecondParam = aProject.LowerDistanceParameter();
673 GeomAdaptor_Curve anAdap( aBSpline.Curve() );
675 aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
681 int HYDROData_PolylineXY::NbSections() const
683 Handle(TDataStd_ExtStringList) aNamesList;
684 Handle(TDataStd_IntegerList) aTypesList;
685 Handle(TDataStd_BooleanList) aClosuresList;
686 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
688 return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
691 void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
692 const SectionType theSectionType,
693 const bool theIsClosed )
695 Handle(TDataStd_ExtStringList) aNamesList;
696 Handle(TDataStd_IntegerList) aTypesList;
697 Handle(TDataStd_BooleanList) aClosuresList;
698 getSectionsLists( aNamesList, aTypesList, aClosuresList );
700 TCollection_ExtendedString aSectName( theSectName );
701 if ( aSectName.Length() <= 0 )
702 aSectName = getUniqueSectionName( aNamesList );
704 aNamesList->Append( aSectName );
705 aTypesList->Append( theSectionType );
706 aClosuresList->Append( theIsClosed );
711 TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
713 TCollection_AsciiString aResName;
715 Handle(TDataStd_ExtStringList) aNamesList;
716 Handle(TDataStd_IntegerList) aTypesList;
717 Handle(TDataStd_BooleanList) aClosuresList;
718 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
719 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
722 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
723 for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
725 if ( aNamesIter.More() )
726 aResName = aNamesIter.Value();
731 void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
732 const TCollection_AsciiString& theSectionName )
734 Handle(TDataStd_ExtStringList) aNamesList;
735 Handle(TDataStd_IntegerList) aTypesList;
736 Handle(TDataStd_BooleanList) aClosuresList;
737 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
738 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
741 TDataStd_ListOfExtendedString anOldNamesList;
742 anOldNamesList = aNamesList->List();
744 // Refill the existing list
747 TCollection_ExtendedString aNewSectName = theSectionName;
749 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
750 for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
751 aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
756 HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
758 Handle(TDataStd_ExtStringList) aNamesList;
759 Handle(TDataStd_IntegerList) aTypesList;
760 Handle(TDataStd_BooleanList) aClosuresList;
761 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
762 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
763 return SECTION_POLYLINE;
765 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
766 for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
768 return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
771 void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
772 const SectionType theSectionType )
774 Handle(TDataStd_ExtStringList) aNamesList;
775 Handle(TDataStd_IntegerList) aTypesList;
776 Handle(TDataStd_BooleanList) aClosuresList;
777 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
778 if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
781 TColStd_ListOfInteger anOldTypesList;
782 anOldTypesList = aTypesList->List();
784 // Refill the existing list
787 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
788 for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
789 aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
794 bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
796 Handle(TDataStd_ExtStringList) aNamesList;
797 Handle(TDataStd_IntegerList) aTypesList;
798 Handle(TDataStd_BooleanList) aClosuresList;
799 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
800 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
803 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
804 for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
806 return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
809 void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
810 const bool theIsClosed )
812 Handle(TDataStd_ExtStringList) aNamesList;
813 Handle(TDataStd_IntegerList) aTypesList;
814 Handle(TDataStd_BooleanList) aClosuresList;
815 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
816 if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
819 TDataStd_ListOfByte anOldClosuresList;
820 anOldClosuresList = aClosuresList->List();
822 // Refill the existing list
823 aClosuresList->Clear();
825 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
826 for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
827 aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
832 void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
833 NCollection_Sequence<SectionType>& theSectTypes,
834 NCollection_Sequence<bool>& theSectClosures ) const
836 theSectNames.Clear();
837 theSectTypes.Clear();
838 theSectClosures.Clear();
840 Handle(TDataStd_ExtStringList) aNamesList;
841 Handle(TDataStd_IntegerList) aTypesList;
842 Handle(TDataStd_BooleanList) aClosuresList;
843 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
844 if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
847 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
848 TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
849 TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
850 for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
851 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
853 const TCollection_ExtendedString& aSectName = aNamesIter.Value();
854 SectionType aSectType = (SectionType)aTypesIter.Value();
855 bool aSectClosures = aClosuresIter.Value();
857 theSectNames.Append( aSectName );
858 theSectTypes.Append( aSectType );
859 theSectClosures.Append( aSectClosures );
863 void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
865 Handle(TDataStd_ExtStringList) aNamesList;
866 Handle(TDataStd_IntegerList) aTypesList;
867 Handle(TDataStd_BooleanList) aClosuresList;
868 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
869 if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
872 if ( aNamesList->Extent() == 1 )
874 removeSectionsLists();
879 TDataStd_ListOfExtendedString anOldNamesList;
880 anOldNamesList = aNamesList->List();
882 TColStd_ListOfInteger anOldTypesList;
883 anOldTypesList = aTypesList->List();
885 TDataStd_ListOfByte anOldClosuresList;
886 anOldClosuresList = aClosuresList->List();
888 // Refill the existing lists
891 aClosuresList->Clear();
893 TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
894 TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
895 TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
896 for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
897 aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
899 if ( i == theSectionIndex )
900 continue; // skip index to remove
902 aNamesList->Append( aNamesIter.Value() );
903 aTypesList->Append( aTypesIter.Value() );
904 aClosuresList->Append( (bool)aClosuresIter.Value() );
907 // Remove points that belongs to removed section
908 removePointsLists( theSectionIndex );
914 void HYDROData_PolylineXY::RemoveSections()
916 removeSectionsLists();
921 void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
922 const Point& thePoint,
923 const int thePointIndex )
925 Handle(TDataStd_RealList) aListX, aListY;
926 getPointsLists( theSectionIndex, aListX, aListY );
928 if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
930 aListX->Append( thePoint.X() );
931 aListY->Append( thePoint.Y() );
935 TColStd_ListOfReal anOldListX;
936 anOldListX = aListX->List();
938 TColStd_ListOfReal anOldListY;
939 anOldListY = aListY->List();
941 // Refill the existing lists
945 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
946 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
947 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
949 double aCoordX = anIterX.Value();
950 double aCoordY = anIterY.Value();
952 if ( i == thePointIndex )
954 // Insert our new point
955 aListX->Append( thePoint.X() );
956 aListY->Append( thePoint.Y() );
959 aListX->Append( aCoordX );
960 aListY->Append( aCoordY );
967 void HYDROData_PolylineXY::SetPoint( const int theSectionIndex,
968 const Point& thePoint,
969 const int thePointIndex )
971 Handle(TDataStd_RealList) aListX, aListY;
972 getPointsLists( theSectionIndex, aListX, aListY );
974 if ( thePointIndex < 0 )
976 aListX->Prepend( thePoint.X() );
977 aListY->Prepend( thePoint.Y() );
979 else if ( thePointIndex >= aListX->Extent() )
981 aListX->Append( thePoint.X() );
982 aListY->Append( thePoint.Y() );
986 TColStd_ListOfReal anOldListX;
987 anOldListX = aListX->List();
989 TColStd_ListOfReal anOldListY;
990 anOldListY = aListY->List();
992 // Refill the existing lists
996 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
997 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
998 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1000 double aCoordX = anIterX.Value();
1001 double aCoordY = anIterY.Value();
1003 if ( i == thePointIndex )
1005 // Insert our new point instead of old one
1006 aCoordX = thePoint.X();
1007 aCoordY = thePoint.Y();
1010 aListX->Append( aCoordX );
1011 aListY->Append( aCoordY );
1015 SetToUpdate( true );
1018 void HYDROData_PolylineXY::SetPoints( const int theSectionIndex,
1019 const PointsList& thePoints )
1021 Handle(TDataStd_RealList) aListX, aListY;
1022 getPointsLists( theSectionIndex, aListX, aListY );
1027 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1029 const Point& aPoint = thePoints.Value( i );
1030 aListX->Append( aPoint.X() );
1031 aListY->Append( aPoint.Y() );
1035 void HYDROData_PolylineXY::RemovePoint( const int theSectionIndex,
1036 const int thePointIndex )
1038 Handle(TDataStd_RealList) aListX, aListY;
1039 getPointsLists( theSectionIndex, aListX, aListY, false );
1040 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1043 if ( aListX->Extent() == 1 )
1045 removePointsLists( theSectionIndex );
1049 TColStd_ListOfReal anOldListX;
1050 anOldListX = aListX->List();
1052 TColStd_ListOfReal anOldListY;
1053 anOldListY = aListY->List();
1055 // Refill the existing lists
1059 TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
1060 TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
1061 for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
1063 if ( i == thePointIndex )
1064 continue; // skip index to remove
1066 aListX->Append( anIterX.Value() );
1067 aListY->Append( anIterY.Value() );
1071 SetToUpdate( true );
1074 HYDROData_PolylineXY::PointsList HYDROData_PolylineXY::GetPoints( const int theSectionIndex ) const
1076 PointsList aResList;
1078 Handle(TDataStd_RealList) aListX, aListY;
1079 getPointsLists( theSectionIndex, aListX, aListY, false );
1080 if ( aListX.IsNull() || aListY.IsNull() || aListX->IsEmpty() )
1083 TColStd_ListIteratorOfListOfReal anIterX( aListX->List() );
1084 TColStd_ListIteratorOfListOfReal anIterY( aListY->List() );
1085 for ( ; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next() )
1087 Point aPoint( anIterX.Value(), anIterY.Value() );
1088 aResList.Append( aPoint );
1094 QPainterPath HYDROData_PolylineXY::GetPainterPath() const
1098 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1099 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1100 NCollection_Sequence<bool> aSectClosures;
1101 GetSections( aSectNames, aSectTypes, aSectClosures );
1103 for ( int aSectionId = 1, aNbSects = aSectNames.Size(); aSectionId <= aNbSects; aSectionId++ )
1105 TCollection_AsciiString aSectName = aSectNames.Value( aSectionId );
1106 SectionType aSectionType = aSectTypes.Value( aSectionId );
1107 bool anIsSectionClosed = aSectClosures.Value( aSectionId );
1109 PointsList aSectPointsList = GetPoints( aSectionId - 1 );
1110 if ( aSectPointsList.IsEmpty() )
1113 NCollection_Sequence<gp_XYZ> aPoints;
1114 for( int i = 1, n = aSectPointsList.Size(); i <= n; ++i )
1116 const Point& aSectPoint = aSectPointsList.Value( i );
1118 gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
1119 aPoints.Append( aPoint );
1122 BuildPainterPath( aPath, aSectionType, anIsSectionClosed, aPoints );
1128 void HYDROData_PolylineXY::UpdateLocalCS( double theDx, double theDy )
1130 NCollection_Sequence<TCollection_AsciiString> aSectNames;
1131 NCollection_Sequence<HYDROData_PolylineXY::SectionType> aSectTypes;
1132 NCollection_Sequence<bool> aSectClosures;
1133 GetSections( aSectNames, aSectTypes, aSectClosures );
1135 gp_XY aDelta( theDx, theDy );
1136 for ( int i = 0, aNbSects = aSectNames.Size(); i < aNbSects; i++ )
1138 PointsList aPoints = GetPoints( i );
1139 for( int j = 1, n = aPoints.Size(); j <= n; ++j )
1141 Point& aPoint = aPoints.ChangeValue( j );
1144 SetPoints( i, aPoints );
1146 SetToUpdate( true );