Salome HOME
Linux compilation.
[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   aResList << QString( "" );
64
65   Handle(HYDROData_Bathymetry) aRefBathymetry = GetBathymetry();
66   setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetBathymetry" );
67
68   Handle(HYDROData_Polyline) aRefPolyline = GetPolyline();
69   setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
70
71   return aResList;
72 }
73
74 TopoDS_Shape HYDROData_ImmersibleZone::GetTopShape() const
75 {
76   Handle(HYDROData_Polyline) aPolyline = GetPolyline();
77   if( !aPolyline.IsNull() )
78   {
79     TopoDS_Wire aPolylineWire = TopoDS::Wire( aPolyline->GetTopShape() );
80     if( !aPolylineWire.IsNull() )
81     {
82       BRepBuilderAPI_MakeFace aMakeFace( aPolylineWire, Standard_True );
83       aMakeFace.Build();
84       if( aMakeFace.IsDone() )
85         return aMakeFace.Face();
86     }
87   }
88   return TopoDS_Face();
89 }
90
91 TopoDS_Shape HYDROData_ImmersibleZone::GetShape3D() const
92 {
93   // TODO
94   return getTopShape();
95 }
96
97 QColor HYDROData_ImmersibleZone::DefaultFillingColor()
98 {
99   return QColor( Qt::green );
100 }
101
102 void HYDROData_ImmersibleZone::SetFillingColor( const QColor& theColor )
103 {
104   return SetColor( theColor, DataTag_FillingColor );
105 }
106
107 QColor HYDROData_ImmersibleZone::GetFillingColor() const
108 {
109   return GetColor( DefaultFillingColor(), DataTag_FillingColor );
110 }
111
112 QColor HYDROData_ImmersibleZone::DefaultBorderColor()
113 {
114   return QColor( Qt::transparent );
115 }
116
117 void HYDROData_ImmersibleZone::SetBorderColor( const QColor& theColor )
118 {
119   return SetColor( theColor, DataTag_BorderColor );
120 }
121
122 QColor HYDROData_ImmersibleZone::GetBorderColor() const
123 {
124   return GetColor( DefaultBorderColor(), DataTag_BorderColor );
125 }
126
127 void HYDROData_ImmersibleZone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline )
128 {
129   SetReferenceObject( thePolyline, DataTag_Polyline );
130 }
131
132 Handle(HYDROData_Polyline) HYDROData_ImmersibleZone::GetPolyline() const
133 {
134   return Handle(HYDROData_Polyline)::DownCast( 
135            GetReferenceObject( DataTag_Polyline ) );
136 }
137
138 void HYDROData_ImmersibleZone::RemovePolyline()
139 {
140   ClearReferenceObjects( DataTag_Polyline );
141 }
142
143 void HYDROData_ImmersibleZone::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
144 {
145   SetReferenceObject( theBathymetry, DataTag_Bathymetry );
146 }
147
148 Handle(HYDROData_Bathymetry) HYDROData_ImmersibleZone::GetBathymetry() const
149 {
150   return Handle(HYDROData_Bathymetry)::DownCast( 
151            GetReferenceObject( DataTag_Bathymetry ) );
152 }
153
154 void HYDROData_ImmersibleZone::RemoveBathymetry()
155 {
156   ClearReferenceObjects( DataTag_Bathymetry );
157 }
158
159