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