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