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"
11 #include "HYDROData_Pipes.h"
13 #include <BRepOffsetAPI_MakePipeShell.hxx>
14 #include <BRepOffsetAPI_MakePipe.hxx>
15 #include <BRepCheck_Analyzer.hxx>
20 #include <TopoDS_Wire.hxx>
21 #include <TopoDS_Vertex.hxx>
22 #include <TopoDS_Face.hxx>
24 //#define DEB_CHANNEL 1
26 #include <BRepTools.hxx>
30 #include <QStringList>
32 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
33 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
36 HYDROData_Channel::HYDROData_Channel()
37 : HYDROData_ArtificialObject()
41 HYDROData_Channel::~HYDROData_Channel()
45 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
47 QStringList aResList = dumpObjectCreation( theTreatedObjects );
48 QString aName = GetObjPyName();
50 Handle(HYDROData_Polyline3D) aRefGideLine = GetGuideLine();
51 setPythonReferenceObject( theTreatedObjects, aResList, aRefGideLine, "SetGuideLine" );
53 Handle(HYDROData_Profile) aRefProfile = GetProfile();
54 setPythonReferenceObject( theTreatedObjects, aResList, aRefProfile, "SetProfile" );
56 aResList << QString( "" );
57 aResList << QString( "%1.Update();" ).arg( aName );
58 aResList << QString( "" );
63 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
65 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
67 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
68 if ( !aGuideLine.IsNull() )
69 aResSeq.Append( aGuideLine );
71 Handle(HYDROData_Profile) aProfile = GetProfile();
72 if ( !aProfile.IsNull() )
73 aResSeq.Append( aProfile );
78 TopoDS_Shape HYDROData_Channel::GetTopShape() const
83 TopoDS_Shape HYDROData_Channel::GetShape3D() const
88 void HYDROData_Channel::Update()
90 HYDROData_ArtificialObject::Update();
92 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
93 Handle(HYDROData_Profile) aProfile = GetProfile();
94 if ( aGuideLine.IsNull() || aProfile.IsNull() )
98 TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
99 if(aPathWire.IsNull())
101 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
102 if(aProfileWire.IsNull())
106 BRepTools::Write( aPathWire, "guideline.brep" );
107 BRepTools::Write( aProfileWire, "profile.brep" );
110 HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
111 aChannelConstructor.Create3dPresentation();
112 aChannelConstructor.Create2dPresentation();
113 SetShape3D( aChannelConstructor.Get3dPresentation() );
114 SetTopShape( aChannelConstructor.Get2dPresentation() );
117 BRepTools::Write( aChannelConstructor.Get2dPresentation(), "channel2d.brep" );
118 BRepTools::Write( aChannelConstructor.Get3dPresentation(), "channel3d.brep" );
121 TopAbs_ShapeEnum aType = GetTopShape().ShapeType();
123 // Create groups for channel
124 TopoDS_Wire aLeftBank = aChannelConstructor.GetLeftBank();
125 TopoDS_Wire aRightBank = aChannelConstructor.GetRightBank();
126 TopoDS_Wire anInlet = aChannelConstructor.GetInlet();
127 TopoDS_Wire anOutlet = aChannelConstructor.GetOutlet();
130 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", GetTopShape(), TopAbs_EDGE );
131 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", aLeftBank, TopAbs_EDGE );
132 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", aRightBank, TopAbs_EDGE );
133 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", anInlet, TopAbs_EDGE );
134 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", anOutlet, TopAbs_EDGE );
137 TopTools_SequenceOfShape aLeftBankEdges;
138 HYDROData_ShapesTool::ExploreShapeToShapes( aLeftBank, TopAbs_EDGE, aLeftBankEdges );
140 TopTools_SequenceOfShape aRightBankEdges;
141 HYDROData_ShapesTool::ExploreShapeToShapes( aRightBank, TopAbs_EDGE, aRightBankEdges );
143 TopTools_SequenceOfShape anInletEdges;
144 HYDROData_ShapesTool::ExploreShapeToShapes( anInlet, TopAbs_EDGE, anInletEdges );
146 TopTools_SequenceOfShape anOutletEdges;
147 HYDROData_ShapesTool::ExploreShapeToShapes( anOutlet, TopAbs_EDGE, anOutletEdges );
149 QString aLeftGroupName = GetName() + "_Left_Bank";
151 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
152 aLeftGroup->SetName( aLeftGroupName );
153 aLeftGroup->SetShapes( aLeftBankEdges );
155 QString aRightGroupName = GetName() + "_Right_Bank";
157 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
158 aRightGroup->SetName( aRightGroupName );
159 aRightGroup->SetShapes( aRightBankEdges );
161 QString anInGroupName = GetName() + "_Inlet";
163 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
164 anInGroup->SetName( anInGroupName );
165 anInGroup->SetShapes( anInletEdges );
167 QString anOutGroupName = GetName() + "_Outlet";
169 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
170 anOutGroup->SetName( anOutGroupName );
171 anOutGroup->SetShapes( anOutletEdges );
174 QColor HYDROData_Channel::DefaultFillingColor()
176 return QColor( Qt::blue );
179 QColor HYDROData_Channel::DefaultBorderColor()
181 return QColor( Qt::transparent );
184 QColor HYDROData_Channel::getDefaultFillingColor() const
186 return DefaultFillingColor();
189 QColor HYDROData_Channel::getDefaultBorderColor() const
191 return DefaultBorderColor();
194 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
196 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
198 if ( theGuideLine.IsNull() )
201 return !aPrevGuideLine.IsNull();
204 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
207 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
208 if ( aHydraulicWire.IsNull() )
209 return false; // The polyline must be a single wire
211 SetReferenceObject( theGuideLine, DataTag_GuideLine );
213 // Indicate model of the need to update the chanel presentation
219 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
221 return Handle(HYDROData_Polyline3D)::DownCast(
222 GetReferenceObject( DataTag_GuideLine ) );
225 void HYDROData_Channel::RemoveGuideLine()
227 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
228 if ( aPrevGuideLine.IsNull() )
231 ClearReferenceObjects( DataTag_GuideLine );
233 // Indicate model of the need to update the chanel presentation
237 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
239 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
241 if ( theProfile.IsNull() )
244 return !aPrevProfile.IsNull();
247 if ( IsEqual( aPrevProfile, theProfile ) )
250 SetReferenceObject( theProfile, DataTag_Profile );
252 // Indicate model of the need to update the chanel presentation
258 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
260 return Handle(HYDROData_Profile)::DownCast(
261 GetReferenceObject( DataTag_Profile ) );
264 void HYDROData_Channel::RemoveProfile()
266 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
267 if ( aPrevProfile.IsNull() )
270 ClearReferenceObjects( DataTag_Profile );
272 // Indicate model of the need to update the chanel presentation
276 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
278 return KIND_OBSTACLE_ALTITUDE;