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>
18 #include <QStringList>
20 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
22 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
23 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
26 HYDROData_Channel::HYDROData_Channel()
27 : HYDROData_ArtificialObject()
31 HYDROData_Channel::~HYDROData_Channel()
35 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
39 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
40 if ( aDocument.IsNull() )
43 QString aDocName = aDocument->GetDocPyName();
44 QString aChannelName = GetName();
46 aResList << QString( "%1 = %2.CreateObject( %3 );" )
47 .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
48 aResList << QString( "%1.SetName( \"%2\" );" )
49 .arg( aChannelName ).arg( aChannelName );
50 aResList << QString( "" );
57 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
59 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
61 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
62 if ( !aGuideLine.IsNull() )
63 aResSeq.Append( aGuideLine );
65 Handle(HYDROData_Profile) aProfile = GetProfile();
66 if ( !aProfile.IsNull() )
67 aResSeq.Append( aProfile );
72 TopoDS_Shape HYDROData_Channel::GetTopShape() const
77 TopoDS_Shape HYDROData_Channel::GetShape3D() const
82 void HYDROData_Channel::Update()
84 HYDROData_ArtificialObject::Update();
86 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
87 Handle(HYDROData_Profile) aProfile = GetProfile();
88 if ( aGuideLine.IsNull() || aProfile.IsNull() )
92 TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
93 if(aPathWire.IsNull())
95 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
96 if(aProfileWire.IsNull())
99 BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
100 aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
101 aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
102 aMkSweep.SetMode(Standard_True);
104 if(aMkSweep.IsDone()) {
105 const TopoDS_Shape& aChannel = aMkSweep.Shape();
106 BRepCheck_Analyzer aCheck(aChannel);
109 //BRepTools::Write(aChannel, "ChanV.brep");
110 SetShape3D( aMkSweep.Shape());
113 cout <<"NOT VALID" <<endl;
114 BRepTools::Write(aChannel, "ChanNV.brep");
120 QColor HYDROData_Channel::DefaultFillingColor()
122 return QColor( Qt::blue );
125 QColor HYDROData_Channel::DefaultBorderColor()
127 return QColor( Qt::transparent );
130 QColor HYDROData_Channel::getDefaultFillingColor() const
132 return DefaultFillingColor();
135 QColor HYDROData_Channel::getDefaultBorderColor() const
137 return DefaultBorderColor();
140 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
142 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
144 if ( theGuideLine.IsNull() )
147 return !aPrevGuideLine.IsNull();
150 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
153 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
154 if ( aHydraulicWire.IsNull() )
155 return false; // The polyline must be a single wire
157 SetReferenceObject( theGuideLine, DataTag_GuideLine );
159 // Indicate model of the need to update the chanel presentation
165 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
167 return Handle(HYDROData_Polyline3D)::DownCast(
168 GetReferenceObject( DataTag_GuideLine ) );
171 void HYDROData_Channel::RemoveGuideLine()
173 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
174 if ( aPrevGuideLine.IsNull() )
177 ClearReferenceObjects( DataTag_GuideLine );
179 // Indicate model of the need to update the chanel presentation
183 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
185 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
187 if ( theProfile.IsNull() )
190 return !aPrevProfile.IsNull();
193 if ( IsEqual( aPrevProfile, theProfile ) )
196 SetReferenceObject( theProfile, DataTag_Profile );
198 // Indicate model of the need to update the chanel presentation
204 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
206 return Handle(HYDROData_Profile)::DownCast(
207 GetReferenceObject( DataTag_Profile ) );
210 void HYDROData_Channel::RemoveProfile()
212 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
213 if ( aPrevProfile.IsNull() )
216 ClearReferenceObjects( DataTag_Profile );
218 // Indicate model of the need to update the chanel presentation