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 //#define DEB_CALCULATION 1
75 #ifdef DEB_CALCULATION
76 #include <BRepTools.hxx>
77 #include <TopLoc_Location.hxx>
79 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
80 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
81 #define CALCULATION_GROUPS_PREF GetName() + "_"
82 //#define DEB_CLASS2D 1
84 #include <BRepBuilderAPI_MakeVertex.hxx>
87 #define EXPORT_NAME "HYDRO_" + GetName()
90 #include <SALOME_NamingService.hxx>
91 #include <SALOME_LifeCycleCORBA.hxx>
95 #include "HYDRO_trace.hxx"
97 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
99 HYDROData_CalculationCase::HYDROData_CalculationCase()
100 : HYDROData_Entity( Geom_2d_and_groups )
104 HYDROData_CalculationCase::~HYDROData_CalculationCase()
108 void HYDROData_CalculationCase::SetName( const QString& theName, bool isDefault )
110 QString anOldCaseName = GetName();
111 if ( anOldCaseName != theName )
113 // Update names of regions and its zones
114 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
116 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
118 HYDROData_SequenceOfObjects::Iterator anIter;
119 anIter.Init( aGroups );
120 for ( ; anIter.More(); anIter.Next() )
122 Handle(HYDROData_SplitShapesGroup) aGroup =
123 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
124 if ( aGroup.IsNull() )
127 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
131 HYDROData_Entity::SetName( theName, isDefault );
134 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
135 MapOfTreatedObjects& theTreatedObjects ) const
137 QStringList aResList = dumpObjectCreation( theTreatedObjects );
138 aResList.prepend( "# Calculation case" );
140 QString aCalculName = GetObjPyName();
142 AssignmentMode aMode = GetAssignmentMode();
143 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
144 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
146 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
147 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
148 for ( ; anIter.More(); anIter.Next() )
150 Handle(HYDROData_Object) aRefGeomObj =
151 Handle(HYDROData_Object)::DownCast( anIter.Value() );
152 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
154 aResList << QString( "" );
156 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
158 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
159 anIter.Init( aGeomGroups );
160 for ( ; anIter.More(); anIter.Next() )
162 Handle(HYDROData_ShapesGroup) aGeomGroup =
163 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
164 if ( aGeomGroup.IsNull() )
167 Handle(HYDROData_Object) aFatherGeom =
168 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
169 if ( aFatherGeom.IsNull() )
172 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
173 aResList << QString( "%1 = %2.GetGroup( %3 )" )
174 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
176 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
179 HYDROData_SequenceOfObjects aBPolygons = GetBoundaryPolygons();
180 for (int i = 1; i <= aBPolygons.Size(); i++ )
182 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBPolygons(i) );
183 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBCPoly, "AddBoundaryPolygon" );
185 aResList << QString( "" );
187 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
188 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
190 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
191 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
193 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
194 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
196 if( aMode==AUTOMATIC )
197 DumpRulesToPython( aCalculName, aResList );
199 aResList << QString( "" );
200 aResList << "# Start the algorithm of the partition and assignment";
201 aResList << QString( "%1.Update()" ).arg( aCalculName );
205 // Now we restore the
206 // - regions and zones order
207 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
210 // Export calculation case
211 aResList << QString( "" );
212 aResList << "# Export of the calculation case";
213 QString anEntryVar = aCalculName + "_entry";
214 aResList << QString( "%1 = %2.Export()" ).arg( anEntryVar ).arg( aCalculName );
216 // Get geometry object and print debug information
218 aResList << "# Get geometry shape and print debug information";
219 aResList << "import GEOM";
220 aResList << QString( "print (\"Entry:\", %1)" ).arg( anEntryVar );
221 QString aGeomShapeName = aCalculName + "_geom";
222 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
223 aResList << QString( "print (\"Geom shape:\", HYDRO_%1)" ).arg( GetName() );
224 aResList << QString( "print (\"Geom shape name:\", HYDRO_%1.GetName())" ).arg( GetName() );
227 //DumpSampleMeshing( aResList, aGeomShapeName, aCalculName+"_mesh" );
229 aResList << QString( "" );
233 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
234 const QString& theGeomShapeName,
235 const QString& theMeshName ) const
238 theResList << "# Meshing";
239 theResList << "import SMESH, SALOMEDS";
240 theResList << "from salome.smesh import smeshBuilder";
241 theResList << "from salome.geom import geomBuilder";
243 theResList << QString( "smesh = smeshBuilder.New()" );
244 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
245 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
246 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
247 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
248 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
249 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
252 theResList << "# Set names of Mesh objects";
253 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
254 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
255 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
256 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
257 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
260 theResList << "# Greate SMESH groups";
261 theResList << QString( "geompy = geomBuilder.New()" );
262 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
263 theResList << QString( "for group in geom_groups:" );
264 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
266 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
267 theResList << QString( " print (\"SMESH group '%s': %s)\" % (smesh_group.GetName(), smesh_group)" );
270 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
272 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
274 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
275 if ( !aBoundaryPolyline.IsNull() )
276 aResSeq.Append( aBoundaryPolyline );
278 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
279 aResSeq.Append( aSeqOfGeomObjs );
282 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
283 aResSeq.Append( aSeqOfRegions );
288 static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
289 HYDROData_SequenceOfObjects aBoundaryPolygons,
290 HYDROData_SplitToZonesTool::SplitDataList& outEdgesList)
292 //perform boundary condition polygons on EdgesList
293 TopTools_SequenceOfShape IncTools, SelectionTools;
294 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
295 for (int i=1; i<=aBoundaryPolygons.Size();i++)
297 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
298 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
299 int bType = aBCPoly->GetBoundaryType();
301 IncTools.Append(aPolyTopShape);
303 SelectionTools.Append(aPolyTopShape);
306 while( anIter.hasNext() )
308 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
309 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
311 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
313 if (HYDROData_BoundaryPolygonTools::IncludeTool(IncTools, aSplitData.Shape) && HYDROData_BoundaryPolygonTools::SelectionTool(SelectionTools, aSplitData.Shape))
314 outEdgesList.append(aSplitData);
319 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
320 const HYDROData_SequenceOfObjects& aBoundaryPolygons,
321 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
322 HYDROData_SplitToZonesTool::SplitDataList& outBoundaryPolygonEdgesList)
324 //perform boundary condition polygons on EdgesList
325 TopTools_SequenceOfShape CutTools;
326 NCollection_DataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> BPolyToName;
329 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
330 for (int i=1; i<=aBoundaryPolygons.Size();i++)
332 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
333 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
334 int bType = aBCPoly->GetBoundaryType();
337 CutTools.Append(aPolyTopShape);
338 QString bp_name = aBCPoly->GetName();
339 BPolyToName.Bind(aPolyTopShape, bp_name);
343 while( anIter.hasNext() )
345 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
346 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
348 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
350 ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
353 NCollection_IndexedDataMap<TopoDS_Shape, TopTools_MapOfShape, TopTools_ShapeMapHasher> BPFaceToCutEdges;
354 HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes, BPFaceToCutEdges);
356 for (int i = 1; i <= CutTools.Length(); i++ )
358 TopoDS_Shape F = CutTools(i);
359 const QString* name = BPolyToName.Seek(F);
360 const TopTools_MapOfShape* EdgesIn = BPFaceToCutEdges.Seek(F); // EdgesIn : edges inside boudnary polygon F
363 TopTools_MapIteratorOfMapOfShape it(*EdgesIn);
364 for (;it.More();it.Next())
366 TopoDS_Edge E = TopoDS::Edge(it.Value());
369 HYDROData_SplitToZonesTool::SplitData SD(HYDROData_SplitToZonesTool::SplitData::Data_Edge, E, *name);
370 outBoundaryPolygonEdgesList.append(SD);
378 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
379 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
380 HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
382 HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList );
383 BRepTools_ReShape reshaper;
386 const HYDROData_SplitToZonesTool::SplitData& aSplitData = it.next();
387 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
390 TopoDS_Shape mS = aSplitData.Shape;
391 for (int i=1; i<=ObjToRes.Extent();i++)
393 TopoDS_Shape K = ObjToRes.FindKey(i);
394 TopoDS_Shape V = ObjToRes.FindFromIndex(i);
397 if (V.ShapeType() != TopAbs_EDGE && V.ShapeType() != TopAbs_WIRE && V.ShapeType() != TopAbs_COMPOUND)
399 if (V.ShapeType() == TopAbs_COMPOUND)
401 TopExp_Explorer exp(V, TopAbs_EDGE);
402 TopTools_ListOfShape lE;
403 for (;exp.More();exp.Next())
404 lE.Append(exp.Current());
405 if (lE.Extent() == 1)
407 else if (lE.Extent() > 1)
419 reshaper.Replace(K, V);
421 TopoDS_Shape nS = reshaper.Apply(mS);
422 HYDROData_SplitToZonesTool::SplitData aNS(aSplitData.Type, nS, aSplitData.ObjectNames);
423 outZoneList.append(aNS);
427 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
428 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher>& ObjToRes,
429 HYDROData_SplitToZonesTool::SplitDataList& newEdges)
431 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
432 while( anIter.hasNext() )
434 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
435 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
438 const TopoDS_Shape* aDivShape = ObjToRes.Seek(aSplitData.Shape);
441 TopExp_Explorer exp(*aDivShape, TopAbs_EDGE);
442 for (;exp.More();exp.Next())
444 HYDROData_SplitToZonesTool::SplitData anNewSData(aSplitData.Type, exp.Current(), aSplitData.ObjectNames);
445 newEdges.append(anNewSData);
449 newEdges.append(aSplitData);
454 void HYDROData_CalculationCase::Update()
456 HYDROData_Entity::Update();
459 // At first we remove previously created objects
463 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document();
464 if ( aDocument.IsNull() )
468 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
470 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
472 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
474 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
475 if ( !aGeomObjects.IsEmpty() ) {
476 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
478 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
479 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
480 if ( !aSplitObjects.isEmpty() ) {
481 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
482 while( anIter.hasNext() ) {
483 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
484 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
485 aZonesList.append( aSplitData );
486 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
487 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
488 anEdgesList.append( aSplitData );
494 //split edges by boundary polygons
495 HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
496 //edge to splitted edge (compound of edges or original edge)
497 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape, TopTools_ShapeMapHasher> ObjToRes;
498 //split edge list by BP
499 HYDROData_SplitToZonesTool::SplitDataList outBoundaryPolygonEdgesList; //new groups - for each BP of type 1 (cut) create a group of edges which are inside of this BP
500 SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes, outBoundaryPolygonEdgesList);
501 HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
502 //replace splitted edges in zone list (faces)
503 PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
505 //create new edges list based on splitting info from ObjToRes
506 HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
507 CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
509 newEdgesList1.append(outBoundaryPolygonEdgesList); //append new list of groups
510 //filter out edges list by include&selection tools
511 FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
513 switch( GetAssignmentMode() )
516 CreateRegionsDef( aDocument,aNewZonesList );
519 CreateRegionsAuto( aDocument,aNewZonesList );
523 CreateEdgeGroupsDef( aDocument, newEdgesList2 );
526 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
527 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
529 // Create result regions for case, by default one zone for one region
530 QString aRegsPref = CALCULATION_REGIONS_PREF;
531 QString aZonesPref = CALCULATION_ZONES_PREF;
533 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
534 while( anIter.hasNext() )
536 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
538 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
540 // Add the zone for region
541 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
545 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
546 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
548 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
549 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
550 QMap<QString, QString> aRegionNameToObjNameMap;
551 QString aZonesPref = CALCULATION_ZONES_PREF;
552 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
554 // 1. First we create a default region for each object included into the calculation case
555 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
556 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
558 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
561 QString anObjName = anObj->GetName();
562 QString aRegName = anObjName + "_reg";
563 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
564 aRegionsMap.insert( anObjName, aRegion );
565 aRegionNameToObjNameMap.insert( aRegName, anObjName );
568 // 2. Now for each zone it is necessary to determine the most priority object
569 // and assign to zone to corresponding region
570 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
571 while( anIter.hasNext() )
573 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
574 HYDROData_Zone::MergeType aMergeType;
575 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
576 if( aRegObj.IsNull() )
578 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
579 if( aRegion.IsNull() )
581 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
583 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
585 qDebug( "Error in algorithm: unresolved conflicts" );
588 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
589 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
590 if ( !aMergeObject.IsNull() ) {
591 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
592 aMergeEntity = aMergeObject->GetAltitudeObject();
597 case HYDROData_Zone::Merge_ZMIN:
598 case HYDROData_Zone::Merge_ZMAX:
599 aRegionZone->SetMergeType( aMergeType );
601 case HYDROData_Zone::Merge_Object:
602 aRegionZone->SetMergeType( aMergeType );
603 aRegionZone->RemoveMergeObject();
604 aRegionZone->SetMergeObject( aMergeEntity );
609 QStringList anObjectsWithEmptyRegions;
610 QMap<QString, Handle(HYDROData_Region)>::const_iterator
611 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
612 for( ; anIt!=aLast; anIt++ )
614 Handle(HYDROData_Region) aRegion = anIt.value();
615 if( aRegion->GetZones().IsEmpty() )
617 QString aRegName = aRegion->GetName();
618 QString anObjName = aRegionNameToObjNameMap[aRegName];
619 anObjectsWithEmptyRegions.append( anObjName );
623 if( !anObjectsWithEmptyRegions.empty() )
625 QString aData = anObjectsWithEmptyRegions.join( ", " );
626 SetWarning( WARN_EMPTY_REGIONS, aData );
630 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
631 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
633 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
635 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
636 while( anIter.hasNext() )
638 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
639 // Create new edges group
640 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
643 QString anObjName = aSplitData.ObjectNames.first();
644 if ( anObjName.isEmpty() )
646 #ifdef DEB_CALCULATION
647 QString aStr = aSplitData.ObjectNames.join(" ");
648 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
650 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
651 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
653 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
654 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
658 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
660 if ( aSplitGroup.IsNull() )
663 aSplitGroup->AddShape( aSplitData.Shape );
665 TopTools_SequenceOfShape theShapes;
666 aSplitGroup->GetShapes(theShapes);
668 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
669 aSplitGroup->SetInternal(true);
673 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
675 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
676 return false; // Wrong type of object
678 if ( HasReference( theObject, DataTag_GeometryObject ) )
679 return false; // Object is already in reference list
681 AddReferenceObject( theObject, DataTag_GeometryObject );
683 // Indicate model of the need to update splitting
689 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
691 return GetReferenceObjects( DataTag_GeometryObject );
694 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
696 if ( theObject.IsNull() )
699 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
701 // Indicate model of the need to update splitting
705 void HYDROData_CalculationCase::RemoveGeometryObjects()
707 ClearReferenceObjects( DataTag_GeometryObject );
709 // Indicate model of the need to update splitting
713 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
715 if ( theGroup.IsNull() )
718 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
719 return false; // Object is already in reference list
721 AddReferenceObject( theGroup, DataTag_GeometryGroup );
723 // Indicate model of the need to update splitting
724 Changed( Geom_Groups );
729 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
731 return GetReferenceObjects( DataTag_GeometryGroup );
734 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
736 if ( theGroup.IsNull() )
739 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
741 // Indicate model of the need to update splitting
742 Changed( Geom_Groups );
745 void HYDROData_CalculationCase::RemoveGeometryGroups()
747 ClearReferenceObjects( DataTag_GeometryGroup );
749 // Indicate model of the need to update splitting
750 Changed( Geom_Groups );
753 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
755 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
757 SetReferenceObject( thePolyline, DataTag_Polyline );
759 // Indicate model of the need to update zones splitting
760 if( !IsEqual( aPrevPolyline, thePolyline ) )
764 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
766 return Handle(HYDROData_PolylineXY)::DownCast(
767 GetReferenceObject( DataTag_Polyline ) );
770 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
772 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
774 ClearReferenceObjects( DataTag_Polyline );
776 // Indicate model of the need to update zones splitting
780 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
782 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
784 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
786 // Indicate model of the need to update land covers partition
787 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
791 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
793 return Handle(HYDROData_StricklerTable)::DownCast(
794 GetReferenceObject( DataTag_StricklerTable ) );
797 void HYDROData_CalculationCase::RemoveStricklerTable()
799 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
801 ClearReferenceObjects( DataTag_StricklerTable );
803 // Indicate model of the need to update land covers partition
807 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
809 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
810 GetReferenceObject( DataTag_LandCoverMap ) );
811 DEBTRACE("GetLandCoverMap " << aMap.IsNull());
815 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
817 SetReferenceObject( theMap, DataTag_LandCoverMap );
820 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
825 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document();
826 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
827 if ( aNewRegion.IsNull() )
830 aNewRegion->AddZone( theZone );
835 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
837 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document();
839 if ( theRegion.IsNull() )
842 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
844 if ( HasReference( theRegion, aDataTag ) )
845 return false; // Object is already in reference list
847 // Move the region from other calculation
848 Handle(HYDROData_CalculationCase) aFatherCalc =
849 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
850 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
852 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
853 theRegion->CopyTo( aNewRegion, true );
855 aFatherCalc->RemoveRegion( theRegion );
857 theRegion->SetLabel( aNewRegion->Label() );
861 AddReferenceObject( theRegion, aDataTag );
867 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
869 return GetReferenceObjects( DataTag_Region );
872 void HYDROData_CalculationCase::UpdateRegionsOrder()
874 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document();
875 if ( aDocument.IsNull() )
878 QString aRegsPref = CALCULATION_REGIONS_PREF;
879 std::map<int, Handle(HYDROData_Region)> IndToRegion; //index in the name of region to region itself
880 HYDROData_SequenceOfObjects aRegions = GetRegions();
881 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
884 for ( ; anIter.More(); anIter.Next() )
886 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() );
887 if ( aRegion.IsNull() )
890 if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref)
891 IndToRegion[aVal] = aRegion;
894 int nbR = aRegions.Length();
895 std::map<int, Handle(HYDROData_Region)>::iterator it = IndToRegion.begin();
896 for( int i = 1; it != IndToRegion.end(); ++it )
897 if (it->first <= nbR + 1)
899 QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i));
900 it->second->SetName(aNewName);
905 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
907 if ( theRegion.IsNull() )
910 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
911 RemoveReferenceObject( theRegion->Label(), aDataTag );
913 // Remove region from data model
914 Handle(HYDROData_CalculationCase) aFatherCalc =
915 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
916 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
920 void HYDROData_CalculationCase::RemoveRegions()
922 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
925 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
927 return GetReferenceObjects( DataTag_SplitGroups );
930 void HYDROData_CalculationCase::RemoveSplitGroups()
932 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
935 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
937 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
938 return GetAltitudeForPoint( thePoint, aZone );
941 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
942 const Handle(HYDROData_Region)& theRegion,
945 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
947 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
948 if ( !aZone.IsNull() )
950 DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
951 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
952 if ( IsEqual( aRefRegion, theRegion ) )
953 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
956 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
957 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
962 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
968 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
969 const Handle(HYDROData_Zone)& theZone,
972 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
973 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
974 if ( theZone.IsNull() )
976 DEBTRACE("Zone nulle");
980 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
981 DEBTRACE("aZoneMergeType " << aZoneMergeType);
982 if ( !theZone->IsMergingNeed() )
984 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
987 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
989 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
993 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
994 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
996 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
997 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
998 if ( !aMergeAltitude.IsNull() )
1000 if ( aZoneInterpolator != NULL )
1002 DEBTRACE("aZoneInterpolator != NULL");
1003 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
1004 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1008 DEBTRACE("aZoneInterpolator == NULL");
1009 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint, theMethod );
1015 DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
1016 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
1017 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
1018 for ( ; anIter.More(); anIter.Next() )
1020 Handle(HYDROData_Object) aZoneObj =
1021 Handle(HYDROData_Object)::DownCast( anIter.Value() );
1022 if ( aZoneObj.IsNull() )
1025 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
1026 if ( anObjAltitude.IsNull() )
1029 double aPointAltitude = 0.0;
1030 if ( aZoneInterpolator != NULL )
1032 DEBTRACE("aZoneInterpolator != NULL");
1033 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
1034 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1038 DEBTRACE("aZoneInterpolator == NULL");
1039 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
1042 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
1045 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
1047 aResAltitude = aPointAltitude;
1050 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
1052 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1053 aResAltitude > aPointAltitude )
1055 aResAltitude = aPointAltitude;
1058 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
1060 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1061 aResAltitude < aPointAltitude )
1063 aResAltitude = aPointAltitude;
1069 return aResAltitude;
1072 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1073 const NCollection_Sequence<gp_XY>& thePoints,
1074 const Handle(HYDROData_Region)& theRegion,
1075 int theMethod) const
1077 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
1078 NCollection_Sequence<double> aResSeq;
1080 QFuture<void> aFuture = QtConcurrent::run([&]() {
1081 int aNbPoints = thePoints.Length();
1083 for ( int i = 1, n = aNbPoints; i <= n; ++i)
1085 const gp_XY& thePnt = thePoints.Value( i );
1087 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
1088 aResSeq.Append( anAltitude );
1092 while( aFuture.isRunning() ) {
1099 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1100 const NCollection_Sequence<gp_XY>& thePoints,
1101 const Handle(HYDROData_Zone)& theZone,
1102 int theMethod) const
1104 NCollection_Sequence<double> aResSeq;
1106 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1108 const gp_XY& thePnt = thePoints.Value( i );
1110 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
1111 aResSeq.Append( anAltitude );
1117 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
1119 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
1120 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1125 aMap->FindByPoint( thePoint, aType );
1126 double aCoeff = aTable->Get( aType, 0.0 );
1130 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
1131 double DefValue, bool UseMax ) const
1133 DEBTRACE("GetStricklerCoefficientForPoints");
1134 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1135 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1136 std::vector<double> theCoeffs;
1137 DEBTRACE("aLCM.IsNull() " << aLCM.IsNull());
1138 DEBTRACE("aTable.IsNull() "<< aTable.IsNull());
1139 if( aLCM.IsNull() || aTable.IsNull() )
1143 QFuture<void> aFuture = QtConcurrent::run([&]() {
1144 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
1147 while( aFuture.isRunning() ) {
1148 QThread::msleep(200);
1154 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
1156 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1157 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1158 std::vector<int> types;
1159 if( aLCM.IsNull() || aTable.IsNull() )
1162 aLCM->ClassifyPoints(thePoints, aTable, types );
1166 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
1168 Handle(HYDROData_Region) aResRegion;
1170 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
1171 if ( !aZone.IsNull() )
1172 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1177 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
1179 Handle(HYDROData_Zone) aResZone;
1181 HYDROData_SequenceOfObjects aRegions = GetRegions();
1183 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1184 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1186 Handle(HYDROData_Region) aRegion =
1187 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1188 if ( aRegion.IsNull() )
1191 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1192 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1193 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1195 Handle(HYDROData_Zone) aRegZone =
1196 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1197 if ( aRegZone.IsNull() )
1200 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1201 if ( aPointRelation != POINT_OUT )
1202 aResZone = aRegZone; // We found the desired zone
1209 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1210 const gp_XY& thePoint,
1211 const Handle(HYDROData_Zone)& theZone ) const
1213 PointClassification aRes = POINT_OUT;
1214 if ( theZone.IsNull() )
1217 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1218 if ( aZoneFace.IsNull() )
1221 TopoDS_Compound aCmp;
1223 aBB.MakeCompound(aCmp);
1224 aBB.Add(aCmp, aZoneFace);
1225 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1226 BRepBuilderAPI_MakeVertex aMk(aPnt);
1227 aBB.Add(aCmp, aMk.Vertex());
1228 BRepTools::Write(aCmp, "FCL2d.brep");
1230 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1231 if (State == TopAbs_OUT)
1233 else if(State == TopAbs_IN)
1235 else if(State == TopAbs_ON)
1240 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1241 const QString& thePrefixOrName,
1244 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1245 int aTag = aNewLab.Tag();
1247 Handle(HYDROData_Region) aNewRegion =
1248 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1249 AddRegion( aNewRegion );
1251 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1252 aNewRegion->SetName( aRegionName, true );
1257 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1259 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1261 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1262 Handle(HYDROData_SplitShapesGroup)::DownCast(
1263 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1264 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1266 aNewGroup->SetName( theName );
1271 void HYDROData_CalculationCase::SetContainerName( const QString& theContainerName )
1274 HYDROData_GeomTool::SetContainerName( theContainerName );
1278 QString HYDROData_CalculationCase::Export() const
1283 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1285 QString aGeomObjEntry, anErrorMsg;
1287 bool isOK = Export( aGEOMEngine, aGeomObjEntry, anErrorMsg, statMess );
1288 return isOK ? aGeomObjEntry : QString();
1293 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1294 QString& theGeomObjEntry,
1295 QString& theErrorMsg,
1296 QString& statMess) const
1299 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1301 // Get groups definitions
1302 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1304 TopTools_SequenceOfShape IntSh; //internal edges
1305 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1306 for ( ; anIter.More(); anIter.Next() )
1309 Handle(HYDROData_ShapesGroup) aGroup =
1310 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1311 if ( aGroup.IsNull() )
1314 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1316 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1317 aGroup->GetShapes( aGroupDef.Shapes );
1319 aSeqOfGroupsDefs.Append( aGroupDef );
1321 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1322 TopTools_SequenceOfShape dummy;
1323 if (!aSSGroup.IsNull())
1324 if (aSSGroup->GetInternal())
1326 aSSGroup->GetShapes(dummy);
1327 IntSh.Append(dummy);
1333 bool isAllNotSubmersible = true;
1334 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1335 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1336 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1337 for ( ; aRegionIter.More(); aRegionIter.Next() )
1339 Handle(HYDROData_Region) aRegion =
1340 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1341 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1344 if ( isAllNotSubmersible )
1345 isAllNotSubmersible = false;
1347 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1348 aShToNames.Add( aRegionShape, aRegion->GetName() );
1353 if ( aCaseRegions.IsEmpty() ) {
1354 theErrorMsg = QString("the list of regions is empty.");
1355 } else if ( isAllNotSubmersible ) {
1356 theErrorMsg = QString("there are no submersible regions.");
1358 aRes = Export( theGeomEngine, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1361 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1363 QString aTelemacFileName = GetName() + ".telemac";
1364 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1366 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1371 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1372 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1373 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1374 QString& theGeomObjEntry ) const
1377 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1378 aSewing.SetNonManifoldMode( Standard_False );
1379 #ifdef DEB_CALCULATION
1380 TCollection_AsciiString aNam("Sh_");
1383 TopTools_DataMapOfShapeListOfShape SH2M;
1384 for ( int i = 1; i <= aShToName.Extent(); i++ )
1386 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1387 if ( aShape.IsNull() )
1390 SH2M.Bind(aShape, TopTools_ListOfShape());
1391 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1392 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1394 aSewing.Add( aShape );
1397 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1399 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1400 for (; anExp.More(); anExp.Next() )
1402 aSewing.Add( anExp.Current() );
1403 LM.Append(anExp.Current());
1405 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1406 for (; anExp.More(); anExp.Next() )
1408 aSewing.Add( anExp.Current() );
1409 LM.Append(anExp.Current());
1415 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1417 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1419 for ( int i = 1; i <= aShToName.Extent(); i++ )
1421 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1422 const QString& Qstr = aShToName.FindFromIndex(i);
1423 const TopTools_ListOfShape& LM = SH2M(CurShape);
1424 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1426 const TopoDS_Shape& csh = it.Value();
1427 if (aSewing.IsModified(csh))
1428 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1430 aFacesToNameModif.Add(csh, Qstr);
1435 // If the sewed shape is empty - return false
1436 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1439 #ifdef DEB_CALCULATION
1440 BRepTools::Write(aSewedShape ,"Sew.brep");
1441 #endif // Publish the sewed shape
1442 QString aName = EXPORT_NAME;
1443 GEOM::GEOM_Object_ptr aMainShape =
1444 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1446 if ( aMainShape->_is_nil() )
1449 if ( theGroupsDefs.IsEmpty() )
1453 TopTools_IndexedMapOfShape aMapOfSubShapes;
1454 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1456 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1458 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1460 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1462 NCollection_Sequence<int> aGroupIndexes;
1463 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1465 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1466 #ifdef DEB_CALCULATION
1467 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1470 TopoDS_Shape aModifiedShape = aShape;
1471 if ( aSewing.IsModified( aShape ) )
1472 aModifiedShape = aSewing.Modified( aShape );
1473 else if ( aSewing.IsModifiedSubShape( aShape ) )
1474 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1476 #ifdef DEB_CALCULATION
1477 const TopLoc_Location& aL1 = aShape.Location();
1478 const TopLoc_Location& aL2 = aModifiedShape.Location();
1479 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1482 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1483 if ( anIndex > 0 ) {
1484 aGroupIndexes.Append( anIndex );
1486 #ifdef DEB_CALCULATION
1487 TCollection_AsciiString aNam("Lost_");
1488 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1489 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1491 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1492 if ( aModifiedShape.IsPartner( aS ) )
1494 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1495 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1496 BRepTools::Write(aS ,aName.ToCString());
1504 if ( !aGroupIndexes.IsEmpty() )
1505 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1508 if ( !aGroupsData.IsEmpty() )
1510 GEOM::GEOM_IGroupOperations_var aGroupOp =
1511 theGeomEngine->GetIGroupOperations();
1513 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1514 for ( ; aMapIt.More(); aMapIt.Next() )
1516 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1517 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1519 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1520 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1523 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1524 aGeomIndexes->length( aGroupIndexes.Length() );
1526 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1527 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1529 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1530 if ( aGroupOp->IsDone() )
1532 SALOMEDS::SObject_var aGroupSO =
1533 theGeomEngine->AddInStudy( aGeomGroup, aGroupName.ToCString(), aMainShape );
1542 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1543 const bool theIsSetToUpdate )
1545 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1546 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1548 // Indicate model of the need to update splitting
1549 if ( theIsSetToUpdate ) {
1554 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1555 HYDROData_PriorityType thePriority,
1556 const Handle(HYDROData_Entity)& theObject2,
1557 HYDROData_Zone::MergeType theMergeType,
1558 HYDROData_CalculationCase::DataTag theDataTag )
1560 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1561 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1563 // Indicate model of the need to update splitting
1567 QString HYDROData_CalculationCase::DumpRules() const
1569 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1570 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1573 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1575 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1576 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1577 anAttr->SetID(TDataStd_Integer::GetID());
1578 // Indicate model of the need to update splitting
1582 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1584 Handle(TDataStd_Integer) aModeAttr;
1585 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1587 return ( AssignmentMode ) aModeAttr->Get();
1592 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1593 QStringList& theScript ) const
1595 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1596 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1599 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1601 return myLastWarning;
1604 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1606 myLastWarning.Type = theType;
1607 myLastWarning.Data = theData;
1610 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1611 const QString& theOldCaseName,
1612 const QString& theName )
1614 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1615 for ( ; anIter.More(); anIter.Next() )
1617 Handle(HYDROData_Region) aRegion =
1618 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1619 if ( aRegion.IsNull() )
1622 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1624 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1625 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1626 for ( ; anIter.More(); anIter.Next() )
1628 Handle(HYDROData_Zone) aRegZone =
1629 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1630 if ( aRegZone.IsNull() )
1633 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1638 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1639 const QString& thePyScriptPath,
1640 MapOfTreatedObjects& theTreatedObjects,
1641 const HYDROData_SequenceOfObjects& theRegions ) const
1643 HYDROData_SequenceOfObjects::Iterator anIter;
1644 anIter.Init(theRegions);
1645 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1647 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1648 if (aRegion.IsNull())
1650 QString defRegName = this->GetName();
1651 QString regSuffix = QString("_Reg_%1").arg(ireg);
1652 defRegName += regSuffix;
1653 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1654 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1655 theResList << aRegDump;
1657 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1659 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1660 if (aRegion.IsNull())
1662 QStringList aRegDump;
1663 aRegion->SetNameInDumpPython(aRegDump);
1664 theResList << aRegDump;
1668 bool HYDROData_CalculationCase::GetRule( int theIndex,
1669 Handle(HYDROData_Entity)& theObject1,
1670 HYDROData_PriorityType& thePriority,
1671 Handle(HYDROData_Entity)& theObject2,
1672 HYDROData_Zone::MergeType& theMergeType,
1673 HYDROData_CalculationCase::DataTag& theDataTag) const
1675 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1676 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1677 theObject1, thePriority, theObject2, theMergeType );
1680 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1682 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1684 if ( HasReference( theInterPolyline, aDataTag ) )
1687 AddReferenceObject( theInterPolyline, aDataTag );
1694 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1696 return GetReferenceObjects( DataTag_InterPoly );
1699 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1701 if ( theInterPolyline.IsNull() )
1704 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1709 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1711 HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1713 if ( HasReference( theBCPolygon, aDataTag ) )
1716 AddReferenceObject( theBCPolygon, aDataTag );
1723 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1725 return GetReferenceObjects( DataTag_BCPolygon );
1728 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1730 if ( theBCPolygon.IsNull() )
1733 RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );