2 #include "HYDROData_Channel.h"
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Polyline3D.h"
6 #include "HYDROData_Profile.h"
9 #include <TopoDS_Wire.hxx>
10 #include <BRepOffsetAPI_MakePipeShell.hxx>
11 #include <BRepCheck_Analyzer.hxx>
12 //#define DEB_CHANNEL 1
14 #include <BRepTools.hxx>
17 #include <QStringList>
19 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
21 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
22 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
25 HYDROData_Channel::HYDROData_Channel()
26 : HYDROData_ArtificialObject()
30 HYDROData_Channel::~HYDROData_Channel()
34 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
38 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
39 if ( aDocument.IsNull() )
42 QString aDocName = aDocument->GetDocPyName();
43 QString aChannelName = GetName();
45 aResList << QString( "%1 = %2.CreateObject( %3 );" )
46 .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
47 aResList << QString( "%1.SetName( \"%2\" );" )
48 .arg( aChannelName ).arg( aChannelName );
49 aResList << QString( "" );
56 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
58 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
60 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
61 if ( !aGuideLine.IsNull() )
62 aResSeq.Append( aGuideLine );
64 Handle(HYDROData_Profile) aProfile = GetProfile();
65 if ( !aProfile.IsNull() )
66 aResSeq.Append( aProfile );
71 TopoDS_Shape HYDROData_Channel::GetTopShape() const
76 TopoDS_Shape HYDROData_Channel::GetShape3D() const
81 void HYDROData_Channel::Update()
83 HYDROData_ArtificialObject::Update();
85 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
86 Handle(HYDROData_Profile) aProfile = GetProfile();
87 if ( aGuideLine.IsNull() || aProfile.IsNull() )
91 TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
92 if(aPathWire.IsNull())
94 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
95 if(aProfileWire.IsNull())
98 BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
99 aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
100 aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
101 aMkSweep.SetMode(Standard_True);
103 if(aMkSweep.IsDone()) {
104 const TopoDS_Shape& aChannel = aMkSweep.Shape();
105 BRepCheck_Analyzer aCheck(aChannel);
108 //BRepTools::Write(aChannel, "ChanV.brep");
109 SetShape3D( aMkSweep.Shape());
112 cout <<"NOT VALID" <<endl;
113 BRepTools::Write(aChannel, "ChanNV.brep");
119 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
121 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
123 if ( theGuideLine.IsNull() )
126 return !aPrevGuideLine.IsNull();
129 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
132 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
133 if ( aHydraulicWire.IsNull() )
134 return false; // The polyline must be a single wire
136 SetReferenceObject( theGuideLine, DataTag_GuideLine );
138 // Indicate model of the need to update the chanel presentation
144 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
146 return Handle(HYDROData_Polyline3D)::DownCast(
147 GetReferenceObject( DataTag_GuideLine ) );
150 void HYDROData_Channel::RemoveGuideLine()
152 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
153 if ( aPrevGuideLine.IsNull() )
156 ClearReferenceObjects( DataTag_GuideLine );
158 // Indicate model of the need to update the chanel presentation
162 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
164 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
166 if ( theProfile.IsNull() )
169 return !aPrevProfile.IsNull();
172 if ( IsEqual( aPrevProfile, theProfile ) )
175 SetReferenceObject( theProfile, DataTag_Profile );
177 // Indicate model of the need to update the chanel presentation
183 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
185 return Handle(HYDROData_Profile)::DownCast(
186 GetReferenceObject( DataTag_Profile ) );
189 void HYDROData_Channel::RemoveProfile()
191 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
192 if ( aPrevProfile.IsNull() )
195 ClearReferenceObjects( DataTag_Profile );
197 // Indicate model of the need to update the chanel presentation