Salome HOME
Python scripting is done forcalculation Regions (Feature #13).
[modules/hydro.git] / src / HYDROData / HYDROData_Calculation.cxx
1
2 #include "HYDROData_Calculation.h"
3
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Iterator.h"
6 #include "HYDROData_Polyline.h"
7 #include "HYDROData_Zone.h"
8 #include "HYDROData_Region.h"
9
10 #include <TDataStd_ReferenceList.hxx>
11
12 #include <QStringList>
13
14 #define PYTHON_CALCULATION_ID "KIND_CALCULATION"
15
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Object)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Calculation, HYDROData_Object)
18
19 HYDROData_Calculation::HYDROData_Calculation()
20 {
21 }
22
23 HYDROData_Calculation::~HYDROData_Calculation()
24 {
25 }
26
27 QStringList HYDROData_Calculation::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 aCalculName = GetName();
37
38   aResList << QString( "%1 = %2.CreateObject( %3 );" )
39               .arg( aCalculName ).arg( aDocName ).arg( PYTHON_CALCULATION_ID );
40   aResList << QString( "%1.SetName( \"%2\" );" )
41               .arg( aCalculName ).arg( aCalculName );
42   aResList << QString( "" );
43
44   Handle(HYDROData_Polyline) aBoundaryPolyline = GetBoundaryPolyline();
45   setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
46   aResList << QString( "" );
47
48   HYDROData_SequenceOfObjects aZones = GetZones();
49   HYDROData_SequenceOfObjects::Iterator anIter( aZones );
50   for ( ; anIter.More(); anIter.Next() )
51   {
52     Handle(HYDROData_Zone) aRefZone =
53       Handle(HYDROData_Zone)::DownCast( anIter.Value() );
54     if ( !aRefZone.IsNull() )
55       setPythonReferenceObject( theTreatedObjects, aResList, aRefZone, "AddZone" );
56   }
57   aResList << QString( "" );
58
59   aZones = GetRegions();
60   anIter.Init( aZones );
61   for ( ; anIter.More(); anIter.Next() )
62   {
63     Handle(HYDROData_Region) aRegion =
64       Handle(HYDROData_Region)::DownCast( anIter.Value() );
65     if ( !aRegion.IsNull() )
66       setPythonReferenceObject( theTreatedObjects, aResList, aRegion, "AddRegion" );
67   }
68
69   return aResList;
70 }
71
72 void HYDROData_Calculation::SetBoundaryPolyline( const Handle(HYDROData_Polyline)& thePolyline )
73 {
74   SetReferenceObject( thePolyline, DataTag_BoundaryPolyline );
75 }
76
77 Handle(HYDROData_Polyline) HYDROData_Calculation::GetBoundaryPolyline() const
78 {
79   return Handle(HYDROData_Polyline)::DownCast( 
80            GetReferenceObject( DataTag_BoundaryPolyline ) );
81 }
82
83 void HYDROData_Calculation::RemoveBoundaryPolyline()
84 {
85   ClearReferenceObjects( DataTag_BoundaryPolyline );
86 }
87
88 int HYDROData_Calculation::NbZones() const
89 {
90   return NbReferenceObjects( DataTag_Zone );
91 }
92
93 void HYDROData_Calculation::AddZone( const Handle(HYDROData_Zone)& theZone )
94 {
95   AddReferenceObject( theZone, DataTag_Zone );
96 }
97
98 void HYDROData_Calculation::SetZone( const int                     theIndex,
99                                      const Handle(HYDROData_Zone)& theZone )
100 {
101   SetReferenceObject( theZone, DataTag_Zone, theIndex );
102 }
103
104 void HYDROData_Calculation::SetZones( const HYDROData_SequenceOfObjects& theZones )
105 {
106   SetReferenceObjects( theZones, DataTag_Zone );
107 }
108
109 Handle(HYDROData_Zone) HYDROData_Calculation::GetZone( const int theIndex ) const
110 {
111   return Handle(HYDROData_Zone)::DownCast( 
112            GetReferenceObject( DataTag_Zone, theIndex ) );
113 }
114
115 HYDROData_SequenceOfObjects HYDROData_Calculation::GetZones() const
116 {
117   return GetReferenceObjects( DataTag_Zone );
118 }
119
120 void HYDROData_Calculation::RemoveZones()
121 {
122   ClearReferenceObjects( DataTag_Zone );
123 }
124
125 int HYDROData_Calculation::NbRegions() const
126 {
127   return NbReferenceObjects( DataTag_Region );
128 }
129
130 void HYDROData_Calculation::AddRegion( const Handle(HYDROData_Region)& theRegion )
131 {
132   AddReferenceObject( theRegion, DataTag_Region );
133 }
134
135 void HYDROData_Calculation::SetRegion( const int                       theIndex,
136                                        const Handle(HYDROData_Region)& theRegion )
137 {
138   SetReferenceObject( theRegion, DataTag_Region, theIndex );
139 }
140
141 void HYDROData_Calculation::SetRegions( const HYDROData_SequenceOfObjects& theRegions )
142 {
143   SetReferenceObjects( theRegions, DataTag_Region );
144 }
145
146 Handle(HYDROData_Region) HYDROData_Calculation::GetRegion( const int theIndex ) const
147 {
148   return Handle(HYDROData_Region)::DownCast( 
149            GetReferenceObject( DataTag_Region, theIndex ) );
150 }
151
152 HYDROData_SequenceOfObjects HYDROData_Calculation::GetRegions() const
153 {
154   return GetReferenceObjects( DataTag_Region );
155 }
156
157 void HYDROData_Calculation::RemoveRegions()
158 {
159   ClearReferenceObjects( DataTag_Region );
160 }
161