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 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
59 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
61 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
62 if ( !aHydAxis.IsNull() )
63 aResSeq.Append( aHydAxis );
65 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
66 aResSeq.Append( aSeqOfProfiles );
71 TopoDS_Shape HYDROData_Stream::GetTopShape() const
76 TopoDS_Shape HYDROData_Stream::GetShape3D() const
81 void HYDROData_Stream::Update()
83 HYDROData_NaturalObject::Update();
85 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
86 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
87 if ( aHydAxis.IsNull() || aRefProfiles.IsEmpty() )
90 TopoDS_Shell a2dShell;
91 BRep_Builder a2dShellBuilder;
92 a2dShellBuilder.MakeShell( a2dShell );
94 bool anIsFirst = true;
95 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
97 // Construct the top presentation
98 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
99 for ( ; anIter.More(); anIter.Next() )
101 Handle(HYDROData_Profile) aProfile =
102 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
103 if ( aProfile.IsNull() )
107 if ( !aProfile->GetFirstPoint( aPnt1 ) || !aProfile->GetLastPoint( aPnt2 ) )
110 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 );
111 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 );
115 aPrevFirstPoint = aCurFirstPoint;
116 aPrevLastPoint = aCurLastPoint;
121 BRepBuilderAPI_MakeEdge aFirstEdge( aPrevFirstPoint, aPrevLastPoint );
122 BRepBuilderAPI_MakeEdge aSecondEdge( aPrevLastPoint, aCurLastPoint );
123 BRepBuilderAPI_MakeEdge aThirdEdge( aCurLastPoint, aCurFirstPoint );
124 BRepBuilderAPI_MakeEdge aFourthEdge( aCurFirstPoint, aPrevFirstPoint );
126 BRepBuilderAPI_MakeWire aMakeWire( aFirstEdge.Edge(), aSecondEdge.Edge(),
127 aThirdEdge.Edge(), aFourthEdge.Edge() );
129 TopoDS_Wire aSectProfileWire = aMakeWire.Wire();
131 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
133 if( aMakeFace.IsDone() )
135 a2dShellBuilder.Add( a2dShell, aMakeFace.Face() );
138 aPrevFirstPoint = aCurFirstPoint;
139 aPrevLastPoint = aCurLastPoint;
142 SetTopShape( a2dShell );
144 // Construct the 3D presentation
148 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
150 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
152 if ( theAxis.IsNull() )
154 RemoveHydraulicAxis();
155 return !aPrevAxis.IsNull();
158 if ( IsEqual( aPrevAxis, theAxis ) )
161 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theAxis->GetShape() );
162 if ( aHydraulicWire.IsNull() )
163 return false; // The polyline must be a single wire
165 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
167 // Update the order of profiles
168 updateProfilesOrder();
170 // Indicate model of the need to update the stream presentation
176 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
178 return Handle(HYDROData_PolylineXY)::DownCast(
179 GetReferenceObject( DataTag_HydraulicAxis ) );
182 void HYDROData_Stream::RemoveHydraulicAxis()
184 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
185 if ( aPrevAxis.IsNull() )
188 ClearReferenceObjects( DataTag_HydraulicAxis );
190 // We remove the reference profiles
193 // Indicate model of the need to update the stream presentation
197 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile ) const
199 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
200 if ( theProfile.IsNull() || aHydAxis.IsNull() )
203 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
204 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
205 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
213 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
215 if ( theProfile.IsNull() )
218 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile ) )
219 return false; // Object is already in reference list or it has no intersection
221 insertProfileInToOrder( theProfile );
223 // Indicate model of the need to update the stream presentation
229 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
231 return GetReferenceObjects( DataTag_Profile );
234 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
236 if ( theProfile.IsNull() || !HasReference( theProfile, DataTag_Profile ) )
239 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
241 // Indicate model of the need to update the stream presentation
247 void HYDROData_Stream::RemoveProfiles()
249 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
251 ClearReferenceObjects( DataTag_Profile );
253 // Indicate model of the need to update the stream presentation
254 SetToUpdate( anIsToUpdate );
257 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile )
259 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
260 if ( theProfile.IsNull() || aHydAxis.IsNull() )
263 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
264 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
265 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
269 AddReferenceObject( theProfile, DataTag_Profile ); // temporary for testing only
272 void HYDROData_Stream::updateProfilesOrder()
274 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
275 if ( aRefProfiles.IsEmpty() )
278 // At first we remove all profiles from order
281 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
282 if ( aHydAxis.IsNull() )
285 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
286 for ( ; anIter.More(); anIter.Next() )
288 Handle(HYDROData_Profile) aProfile =
289 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
290 if ( aProfile.IsNull() || !HasIntersection( aProfile ) )
293 insertProfileInToOrder( aProfile );