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