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>
23 //#define DEB_CHANNEL 1
25 #include <BRepTools.hxx>
29 #include <QStringList>
31 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
32 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
35 HYDROData_Channel::HYDROData_Channel()
36 : HYDROData_ArtificialObject()
40 HYDROData_Channel::~HYDROData_Channel()
44 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
46 QStringList aResList = dumpObjectCreation( theTreatedObjects );
47 QString aName = GetObjPyName();
49 Handle(HYDROData_Polyline3D) aRefGideLine = GetGuideLine();
50 setPythonReferenceObject( theTreatedObjects, aResList, aRefGideLine, "SetGuideLine" );
52 Handle(HYDROData_Profile) aRefProfile = GetProfile();
53 setPythonReferenceObject( theTreatedObjects, aResList, aRefProfile, "SetProfile" );
55 aResList << QString( "" );
56 aResList << QString( "%1.Update();" ).arg( aName );
57 aResList << QString( "" );
62 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
64 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
66 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
67 if ( !aGuideLine.IsNull() )
68 aResSeq.Append( aGuideLine );
70 Handle(HYDROData_Profile) aProfile = GetProfile();
71 if ( !aProfile.IsNull() )
72 aResSeq.Append( aProfile );
77 TopoDS_Shape HYDROData_Channel::GetTopShape() const
82 TopoDS_Shape HYDROData_Channel::GetShape3D() const
87 bool HYDROData_Channel::CreatePresentaions( const Handle(HYDROData_Polyline3D)& theGuideLine,
88 const Handle(HYDROData_Profile)& theProfile,
89 PrsDefinition& thePrs )
91 if ( theGuideLine.IsNull() || theProfile.IsNull() )
95 TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() );
96 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() );
97 if ( aPathWire.IsNull() || aProfileWire.IsNull() )
101 BRepTools::Write( aPathWire, "guideline.brep" );
102 BRepTools::Write( aProfileWire, "profile.brep" );
105 HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
106 if( aChannelConstructor.GetStatus() != 0 )
109 aChannelConstructor.Create3dPresentation();
110 aChannelConstructor.Create2dPresentation();
111 thePrs.myPrs3D = aChannelConstructor.Get3dPresentation();
112 thePrs.myPrs2D = aChannelConstructor.Get2dPresentation();
114 thePrs.myLeftBank = aChannelConstructor.GetLeftBank();
115 thePrs.myRightBank = aChannelConstructor.GetRightBank();
116 thePrs.myInlet = aChannelConstructor.GetInlet();
117 thePrs.myOutlet = aChannelConstructor.GetOutlet();
120 BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" );
121 BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" );
122 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE );
123 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE );
124 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE );
125 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE );
126 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE );
132 void HYDROData_Channel::Update()
134 HYDROData_ArtificialObject::Update();
136 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
137 Handle(HYDROData_Profile) aProfile = GetProfile();
139 PrsDefinition aResultPrs;
140 if ( !CreatePresentaions( aGuideLine, aProfile, aResultPrs ) )
143 SetShape3D( aResultPrs.myPrs3D );
144 SetTopShape( aResultPrs.myPrs2D );
146 // Create groups for channel
147 TopTools_SequenceOfShape aLeftBankEdges;
148 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myLeftBank, TopAbs_EDGE, aLeftBankEdges );
150 TopTools_SequenceOfShape aRightBankEdges;
151 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myRightBank, TopAbs_EDGE, aRightBankEdges );
153 TopTools_SequenceOfShape anInletEdges;
154 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myInlet, TopAbs_EDGE, anInletEdges );
156 TopTools_SequenceOfShape anOutletEdges;
157 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myOutlet, TopAbs_EDGE, anOutletEdges );
159 QString aLeftGroupName = GetName() + "_Left_Bank";
161 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
162 aLeftGroup->SetName( aLeftGroupName );
163 aLeftGroup->SetShapes( aLeftBankEdges );
165 QString aRightGroupName = GetName() + "_Right_Bank";
167 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
168 aRightGroup->SetName( aRightGroupName );
169 aRightGroup->SetShapes( aRightBankEdges );
171 QString anInGroupName = GetName() + "_Inlet";
173 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
174 anInGroup->SetName( anInGroupName );
175 anInGroup->SetShapes( anInletEdges );
177 QString anOutGroupName = GetName() + "_Outlet";
179 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
180 anOutGroup->SetName( anOutGroupName );
181 anOutGroup->SetShapes( anOutletEdges );
184 bool HYDROData_Channel::IsHas2dPrs() const
189 QColor HYDROData_Channel::DefaultFillingColor()
191 return QColor( Qt::blue );
194 QColor HYDROData_Channel::DefaultBorderColor()
196 return QColor( Qt::transparent );
199 QColor HYDROData_Channel::getDefaultFillingColor() const
201 return DefaultFillingColor();
204 QColor HYDROData_Channel::getDefaultBorderColor() const
206 return DefaultBorderColor();
209 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
211 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
213 if ( theGuideLine.IsNull() )
216 return !aPrevGuideLine.IsNull();
219 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
222 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
223 if ( aHydraulicWire.IsNull() )
224 return false; // The polyline must be a single wire
226 SetReferenceObject( theGuideLine, DataTag_GuideLine );
228 // Indicate model of the need to update the chanel presentation
234 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
236 return Handle(HYDROData_Polyline3D)::DownCast(
237 GetReferenceObject( DataTag_GuideLine ) );
240 void HYDROData_Channel::RemoveGuideLine()
242 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
243 if ( aPrevGuideLine.IsNull() )
246 ClearReferenceObjects( DataTag_GuideLine );
248 // Indicate model of the need to update the chanel presentation
252 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
254 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
256 if ( theProfile.IsNull() )
259 return !aPrevProfile.IsNull();
262 if ( IsEqual( aPrevProfile, theProfile ) )
265 SetReferenceObject( theProfile, DataTag_Profile );
267 // Indicate model of the need to update the chanel presentation
273 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
275 return Handle(HYDROData_Profile)::DownCast(
276 GetReferenceObject( DataTag_Profile ) );
279 void HYDROData_Channel::RemoveProfile()
281 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
282 if ( aPrevProfile.IsNull() )
285 ClearReferenceObjects( DataTag_Profile );
287 // Indicate model of the need to update the chanel presentation
291 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
293 return KIND_OBSTACLE_ALTITUDE;