Salome HOME
Dump to python corrected.
[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   BRepTools::Write( aPathWire, "guideline.brep" );
107   BRepTools::Write( aProfileWire, "profile.brep" );
108
109   HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
110   aChannelConstructor.Create3dPresentation();
111   aChannelConstructor.Create2dPresentation();
112   SetShape3D( aChannelConstructor.Get3dPresentation() );
113   SetTopShape( aChannelConstructor.Get2dPresentation() );
114
115   BRepTools::Write( aChannelConstructor.Get2dPresentation(), "channel2d.brep" );
116   BRepTools::Write( aChannelConstructor.Get3dPresentation(), "channel3d.brep" );
117
118   TopAbs_ShapeEnum aType = GetTopShape().ShapeType();
119
120   // Create groups for channel
121   TopoDS_Wire aLeftBank = aChannelConstructor.GetLeftBank();
122   TopoDS_Wire aRightBank = aChannelConstructor.GetRightBank();
123   TopoDS_Wire anInlet = aChannelConstructor.GetInlet();
124   TopoDS_Wire anOutlet = aChannelConstructor.GetOutlet();
125
126   TopTools_SequenceOfShape aLeftBankEdges;
127   HYDROData_ShapesTool::ExploreShapeToShapes( aLeftBank, TopAbs_EDGE, aLeftBankEdges );
128
129   TopTools_SequenceOfShape aRightBankEdges;
130   HYDROData_ShapesTool::ExploreShapeToShapes( aRightBank, TopAbs_EDGE, aRightBankEdges );
131
132   TopTools_SequenceOfShape anInletEdges;
133   HYDROData_ShapesTool::ExploreShapeToShapes( anInlet, TopAbs_EDGE, anInletEdges );
134
135   TopTools_SequenceOfShape anOutletEdges;
136   HYDROData_ShapesTool::ExploreShapeToShapes( anOutlet, TopAbs_EDGE, anOutletEdges );
137
138   QString aLeftGroupName = GetName() + "_Left_Bank";
139
140   Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
141   aLeftGroup->SetName( aLeftGroupName );
142   aLeftGroup->SetShapes( aLeftBankEdges );
143
144   QString aRightGroupName = GetName() + "_Right_Bank";
145
146   Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
147   aRightGroup->SetName( aRightGroupName );
148   aRightGroup->SetShapes( aRightBankEdges );
149
150   QString anInGroupName = GetName() + "_Inlet";
151
152   Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
153   anInGroup->SetName( anInGroupName );
154   anInGroup->SetShapes( anInletEdges );
155
156   QString anOutGroupName = GetName() + "_Outlet";
157
158   Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
159   anOutGroup->SetName( anOutGroupName );
160   anOutGroup->SetShapes( anOutletEdges );
161 }
162
163 QColor HYDROData_Channel::DefaultFillingColor()
164 {
165   return QColor( Qt::blue );
166 }
167
168 QColor HYDROData_Channel::DefaultBorderColor()
169 {
170   return QColor( Qt::transparent );
171 }
172
173 QColor HYDROData_Channel::getDefaultFillingColor() const
174 {
175   return DefaultFillingColor();
176 }
177
178 QColor HYDROData_Channel::getDefaultBorderColor() const
179 {
180   return DefaultBorderColor();
181 }
182
183 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
184 {
185   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
186
187   if ( theGuideLine.IsNull() )
188   {
189     RemoveGuideLine();
190     return !aPrevGuideLine.IsNull();
191   }
192
193   if ( IsEqual( aPrevGuideLine, theGuideLine ) )
194     return false;
195
196   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
197   if ( aHydraulicWire.IsNull() )
198     return false; // The polyline must be a single wire
199
200   SetReferenceObject( theGuideLine, DataTag_GuideLine );
201
202   // Indicate model of the need to update the chanel presentation
203   SetToUpdate( true );
204
205   return true;
206 }
207
208 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
209 {
210   return Handle(HYDROData_Polyline3D)::DownCast( 
211            GetReferenceObject( DataTag_GuideLine ) );
212 }
213
214 void HYDROData_Channel::RemoveGuideLine()
215 {
216   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
217   if ( aPrevGuideLine.IsNull() )
218     return;
219
220   ClearReferenceObjects( DataTag_GuideLine );
221
222   // Indicate model of the need to update the chanel presentation
223   SetToUpdate( true );
224 }
225
226 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
227 {
228   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
229
230   if ( theProfile.IsNull() )
231   {
232     RemoveProfile();
233     return !aPrevProfile.IsNull();
234   }
235
236   if ( IsEqual( aPrevProfile, theProfile ) )
237     return false;
238
239   SetReferenceObject( theProfile, DataTag_Profile );
240
241   // Indicate model of the need to update the chanel presentation
242   SetToUpdate( true );
243
244   return true;
245 }
246
247 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
248 {
249   return Handle(HYDROData_Profile)::DownCast( 
250            GetReferenceObject( DataTag_Profile ) );
251 }
252
253 void HYDROData_Channel::RemoveProfile()
254 {
255   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
256   if ( aPrevProfile.IsNull() )
257     return;
258
259   ClearReferenceObjects( DataTag_Profile );
260
261   // Indicate model of the need to update the chanel presentation
262   SetToUpdate( true );
263 }
264
265 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
266 {
267   return KIND_OBSTACLE_ALTITUDE;
268 }
269