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