]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Channel.cxx
Salome HOME
check status of channel constructor
[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 QColor HYDROData_Channel::DefaultFillingColor()
178 {
179   return QColor( Qt::blue );
180 }
181
182 QColor HYDROData_Channel::DefaultBorderColor()
183 {
184   return QColor( Qt::transparent );
185 }
186
187 QColor HYDROData_Channel::getDefaultFillingColor() const
188 {
189   return DefaultFillingColor();
190 }
191
192 QColor HYDROData_Channel::getDefaultBorderColor() const
193 {
194   return DefaultBorderColor();
195 }
196
197 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
198 {
199   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
200
201   if ( theGuideLine.IsNull() )
202   {
203     RemoveGuideLine();
204     return !aPrevGuideLine.IsNull();
205   }
206
207   if ( IsEqual( aPrevGuideLine, theGuideLine ) )
208     return false;
209
210   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
211   if ( aHydraulicWire.IsNull() )
212     return false; // The polyline must be a single wire
213
214   SetReferenceObject( theGuideLine, DataTag_GuideLine );
215
216   // Indicate model of the need to update the chanel presentation
217   SetToUpdate( true );
218
219   return true;
220 }
221
222 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
223 {
224   return Handle(HYDROData_Polyline3D)::DownCast( 
225            GetReferenceObject( DataTag_GuideLine ) );
226 }
227
228 void HYDROData_Channel::RemoveGuideLine()
229 {
230   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
231   if ( aPrevGuideLine.IsNull() )
232     return;
233
234   ClearReferenceObjects( DataTag_GuideLine );
235
236   // Indicate model of the need to update the chanel presentation
237   SetToUpdate( true );
238 }
239
240 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
241 {
242   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
243
244   if ( theProfile.IsNull() )
245   {
246     RemoveProfile();
247     return !aPrevProfile.IsNull();
248   }
249
250   if ( IsEqual( aPrevProfile, theProfile ) )
251     return false;
252
253   SetReferenceObject( theProfile, DataTag_Profile );
254
255   // Indicate model of the need to update the chanel presentation
256   SetToUpdate( true );
257
258   return true;
259 }
260
261 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
262 {
263   return Handle(HYDROData_Profile)::DownCast( 
264            GetReferenceObject( DataTag_Profile ) );
265 }
266
267 void HYDROData_Channel::RemoveProfile()
268 {
269   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
270   if ( aPrevProfile.IsNull() )
271     return;
272
273   ClearReferenceObjects( DataTag_Profile );
274
275   // Indicate model of the need to update the chanel presentation
276   SetToUpdate( true );
277 }
278
279 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
280 {
281   return KIND_OBSTACLE_ALTITUDE;
282 }
283