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 if( aChannelConstructor.GetStatus() != 0 )
114 aChannelConstructor.Create3dPresentation();
115 aChannelConstructor.Create2dPresentation();
116 SetShape3D( aChannelConstructor.Get3dPresentation() );
117 SetTopShape( aChannelConstructor.Get2dPresentation() );
120 BRepTools::Write( aChannelConstructor.Get2dPresentation(), "channel2d.brep" );
121 BRepTools::Write( aChannelConstructor.Get3dPresentation(), "channel3d.brep" );
124 TopAbs_ShapeEnum aType = GetTopShape().ShapeType();
126 // Create groups for channel
127 TopoDS_Wire aLeftBank = aChannelConstructor.GetLeftBank();
128 TopoDS_Wire aRightBank = aChannelConstructor.GetRightBank();
129 TopoDS_Wire anInlet = aChannelConstructor.GetInlet();
130 TopoDS_Wire anOutlet = aChannelConstructor.GetOutlet();
133 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", GetTopShape(), TopAbs_EDGE );
134 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", aLeftBank, TopAbs_EDGE );
135 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", aRightBank, TopAbs_EDGE );
136 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", anInlet, TopAbs_EDGE );
137 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", anOutlet, TopAbs_EDGE );
140 TopTools_SequenceOfShape aLeftBankEdges;
141 HYDROData_ShapesTool::ExploreShapeToShapes( aLeftBank, TopAbs_EDGE, aLeftBankEdges );
143 TopTools_SequenceOfShape aRightBankEdges;
144 HYDROData_ShapesTool::ExploreShapeToShapes( aRightBank, TopAbs_EDGE, aRightBankEdges );
146 TopTools_SequenceOfShape anInletEdges;
147 HYDROData_ShapesTool::ExploreShapeToShapes( anInlet, TopAbs_EDGE, anInletEdges );
149 TopTools_SequenceOfShape anOutletEdges;
150 HYDROData_ShapesTool::ExploreShapeToShapes( anOutlet, TopAbs_EDGE, anOutletEdges );
152 QString aLeftGroupName = GetName() + "_Left_Bank";
154 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
155 aLeftGroup->SetName( aLeftGroupName );
156 aLeftGroup->SetShapes( aLeftBankEdges );
158 QString aRightGroupName = GetName() + "_Right_Bank";
160 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
161 aRightGroup->SetName( aRightGroupName );
162 aRightGroup->SetShapes( aRightBankEdges );
164 QString anInGroupName = GetName() + "_Inlet";
166 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
167 anInGroup->SetName( anInGroupName );
168 anInGroup->SetShapes( anInletEdges );
170 QString anOutGroupName = GetName() + "_Outlet";
172 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
173 anOutGroup->SetName( anOutGroupName );
174 anOutGroup->SetShapes( anOutletEdges );
177 QColor HYDROData_Channel::DefaultFillingColor()
179 return QColor( Qt::blue );
182 QColor HYDROData_Channel::DefaultBorderColor()
184 return QColor( Qt::transparent );
187 QColor HYDROData_Channel::getDefaultFillingColor() const
189 return DefaultFillingColor();
192 QColor HYDROData_Channel::getDefaultBorderColor() const
194 return DefaultBorderColor();
197 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
199 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
201 if ( theGuideLine.IsNull() )
204 return !aPrevGuideLine.IsNull();
207 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
210 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
211 if ( aHydraulicWire.IsNull() )
212 return false; // The polyline must be a single wire
214 SetReferenceObject( theGuideLine, DataTag_GuideLine );
216 // Indicate model of the need to update the chanel presentation
222 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
224 return Handle(HYDROData_Polyline3D)::DownCast(
225 GetReferenceObject( DataTag_GuideLine ) );
228 void HYDROData_Channel::RemoveGuideLine()
230 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
231 if ( aPrevGuideLine.IsNull() )
234 ClearReferenceObjects( DataTag_GuideLine );
236 // Indicate model of the need to update the chanel presentation
240 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
242 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
244 if ( theProfile.IsNull() )
247 return !aPrevProfile.IsNull();
250 if ( IsEqual( aPrevProfile, theProfile ) )
253 SetReferenceObject( theProfile, DataTag_Profile );
255 // Indicate model of the need to update the chanel presentation
261 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
263 return Handle(HYDROData_Profile)::DownCast(
264 GetReferenceObject( DataTag_Profile ) );
267 void HYDROData_Channel::RemoveProfile()
269 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
270 if ( aPrevProfile.IsNull() )
273 ClearReferenceObjects( DataTag_Profile );
275 // Indicate model of the need to update the chanel presentation
279 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
281 return KIND_OBSTACLE_ALTITUDE;