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