Salome HOME
Path to resource files corrected as in LINUX platform.
[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_Object.h"
7 #include "HYDROData_SplitToZonesTool.h"
8 #include "HYDROData_Region.h"
9 #include "HYDROData_Tool.h"
10 #include "HYDROData_Zone.h"
11
12 #include <QStringList>
13
14 #define PYTHON_CALCULATION_ID "KIND_CALCULATION"
15
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Entity)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Calculation, HYDROData_Entity)
18
19 HYDROData_Calculation::HYDROData_Calculation()
20 : HYDROData_Entity()
21 {
22 }
23
24 HYDROData_Calculation::~HYDROData_Calculation()
25 {
26 }
27
28 QStringList HYDROData_Calculation::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
29 {
30   QStringList aResList;
31
32   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
33   if ( aDocument.IsNull() )
34     return aResList;
35                              
36   QString aDocName = aDocument->GetDocPyName();
37   QString aCalculName = GetName();
38
39   aResList << QString( "%1 = %2.CreateObject( %3 );" )
40               .arg( aCalculName ).arg( aDocName ).arg( PYTHON_CALCULATION_ID );
41   aResList << QString( "%1.SetName( \"%2\" );" )
42               .arg( aCalculName ).arg( aCalculName );
43   aResList << QString( "" );
44
45   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
46   HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
47   for ( ; anIter.More(); anIter.Next() )
48   {
49     Handle(HYDROData_Object) aRefGeomObj =
50       Handle(HYDROData_Object)::DownCast( anIter.Value() );
51     if ( !aRefGeomObj.IsNull() )
52       setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
53   }
54   aResList << QString( "" );
55
56   aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName );
57   aResList << QString( "" );
58
59   // Now we restore the regions and zones order
60   HYDROData_SequenceOfObjects aRegions = GetRegions();
61   anIter.Init( aRegions );
62   for ( ; anIter.More(); anIter.Next() )
63   {
64     Handle(HYDROData_Region) aRegion =
65       Handle(HYDROData_Region)::DownCast( anIter.Value() );
66     if ( aRegion.IsNull() )
67       continue;
68
69     QString aRegionName = aRegion->GetName();
70     // TODO
71   }
72
73   return aResList;
74 }
75
76 void HYDROData_Calculation::SplitGeometryObjects()
77 {
78   // At first we remove previously created regions
79   RemoveRegions();
80   RemoveChildRegions();
81
82   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
83   if ( aDocument.IsNull() )
84     return;
85
86   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
87   if ( aGeomObjects.IsEmpty() )
88     return;
89
90   HYDROData_SplitToZonesTool::SplitDataList aSplitedZones =
91     HYDROData_SplitToZonesTool::SplitToZones( aGeomObjects );
92   if ( aSplitedZones.isEmpty() )
93     return;
94
95   // Create result regions for case, by default one zone for one region
96   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones );
97   while( anIter.hasNext() )
98   {
99     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
100
101     // Create new region
102     Handle(HYDROData_Region) aRegion = AddNewRegion();
103     AddRegion( aRegion );
104
105     QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
106     aRegion->SetName( aRegionName );
107
108     // Add the zone for region
109     Handle(HYDROData_Zone) aRegionZone = aRegion->AddNewZone();
110     aRegion->AddZone( aRegionZone );
111
112     QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" );
113     aRegionZone->SetName( aZoneName );
114
115     aRegionZone->SetShape( aSplitData.Face() );
116
117     // Add the reference object for zone
118     for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
119     {
120       const QString& anObjName = aSplitData.ObjectNames.at( i );
121       
122       Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
123         HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
124       if ( aRefObject.IsNull() )
125         continue;
126
127       aRegionZone->AddGeometryObject( aRefObject );
128     }
129   }
130 }
131
132 int HYDROData_Calculation::NbGeometryObjects() const
133 {
134   return NbReferenceObjects( DataTag_GeometryObject );
135 }
136
137 void HYDROData_Calculation::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
138 {
139   AddReferenceObject( theObject, DataTag_GeometryObject );
140 }
141
142 void HYDROData_Calculation::SetGeometryObject( const int                       theIndex,
143                                                const Handle(HYDROData_Object)& theObject )
144 {
145   SetReferenceObject( theObject, DataTag_GeometryObject, theIndex );
146 }
147
148 void HYDROData_Calculation::SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects )
149 {
150   SetReferenceObjects( theObjects, DataTag_GeometryObject );
151 }
152
153 Handle(HYDROData_Object) HYDROData_Calculation::GetGeometryObject( const int theIndex ) const
154 {
155   return Handle(HYDROData_Object)::DownCast( 
156            GetReferenceObject( DataTag_GeometryObject, theIndex ) );
157 }
158
159 HYDROData_SequenceOfObjects HYDROData_Calculation::GetGeometryObjects() const
160 {
161   return GetReferenceObjects( DataTag_GeometryObject );
162 }
163
164 void HYDROData_Calculation::RemoveGeometryObjects()
165 {
166   ClearReferenceObjects( DataTag_GeometryObject );
167 }
168
169 Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion()
170 {
171   TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild();
172
173   return Handle(HYDROData_Region)::DownCast(
174     HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
175 }
176
177 void HYDROData_Calculation::RemoveChildRegions()
178 {
179   myLab.FindChild( ChildTag_Region ).ForgetAllAttributes( true );
180 }
181
182 int HYDROData_Calculation::NbRegions() const
183 {
184   return NbReferenceObjects( DataTag_Region );
185 }
186
187 void HYDROData_Calculation::AddRegion( const Handle(HYDROData_Region)& theRegion )
188 {
189   AddReferenceObject( theRegion, DataTag_Region );
190 }
191
192 void HYDROData_Calculation::SetRegion( const int                       theIndex,
193                                        const Handle(HYDROData_Region)& theRegion )
194 {
195   SetReferenceObject( theRegion, DataTag_Region, theIndex );
196 }
197
198 void HYDROData_Calculation::InsertRegion( const int                       theBeforeIndex,
199                                           const Handle(HYDROData_Region)& theRegion )
200 {
201   InsertReferenceObject( theRegion, DataTag_Region, theBeforeIndex );
202 }
203
204 void HYDROData_Calculation::SetRegions( const HYDROData_SequenceOfObjects& theRegions )
205 {
206   SetReferenceObjects( theRegions, DataTag_Region );
207 }
208
209 Handle(HYDROData_Region) HYDROData_Calculation::GetRegion( const int theIndex ) const
210 {
211   return Handle(HYDROData_Region)::DownCast( 
212            GetReferenceObject( DataTag_Region, theIndex ) );
213 }
214
215 HYDROData_SequenceOfObjects HYDROData_Calculation::GetRegions() const
216 {
217   return GetReferenceObjects( DataTag_Region );
218 }
219
220 void HYDROData_Calculation::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
221 {
222   if ( theRegion.IsNull() )
223     return;
224
225   RemoveReferenceObject( theRegion->Label(), DataTag_Region );
226 }
227
228 void HYDROData_Calculation::RemoveRegion( const int theIndex )
229 {
230   RemoveReferenceObject( DataTag_Region, theIndex );
231 }
232
233 void HYDROData_Calculation::RemoveRegions()
234 {
235   ClearReferenceObjects( DataTag_Region );
236 }