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