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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_CalculationCase.h"
20 #include "HYDROData_ArtificialObject.h"
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_Iterator.h"
25 #include "HYDROData_NaturalObject.h"
26 #include "HYDROData_PolylineXY.h"
27 #include "HYDROData_StricklerTable.h"
28 #include "HYDROData_LandCoverMap.h"
29 #include "HYDROData_SplitShapesGroup.h"
30 #include "HYDROData_Region.h"
31 #include "HYDROData_Tool.h"
32 #include "HYDROData_GeomTool.h"
33 #include <HYDROData_Tool.h>
34 #include <HYDROData_BCPolygon.h>
35 #include <HYDROData_BoundaryPolygonTools.h>
36 #include <HYDROData_SplitToZonesTool.h>
39 #pragma warning ( disable: 4251 )
47 #pragma warning ( default: 4251 )
52 #include <QtConcurrent/QtConcurrent>
56 #include <TopoDS_Shell.hxx>
57 #include <TopoDS_Edge.hxx>
59 #include <BRep_Builder.hxx>
60 #include <BRepBuilderAPI_Sewing.hxx>
61 #include <BRepTopAdaptor_FClass2d.hxx>
62 #include <BRepTools_ReShape.hxx>
63 #include <BRepLib_MakeWire.hxx>
65 #include <BRepTools.hxx>
68 #include <TopExp_Explorer.hxx>
70 #include <TopTools_ListOfShape.hxx>
71 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <TDataStd_Integer.hxx>
74 #include <Message_ProgressSentry.hxx>
76 //#define DEB_CALCULATION 1
77 #ifdef DEB_CALCULATION
78 #include <BRepTools.hxx>
79 #include <TopLoc_Location.hxx>
81 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
82 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
83 #define CALCULATION_GROUPS_PREF GetName() + "_"
84 //#define DEB_CLASS2D 1
86 #include <BRepBuilderAPI_MakeVertex.hxx>
89 #define EXPORT_NAME "HYDRO_" + GetName()
92 #include <SALOME_NamingService.hxx>
93 #include <SALOME_LifeCycleCORBA.hxx>
97 #include "HYDRO_trace.hxx"
99 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
101 HYDROData_CalculationCase::HYDROData_CalculationCase()
102 : HYDROData_Entity( Geom_2d_and_groups )
106 HYDROData_CalculationCase::~HYDROData_CalculationCase()
110 void HYDROData_CalculationCase::SetName( const QString& theName )
112 QString anOldCaseName = GetName();
113 if ( anOldCaseName != theName )
115 // Update names of regions and its zones
116 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
118 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
120 HYDROData_SequenceOfObjects::Iterator anIter;
121 anIter.Init( aGroups );
122 for ( ; anIter.More(); anIter.Next() )
124 Handle(HYDROData_SplitShapesGroup) aGroup =
125 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
126 if ( aGroup.IsNull() )
129 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
133 HYDROData_Entity::SetName( theName );
136 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
137 MapOfTreatedObjects& theTreatedObjects ) const
139 QStringList aResList = dumpObjectCreation( theTreatedObjects );
140 aResList.prepend( "# Calculation case" );
142 QString aCalculName = GetObjPyName();
144 AssignmentMode aMode = GetAssignmentMode();
145 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
146 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
148 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
149 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
150 for ( ; anIter.More(); anIter.Next() )
152 Handle(HYDROData_Object) aRefGeomObj =
153 Handle(HYDROData_Object)::DownCast( anIter.Value() );
154 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
156 aResList << QString( "" );
158 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
160 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
161 anIter.Init( aGeomGroups );
162 for ( ; anIter.More(); anIter.Next() )
164 Handle(HYDROData_ShapesGroup) aGeomGroup =
165 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
166 if ( aGeomGroup.IsNull() )
169 Handle(HYDROData_Object) aFatherGeom =
170 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
171 if ( aFatherGeom.IsNull() )
174 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
175 aResList << QString( "%1 = %2.GetGroup( %3 )" )
176 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
178 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
181 HYDROData_SequenceOfObjects aBPolygons = GetBoundaryPolygons();
182 for (int i = 1; i <= aBPolygons.Size(); i++ )
184 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBPolygons(i) );
185 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBCPoly, "AddBoundaryPolygon" );
187 aResList << QString( "" );
189 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
190 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
192 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
193 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
195 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
196 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
198 if( aMode==AUTOMATIC )
199 DumpRulesToPython( aCalculName, aResList );
201 aResList << QString( "" );
202 aResList << "# Start the algorithm of the partition and assignment";
203 aResList << QString( "%1.Update()" ).arg( aCalculName );
207 // Now we restore the
208 // - regions and zones order
209 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
212 // Export calculation case
213 aResList << QString( "" );
214 aResList << "# Export of the calculation case";
215 QString aStudyName = "theStudy";
216 QString anEntryVar = aCalculName + "_entry";
217 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
219 // Get geometry object and print debug information
221 aResList << "# Get geometry shape and print debug information";
222 aResList << "import GEOM";
223 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
224 QString aGeomShapeName = aCalculName + "_geom";
225 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
226 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
227 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
230 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
232 aResList << QString( "" );
236 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
237 const QString& theStudyName,
238 const QString& theGeomShapeName,
239 const QString& theMeshName ) const
242 theResList << "# Meshing";
243 theResList << "import SMESH, SALOMEDS";
244 theResList << "from salome.smesh import smeshBuilder";
245 theResList << "from salome.geom import geomBuilder";
247 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
248 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
249 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
250 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
251 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
252 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
253 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
256 theResList << "# Set names of Mesh objects";
257 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
258 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
259 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
260 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
261 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
264 theResList << "# Greate SMESH groups";
265 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
266 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
267 theResList << QString( "for group in geom_groups:" );
268 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
270 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
271 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
274 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
276 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
278 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
279 if ( !aBoundaryPolyline.IsNull() )
280 aResSeq.Append( aBoundaryPolyline );
282 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
283 aResSeq.Append( aSeqOfGeomObjs );
286 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
287 aResSeq.Append( aSeqOfRegions );
292 static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
293 HYDROData_SequenceOfObjects aBoundaryPolygons,
294 HYDROData_SplitToZonesTool::SplitDataList& outEdgesList)
296 //perform boundary condition polygons on EdgesList
297 TopTools_SequenceOfShape IncTools, SelectionTools;
298 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
299 for (int i=1; i<=aBoundaryPolygons.Size();i++)
301 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
302 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
303 int bType = aBCPoly->GetBoundaryType();
305 IncTools.Append(aPolyTopShape);
307 SelectionTools.Append(aPolyTopShape);
310 while( anIter.hasNext() )
312 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
313 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
315 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
317 if (HYDROData_BoundaryPolygonTools::IncludeTool(IncTools, aSplitData.Shape) && HYDROData_BoundaryPolygonTools::SelectionTool(SelectionTools, aSplitData.Shape))
318 outEdgesList.append(aSplitData);
323 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
324 const HYDROData_SequenceOfObjects& aBoundaryPolygons,
325 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
326 HYDROData_SplitToZonesTool::SplitDataList& outBoundaryPolygonEdgesList)
328 //perform boundary condition polygons on EdgesList
329 TopTools_SequenceOfShape CutTools;
330 NCollection_DataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> BPolyToName;
333 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
334 for (int i=1; i<=aBoundaryPolygons.Size();i++)
336 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
337 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
338 int bType = aBCPoly->GetBoundaryType();
341 CutTools.Append(aPolyTopShape);
342 QString bp_name = aBCPoly->GetName();
343 BPolyToName.Bind(aPolyTopShape, bp_name);
347 while( anIter.hasNext() )
349 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
350 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
352 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
354 ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
357 NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher> BPFaceToCutEdges;
358 HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes, BPFaceToCutEdges);
360 for (int i = 1; i <= CutTools.Length(); i++ )
362 TopoDS_Shape F = CutTools(i);
363 const QString* name = BPolyToName.Seek(F);
364 const TopTools_MapOfShape* EdgesIn = BPFaceToCutEdges.Seek(F); // EdgesIn : edges inside boudnary polygon F
367 TopTools_MapIteratorOfMapOfShape it(*EdgesIn);
368 for (;it.More();it.Next())
370 TopoDS_Edge E = TopoDS::Edge(it.Value());
373 HYDROData_SplitToZonesTool::SplitData SD(HYDROData_SplitToZonesTool::SplitData::Data_Edge, E, *name);
374 outBoundaryPolygonEdgesList.append(SD);
382 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
383 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
384 HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
386 HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList );
387 BRepTools_ReShape reshaper;
390 const HYDROData_SplitToZonesTool::SplitData& aSplitData = it.next();
391 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
394 TopoDS_Shape mS = aSplitData.Shape;
395 for (int i=1; i<=ObjToRes.Extent();i++)
397 TopoDS_Shape K = ObjToRes.FindKey(i);
398 TopoDS_Shape V = ObjToRes.FindFromIndex(i);
399 if (V.ShapeType() != TopAbs_EDGE && V.ShapeType() != TopAbs_WIRE && V.ShapeType() != TopAbs_COMPOUND)
401 if (V.ShapeType() == TopAbs_COMPOUND)
403 TopExp_Explorer exp(V, TopAbs_EDGE);
404 TopTools_ListOfShape lE;
405 for (;exp.More();exp.Next())
406 lE.Append(exp.Current());
407 if (lE.Extent() == 1)
409 else if (lE.Extent() > 1)
421 reshaper.Replace(K, V);
423 TopoDS_Shape nS = reshaper.Apply(mS);
424 HYDROData_SplitToZonesTool::SplitData aNS(aSplitData.Type, nS, aSplitData.ObjectNames);
425 outZoneList.append(aNS);
429 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
430 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
431 HYDROData_SplitToZonesTool::SplitDataList& newEdges)
433 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
434 while( anIter.hasNext() )
436 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
437 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
440 const TopoDS_Shape* aDivShape = ObjToRes.Seek(aSplitData.Shape);
443 TopExp_Explorer exp(*aDivShape, TopAbs_EDGE);
444 for (;exp.More();exp.Next())
446 HYDROData_SplitToZonesTool::SplitData anNewSData(aSplitData.Type, exp.Current(), aSplitData.ObjectNames);
447 newEdges.append(anNewSData);
451 newEdges.append(aSplitData);
456 void HYDROData_CalculationCase::Update()
458 HYDROData_Entity::Update();
461 // At first we remove previously created objects
465 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
466 if ( aDocument.IsNull() )
470 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
472 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
474 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
476 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
477 if ( !aGeomObjects.IsEmpty() ) {
478 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
480 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
481 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
482 if ( !aSplitObjects.isEmpty() ) {
483 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
484 while( anIter.hasNext() ) {
485 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
486 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
487 aZonesList.append( aSplitData );
488 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
489 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
490 anEdgesList.append( aSplitData );
496 //split edges by boundary polygons
497 HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
498 //edge to splitted edge (compound of edges or original edge)
499 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> ObjToRes;
500 //split edge list by BP
501 HYDROData_SplitToZonesTool::SplitDataList outBoundaryPolygonEdgesList; //new groups - for each BP of type 1 (cut) create a group of edges which are inside of this BP
502 SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes, outBoundaryPolygonEdgesList);
503 HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
504 //replace splitted edges in zone list (faces)
505 PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
507 //create new edges list based on splitting info from ObjToRes
508 HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
509 CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
511 newEdgesList1.append(outBoundaryPolygonEdgesList); //append new list of groups
512 //filter out edges list by include&selection tools
513 FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
515 switch( GetAssignmentMode() )
518 CreateRegionsDef( aDocument,aNewZonesList );
521 CreateRegionsAuto( aDocument,aNewZonesList );
525 CreateEdgeGroupsDef( aDocument, newEdgesList2 );
528 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
529 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
531 // Create result regions for case, by default one zone for one region
532 QString aRegsPref = CALCULATION_REGIONS_PREF;
533 QString aZonesPref = CALCULATION_ZONES_PREF;
535 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
536 while( anIter.hasNext() )
538 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
540 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
542 // Add the zone for region
543 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
547 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
548 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
550 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
551 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
552 QMap<QString, QString> aRegionNameToObjNameMap;
553 QString aZonesPref = CALCULATION_ZONES_PREF;
554 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
556 // 1. First we create a default region for each object included into the calculation case
557 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
558 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
560 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
563 QString anObjName = anObj->GetName();
564 QString aRegName = anObjName + "_reg";
565 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
566 aRegionsMap.insert( anObjName, aRegion );
567 aRegionNameToObjNameMap.insert( aRegName, anObjName );
570 // 2. Now for each zone it is necessary to determine the most priority object
571 // and assign to zone to corresponding region
572 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
573 while( anIter.hasNext() )
575 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
576 HYDROData_Zone::MergeType aMergeType;
577 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
578 if( aRegObj.IsNull() )
580 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
581 if( aRegion.IsNull() )
583 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
585 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
587 qDebug( "Error in algorithm: unresolved conflicts" );
590 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
591 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
592 if ( !aMergeObject.IsNull() ) {
593 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
594 aMergeEntity = aMergeObject->GetAltitudeObject();
599 case HYDROData_Zone::Merge_ZMIN:
600 case HYDROData_Zone::Merge_ZMAX:
601 aRegionZone->SetMergeType( aMergeType );
603 case HYDROData_Zone::Merge_Object:
604 aRegionZone->SetMergeType( aMergeType );
605 aRegionZone->RemoveMergeObject();
606 aRegionZone->SetMergeObject( aMergeEntity );
611 QStringList anObjectsWithEmptyRegions;
612 QMap<QString, Handle(HYDROData_Region)>::const_iterator
613 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
614 for( ; anIt!=aLast; anIt++ )
616 Handle(HYDROData_Region) aRegion = anIt.value();
617 if( aRegion->GetZones().IsEmpty() )
619 QString aRegName = aRegion->GetName();
620 QString anObjName = aRegionNameToObjNameMap[aRegName];
621 anObjectsWithEmptyRegions.append( anObjName );
625 if( !anObjectsWithEmptyRegions.empty() )
627 QString aData = anObjectsWithEmptyRegions.join( ", " );
628 SetWarning( WARN_EMPTY_REGIONS, aData );
632 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
633 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
635 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
637 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
638 while( anIter.hasNext() )
640 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
641 // Create new edges group
642 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
645 QString anObjName = aSplitData.ObjectNames.first();
646 if ( anObjName.isEmpty() )
648 #ifdef DEB_CALCULATION
649 QString aStr = aSplitData.ObjectNames.join(" ");
650 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
652 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
653 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
655 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
656 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
660 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
662 if ( aSplitGroup.IsNull() )
665 aSplitGroup->AddShape( aSplitData.Shape );
667 TopTools_SequenceOfShape theShapes;
668 aSplitGroup->GetShapes(theShapes);
670 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
671 aSplitGroup->SetInternal(true);
675 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
677 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
678 return false; // Wrong type of object
680 if ( HasReference( theObject, DataTag_GeometryObject ) )
681 return false; // Object is already in reference list
683 AddReferenceObject( theObject, DataTag_GeometryObject );
685 // Indicate model of the need to update splitting
691 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
693 return GetReferenceObjects( DataTag_GeometryObject );
696 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
698 if ( theObject.IsNull() )
701 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
703 // Indicate model of the need to update splitting
707 void HYDROData_CalculationCase::RemoveGeometryObjects()
709 ClearReferenceObjects( DataTag_GeometryObject );
711 // Indicate model of the need to update splitting
715 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
717 if ( theGroup.IsNull() )
720 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
721 return false; // Object is already in reference list
723 AddReferenceObject( theGroup, DataTag_GeometryGroup );
725 // Indicate model of the need to update splitting
726 Changed( Geom_Groups );
731 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
733 return GetReferenceObjects( DataTag_GeometryGroup );
736 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
738 if ( theGroup.IsNull() )
741 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
743 // Indicate model of the need to update splitting
744 Changed( Geom_Groups );
747 void HYDROData_CalculationCase::RemoveGeometryGroups()
749 ClearReferenceObjects( DataTag_GeometryGroup );
751 // Indicate model of the need to update splitting
752 Changed( Geom_Groups );
755 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
757 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
759 SetReferenceObject( thePolyline, DataTag_Polyline );
761 // Indicate model of the need to update zones splitting
762 if( !IsEqual( aPrevPolyline, thePolyline ) )
766 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
768 return Handle(HYDROData_PolylineXY)::DownCast(
769 GetReferenceObject( DataTag_Polyline ) );
772 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
774 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
776 ClearReferenceObjects( DataTag_Polyline );
778 // Indicate model of the need to update zones splitting
782 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
784 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
786 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
788 // Indicate model of the need to update land covers partition
789 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
793 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
795 return Handle(HYDROData_StricklerTable)::DownCast(
796 GetReferenceObject( DataTag_StricklerTable ) );
799 void HYDROData_CalculationCase::RemoveStricklerTable()
801 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
803 ClearReferenceObjects( DataTag_StricklerTable );
805 // Indicate model of the need to update land covers partition
809 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
811 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
812 GetReferenceObject( DataTag_LandCoverMap ) );
813 DEBTRACE("GetLandCoverMap " << aMap.IsNull());
817 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
819 SetReferenceObject( theMap, DataTag_LandCoverMap );
822 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
827 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
828 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
829 if ( aNewRegion.IsNull() )
832 aNewRegion->AddZone( theZone );
837 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
839 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
841 if ( theRegion.IsNull() )
844 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
846 if ( HasReference( theRegion, aDataTag ) )
847 return false; // Object is already in reference list
849 // Move the region from other calculation
850 Handle(HYDROData_CalculationCase) aFatherCalc =
851 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
852 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
854 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
855 theRegion->CopyTo( aNewRegion, true );
857 aFatherCalc->RemoveRegion( theRegion );
859 theRegion->SetLabel( aNewRegion->Label() );
863 AddReferenceObject( theRegion, aDataTag );
869 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
871 return GetReferenceObjects( DataTag_Region );
874 void HYDROData_CalculationCase::UpdateRegionsOrder()
876 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
877 if ( aDocument.IsNull() )
880 QString aRegsPref = CALCULATION_REGIONS_PREF;
881 std::map<int, Handle(HYDROData_Region)> IndToRegion; //index in the name of region to region itself
882 HYDROData_SequenceOfObjects aRegions = GetRegions();
883 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
886 for ( ; anIter.More(); anIter.Next() )
888 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() );
889 if ( aRegion.IsNull() )
892 if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref)
893 IndToRegion[aVal] = aRegion;
896 int nbR = aRegions.Length();
897 std::map<int, Handle(HYDROData_Region)>::iterator it = IndToRegion.begin();
898 for( int i = 1; it != IndToRegion.end(); ++it )
899 if (it->first <= nbR + 1)
901 QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i));
902 it->second->SetName(aNewName);
907 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
909 if ( theRegion.IsNull() )
912 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
913 RemoveReferenceObject( theRegion->Label(), aDataTag );
915 // Remove region from data model
916 Handle(HYDROData_CalculationCase) aFatherCalc =
917 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
918 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
922 void HYDROData_CalculationCase::RemoveRegions()
924 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
927 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
929 return GetReferenceObjects( DataTag_SplitGroups );
932 void HYDROData_CalculationCase::RemoveSplitGroups()
934 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
937 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
939 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
940 return GetAltitudeForPoint( thePoint, aZone );
943 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
944 const Handle(HYDROData_Region)& theRegion,
947 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
949 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
950 if ( !aZone.IsNull() )
952 DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
953 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
954 if ( IsEqual( aRefRegion, theRegion ) )
955 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
958 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
959 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
964 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
970 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
971 const Handle(HYDROData_Zone)& theZone,
974 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
975 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
976 if ( theZone.IsNull() )
978 DEBTRACE("Zone nulle");
982 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
983 DEBTRACE("aZoneMergeType " << aZoneMergeType);
984 if ( !theZone->IsMergingNeed() )
986 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
989 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
991 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
995 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
996 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
998 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
999 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
1000 if ( !aMergeAltitude.IsNull() )
1002 if ( aZoneInterpolator != NULL )
1004 DEBTRACE("aZoneInterpolator != NULL");
1005 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
1006 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1010 DEBTRACE("aZoneInterpolator == NULL");
1011 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint, theMethod );
1017 DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
1018 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
1019 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
1020 for ( ; anIter.More(); anIter.Next() )
1022 Handle(HYDROData_Object) aZoneObj =
1023 Handle(HYDROData_Object)::DownCast( anIter.Value() );
1024 if ( aZoneObj.IsNull() )
1027 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
1028 if ( anObjAltitude.IsNull() )
1031 double aPointAltitude = 0.0;
1032 if ( aZoneInterpolator != NULL )
1034 DEBTRACE("aZoneInterpolator != NULL");
1035 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
1036 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1040 DEBTRACE("aZoneInterpolator == NULL");
1041 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
1044 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
1047 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
1049 aResAltitude = aPointAltitude;
1052 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
1054 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1055 aResAltitude > aPointAltitude )
1057 aResAltitude = aPointAltitude;
1060 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
1062 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1063 aResAltitude < aPointAltitude )
1065 aResAltitude = aPointAltitude;
1071 return aResAltitude;
1074 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1075 const NCollection_Sequence<gp_XY>& thePoints,
1076 const Handle(HYDROData_Region)& theRegion,
1077 int theMethod) const
1079 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
1080 NCollection_Sequence<double> aResSeq;
1082 Handle(Message_ProgressIndicator) aZIProgress = HYDROData_Tool::GetZIProgress();
1083 //DEBTRACE("aZIProgress=" << aZIProgress);
1084 if ( aZIProgress ) {
1085 aZIProgress->Reset();
1088 QFuture<void> aFuture = QtConcurrent::run([&]() {
1089 int aNbPoints = thePoints.Length();
1091 Message_ProgressSentry aPSentry(HYDROData_Tool::GetZIProgress(), "GetAltitudesForPoints", 0, aNbPoints, 1);
1092 for ( int i = 1, n = aNbPoints; i <= n && aPSentry.More(); ++i, aPSentry.Next() )
1094 const gp_XY& thePnt = thePoints.Value( i );
1096 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
1097 aResSeq.Append( anAltitude );
1101 while( aFuture.isRunning() ) {
1102 if ( aZIProgress ) {
1103 aZIProgress->Show( Standard_True );
1104 QThread::usleep(500);
1107 //DEBTRACE("aZIProgress=" << aZIProgress);
1109 aZIProgress->Show( Standard_True );
1114 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1115 const NCollection_Sequence<gp_XY>& thePoints,
1116 const Handle(HYDROData_Zone)& theZone,
1117 int theMethod) const
1119 NCollection_Sequence<double> aResSeq;
1121 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1123 const gp_XY& thePnt = thePoints.Value( i );
1125 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
1126 aResSeq.Append( anAltitude );
1132 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
1134 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
1135 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1140 aMap->FindByPoint( thePoint, aType );
1141 double aCoeff = aTable->Get( aType, 0.0 );
1145 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
1146 double DefValue, bool UseMax ) const
1148 DEBTRACE("GetStricklerCoefficientForPoints");
1149 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1150 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1151 std::vector<double> theCoeffs;
1152 DEBTRACE("aLCM.IsNull() " << aLCM.IsNull());
1153 DEBTRACE("aTable.IsNull() "<< aTable.IsNull());
1154 if( aLCM.IsNull() || aTable.IsNull() )
1157 Handle(Message_ProgressIndicator) aSIProgress = HYDROData_Tool::GetSIProgress();
1158 if ( aSIProgress ) {
1159 aSIProgress->Reset();
1162 QFuture<void> aFuture = QtConcurrent::run([&]() {
1163 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
1166 while( aFuture.isRunning() ) {
1167 if ( aSIProgress ) {
1168 aSIProgress->Show( Standard_True );
1169 QThread::usleep(500);
1176 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
1178 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1179 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1180 std::vector<int> types;
1181 if( aLCM.IsNull() || aTable.IsNull() )
1184 aLCM->ClassifyPoints(thePoints, aTable, types );
1188 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
1190 Handle(HYDROData_Region) aResRegion;
1192 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
1193 if ( !aZone.IsNull() )
1194 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1199 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
1201 Handle(HYDROData_Zone) aResZone;
1203 HYDROData_SequenceOfObjects aRegions = GetRegions();
1205 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1206 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1208 Handle(HYDROData_Region) aRegion =
1209 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1210 if ( aRegion.IsNull() )
1213 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1214 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1215 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1217 Handle(HYDROData_Zone) aRegZone =
1218 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1219 if ( aRegZone.IsNull() )
1222 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1223 if ( aPointRelation != POINT_OUT )
1224 aResZone = aRegZone; // We found the desired zone
1231 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1232 const gp_XY& thePoint,
1233 const Handle(HYDROData_Zone)& theZone ) const
1235 PointClassification aRes = POINT_OUT;
1236 if ( theZone.IsNull() )
1239 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1240 if ( aZoneFace.IsNull() )
1243 TopoDS_Compound aCmp;
1245 aBB.MakeCompound(aCmp);
1246 aBB.Add(aCmp, aZoneFace);
1247 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1248 BRepBuilderAPI_MakeVertex aMk(aPnt);
1249 aBB.Add(aCmp, aMk.Vertex());
1250 BRepTools::Write(aCmp, "FCL2d.brep");
1252 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1253 if (State == TopAbs_OUT)
1255 else if(State == TopAbs_IN)
1257 else if(State == TopAbs_ON)
1262 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1263 const QString& thePrefixOrName,
1266 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1267 int aTag = aNewLab.Tag();
1269 Handle(HYDROData_Region) aNewRegion =
1270 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1271 AddRegion( aNewRegion );
1273 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1274 aNewRegion->SetName( aRegionName, true );
1279 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1281 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1283 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1284 Handle(HYDROData_SplitShapesGroup)::DownCast(
1285 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1286 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1288 aNewGroup->SetName( theName );
1293 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1298 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1299 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1301 QString aGeomObjEntry, anErrorMsg;
1303 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg, statMess );
1304 return isOK ? aGeomObjEntry : QString();
1309 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1310 SALOMEDS::Study_ptr theStudy,
1311 QString& theGeomObjEntry,
1312 QString& theErrorMsg,
1313 QString& statMess) const
1316 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1318 // Get groups definitions
1319 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1321 TopTools_SequenceOfShape IntSh; //internal edges
1322 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1323 for ( ; anIter.More(); anIter.Next() )
1326 Handle(HYDROData_ShapesGroup) aGroup =
1327 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1328 if ( aGroup.IsNull() )
1331 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1333 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1334 aGroup->GetShapes( aGroupDef.Shapes );
1336 aSeqOfGroupsDefs.Append( aGroupDef );
1338 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1339 TopTools_SequenceOfShape dummy;
1340 if (!aSSGroup.IsNull())
1341 if (aSSGroup->GetInternal())
1343 aSSGroup->GetShapes(dummy);
1344 IntSh.Append(dummy);
1350 bool isAllNotSubmersible = true;
1351 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1352 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1353 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1354 for ( ; aRegionIter.More(); aRegionIter.Next() )
1356 Handle(HYDROData_Region) aRegion =
1357 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1358 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1361 if ( isAllNotSubmersible )
1362 isAllNotSubmersible = false;
1364 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1365 aShToNames.Add( aRegionShape, aRegion->GetName() );
1370 if ( aCaseRegions.IsEmpty() ) {
1371 theErrorMsg = QString("the list of regions is empty.");
1372 } else if ( isAllNotSubmersible ) {
1373 theErrorMsg = QString("there are no submersible regions.");
1375 aRes = Export( theGeomEngine, theStudy, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1378 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1380 QString aTelemacFileName = GetName() + ".telemac";
1381 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1383 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1388 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1389 SALOMEDS::Study_ptr theStudy,
1390 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1391 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1392 QString& theGeomObjEntry ) const
1395 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1396 aSewing.SetNonManifoldMode( Standard_False );
1397 #ifdef DEB_CALCULATION
1398 TCollection_AsciiString aNam("Sh_");
1401 TopTools_DataMapOfShapeListOfShape SH2M;
1402 for ( int i = 1; i <= aShToName.Extent(); i++ )
1404 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1405 if ( aShape.IsNull() )
1408 SH2M.Bind(aShape, TopTools_ListOfShape());
1409 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1410 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1412 aSewing.Add( aShape );
1415 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1417 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1418 for (; anExp.More(); anExp.Next() )
1420 aSewing.Add( anExp.Current() );
1421 LM.Append(anExp.Current());
1423 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1424 for (; anExp.More(); anExp.Next() )
1426 aSewing.Add( anExp.Current() );
1427 LM.Append(anExp.Current());
1433 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1435 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1437 for ( int i = 1; i <= aShToName.Extent(); i++ )
1439 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1440 const QString& Qstr = aShToName.FindFromIndex(i);
1441 const TopTools_ListOfShape& LM = SH2M(CurShape);
1442 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1444 const TopoDS_Shape& csh = it.Value();
1445 if (aSewing.IsModified(csh))
1446 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1448 aFacesToNameModif.Add(csh, Qstr);
1453 // If the sewed shape is empty - return false
1454 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1457 #ifdef DEB_CALCULATION
1458 BRepTools::Write(aSewedShape ,"Sew.brep");
1459 #endif // Publish the sewed shape
1460 QString aName = EXPORT_NAME;
1461 GEOM::GEOM_Object_ptr aMainShape =
1462 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1464 if ( aMainShape->_is_nil() )
1467 if ( theGroupsDefs.IsEmpty() )
1471 TopTools_IndexedMapOfShape aMapOfSubShapes;
1472 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1474 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1476 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1478 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1480 NCollection_Sequence<int> aGroupIndexes;
1481 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1483 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1484 #ifdef DEB_CALCULATION
1485 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1488 TopoDS_Shape aModifiedShape = aShape;
1489 if ( aSewing.IsModified( aShape ) )
1490 aModifiedShape = aSewing.Modified( aShape );
1491 else if ( aSewing.IsModifiedSubShape( aShape ) )
1492 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1494 #ifdef DEB_CALCULATION
1495 const TopLoc_Location& aL1 = aShape.Location();
1496 const TopLoc_Location& aL2 = aModifiedShape.Location();
1497 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1500 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1501 if ( anIndex > 0 ) {
1502 aGroupIndexes.Append( anIndex );
1504 #ifdef DEB_CALCULATION
1505 TCollection_AsciiString aNam("Lost_");
1506 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1507 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1509 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1510 if ( aModifiedShape.IsPartner( aS ) )
1512 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1513 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1514 BRepTools::Write(aS ,aName.ToCString());
1522 if ( !aGroupIndexes.IsEmpty() )
1523 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1526 if ( !aGroupsData.IsEmpty() )
1528 GEOM::GEOM_IGroupOperations_var aGroupOp =
1529 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1531 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1532 for ( ; aMapIt.More(); aMapIt.Next() )
1534 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1535 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1537 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1538 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1541 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1542 aGeomIndexes->length( aGroupIndexes.Length() );
1544 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1545 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1547 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1548 if ( aGroupOp->IsDone() )
1550 SALOMEDS::SObject_var aGroupSO =
1551 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1560 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1561 const bool theIsSetToUpdate )
1563 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1564 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1566 // Indicate model of the need to update splitting
1567 if ( theIsSetToUpdate ) {
1572 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1573 HYDROData_PriorityType thePriority,
1574 const Handle(HYDROData_Entity)& theObject2,
1575 HYDROData_Zone::MergeType theMergeType,
1576 HYDROData_CalculationCase::DataTag theDataTag )
1578 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1579 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1581 // Indicate model of the need to update splitting
1585 QString HYDROData_CalculationCase::DumpRules() const
1587 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1588 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1591 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1593 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1594 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1595 anAttr->SetID(TDataStd_Integer::GetID());
1596 // Indicate model of the need to update splitting
1600 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1602 Handle(TDataStd_Integer) aModeAttr;
1603 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1605 return ( AssignmentMode ) aModeAttr->Get();
1610 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1611 QStringList& theScript ) const
1613 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1614 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1617 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1619 return myLastWarning;
1622 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1624 myLastWarning.Type = theType;
1625 myLastWarning.Data = theData;
1628 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1629 const QString& theOldCaseName,
1630 const QString& theName )
1632 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1633 for ( ; anIter.More(); anIter.Next() )
1635 Handle(HYDROData_Region) aRegion =
1636 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1637 if ( aRegion.IsNull() )
1640 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1642 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1643 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1644 for ( ; anIter.More(); anIter.Next() )
1646 Handle(HYDROData_Zone) aRegZone =
1647 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1648 if ( aRegZone.IsNull() )
1651 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1656 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1657 const QString& thePyScriptPath,
1658 MapOfTreatedObjects& theTreatedObjects,
1659 const HYDROData_SequenceOfObjects& theRegions ) const
1661 HYDROData_SequenceOfObjects::Iterator anIter;
1662 anIter.Init(theRegions);
1663 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1665 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1666 if (aRegion.IsNull())
1668 QString defRegName = this->GetName();
1669 QString regSuffix = QString("_Reg_%1").arg(ireg);
1670 defRegName += regSuffix;
1671 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1672 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1673 theResList << aRegDump;
1675 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1677 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1678 if (aRegion.IsNull())
1680 QStringList aRegDump;
1681 aRegion->SetNameInDumpPython(aRegDump);
1682 theResList << aRegDump;
1686 bool HYDROData_CalculationCase::GetRule( int theIndex,
1687 Handle(HYDROData_Entity)& theObject1,
1688 HYDROData_PriorityType& thePriority,
1689 Handle(HYDROData_Entity)& theObject2,
1690 HYDROData_Zone::MergeType& theMergeType,
1691 HYDROData_CalculationCase::DataTag& theDataTag) const
1693 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1694 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1695 theObject1, thePriority, theObject2, theMergeType );
1698 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1700 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1702 if ( HasReference( theInterPolyline, aDataTag ) )
1705 AddReferenceObject( theInterPolyline, aDataTag );
1712 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1714 return GetReferenceObjects( DataTag_InterPoly );
1717 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1719 if ( theInterPolyline.IsNull() )
1722 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1727 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1729 HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1731 if ( HasReference( theBCPolygon, aDataTag ) )
1734 AddReferenceObject( theBCPolygon, aDataTag );
1741 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1743 return GetReferenceObjects( DataTag_BCPolygon );
1746 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1748 if ( theBCPolygon.IsNull() )
1751 RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );