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 anEntryVar = aCalculName + "_entry";
216 aResList << QString( "%1 = %2.Export()" ).arg( anEntryVar ).arg( aCalculName );
218 // Get geometry object and print debug information
220 aResList << "# Get geometry shape and print debug information";
221 aResList << "import GEOM";
222 aResList << QString( "print (\"Entry:\", %1)" ).arg( anEntryVar );
223 QString aGeomShapeName = aCalculName + "_geom";
224 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
225 aResList << QString( "print (\"Geom shape:\", HYDRO_%1)" ).arg( GetName() );
226 aResList << QString( "print (\"Geom shape name:\", HYDRO_%1.GetName())" ).arg( GetName() );
229 //DumpSampleMeshing( aResList, aGeomShapeName, aCalculName+"_mesh" );
231 aResList << QString( "" );
235 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
236 const QString& theGeomShapeName,
237 const QString& theMeshName ) const
240 theResList << "# Meshing";
241 theResList << "import SMESH, SALOMEDS";
242 theResList << "from salome.smesh import smeshBuilder";
243 theResList << "from salome.geom import geomBuilder";
245 theResList << QString( "smesh = smeshBuilder.New()" );
246 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
247 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
248 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
249 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
250 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
251 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
254 theResList << "# Set names of Mesh objects";
255 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
256 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
257 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
258 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
259 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
262 theResList << "# Greate SMESH groups";
263 theResList << QString( "geompy = geomBuilder.New()" );
264 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
265 theResList << QString( "for group in geom_groups:" );
266 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
268 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
269 theResList << QString( " print (\"SMESH group '%s': %s)\" % (smesh_group.GetName(), smesh_group)" );
272 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
274 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
276 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
277 if ( !aBoundaryPolyline.IsNull() )
278 aResSeq.Append( aBoundaryPolyline );
280 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
281 aResSeq.Append( aSeqOfGeomObjs );
284 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
285 aResSeq.Append( aSeqOfRegions );
290 static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
291 HYDROData_SequenceOfObjects aBoundaryPolygons,
292 HYDROData_SplitToZonesTool::SplitDataList& outEdgesList)
294 //perform boundary condition polygons on EdgesList
295 TopTools_SequenceOfShape IncTools, SelectionTools;
296 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
297 for (int i=1; i<=aBoundaryPolygons.Size();i++)
299 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
300 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
301 int bType = aBCPoly->GetBoundaryType();
303 IncTools.Append(aPolyTopShape);
305 SelectionTools.Append(aPolyTopShape);
308 while( anIter.hasNext() )
310 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
311 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
313 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
315 if (HYDROData_BoundaryPolygonTools::IncludeTool(IncTools, aSplitData.Shape) && HYDROData_BoundaryPolygonTools::SelectionTool(SelectionTools, aSplitData.Shape))
316 outEdgesList.append(aSplitData);
321 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
322 const HYDROData_SequenceOfObjects& aBoundaryPolygons,
323 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
324 HYDROData_SplitToZonesTool::SplitDataList& outBoundaryPolygonEdgesList)
326 //perform boundary condition polygons on EdgesList
327 TopTools_SequenceOfShape CutTools;
328 NCollection_DataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> BPolyToName;
331 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
332 for (int i=1; i<=aBoundaryPolygons.Size();i++)
334 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
335 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
336 int bType = aBCPoly->GetBoundaryType();
339 CutTools.Append(aPolyTopShape);
340 QString bp_name = aBCPoly->GetName();
341 BPolyToName.Bind(aPolyTopShape, bp_name);
345 while( anIter.hasNext() )
347 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
348 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
350 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
352 ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
355 NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher> BPFaceToCutEdges;
356 HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes, BPFaceToCutEdges);
358 for (int i = 1; i <= CutTools.Length(); i++ )
360 TopoDS_Shape F = CutTools(i);
361 const QString* name = BPolyToName.Seek(F);
362 const TopTools_MapOfShape* EdgesIn = BPFaceToCutEdges.Seek(F); // EdgesIn : edges inside boudnary polygon F
365 TopTools_MapIteratorOfMapOfShape it(*EdgesIn);
366 for (;it.More();it.Next())
368 TopoDS_Edge E = TopoDS::Edge(it.Value());
371 HYDROData_SplitToZonesTool::SplitData SD(HYDROData_SplitToZonesTool::SplitData::Data_Edge, E, *name);
372 outBoundaryPolygonEdgesList.append(SD);
380 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
381 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
382 HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
384 HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList );
385 BRepTools_ReShape reshaper;
388 const HYDROData_SplitToZonesTool::SplitData& aSplitData = it.next();
389 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
392 TopoDS_Shape mS = aSplitData.Shape;
393 for (int i=1; i<=ObjToRes.Extent();i++)
395 TopoDS_Shape K = ObjToRes.FindKey(i);
396 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();
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();
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();
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();
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 void HYDROData_CalculationCase::SetContainerName( const QString& theContainerName )
1296 HYDROData_GeomTool::SetContainerName( theContainerName );
1300 QString HYDROData_CalculationCase::Export() const
1305 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1307 QString aGeomObjEntry, anErrorMsg;
1309 bool isOK = Export( aGEOMEngine, aGeomObjEntry, anErrorMsg, statMess );
1310 return isOK ? aGeomObjEntry : QString();
1315 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1316 QString& theGeomObjEntry,
1317 QString& theErrorMsg,
1318 QString& statMess) const
1321 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1323 // Get groups definitions
1324 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1326 TopTools_SequenceOfShape IntSh; //internal edges
1327 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1328 for ( ; anIter.More(); anIter.Next() )
1331 Handle(HYDROData_ShapesGroup) aGroup =
1332 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1333 if ( aGroup.IsNull() )
1336 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1338 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1339 aGroup->GetShapes( aGroupDef.Shapes );
1341 aSeqOfGroupsDefs.Append( aGroupDef );
1343 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1344 TopTools_SequenceOfShape dummy;
1345 if (!aSSGroup.IsNull())
1346 if (aSSGroup->GetInternal())
1348 aSSGroup->GetShapes(dummy);
1349 IntSh.Append(dummy);
1355 bool isAllNotSubmersible = true;
1356 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1357 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1358 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1359 for ( ; aRegionIter.More(); aRegionIter.Next() )
1361 Handle(HYDROData_Region) aRegion =
1362 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1363 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1366 if ( isAllNotSubmersible )
1367 isAllNotSubmersible = false;
1369 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1370 aShToNames.Add( aRegionShape, aRegion->GetName() );
1375 if ( aCaseRegions.IsEmpty() ) {
1376 theErrorMsg = QString("the list of regions is empty.");
1377 } else if ( isAllNotSubmersible ) {
1378 theErrorMsg = QString("there are no submersible regions.");
1380 aRes = Export( theGeomEngine, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1383 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1385 QString aTelemacFileName = GetName() + ".telemac";
1386 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1388 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1393 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1394 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1395 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1396 QString& theGeomObjEntry ) const
1399 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1400 aSewing.SetNonManifoldMode( Standard_False );
1401 #ifdef DEB_CALCULATION
1402 TCollection_AsciiString aNam("Sh_");
1405 TopTools_DataMapOfShapeListOfShape SH2M;
1406 for ( int i = 1; i <= aShToName.Extent(); i++ )
1408 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1409 if ( aShape.IsNull() )
1412 SH2M.Bind(aShape, TopTools_ListOfShape());
1413 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1414 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1416 aSewing.Add( aShape );
1419 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1421 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1422 for (; anExp.More(); anExp.Next() )
1424 aSewing.Add( anExp.Current() );
1425 LM.Append(anExp.Current());
1427 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1428 for (; anExp.More(); anExp.Next() )
1430 aSewing.Add( anExp.Current() );
1431 LM.Append(anExp.Current());
1437 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1439 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1441 for ( int i = 1; i <= aShToName.Extent(); i++ )
1443 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1444 const QString& Qstr = aShToName.FindFromIndex(i);
1445 const TopTools_ListOfShape& LM = SH2M(CurShape);
1446 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1448 const TopoDS_Shape& csh = it.Value();
1449 if (aSewing.IsModified(csh))
1450 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1452 aFacesToNameModif.Add(csh, Qstr);
1457 // If the sewed shape is empty - return false
1458 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1461 #ifdef DEB_CALCULATION
1462 BRepTools::Write(aSewedShape ,"Sew.brep");
1463 #endif // Publish the sewed shape
1464 QString aName = EXPORT_NAME;
1465 GEOM::GEOM_Object_ptr aMainShape =
1466 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1468 if ( aMainShape->_is_nil() )
1471 if ( theGroupsDefs.IsEmpty() )
1475 TopTools_IndexedMapOfShape aMapOfSubShapes;
1476 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1478 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1480 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1482 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1484 NCollection_Sequence<int> aGroupIndexes;
1485 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1487 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1488 #ifdef DEB_CALCULATION
1489 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1492 TopoDS_Shape aModifiedShape = aShape;
1493 if ( aSewing.IsModified( aShape ) )
1494 aModifiedShape = aSewing.Modified( aShape );
1495 else if ( aSewing.IsModifiedSubShape( aShape ) )
1496 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1498 #ifdef DEB_CALCULATION
1499 const TopLoc_Location& aL1 = aShape.Location();
1500 const TopLoc_Location& aL2 = aModifiedShape.Location();
1501 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1504 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1505 if ( anIndex > 0 ) {
1506 aGroupIndexes.Append( anIndex );
1508 #ifdef DEB_CALCULATION
1509 TCollection_AsciiString aNam("Lost_");
1510 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1511 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1513 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1514 if ( aModifiedShape.IsPartner( aS ) )
1516 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1517 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1518 BRepTools::Write(aS ,aName.ToCString());
1526 if ( !aGroupIndexes.IsEmpty() )
1527 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1530 if ( !aGroupsData.IsEmpty() )
1532 GEOM::GEOM_IGroupOperations_var aGroupOp =
1533 theGeomEngine->GetIGroupOperations();
1535 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1536 for ( ; aMapIt.More(); aMapIt.Next() )
1538 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1539 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1541 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1542 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1545 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1546 aGeomIndexes->length( aGroupIndexes.Length() );
1548 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1549 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1551 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1552 if ( aGroupOp->IsDone() )
1554 SALOMEDS::SObject_var aGroupSO =
1555 theGeomEngine->AddInStudy( aGeomGroup, aGroupName.ToCString(), aMainShape );
1564 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1565 const bool theIsSetToUpdate )
1567 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1568 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1570 // Indicate model of the need to update splitting
1571 if ( theIsSetToUpdate ) {
1576 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1577 HYDROData_PriorityType thePriority,
1578 const Handle(HYDROData_Entity)& theObject2,
1579 HYDROData_Zone::MergeType theMergeType,
1580 HYDROData_CalculationCase::DataTag theDataTag )
1582 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1583 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1585 // Indicate model of the need to update splitting
1589 QString HYDROData_CalculationCase::DumpRules() const
1591 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1592 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1595 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1597 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1598 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1599 anAttr->SetID(TDataStd_Integer::GetID());
1600 // Indicate model of the need to update splitting
1604 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1606 Handle(TDataStd_Integer) aModeAttr;
1607 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1609 return ( AssignmentMode ) aModeAttr->Get();
1614 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1615 QStringList& theScript ) const
1617 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1618 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1621 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1623 return myLastWarning;
1626 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1628 myLastWarning.Type = theType;
1629 myLastWarning.Data = theData;
1632 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1633 const QString& theOldCaseName,
1634 const QString& theName )
1636 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1637 for ( ; anIter.More(); anIter.Next() )
1639 Handle(HYDROData_Region) aRegion =
1640 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1641 if ( aRegion.IsNull() )
1644 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1646 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1647 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1648 for ( ; anIter.More(); anIter.Next() )
1650 Handle(HYDROData_Zone) aRegZone =
1651 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1652 if ( aRegZone.IsNull() )
1655 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1660 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1661 const QString& thePyScriptPath,
1662 MapOfTreatedObjects& theTreatedObjects,
1663 const HYDROData_SequenceOfObjects& theRegions ) const
1665 HYDROData_SequenceOfObjects::Iterator anIter;
1666 anIter.Init(theRegions);
1667 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1669 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1670 if (aRegion.IsNull())
1672 QString defRegName = this->GetName();
1673 QString regSuffix = QString("_Reg_%1").arg(ireg);
1674 defRegName += regSuffix;
1675 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1676 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1677 theResList << aRegDump;
1679 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1681 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1682 if (aRegion.IsNull())
1684 QStringList aRegDump;
1685 aRegion->SetNameInDumpPython(aRegDump);
1686 theResList << aRegDump;
1690 bool HYDROData_CalculationCase::GetRule( int theIndex,
1691 Handle(HYDROData_Entity)& theObject1,
1692 HYDROData_PriorityType& thePriority,
1693 Handle(HYDROData_Entity)& theObject2,
1694 HYDROData_Zone::MergeType& theMergeType,
1695 HYDROData_CalculationCase::DataTag& theDataTag) const
1697 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1698 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1699 theObject1, thePriority, theObject2, theMergeType );
1702 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1704 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1706 if ( HasReference( theInterPolyline, aDataTag ) )
1709 AddReferenceObject( theInterPolyline, aDataTag );
1716 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1718 return GetReferenceObjects( DataTag_InterPoly );
1721 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1723 if ( theInterPolyline.IsNull() )
1726 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1731 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1733 HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1735 if ( HasReference( theBCPolygon, aDataTag ) )
1738 AddReferenceObject( theBCPolygon, aDataTag );
1745 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1747 return GetReferenceObjects( DataTag_BCPolygon );
1750 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1752 if ( theBCPolygon.IsNull() )
1755 RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );