Salome HOME
5c5760130d4124f270dfc528dd99a1e8612f68f8
[modules/hydro.git] / src / HYDROData / HYDROData_CalculationCase.cxx
1
2 #include "HYDROData_CalculationCase.h"
3
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_IAltitudeObject.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_ShapesGroup.h"
8 #include "HYDROData_Iterator.h"
9 #include "HYDROData_NaturalObject.h"
10 #include "HYDROData_PolylineXY.h"
11 #include "HYDROData_SplittedShapesGroup.h"
12 #include "HYDROData_Region.h"
13 #include "HYDROData_Tool.h"
14
15 #include <GEOMBase.h>
16
17 #include <QSet>
18
19 #include <TopoDS.hxx>
20 #include <TopoDS_Shell.hxx>
21 #include <TopoDS_Edge.hxx>
22
23 #include <BRep_Builder.hxx>
24 #include <BRepBuilderAPI_Sewing.hxx>
25 #include <BRepTopAdaptor_FClass2d.hxx>
26
27 #include <BRepTools.hxx>
28
29 #include <TopAbs.hxx>
30 #include <TopExp_Explorer.hxx>
31 #include <TopExp.hxx>
32 #include <TopTools_ListOfShape.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
34 #include <TDataStd_Integer.hxx>
35
36 //#define  DEB_CALCULATION 1
37 #ifdef DEB_CALCULATION
38 #include <BRepTools.hxx>
39 #include <TopLoc_Location.hxx>
40 #endif 
41 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
42 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
43 #define CALCULATION_GROUPS_PREF GetName() + "_"
44 //#define DEB_CLASS2D 1
45 #ifdef DEB_CLASS2D
46 #include <BRepBuilderAPI_MakeVertex.hxx>
47 #endif
48
49 #define EXPORT_NAME "HYDRO_" + GetName()
50
51 #include <SALOME_NamingService.hxx>
52 #include <SALOME_LifeCycleCORBA.hxx>
53
54
55
56
57
58 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
59 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
60
61 HYDROData_CalculationCase::HYDROData_CalculationCase()
62 : HYDROData_Entity()
63 {
64 }
65
66 HYDROData_CalculationCase::~HYDROData_CalculationCase()
67 {
68 }
69
70 void HYDROData_CalculationCase::SetName( const QString& theName )
71 {
72   QString anOldCaseName = GetName();
73   if ( anOldCaseName != theName )
74   {
75     HYDROData_SequenceOfObjects aRegions = GetRegions();
76
77     HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
78     for ( ; anIter.More(); anIter.Next() )
79     {
80       Handle(HYDROData_Region) aRegion =
81         Handle(HYDROData_Region)::DownCast( anIter.Value() );
82       if ( aRegion.IsNull() )
83         continue;
84
85       HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
86
87       HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
88       HYDROData_SequenceOfObjects::Iterator anIter( aZones );
89       for ( ; anIter.More(); anIter.Next() )
90       {
91         Handle(HYDROData_Zone) aRegZone =
92           Handle(HYDROData_Zone)::DownCast( anIter.Value() );
93         if ( aRegZone.IsNull() )
94           continue;
95
96         HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
97       }
98     }
99
100     HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
101
102     anIter.Init( aGroups );
103     for ( ; anIter.More(); anIter.Next() )
104     {
105       Handle(HYDROData_SplittedShapesGroup) aGroup =
106         Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
107       if ( aGroup.IsNull() )
108         continue;
109
110       HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
111     }
112   }
113
114   HYDROData_Entity::SetName( theName );
115 }
116
117 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
118 {
119   QStringList aResList = dumpObjectCreation( theTreatedObjects );
120
121   QString aCalculName = GetObjPyName();
122
123   AssignmentMode aMode = GetAssignmentMode();
124   QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
125   aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
126
127   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
128   HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
129   for ( ; anIter.More(); anIter.Next() )
130   {
131     Handle(HYDROData_Object) aRefGeomObj =
132       Handle(HYDROData_Object)::DownCast( anIter.Value() );
133     setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
134   }
135   aResList << QString( "" );
136
137   QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
138
139   HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
140   anIter.Init( aGeomGroups );
141   for ( ; anIter.More(); anIter.Next() )
142   {
143     Handle(HYDROData_ShapesGroup) aGeomGroup =
144       Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
145     if ( aGeomGroup.IsNull() )
146       continue;
147
148     Handle(HYDROData_Object) aFatherGeom =
149       Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
150     if ( aFatherGeom.IsNull() )
151       continue;
152
153     int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
154     aResList << QString( "%1 = %2.GetGroup( %3 );" )
155               .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
156
157     aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
158   }
159   aResList << QString( "" );
160
161   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
162   setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
163   aResList << QString( "" );
164
165   if( aMode==AUTOMATIC )
166     DumpRulesToPython( aCalculName, aResList );
167
168   aResList << QString( "" );
169   aResList << QString( "%1.Update();" ).arg( aCalculName );
170   aResList << QString( "" );
171
172   if( aMode==MANUAL )
173   {
174     // Now we restore the regions and zones order
175     HYDROData_SequenceOfObjects aRegions = GetRegions();
176     anIter.Init( aRegions );
177     for ( ; anIter.More(); anIter.Next() )
178     {
179       Handle(HYDROData_Region) aRegion =
180         Handle(HYDROData_Region)::DownCast( anIter.Value() );
181       if ( aRegion.IsNull() )
182         continue;
183
184       QString aRegionName = aRegion->GetName();
185
186       HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
187       HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
188       for ( ; aZonesIter.More(); aZonesIter.Next() )
189       {
190         Handle(HYDROData_Zone) aRegZone =
191           Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
192         if ( aRegZone.IsNull() )
193           continue;
194
195         // TODO
196       }
197     }
198   }
199
200   aResList << QString( "" );
201   return aResList;
202 }
203
204 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
205 {
206   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
207
208   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
209   if ( !aBoundaryPolyline.IsNull() )
210     aResSeq.Append( aBoundaryPolyline );
211
212   HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
213   aResSeq.Append( aSeqOfRegions );
214
215   return aResSeq;
216 }
217
218 void HYDROData_CalculationCase::Update()
219 {
220   HYDROData_Entity::Update();
221   SetWarning();
222
223   // At first we remove previously created objects
224   RemoveRegions();
225   RemoveSplittedGroups();
226
227   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
228   if ( aDocument.IsNull() )
229     return;
230
231   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
232   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
233   if ( aGeomObjects.IsEmpty() )
234     return;
235
236   HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
237
238   HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
239     HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
240   if ( aSplitObjects.isEmpty() )
241     return;
242
243   HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
244
245   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
246   while( anIter.hasNext() )
247   {
248     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
249     if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
250       aZonesList.append( aSplitData );
251     else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
252       anEdgesList.append( aSplitData );
253   }
254
255   switch( GetAssignmentMode() )
256   {
257   case MANUAL:
258     CreateRegionsDef( aDocument, aZonesList );
259     break;
260   case AUTOMATIC:
261     CreateRegionsAuto( aDocument, aZonesList );
262     break;
263   }
264   CreateEdgeGroupsDef( aDocument, anEdgesList );
265 }
266
267 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
268                                                   const HYDROData_SplitToZonesTool::SplitDataList& theZones )
269 {
270   // Create result regions for case, by default one zone for one region
271   QString aRegsPref = CALCULATION_REGIONS_PREF;
272   QString aZonesPref = CALCULATION_ZONES_PREF;
273
274   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
275   while( anIter.hasNext() )
276   {
277     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
278     // Create new region
279     Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
280
281     // Add the zone for region
282     Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
283   }
284 }
285
286 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
287                                                    const HYDROData_SplitToZonesTool::SplitDataList& theZones )
288 {
289   QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
290   QMap<QString, QString> aRegionNameToObjNameMap;
291   QString aZonesPref = CALCULATION_ZONES_PREF;
292   HYDROData_PriorityQueue aPr( this );
293
294   // 1. First we create a default region for each object included into the calculation case
295   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
296   for( int i=aGeomObjects.Lower(), n=aGeomObjects.Upper(); i<=n; i++ )
297   {
298     Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( aGeomObjects.Value( i ) );
299     if( anObj.IsNull() )
300       continue;
301     QString anObjName = anObj->GetName();
302     QString aRegName = anObjName + "_reg";
303     Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
304     aRegionsMap.insert( anObjName, aRegion );
305     aRegionNameToObjNameMap.insert( aRegName, anObjName );
306   }
307
308   // 2. Now for each zone it is necessary to determine the most priority object
309   //    and assign to zone to corresponding region
310   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
311   while( anIter.hasNext() )
312   {
313     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
314     HYDROData_Zone::MergeAltitudesType aMergeType;
315     Handle(HYDROData_Object) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
316     if( aRegObj.IsNull() )
317       continue;
318     Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
319     if( aRegion.IsNull() )
320       continue;
321     Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
322
323     if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
324     {
325       qDebug( "Error in algorithm: unresolved conflicts" );
326     }
327
328     switch( aMergeType )
329     {
330     case HYDROData_Zone::Merge_ZMIN:
331     case HYDROData_Zone::Merge_ZMAX:
332       aRegionZone->SetMergeType( aMergeType );
333       break;
334     case HYDROData_Zone::Merge_Object:
335       aRegionZone->SetMergeType( aMergeType );
336       aRegionZone->RemoveMergeAltitude();
337       aRegionZone->SetMergeAltitude( aRegObj->GetAltitudeObject() );
338       break;
339     }
340   }
341
342   QStringList anObjectsWithEmptyRegions;
343   QMap<QString, Handle(HYDROData_Region)>::const_iterator
344     anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
345   for( ; anIt!=aLast; anIt++ )
346   {
347     Handle(HYDROData_Region) aRegion = anIt.value();
348     if( aRegion->GetZones().IsEmpty() )
349     {
350       QString aRegName = aRegion->GetName();
351       QString anObjName = aRegionNameToObjNameMap[aRegName];
352       anObjectsWithEmptyRegions.append( anObjName );
353     }
354   }
355   
356   if( !anObjectsWithEmptyRegions.empty() )
357   {
358     QString aData = anObjectsWithEmptyRegions.join( ", " );
359     SetWarning( WARN_EMPTY_REGIONS, aData );
360   }
361 }
362
363 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
364                                                      const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
365 {
366   QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
367
368   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
369   while( anIter.hasNext() )
370   {
371     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
372     // Create new edges group
373     if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
374       continue;
375
376     QString anObjName = aSplitData.ObjectNames.first();
377     if ( anObjName.isEmpty() )
378       continue;
379 #ifdef DEB_CALCULATION
380     QString aStr = aSplitData.ObjectNames.join(" "); 
381           cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl; 
382 #endif
383     Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
384     if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
385     {
386       aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
387       aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
388     }
389     else
390     {
391       aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
392     }
393     if ( aSplittedGroup.IsNull() )
394       continue;
395
396     aSplittedGroup->AddShape( aSplitData.Shape );
397   }
398 }
399
400 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
401 {
402   if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
403     return false; // Wrong type of object
404
405   if ( HasReference( theObject, DataTag_GeometryObject ) )
406     return false; // Object is already in reference list
407
408   AddReferenceObject( theObject, DataTag_GeometryObject );
409   
410   // Indicate model of the need to update splitting
411   SetToUpdate( true );
412
413   return true;
414 }
415
416 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
417 {
418   return GetReferenceObjects( DataTag_GeometryObject );
419 }
420
421 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
422 {
423   if ( theObject.IsNull() )
424     return;
425
426   RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
427
428   // Indicate model of the need to update splitting
429   SetToUpdate( true );
430 }
431
432 void HYDROData_CalculationCase::RemoveGeometryObjects()
433 {
434   ClearReferenceObjects( DataTag_GeometryObject );
435
436   // Indicate model of the need to update splitting
437   SetToUpdate( true );
438 }
439
440 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
441 {
442   if ( theGroup.IsNull() )
443     return false;
444
445   if ( HasReference( theGroup, DataTag_GeometryGroup ) )
446     return false; // Object is already in reference list
447
448   AddReferenceObject( theGroup, DataTag_GeometryGroup );
449   
450   // Indicate model of the need to update splitting
451   SetToUpdate( true );
452
453   return true;
454 }
455
456 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
457 {
458   return GetReferenceObjects( DataTag_GeometryGroup );
459 }
460
461 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
462 {
463   if ( theGroup.IsNull() )
464     return;
465
466   RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
467
468   // Indicate model of the need to update splitting
469   SetToUpdate( true );
470 }
471
472 void HYDROData_CalculationCase::RemoveGeometryGroups()
473 {
474   ClearReferenceObjects( DataTag_GeometryGroup );
475
476   // Indicate model of the need to update splitting
477   SetToUpdate( true );
478 }
479
480 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
481 {
482   Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
483
484   SetReferenceObject( thePolyline, DataTag_Polyline );
485
486   // Indicate model of the need to update zones splitting
487   SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
488 }
489
490 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
491 {
492   return Handle(HYDROData_PolylineXY)::DownCast( 
493            GetReferenceObject( DataTag_Polyline ) );
494 }
495
496 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
497 {
498   Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
499
500   ClearReferenceObjects( DataTag_Polyline );
501
502   // Indicate model of the need to update zones splitting
503   SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
504 }
505
506 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
507 {
508   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
509   Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
510   if ( aNewRegion.IsNull() )
511     return aNewRegion;
512
513   aNewRegion->AddZone( theZone );
514
515   return aNewRegion;
516 }
517
518 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
519 {
520   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
521
522   if ( theRegion.IsNull() )
523     return false;
524   
525   if ( HasReference( theRegion, DataTag_Region ) )
526     return false; // Object is already in reference list
527
528   // Move the region from other calculation
529   Handle(HYDROData_CalculationCase) aFatherCalc = 
530     Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
531   if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
532   {
533     Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
534     theRegion->CopyTo( aNewRegion );
535
536     aFatherCalc->RemoveRegion( theRegion );
537
538     theRegion->SetLabel( aNewRegion->Label() );
539   }
540   else
541   {
542     AddReferenceObject( theRegion, DataTag_Region );
543   }
544
545   return true;
546 }
547
548 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
549 {
550   return GetReferenceObjects( DataTag_Region );
551 }
552
553 void HYDROData_CalculationCase::UpdateRegionsOrder()
554 {
555   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
556   if ( aDocument.IsNull() )
557     return;
558
559   HYDROData_SequenceOfObjects aRegions = GetRegions();
560
561   HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
562   for ( ; anIter.More(); anIter.Next() )
563   {
564     Handle(HYDROData_Region) aRegion =
565       Handle(HYDROData_Region)::DownCast( anIter.Value() );
566     if ( aRegion.IsNull() )
567       continue;
568
569     aRegion->SetName( "" );
570   }
571
572   QString aRegsPref = CALCULATION_REGIONS_PREF;
573
574   anIter.Init( aRegions );
575   for ( ; anIter.More(); anIter.Next() )
576   {
577     Handle(HYDROData_Region) aRegion =
578       Handle(HYDROData_Region)::DownCast( anIter.Value() );
579     if ( aRegion.IsNull() )
580       continue;
581
582     QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
583     aRegion->SetName( aRegionName );
584   }
585 }
586
587 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
588 {
589   if ( theRegion.IsNull() )
590     return;
591
592   RemoveReferenceObject( theRegion->Label(), DataTag_Region );
593
594   // Remove region from data model
595   Handle(HYDROData_CalculationCase) aFatherCalc = 
596     Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
597   if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
598     theRegion->Remove();
599 }
600
601 void HYDROData_CalculationCase::RemoveRegions()
602 {
603   myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
604 }
605
606 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
607 {
608   return GetReferenceObjects( DataTag_SplittedGroups );
609 }
610
611 void HYDROData_CalculationCase::RemoveSplittedGroups()
612 {
613   myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
614 }
615
616 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
617 {
618   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
619   return GetAltitudeForPoint( thePoint, aZone );
620 }
621
622 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY&                    thePoint,
623                                                        const Handle(HYDROData_Region)& theRegion ) const
624 {
625   double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
626
627   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
628   if ( !aZone.IsNull() )
629   {
630     Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
631     if ( IsEqual( aRefRegion, theRegion ) )
632       aResAltitude = GetAltitudeForPoint( thePoint, aZone );
633   }
634
635   return aResAltitude;
636 }
637
638 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY&                  thePoint,
639                                                        const Handle(HYDROData_Zone)& theZone ) const
640 {
641   double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
642   if ( theZone.IsNull() )
643     return aResAltitude;
644
645   HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
646   if ( !theZone->IsMergingNeed() )
647   {
648     aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
649   }
650   else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
651   {
652     return aResAltitude;
653   }
654
655   HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
656   if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
657   {
658     Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
659     if ( !aMergeAltitude.IsNull() )
660     {
661       if ( aZoneInterpolator != NULL )
662       {
663         aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
664         aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
665       }
666       else
667         aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
668     }
669   }
670   else
671   {
672     HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
673     HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
674     for ( ; anIter.More(); anIter.Next() )
675     {
676       Handle(HYDROData_Object) aZoneObj =
677         Handle(HYDROData_Object)::DownCast( anIter.Value() );
678       if ( aZoneObj.IsNull() )
679         continue;
680
681       Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
682       if ( anObjAltitude.IsNull() )
683         continue;
684
685       double aPointAltitude = 0.0;
686       if ( aZoneInterpolator != NULL )
687       {
688         aZoneInterpolator->SetAltitudeObject( anObjAltitude );
689         aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
690       }
691       else
692         aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
693
694       if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
695         continue;
696
697       if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
698       {
699         aResAltitude = aPointAltitude;
700         break;
701       }
702       else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
703       {
704         if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
705              aResAltitude > aPointAltitude )
706         {
707           aResAltitude = aPointAltitude;
708         }
709       }
710       else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
711       {
712         if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
713              aResAltitude < aPointAltitude )
714         {
715           aResAltitude = aPointAltitude;
716         }
717       }
718     }
719   }
720
721   return aResAltitude;
722 }
723
724 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints( 
725   const NCollection_Sequence<gp_XY>& thePoints,
726   const Handle(HYDROData_Region)&    theRegion ) const
727 {
728   NCollection_Sequence<double> aResSeq;
729
730   for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
731   {
732     const gp_XY& thePnt = thePoints.Value( i );
733     
734     double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
735     aResSeq.Append( anAltitude );
736   }
737
738   return aResSeq;
739 }
740
741 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints( 
742   const NCollection_Sequence<gp_XY>& thePoints,
743   const Handle(HYDROData_Zone)&      theZone ) const
744 {
745   NCollection_Sequence<double> aResSeq;
746
747   for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
748   {
749     const gp_XY& thePnt = thePoints.Value( i );
750     
751     double anAltitude = GetAltitudeForPoint( thePnt, theZone );
752     aResSeq.Append( anAltitude );
753   }
754
755   return aResSeq;
756 }
757
758 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
759 {
760   Handle(HYDROData_Region) aResRegion;
761
762   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
763   if ( !aZone.IsNull() )
764     aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
765
766   return aResRegion;
767 }
768
769 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
770 {
771   Handle(HYDROData_Zone) aResZone;
772
773   HYDROData_SequenceOfObjects aRegions = GetRegions();
774
775   HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
776   for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
777   {
778     Handle(HYDROData_Region) aRegion =
779       Handle(HYDROData_Region)::DownCast( anIter.Value() );
780     if ( aRegion.IsNull() )
781       continue;
782
783     HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
784     HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
785     for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
786     {
787       Handle(HYDROData_Zone) aRegZone =
788         Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
789       if ( aRegZone.IsNull() )
790         continue;
791
792       PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
793       if ( aPointRelation != POINT_OUT )
794         aResZone = aRegZone; // We found the desired zone
795     }
796   }
797
798   return aResZone;
799 }
800
801 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
802   const gp_XY&                  thePoint,
803   const Handle(HYDROData_Zone)& theZone ) const
804 {
805   PointClassification aRes = POINT_OUT;
806   if ( theZone.IsNull() )
807     return aRes;
808
809   TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
810   if ( aZoneFace.IsNull() )
811     return aRes;
812 #ifdef DEB_CLASS2D      
813           TopoDS_Compound aCmp;
814       BRep_Builder aBB;
815       aBB.MakeCompound(aCmp);
816           aBB.Add(aCmp, aZoneFace);
817           gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
818           BRepBuilderAPI_MakeVertex aMk(aPnt);
819           aBB.Add(aCmp, aMk.Vertex());
820           BRepTools::Write(aCmp, "FCL2d.brep");
821 #endif  
822   TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
823   if (State == TopAbs_OUT)
824     aRes =  POINT_OUT;
825   else if(State == TopAbs_IN)
826     aRes =  POINT_IN;
827   else if(State == TopAbs_ON)
828     aRes =  POINT_ON;
829   return aRes;
830 }
831
832 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
833                                                                   const QString& thePrefixOrName,
834                                                                   bool isPrefix )
835 {
836   TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
837
838   Handle(HYDROData_Region) aNewRegion =
839     Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
840   AddRegion( aNewRegion );
841
842   QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
843   aNewRegion->SetName( aRegionName );
844
845   return aNewRegion;
846 }
847
848 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
849 {
850   TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
851
852   Handle(HYDROData_SplittedShapesGroup) aNewGroup =
853     Handle(HYDROData_SplittedShapesGroup)::DownCast( 
854       HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
855   AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
856
857   aNewGroup->SetName( theName );
858
859   return aNewGroup;
860 }
861
862 QString HYDROData_CalculationCase::Export( int theStudyId ) const
863 {
864   int argc = 0;
865   char** argv = 0;
866   CORBA::ORB_var anORB = CORBA::ORB_init( argc, argv, "omniORB4"/*CORBA::ORB_ID*/ );
867   SALOME_NamingService aNameService( anORB );
868   SALOME_LifeCycleCORBA aLCC( &aNameService );
869   Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component( "FactoryServer", "GEOM" );
870   GEOM::GEOM_Gen_var aGEOMEngine = GEOM::GEOM_Gen::_narrow( aComponent );
871   
872   CORBA::Object_var aSMObject = aNameService.Resolve("/myStudyManager");
873   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
874   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( theStudyId );
875
876   QString aGeomObjEntry;
877   bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry );
878   return isOK ? aGeomObjEntry : QString();
879 }
880
881 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var  theGeomEngine,
882                                         SALOMEDS::Study_ptr theStudy,
883                                         QString& theGeomObjEntry ) const
884 {
885   HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
886
887   // Get groups definitions
888   HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
889
890   HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
891   for ( ; anIter.More(); anIter.Next() )
892   {
893     // Get shapes group
894     Handle(HYDROData_ShapesGroup) aGroup =
895       Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
896     if ( aGroup.IsNull() )
897       continue;
898
899     HYDROData_ShapesGroup::GroupDefinition aGroupDef;
900
901     aGroupDef.Name = aGroup->GetName().toLatin1().constData();
902     aGroup->GetShapes( aGroupDef.Shapes );
903
904     aSeqOfGroupsDefs.Append( aGroupDef );
905   }
906   
907   // Get faces
908   TopTools_ListOfShape aFaces;
909   HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
910   HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
911   for ( ; aRegionIter.More(); aRegionIter.Next() )
912   {
913     Handle(HYDROData_Region) aRegion =
914       Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
915     if( aRegion.IsNull() )
916       continue;
917
918     TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
919     aFaces.Append( aRegionShape );
920   }
921
922   return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );
923 }
924
925 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var                            theGeomEngine,
926                                         SALOMEDS::Study_ptr                           theStudy,
927                                         const TopTools_ListOfShape&                   theFaces,
928                                         const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
929                                         QString& theGeomObjEntry ) const
930 {
931   // Sew faces
932   BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
933   aSewing.SetNonManifoldMode( Standard_False );
934 #ifdef DEB_CALCULATION
935   TCollection_AsciiString aNam("Sh_");
936   int i=1;
937 #endif
938   TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
939   for ( ; aFaceIter.More(); aFaceIter.Next() )
940   {
941     TopoDS_Shape aShape = aFaceIter.Value();
942     if ( aShape.IsNull() )
943       continue;
944
945     if ( aShape.ShapeType() == TopAbs_FACE )
946     {
947       aSewing.Add( aShape );
948 #ifdef DEB_CALCULATION
949       TCollection_AsciiString aName = aNam + ++i + ".brep";
950       BRepTools::Write(aShape ,aName.ToCString());
951 #endif
952     }
953     else
954     {
955 #ifdef DEB_CALCULATION
956       int j = 1;
957 #endif
958       TopExp_Explorer anExp( aShape, TopAbs_FACE );
959       for (; anExp.More(); anExp.Next() ) {
960         aSewing.Add( anExp.Current() );
961 #ifdef DEB_CALCULATION
962
963         TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
964         BRepTools::Write(anExp.Current() ,aName.ToCString());
965 #endif
966       }
967     }
968   } // faces iterator
969   
970   aSewing.Perform();
971   TopoDS_Shape aSewedShape = aSewing.SewedShape();
972
973   // If the sewed shape is empty - return false
974   if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
975     return false;
976
977 #ifdef DEB_CALCULATION
978   BRepTools::Write(aSewedShape ,"Sew.brep");
979 #endif
980   // Publish the sewed shape
981   QString aName = EXPORT_NAME;
982   GEOM::GEOM_Object_ptr aMainShape = 
983     publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
984
985   if ( aMainShape->_is_nil() )  
986     return false;
987
988   if ( theGroupsDefs.IsEmpty() )
989     return true;
990
991   // Create groups
992   TopTools_IndexedMapOfShape aMapOfSubShapes;
993   TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
994
995   NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
996
997   for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
998   {
999     const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1000
1001     NCollection_Sequence<int> aGroupIndexes;
1002     for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1003     {
1004       const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1005 #ifdef DEB_CALCULATION
1006       cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1007 #endif
1008       
1009       TopoDS_Shape aModifiedShape = aShape;
1010       if ( aSewing.IsModified( aShape ) )
1011         aModifiedShape = aSewing.Modified( aShape );
1012       else if ( aSewing.IsModifiedSubShape( aShape ) )
1013         aModifiedShape = aSewing.ModifiedSubShape( aShape );
1014
1015 #ifdef DEB_CALCULATION
1016       const TopLoc_Location& aL1 = aShape.Location();
1017       const TopLoc_Location& aL2 = aModifiedShape.Location();
1018       cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1019 #endif
1020
1021       int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1022       if ( anIndex > 0 ) {
1023         aGroupIndexes.Append( anIndex );
1024       } else {
1025 #ifdef DEB_CALCULATION    
1026         TCollection_AsciiString aNam("Lost_");
1027         if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1028         for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1029         {
1030            const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1031            if ( aModifiedShape.IsPartner( aS ) )
1032            {
1033              cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1034              TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1035              BRepTools::Write(aS ,aName.ToCString());
1036             break;
1037            }
1038          }
1039         }
1040 #endif
1041       }
1042     }
1043     if ( !aGroupIndexes.IsEmpty() )
1044       aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1045   }
1046  
1047   if ( !aGroupsData.IsEmpty() )
1048   {
1049     GEOM::GEOM_IGroupOperations_var aGroupOp = 
1050       theGeomEngine->GetIGroupOperations( theStudy->StudyId() );  
1051
1052     NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1053     for ( ; aMapIt.More(); aMapIt.Next() )
1054     {
1055       const TCollection_AsciiString& aGroupName = aMapIt.Key(); 
1056       const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1057
1058       GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1059       if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1060         continue;
1061
1062       GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1063       aGeomIndexes->length( aGroupIndexes.Length() );
1064
1065       for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1066         aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1067
1068       aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1069       if ( aGroupOp->IsDone() )
1070       {
1071         SALOMEDS::SObject_var aGroupSO = 
1072           theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1073       }
1074     }
1075   }
1076
1077   return true;
1078 }
1079
1080 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM( 
1081   GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
1082   const TopoDS_Shape& theShape, const QString& theName,
1083   QString& theGeomObjEntry ) const
1084 {
1085   theGeomObjEntry = "";
1086   GEOM::GEOM_Object_var aGeomObj;
1087
1088   if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
1089        theShape.IsNull() ) {
1090     return aGeomObj._retn();
1091   }
1092
1093   std::ostringstream aStreamShape;
1094   // Write TopoDS_Shape in ASCII format to the stream
1095   BRepTools::Write( theShape, aStreamShape );
1096   // Returns the number of bytes that have been stored in the stream's buffer.
1097   int aSize = aStreamShape.str().size();
1098   // Allocate octect buffer of required size
1099   CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
1100   // Copy ostrstream content to the octect buffer
1101   memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
1102   // Create TMPFile
1103   SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
1104
1105   // Restore shape from the stream and get the GEOM object
1106   GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
1107   aGeomObj = anInsOp->RestoreShape( aSeqFile );
1108   
1109   // Puplish the GEOM object
1110   if ( !aGeomObj->_is_nil() ) {
1111     QString aName = GEOMBase::GetDefaultName( theName );
1112
1113     SALOMEDS::SObject_var aResultSO = 
1114       theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), 
1115                                      aGeomObj, qPrintable( aName ) );
1116     if ( aResultSO->_is_nil() ) {
1117       aGeomObj = GEOM::GEOM_Object::_nil();
1118     }
1119     else
1120       theGeomObjEntry = aResultSO->GetID();
1121   }
1122
1123   return aGeomObj._retn();
1124 }
1125
1126 void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate )
1127 {
1128   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1129   HYDROData_PriorityQueue::ClearRules( aRulesLab );
1130
1131   // Indicate model of the need to update splitting
1132   if ( theIsSetToUpdate ) {
1133     SetToUpdate( true );
1134   }
1135 }
1136
1137 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)&    theObject1,
1138                                          HYDROData_PriorityType             thePriority,
1139                                          const Handle(HYDROData_Object)&    theObject2,
1140                                          HYDROData_Zone::MergeAltitudesType theMergeType )
1141 {
1142   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1143   HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1144
1145   // Indicate model of the need to update splitting
1146   SetToUpdate( true );
1147 }
1148
1149 QString HYDROData_CalculationCase::DumpRules() const
1150 {
1151   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1152   return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1153 }
1154
1155 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1156 {
1157   TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1158   TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1159
1160   // Indicate model of the need to update splitting
1161   SetToUpdate( true );
1162 }
1163
1164 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1165 {
1166   Handle(TDataStd_Integer) aModeAttr;
1167   bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1168   if( isOK )
1169     return ( AssignmentMode ) aModeAttr->Get();
1170   else
1171     return MANUAL;
1172 }
1173
1174 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1175                                                    QStringList& theScript ) const
1176 {
1177   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1178   HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1179 }
1180
1181 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1182 {
1183   return myLastWarning;
1184 }
1185
1186 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1187 {
1188   myLastWarning.Type = theType;
1189   myLastWarning.Data = theData;
1190 }
1191
1192 bool HYDROData_CalculationCase::GetRule( int theIndex, 
1193                                          Handle(HYDROData_Object)&           theObject1,
1194                                          HYDROData_PriorityType&             thePriority,
1195                                          Handle(HYDROData_Object)&           theObject2,
1196                                          HYDROData_Zone::MergeAltitudesType& theMergeType ) const
1197 {
1198   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1199   return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1200     theObject1, thePriority, theObject2, theMergeType );
1201 }