+ TCollection_AsciiString aRes;
+
+ TDF_Label aLabel = myLab.FindChild( DataTag_GeomObjectEntry, false );
+ if ( !aLabel.IsNull() )
+ {
+ Handle(TDataStd_AsciiString) anAsciiStr;
+ if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) )
+ aRes = anAsciiStr->Get();
+ }
+
+ return aRes;
+}
+
+bool convertEdgeToSection( const TopoDS_Edge& theEdge,
+ NCollection_Sequence<TCollection_AsciiString>& theSectNames,
+ NCollection_Sequence<HYDROData_PolylineXY::SectionType>& theSectTypes,
+ NCollection_Sequence<bool>& theSectClosures,
+ NCollection_Sequence<HYDROData_PolylineXY::PointsList>& theSectPoints,
+ bool IsCanBeClosed,
+ bool IsInterpolationAllowed,
+ double theDeflection )
+{
+ Standard_Real aFirst = 0.0, aLast = 0.0;
+ Handle(Geom_Curve) anEdgeGeomCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
+ if ( anEdgeGeomCurve.IsNull() )
+ return false;
+
+ TCollection_AsciiString aSectName = getUniqueSectionName( theSectNames );
+ bool anIsEdgeClosed = anEdgeGeomCurve->IsClosed();
+
+ HYDROData_PolylineXY::SectionType aSectionType = HYDROData_PolylineXY::SECTION_POLYLINE;
+ HYDROData_PolylineXY::PointsList aPointsList;
+
+ if( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_Line) ) )
+ {
+ Handle(Geom_Line) aGeomLine = Handle(Geom_Line)::DownCast( anEdgeGeomCurve );
+
+ gp_Pnt aFirstPoint, aLastPoint;
+ aGeomLine->D0( aFirst, aFirstPoint );
+ aGeomLine->D0( aLast, aLastPoint );
+
+ HYDROData_PolylineXY::Point aSectFirstPoint( aFirstPoint.X(), aFirstPoint.Y() );
+ aPointsList.Append( aSectFirstPoint );
+
+ HYDROData_PolylineXY::Point aSectLastPoint( aLastPoint.X(), aLastPoint.Y() );
+ aPointsList.Append( aSectLastPoint );
+ }
+ else if ( anEdgeGeomCurve->IsKind( STANDARD_TYPE(Geom_BSplineCurve) ) || IsInterpolationAllowed )
+ {
+ aSectionType = HYDROData_PolylineXY::SECTION_SPLINE;
+
+ BRepAdaptor_Curve anAdaptorCurve( theEdge );
+ GCPnts_QuasiUniformDeflection aDiscrete( anAdaptorCurve, theDeflection );
+
+ int aNbPoints = aDiscrete.NbPoints();
+
+ // Decrease the number of imported poles because of last one
+ // pole is the closing point which are the start point
+ if ( anIsEdgeClosed ) aNbPoints--;
+
+ for ( int i = 1; i <= aNbPoints; ++i )
+ {
+ const gp_Pnt& aPoint = aDiscrete.Value( i );
+
+ HYDROData_PolylineXY::Point aSectPoint( aPoint.X(), aPoint.Y() );
+ aPointsList.Append( aSectPoint );
+ }
+ }
+ else
+ {
+ // Other curve types are not supported
+ return false;
+ }
+
+ if ( aPointsList.IsEmpty() )
+ return false;
+
+ theSectNames.Append( aSectName );
+ theSectTypes.Append( aSectionType );
+ theSectClosures.Append( anIsEdgeClosed );
+ theSectPoints.Append( aPointsList );
+
+ return true;
+}
+
+bool HYDROData_PolylineXY::ImportShape( const TopoDS_Shape& theShape,
+ bool IsInterpolationAllowed,
+ double theDeviation )
+{
+ if ( theShape.IsNull() )
+ return false;
+
+ RemoveSections();
+
+ bool anIsCanBeImported = false;
+
+ NCollection_Sequence<TCollection_AsciiString> aSectNames;
+ NCollection_Sequence<SectionType> aSectTypes;
+ NCollection_Sequence<bool> aSectClosures;
+ NCollection_Sequence<PointsList> aSectPoints;
+
+ if ( theShape.ShapeType() == TopAbs_EDGE )
+ {
+ TopoDS_Edge anEdge = TopoDS::Edge( theShape );
+ anIsCanBeImported = convertEdgeToSection( anEdge, aSectNames, aSectTypes,
+ aSectClosures, aSectPoints, true, IsInterpolationAllowed, theDeviation );
+ }
+ else if ( theShape.ShapeType() == TopAbs_WIRE )
+ {
+ TopTools_SequenceOfShape anEdges;
+ HYDROData_ShapesTool::ExploreShapeToShapes( theShape, TopAbs_EDGE, anEdges );
+
+ anIsCanBeImported = !anEdges.IsEmpty();
+ for ( int i = 1, n = anEdges.Length(); i <= n && anIsCanBeImported; ++i )
+ {
+ TopoDS_Edge aWireEdge = TopoDS::Edge( anEdges.Value( i ) );
+ anIsCanBeImported = convertEdgeToSection( aWireEdge, aSectNames, aSectTypes,
+ aSectClosures, aSectPoints, false, IsInterpolationAllowed, theDeviation );
+ }
+ }
+
+ if ( anIsCanBeImported )
+ {
+ for ( int i = 1, n = aSectNames.Length(); i <= n; ++i )
+ {
+ const TCollection_AsciiString& aSectName = aSectNames.Value( i );
+ const SectionType& aSectType = aSectTypes.Value( i );
+ bool anIsSectionClosed = aSectClosures.Value( i );
+ const PointsList& aSectPointsList = aSectPoints( i );
+
+ AddSection( aSectName, aSectType, anIsSectionClosed );
+ SetPoints( i - 1, aSectPointsList );
+ }
+ }
+ else
+ {
+ TopoDS_Shape aShape = theShape;
+
+ if ( theShape.ShapeType() == TopAbs_EDGE )
+ {
+ // We make the wire from incoming edge because of other algorithms
+ // are waiting at least the wire from polyline
+ TopoDS_Edge anEdge = TopoDS::Edge( theShape );
+ BRepBuilderAPI_MakeWire aMakeWire( anEdge );
+ aMakeWire.Build();
+ if ( aMakeWire.IsDone() )
+ aShape = aMakeWire.Wire();
+ }
+
+ gp_Pln aPlane( gp_Pnt( 0, 0, 0 ), gp_Dir( 0, 0, 1 ) );
+ BRepBuilderAPI_MakeFace aMakeFace( aPlane );
+ aMakeFace.Build();
+ BRepOffsetAPI_NormalProjection aProj( aMakeFace.Face() );
+ aProj.Add( aShape );
+ aProj.Build();
+ TopoDS_Shape aResult;
+ if( aProj.IsDone() )
+ aResult = aProj.Shape();
+
+ SetShape( aResult );
+ }
+
+ setEditable( anIsCanBeImported );
+
+ return true;
+}
+
+TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& theType,
+ const bool& theIsClosed,
+ const NCollection_Sequence<gp_XYZ>& thePoints )
+{
+ TopoDS_Wire aWire;
+ if( theType == SECTION_POLYLINE )
+ {
+ int aNbPoints = thePoints.Length();
+ BRepBuilderAPI_MakePolygon aMakeWire;
+ for ( int i = 1, n = aNbPoints; i <= n ; ++i )
+ {
+ gp_XYZ aPoint = thePoints.Value( i );
+ gp_Pnt aPnt( aPoint.X(), aPoint.Y(), aPoint.Z() );
+ aMakeWire.Add( aPnt );
+ }
+ if( theIsClosed && ( aNbPoints > 2 ) )
+ aMakeWire.Close();
+
+ if ( aMakeWire.IsDone() )
+ aWire = aMakeWire.Wire();
+ }
+ else //if( theType == PolylineSection::SECTION_SPLINE )
+ {
+ BRepBuilderAPI_MakeWire aMakeWire;
+
+ if ( thePoints.Size() > 1 )
+ {
+ Handle(Geom_BSplineCurve) aCurve =
+ HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
+
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aCurve ).Edge();
+ aMakeWire.Add( anEdge );
+ }
+ aMakeWire.Build();
+ if ( aMakeWire.IsDone() )
+ aWire = aMakeWire;
+ }
+
+ return aWire;
+}
+
+void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& thePath,
+ const SectionType& theType,
+ const bool& theIsClosed,
+ const NCollection_Sequence<gp_XYZ>& thePoints )
+{
+ if ( thePoints.IsEmpty() )
+ return;
+
+ if ( theType == SECTION_POLYLINE )
+ {
+ const gp_XYZ& aFirstPoint = thePoints.Value( 1 );
+ thePath.moveTo( aFirstPoint.X(), aFirstPoint.Y() );
+
+ for( int i = 2, n = thePoints.Size(); i <= n; ++i )
+ {
+ const gp_XYZ& aSectPoint = thePoints.Value( i );
+
+ thePath.lineTo( aSectPoint.X(), aSectPoint.Y() );
+ }
+
+ if( theIsClosed )
+ thePath.closeSubpath();
+ }
+ else
+ {
+ Handle(Geom_BSplineCurve) aCurve =
+ HYDROData_BSplineOperation::ComputeCurve( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE );
+ HYDROData_BSplineOperation::ComputePath( aCurve, thePath );
+ }