]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Channel.cxx
Salome HOME
f8e30fbbf434480905e1af09f467dad51c5a7a19
[modules/hydro.git] / src / HYDROData / HYDROData_Channel.cxx
1
2 #include "HYDROData_Channel.h"
3
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Polyline3D.h"
6 #include "HYDROData_Profile.h"
7 #include "HYDROData_PolylineXY.h"
8 #include "HYDROData_Projection.h"
9 #include "HYDROData_ShapesGroup.h"
10 #include "HYDROData_ShapesTool.h"
11 #include "HYDROData_Pipes.h"
12
13 #include <BRepOffsetAPI_MakePipeShell.hxx>
14 #include <BRepOffsetAPI_MakePipe.hxx>
15 #include <BRepCheck_Analyzer.hxx>
16 #include <BRepTools.hxx>
17
18 #include <TopExp.hxx>
19
20 #include <TopoDS.hxx>
21 #include <TopoDS_Wire.hxx>
22 #include <TopoDS_Vertex.hxx>
23 #include <TopoDS_Face.hxx>
24
25 //#define DEB_CHANNEL 1
26 #ifdef DEB_CHANNEL
27 #include <BRepTools.hxx>
28 #endif
29
30 #include <QColor>
31 #include <QStringList>
32
33 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
34
35 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
37
38
39 HYDROData_Channel::HYDROData_Channel()
40 : HYDROData_ArtificialObject()
41 {
42 }
43
44 HYDROData_Channel::~HYDROData_Channel()
45 {
46 }
47
48 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
49 {
50   QStringList aResList;
51
52   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
53   if ( aDocument.IsNull() )
54     return aResList;
55
56   QString aDocName = aDocument->GetDocPyName();
57   QString aChannelName = GetName();
58
59   aResList << QString( "%1 = %2.CreateObject( %3 );" )
60               .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
61   aResList << QString( "%1.SetName( \"%2\" );" )
62               .arg( aChannelName ).arg( aChannelName );
63   aResList << QString( "" );
64
65   // TODO
66
67   return aResList;
68 }
69
70 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
71 {
72   HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
73
74   Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
75   if ( !aGuideLine.IsNull() )
76     aResSeq.Append( aGuideLine );
77
78   Handle(HYDROData_Profile) aProfile = GetProfile();
79   if ( !aProfile.IsNull() )
80     aResSeq.Append( aProfile );
81
82   return aResSeq;
83 }
84
85 TopoDS_Shape HYDROData_Channel::GetTopShape() const
86 {
87   return getTopShape();
88 }
89
90 TopoDS_Shape HYDROData_Channel::GetShape3D() const
91 {
92   return getShape3D();
93 }
94
95 void HYDROData_Channel::Update()
96 {
97   HYDROData_ArtificialObject::Update();
98
99   Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
100   Handle(HYDROData_Profile) aProfile = GetProfile();
101   if ( aGuideLine.IsNull() || aProfile.IsNull() )
102     return;
103
104   // build 3d shape 
105   TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
106   if(aPathWire.IsNull())
107     return;
108   TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
109   if(aProfileWire.IsNull())
110     return;
111
112   //BRepTools::Write( aPathWire, "guideline.brep" );
113   //BRepTools::Write( aProfileWire, "profile.brep" );
114
115   HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
116   aChannelConstructor.Create3dPresentation();
117   aChannelConstructor.Create2dPresentation();
118   SetShape3D( aChannelConstructor.Get3dPresentation() );
119   SetTopShape( aChannelConstructor.Get2dPresentation() );
120
121   // Create groups for channel
122   TopoDS_Wire aLeftBank = aChannelConstructor.GetLeftBank();
123   TopoDS_Wire aRightBank = aChannelConstructor.GetRightBank();
124   TopoDS_Wire anInlet = aChannelConstructor.GetInlet();
125   TopoDS_Wire anOutlet = aChannelConstructor.GetOutlet();
126
127   TopTools_SequenceOfShape aLeftBankEdges;
128   HYDROData_ShapesTool::ExploreShapeToShapes( aLeftBank, TopAbs_EDGE, aLeftBankEdges );
129
130   TopTools_SequenceOfShape aRightBankEdges;
131   HYDROData_ShapesTool::ExploreShapeToShapes( aRightBank, TopAbs_EDGE, aRightBankEdges );
132
133   TopTools_SequenceOfShape anInletEdges;
134   HYDROData_ShapesTool::ExploreShapeToShapes( anInlet, TopAbs_EDGE, anInletEdges );
135
136   TopTools_SequenceOfShape anOutletEdges;
137   HYDROData_ShapesTool::ExploreShapeToShapes( anOutlet, TopAbs_EDGE, anOutletEdges );
138
139   QString aLeftGroupName = GetName() + "_Left_Bank";
140
141   Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
142   aLeftGroup->SetName( aLeftGroupName );
143   aLeftGroup->SetShapes( aLeftBankEdges );
144
145   QString aRightGroupName = GetName() + "_Right_Bank";
146
147   Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
148   aRightGroup->SetName( aRightGroupName );
149   aRightGroup->SetShapes( aRightBankEdges );
150
151   QString anInGroupName = GetName() + "_Inlet";
152
153   Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
154   anInGroup->SetName( anInGroupName );
155   anInGroup->SetShapes( anInletEdges );
156
157   QString anOutGroupName = GetName() + "_Outlet";
158
159   Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
160   anOutGroup->SetName( anOutGroupName );
161   anOutGroup->SetShapes( anOutletEdges );
162 }
163
164 QColor HYDROData_Channel::DefaultFillingColor()
165 {
166   return QColor( Qt::blue );
167 }
168
169 QColor HYDROData_Channel::DefaultBorderColor()
170 {
171   return QColor( Qt::transparent );
172 }
173
174 QColor HYDROData_Channel::getDefaultFillingColor() const
175 {
176   return DefaultFillingColor();
177 }
178
179 QColor HYDROData_Channel::getDefaultBorderColor() const
180 {
181   return DefaultBorderColor();
182 }
183
184 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
185 {
186   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
187
188   if ( theGuideLine.IsNull() )
189   {
190     RemoveGuideLine();
191     return !aPrevGuideLine.IsNull();
192   }
193
194   if ( IsEqual( aPrevGuideLine, theGuideLine ) )
195     return false;
196
197   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
198   if ( aHydraulicWire.IsNull() )
199     return false; // The polyline must be a single wire
200
201   SetReferenceObject( theGuideLine, DataTag_GuideLine );
202
203   // Indicate model of the need to update the chanel presentation
204   SetToUpdate( true );
205
206   return true;
207 }
208
209 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
210 {
211   return Handle(HYDROData_Polyline3D)::DownCast( 
212            GetReferenceObject( DataTag_GuideLine ) );
213 }
214
215 void HYDROData_Channel::RemoveGuideLine()
216 {
217   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
218   if ( aPrevGuideLine.IsNull() )
219     return;
220
221   ClearReferenceObjects( DataTag_GuideLine );
222
223   // Indicate model of the need to update the chanel presentation
224   SetToUpdate( true );
225 }
226
227 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
228 {
229   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
230
231   if ( theProfile.IsNull() )
232   {
233     RemoveProfile();
234     return !aPrevProfile.IsNull();
235   }
236
237   if ( IsEqual( aPrevProfile, theProfile ) )
238     return false;
239
240   SetReferenceObject( theProfile, DataTag_Profile );
241
242   // Indicate model of the need to update the chanel presentation
243   SetToUpdate( true );
244
245   return true;
246 }
247
248 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
249 {
250   return Handle(HYDROData_Profile)::DownCast( 
251            GetReferenceObject( DataTag_Profile ) );
252 }
253
254 void HYDROData_Channel::RemoveProfile()
255 {
256   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
257   if ( aPrevProfile.IsNull() )
258     return;
259
260   ClearReferenceObjects( DataTag_Profile );
261
262   // Indicate model of the need to update the chanel presentation
263   SetToUpdate( true );
264 }
265
266 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
267 {
268   return KIND_OBSTACLE_ALTITUDE;
269 }
270