+ aResult = aCmp;
+ }
+ }
+ else if (aSeqEdges->Length() == 1)
+ {
+ BRepBuilderAPI_MakeWire mkWire (TopoDS::Edge(aSeqEdges->Value(1)));
+ if (mkWire.IsDone())
+ aResult = mkWire.Wire();
+ }
+
+ setPolylineShape( aResult );
+}
+
+bool HYDROData_PolylineXY::IsHas2dPrs() const
+{
+ return true;
+}
+
+bool HYDROData_PolylineXY::IsEditable() const
+{
+ return !myLab.IsAttribute( GUID_IS_UNEDITABLE );
+}
+
+void HYDROData_PolylineXY::setEditable( const bool theIsEditable )
+{
+ if ( !theIsEditable )
+ TDataStd_UAttribute::Set( myLab, GUID_IS_UNEDITABLE );
+ else
+ myLab.ForgetAttribute( GUID_IS_UNEDITABLE );
+}
+
+/**
+ * Returns true if polyline is closed
+ */
+bool HYDROData_PolylineXY::IsClosed( const bool theIsSimpleCheck ) const
+{
+ bool anIsClosed = false;
+
+ TopoDS_Shape aShape = GetShape();
+ if ( aShape.IsNull() )
+ return anIsClosed;
+
+ TopTools_SequenceOfShape aWires;
+ HYDROData_ShapesTool::ExploreShapeToShapes( aShape, TopAbs_WIRE, aWires );
+
+ int aNbWires = aWires.Length();
+ if ( theIsSimpleCheck )
+ {
+ anIsClosed = aNbWires > 0;
+ for ( int i = 1; i <= aNbWires && anIsClosed; ++i )
+ {
+ const TopoDS_Shape& aWire = aWires.Value( i );
+ anIsClosed = BRep_Tool::IsClosed( aWire );
+ }
+ }
+ else
+ {
+ anIsClosed = aNbWires == 1 && BRep_Tool::IsClosed( aWires.First() );
+ }
+
+ return anIsClosed;
+}
+
+double HYDROData_PolylineXY::GetDistance( const int theSectionIndex,
+ const int thePointIndex ) const
+{
+ double aResDistance = -1;
+ if ( theSectionIndex < 0 || theSectionIndex >= NbSections() )
+ return aResDistance;
+
+ if ( thePointIndex == 0 )
+ return 0.0;
+
+ SectionType aSectionType = GetSectionType( theSectionIndex );
+ bool anIsSectionClosed = IsClosedSection( theSectionIndex );
+ PointsList aSectPointsList = GetPoints( theSectionIndex );
+ if ( thePointIndex < 0 || thePointIndex >= aSectPointsList.Size() )
+ return aResDistance;
+
+ if ( aSectionType == SECTION_POLYLINE )
+ {
+ aResDistance = 0.0;
+
+ Point aPrevPoint = aSectPointsList.Value( 1 );
+ for ( int i = 2, aNbPoints = aSectPointsList.Size(); i <= aNbPoints; ++i )
+ {
+ const Point& aSectPoint = aSectPointsList.Value( i );
+ aResDistance += gp_Pnt2d( aPrevPoint ).Distance( aSectPoint );
+ aPrevPoint = aSectPoint;
+
+ if ( thePointIndex == i - 1 )
+ break;
+ }
+ }
+ else
+ {
+ gp_XYZ aPointToTest;
+
+ int aSectNbPoints = aSectPointsList.Size();
+ NCollection_Sequence<gp_XYZ> aPoints;
+ for( int i = 1 ; i <= aSectNbPoints; ++i )
+ {
+ const Point& aSectPoint = aSectPointsList.Value( i );
+
+ gp_XYZ aPoint( aSectPoint.X(), aSectPoint.Y(), 0.0 );
+ aPoints.Append( aPoint );
+
+ if ( thePointIndex == i - 1 )
+ aPointToTest = aPoint;
+ }
+
+ HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE );
+
+ Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter();
+ Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter();
+
+ if ( thePointIndex != aSectNbPoints - 1 )
+ {
+ GeomAPI_ProjectPointOnCurve aProject( aPointToTest, aBSpline.Curve() );
+ aSecondParam = aProject.LowerDistanceParameter();
+ }
+
+ GeomAdaptor_Curve anAdap( aBSpline.Curve() );
+
+ aResDistance = GCPnts_AbscissaPoint::Length( anAdap, aFirstParam, aSecondParam );
+ }
+
+ return aResDistance;
+}
+
+int HYDROData_PolylineXY::NbSections() const
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+
+ return !aClosuresList.IsNull() ? aClosuresList->Extent() : 0;
+}
+
+void HYDROData_PolylineXY::AddSection( const TCollection_AsciiString& theSectName,
+ const SectionType theSectionType,
+ const bool theIsClosed )
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList );
+
+ TCollection_ExtendedString aSectName( theSectName );
+ if ( aSectName.Length() <= 0 )
+ aSectName = getUniqueSectionName( aNamesList );
+
+ aNamesList->Append( aSectName );
+ aTypesList->Append( theSectionType );
+ aClosuresList->Append( theIsClosed );
+
+ SetToUpdate( true );
+}
+
+TCollection_AsciiString HYDROData_PolylineXY::GetSectionName( const int theSectionIndex ) const
+{
+ TCollection_AsciiString aResName;
+
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
+ return aResName;
+
+ TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
+ for ( int i = 0; aNamesIter.More() && i != theSectionIndex; aNamesIter.Next(), ++i );
+
+ if ( aNamesIter.More() )
+ aResName = aNamesIter.Value();
+
+ return aResName;
+}
+
+void HYDROData_PolylineXY::SetSectionName( const int theSectionIndex,
+ const TCollection_AsciiString& theSectionName )
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
+ return;
+
+ TDataStd_ListOfExtendedString anOldNamesList;
+ anOldNamesList = aNamesList->List();
+
+ // Refill the existing list
+ aNamesList->Clear();
+
+ TCollection_ExtendedString aNewSectName = theSectionName;
+
+ TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
+ for ( int i = 0; aNamesIter.More(); aNamesIter.Next(), ++i )
+ aNamesList->Append( i == theSectionIndex ? aNewSectName : aNamesIter.Value() );
+
+ SetToUpdate( true );
+}
+
+HYDROData_PolylineXY::SectionType HYDROData_PolylineXY::GetSectionType( const int theSectionIndex ) const
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
+ return SECTION_POLYLINE;
+
+ TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
+ for ( int i = 0; aTypesIter.More() && i != theSectionIndex; aTypesIter.Next(), ++i );
+
+ return aTypesIter.More() ? (SectionType)aTypesIter.Value() : SECTION_POLYLINE;
+}
+
+void HYDROData_PolylineXY::SetSectionType( const int theSectionIndex,
+ const SectionType theSectionType )
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aTypesList.IsNull() || theSectionIndex >= aTypesList->Extent() )
+ return;
+
+ TColStd_ListOfInteger anOldTypesList;
+ anOldTypesList = aTypesList->List();
+
+ // Refill the existing list
+ aTypesList->Clear();
+
+ TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
+ for ( int i = 0; aTypesIter.More(); aTypesIter.Next(), ++i )
+ aTypesList->Append( i == theSectionIndex ? theSectionType : aTypesIter.Value() );
+
+ SetToUpdate( true );
+}
+
+bool HYDROData_PolylineXY::IsClosedSection( const int theSectionIndex ) const
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
+ return false;
+
+ TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
+ for ( int i = 0; aClosuresIter.More() && i != theSectionIndex; aClosuresIter.Next(), ++i );
+
+ return aClosuresIter.More() ? (bool)aClosuresIter.Value() : false;
+}
+
+void HYDROData_PolylineXY::SetSectionClosed( const int theSectionIndex,
+ const bool theIsClosed )
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aClosuresList.IsNull() || theSectionIndex >= aClosuresList->Extent() )
+ return;
+
+ TDataStd_ListOfByte anOldClosuresList;
+ anOldClosuresList = aClosuresList->List();
+
+ // Refill the existing list
+ aClosuresList->Clear();
+
+ TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
+ for ( int i = 0; aClosuresIter.More(); aClosuresIter.Next(), ++i )
+ aClosuresList->Append( i == theSectionIndex ? theIsClosed : (bool)aClosuresIter.Value() );
+
+ SetToUpdate( true );
+}
+
+void HYDROData_PolylineXY::GetSections( NCollection_Sequence<TCollection_AsciiString>& theSectNames,
+ NCollection_Sequence<SectionType>& theSectTypes,
+ NCollection_Sequence<bool>& theSectClosures ) const
+{
+ theSectNames.Clear();
+ theSectTypes.Clear();
+ theSectClosures.Clear();
+
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aNamesList.IsNull() || aTypesList.IsNull() || aClosuresList.IsNull() )
+ return;
+
+ TDataStd_ListIteratorOfListOfExtendedString aNamesIter( aNamesList->List() );
+ TColStd_ListIteratorOfListOfInteger aTypesIter( aTypesList->List() );
+ TDataStd_ListIteratorOfListOfByte aClosuresIter( aClosuresList->List() );
+ for ( ; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
+ aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next() )
+ {
+ const TCollection_ExtendedString& aSectName = aNamesIter.Value();
+ SectionType aSectType = (SectionType)aTypesIter.Value();
+ bool aSectClosures = aClosuresIter.Value();
+
+ theSectNames.Append( aSectName );
+ theSectTypes.Append( aSectType );
+ theSectClosures.Append( aSectClosures );
+ }
+}
+
+void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
+{
+ Handle(TDataStd_ExtStringList) aNamesList;
+ Handle(TDataStd_IntegerList) aTypesList;
+ Handle(TDataStd_BooleanList) aClosuresList;
+ getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+ if ( aNamesList.IsNull() || theSectionIndex >= aNamesList->Extent() )
+ return;
+
+ if ( aNamesList->Extent() == 1 )
+ {
+ removeSectionsLists();
+ removePointsLists();
+ }
+ else
+ {
+ TDataStd_ListOfExtendedString anOldNamesList;
+ anOldNamesList = aNamesList->List();
+
+ TColStd_ListOfInteger anOldTypesList;
+ anOldTypesList = aTypesList->List();
+
+ TDataStd_ListOfByte anOldClosuresList;
+ anOldClosuresList = aClosuresList->List();
+
+ // Refill the existing lists
+ aNamesList->Clear();
+ aTypesList->Clear();
+ aClosuresList->Clear();
+
+ TDataStd_ListIteratorOfListOfExtendedString aNamesIter( anOldNamesList );
+ TColStd_ListIteratorOfListOfInteger aTypesIter( anOldTypesList );
+ TDataStd_ListIteratorOfListOfByte aClosuresIter( anOldClosuresList );
+ for ( int i = 0; aNamesIter.More() && aTypesIter.More() && aClosuresIter.More();
+ aNamesIter.Next(), aTypesIter.Next(), aClosuresIter.Next(), ++i )
+ {
+ if ( i == theSectionIndex )
+ continue; // skip index to remove
+
+ aNamesList->Append( aNamesIter.Value() );
+ aTypesList->Append( aTypesIter.Value() );
+ aClosuresList->Append( (bool)aClosuresIter.Value() );
+ }
+
+ // Remove points that belongs to removed section
+ removePointsLists( theSectionIndex );
+ }
+
+ SetToUpdate( true );
+}
+
+void HYDROData_PolylineXY::RemoveSections()
+{
+ removeSectionsLists();
+ removePointsLists();
+ SetToUpdate( true );
+}
+
+void HYDROData_PolylineXY::AddPoint( const int theSectionIndex,
+ const Point& thePoint,
+ const int thePointIndex )
+{
+ Handle(TDataStd_RealList) aListX, aListY;
+ getPointsLists( theSectionIndex, aListX, aListY );
+
+ if ( thePointIndex < 0 || thePointIndex >= aListX->Extent() )
+ {
+ aListX->Append( thePoint.X() );
+ aListY->Append( thePoint.Y() );
+ }
+ else
+ {
+ TColStd_ListOfReal anOldListX;
+ anOldListX = aListX->List();
+
+ TColStd_ListOfReal anOldListY;
+ anOldListY = aListY->List();
+
+ // Refill the existing lists
+ aListX->Clear();
+ aListY->Clear();
+
+ TColStd_ListIteratorOfListOfReal anIterX( anOldListX );
+ TColStd_ListIteratorOfListOfReal anIterY( anOldListY );
+ for ( int i = 0; anIterX.More() && anIterY.More(); anIterX.Next(), anIterY.Next(), ++i )
+ {
+ double aCoordX = anIterX.Value();
+ double aCoordY = anIterY.Value();
+
+ if ( i == thePointIndex )