1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROData_PolylineOperator.h>
20 #include <BRepBuilderAPI_MakeEdge2d.hxx>
21 #include <TopoDS_Edge.hxx>
23 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
25 int aSize = theList.size();
26 int aNewSize = aSize + theList2.size();
31 theList.resize( aNewSize );
32 for( int i=aSize, j=0; i<aNewSize; i++, j++ )
33 theList[i] = theList2[j];
37 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
38 const gp_Pnt2d& thePoint ) const
40 std::vector<gp_Pnt2d> aPointsList( 1 );
41 aPointsList[0] = thePoint;
42 std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
44 for( int i=0, n=aCurves.size(); i<n; i++ )
46 std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
47 bool isLocalOK = CreatePolylines( aCurvesList );
48 isOK = isOK && isLocalOK;
53 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
54 const Handle( HYDROData_PolylineXY )& theTool ) const
56 std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
57 std::vector<Handle( Geom2d_Curve )> aToolCurves = GetCurves( theTool );
59 for( int i=0, n=aCurves.size(); i<n; i++ )
60 for( int j=0, m=aToolCurves.size(); j<m; j++ )
62 std::vector<gp_Pnt2d> aPointsList = Intersection( aCurves[i], aToolCurves[j] );
63 std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
64 bool isLocalOK = CreatePolylines( aCurvesList );
65 isOK = isOK && isLocalOK;
70 bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePolylines )
72 int f = thePolylines.Lower(), l = thePolylines.Upper();
74 std::vector<Handle( Geom2d_Curve )> anAllCurves;
75 for( int i=f; i<=l; i++ )
77 Handle( HYDROData_PolylineXY ) aPolyline = Handle( HYDROData_PolylineXY )::DownCast( thePolylines.Value( i ) );
78 std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( aPolyline );
79 append( anAllCurves, aCurves );
82 for( int i=0, n=anAllCurves.size(); i<n; i++ )
84 std::vector<gp_Pnt2d> aCompletePointsList;
85 for( int j=0; j<n; j++ )
89 std::vector<gp_Pnt2d> aPointsList = Intersection( anAllCurves[i], anAllCurves[j] );
90 append( aCompletePointsList, aPointsList );
92 std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( anAllCurves[i], aCompletePointsList );
93 bool isLocalOK = CreatePolylines( aCurvesList );
94 isOK = isOK && isLocalOK;
99 bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines )
105 std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline )
107 std::vector<Handle( Geom2d_Curve )> aResult;
112 std::vector<gp_Pnt2d> HYDROData_PolylineOperator::Intersection( const Handle( Geom2d_Curve )& theCurve,
113 const Handle( Geom2d_Curve )& theTool )
115 std::vector<gp_Pnt2d> aResult;
120 std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::Split( const Handle( Geom2d_Curve )& theCurve,
121 const std::vector<gp_Pnt2d>& thePoints )
123 std::vector<Handle( Geom2d_Curve )> aResult;
128 bool HYDROData_PolylineOperator::CreatePolylines( const std::vector<Handle( Geom2d_Curve )>& theCurves )
130 int n = theCurves.size();
131 for( int i=0; i<n; i++ )
133 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge2d( theCurves[i] ).Edge();