]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Zone.cxx
Salome HOME
Python scripting is done for Zones and Calculations (Feature #13).
[modules/hydro.git] / src / HYDROData / HYDROData_Zone.cxx
1
2 #include "HYDROData_Zone.h"
3
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_Polyline.h"
7 #include "HYDROData_Iterator.h"
8
9 #include <TDataStd_IntegerArray.hxx>
10
11 #include <QColor>
12 #include <QStringList>
13
14 #define PYTHON_ZONE_ID "KIND_ZONE"
15
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Object)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Object)
18
19 HYDROData_Zone::HYDROData_Zone()
20 {
21 }
22
23 HYDROData_Zone::~HYDROData_Zone()
24 {
25 }
26
27 QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
28 {
29   QStringList aResList;
30
31   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
32   if ( aDocument.IsNull() )
33     return aResList;
34
35   QString aDocName = aDocument->GetDocPyName();
36   QString aZoneName = GetName();
37
38   aResList << QString( "%1 = %2.CreateObject( %3 );" )
39               .arg( aZoneName ).arg( aDocName ).arg( PYTHON_ZONE_ID );
40   aResList << QString( "%1.SetName( \"%2\" );" )
41               .arg( aZoneName ).arg( aZoneName );
42   aResList << QString( "" );
43
44   QColor aFillingColor = GetFillingColor();
45   aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
46               .arg( aFillingColor.red()  ).arg( aFillingColor.green() )
47               .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
48   aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
49   aResList << QString( "" );
50
51   QColor aBorderColor = GetBorderColor();
52   aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
53               .arg( aBorderColor.red()  ).arg( aBorderColor.green() )
54               .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
55   aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
56   aResList << QString( "" );
57
58   Handle(HYDROData_Polyline) aRefPolyline = GetPolyline();
59   setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
60   aResList << QString( "" );
61
62   HYDROData_SequenceOfObjects aZoneBaths = GetBathymetries();
63   HYDROData_SequenceOfObjects::Iterator aBathsIter( aZoneBaths );
64   for ( ; aBathsIter.More(); aBathsIter.Next() )
65   {
66     Handle(HYDROData_Bathymetry) aRefBath =
67       Handle(HYDROData_Bathymetry)::DownCast( aBathsIter.Value() );
68     if ( !aRefBath.IsNull() )
69       setPythonReferenceObject( theTreatedObjects, aResList, aRefBath, "AddBathymetry" );
70   }
71
72   return aResList;
73 }
74
75 QColor HYDROData_Zone::DefaultFillingColor()
76 {
77   return QColor( Qt::green );
78 }
79
80 void HYDROData_Zone::SetFillingColor( const QColor& theColor )
81 {
82   return SetColor( theColor, DataTag_FillingColor );
83 }
84
85 QColor HYDROData_Zone::GetFillingColor() const
86 {
87   return GetColor( DefaultFillingColor(), DataTag_FillingColor );
88 }
89
90 QColor HYDROData_Zone::DefaultBorderColor()
91 {
92   return QColor( Qt::transparent );
93 }
94
95 void HYDROData_Zone::SetBorderColor( const QColor& theColor )
96 {
97   return SetColor( theColor, DataTag_BorderColor );
98 }
99
100 QColor HYDROData_Zone::GetBorderColor() const
101 {
102   return GetColor( DefaultBorderColor(), DataTag_BorderColor );
103 }
104
105 void HYDROData_Zone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline )
106 {
107   SetReferenceObject( thePolyline, DataTag_Polyline );
108 }
109
110 Handle(HYDROData_Polyline) HYDROData_Zone::GetPolyline() const
111 {
112   return Handle(HYDROData_Polyline)::DownCast( 
113            GetReferenceObject( DataTag_Polyline ) );
114 }
115
116 void HYDROData_Zone::RemovePolyline()
117 {
118   ClearReferenceObjects( DataTag_Polyline );
119 }
120
121 int HYDROData_Zone::NbBathymetries() const
122 {
123   return NbReferenceObjects( DataTag_Bathymetry );
124 }
125
126 void HYDROData_Zone::AddBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
127 {
128   AddReferenceObject( theBathymetry, DataTag_Bathymetry );
129 }
130
131 void HYDROData_Zone::SetBathymetry( const int                           theIndex,
132                                     const Handle(HYDROData_Bathymetry)& theBathymetry )
133 {
134   SetReferenceObject( theBathymetry, DataTag_Bathymetry, theIndex );
135 }
136
137 Handle(HYDROData_Bathymetry) HYDROData_Zone::GetBathymetry( const int theIndex ) const
138 {
139   return Handle(HYDROData_Bathymetry)::DownCast( 
140            GetReferenceObject( DataTag_Bathymetry, theIndex ) );
141 }
142
143 HYDROData_SequenceOfObjects HYDROData_Zone::GetBathymetries() const
144 {
145   return GetReferenceObjects( DataTag_Bathymetry );
146 }
147
148 void HYDROData_Zone::RemoveBathymetries()
149 {
150   ClearReferenceObjects( DataTag_Bathymetry );
151 }
152
153 QPainterPath HYDROData_Zone::GetPainterPath() const
154 {
155   QPainterPath aPath;
156
157   Handle(HYDROData_Polyline) aPolyline = GetPolyline();
158   if ( !aPolyline.IsNull() )
159   {
160     aPath = aPolyline->painterPath();
161   }
162
163   return aPath;
164 }
165