Salome HOME
#refs 522 (very draft) //import only
[modules/hydro.git] / src / HYDROData / HYDROData_Channel.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROData_Channel.h"
24
25 #include "HYDROData_Document.h"
26 #include "HYDROData_Polyline3D.h"
27 #include "HYDROData_Profile.h"
28 #include "HYDROData_PolylineXY.h"
29 #include "HYDROData_Projection.h"
30 #include "HYDROData_ShapesGroup.h"
31 #include "HYDROData_ShapesTool.h"
32 #include "HYDROData_Pipes.h"
33
34 #include <BRepOffsetAPI_MakePipeShell.hxx>
35 #include <BRepOffsetAPI_MakePipe.hxx>
36 #include <BRepCheck_Analyzer.hxx>
37
38 #include <TopExp.hxx>
39
40 #include <TopoDS.hxx>
41 #include <TopoDS_Wire.hxx>
42 #include <TopoDS_Vertex.hxx>
43
44 //#define DEB_CHANNEL 1
45 #ifdef DEB_CHANNEL
46 #include <BRepTools.hxx>
47 #endif
48
49 #include <QColor>
50 #include <QStringList>
51
52 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
53 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
54
55
56 HYDROData_Channel::HYDROData_Channel()
57 : HYDROData_ArtificialObject()
58 {
59 }
60
61 HYDROData_Channel::~HYDROData_Channel()
62 {
63 }
64
65 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
66 {
67   QStringList aResList = dumpObjectCreation( theTreatedObjects );
68   QString aName = GetObjPyName();
69
70   Handle(HYDROData_Polyline3D) aRefGideLine = GetGuideLine();
71   setPythonReferenceObject( theTreatedObjects, aResList, aRefGideLine, "SetGuideLine" );
72
73   Handle(HYDROData_Profile) aRefProfile = GetProfile();
74   setPythonReferenceObject( theTreatedObjects, aResList, aRefProfile, "SetProfile" );
75
76   aResList << QString( "" );
77   aResList << QString( "%1.Update();" ).arg( aName );
78   aResList << QString( "" );
79
80   return aResList;
81 }
82
83 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
84 {
85   HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
86
87   Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
88   if ( !aGuideLine.IsNull() )
89     aResSeq.Append( aGuideLine );
90
91   Handle(HYDROData_Profile) aProfile = GetProfile();
92   if ( !aProfile.IsNull() )
93     aResSeq.Append( aProfile );
94
95   return aResSeq;
96 }
97
98 TopoDS_Shape HYDROData_Channel::GetTopShape() const
99 {
100   return getTopShape();
101 }
102
103 TopoDS_Shape HYDROData_Channel::GetShape3D() const
104 {
105   return getShape3D();
106 }
107
108 bool HYDROData_Channel::CreatePresentations( const Handle(HYDROData_Polyline3D)& theGuideLine,
109                                             const Handle(HYDROData_Profile)&    theProfile,
110                                             PrsDefinition&                      thePrs )
111 {
112   if ( theGuideLine.IsNull() || theProfile.IsNull() )
113     return false;
114
115   // build 3d shape 
116   TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() );
117   TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() );
118   if ( aPathWire.IsNull() || aProfileWire.IsNull() )
119     return false;
120
121 #ifdef DEB_CHANNEL
122   BRepTools::Write( aPathWire, "guideline.brep" );
123   BRepTools::Write( aProfileWire, "profile.brep" );
124 #endif
125
126   HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
127   if( aChannelConstructor.GetStatus() != 0 )
128     return false;
129
130   aChannelConstructor.Create3dPresentation();
131   aChannelConstructor.Create2dPresentation();
132   thePrs.myPrs3D = aChannelConstructor.Get3dPresentation();
133   thePrs.myPrs2D = aChannelConstructor.Get2dPresentation();
134
135   thePrs.myLeftBank = aChannelConstructor.GetLeftBank();
136   thePrs.myRightBank = aChannelConstructor.GetRightBank();
137   thePrs.myInlet = aChannelConstructor.GetInlet();
138   thePrs.myOutlet = aChannelConstructor.GetOutlet();
139
140 #ifdef DEB_CHANNEL
141   BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" );
142   BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" );
143   HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE );
144   HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE );
145   HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE );
146   HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE );
147   HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE );
148 #endif
149
150   return true;
151 }
152
153 void HYDROData_Channel::Update()
154 {
155   HYDROData_ArtificialObject::Update();
156
157   Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
158   Handle(HYDROData_Profile) aProfile = GetProfile();
159
160   PrsDefinition aResultPrs;
161   if ( !CreatePresentations( aGuideLine, aProfile, aResultPrs ) )
162     return;
163
164   SetShape3D( aResultPrs.myPrs3D );
165   SetTopShape( aResultPrs.myPrs2D );
166
167   // Create groups for channel
168   TopTools_SequenceOfShape aLeftBankEdges;
169   HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myLeftBank, TopAbs_EDGE, aLeftBankEdges );
170
171   TopTools_SequenceOfShape aRightBankEdges;
172   HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myRightBank, TopAbs_EDGE, aRightBankEdges );
173
174   TopTools_SequenceOfShape anInletEdges;
175   HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myInlet, TopAbs_EDGE, anInletEdges );
176
177   TopTools_SequenceOfShape anOutletEdges;
178   HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myOutlet, TopAbs_EDGE, anOutletEdges );
179
180   QString aLeftGroupName = GetName() + "_Left_Bank";
181
182   Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
183   aLeftGroup->SetName( aLeftGroupName );
184   aLeftGroup->SetShapes( aLeftBankEdges );
185
186   QString aRightGroupName = GetName() + "_Right_Bank";
187
188   Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
189   aRightGroup->SetName( aRightGroupName );
190   aRightGroup->SetShapes( aRightBankEdges );
191
192   QString anInGroupName = GetName() + "_Inlet";
193
194   Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
195   anInGroup->SetName( anInGroupName );
196   anInGroup->SetShapes( anInletEdges );
197
198   QString anOutGroupName = GetName() + "_Outlet";
199
200   Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
201   anOutGroup->SetName( anOutGroupName );
202   anOutGroup->SetShapes( anOutletEdges );
203 }
204
205 bool HYDROData_Channel::IsHas2dPrs() const
206 {
207   return true;
208 }
209
210 QColor HYDROData_Channel::DefaultFillingColor()
211 {
212   return QColor( Qt::blue );
213 }
214
215 QColor HYDROData_Channel::DefaultBorderColor()
216 {
217   return QColor( Qt::transparent );
218 }
219
220 QColor HYDROData_Channel::getDefaultFillingColor() const
221 {
222   return DefaultFillingColor();
223 }
224
225 QColor HYDROData_Channel::getDefaultBorderColor() const
226 {
227   return DefaultBorderColor();
228 }
229
230 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
231 {
232   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
233
234   if ( theGuideLine.IsNull() )
235   {
236     RemoveGuideLine();
237     return !aPrevGuideLine.IsNull();
238   }
239
240   if ( IsEqual( aPrevGuideLine, theGuideLine ) )
241     return false;
242
243   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
244   if ( aHydraulicWire.IsNull() )
245     return false; // The polyline must be a single wire
246
247   SetReferenceObject( theGuideLine, DataTag_GuideLine );
248
249   // Indicate model of the need to update the chanel presentation
250   SetToUpdate( true );
251
252   return true;
253 }
254
255 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
256 {
257   return Handle(HYDROData_Polyline3D)::DownCast( 
258            GetReferenceObject( DataTag_GuideLine ) );
259 }
260
261 void HYDROData_Channel::RemoveGuideLine()
262 {
263   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
264   if ( aPrevGuideLine.IsNull() )
265     return;
266
267   ClearReferenceObjects( DataTag_GuideLine );
268
269   // Indicate model of the need to update the chanel presentation
270   SetToUpdate( true );
271 }
272
273 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
274 {
275   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
276
277   if ( theProfile.IsNull() )
278   {
279     RemoveProfile();
280     return !aPrevProfile.IsNull();
281   }
282
283   if ( IsEqual( aPrevProfile, theProfile ) )
284     return false;
285
286   SetReferenceObject( theProfile, DataTag_Profile );
287
288   // Indicate model of the need to update the chanel presentation
289   SetToUpdate( true );
290
291   return true;
292 }
293
294 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
295 {
296   return Handle(HYDROData_Profile)::DownCast( 
297            GetReferenceObject( DataTag_Profile ) );
298 }
299
300 void HYDROData_Channel::RemoveProfile()
301 {
302   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
303   if ( aPrevProfile.IsNull() )
304     return;
305
306   ClearReferenceObjects( DataTag_Profile );
307
308   // Indicate model of the need to update the chanel presentation
309   SetToUpdate( true );
310 }
311
312 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
313 {
314   return KIND_OBSTACLE_ALTITUDE;
315 }
316