Salome HOME
Merge branch 'BR_v14_rc' of ssh://git.salome-platform.org/modules/hydro into BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_PolylineOperator.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROData_PolylineOperator.h>
20 #include <BRepBuilderAPI_MakeEdge2d.hxx>
21 #include <TopoDS_Edge.hxx>
22
23 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
24 {
25   int aSize = theList.size();
26   int aNewSize = aSize + theList2.size();
27
28   if( aSize==aNewSize )
29     return;
30
31   theList.resize( aNewSize );
32   for( int i=aSize, j=0; i<aNewSize; i++, j++ )
33     theList[i] = theList2[j];
34 }
35
36
37 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
38                                         const gp_Pnt2d& thePoint ) const
39 {
40   std::vector<gp_Pnt2d> aPointsList( 1 );
41   aPointsList[0] = thePoint;
42   std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
43   bool isOK = true;
44   for( int i=0, n=aCurves.size(); i<n; i++ )
45   {
46     std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( aCurves[i], aPointsList );
47     bool isLocalOK = CreatePolylines( aCurvesList );
48     isOK = isOK && isLocalOK;
49   }
50   return isOK;
51 }
52
53 bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_PolylineXY )& thePolyline,
54                                         const Handle( HYDROData_PolylineXY )& theTool ) const
55 {
56   std::vector<Handle( Geom2d_Curve )> aCurves = GetCurves( thePolyline );
57   std::vector<Handle( Geom2d_Curve )> aToolCurves = GetCurves( theTool );
58   bool isOK = true;
59   for( int i=0, n=aCurves.size(); i<n; i++ )
60     for( int j=0, m=aToolCurves.size(); j<m; j++ )
61     {
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;
66     }
67   return isOK;
68 }
69
70 bool HYDROData_PolylineOperator::Split( const HYDROData_SequenceOfObjects& thePolylines )
71 {
72   int f = thePolylines.Lower(), l = thePolylines.Upper();
73   bool isOK = true;
74   std::vector<Handle( Geom2d_Curve )> anAllCurves;
75   for( int i=f; i<=l; i++ )
76   {
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 );
80   }
81
82   for( int i=0, n=anAllCurves.size(); i<n; i++ )
83   {
84     std::vector<gp_Pnt2d> aCompletePointsList;
85     for( int j=0; j<n; j++ )
86     {
87       if( i==j )
88         continue;
89       std::vector<gp_Pnt2d> aPointsList = Intersection( anAllCurves[i], anAllCurves[j] );
90       append( aCompletePointsList, aPointsList );
91     }
92     std::vector<Handle( Geom2d_Curve )> aCurvesList = Split( anAllCurves[i], aCompletePointsList );
93     bool isLocalOK = CreatePolylines( aCurvesList );
94     isOK = isOK && isLocalOK;
95   }
96   return isOK;
97 }
98
99 bool HYDROData_PolylineOperator::Merge( const HYDROData_SequenceOfObjects& thePolylines )
100 {
101   //TODO
102   return true;
103 }
104
105 std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::GetCurves( const Handle( HYDROData_PolylineXY )& thePolyline )
106 {
107   std::vector<Handle( Geom2d_Curve )> aResult;
108   //TODO
109   return aResult;
110 }
111
112 std::vector<gp_Pnt2d> HYDROData_PolylineOperator::Intersection( const Handle( Geom2d_Curve )& theCurve,
113                                                                 const Handle( Geom2d_Curve )& theTool )
114 {
115   std::vector<gp_Pnt2d> aResult;
116   //TODO
117   return aResult;
118 }
119
120 std::vector<Handle( Geom2d_Curve )> HYDROData_PolylineOperator::Split( const Handle( Geom2d_Curve )& theCurve,
121                                                                        const std::vector<gp_Pnt2d>& thePoints )
122 {
123   std::vector<Handle( Geom2d_Curve )> aResult;
124   //TODO
125   return aResult;
126 }
127
128 bool HYDROData_PolylineOperator::CreatePolylines( const std::vector<Handle( Geom2d_Curve )>& theCurves )
129 {
130   int n = theCurves.size();
131   for( int i=0; i<n; i++ )
132   {
133     TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge2d( theCurves[i] ).Edge();
134     //TODO
135   }
136   return true;
137 }