2 #include "HYDROData_Stream.h"
4 #include "HYDROData_Document.h"
5 #include "HYDROData_PolylineXY.h"
6 #include "HYDROData_Profile.h"
8 #include <BRep_Builder.hxx>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
10 #include <BRepBuilderAPI_MakeWire.hxx>
11 #include <BRepBuilderAPI_MakeFace.hxx>
14 #include <TopoDS_Wire.hxx>
15 #include <TopoDS_Shell.hxx>
16 #include <TopoDS_Face.hxx>
18 #include <QStringList>
20 #define PYTHON_STREAM_ID "KIND_STREAM"
22 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
23 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
26 HYDROData_Stream::HYDROData_Stream()
27 : HYDROData_NaturalObject()
31 HYDROData_Stream::~HYDROData_Stream()
35 QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
39 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
40 if ( aDocument.IsNull() )
43 QString aDocName = aDocument->GetDocPyName();
44 QString aStreamName = GetName();
46 aResList << QString( "%1 = %2.CreateObject( %3 );" )
47 .arg( aStreamName ).arg( aDocName ).arg( PYTHON_STREAM_ID );
48 aResList << QString( "%1.SetName( \"%2\" );" )
49 .arg( aStreamName ).arg( aStreamName );
50 aResList << QString( "" );
57 TopoDS_Shape HYDROData_Stream::GetTopShape() const
62 TopoDS_Shape HYDROData_Stream::GetShape3D() const
67 void HYDROData_Stream::Update()
72 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
73 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
74 if ( aHydAxis.IsNull() || aRefProfiles.IsEmpty() )
77 TopoDS_Shell a2dShell;
78 BRep_Builder a2dShellBuilder;
79 a2dShellBuilder.MakeShell( a2dShell );
81 bool anIsFirst = true;
82 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
84 // Construct the top presentation
85 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
86 for ( ; anIter.More(); anIter.Next() )
88 Handle(HYDROData_Profile) aProfile =
89 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
90 if ( aProfile.IsNull() )
94 if ( !aProfile->GetFirstPoint( aPnt1 ) || !aProfile->GetLastPoint( aPnt2 ) )
97 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 );
98 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 );
102 aPrevFirstPoint = aCurFirstPoint;
103 aPrevLastPoint = aCurLastPoint;
108 BRepBuilderAPI_MakeEdge aFirstEdge( aPrevFirstPoint, aPrevLastPoint );
109 BRepBuilderAPI_MakeEdge aSecondEdge( aPrevLastPoint, aCurLastPoint );
110 BRepBuilderAPI_MakeEdge aThirdEdge( aCurLastPoint, aCurFirstPoint );
111 BRepBuilderAPI_MakeEdge aFourthEdge( aCurFirstPoint, aPrevFirstPoint );
113 BRepBuilderAPI_MakeWire aMakeWire( aFirstEdge.Edge(), aSecondEdge.Edge(),
114 aThirdEdge.Edge(), aFourthEdge.Edge() );
116 TopoDS_Wire aSectProfileWire = aMakeWire.Wire();
118 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
120 if( aMakeFace.IsDone() )
122 a2dShellBuilder.Add( a2dShell, aMakeFace.Face() );
126 SetTopShape( a2dShell );
128 // Construct the 3D presentation
132 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
134 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
135 if ( theAxis.IsNull() || IsEqual( aPrevAxis, theAxis ) )
138 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theAxis->GetShape() );
139 if ( aHydraulicWire.IsNull() )
140 return false; // The polyline must be a single wire
142 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
144 // Update the order of profiles
145 updateProfilesOrder();
147 // Indicate model of the need to update the stream presentation
153 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
155 return Handle(HYDROData_PolylineXY)::DownCast(
156 GetReferenceObject( DataTag_HydraulicAxis ) );
159 void HYDROData_Stream::RemoveHydraulicAxis()
161 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
162 if ( aPrevAxis.IsNull() )
165 ClearReferenceObjects( DataTag_HydraulicAxis );
167 // We remove the reference profiles
170 // Indicate model of the need to update the stream presentation
174 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile ) const
176 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
177 if ( theProfile.IsNull() || aHydAxis.IsNull() )
180 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
181 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
182 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
190 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
192 if ( theProfile.IsNull() )
195 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile ) )
196 return false; // Object is already in reference list or it has no intersection
198 insertProfileInToOrder( theProfile );
200 // Indicate model of the need to update the stream presentation
206 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
208 return GetReferenceObjects( DataTag_Profile );
211 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
213 if ( theProfile.IsNull() || !HasReference( theProfile, DataTag_Profile ) )
216 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
218 // Indicate model of the need to update the stream presentation
224 void HYDROData_Stream::RemoveProfiles()
226 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
228 ClearReferenceObjects( DataTag_Profile );
230 // Indicate model of the need to update the stream presentation
231 SetToUpdate( anIsToUpdate );
234 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile )
236 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
237 if ( theProfile.IsNull() || aHydAxis.IsNull() )
240 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
241 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
242 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
248 void HYDROData_Stream::updateProfilesOrder()
250 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
251 if ( aRefProfiles.IsEmpty() )
254 // At first we remove all profiles from order
257 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
258 if ( aHydAxis.IsNull() )
261 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
262 for ( ; anIter.More(); anIter.Next() )
264 Handle(HYDROData_Profile) aProfile =
265 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
266 if ( aProfile.IsNull() || !HasIntersection( aProfile ) )
269 insertProfileInToOrder( aProfile );