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