2 #include "HYDROData_ImmersibleZone.h"
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_PolylineXY.h"
8 #include <BRepBuilderAPI_MakeFace.hxx>
11 #include <TopoDS_Face.hxx>
12 #include <TopoDS_Wire.hxx>
13 #include <TopoDS_Compound.hxx>
14 #include <TopExp_Explorer.hxx>
15 #include <TopTools_ListIteratorOfListOfShape.hxx>
16 #include <BRep_Builder.hxx>
17 #include <BRepAlgo_FaceRestrictor.hxx>
18 #include <BRepCheck_Analyzer.hxx>
20 #include <QStringList>
22 #define PYTHON_IMMERSIBLE_ZONE_ID "KIND_IMMERSIBLE_ZONE"
23 //#define HYDRODATA_IMZONE_DEB 1
25 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
26 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
29 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
30 : HYDROData_NaturalObject()
34 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
38 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
42 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
43 if ( aDocument.IsNull() )
46 QString aDocName = aDocument->GetDocPyName();
47 QString aZoneName = GetName();
49 aResList << QString( "%1 = %2.CreateObject( %3 );" )
50 .arg( aZoneName ).arg( aDocName ).arg( PYTHON_IMMERSIBLE_ZONE_ID );
51 aResList << QString( "%1.SetName( \"%2\" );" )
52 .arg( aZoneName ).arg( aZoneName );
53 aResList << QString( "" );
55 QColor aFillingColor = GetFillingColor();
56 aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
57 .arg( aFillingColor.red() ).arg( aFillingColor.green() )
58 .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
59 aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
60 aResList << QString( "" );
62 QColor aBorderColor = GetBorderColor();
63 aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
64 .arg( aBorderColor.red() ).arg( aBorderColor.green() )
65 .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
66 aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
67 aResList << QString( "" );
69 Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
70 setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetBathymetry" );
72 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline();
73 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
78 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
80 TopoDS_Shape aResShape = TopoDS_Face();
82 Handle(HYDROData_PolylineXY) aPolyline = GetPolyline();
83 if( !aPolyline.IsNull() )
85 TopoDS_Shape aPolylineShape = aPolyline->GetShape();
86 TopTools_ListOfShape aWiresList;
88 if ( !aPolylineShape.IsNull() &&
89 aPolylineShape.ShapeType() == TopAbs_WIRE ) {
90 const TopoDS_Wire& aPolylineWire = TopoDS::Wire( aPolylineShape );
91 if ( !aPolylineWire.IsNull() ) {
92 BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
94 if( aMakeFace.IsDone() ) {
95 return aMakeFace.Face();
99 TopExp_Explorer anExp( aPolylineShape, TopAbs_WIRE );
100 for ( ; anExp.More(); anExp.Next() ) {
101 if(!anExp.Current().IsNull()) {
102 const TopoDS_Wire& aWire = TopoDS::Wire( anExp.Current() );
103 aWiresList.Append( aWire );
106 if(aWiresList.IsEmpty())
108 BRepAlgo_FaceRestrictor aFR;
109 TopoDS_Face aRefFace;
110 TopoDS_Shape aS = aWiresList.First();
111 BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire(aWiresList.First()), Standard_True );
113 if( aMakeFace.IsDone() ) {
114 aRefFace = aMakeFace.Face();
116 if(aRefFace.IsNull())
118 aFR.Init(aRefFace,Standard_False, Standard_True);
119 TopTools_ListIteratorOfListOfShape anIt( aWiresList );
120 for ( ; anIt.More(); anIt.Next() ) {
121 TopoDS_Wire& aWire = TopoDS::Wire( anIt.Value() );
122 if ( aWire.IsNull() )
128 TopoDS_Compound aResult;
130 aBB.MakeCompound(aResult);
131 for (; aFR.More(); aFR.Next()) {
132 const TopoDS_Face& aFF = aFR.Current();
133 aBB.Add(aResult,aFF);
135 BRepCheck_Analyzer aChecker(aResult);
136 if(aChecker.IsValid())
138 #ifdef HYDRODATA_IMZONE_DEB
149 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
152 return getTopShape();
155 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
157 return QColor( Qt::green );
160 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
162 return QColor( Qt::transparent );
165 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
167 SetReferenceObject( thePolyline, DataTag_Polyline );
170 Handle(HYDROData_PolylineXY) HYDROData_ImmersibleZone::GetPolyline() const
172 return Handle(HYDROData_PolylineXY)::DownCast(
173 GetReferenceObject( DataTag_Polyline ) );
176 void HYDROData_ImmersibleZone::RemovePolyline()
178 ClearReferenceObjects( DataTag_Polyline );