]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_CalculationCase.cxx
Salome HOME
refs #1833: progress dialog for Strickler coefficient interpolation.
[modules/hydro.git] / src / HYDROData / HYDROData_CalculationCase.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_CalculationCase.h"
20 #include "HYDROData_ArtificialObject.h"
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_Iterator.h"
25 #include "HYDROData_NaturalObject.h"
26 #include "HYDROData_PolylineXY.h"
27 #include "HYDROData_StricklerTable.h"
28 #include "HYDROData_LandCoverMap.h"
29 #include "HYDROData_SplitShapesGroup.h"
30 #include "HYDROData_Region.h"
31 #include "HYDROData_Tool.h"
32 #include "HYDROData_GeomTool.h"
33 #include <HYDROData_Tool.h>
34 #include <HYDROData_BCPolygon.h>
35 #include <HYDROData_BoundaryPolygonTools.h>
36
37 #ifdef WIN32
38   #pragma warning ( disable: 4251 )
39 #endif
40
41 #ifndef LIGHT_MODE
42 #include <GEOMBase.h>
43 #endif
44
45 #ifdef WIN32
46   #pragma warning ( default: 4251 )
47 #endif
48
49 #include <QSet>
50 #include <QFuture>
51 #include <QtConcurrent/QtConcurrent>
52 #include <QThread>
53
54 #include <TopoDS.hxx>
55 #include <TopoDS_Shell.hxx>
56 #include <TopoDS_Edge.hxx>
57
58 #include <BRep_Builder.hxx>
59 #include <BRepBuilderAPI_Sewing.hxx>
60 #include <BRepTopAdaptor_FClass2d.hxx>
61 #include <BRepTools_ReShape.hxx>
62 #include <BRepLib_MakeWire.hxx>
63
64 #include <BRepTools.hxx>
65
66 #include <TopAbs.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopExp.hxx>
69 #include <TopTools_ListOfShape.hxx>
70 #include <TopTools_ListIteratorOfListOfShape.hxx>
71 #include <TDataStd_Integer.hxx>
72
73 //#define  DEB_CALCULATION 1
74 #ifdef DEB_CALCULATION
75 #include <BRepTools.hxx>
76 #include <TopLoc_Location.hxx>
77 #endif 
78 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
79 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
80 #define CALCULATION_GROUPS_PREF GetName() + "_"
81 //#define DEB_CLASS2D 1
82 #ifdef DEB_CLASS2D
83 #include <BRepBuilderAPI_MakeVertex.hxx>
84 #endif
85
86 #define EXPORT_NAME "HYDRO_" + GetName()
87
88 #ifndef LIGHT_MODE
89 #include <SALOME_NamingService.hxx>
90 #include <SALOME_LifeCycleCORBA.hxx>
91 #endif
92
93 //#define _DEVDEBUG_
94 #include "HYDRO_trace.hxx"
95
96 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
97
98 HYDROData_CalculationCase::HYDROData_CalculationCase()
99 : HYDROData_Entity( Geom_2d_and_groups )
100 {
101 }
102
103 HYDROData_CalculationCase::~HYDROData_CalculationCase()
104 {
105 }
106
107 void HYDROData_CalculationCase::SetName( const QString& theName )
108 {
109   QString anOldCaseName = GetName();
110   if ( anOldCaseName != theName )
111   {
112     // Update names of regions and its zones
113     UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
114
115     HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
116
117     HYDROData_SequenceOfObjects::Iterator anIter;
118     anIter.Init( aGroups );
119     for ( ; anIter.More(); anIter.Next() )
120     {
121       Handle(HYDROData_SplitShapesGroup) aGroup =
122         Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
123       if ( aGroup.IsNull() )
124         continue;
125
126       HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
127     }
128   }
129
130   HYDROData_Entity::SetName( theName );
131 }
132
133 QStringList HYDROData_CalculationCase::DumpToPython( const QString&       thePyScriptPath,
134                                                      MapOfTreatedObjects& theTreatedObjects ) const
135 {
136   QStringList aResList = dumpObjectCreation( theTreatedObjects );
137   aResList.prepend( "# Calculation case" );
138
139   QString aCalculName = GetObjPyName();
140
141   AssignmentMode aMode = GetAssignmentMode();  
142   QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
143   aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
144
145   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
146   HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
147   for ( ; anIter.More(); anIter.Next() )
148   {
149     Handle(HYDROData_Object) aRefGeomObj =
150       Handle(HYDROData_Object)::DownCast( anIter.Value() );
151     setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
152   }
153   aResList << QString( "" );
154
155   QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
156
157   HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
158   anIter.Init( aGeomGroups );
159   for ( ; anIter.More(); anIter.Next() )
160   {
161     Handle(HYDROData_ShapesGroup) aGeomGroup =
162       Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
163     if ( aGeomGroup.IsNull() )
164       continue;
165
166     Handle(HYDROData_Object) aFatherGeom =
167       Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
168     if ( aFatherGeom.IsNull() )
169       continue;
170
171     int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
172     aResList << QString( "%1 = %2.GetGroup( %3 )" )
173               .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
174
175     aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
176   }
177
178   HYDROData_SequenceOfObjects aBPolygons = GetBoundaryPolygons();
179   for (int i = 1; i <= aBPolygons.Size(); i++ )
180   {
181     Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBPolygons(i) );
182     setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBCPoly, "AddBoundaryPolygon" );
183   }
184   aResList << QString( "" );
185
186   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
187   setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
188
189   Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
190   setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
191
192   Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
193   setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
194
195   if( aMode==AUTOMATIC )
196     DumpRulesToPython( aCalculName, aResList );
197
198   aResList << QString( "" );
199   aResList << "# Start the algorithm of the partition and assignment";
200   aResList << QString( "%1.Update()" ).arg( aCalculName );
201
202   if( aMode==MANUAL )
203   {
204     // Now we restore the
205     // - regions and zones order
206     DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );   
207   }
208
209   // Export calculation case
210   aResList << QString( "" );
211   aResList << "# Export of the calculation case";
212   QString aStudyName = "theStudy";
213   QString anEntryVar = aCalculName + "_entry";
214   aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
215
216   // Get geometry object and print debug information
217   aResList << "";
218   aResList << "# Get geometry shape and print debug information";
219   aResList << "import GEOM";
220   aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
221   QString aGeomShapeName = aCalculName + "_geom";
222   aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
223   aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
224   aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
225
226
227   //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
228
229   aResList << QString( "" );
230   return aResList;
231 }
232
233 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
234                                                    const QString& theStudyName,
235                                                    const QString& theGeomShapeName,
236                                                    const QString& theMeshName ) const
237 {
238   theResList << "";
239   theResList << "# Meshing";
240   theResList << "import SMESH, SALOMEDS";
241   theResList << "from salome.smesh import smeshBuilder";
242   theResList << "from salome.geom import geomBuilder";
243
244   theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
245   theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
246   theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
247   theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
248   theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
249   theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
250   theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
251
252   theResList << "";
253   theResList << "# Set names of Mesh objects";
254   theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
255   theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
256   theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
257   theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
258   theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
259
260   theResList << "";
261   theResList << "# Greate SMESH groups";
262   theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
263   theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
264   theResList << QString( "for group in geom_groups:" );
265   theResList << QString( "    smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
266                 .arg( theMeshName );
267   theResList << QString( "    smesh.SetName(smesh_group, group.GetName())" );
268   theResList << QString( "    print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
269 }
270
271 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
272 {
273   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
274
275   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
276   if ( !aBoundaryPolyline.IsNull() )
277     aResSeq.Append( aBoundaryPolyline );
278
279   HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
280   aResSeq.Append( aSeqOfGeomObjs );
281
282   // Regions
283   HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
284   aResSeq.Append( aSeqOfRegions );
285
286   return aResSeq;
287 }
288
289 static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
290                                                            HYDROData_SequenceOfObjects aBoundaryPolygons,
291                                                            HYDROData_SplitToZonesTool::SplitDataList& outEdgesList)
292 {
293   //perform boundary condition polygons on EdgesList
294   TopTools_SequenceOfShape IncTools, SelectionTools;
295   HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
296   for (int i=1; i<=aBoundaryPolygons.Size();i++)
297   {
298     Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
299     TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
300     int bType = aBCPoly->GetBoundaryType();
301     if (bType == 2) 
302       IncTools.Append(aPolyTopShape);
303     else if (bType == 3)
304       SelectionTools.Append(aPolyTopShape);
305   }
306   
307   while( anIter.hasNext() )
308   {
309     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
310     if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
311       continue;
312     if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
313       continue;
314     if (HYDROData_BoundaryPolygonTools::IncludeTool(IncTools, aSplitData.Shape) && HYDROData_BoundaryPolygonTools::SelectionTool(SelectionTools, aSplitData.Shape))
315       outEdgesList.append(aSplitData);
316   }
317 }
318
319
320 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
321                                           const HYDROData_SequenceOfObjects& aBoundaryPolygons,
322                                           NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes)
323 {
324   //perform boundary condition polygons on EdgesList
325   TopTools_SequenceOfShape CutTools;
326   ObjToRes.Clear();
327   HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
328   for (int i=1; i<=aBoundaryPolygons.Size();i++)
329   {
330     Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
331     TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
332     int bType = aBCPoly->GetBoundaryType();
333     if (bType == 1) 
334       CutTools.Append(aPolyTopShape);
335   }
336   
337   while( anIter.hasNext() )
338   {
339     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
340     if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
341       continue;
342     if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
343       continue;
344     ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
345   }
346
347   HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes);
348 }
349
350
351 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
352                                    const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
353                                    HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
354 {
355   HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList ); 
356   BRepTools_ReShape reshaper;
357   for (;it.hasNext();)
358   {
359     const HYDROData_SplitToZonesTool::SplitData& aSplitData = it.next();
360     if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
361       continue;
362
363     TopoDS_Shape mS = aSplitData.Shape;
364     for (int i=1; i<=ObjToRes.Extent();i++)
365     {
366       TopoDS_Shape K = ObjToRes.FindKey(i);
367       TopoDS_Shape V = ObjToRes.FindFromIndex(i);
368       if (V.ShapeType() != TopAbs_EDGE && V.ShapeType() != TopAbs_WIRE && V.ShapeType() != TopAbs_COMPOUND)
369         continue;
370       if (V.ShapeType() == TopAbs_COMPOUND)
371       {
372         TopExp_Explorer exp(V, TopAbs_EDGE);
373         TopTools_ListOfShape lE;
374         for (;exp.More();exp.Next())
375           lE.Append(exp.Current());
376         if (lE.Extent() == 1)
377           V = lE.First();
378         else if (lE.Extent() > 1)
379         {
380           BRepLib_MakeWire MW;
381           MW.Add(lE);
382           if (MW.IsDone())
383             V = MW.Wire();
384           else
385             continue;
386         }
387         else 
388           continue;
389       }
390       reshaper.Replace(K, V);
391     }
392     TopoDS_Shape nS = reshaper.Apply(mS);
393     HYDROData_SplitToZonesTool::SplitData aNS(aSplitData.Type, nS, aSplitData.ObjectNames);
394     outZoneList.append(aNS);
395   } 
396 }
397
398 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
399                                const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
400                                HYDROData_SplitToZonesTool::SplitDataList& newEdges)
401 {
402   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
403   while( anIter.hasNext() )
404   {
405     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
406     if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
407       continue;
408
409     const TopoDS_Shape* aDivShape = ObjToRes.Seek(aSplitData.Shape);
410     if (aDivShape)
411     {
412       TopExp_Explorer exp(*aDivShape, TopAbs_EDGE);
413       for (;exp.More();exp.Next())
414       {
415         HYDROData_SplitToZonesTool::SplitData anNewSData(aSplitData.Type, exp.Current(), aSplitData.ObjectNames);
416         newEdges.append(anNewSData);
417       }
418     }
419     else
420       newEdges.append(aSplitData);
421   }
422 }
423
424
425 void HYDROData_CalculationCase::Update()
426 {
427   HYDROData_Entity::Update();
428   SetWarning();
429
430   // At first we remove previously created objects
431   RemoveRegions();
432   RemoveSplitGroups();
433
434   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
435   if ( aDocument.IsNull() )
436     return;
437
438   // Split to zones
439   HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
440
441   Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
442
443   HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
444
445   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
446   if ( !aGeomObjects.IsEmpty() ) {
447     HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
448
449     HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
450       HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
451     if ( !aSplitObjects.isEmpty() ) {
452       HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
453       while( anIter.hasNext() ) {
454         const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
455         if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
456           aZonesList.append( aSplitData );
457         else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
458                   aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
459           anEdgesList.append( aSplitData );
460       }
461     }
462   }
463
464   //
465   //split edges by boundary polygons
466   HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
467   //edge to splitted edge (compound of edges or original edge)
468   NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape> ObjToRes;
469   //split edge list by BP
470   SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes);
471   HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
472   //replace splitted edges in zone list (faces)
473   PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
474   //
475   //create new edges list based on splitting info from ObjToRes
476   HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
477   CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
478   //filter out edges list by include&selection tools 
479   FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
480   
481   switch( GetAssignmentMode() )
482   {
483   case MANUAL:
484     CreateRegionsDef( aDocument,aNewZonesList );    
485     break;
486   case AUTOMATIC:
487     CreateRegionsAuto( aDocument,aNewZonesList );    
488     break;
489   }
490
491   CreateEdgeGroupsDef( aDocument, newEdgesList2 );
492 }
493
494 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
495                                                   const HYDROData_SplitToZonesTool::SplitDataList& theZones )
496 {
497   // Create result regions for case, by default one zone for one region
498   QString aRegsPref = CALCULATION_REGIONS_PREF;
499   QString aZonesPref = CALCULATION_ZONES_PREF;
500
501   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
502   while( anIter.hasNext() )
503   {
504     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
505     // Create new region
506     Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
507
508     // Add the zone for region
509     Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
510   }
511 }
512
513 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
514                                                    const HYDROData_SplitToZonesTool::SplitDataList& theZones )
515 {
516   DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
517   QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
518   QMap<QString, QString> aRegionNameToObjNameMap;
519   QString aZonesPref = CALCULATION_ZONES_PREF;
520   HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
521
522   // 1. First we create a default region for each object included into the calculation case
523   HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
524   for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
525   {
526     Handle(HYDROData_Entity) anObj = anObjects.Value( i );
527     if( anObj.IsNull() )
528       continue;
529     QString anObjName = anObj->GetName();
530     QString aRegName = anObjName + "_reg";
531     Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
532     aRegionsMap.insert( anObjName, aRegion );
533     aRegionNameToObjNameMap.insert( aRegName, anObjName );
534   }
535
536   // 2. Now for each zone it is necessary to determine the most priority object
537   //    and assign to zone to corresponding region
538   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
539   while( anIter.hasNext() )
540   {
541     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
542     HYDROData_Zone::MergeType aMergeType;
543     Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
544     if( aRegObj.IsNull() )
545       continue;
546     Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
547     if( aRegion.IsNull() )
548       continue;
549     Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
550
551     if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
552     {
553       qDebug( "Error in algorithm: unresolved conflicts" );
554     }
555
556     Handle(HYDROData_Entity) aMergeEntity = aRegObj;
557     Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
558     if ( !aMergeObject.IsNull() ) {
559       DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
560       aMergeEntity = aMergeObject->GetAltitudeObject();
561     }
562
563     switch( aMergeType )
564     {
565     case HYDROData_Zone::Merge_ZMIN:
566     case HYDROData_Zone::Merge_ZMAX:
567       aRegionZone->SetMergeType( aMergeType );
568       break;
569     case HYDROData_Zone::Merge_Object:
570       aRegionZone->SetMergeType( aMergeType );
571       aRegionZone->RemoveMergeObject();
572       aRegionZone->SetMergeObject( aMergeEntity );
573       break;
574     }
575   }
576
577   QStringList anObjectsWithEmptyRegions;
578   QMap<QString, Handle(HYDROData_Region)>::const_iterator
579     anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
580   for( ; anIt!=aLast; anIt++ )
581   {
582     Handle(HYDROData_Region) aRegion = anIt.value();
583     if( aRegion->GetZones().IsEmpty() )
584     {
585       QString aRegName = aRegion->GetName();
586       QString anObjName = aRegionNameToObjNameMap[aRegName];
587       anObjectsWithEmptyRegions.append( anObjName );
588     }
589   }
590   
591   if( !anObjectsWithEmptyRegions.empty() )
592   {
593     QString aData = anObjectsWithEmptyRegions.join( ", " );
594     SetWarning( WARN_EMPTY_REGIONS, aData );
595   }
596 }
597
598 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
599                                                      const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
600 {
601   QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
602
603   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
604   while( anIter.hasNext() )
605   {
606     const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
607     // Create new edges group
608     if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
609       continue;
610
611     QString anObjName = aSplitData.ObjectNames.first();
612     if ( anObjName.isEmpty() )
613       continue;
614 #ifdef DEB_CALCULATION
615     QString aStr = aSplitData.ObjectNames.join(" "); 
616           cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl; 
617 #endif
618     Handle(HYDROData_SplitShapesGroup) aSplitGroup;
619     if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
620     {
621       aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
622       aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
623     }
624     else
625     {
626       aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
627     }
628     if ( aSplitGroup.IsNull() )
629       continue;
630
631       aSplitGroup->AddShape( aSplitData.Shape );
632
633     TopTools_SequenceOfShape theShapes;
634     aSplitGroup->GetShapes(theShapes);
635
636     if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
637       aSplitGroup->SetInternal(true); 
638   }
639 }
640
641 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
642 {
643   if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
644     return false; // Wrong type of object
645
646   if ( HasReference( theObject, DataTag_GeometryObject ) )
647     return false; // Object is already in reference list
648
649   AddReferenceObject( theObject, DataTag_GeometryObject );
650   
651   // Indicate model of the need to update splitting
652   Changed( Geom_2d );
653
654   return true;
655 }
656
657 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
658 {
659   return GetReferenceObjects( DataTag_GeometryObject );
660 }
661
662 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
663 {
664   if ( theObject.IsNull() )
665     return;
666
667   RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
668
669   // Indicate model of the need to update splitting
670   Changed( Geom_2d );
671 }
672
673 void HYDROData_CalculationCase::RemoveGeometryObjects()
674 {
675   ClearReferenceObjects( DataTag_GeometryObject );
676
677   // Indicate model of the need to update splitting
678   Changed( Geom_2d );
679 }
680
681 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
682 {
683   if ( theGroup.IsNull() )
684     return false;
685
686   if ( HasReference( theGroup, DataTag_GeometryGroup ) )
687     return false; // Object is already in reference list
688
689   AddReferenceObject( theGroup, DataTag_GeometryGroup );
690   
691   // Indicate model of the need to update splitting
692   Changed( Geom_Groups );
693
694   return true;
695 }
696
697 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
698 {
699   return GetReferenceObjects( DataTag_GeometryGroup );
700 }
701
702 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
703 {
704   if ( theGroup.IsNull() )
705     return;
706
707   RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
708
709   // Indicate model of the need to update splitting
710   Changed( Geom_Groups );
711 }
712
713 void HYDROData_CalculationCase::RemoveGeometryGroups()
714 {
715   ClearReferenceObjects( DataTag_GeometryGroup );
716
717   // Indicate model of the need to update splitting
718   Changed( Geom_Groups );
719 }
720
721 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
722 {
723   Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
724
725   SetReferenceObject( thePolyline, DataTag_Polyline );
726
727   // Indicate model of the need to update zones splitting
728   if( !IsEqual( aPrevPolyline, thePolyline ) )
729     Changed( Geom_2d );
730 }
731
732 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
733 {
734   return Handle(HYDROData_PolylineXY)::DownCast( 
735            GetReferenceObject( DataTag_Polyline ) );
736 }
737
738 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
739 {
740   Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
741
742   ClearReferenceObjects( DataTag_Polyline );
743
744   // Indicate model of the need to update zones splitting
745   Changed( Geom_2d );
746 }
747
748 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
749 {
750   Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
751
752   SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
753
754   // Indicate model of the need to update land covers partition
755   if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
756     Changed( Geom_No );
757 }
758
759 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
760 {
761   return Handle(HYDROData_StricklerTable)::DownCast( 
762            GetReferenceObject( DataTag_StricklerTable ) );
763 }
764
765 void HYDROData_CalculationCase::RemoveStricklerTable()
766 {
767   Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
768
769   ClearReferenceObjects( DataTag_StricklerTable );
770
771   // Indicate model of the need to update land covers partition
772   Changed( Geom_No );
773 }
774
775 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
776 {
777   Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
778     GetReferenceObject( DataTag_LandCoverMap ) );
779   DEBTRACE("GetLandCoverMap " << aMap.IsNull());
780   return aMap;
781 }
782
783 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
784 {
785   SetReferenceObject( theMap, DataTag_LandCoverMap );
786 }
787
788 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
789 {
790   Changed( Geom_No );
791   Changed( Geom_No );
792   Changed( Geom_No );
793   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
794   Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
795   if ( aNewRegion.IsNull() )
796     return aNewRegion;
797
798   aNewRegion->AddZone( theZone );
799
800   return aNewRegion;
801 }
802
803 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
804 {
805   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
806
807   if ( theRegion.IsNull() )
808     return false;
809   
810   HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
811
812   if ( HasReference( theRegion, aDataTag ) )
813     return false; // Object is already in reference list
814
815   // Move the region from other calculation
816   Handle(HYDROData_CalculationCase) aFatherCalc = 
817     Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
818   if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
819   {
820     Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
821     theRegion->CopyTo( aNewRegion, true );
822
823     aFatherCalc->RemoveRegion( theRegion );
824
825     theRegion->SetLabel( aNewRegion->Label() );
826   }
827   else
828   {
829     AddReferenceObject( theRegion, aDataTag );
830   }
831
832   return true;
833 }
834
835 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
836 {
837   return GetReferenceObjects( DataTag_Region );
838 }
839
840 void HYDROData_CalculationCase::UpdateRegionsOrder()
841 {
842   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
843   if ( aDocument.IsNull() )
844     return;
845
846   QString aRegsPref = CALCULATION_REGIONS_PREF;
847   std::map<int, Handle(HYDROData_Region)> IndToRegion; //index in the name of region to region itself 
848   HYDROData_SequenceOfObjects aRegions = GetRegions();
849   HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
850   QString aName;
851   int aVal;
852   for ( ; anIter.More(); anIter.Next() )
853   {
854     Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() );
855     if ( aRegion.IsNull() )
856       continue;
857
858     if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref)
859       IndToRegion[aVal] = aRegion;
860   }
861
862   int nbR = aRegions.Length();
863   std::map<int, Handle(HYDROData_Region)>::iterator it = IndToRegion.begin();
864   for( int i = 1; it != IndToRegion.end(); ++it )
865     if (it->first <= nbR + 1)
866     {
867       QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i));
868       it->second->SetName(aNewName);
869       i++;
870     }
871 }
872
873 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
874 {
875   if ( theRegion.IsNull() )
876     return;
877
878   HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
879   RemoveReferenceObject( theRegion->Label(), aDataTag );
880
881   // Remove region from data model
882   Handle(HYDROData_CalculationCase) aFatherCalc = 
883     Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
884   if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
885     theRegion->Remove();
886 }
887
888 void HYDROData_CalculationCase::RemoveRegions()
889 {
890   myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
891 }
892
893 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
894 {
895   return GetReferenceObjects( DataTag_SplitGroups );
896 }
897
898 void HYDROData_CalculationCase::RemoveSplitGroups()
899 {
900   myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
901 }
902
903 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
904 {
905   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
906   return GetAltitudeForPoint( thePoint, aZone );
907 }
908
909 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY&                    thePoint,
910                                                        const Handle(HYDROData_Region)& theRegion,
911                                                        int theMethod) const
912 {
913   double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
914
915   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
916   if ( !aZone.IsNull() )
917   {
918     DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
919     Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
920     if ( IsEqual( aRefRegion, theRegion ) )
921       aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
922     else
923       {
924         DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
925         aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
926       }
927   }
928   else
929     {
930       DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
931     }
932
933   return aResAltitude;
934 }
935
936 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY&                  thePoint,
937                                                        const Handle(HYDROData_Zone)& theZone,
938                                                        int theMethod) const
939 {
940   DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
941   double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
942   if ( theZone.IsNull() )
943   {
944         DEBTRACE("Zone nulle");
945     return aResAltitude;
946   }
947
948   HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
949   DEBTRACE("aZoneMergeType " << aZoneMergeType);
950   if ( !theZone->IsMergingNeed() )
951   {
952     aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
953     DEBTRACE("---");
954   }
955   else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
956   {
957         DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
958     return aResAltitude;
959   }
960
961   HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
962   if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
963   {
964     Handle(HYDROData_IAltitudeObject) aMergeAltitude = 
965       Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
966     if ( !aMergeAltitude.IsNull() )
967     {
968       if ( aZoneInterpolator != NULL )
969       {
970         DEBTRACE("aZoneInterpolator != NULL");
971         aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
972         aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
973       }
974       else
975       {
976         DEBTRACE("aZoneInterpolator == NULL");
977         aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
978       }
979     }
980   }
981   else
982   {
983         DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
984     HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
985     HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
986     for ( ; anIter.More(); anIter.Next() )
987     {
988       Handle(HYDROData_Object) aZoneObj =
989         Handle(HYDROData_Object)::DownCast( anIter.Value() );
990       if ( aZoneObj.IsNull() )
991         continue;
992
993       Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
994       if ( anObjAltitude.IsNull() )
995         continue;
996
997       double aPointAltitude = 0.0;
998       if ( aZoneInterpolator != NULL )
999       {
1000         DEBTRACE("aZoneInterpolator != NULL");
1001         aZoneInterpolator->SetAltitudeObject( anObjAltitude );
1002         aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1003       }
1004       else
1005       {
1006         DEBTRACE("aZoneInterpolator == NULL");
1007         aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
1008       }
1009
1010       if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
1011         continue;
1012
1013       if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
1014       {
1015         aResAltitude = aPointAltitude;
1016         break;
1017       }
1018       else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
1019       {
1020         if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1021              aResAltitude > aPointAltitude )
1022         {
1023           aResAltitude = aPointAltitude;
1024         }
1025       }
1026       else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
1027       {
1028         if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1029              aResAltitude < aPointAltitude )
1030         {
1031           aResAltitude = aPointAltitude;
1032         }
1033       }
1034     }
1035   }
1036
1037   return aResAltitude;
1038 }
1039
1040 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints( 
1041   const NCollection_Sequence<gp_XY>& thePoints,
1042   const Handle(HYDROData_Region)&    theRegion,
1043   int theMethod) const
1044 {
1045   DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
1046   NCollection_Sequence<double> aResSeq;
1047
1048   for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1049   {
1050     const gp_XY& thePnt = thePoints.Value( i );
1051     
1052     double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
1053     aResSeq.Append( anAltitude );
1054   }
1055
1056   return aResSeq;
1057 }
1058
1059 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints( 
1060   const NCollection_Sequence<gp_XY>& thePoints,
1061   const Handle(HYDROData_Zone)&      theZone,
1062   int theMethod) const
1063 {
1064   NCollection_Sequence<double> aResSeq;
1065
1066   for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1067   {
1068     const gp_XY& thePnt = thePoints.Value( i );
1069     
1070     double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
1071     aResSeq.Append( anAltitude );
1072   }
1073
1074   return aResSeq;
1075 }
1076
1077 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
1078 {
1079   Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
1080   Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1081   if( aMap.IsNull() )
1082     return 0.0;
1083
1084   QString aType;
1085   aMap->FindByPoint( thePoint, aType );
1086   double aCoeff = aTable->Get( aType, 0.0 );
1087   return aCoeff;
1088 }
1089
1090 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
1091   double DefValue, bool UseMax ) const
1092 {
1093   DEBTRACE("GetStricklerCoefficientForPoints");
1094   Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1095   Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1096   std::vector<double> theCoeffs;
1097   DEBTRACE("aLCM.IsNull() " << aLCM.IsNull());
1098   DEBTRACE("aTable.IsNull() "<< aTable.IsNull());
1099   if( aLCM.IsNull() || aTable.IsNull() )
1100     return theCoeffs;
1101
1102   Handle(Message_ProgressIndicator) aSIProgress = HYDROData_Tool::GetSIProgress();
1103   if ( aSIProgress ) {
1104     aSIProgress->Reset();
1105   }
1106
1107   QFuture<void> aFuture = QtConcurrent::run([&]() {
1108     aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
1109   });
1110
1111   while( aFuture.isRunning() ) {
1112     if ( aSIProgress ) {
1113       aSIProgress->Show( Standard_True );
1114       QThread::usleep(500);
1115     }
1116   }
1117
1118   return theCoeffs;
1119 }
1120
1121 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
1122 {
1123   Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1124   Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1125   std::vector<int> types;
1126   if( aLCM.IsNull() || aTable.IsNull() )
1127     return types;
1128
1129   aLCM->ClassifyPoints(thePoints, aTable, types );
1130   return types;
1131 }
1132
1133 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
1134 {
1135   Handle(HYDROData_Region) aResRegion;
1136
1137   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
1138   if ( !aZone.IsNull() )
1139     aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1140
1141   return aResRegion;
1142 }
1143
1144 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
1145 {
1146   Handle(HYDROData_Zone) aResZone;
1147
1148   HYDROData_SequenceOfObjects aRegions = GetRegions();
1149
1150   HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1151   for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1152   {
1153     Handle(HYDROData_Region) aRegion =
1154       Handle(HYDROData_Region)::DownCast( anIter.Value() );
1155     if ( aRegion.IsNull() )
1156       continue;
1157
1158     HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1159     HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1160     for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1161     {
1162       Handle(HYDROData_Zone) aRegZone =
1163         Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1164       if ( aRegZone.IsNull() )
1165         continue;
1166
1167       PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1168       if ( aPointRelation != POINT_OUT )
1169         aResZone = aRegZone; // We found the desired zone
1170     }
1171   }
1172
1173   return aResZone;
1174 }
1175
1176 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1177   const gp_XY&                  thePoint,
1178   const Handle(HYDROData_Zone)& theZone ) const
1179 {
1180   PointClassification aRes = POINT_OUT;
1181   if ( theZone.IsNull() )
1182     return aRes;
1183
1184   TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1185   if ( aZoneFace.IsNull() )
1186     return aRes;
1187 #ifdef DEB_CLASS2D      
1188           TopoDS_Compound aCmp;
1189       BRep_Builder aBB;
1190       aBB.MakeCompound(aCmp);
1191           aBB.Add(aCmp, aZoneFace);
1192           gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1193           BRepBuilderAPI_MakeVertex aMk(aPnt);
1194           aBB.Add(aCmp, aMk.Vertex());
1195           BRepTools::Write(aCmp, "FCL2d.brep");
1196 #endif  
1197   TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1198   if (State == TopAbs_OUT)
1199     aRes =  POINT_OUT;
1200   else if(State == TopAbs_IN)
1201     aRes =  POINT_IN;
1202   else if(State == TopAbs_ON)
1203     aRes =  POINT_ON;
1204   return aRes;
1205 }
1206
1207 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1208                                                                   const QString& thePrefixOrName,
1209                                                                   bool isPrefix )
1210 {
1211   TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1212   int aTag = aNewLab.Tag();
1213
1214   Handle(HYDROData_Region) aNewRegion =
1215     Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1216   AddRegion( aNewRegion );
1217
1218   QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1219   aNewRegion->SetName( aRegionName, true );
1220
1221   return aNewRegion;
1222 }
1223
1224 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1225 {
1226   TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1227
1228   Handle(HYDROData_SplitShapesGroup) aNewGroup =
1229     Handle(HYDROData_SplitShapesGroup)::DownCast( 
1230       HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1231   AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1232
1233   aNewGroup->SetName( theName );
1234
1235   return aNewGroup;
1236 }
1237
1238 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1239 {
1240 #ifdef LIGHT_MODE
1241   return "";
1242 #else
1243   GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1244   SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1245   
1246   QString aGeomObjEntry, anErrorMsg;
1247   QString statMess;
1248   bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg, statMess );
1249   return isOK ? aGeomObjEntry : QString();
1250 #endif
1251 }
1252
1253 #ifndef LIGHT_MODE
1254 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var  theGeomEngine,
1255                                         SALOMEDS::Study_ptr theStudy,
1256                                         QString& theGeomObjEntry,
1257                                         QString& theErrorMsg,
1258                                         QString& statMess) const
1259 {
1260   DEBTRACE("Export");
1261   HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1262
1263   // Get groups definitions
1264   HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1265
1266   TopTools_SequenceOfShape IntSh; //internal edges
1267   HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1268   for ( ; anIter.More(); anIter.Next() )
1269   {
1270     // Get shapes group
1271     Handle(HYDROData_ShapesGroup) aGroup =
1272       Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1273     if ( aGroup.IsNull() )
1274       continue;
1275
1276     HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1277
1278     aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1279     aGroup->GetShapes( aGroupDef.Shapes );
1280
1281     aSeqOfGroupsDefs.Append( aGroupDef );
1282
1283     Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1284     TopTools_SequenceOfShape dummy;
1285     if (!aSSGroup.IsNull())
1286       if (aSSGroup->GetInternal())
1287       {
1288         aSSGroup->GetShapes(dummy);
1289         IntSh.Append(dummy);
1290       }
1291
1292   }
1293   
1294   // Get faces
1295   bool isAllNotSubmersible = true;
1296   HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1297   HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1298   NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1299   for ( ; aRegionIter.More(); aRegionIter.Next() )
1300   {
1301     Handle(HYDROData_Region) aRegion =
1302       Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1303     if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1304       continue;
1305     
1306     if ( isAllNotSubmersible )
1307       isAllNotSubmersible = false;
1308
1309     TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1310     aShToNames.Add( aRegionShape, aRegion->GetName() );
1311   }
1312
1313   bool aRes = false;
1314
1315   if ( aCaseRegions.IsEmpty() ) {
1316     theErrorMsg = QString("the list of regions is empty.");
1317   } else if ( isAllNotSubmersible ) {
1318     theErrorMsg = QString("there are no submersible regions.");
1319   } else {
1320     aRes = Export( theGeomEngine, theStudy, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1321   }
1322
1323   if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1324   {
1325     QString aTelemacFileName = GetName() + ".telemac";
1326     aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1327     if (!aRes)
1328       theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1329   }
1330   return aRes;
1331 }
1332
1333 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var                            theGeomEngine,
1334                                         SALOMEDS::Study_ptr                           theStudy,
1335                                         const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1336                                         const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1337                                         QString& theGeomObjEntry ) const
1338 {
1339   // Sew faces
1340   BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1341   aSewing.SetNonManifoldMode( Standard_False );
1342 #ifdef DEB_CALCULATION
1343   TCollection_AsciiString aNam("Sh_");
1344   int i=1;
1345 #endif
1346   TopTools_DataMapOfShapeListOfShape SH2M;
1347   for ( int i = 1; i <= aShToName.Extent(); i++ )
1348   {
1349     const TopoDS_Shape& aShape = aShToName.FindKey(i);
1350     if ( aShape.IsNull() )
1351       continue;
1352
1353     SH2M.Bind(aShape, TopTools_ListOfShape());
1354     TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1355     if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1356     {
1357       aSewing.Add( aShape );
1358       LM.Append(aShape);
1359     }
1360     else if (aShape.ShapeType() == TopAbs_COMPOUND)
1361     {
1362       TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1363       for (; anExp.More(); anExp.Next() )
1364       {
1365         aSewing.Add( anExp.Current() );
1366         LM.Append(anExp.Current());
1367       }
1368       anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1369       for (; anExp.More(); anExp.Next() )
1370       {
1371         aSewing.Add( anExp.Current() );
1372         LM.Append(anExp.Current());
1373       }
1374     }
1375   } // faces iterator
1376   
1377   aSewing.Perform();
1378   TopoDS_Shape aSewedShape = aSewing.SewedShape();
1379
1380   NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1381
1382   for ( int i = 1; i <= aShToName.Extent(); i++ )
1383   {
1384     const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1385     const QString& Qstr = aShToName.FindFromIndex(i);
1386     const TopTools_ListOfShape& LM = SH2M(CurShape);
1387     for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1388     {
1389       const TopoDS_Shape& csh = it.Value();
1390       if (aSewing.IsModified(csh))
1391         aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1392       else
1393         aFacesToNameModif.Add(csh, Qstr);
1394     }
1395   }
1396
1397  
1398   // If the sewed shape is empty - return false
1399   if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1400     return false;
1401
1402 #ifdef DEB_CALCULATION
1403   BRepTools::Write(aSewedShape ,"Sew.brep");
1404 #endif  // Publish the sewed shape
1405   QString aName = EXPORT_NAME;
1406   GEOM::GEOM_Object_ptr aMainShape = 
1407     HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1408
1409   if ( aMainShape->_is_nil() )  
1410     return false;
1411
1412   if ( theGroupsDefs.IsEmpty() )
1413     return true;
1414
1415   // Create groups
1416   TopTools_IndexedMapOfShape aMapOfSubShapes;
1417   TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1418
1419   NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1420
1421   for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1422   {
1423     const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1424
1425     NCollection_Sequence<int> aGroupIndexes;
1426     for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1427     {
1428       const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1429 #ifdef DEB_CALCULATION
1430       cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1431 #endif
1432       
1433       TopoDS_Shape aModifiedShape = aShape;
1434       if ( aSewing.IsModified( aShape ) )
1435         aModifiedShape = aSewing.Modified( aShape );
1436       else if ( aSewing.IsModifiedSubShape( aShape ) )
1437         aModifiedShape = aSewing.ModifiedSubShape( aShape );
1438
1439 #ifdef DEB_CALCULATION
1440       const TopLoc_Location& aL1 = aShape.Location();
1441       const TopLoc_Location& aL2 = aModifiedShape.Location();
1442       cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1443 #endif
1444
1445       int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1446       if ( anIndex > 0 ) {
1447         aGroupIndexes.Append( anIndex );
1448       } else {
1449 #ifdef DEB_CALCULATION    
1450         TCollection_AsciiString aNam("Lost_");
1451         if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1452         for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1453         {
1454            const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1455            if ( aModifiedShape.IsPartner( aS ) )
1456            {
1457              cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1458              TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1459              BRepTools::Write(aS ,aName.ToCString());
1460             break;
1461            }
1462          }
1463         }
1464 #endif
1465       }
1466     }
1467     if ( !aGroupIndexes.IsEmpty() )
1468       aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1469   }
1470  
1471   if ( !aGroupsData.IsEmpty() )
1472   {
1473     GEOM::GEOM_IGroupOperations_var aGroupOp = 
1474       theGeomEngine->GetIGroupOperations( theStudy->StudyId() );  
1475
1476     NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1477     for ( ; aMapIt.More(); aMapIt.Next() )
1478     {
1479       const TCollection_AsciiString& aGroupName = aMapIt.Key(); 
1480       const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1481
1482       GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1483       if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1484         continue;
1485
1486       GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1487       aGeomIndexes->length( aGroupIndexes.Length() );
1488
1489       for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1490         aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1491
1492       aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1493       if ( aGroupOp->IsDone() )
1494       {
1495         SALOMEDS::SObject_var aGroupSO = 
1496           theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1497       }
1498     }
1499   }
1500
1501   return true;
1502 }
1503 #endif
1504
1505 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1506                                             const bool theIsSetToUpdate )
1507 {
1508   TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1509   HYDROData_PriorityQueue::ClearRules( aRulesLab );
1510
1511   // Indicate model of the need to update splitting
1512   if ( theIsSetToUpdate ) {
1513     Changed( Geom_2d );
1514   }
1515 }
1516
1517 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)&    theObject1,
1518                                          HYDROData_PriorityType             thePriority,
1519                                          const Handle(HYDROData_Entity)&    theObject2,
1520                                          HYDROData_Zone::MergeType          theMergeType,
1521                                          HYDROData_CalculationCase::DataTag theDataTag )
1522 {
1523   TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1524   HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1525
1526   // Indicate model of the need to update splitting
1527   Changed( Geom_2d );
1528 }
1529
1530 QString HYDROData_CalculationCase::DumpRules() const
1531 {
1532   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1533   return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1534 }
1535
1536 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1537 {
1538   TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1539   Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1540   anAttr->SetID(TDataStd_Integer::GetID());
1541   // Indicate model of the need to update splitting
1542   Changed( Geom_2d );
1543 }
1544
1545 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1546 {
1547   Handle(TDataStd_Integer) aModeAttr;
1548   bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1549   if( isOK )
1550     return ( AssignmentMode ) aModeAttr->Get();
1551   else
1552     return MANUAL;
1553 }
1554
1555 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1556                                                    QStringList& theScript ) const
1557 {
1558   TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1559   HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1560 }
1561
1562 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1563 {
1564   return myLastWarning;
1565 }
1566
1567 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1568 {
1569   myLastWarning.Type = theType;
1570   myLastWarning.Data = theData;
1571 }
1572
1573 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1574                                                     const QString& theOldCaseName,
1575                                                     const QString& theName )
1576 {
1577   HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1578   for ( ; anIter.More(); anIter.Next() )
1579   {
1580     Handle(HYDROData_Region) aRegion =
1581       Handle(HYDROData_Region)::DownCast( anIter.Value() );
1582     if ( aRegion.IsNull() )
1583       continue;
1584
1585     HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1586
1587     HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1588     HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1589     for ( ; anIter.More(); anIter.Next() )
1590     {
1591       Handle(HYDROData_Zone) aRegZone =
1592         Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1593       if ( aRegZone.IsNull() )
1594         continue;
1595
1596       HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1597     }
1598   }
1599 }
1600
1601 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1602                                                      const QString& thePyScriptPath,
1603                                                      MapOfTreatedObjects& theTreatedObjects,
1604                                                      const HYDROData_SequenceOfObjects& theRegions ) const
1605 {
1606   HYDROData_SequenceOfObjects::Iterator anIter;
1607   anIter.Init(theRegions);
1608   for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1609     {
1610       Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1611       if (aRegion.IsNull())
1612         continue;
1613       QString defRegName = this->GetName();
1614       QString regSuffix = QString("_Reg_%1").arg(ireg);
1615       defRegName += regSuffix;
1616       theTreatedObjects.insert(aRegion->GetName(), aRegion);
1617       QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1618       theResList << aRegDump;
1619     }
1620   for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1621     {
1622       Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1623       if (aRegion.IsNull())
1624         continue;
1625       QStringList aRegDump;
1626       aRegion->SetNameInDumpPython(aRegDump);
1627       theResList << aRegDump;
1628     }
1629 }
1630
1631 bool HYDROData_CalculationCase::GetRule( int theIndex, 
1632                                          Handle(HYDROData_Entity)&           theObject1,
1633                                          HYDROData_PriorityType&             thePriority,
1634                                          Handle(HYDROData_Entity)&           theObject2,
1635                                          HYDROData_Zone::MergeType&          theMergeType,
1636                                          HYDROData_CalculationCase::DataTag& theDataTag) const
1637 {
1638   TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1639   return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1640     theObject1, thePriority, theObject2, theMergeType );
1641 }
1642
1643 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1644 {
1645   HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1646
1647   if ( HasReference( theInterPolyline, aDataTag ) )
1648     return false; 
1649
1650   AddReferenceObject( theInterPolyline, aDataTag );
1651
1652   Changed( Geom_2d );
1653
1654   return true;
1655 }
1656
1657 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1658 {
1659   return GetReferenceObjects( DataTag_InterPoly ); 
1660 }
1661
1662 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline ) 
1663 {
1664   if ( theInterPolyline.IsNull() )
1665     return;
1666
1667   RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1668
1669   Changed( Geom_2d );
1670 }
1671
1672 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1673 {
1674   HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1675
1676   if ( HasReference( theBCPolygon, aDataTag ) )
1677     return false; 
1678
1679   AddReferenceObject( theBCPolygon, aDataTag );
1680
1681   Changed( Geom_2d );
1682
1683   return true;
1684 }
1685
1686 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1687 {
1688   return GetReferenceObjects( DataTag_BCPolygon ); 
1689 }
1690
1691 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon ) 
1692 {
1693   if ( theBCPolygon.IsNull() )
1694     return;
1695
1696   RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );
1697
1698   Changed( Geom_2d );
1699 }
1700
1701
1702
1703