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"
10 #include <TopoDS_Wire.hxx>
11 #include <BRepOffsetAPI_MakePipeShell.hxx>
12 #include <BRepOffsetAPI_MakePipe.hxx>
13 #include <BRepCheck_Analyzer.hxx>
14 #include <TopoDS_Vertex.hxx>
16 //#define DEB_CHANNEL 1
18 #include <BRepTools.hxx>
22 #include <QStringList>
24 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
26 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
27 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
30 HYDROData_Channel::HYDROData_Channel()
31 : HYDROData_ArtificialObject()
35 HYDROData_Channel::~HYDROData_Channel()
39 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
43 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
44 if ( aDocument.IsNull() )
47 QString aDocName = aDocument->GetDocPyName();
48 QString aChannelName = GetName();
50 aResList << QString( "%1 = %2.CreateObject( %3 );" )
51 .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
52 aResList << QString( "%1.SetName( \"%2\" );" )
53 .arg( aChannelName ).arg( aChannelName );
54 aResList << QString( "" );
61 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
63 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
65 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
66 if ( !aGuideLine.IsNull() )
67 aResSeq.Append( aGuideLine );
69 Handle(HYDROData_Profile) aProfile = GetProfile();
70 if ( !aProfile.IsNull() )
71 aResSeq.Append( aProfile );
76 TopoDS_Shape HYDROData_Channel::GetTopShape() const
81 TopoDS_Shape HYDROData_Channel::GetShape3D() const
86 void HYDROData_Channel::Update()
88 HYDROData_ArtificialObject::Update();
90 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
91 Handle(HYDROData_Profile) aProfile = GetProfile();
92 if ( aGuideLine.IsNull() || aProfile.IsNull() )
96 TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
97 if(aPathWire.IsNull())
99 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
100 if(aProfileWire.IsNull())
103 BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
104 aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
105 aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
106 aMkSweep.SetMode(Standard_True);
108 if(aMkSweep.IsDone()) {
109 const TopoDS_Shape& aChannel = aMkSweep.Shape();
110 BRepCheck_Analyzer aCheck(aChannel);
113 //BRepTools::Write(aChannel, "ChanV.brep");
114 SetShape3D( aMkSweep.Shape());
117 cout <<"NOT VALID" <<endl;
118 BRepTools::Write(aChannel, "ChanNV.brep");
123 // build 2d shape -- temporary solution!!
124 //aMkSweep.Generated() - it seems doesn't work
125 //TopoDS_Vertex aV1,aV2;
126 //TopExp::Vertices (aProfileWire, aV1, aV2);
127 //const TopTools_ListOfShape& aList1 = aMkSweep.Generated(aV1);
128 //const TopTools_ListOfShape& aList2 = aMkSweep.Generated(aV2);
129 //cout <<"List1 = " << aList1.Extent() <<endl;
130 //cout <<"List2 = " << aList2.Extent() <<endl;
131 TopoDS_Wire aPathWire2d = TopoDS::Wire(aGuideLine->GetPolylineXY()->GetShape());
132 if(aPathWire2d.IsNull())
134 TopoDS_Wire aProfileWire2d = TopoDS::Wire( aProfile->GetTopShape() );
135 if(aProfileWire2d.IsNull())
137 //BRepTools::Write(aPathWire2d, "PathWire2.brep");
138 //BRepTools::Write(aProfileWire2d, "ProfileWire2.brep");
139 //BRepOffsetAPI_MakePipeShell aMkSweep2d(aPathWire2d);
140 //aMkSweep2d.Add(aProfileWire2d,Standard_True, Standard_True);
141 //aMkSweep2d.SetTransitionMode(BRepBuilderAPI_RightCorner);
142 //aMkSweep2d.SetMode(Standard_True);
143 //aMkSweep2d.Build();
144 BRepOffsetAPI_MakePipe aMkSweep2d(aPathWire2d, aProfileWire2d);
146 if(aMkSweep2d.IsDone()) {
147 const TopoDS_Shape& aChannel2d = aMkSweep2d.Shape();
148 BRepCheck_Analyzer aCheck(aChannel2d);
151 //BRepTools::Write(aChannel2d, "Chan2dV.brep");
152 SetTopShape( aChannel2d);
156 cout <<"NOT VALID" <<endl;
157 BRepTools::Write(aChannel2d, "Chan2dNV.brep");
163 QColor HYDROData_Channel::DefaultFillingColor()
165 return QColor( Qt::blue );
168 QColor HYDROData_Channel::DefaultBorderColor()
170 return QColor( Qt::transparent );
173 QColor HYDROData_Channel::getDefaultFillingColor() const
175 return DefaultFillingColor();
178 QColor HYDROData_Channel::getDefaultBorderColor() const
180 return DefaultBorderColor();
183 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
185 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
187 if ( theGuideLine.IsNull() )
190 return !aPrevGuideLine.IsNull();
193 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
196 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
197 if ( aHydraulicWire.IsNull() )
198 return false; // The polyline must be a single wire
200 SetReferenceObject( theGuideLine, DataTag_GuideLine );
202 // Indicate model of the need to update the chanel presentation
208 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
210 return Handle(HYDROData_Polyline3D)::DownCast(
211 GetReferenceObject( DataTag_GuideLine ) );
214 void HYDROData_Channel::RemoveGuideLine()
216 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
217 if ( aPrevGuideLine.IsNull() )
220 ClearReferenceObjects( DataTag_GuideLine );
222 // Indicate model of the need to update the chanel presentation
226 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
228 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
230 if ( theProfile.IsNull() )
233 return !aPrevProfile.IsNull();
236 if ( IsEqual( aPrevProfile, theProfile ) )
239 SetReferenceObject( theProfile, DataTag_Profile );
241 // Indicate model of the need to update the chanel presentation
247 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
249 return Handle(HYDROData_Profile)::DownCast(
250 GetReferenceObject( DataTag_Profile ) );
253 void HYDROData_Channel::RemoveProfile()
255 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
256 if ( aPrevProfile.IsNull() )
259 ClearReferenceObjects( DataTag_Profile );
261 // Indicate model of the need to update the chanel presentation