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