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);
401 if (V.ShapeType() != TopAbs_EDGE && V.ShapeType() != TopAbs_WIRE && V.ShapeType() != TopAbs_COMPOUND)
403 if (V.ShapeType() == TopAbs_COMPOUND)
405 TopExp_Explorer exp(V, TopAbs_EDGE);
406 TopTools_ListOfShape lE;
407 for (;exp.More();exp.Next())
408 lE.Append(exp.Current());
409 if (lE.Extent() == 1)
411 else if (lE.Extent() > 1)
423 reshaper.Replace(K, V);
425 TopoDS_Shape nS = reshaper.Apply(mS);
426 HYDROData_SplitToZonesTool::SplitData aNS(aSplitData.Type, nS, aSplitData.ObjectNames);
427 outZoneList.append(aNS);
431 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
432 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
433 HYDROData_SplitToZonesTool::SplitDataList& newEdges)
435 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
436 while( anIter.hasNext() )
438 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
439 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
442 const TopoDS_Shape* aDivShape = ObjToRes.Seek(aSplitData.Shape);
445 TopExp_Explorer exp(*aDivShape, TopAbs_EDGE);
446 for (;exp.More();exp.Next())
448 HYDROData_SplitToZonesTool::SplitData anNewSData(aSplitData.Type, exp.Current(), aSplitData.ObjectNames);
449 newEdges.append(anNewSData);
453 newEdges.append(aSplitData);
458 void HYDROData_CalculationCase::Update()
460 HYDROData_Entity::Update();
463 // At first we remove previously created objects
467 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
468 if ( aDocument.IsNull() )
472 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
474 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
476 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
478 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
479 if ( !aGeomObjects.IsEmpty() ) {
480 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
482 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
483 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
484 if ( !aSplitObjects.isEmpty() ) {
485 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
486 while( anIter.hasNext() ) {
487 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
488 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
489 aZonesList.append( aSplitData );
490 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
491 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
492 anEdgesList.append( aSplitData );
498 //split edges by boundary polygons
499 HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
500 //edge to splitted edge (compound of edges or original edge)
501 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> ObjToRes;
502 //split edge list by BP
503 HYDROData_SplitToZonesTool::SplitDataList outBoundaryPolygonEdgesList; //new groups - for each BP of type 1 (cut) create a group of edges which are inside of this BP
504 SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes, outBoundaryPolygonEdgesList);
505 HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
506 //replace splitted edges in zone list (faces)
507 PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
509 //create new edges list based on splitting info from ObjToRes
510 HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
511 CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
513 newEdgesList1.append(outBoundaryPolygonEdgesList); //append new list of groups
514 //filter out edges list by include&selection tools
515 FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
517 switch( GetAssignmentMode() )
520 CreateRegionsDef( aDocument,aNewZonesList );
523 CreateRegionsAuto( aDocument,aNewZonesList );
527 CreateEdgeGroupsDef( aDocument, newEdgesList2 );
530 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
531 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
533 // Create result regions for case, by default one zone for one region
534 QString aRegsPref = CALCULATION_REGIONS_PREF;
535 QString aZonesPref = CALCULATION_ZONES_PREF;
537 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
538 while( anIter.hasNext() )
540 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
542 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
544 // Add the zone for region
545 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
549 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
550 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
552 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
553 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
554 QMap<QString, QString> aRegionNameToObjNameMap;
555 QString aZonesPref = CALCULATION_ZONES_PREF;
556 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
558 // 1. First we create a default region for each object included into the calculation case
559 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
560 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
562 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
565 QString anObjName = anObj->GetName();
566 QString aRegName = anObjName + "_reg";
567 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
568 aRegionsMap.insert( anObjName, aRegion );
569 aRegionNameToObjNameMap.insert( aRegName, anObjName );
572 // 2. Now for each zone it is necessary to determine the most priority object
573 // and assign to zone to corresponding region
574 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
575 while( anIter.hasNext() )
577 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
578 HYDROData_Zone::MergeType aMergeType;
579 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
580 if( aRegObj.IsNull() )
582 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
583 if( aRegion.IsNull() )
585 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
587 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
589 qDebug( "Error in algorithm: unresolved conflicts" );
592 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
593 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
594 if ( !aMergeObject.IsNull() ) {
595 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
596 aMergeEntity = aMergeObject->GetAltitudeObject();
601 case HYDROData_Zone::Merge_ZMIN:
602 case HYDROData_Zone::Merge_ZMAX:
603 aRegionZone->SetMergeType( aMergeType );
605 case HYDROData_Zone::Merge_Object:
606 aRegionZone->SetMergeType( aMergeType );
607 aRegionZone->RemoveMergeObject();
608 aRegionZone->SetMergeObject( aMergeEntity );
613 QStringList anObjectsWithEmptyRegions;
614 QMap<QString, Handle(HYDROData_Region)>::const_iterator
615 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
616 for( ; anIt!=aLast; anIt++ )
618 Handle(HYDROData_Region) aRegion = anIt.value();
619 if( aRegion->GetZones().IsEmpty() )
621 QString aRegName = aRegion->GetName();
622 QString anObjName = aRegionNameToObjNameMap[aRegName];
623 anObjectsWithEmptyRegions.append( anObjName );
627 if( !anObjectsWithEmptyRegions.empty() )
629 QString aData = anObjectsWithEmptyRegions.join( ", " );
630 SetWarning( WARN_EMPTY_REGIONS, aData );
634 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
635 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
637 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
639 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
640 while( anIter.hasNext() )
642 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
643 // Create new edges group
644 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
647 QString anObjName = aSplitData.ObjectNames.first();
648 if ( anObjName.isEmpty() )
650 #ifdef DEB_CALCULATION
651 QString aStr = aSplitData.ObjectNames.join(" ");
652 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
654 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
655 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
657 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
658 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
662 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
664 if ( aSplitGroup.IsNull() )
667 aSplitGroup->AddShape( aSplitData.Shape );
669 TopTools_SequenceOfShape theShapes;
670 aSplitGroup->GetShapes(theShapes);
672 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
673 aSplitGroup->SetInternal(true);
677 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
679 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
680 return false; // Wrong type of object
682 if ( HasReference( theObject, DataTag_GeometryObject ) )
683 return false; // Object is already in reference list
685 AddReferenceObject( theObject, DataTag_GeometryObject );
687 // Indicate model of the need to update splitting
693 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
695 return GetReferenceObjects( DataTag_GeometryObject );
698 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
700 if ( theObject.IsNull() )
703 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
705 // Indicate model of the need to update splitting
709 void HYDROData_CalculationCase::RemoveGeometryObjects()
711 ClearReferenceObjects( DataTag_GeometryObject );
713 // Indicate model of the need to update splitting
717 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
719 if ( theGroup.IsNull() )
722 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
723 return false; // Object is already in reference list
725 AddReferenceObject( theGroup, DataTag_GeometryGroup );
727 // Indicate model of the need to update splitting
728 Changed( Geom_Groups );
733 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
735 return GetReferenceObjects( DataTag_GeometryGroup );
738 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
740 if ( theGroup.IsNull() )
743 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
745 // Indicate model of the need to update splitting
746 Changed( Geom_Groups );
749 void HYDROData_CalculationCase::RemoveGeometryGroups()
751 ClearReferenceObjects( DataTag_GeometryGroup );
753 // Indicate model of the need to update splitting
754 Changed( Geom_Groups );
757 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
759 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
761 SetReferenceObject( thePolyline, DataTag_Polyline );
763 // Indicate model of the need to update zones splitting
764 if( !IsEqual( aPrevPolyline, thePolyline ) )
768 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
770 return Handle(HYDROData_PolylineXY)::DownCast(
771 GetReferenceObject( DataTag_Polyline ) );
774 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
776 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
778 ClearReferenceObjects( DataTag_Polyline );
780 // Indicate model of the need to update zones splitting
784 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
786 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
788 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
790 // Indicate model of the need to update land covers partition
791 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
795 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
797 return Handle(HYDROData_StricklerTable)::DownCast(
798 GetReferenceObject( DataTag_StricklerTable ) );
801 void HYDROData_CalculationCase::RemoveStricklerTable()
803 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
805 ClearReferenceObjects( DataTag_StricklerTable );
807 // Indicate model of the need to update land covers partition
811 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
813 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
814 GetReferenceObject( DataTag_LandCoverMap ) );
815 DEBTRACE("GetLandCoverMap " << aMap.IsNull());
819 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
821 SetReferenceObject( theMap, DataTag_LandCoverMap );
824 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
829 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
830 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
831 if ( aNewRegion.IsNull() )
834 aNewRegion->AddZone( theZone );
839 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
841 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
843 if ( theRegion.IsNull() )
846 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
848 if ( HasReference( theRegion, aDataTag ) )
849 return false; // Object is already in reference list
851 // Move the region from other calculation
852 Handle(HYDROData_CalculationCase) aFatherCalc =
853 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
854 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
856 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
857 theRegion->CopyTo( aNewRegion, true );
859 aFatherCalc->RemoveRegion( theRegion );
861 theRegion->SetLabel( aNewRegion->Label() );
865 AddReferenceObject( theRegion, aDataTag );
871 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
873 return GetReferenceObjects( DataTag_Region );
876 void HYDROData_CalculationCase::UpdateRegionsOrder()
878 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
879 if ( aDocument.IsNull() )
882 QString aRegsPref = CALCULATION_REGIONS_PREF;
883 std::map<int, Handle(HYDROData_Region)> IndToRegion; //index in the name of region to region itself
884 HYDROData_SequenceOfObjects aRegions = GetRegions();
885 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
888 for ( ; anIter.More(); anIter.Next() )
890 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() );
891 if ( aRegion.IsNull() )
894 if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref)
895 IndToRegion[aVal] = aRegion;
898 int nbR = aRegions.Length();
899 std::map<int, Handle(HYDROData_Region)>::iterator it = IndToRegion.begin();
900 for( int i = 1; it != IndToRegion.end(); ++it )
901 if (it->first <= nbR + 1)
903 QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i));
904 it->second->SetName(aNewName);
909 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
911 if ( theRegion.IsNull() )
914 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
915 RemoveReferenceObject( theRegion->Label(), aDataTag );
917 // Remove region from data model
918 Handle(HYDROData_CalculationCase) aFatherCalc =
919 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
920 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
924 void HYDROData_CalculationCase::RemoveRegions()
926 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
929 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
931 return GetReferenceObjects( DataTag_SplitGroups );
934 void HYDROData_CalculationCase::RemoveSplitGroups()
936 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
939 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
941 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
942 return GetAltitudeForPoint( thePoint, aZone );
945 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
946 const Handle(HYDROData_Region)& theRegion,
949 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
951 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
952 if ( !aZone.IsNull() )
954 DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
955 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
956 if ( IsEqual( aRefRegion, theRegion ) )
957 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
960 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
961 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
966 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
972 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
973 const Handle(HYDROData_Zone)& theZone,
976 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
977 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
978 if ( theZone.IsNull() )
980 DEBTRACE("Zone nulle");
984 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
985 DEBTRACE("aZoneMergeType " << aZoneMergeType);
986 if ( !theZone->IsMergingNeed() )
988 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
991 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
993 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
997 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
998 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
1000 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
1001 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
1002 if ( !aMergeAltitude.IsNull() )
1004 if ( aZoneInterpolator != NULL )
1006 DEBTRACE("aZoneInterpolator != NULL");
1007 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
1008 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1012 DEBTRACE("aZoneInterpolator == NULL");
1013 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint, theMethod );
1019 DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
1020 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
1021 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
1022 for ( ; anIter.More(); anIter.Next() )
1024 Handle(HYDROData_Object) aZoneObj =
1025 Handle(HYDROData_Object)::DownCast( anIter.Value() );
1026 if ( aZoneObj.IsNull() )
1029 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
1030 if ( anObjAltitude.IsNull() )
1033 double aPointAltitude = 0.0;
1034 if ( aZoneInterpolator != NULL )
1036 DEBTRACE("aZoneInterpolator != NULL");
1037 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
1038 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1042 DEBTRACE("aZoneInterpolator == NULL");
1043 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
1046 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
1049 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
1051 aResAltitude = aPointAltitude;
1054 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
1056 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1057 aResAltitude > aPointAltitude )
1059 aResAltitude = aPointAltitude;
1062 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
1064 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1065 aResAltitude < aPointAltitude )
1067 aResAltitude = aPointAltitude;
1073 return aResAltitude;
1076 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1077 const NCollection_Sequence<gp_XY>& thePoints,
1078 const Handle(HYDROData_Region)& theRegion,
1079 int theMethod) const
1081 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
1082 NCollection_Sequence<double> aResSeq;
1084 Handle(Message_ProgressIndicator) aZIProgress = HYDROData_Tool::GetZIProgress();
1085 //DEBTRACE("aZIProgress=" << aZIProgress);
1086 if ( aZIProgress ) {
1087 aZIProgress->Reset();
1090 QFuture<void> aFuture = QtConcurrent::run([&]() {
1091 int aNbPoints = thePoints.Length();
1093 Message_ProgressSentry aPSentry(HYDROData_Tool::GetZIProgress(), "GetAltitudesForPoints", 0, aNbPoints, 1);
1094 for ( int i = 1, n = aNbPoints; i <= n && aPSentry.More(); ++i, aPSentry.Next() )
1096 const gp_XY& thePnt = thePoints.Value( i );
1098 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
1099 aResSeq.Append( anAltitude );
1103 while( aFuture.isRunning() ) {
1104 if ( aZIProgress ) {
1105 aZIProgress->Show( Standard_True );
1106 QThread::usleep(500);
1109 //DEBTRACE("aZIProgress=" << aZIProgress);
1111 aZIProgress->Show( Standard_True );
1116 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1117 const NCollection_Sequence<gp_XY>& thePoints,
1118 const Handle(HYDROData_Zone)& theZone,
1119 int theMethod) const
1121 NCollection_Sequence<double> aResSeq;
1123 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1125 const gp_XY& thePnt = thePoints.Value( i );
1127 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
1128 aResSeq.Append( anAltitude );
1134 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
1136 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
1137 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1142 aMap->FindByPoint( thePoint, aType );
1143 double aCoeff = aTable->Get( aType, 0.0 );
1147 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
1148 double DefValue, bool UseMax ) const
1150 DEBTRACE("GetStricklerCoefficientForPoints");
1151 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1152 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1153 std::vector<double> theCoeffs;
1154 DEBTRACE("aLCM.IsNull() " << aLCM.IsNull());
1155 DEBTRACE("aTable.IsNull() "<< aTable.IsNull());
1156 if( aLCM.IsNull() || aTable.IsNull() )
1159 Handle(Message_ProgressIndicator) aSIProgress = HYDROData_Tool::GetSIProgress();
1160 if ( aSIProgress ) {
1161 aSIProgress->Reset();
1164 QFuture<void> aFuture = QtConcurrent::run([&]() {
1165 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
1168 while( aFuture.isRunning() ) {
1169 if ( aSIProgress ) {
1170 aSIProgress->Show( Standard_True );
1171 QThread::usleep(500);
1178 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
1180 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1181 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1182 std::vector<int> types;
1183 if( aLCM.IsNull() || aTable.IsNull() )
1186 aLCM->ClassifyPoints(thePoints, aTable, types );
1190 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
1192 Handle(HYDROData_Region) aResRegion;
1194 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
1195 if ( !aZone.IsNull() )
1196 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1201 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
1203 Handle(HYDROData_Zone) aResZone;
1205 HYDROData_SequenceOfObjects aRegions = GetRegions();
1207 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1208 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1210 Handle(HYDROData_Region) aRegion =
1211 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1212 if ( aRegion.IsNull() )
1215 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1216 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1217 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1219 Handle(HYDROData_Zone) aRegZone =
1220 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1221 if ( aRegZone.IsNull() )
1224 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1225 if ( aPointRelation != POINT_OUT )
1226 aResZone = aRegZone; // We found the desired zone
1233 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1234 const gp_XY& thePoint,
1235 const Handle(HYDROData_Zone)& theZone ) const
1237 PointClassification aRes = POINT_OUT;
1238 if ( theZone.IsNull() )
1241 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1242 if ( aZoneFace.IsNull() )
1245 TopoDS_Compound aCmp;
1247 aBB.MakeCompound(aCmp);
1248 aBB.Add(aCmp, aZoneFace);
1249 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1250 BRepBuilderAPI_MakeVertex aMk(aPnt);
1251 aBB.Add(aCmp, aMk.Vertex());
1252 BRepTools::Write(aCmp, "FCL2d.brep");
1254 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1255 if (State == TopAbs_OUT)
1257 else if(State == TopAbs_IN)
1259 else if(State == TopAbs_ON)
1264 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1265 const QString& thePrefixOrName,
1268 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1269 int aTag = aNewLab.Tag();
1271 Handle(HYDROData_Region) aNewRegion =
1272 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1273 AddRegion( aNewRegion );
1275 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1276 aNewRegion->SetName( aRegionName, true );
1281 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1283 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1285 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1286 Handle(HYDROData_SplitShapesGroup)::DownCast(
1287 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1288 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1290 aNewGroup->SetName( theName );
1295 QString HYDROData_CalculationCase::Export() const
1300 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1302 QString aGeomObjEntry, anErrorMsg;
1304 bool isOK = Export( aGEOMEngine, aGeomObjEntry, anErrorMsg, statMess );
1305 return isOK ? aGeomObjEntry : QString();
1310 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
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, 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 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1390 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1391 QString& theGeomObjEntry ) const
1394 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1395 aSewing.SetNonManifoldMode( Standard_False );
1396 #ifdef DEB_CALCULATION
1397 TCollection_AsciiString aNam("Sh_");
1400 TopTools_DataMapOfShapeListOfShape SH2M;
1401 for ( int i = 1; i <= aShToName.Extent(); i++ )
1403 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1404 if ( aShape.IsNull() )
1407 SH2M.Bind(aShape, TopTools_ListOfShape());
1408 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1409 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1411 aSewing.Add( aShape );
1414 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1416 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1417 for (; anExp.More(); anExp.Next() )
1419 aSewing.Add( anExp.Current() );
1420 LM.Append(anExp.Current());
1422 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1423 for (; anExp.More(); anExp.Next() )
1425 aSewing.Add( anExp.Current() );
1426 LM.Append(anExp.Current());
1432 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1434 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1436 for ( int i = 1; i <= aShToName.Extent(); i++ )
1438 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1439 const QString& Qstr = aShToName.FindFromIndex(i);
1440 const TopTools_ListOfShape& LM = SH2M(CurShape);
1441 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1443 const TopoDS_Shape& csh = it.Value();
1444 if (aSewing.IsModified(csh))
1445 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1447 aFacesToNameModif.Add(csh, Qstr);
1452 // If the sewed shape is empty - return false
1453 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1456 #ifdef DEB_CALCULATION
1457 BRepTools::Write(aSewedShape ,"Sew.brep");
1458 #endif // Publish the sewed shape
1459 QString aName = EXPORT_NAME;
1460 GEOM::GEOM_Object_ptr aMainShape =
1461 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1463 if ( aMainShape->_is_nil() )
1466 if ( theGroupsDefs.IsEmpty() )
1470 TopTools_IndexedMapOfShape aMapOfSubShapes;
1471 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1473 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1475 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1477 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1479 NCollection_Sequence<int> aGroupIndexes;
1480 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1482 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1483 #ifdef DEB_CALCULATION
1484 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1487 TopoDS_Shape aModifiedShape = aShape;
1488 if ( aSewing.IsModified( aShape ) )
1489 aModifiedShape = aSewing.Modified( aShape );
1490 else if ( aSewing.IsModifiedSubShape( aShape ) )
1491 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1493 #ifdef DEB_CALCULATION
1494 const TopLoc_Location& aL1 = aShape.Location();
1495 const TopLoc_Location& aL2 = aModifiedShape.Location();
1496 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1499 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1500 if ( anIndex > 0 ) {
1501 aGroupIndexes.Append( anIndex );
1503 #ifdef DEB_CALCULATION
1504 TCollection_AsciiString aNam("Lost_");
1505 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1506 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1508 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1509 if ( aModifiedShape.IsPartner( aS ) )
1511 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1512 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1513 BRepTools::Write(aS ,aName.ToCString());
1521 if ( !aGroupIndexes.IsEmpty() )
1522 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1525 if ( !aGroupsData.IsEmpty() )
1527 GEOM::GEOM_IGroupOperations_var aGroupOp =
1528 theGeomEngine->GetIGroupOperations();
1530 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1531 for ( ; aMapIt.More(); aMapIt.Next() )
1533 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1534 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1536 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1537 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1540 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1541 aGeomIndexes->length( aGroupIndexes.Length() );
1543 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1544 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1546 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1547 if ( aGroupOp->IsDone() )
1549 SALOMEDS::SObject_var aGroupSO =
1550 theGeomEngine->AddInStudy( aGeomGroup, aGroupName.ToCString(), aMainShape );
1559 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1560 const bool theIsSetToUpdate )
1562 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1563 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1565 // Indicate model of the need to update splitting
1566 if ( theIsSetToUpdate ) {
1571 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1572 HYDROData_PriorityType thePriority,
1573 const Handle(HYDROData_Entity)& theObject2,
1574 HYDROData_Zone::MergeType theMergeType,
1575 HYDROData_CalculationCase::DataTag theDataTag )
1577 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1578 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1580 // Indicate model of the need to update splitting
1584 QString HYDROData_CalculationCase::DumpRules() const
1586 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1587 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1590 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1592 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1593 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1594 anAttr->SetID(TDataStd_Integer::GetID());
1595 // Indicate model of the need to update splitting
1599 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1601 Handle(TDataStd_Integer) aModeAttr;
1602 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1604 return ( AssignmentMode ) aModeAttr->Get();
1609 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1610 QStringList& theScript ) const
1612 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1613 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1616 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1618 return myLastWarning;
1621 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1623 myLastWarning.Type = theType;
1624 myLastWarning.Data = theData;
1627 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1628 const QString& theOldCaseName,
1629 const QString& theName )
1631 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1632 for ( ; anIter.More(); anIter.Next() )
1634 Handle(HYDROData_Region) aRegion =
1635 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1636 if ( aRegion.IsNull() )
1639 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1641 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1642 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1643 for ( ; anIter.More(); anIter.Next() )
1645 Handle(HYDROData_Zone) aRegZone =
1646 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1647 if ( aRegZone.IsNull() )
1650 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1655 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1656 const QString& thePyScriptPath,
1657 MapOfTreatedObjects& theTreatedObjects,
1658 const HYDROData_SequenceOfObjects& theRegions ) const
1660 HYDROData_SequenceOfObjects::Iterator anIter;
1661 anIter.Init(theRegions);
1662 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1664 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1665 if (aRegion.IsNull())
1667 QString defRegName = this->GetName();
1668 QString regSuffix = QString("_Reg_%1").arg(ireg);
1669 defRegName += regSuffix;
1670 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1671 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1672 theResList << aRegDump;
1674 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1676 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1677 if (aRegion.IsNull())
1679 QStringList aRegDump;
1680 aRegion->SetNameInDumpPython(aRegDump);
1681 theResList << aRegDump;
1685 bool HYDROData_CalculationCase::GetRule( int theIndex,
1686 Handle(HYDROData_Entity)& theObject1,
1687 HYDROData_PriorityType& thePriority,
1688 Handle(HYDROData_Entity)& theObject2,
1689 HYDROData_Zone::MergeType& theMergeType,
1690 HYDROData_CalculationCase::DataTag& theDataTag) const
1692 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1693 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1694 theObject1, thePriority, theObject2, theMergeType );
1697 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1699 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1701 if ( HasReference( theInterPolyline, aDataTag ) )
1704 AddReferenceObject( theInterPolyline, aDataTag );
1711 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1713 return GetReferenceObjects( DataTag_InterPoly );
1716 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1718 if ( theInterPolyline.IsNull() )
1721 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1726 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1728 HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1730 if ( HasReference( theBCPolygon, aDataTag ) )
1733 AddReferenceObject( theBCPolygon, aDataTag );
1740 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1742 return GetReferenceObjects( DataTag_BCPolygon );
1745 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1747 if ( theBCPolygon.IsNull() )
1750 RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );