1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_Channel.h"
25 #include "HYDROData_Document.h"
26 #include "HYDROData_Polyline3D.h"
27 #include "HYDROData_Profile.h"
28 #include "HYDROData_PolylineXY.h"
29 #include "HYDROData_Projection.h"
30 #include "HYDROData_ShapesGroup.h"
31 #include "HYDROData_ShapesTool.h"
32 #include "HYDROData_Pipes.h"
34 #include <BRepOffsetAPI_MakePipeShell.hxx>
35 #include <BRepOffsetAPI_MakePipe.hxx>
36 #include <BRepCheck_Analyzer.hxx>
41 #include <TopoDS_Wire.hxx>
42 #include <TopoDS_Vertex.hxx>
44 //#define DEB_CHANNEL 1
46 #include <BRepTools.hxx>
50 #include <QStringList>
52 IMPLEMENT_STANDARD_HANDLE(HYDROData_Channel,HYDROData_ArtificialObject)
53 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Channel,HYDROData_ArtificialObject)
56 HYDROData_Channel::HYDROData_Channel()
57 : HYDROData_ArtificialObject()
61 HYDROData_Channel::~HYDROData_Channel()
65 QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
67 QStringList aResList = dumpObjectCreation( theTreatedObjects );
68 QString aName = GetObjPyName();
70 Handle(HYDROData_Polyline3D) aRefGideLine = GetGuideLine();
71 setPythonReferenceObject( theTreatedObjects, aResList, aRefGideLine, "SetGuideLine" );
73 Handle(HYDROData_Profile) aRefProfile = GetProfile();
74 setPythonReferenceObject( theTreatedObjects, aResList, aRefProfile, "SetProfile" );
76 aResList << QString( "" );
77 aResList << QString( "%1.Update();" ).arg( aName );
78 aResList << QString( "" );
83 HYDROData_SequenceOfObjects HYDROData_Channel::GetAllReferenceObjects() const
85 HYDROData_SequenceOfObjects aResSeq = HYDROData_ArtificialObject::GetAllReferenceObjects();
87 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
88 if ( !aGuideLine.IsNull() )
89 aResSeq.Append( aGuideLine );
91 Handle(HYDROData_Profile) aProfile = GetProfile();
92 if ( !aProfile.IsNull() )
93 aResSeq.Append( aProfile );
98 TopoDS_Shape HYDROData_Channel::GetTopShape() const
100 return getTopShape();
103 TopoDS_Shape HYDROData_Channel::GetShape3D() const
108 bool HYDROData_Channel::CreatePresentations( const Handle(HYDROData_Polyline3D)& theGuideLine,
109 const Handle(HYDROData_Profile)& theProfile,
110 PrsDefinition& thePrs )
112 if ( theGuideLine.IsNull() || theProfile.IsNull() )
116 TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() );
117 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() );
118 if ( aPathWire.IsNull() || aProfileWire.IsNull() )
122 BRepTools::Write( aPathWire, "guideline.brep" );
123 BRepTools::Write( aProfileWire, "profile.brep" );
126 HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
127 if( aChannelConstructor.GetStatus() != 0 )
130 aChannelConstructor.Create3dPresentation();
131 aChannelConstructor.Create2dPresentation();
132 thePrs.myPrs3D = aChannelConstructor.Get3dPresentation();
133 thePrs.myPrs2D = aChannelConstructor.Get2dPresentation();
135 thePrs.myLeftBank = aChannelConstructor.GetLeftBank();
136 thePrs.myRightBank = aChannelConstructor.GetRightBank();
137 thePrs.myInlet = aChannelConstructor.GetInlet();
138 thePrs.myOutlet = aChannelConstructor.GetOutlet();
141 BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" );
142 BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" );
143 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE );
144 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE );
145 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE );
146 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE );
147 HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE );
153 void HYDROData_Channel::Update()
155 HYDROData_ArtificialObject::Update();
157 Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
158 Handle(HYDROData_Profile) aProfile = GetProfile();
160 PrsDefinition aResultPrs;
161 if ( !CreatePresentations( aGuideLine, aProfile, aResultPrs ) )
164 SetShape3D( aResultPrs.myPrs3D );
165 SetTopShape( aResultPrs.myPrs2D );
167 // Create groups for channel
168 TopTools_SequenceOfShape aLeftBankEdges;
169 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myLeftBank, TopAbs_EDGE, aLeftBankEdges );
171 TopTools_SequenceOfShape aRightBankEdges;
172 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myRightBank, TopAbs_EDGE, aRightBankEdges );
174 TopTools_SequenceOfShape anInletEdges;
175 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myInlet, TopAbs_EDGE, anInletEdges );
177 TopTools_SequenceOfShape anOutletEdges;
178 HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myOutlet, TopAbs_EDGE, anOutletEdges );
180 QString aLeftGroupName = GetName() + "_Left_Bank";
182 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
183 aLeftGroup->SetName( aLeftGroupName );
184 aLeftGroup->SetShapes( aLeftBankEdges );
186 QString aRightGroupName = GetName() + "_Right_Bank";
188 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
189 aRightGroup->SetName( aRightGroupName );
190 aRightGroup->SetShapes( aRightBankEdges );
192 QString anInGroupName = GetName() + "_Inlet";
194 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
195 anInGroup->SetName( anInGroupName );
196 anInGroup->SetShapes( anInletEdges );
198 QString anOutGroupName = GetName() + "_Outlet";
200 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
201 anOutGroup->SetName( anOutGroupName );
202 anOutGroup->SetShapes( anOutletEdges );
205 bool HYDROData_Channel::IsHas2dPrs() const
210 QColor HYDROData_Channel::DefaultFillingColor()
212 return QColor( Qt::blue );
215 QColor HYDROData_Channel::DefaultBorderColor()
217 return QColor( Qt::transparent );
220 QColor HYDROData_Channel::getDefaultFillingColor() const
222 return DefaultFillingColor();
225 QColor HYDROData_Channel::getDefaultBorderColor() const
227 return DefaultBorderColor();
230 bool HYDROData_Channel::SetGuideLine( const Handle(HYDROData_Polyline3D)& theGuideLine )
232 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
234 if ( theGuideLine.IsNull() )
237 return !aPrevGuideLine.IsNull();
240 if ( IsEqual( aPrevGuideLine, theGuideLine ) )
243 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theGuideLine->GetTopShape() );
244 if ( aHydraulicWire.IsNull() )
245 return false; // The polyline must be a single wire
247 SetReferenceObject( theGuideLine, DataTag_GuideLine );
249 // Indicate model of the need to update the chanel presentation
255 Handle(HYDROData_Polyline3D) HYDROData_Channel::GetGuideLine() const
257 return Handle(HYDROData_Polyline3D)::DownCast(
258 GetReferenceObject( DataTag_GuideLine ) );
261 void HYDROData_Channel::RemoveGuideLine()
263 Handle(HYDROData_Polyline3D) aPrevGuideLine = GetGuideLine();
264 if ( aPrevGuideLine.IsNull() )
267 ClearReferenceObjects( DataTag_GuideLine );
269 // Indicate model of the need to update the chanel presentation
273 bool HYDROData_Channel::SetProfile( const Handle(HYDROData_Profile)& theProfile )
275 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
277 if ( theProfile.IsNull() )
280 return !aPrevProfile.IsNull();
283 if ( IsEqual( aPrevProfile, theProfile ) )
286 SetReferenceObject( theProfile, DataTag_Profile );
288 // Indicate model of the need to update the chanel presentation
294 Handle(HYDROData_Profile) HYDROData_Channel::GetProfile() const
296 return Handle(HYDROData_Profile)::DownCast(
297 GetReferenceObject( DataTag_Profile ) );
300 void HYDROData_Channel::RemoveProfile()
302 Handle(HYDROData_Profile) aPrevProfile = GetProfile();
303 if ( aPrevProfile.IsNull() )
306 ClearReferenceObjects( DataTag_Profile );
308 // Indicate model of the need to update the chanel presentation
312 ObjectKind HYDROData_Channel::getAltitudeObjectType() const
314 return KIND_OBSTACLE_ALTITUDE;