2 #include "HYDROData_Channel.h"
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"
12 #include <BRepOffsetAPI_MakePipeShell.hxx>
13 #include <BRepOffsetAPI_MakePipe.hxx>
14 #include <BRepCheck_Analyzer.hxx>
19 #include <TopoDS_Wire.hxx>
20 #include <TopoDS_Vertex.hxx>
21 #include <TopoDS_Face.hxx>
23 //#define DEB_CHANNEL 1
25 #include <BRepTools.hxx>
29 #include <QStringList>
31 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
33 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
34 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
37 HYDROData_Channel::HYDROData_Channel()
38 : HYDROData_ArtificialObject()
42 HYDROData_Channel::~HYDROData_Channel()
46 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
50 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
51 if ( aDocument.IsNull() )
54 QString aDocName = aDocument->GetDocPyName();
55 QString aChannelName = GetName();
57 aResList << QString( "%1 = %2.CreateObject( %3 );" )
58 .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
59 aResList << QString( "%1.SetName( \"%2\" );" )
60 .arg( aChannelName ).arg( aChannelName );
61 aResList << QString( "" );
68 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
70 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
72 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
73 if ( !aGuideLine.IsNull() )
74 aResSeq.Append( aGuideLine );
76 Handle(HYDROData_Profile) aProfile = GetProfile();
77 if ( !aProfile.IsNull() )
78 aResSeq.Append( aProfile );
83 TopoDS_Shape HYDROData_Channel::GetTopShape() const
88 TopoDS_Shape HYDROData_Channel::GetShape3D() const
93 void HYDROData_Channel::Update()
95 HYDROData_ArtificialObject::Update();
97 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
98 Handle(HYDROData_Profile) aProfile = GetProfile();
99 if ( aGuideLine.IsNull() || aProfile.IsNull() )
103 TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
104 if(aPathWire.IsNull())
106 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
107 if(aProfileWire.IsNull())
110 BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
111 aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
112 aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
113 //aMkSweep.SetMode(Standard_True);
115 if(aMkSweep.IsDone()) {
116 const TopoDS_Shape& aChannel = aMkSweep.Shape();
117 BRepCheck_Analyzer aCheck(aChannel);
120 //BRepTools::Write(aChannel, "ChanV.brep");
121 SetShape3D( aMkSweep.Shape());
124 cout <<"NOT VALID" <<endl;
125 BRepTools::Write(aChannel, "ChanNV.brep");
130 TopoDS_Shape a3dShape = GetShape3D();
131 if ( a3dShape.IsNull() )
134 // build 2d shape -- temporary solution!!
135 TopoDS_Face aProj = HYDROData_Projection::MakeProjection( a3dShape );
136 SetTopShape( aProj );
137 if ( aProj.IsNull() )
140 // Create the channel groups
141 TopoDS_Shape aFirstShape = aMkSweep.FirstShape();
142 TopoDS_Shape aLastShape = aMkSweep.LastShape();
143 if ( aFirstShape.IsNull() || aFirstShape.ShapeType() != TopAbs_WIRE ||
144 aLastShape.IsNull() || aLastShape.ShapeType() != TopAbs_WIRE )
147 TopoDS_Wire anInletWire = TopoDS::Wire( aFirstShape );
148 TopoDS_Wire anOutletWire = TopoDS::Wire( aLastShape );
150 TopoDS_Vertex anInletFirstVert, anInletLastVert;
151 TopExp::Vertices( anInletWire, anInletFirstVert, anInletLastVert );
153 const TopTools_ListOfShape& aGeneratedLeftEdges = aMkSweep.Generated( anInletFirstVert );
154 const TopTools_ListOfShape& aGeneratedRightEdges = aMkSweep.Generated( anInletLastVert );
156 TopTools_SequenceOfShape aProjEdges;
157 HYDROData_ShapesTool::ExploreShapeToShapes( aProj, TopAbs_EDGE, aProjEdges );
159 TopTools_SequenceOfShape aProjLeftEdges;
160 findEdges( aProjEdges, aGeneratedLeftEdges, aProjLeftEdges );
162 TopTools_SequenceOfShape aProjRightEdges;
163 findEdges( aProjEdges, aGeneratedRightEdges, aProjRightEdges );
165 TopTools_SequenceOfShape aProjInletEdges;
166 findEdges( aProjEdges, anInletWire, aProjInletEdges );
168 TopTools_SequenceOfShape aProjOutletEdges;
169 findEdges( aProjEdges, anOutletWire, aProjOutletEdges );
171 QString aLeftGroupName = GetName() + "_Left_Bank";
173 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
174 aLeftGroup->SetName( aLeftGroupName );
175 aLeftGroup->SetShapes( aProjLeftEdges );
177 QString aRightGroupName = GetName() + "_Right_Bank";
179 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
180 aRightGroup->SetName( aRightGroupName );
181 aRightGroup->SetShapes( aProjRightEdges );
183 QString anInGroupName = GetName() + "_Inlet";
185 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
186 anInGroup->SetName( anInGroupName );
187 anInGroup->SetShapes( aProjInletEdges );
189 QString anOutGroupName = GetName() + "_Outlet";
191 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
192 anOutGroup->SetName( anOutGroupName );
193 anOutGroup->SetShapes( aProjOutletEdges );
196 QColor HYDROData_Channel::DefaultFillingColor()
198 return QColor( Qt::blue );
201 QColor HYDROData_Channel::DefaultBorderColor()
203 return QColor( Qt::transparent );
206 QColor HYDROData_Channel::getDefaultFillingColor() const
208 return DefaultFillingColor();
211 QColor HYDROData_Channel::getDefaultBorderColor() const
213 return DefaultBorderColor();
216 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
218 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
220 if ( theGuideLine.IsNull() )
223 return !aPrevGuideLine.IsNull();
226 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
229 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
230 if ( aHydraulicWire.IsNull() )
231 return false; // The polyline must be a single wire
233 SetReferenceObject( theGuideLine, DataTag_GuideLine );
235 // Indicate model of the need to update the chanel presentation
241 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
243 return Handle(HYDROData_Polyline3D)::DownCast(
244 GetReferenceObject( DataTag_GuideLine ) );
247 void HYDROData_Channel::RemoveGuideLine()
249 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
250 if ( aPrevGuideLine.IsNull() )
253 ClearReferenceObjects( DataTag_GuideLine );
255 // Indicate model of the need to update the chanel presentation
259 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
261 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
263 if ( theProfile.IsNull() )
266 return !aPrevProfile.IsNull();
269 if ( IsEqual( aPrevProfile, theProfile ) )
272 SetReferenceObject( theProfile, DataTag_Profile );
274 // Indicate model of the need to update the chanel presentation
280 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
282 return Handle(HYDROData_Profile)::DownCast(
283 GetReferenceObject( DataTag_Profile ) );
286 void HYDROData_Channel::RemoveProfile()
288 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
289 if ( aPrevProfile.IsNull() )
292 ClearReferenceObjects( DataTag_Profile );
294 // Indicate model of the need to update the chanel presentation
298 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
300 return KIND_OBSTACLE_ALTITUDE;
303 void HYDROData_Channel::findEdges( const TopTools_SequenceOfShape& theInShapes,
304 const TopTools_ListOfShape& theEdges3D,
305 TopTools_SequenceOfShape& theOutShapes ) const
307 theOutShapes.Clear();
308 if ( theEdges3D.IsEmpty() || theInShapes.IsEmpty() )
311 const TopoDS_Shape& aFirstShape3D = theEdges3D.First();
312 const TopoDS_Shape& aLastShape3D = theEdges3D.Last();
314 TopoDS_Vertex aFirstVert, aLastVert, aDummyVert;
315 if ( !HYDROData_ShapesTool::Vertices( aFirstShape3D, aFirstVert, aDummyVert ) ||
316 !HYDROData_ShapesTool::Vertices( aLastShape3D, aDummyVert, aLastVert ) )
319 bool isStarted = false;
320 for ( int i = 1, n = theInShapes.Length(); i <= n; ++i )
322 const TopoDS_Shape& anInShape = theInShapes.Value( i );
324 TopoDS_Vertex aShapeFirstVert, aShapeLastVert;
325 if ( !HYDROData_ShapesTool::Vertices( anInShape, aShapeFirstVert, aShapeLastVert ) )
330 isStarted = HYDROData_ShapesTool::IsVerticesEquals( aFirstVert, aShapeFirstVert, true );
335 theOutShapes.Append( anInShape );
337 if ( HYDROData_ShapesTool::IsVerticesEquals( aLastVert, aShapeLastVert, true ) )
343 void HYDROData_Channel::findEdges( const TopTools_SequenceOfShape& theProjShapes,
344 const TopoDS_Shape& theEdge3D,
345 TopTools_SequenceOfShape& theOutShapes ) const
347 TopTools_ListOfShape aTmpList;
348 aTmpList.Append( theEdge3D );
349 findEdges( theProjShapes, aTmpList, theOutShapes );