Salome HOME
286cbaa39a9df099166b418d0d2221189f2f7acb
[modules/hydro.git] / src / HYDROData / HYDROData_ImmersibleZone.cxx
1
2 #include "HYDROData_ImmersibleZone.h"
3
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_Polyline.h"
7
8 #include <BRepBuilderAPI_MakeFace.hxx>
9
10 #include <TopoDS.hxx>
11 #include <TopoDS_Face.hxx>
12 #include <TopoDS_Wire.hxx>
13
14 #include <QColor>
15 #include <QStringList>
16
17 #define PYTHON_IMMERSIBLE_ZONE_ID "KIND_IMMERSIBLE_ZONE"
18
19 IMPLEMENT_STANDARD_HANDLE(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
20 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ImmersibleZone,HYDROData_NaturalObject)
21
22
23 HYDROData_ImmersibleZone::HYDROData_ImmersibleZone()
24 : HYDROData_NaturalObject()
25 {
26 }
27
28 HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone()
29 {
30 }
31
32 QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
33 {
34   QStringList aResList;
35
36   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
37   if ( aDocument.IsNull() )
38     return aResList;
39
40   QString aDocName = aDocument->GetDocPyName();
41   QString aZoneName = GetName();
42
43   aResList << QString( "%1 = %2.CreateObject( %3 );" )
44               .arg( aZoneName ).arg( aDocName ).arg( PYTHON_IMMERSIBLE_ZONE_ID );
45   aResList << QString( "%1.SetName( \"%2\" );" )
46               .arg( aZoneName ).arg( aZoneName );
47   aResList << QString( "" );
48
49   QColor aFillingColor = GetFillingColor();
50   aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
51               .arg( aFillingColor.red()  ).arg( aFillingColor.green() )
52               .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
53   aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
54   aResList << QString( "" );
55
56   QColor aBorderColor = GetBorderColor();
57   aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
58               .arg( aBorderColor.red()  ).arg( aBorderColor.green() )
59               .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
60   aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
61   aResList << QString( "" );
62
63   Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
64   setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetBathymetry" );
65
66   Handle(HYDROData_Polyline) aRefPolyline = GetPolyline();
67   setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
68
69   return aResList;
70 }
71
72 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
73 {
74   Handle(HYDROData_Polyline) aPolyline = GetPolyline();
75   if( !aPolyline.IsNull() )
76   {
77     TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() );
78     if( !aPolylineWire.IsNull() )
79     {
80       BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
81       aMakeFace.Build();
82       if( aMakeFace.IsDone() )
83         return aMakeFace.Face();
84     }
85   }
86   return TopoDS_Face();
87 }
88
89 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
90 {
91   // TODO
92   return getTopShape();
93 }
94
95 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
96 {
97   return QColor( Qt::green );
98 }
99
100 void HYDROData_ImmersibleZone::SetFillingColor( const QColor& theColor )
101 {
102   return SetColor( theColor, DataTag_FillingColor );
103 }
104
105 QColor HYDROData_ImmersibleZone::GetFillingColor() const
106 {
107   return GetColor( DefaultFillingColor(), DataTag_FillingColor );
108 }
109
110 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
111 {
112   return QColor( Qt::transparent );
113 }
114
115 void HYDROData_ImmersibleZone::SetBorderColor( const QColor& theColor )
116 {
117   return SetColor( theColor, DataTag_BorderColor );
118 }
119
120 QColor HYDROData_ImmersibleZone::GetBorderColor() const
121 {
122   return GetColor( DefaultBorderColor(), DataTag_BorderColor );
123 }
124
125 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline )
126 {
127   SetReferenceObject( thePolyline, DataTag_Polyline );
128 }
129
130 Handle(HYDROData_Polyline) HYDROData_ImmersibleZone::GetPolyline() const
131 {
132   return Handle(HYDROData_Polyline)::DownCast( 
133            GetReferenceObject( DataTag_Polyline ) );
134 }
135
136 void HYDROData_ImmersibleZone::RemovePolyline()
137 {
138   ClearReferenceObjects( DataTag_Polyline );
139 }
140
141 void HYDROData_ImmersibleZone::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
142 {
143   SetReferenceObject( theBathymetry, DataTag_Bathymetry );
144 }
145
146 Handle(HYDROData_Bathymetry) HYDROData_ImmersibleZone::GetBathymetry() const
147 {
148   return Handle(HYDROData_Bathymetry)::DownCast( 
149            GetReferenceObject( DataTag_Bathymetry ) );
150 }
151
152 void HYDROData_ImmersibleZone::RemoveBathymetry()
153 {
154   ClearReferenceObjects( DataTag_Bathymetry );
155 }
156
157