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"
11 #include <TopoDS_Wire.hxx>
12 #include <BRepOffsetAPI_MakePipeShell.hxx>
13 #include <BRepOffsetAPI_MakePipe.hxx>
14 #include <BRepCheck_Analyzer.hxx>
15 #include <TopoDS_Vertex.hxx>
16 #include <TopoDS_Face.hxx>
18 //#define DEB_CHANNEL 1
20 #include <BRepTools.hxx>
24 #include <QStringList>
26 #define PYTHON_CHANNEL_ID "KIND_CHANNEL"
28 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
29 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
32 HYDROData_Channel::HYDROData_Channel()
33 : HYDROData_ArtificialObject()
37 HYDROData_Channel::~HYDROData_Channel()
41 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
45 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
46 if ( aDocument.IsNull() )
49 QString aDocName = aDocument->GetDocPyName();
50 QString aChannelName = GetName();
52 aResList << QString( "%1 = %2.CreateObject( %3 );" )
53 .arg( aChannelName ).arg( aDocName ).arg( PYTHON_CHANNEL_ID );
54 aResList << QString( "%1.SetName( \"%2\" );" )
55 .arg( aChannelName ).arg( aChannelName );
56 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())
105 BRepOffsetAPI_MakePipeShell aMkSweep(aPathWire);
106 aMkSweep.Add(aProfileWire,Standard_True, Standard_True);
107 aMkSweep.SetTransitionMode(BRepBuilderAPI_RightCorner);
108 //aMkSweep.SetMode(Standard_True);
110 if(aMkSweep.IsDone()) {
111 const TopoDS_Shape& aChannel = aMkSweep.Shape();
112 BRepCheck_Analyzer aCheck(aChannel);
115 //BRepTools::Write(aChannel, "ChanV.brep");
116 SetShape3D( aMkSweep.Shape());
119 cout <<"NOT VALID" <<endl;
120 BRepTools::Write(aChannel, "ChanNV.brep");
125 // build 2d shape -- temporary solution!!
126 TopoDS_Face aProj = HYDROData_Projection::MakeProjection( GetShape3D() );
127 SetTopShape( aProj );
130 //aMkSweep.Generated() - it seems doesn't work
131 //TopoDS_Vertex aV1,aV2;
132 //TopExp::Vertices (aProfileWire, aV1, aV2);
133 //const TopTools_ListOfShape& aList1 = aMkSweep.Generated(aV1);
134 //const TopTools_ListOfShape& aList2 = aMkSweep.Generated(aV2);
135 //cout <<"List1 = " << aList1.Extent() <<endl;
136 //cout <<"List2 = " << aList2.Extent() <<endl;
137 TopoDS_Wire aPathWire2d = TopoDS::Wire(aGuideLine->GetPolylineXY()->GetShape());
138 if(aPathWire2d.IsNull())
140 TopoDS_Wire aProfileWire2d = TopoDS::Wire( aProfile->GetTopShape() );
141 if(aProfileWire2d.IsNull())
143 //BRepTools::Write(aPathWire2d, "PathWire2.brep");
144 //BRepTools::Write(aProfileWire2d, "ProfileWire2.brep");
145 //BRepOffsetAPI_MakePipeShell aMkSweep2d(aPathWire2d);
146 //aMkSweep2d.Add(aProfileWire2d,Standard_True, Standard_True);
147 //aMkSweep2d.SetTransitionMode(BRepBuilderAPI_RightCorner);
148 //aMkSweep2d.SetMode(Standard_True);
149 //aMkSweep2d.Build();
150 BRepOffsetAPI_MakePipe aMkSweep2d(aPathWire2d, aProfileWire2d);
152 if(aMkSweep2d.IsDone()) {
153 const TopoDS_Shape& aChannel2d = aMkSweep2d.Shape();
154 BRepCheck_Analyzer aCheck(aChannel2d);
157 //BRepTools::Write(aChannel2d, "Chan2dV.brep");
158 SetTopShape( aChannel2d);
162 cout <<"NOT VALID" <<endl;
163 BRepTools::Write(aChannel2d, "Chan2dNV.brep");
169 QColor HYDROData_Channel::DefaultFillingColor()
171 return QColor( Qt::blue );
174 QColor HYDROData_Channel::DefaultBorderColor()
176 return QColor( Qt::transparent );
179 QColor HYDROData_Channel::getDefaultFillingColor() const
181 return DefaultFillingColor();
184 QColor HYDROData_Channel::getDefaultBorderColor() const
186 return DefaultBorderColor();
189 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
191 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
193 if ( theGuideLine.IsNull() )
196 return !aPrevGuideLine.IsNull();
199 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
202 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
203 if ( aHydraulicWire.IsNull() )
204 return false; // The polyline must be a single wire
206 SetReferenceObject( theGuideLine, DataTag_GuideLine );
208 // Indicate model of the need to update the chanel presentation
214 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
216 return Handle(HYDROData_Polyline3D)::DownCast(
217 GetReferenceObject( DataTag_GuideLine ) );
220 void HYDROData_Channel::RemoveGuideLine()
222 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
223 if ( aPrevGuideLine.IsNull() )
226 ClearReferenceObjects( DataTag_GuideLine );
228 // Indicate model of the need to update the chanel presentation
232 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
234 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
236 if ( theProfile.IsNull() )
239 return !aPrevProfile.IsNull();
242 if ( IsEqual( aPrevProfile, theProfile ) )
245 SetReferenceObject( theProfile, DataTag_Profile );
247 // Indicate model of the need to update the chanel presentation
253 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
255 return Handle(HYDROData_Profile)::DownCast(
256 GetReferenceObject( DataTag_Profile ) );
259 void HYDROData_Channel::RemoveProfile()
261 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
262 if ( aPrevProfile.IsNull() )
265 ClearReferenceObjects( DataTag_Profile );
267 // Indicate model of the need to update the chanel presentation
271 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
273 return KIND_OBSTACLE_ALTITUDE;