1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_Channel.h"
21 #include "HYDROData_Document.h"
22 #include "HYDROData_Polyline3D.h"
23 #include "HYDROData_Profile.h"
24 #include "HYDROData_PolylineXY.h"
25 #include "HYDROData_Projection.h"
26 #include "HYDROData_ShapesGroup.h"
27 #include "HYDROData_ShapesTool.h"
28 #include "HYDROData_Pipes.h"
30 #include <BRepOffsetAPI_MakePipeShell.hxx>
31 #include <BRepOffsetAPI_MakePipe.hxx>
32 #include <BRepCheck_Analyzer.hxx>
37 #include <TopoDS_Wire.hxx>
38 #include <TopoDS_Vertex.hxx>
40 //#define DEB_CHANNEL 1
42 #include <BRepTools.hxx>
46 #include <QStringList>
48 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
49 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
52 HYDROData_Channel::HYDROData_Channel()
53 : HYDROData_ArtificialObject()
57 HYDROData_Channel::~HYDROData_Channel()
61 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
63 QStringList aResList = dumpObjectCreation( theTreatedObjects );
64 QString aName = GetObjPyName();
66 Handle(HYDROData_Polyline3D) aRefGideLine = GetGuideLine();
67 setPythonReferenceObject( theTreatedObjects, aResList, aRefGideLine, "SetGuideLine" );
69 Handle(HYDROData_Profile) aRefProfile = GetProfile();
70 setPythonReferenceObject( theTreatedObjects, aResList, aRefProfile, "SetProfile" );
72 aResList << QString( "" );
73 aResList << QString( "%1.Update();" ).arg( aName );
74 aResList << QString( "" );
79 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
81 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
83 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
84 if ( !aGuideLine.IsNull() )
85 aResSeq.Append( aGuideLine );
87 Handle(HYDROData_Profile) aProfile = GetProfile();
88 if ( !aProfile.IsNull() )
89 aResSeq.Append( aProfile );
94 TopoDS_Shape HYDROData_Channel::GetTopShape() const
99 TopoDS_Shape HYDROData_Channel::GetShape3D() const
104 bool HYDROData_Channel::CreatePresentations( const Handle(HYDROData_Polyline3D)& theGuideLine,
105 const Handle(HYDROData_Profile)& theProfile,
106 PrsDefinition& thePrs )
108 if ( theGuideLine.IsNull() || theProfile.IsNull() )
112 TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() );
113 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() );
114 if ( aPathWire.IsNull() || aProfileWire.IsNull() )
118 BRepTools::Write( aPathWire, "guideline.brep" );
119 BRepTools::Write( aProfileWire, "profile.brep" );
122 HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
123 if( aChannelConstructor.GetStatus() != 0 )
126 aChannelConstructor.Create3dPresentation();
127 aChannelConstructor.Create2dPresentation();
128 thePrs.myPrs3D = aChannelConstructor.Get3dPresentation();
129 thePrs.myPrs2D = aChannelConstructor.Get2dPresentation();
131 thePrs.myLeftBank = aChannelConstructor.GetLeftBank();
132 thePrs.myRightBank = aChannelConstructor.GetRightBank();
133 thePrs.myInlet = aChannelConstructor.GetInlet();
134 thePrs.myOutlet = aChannelConstructor.GetOutlet();
137 BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" );
138 BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" );
139 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE );
140 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE );
141 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE );
142 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE );
143 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE );
149 void HYDROData_Channel::Update()
151 HYDROData_ArtificialObject::Update();
153 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
154 Handle(HYDROData_Profile) aProfile = GetProfile();
156 PrsDefinition aResultPrs;
157 if ( !CreatePresentations( aGuideLine, aProfile, aResultPrs ) )
160 SetShape3D( aResultPrs.myPrs3D );
161 SetTopShape( aResultPrs.myPrs2D );
163 // Create groups for channel
164 TopTools_SequenceOfShape aLeftBankEdges;
165 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myLeftBank, TopAbs_EDGE, aLeftBankEdges );
167 TopTools_SequenceOfShape aRightBankEdges;
168 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myRightBank, TopAbs_EDGE, aRightBankEdges );
170 TopTools_SequenceOfShape anInletEdges;
171 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myInlet, TopAbs_EDGE, anInletEdges );
173 TopTools_SequenceOfShape anOutletEdges;
174 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myOutlet, TopAbs_EDGE, anOutletEdges );
176 QString aLeftGroupName = GetName() + "_Left_Bank";
178 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
179 aLeftGroup->SetName( aLeftGroupName );
180 aLeftGroup->SetShapes( aLeftBankEdges );
182 QString aRightGroupName = GetName() + "_Right_Bank";
184 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
185 aRightGroup->SetName( aRightGroupName );
186 aRightGroup->SetShapes( aRightBankEdges );
188 QString anInGroupName = GetName() + "_Inlet";
190 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
191 anInGroup->SetName( anInGroupName );
192 anInGroup->SetShapes( anInletEdges );
194 QString anOutGroupName = GetName() + "_Outlet";
196 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
197 anOutGroup->SetName( anOutGroupName );
198 anOutGroup->SetShapes( anOutletEdges );
201 bool HYDROData_Channel::IsHas2dPrs() const
206 QColor HYDROData_Channel::DefaultFillingColor()
208 return QColor( Qt::blue );
211 QColor HYDROData_Channel::DefaultBorderColor()
213 return QColor( Qt::transparent );
216 QColor HYDROData_Channel::getDefaultFillingColor() const
218 return DefaultFillingColor();
221 QColor HYDROData_Channel::getDefaultBorderColor() const
223 return DefaultBorderColor();
226 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
228 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
230 if ( theGuideLine.IsNull() )
233 return !aPrevGuideLine.IsNull();
236 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
239 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
240 if ( aHydraulicWire.IsNull() )
241 return false; // The polyline must be a single wire
243 SetReferenceObject( theGuideLine, DataTag_GuideLine );
245 // Indicate model of the need to update the chanel presentation
251 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
253 return Handle(HYDROData_Polyline3D)::DownCast(
254 GetReferenceObject( DataTag_GuideLine ) );
257 void HYDROData_Channel::RemoveGuideLine()
259 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
260 if ( aPrevGuideLine.IsNull() )
263 ClearReferenceObjects( DataTag_GuideLine );
265 // Indicate model of the need to update the chanel presentation
269 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
271 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
273 if ( theProfile.IsNull() )
276 return !aPrevProfile.IsNull();
279 if ( IsEqual( aPrevProfile, theProfile ) )
282 SetReferenceObject( theProfile, DataTag_Profile );
284 // Indicate model of the need to update the chanel presentation
290 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
292 return Handle(HYDROData_Profile)::DownCast(
293 GetReferenceObject( DataTag_Profile ) );
296 void HYDROData_Channel::RemoveProfile()
298 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
299 if ( aPrevProfile.IsNull() )
302 ClearReferenceObjects( DataTag_Profile );
304 // Indicate model of the need to update the chanel presentation
308 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
310 return KIND_OBSTACLE_ALTITUDE;