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