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