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