]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Channel.cxx
Salome HOME
Altitude objects for Obstacle, Stream and Channel objects base implementation (Bug...
[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
10 #include <TopoDS.hxx>
11 #include <TopoDS_Wire.hxx>
12 #include <BRepOffsetAPI_MakePipeShell.hxx>
13 #include <BRepOffsetAPI_MakePipe.hxx>
14 #include <BRepCheck_Analyzer.hxx>
15 #include <TopoDS_Vertex.hxx>
16 #include <TopoDS_Face.hxx>
17 #include <TopExp.hxx>
18 //#define DEB_CHANNEL 1
19 #ifdef DEB_CHANNEL
20 #include <BRepTools.hxx>
21 #endif
22
23 #include <QColor>
24 #include <QStringList>
25
26 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
27
28 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
29 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
30
31
32 HYDROData_Channel::HYDROData_Channel()
33 : HYDROData_ArtificialObject()
34 {
35 }
36
37 HYDROData_Channel::~HYDROData_Channel()
38 {
39 }
40
41 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
42 {
43   QStringList aResList;
44
45   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
46   if ( aDocument.IsNull() )
47     return aResList;
48
49   QString aDocName = aDocument->GetDocPyName();
50   QString aChannelName = GetName();
51
52   aResList << QString( "%1 = %2.CreateObject( %3 );" )
53               .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
54   aResList << QString( "%1.SetName( \"%2\" );" )
55               .arg( aChannelName ).arg( aChannelName );
56   aResList << QString( "" );
57
58   // TODO
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   BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
106   aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
107   aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
108   //aMkSweep.SetMode(Standard_True);
109   aMkSweep.Build();
110   if(aMkSweep.IsDone())  { 
111         const TopoDS_Shape& aChannel = aMkSweep.Shape();
112     BRepCheck_Analyzer aCheck(aChannel);
113     if(aCheck.IsValid()) 
114         {
115       //BRepTools::Write(aChannel, "ChanV.brep");  
116       SetShape3D( aMkSweep.Shape());
117         } else {
118 #ifdef DEB_CHANNEL
119           cout <<"NOT VALID" <<endl;
120           BRepTools::Write(aChannel, "ChanNV.brep");  
121 #endif
122         }
123   }
124
125   // build 2d shape -- temporary solution!!
126   TopoDS_Face aProj = HYDROData_Projection::MakeProjection( GetShape3D() );
127   SetTopShape( aProj );
128
129   /*
130   //aMkSweep.Generated() - it seems doesn't work
131   //TopoDS_Vertex aV1,aV2;
132   //TopExp::Vertices (aProfileWire, aV1, aV2);
133   //const TopTools_ListOfShape& aList1 = aMkSweep.Generated(aV1);
134   //const TopTools_ListOfShape& aList2 = aMkSweep.Generated(aV2);
135   //cout <<"List1 = " << aList1.Extent() <<endl;
136   //cout <<"List2 = " << aList2.Extent() <<endl;
137   TopoDS_Wire aPathWire2d = TopoDS::Wire(aGuideLine->GetPolylineXY()->GetShape()); 
138   if(aPathWire2d.IsNull())
139     return;
140   TopoDS_Wire aProfileWire2d = TopoDS::Wire( aProfile->GetTopShape() ); 
141   if(aProfileWire2d.IsNull())
142         return;
143   //BRepTools::Write(aPathWire2d, "PathWire2.brep");  
144   //BRepTools::Write(aProfileWire2d, "ProfileWire2.brep");  
145   //BRepOffsetAPI_MakePipeShell aMkSweep2d(aPathWire2d);
146   //aMkSweep2d.Add(aProfileWire2d,Standard_True, Standard_True);
147   //aMkSweep2d.SetTransitionMode(BRepBuilderAPI_RightCorner);
148   //aMkSweep2d.SetMode(Standard_True);
149   //aMkSweep2d.Build();
150    BRepOffsetAPI_MakePipe aMkSweep2d(aPathWire2d, aProfileWire2d);
151    aMkSweep2d.Build();
152   if(aMkSweep2d.IsDone())        { 
153         const TopoDS_Shape& aChannel2d = aMkSweep2d.Shape();
154     BRepCheck_Analyzer aCheck(aChannel2d);
155     if(aCheck.IsValid()) 
156         {
157       //BRepTools::Write(aChannel2d, "Chan2dV.brep");  
158       SetTopShape( aChannel2d);
159         }
160 #ifdef DEB_CHANNEL      
161         else {
162           cout <<"NOT VALID" <<endl;
163           BRepTools::Write(aChannel2d, "Chan2dNV.brep");  
164         }
165 #endif
166   }*/
167 }
168
169 QColor HYDROData_Channel::DefaultFillingColor()
170 {
171   return QColor( Qt::blue );
172 }
173
174 QColor HYDROData_Channel::DefaultBorderColor()
175 {
176   return QColor( Qt::transparent );
177 }
178
179 QColor HYDROData_Channel::getDefaultFillingColor() const
180 {
181   return DefaultFillingColor();
182 }
183
184 QColor HYDROData_Channel::getDefaultBorderColor() const
185 {
186   return DefaultBorderColor();
187 }
188
189 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
190 {
191   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
192
193   if ( theGuideLine.IsNull() )
194   {
195     RemoveGuideLine();
196     return !aPrevGuideLine.IsNull();
197   }
198
199   if ( IsEqual( aPrevGuideLine, theGuideLine ) )
200     return false;
201
202   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
203   if ( aHydraulicWire.IsNull() )
204     return false; // The polyline must be a single wire
205
206   SetReferenceObject( theGuideLine, DataTag_GuideLine );
207
208   // Indicate model of the need to update the chanel presentation
209   SetToUpdate( true );
210
211   return true;
212 }
213
214 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
215 {
216   return Handle(HYDROData_Polyline3D)::DownCast( 
217            GetReferenceObject( DataTag_GuideLine ) );
218 }
219
220 void HYDROData_Channel::RemoveGuideLine()
221 {
222   Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
223   if ( aPrevGuideLine.IsNull() )
224     return;
225
226   ClearReferenceObjects( DataTag_GuideLine );
227
228   // Indicate model of the need to update the chanel presentation
229   SetToUpdate( true );
230 }
231
232 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
233 {
234   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
235
236   if ( theProfile.IsNull() )
237   {
238     RemoveProfile();
239     return !aPrevProfile.IsNull();
240   }
241
242   if ( IsEqual( aPrevProfile, theProfile ) )
243     return false;
244
245   SetReferenceObject( theProfile, DataTag_Profile );
246
247   // Indicate model of the need to update the chanel presentation
248   SetToUpdate( true );
249
250   return true;
251 }
252
253 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
254 {
255   return Handle(HYDROData_Profile)::DownCast( 
256            GetReferenceObject( DataTag_Profile ) );
257 }
258
259 void HYDROData_Channel::RemoveProfile()
260 {
261   Handle(HYDROData_Profile) aPrevProfile = GetProfile();
262   if ( aPrevProfile.IsNull() )
263     return;
264
265   ClearReferenceObjects( DataTag_Profile );
266
267   // Indicate model of the need to update the chanel presentation
268   SetToUpdate( true );
269 }
270
271 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
272 {
273   return KIND_OBSTACLE_ALTITUDE;
274 }