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>
38 #pragma warning ( disable: 4251 )
46 #pragma warning ( default: 4251 )
51 #include <QtConcurrent/QtConcurrent>
55 #include <TopoDS_Shell.hxx>
56 #include <TopoDS_Edge.hxx>
58 #include <BRep_Builder.hxx>
59 #include <BRepBuilderAPI_Sewing.hxx>
60 #include <BRepTopAdaptor_FClass2d.hxx>
61 #include <BRepTools_ReShape.hxx>
62 #include <BRepLib_MakeWire.hxx>
64 #include <BRepTools.hxx>
67 #include <TopExp_Explorer.hxx>
69 #include <TopTools_ListOfShape.hxx>
70 #include <TopTools_ListIteratorOfListOfShape.hxx>
71 #include <TDataStd_Integer.hxx>
73 #include <Message_ProgressSentry.hxx>
75 //#define DEB_CALCULATION 1
76 #ifdef DEB_CALCULATION
77 #include <BRepTools.hxx>
78 #include <TopLoc_Location.hxx>
80 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
81 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
82 #define CALCULATION_GROUPS_PREF GetName() + "_"
83 //#define DEB_CLASS2D 1
85 #include <BRepBuilderAPI_MakeVertex.hxx>
88 #define EXPORT_NAME "HYDRO_" + GetName()
91 #include <SALOME_NamingService.hxx>
92 #include <SALOME_LifeCycleCORBA.hxx>
96 #include "HYDRO_trace.hxx"
98 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
100 HYDROData_CalculationCase::HYDROData_CalculationCase()
101 : HYDROData_Entity( Geom_2d_and_groups )
105 HYDROData_CalculationCase::~HYDROData_CalculationCase()
109 void HYDROData_CalculationCase::SetName( const QString& theName )
111 QString anOldCaseName = GetName();
112 if ( anOldCaseName != theName )
114 // Update names of regions and its zones
115 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
117 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
119 HYDROData_SequenceOfObjects::Iterator anIter;
120 anIter.Init( aGroups );
121 for ( ; anIter.More(); anIter.Next() )
123 Handle(HYDROData_SplitShapesGroup) aGroup =
124 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
125 if ( aGroup.IsNull() )
128 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
132 HYDROData_Entity::SetName( theName );
135 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
136 MapOfTreatedObjects& theTreatedObjects ) const
138 QStringList aResList = dumpObjectCreation( theTreatedObjects );
139 aResList.prepend( "# Calculation case" );
141 QString aCalculName = GetObjPyName();
143 AssignmentMode aMode = GetAssignmentMode();
144 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
145 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
147 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
148 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
149 for ( ; anIter.More(); anIter.Next() )
151 Handle(HYDROData_Object) aRefGeomObj =
152 Handle(HYDROData_Object)::DownCast( anIter.Value() );
153 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
155 aResList << QString( "" );
157 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
159 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
160 anIter.Init( aGeomGroups );
161 for ( ; anIter.More(); anIter.Next() )
163 Handle(HYDROData_ShapesGroup) aGeomGroup =
164 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
165 if ( aGeomGroup.IsNull() )
168 Handle(HYDROData_Object) aFatherGeom =
169 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
170 if ( aFatherGeom.IsNull() )
173 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
174 aResList << QString( "%1 = %2.GetGroup( %3 )" )
175 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
177 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
180 HYDROData_SequenceOfObjects aBPolygons = GetBoundaryPolygons();
181 for (int i = 1; i <= aBPolygons.Size(); i++ )
183 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBPolygons(i) );
184 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBCPoly, "AddBoundaryPolygon" );
186 aResList << QString( "" );
188 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
189 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
191 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
192 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
194 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
195 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
197 if( aMode==AUTOMATIC )
198 DumpRulesToPython( aCalculName, aResList );
200 aResList << QString( "" );
201 aResList << "# Start the algorithm of the partition and assignment";
202 aResList << QString( "%1.Update()" ).arg( aCalculName );
206 // Now we restore the
207 // - regions and zones order
208 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
211 // Export calculation case
212 aResList << QString( "" );
213 aResList << "# Export of the calculation case";
214 QString aStudyName = "theStudy";
215 QString anEntryVar = aCalculName + "_entry";
216 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
218 // Get geometry object and print debug information
220 aResList << "# Get geometry shape and print debug information";
221 aResList << "import GEOM";
222 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
223 QString aGeomShapeName = aCalculName + "_geom";
224 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
225 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
226 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
229 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
231 aResList << QString( "" );
235 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
236 const QString& theStudyName,
237 const QString& theGeomShapeName,
238 const QString& theMeshName ) const
241 theResList << "# Meshing";
242 theResList << "import SMESH, SALOMEDS";
243 theResList << "from salome.smesh import smeshBuilder";
244 theResList << "from salome.geom import geomBuilder";
246 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
247 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
248 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
249 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
250 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
251 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
252 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
255 theResList << "# Set names of Mesh objects";
256 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
257 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
258 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
259 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
260 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
263 theResList << "# Greate SMESH groups";
264 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
265 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
266 theResList << QString( "for group in geom_groups:" );
267 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
269 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
270 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
273 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
275 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
277 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
278 if ( !aBoundaryPolyline.IsNull() )
279 aResSeq.Append( aBoundaryPolyline );
281 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
282 aResSeq.Append( aSeqOfGeomObjs );
285 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
286 aResSeq.Append( aSeqOfRegions );
291 static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
292 HYDROData_SequenceOfObjects aBoundaryPolygons,
293 HYDROData_SplitToZonesTool::SplitDataList& outEdgesList)
295 //perform boundary condition polygons on EdgesList
296 TopTools_SequenceOfShape IncTools, SelectionTools;
297 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
298 for (int i=1; i<=aBoundaryPolygons.Size();i++)
300 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
301 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
302 int bType = aBCPoly->GetBoundaryType();
304 IncTools.Append(aPolyTopShape);
306 SelectionTools.Append(aPolyTopShape);
309 while( anIter.hasNext() )
311 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
312 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
314 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
316 if (HYDROData_BoundaryPolygonTools::IncludeTool(IncTools, aSplitData.Shape) && HYDROData_BoundaryPolygonTools::SelectionTool(SelectionTools, aSplitData.Shape))
317 outEdgesList.append(aSplitData);
322 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
323 const HYDROData_SequenceOfObjects& aBoundaryPolygons,
324 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes)
326 //perform boundary condition polygons on EdgesList
327 TopTools_SequenceOfShape CutTools;
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();
336 CutTools.Append(aPolyTopShape);
339 while( anIter.hasNext() )
341 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
342 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
344 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
346 ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
349 HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes);
353 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
354 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
355 HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
357 HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList );
358 BRepTools_ReShape reshaper;
361 const HYDROData_SplitToZonesTool::SplitData& aSplitData = it.next();
362 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
365 TopoDS_Shape mS = aSplitData.Shape;
366 for (int i=1; i<=ObjToRes.Extent();i++)
368 TopoDS_Shape K = ObjToRes.FindKey(i);
369 TopoDS_Shape V = ObjToRes.FindFromIndex(i);
370 if (V.ShapeType() != TopAbs_EDGE && V.ShapeType() != TopAbs_WIRE && V.ShapeType() != TopAbs_COMPOUND)
372 if (V.ShapeType() == TopAbs_COMPOUND)
374 TopExp_Explorer exp(V, TopAbs_EDGE);
375 TopTools_ListOfShape lE;
376 for (;exp.More();exp.Next())
377 lE.Append(exp.Current());
378 if (lE.Extent() == 1)
380 else if (lE.Extent() > 1)
392 reshaper.Replace(K, V);
394 TopoDS_Shape nS = reshaper.Apply(mS);
395 HYDROData_SplitToZonesTool::SplitData aNS(aSplitData.Type, nS, aSplitData.ObjectNames);
396 outZoneList.append(aNS);
400 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
401 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
402 HYDROData_SplitToZonesTool::SplitDataList& newEdges)
404 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
405 while( anIter.hasNext() )
407 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
408 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
411 const TopoDS_Shape* aDivShape = ObjToRes.Seek(aSplitData.Shape);
414 TopExp_Explorer exp(*aDivShape, TopAbs_EDGE);
415 for (;exp.More();exp.Next())
417 HYDROData_SplitToZonesTool::SplitData anNewSData(aSplitData.Type, exp.Current(), aSplitData.ObjectNames);
418 newEdges.append(anNewSData);
422 newEdges.append(aSplitData);
427 void HYDROData_CalculationCase::Update()
429 HYDROData_Entity::Update();
432 // At first we remove previously created objects
436 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
437 if ( aDocument.IsNull() )
441 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
443 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
445 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
447 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
448 if ( !aGeomObjects.IsEmpty() ) {
449 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
451 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
452 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
453 if ( !aSplitObjects.isEmpty() ) {
454 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
455 while( anIter.hasNext() ) {
456 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
457 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
458 aZonesList.append( aSplitData );
459 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
460 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
461 anEdgesList.append( aSplitData );
467 //split edges by boundary polygons
468 HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
469 //edge to splitted edge (compound of edges or original edge)
470 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape> ObjToRes;
471 //split edge list by BP
472 SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes);
473 HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
474 //replace splitted edges in zone list (faces)
475 PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
477 //create new edges list based on splitting info from ObjToRes
478 HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
479 CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
480 //filter out edges list by include&selection tools
481 FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
483 switch( GetAssignmentMode() )
486 CreateRegionsDef( aDocument,aNewZonesList );
489 CreateRegionsAuto( aDocument,aNewZonesList );
493 CreateEdgeGroupsDef( aDocument, newEdgesList2 );
496 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
497 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
499 // Create result regions for case, by default one zone for one region
500 QString aRegsPref = CALCULATION_REGIONS_PREF;
501 QString aZonesPref = CALCULATION_ZONES_PREF;
503 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
504 while( anIter.hasNext() )
506 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
508 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
510 // Add the zone for region
511 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
515 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
516 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
518 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
519 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
520 QMap<QString, QString> aRegionNameToObjNameMap;
521 QString aZonesPref = CALCULATION_ZONES_PREF;
522 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
524 // 1. First we create a default region for each object included into the calculation case
525 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
526 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
528 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
531 QString anObjName = anObj->GetName();
532 QString aRegName = anObjName + "_reg";
533 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
534 aRegionsMap.insert( anObjName, aRegion );
535 aRegionNameToObjNameMap.insert( aRegName, anObjName );
538 // 2. Now for each zone it is necessary to determine the most priority object
539 // and assign to zone to corresponding region
540 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
541 while( anIter.hasNext() )
543 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
544 HYDROData_Zone::MergeType aMergeType;
545 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
546 if( aRegObj.IsNull() )
548 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
549 if( aRegion.IsNull() )
551 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
553 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
555 qDebug( "Error in algorithm: unresolved conflicts" );
558 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
559 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
560 if ( !aMergeObject.IsNull() ) {
561 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
562 aMergeEntity = aMergeObject->GetAltitudeObject();
567 case HYDROData_Zone::Merge_ZMIN:
568 case HYDROData_Zone::Merge_ZMAX:
569 aRegionZone->SetMergeType( aMergeType );
571 case HYDROData_Zone::Merge_Object:
572 aRegionZone->SetMergeType( aMergeType );
573 aRegionZone->RemoveMergeObject();
574 aRegionZone->SetMergeObject( aMergeEntity );
579 QStringList anObjectsWithEmptyRegions;
580 QMap<QString, Handle(HYDROData_Region)>::const_iterator
581 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
582 for( ; anIt!=aLast; anIt++ )
584 Handle(HYDROData_Region) aRegion = anIt.value();
585 if( aRegion->GetZones().IsEmpty() )
587 QString aRegName = aRegion->GetName();
588 QString anObjName = aRegionNameToObjNameMap[aRegName];
589 anObjectsWithEmptyRegions.append( anObjName );
593 if( !anObjectsWithEmptyRegions.empty() )
595 QString aData = anObjectsWithEmptyRegions.join( ", " );
596 SetWarning( WARN_EMPTY_REGIONS, aData );
600 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
601 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
603 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
605 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
606 while( anIter.hasNext() )
608 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
609 // Create new edges group
610 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
613 QString anObjName = aSplitData.ObjectNames.first();
614 if ( anObjName.isEmpty() )
616 #ifdef DEB_CALCULATION
617 QString aStr = aSplitData.ObjectNames.join(" ");
618 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
620 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
621 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
623 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
624 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
628 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
630 if ( aSplitGroup.IsNull() )
633 aSplitGroup->AddShape( aSplitData.Shape );
635 TopTools_SequenceOfShape theShapes;
636 aSplitGroup->GetShapes(theShapes);
638 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
639 aSplitGroup->SetInternal(true);
643 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
645 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
646 return false; // Wrong type of object
648 if ( HasReference( theObject, DataTag_GeometryObject ) )
649 return false; // Object is already in reference list
651 AddReferenceObject( theObject, DataTag_GeometryObject );
653 // Indicate model of the need to update splitting
659 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
661 return GetReferenceObjects( DataTag_GeometryObject );
664 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
666 if ( theObject.IsNull() )
669 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
671 // Indicate model of the need to update splitting
675 void HYDROData_CalculationCase::RemoveGeometryObjects()
677 ClearReferenceObjects( DataTag_GeometryObject );
679 // Indicate model of the need to update splitting
683 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
685 if ( theGroup.IsNull() )
688 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
689 return false; // Object is already in reference list
691 AddReferenceObject( theGroup, DataTag_GeometryGroup );
693 // Indicate model of the need to update splitting
694 Changed( Geom_Groups );
699 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
701 return GetReferenceObjects( DataTag_GeometryGroup );
704 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
706 if ( theGroup.IsNull() )
709 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
711 // Indicate model of the need to update splitting
712 Changed( Geom_Groups );
715 void HYDROData_CalculationCase::RemoveGeometryGroups()
717 ClearReferenceObjects( DataTag_GeometryGroup );
719 // Indicate model of the need to update splitting
720 Changed( Geom_Groups );
723 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
725 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
727 SetReferenceObject( thePolyline, DataTag_Polyline );
729 // Indicate model of the need to update zones splitting
730 if( !IsEqual( aPrevPolyline, thePolyline ) )
734 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
736 return Handle(HYDROData_PolylineXY)::DownCast(
737 GetReferenceObject( DataTag_Polyline ) );
740 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
742 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
744 ClearReferenceObjects( DataTag_Polyline );
746 // Indicate model of the need to update zones splitting
750 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
752 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
754 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
756 // Indicate model of the need to update land covers partition
757 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
761 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
763 return Handle(HYDROData_StricklerTable)::DownCast(
764 GetReferenceObject( DataTag_StricklerTable ) );
767 void HYDROData_CalculationCase::RemoveStricklerTable()
769 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
771 ClearReferenceObjects( DataTag_StricklerTable );
773 // Indicate model of the need to update land covers partition
777 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
779 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
780 GetReferenceObject( DataTag_LandCoverMap ) );
781 DEBTRACE("GetLandCoverMap " << aMap.IsNull());
785 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
787 SetReferenceObject( theMap, DataTag_LandCoverMap );
790 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
795 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
796 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
797 if ( aNewRegion.IsNull() )
800 aNewRegion->AddZone( theZone );
805 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
807 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
809 if ( theRegion.IsNull() )
812 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
814 if ( HasReference( theRegion, aDataTag ) )
815 return false; // Object is already in reference list
817 // Move the region from other calculation
818 Handle(HYDROData_CalculationCase) aFatherCalc =
819 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
820 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
822 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
823 theRegion->CopyTo( aNewRegion, true );
825 aFatherCalc->RemoveRegion( theRegion );
827 theRegion->SetLabel( aNewRegion->Label() );
831 AddReferenceObject( theRegion, aDataTag );
837 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
839 return GetReferenceObjects( DataTag_Region );
842 void HYDROData_CalculationCase::UpdateRegionsOrder()
844 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
845 if ( aDocument.IsNull() )
848 QString aRegsPref = CALCULATION_REGIONS_PREF;
849 std::map<int, Handle(HYDROData_Region)> IndToRegion; //index in the name of region to region itself
850 HYDROData_SequenceOfObjects aRegions = GetRegions();
851 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
854 for ( ; anIter.More(); anIter.Next() )
856 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() );
857 if ( aRegion.IsNull() )
860 if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref)
861 IndToRegion[aVal] = aRegion;
864 int nbR = aRegions.Length();
865 std::map<int, Handle(HYDROData_Region)>::iterator it = IndToRegion.begin();
866 for( int i = 1; it != IndToRegion.end(); ++it )
867 if (it->first <= nbR + 1)
869 QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i));
870 it->second->SetName(aNewName);
875 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
877 if ( theRegion.IsNull() )
880 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
881 RemoveReferenceObject( theRegion->Label(), aDataTag );
883 // Remove region from data model
884 Handle(HYDROData_CalculationCase) aFatherCalc =
885 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
886 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
890 void HYDROData_CalculationCase::RemoveRegions()
892 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
895 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
897 return GetReferenceObjects( DataTag_SplitGroups );
900 void HYDROData_CalculationCase::RemoveSplitGroups()
902 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
905 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
907 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
908 return GetAltitudeForPoint( thePoint, aZone );
911 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
912 const Handle(HYDROData_Region)& theRegion,
915 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
917 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
918 if ( !aZone.IsNull() )
920 DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
921 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
922 if ( IsEqual( aRefRegion, theRegion ) )
923 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
926 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
927 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
932 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
938 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
939 const Handle(HYDROData_Zone)& theZone,
942 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
943 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
944 if ( theZone.IsNull() )
946 DEBTRACE("Zone nulle");
950 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
951 DEBTRACE("aZoneMergeType " << aZoneMergeType);
952 if ( !theZone->IsMergingNeed() )
954 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
957 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
959 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
963 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
964 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
966 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
967 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
968 if ( !aMergeAltitude.IsNull() )
970 if ( aZoneInterpolator != NULL )
972 DEBTRACE("aZoneInterpolator != NULL");
973 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
974 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
978 DEBTRACE("aZoneInterpolator == NULL");
979 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
985 DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
986 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
987 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
988 for ( ; anIter.More(); anIter.Next() )
990 Handle(HYDROData_Object) aZoneObj =
991 Handle(HYDROData_Object)::DownCast( anIter.Value() );
992 if ( aZoneObj.IsNull() )
995 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
996 if ( anObjAltitude.IsNull() )
999 double aPointAltitude = 0.0;
1000 if ( aZoneInterpolator != NULL )
1002 DEBTRACE("aZoneInterpolator != NULL");
1003 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
1004 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1008 DEBTRACE("aZoneInterpolator == NULL");
1009 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
1012 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
1015 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
1017 aResAltitude = aPointAltitude;
1020 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
1022 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1023 aResAltitude > aPointAltitude )
1025 aResAltitude = aPointAltitude;
1028 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
1030 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1031 aResAltitude < aPointAltitude )
1033 aResAltitude = aPointAltitude;
1039 return aResAltitude;
1042 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1043 const NCollection_Sequence<gp_XY>& thePoints,
1044 const Handle(HYDROData_Region)& theRegion,
1045 int theMethod) const
1047 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
1048 NCollection_Sequence<double> aResSeq;
1050 Handle(Message_ProgressIndicator) aZIProgress = HYDROData_Tool::GetZIProgress();
1051 //DEBTRACE("aZIProgress=" << aZIProgress);
1052 if ( aZIProgress ) {
1053 aZIProgress->Reset();
1056 QFuture<void> aFuture = QtConcurrent::run([&]() {
1057 int aNbPoints = thePoints.Length();
1059 Message_ProgressSentry aPSentry(HYDROData_Tool::GetZIProgress(), "GetAltitudesForPoints", 0, aNbPoints, 1);
1060 for ( int i = 1, n = aNbPoints; i <= n && aPSentry.More(); ++i, aPSentry.Next() )
1062 const gp_XY& thePnt = thePoints.Value( i );
1064 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
1065 aResSeq.Append( anAltitude );
1069 while( aFuture.isRunning() ) {
1070 if ( aZIProgress ) {
1071 aZIProgress->Show( Standard_True );
1072 QThread::usleep(500);
1075 //DEBTRACE("aZIProgress=" << aZIProgress);
1077 aZIProgress->Show( Standard_True );
1082 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1083 const NCollection_Sequence<gp_XY>& thePoints,
1084 const Handle(HYDROData_Zone)& theZone,
1085 int theMethod) const
1087 NCollection_Sequence<double> aResSeq;
1089 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1091 const gp_XY& thePnt = thePoints.Value( i );
1093 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
1094 aResSeq.Append( anAltitude );
1100 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
1102 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
1103 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1108 aMap->FindByPoint( thePoint, aType );
1109 double aCoeff = aTable->Get( aType, 0.0 );
1113 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
1114 double DefValue, bool UseMax ) const
1116 DEBTRACE("GetStricklerCoefficientForPoints");
1117 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1118 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1119 std::vector<double> theCoeffs;
1120 DEBTRACE("aLCM.IsNull() " << aLCM.IsNull());
1121 DEBTRACE("aTable.IsNull() "<< aTable.IsNull());
1122 if( aLCM.IsNull() || aTable.IsNull() )
1125 Handle(Message_ProgressIndicator) aSIProgress = HYDROData_Tool::GetSIProgress();
1126 if ( aSIProgress ) {
1127 aSIProgress->Reset();
1130 QFuture<void> aFuture = QtConcurrent::run([&]() {
1131 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
1134 while( aFuture.isRunning() ) {
1135 if ( aSIProgress ) {
1136 aSIProgress->Show( Standard_True );
1137 QThread::usleep(500);
1144 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
1146 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1147 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1148 std::vector<int> types;
1149 if( aLCM.IsNull() || aTable.IsNull() )
1152 aLCM->ClassifyPoints(thePoints, aTable, types );
1156 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
1158 Handle(HYDROData_Region) aResRegion;
1160 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
1161 if ( !aZone.IsNull() )
1162 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1167 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
1169 Handle(HYDROData_Zone) aResZone;
1171 HYDROData_SequenceOfObjects aRegions = GetRegions();
1173 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1174 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1176 Handle(HYDROData_Region) aRegion =
1177 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1178 if ( aRegion.IsNull() )
1181 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1182 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1183 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1185 Handle(HYDROData_Zone) aRegZone =
1186 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1187 if ( aRegZone.IsNull() )
1190 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1191 if ( aPointRelation != POINT_OUT )
1192 aResZone = aRegZone; // We found the desired zone
1199 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1200 const gp_XY& thePoint,
1201 const Handle(HYDROData_Zone)& theZone ) const
1203 PointClassification aRes = POINT_OUT;
1204 if ( theZone.IsNull() )
1207 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1208 if ( aZoneFace.IsNull() )
1211 TopoDS_Compound aCmp;
1213 aBB.MakeCompound(aCmp);
1214 aBB.Add(aCmp, aZoneFace);
1215 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1216 BRepBuilderAPI_MakeVertex aMk(aPnt);
1217 aBB.Add(aCmp, aMk.Vertex());
1218 BRepTools::Write(aCmp, "FCL2d.brep");
1220 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1221 if (State == TopAbs_OUT)
1223 else if(State == TopAbs_IN)
1225 else if(State == TopAbs_ON)
1230 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1231 const QString& thePrefixOrName,
1234 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1235 int aTag = aNewLab.Tag();
1237 Handle(HYDROData_Region) aNewRegion =
1238 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1239 AddRegion( aNewRegion );
1241 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1242 aNewRegion->SetName( aRegionName, true );
1247 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1249 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1251 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1252 Handle(HYDROData_SplitShapesGroup)::DownCast(
1253 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1254 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1256 aNewGroup->SetName( theName );
1261 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1266 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1267 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1269 QString aGeomObjEntry, anErrorMsg;
1271 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg, statMess );
1272 return isOK ? aGeomObjEntry : QString();
1277 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1278 SALOMEDS::Study_ptr theStudy,
1279 QString& theGeomObjEntry,
1280 QString& theErrorMsg,
1281 QString& statMess) const
1284 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1286 // Get groups definitions
1287 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1289 TopTools_SequenceOfShape IntSh; //internal edges
1290 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1291 for ( ; anIter.More(); anIter.Next() )
1294 Handle(HYDROData_ShapesGroup) aGroup =
1295 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1296 if ( aGroup.IsNull() )
1299 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1301 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1302 aGroup->GetShapes( aGroupDef.Shapes );
1304 aSeqOfGroupsDefs.Append( aGroupDef );
1306 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1307 TopTools_SequenceOfShape dummy;
1308 if (!aSSGroup.IsNull())
1309 if (aSSGroup->GetInternal())
1311 aSSGroup->GetShapes(dummy);
1312 IntSh.Append(dummy);
1318 bool isAllNotSubmersible = true;
1319 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1320 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1321 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1322 for ( ; aRegionIter.More(); aRegionIter.Next() )
1324 Handle(HYDROData_Region) aRegion =
1325 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1326 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1329 if ( isAllNotSubmersible )
1330 isAllNotSubmersible = false;
1332 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1333 aShToNames.Add( aRegionShape, aRegion->GetName() );
1338 if ( aCaseRegions.IsEmpty() ) {
1339 theErrorMsg = QString("the list of regions is empty.");
1340 } else if ( isAllNotSubmersible ) {
1341 theErrorMsg = QString("there are no submersible regions.");
1343 aRes = Export( theGeomEngine, theStudy, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1346 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1348 QString aTelemacFileName = GetName() + ".telemac";
1349 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1351 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1356 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1357 SALOMEDS::Study_ptr theStudy,
1358 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1359 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1360 QString& theGeomObjEntry ) const
1363 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1364 aSewing.SetNonManifoldMode( Standard_False );
1365 #ifdef DEB_CALCULATION
1366 TCollection_AsciiString aNam("Sh_");
1369 TopTools_DataMapOfShapeListOfShape SH2M;
1370 for ( int i = 1; i <= aShToName.Extent(); i++ )
1372 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1373 if ( aShape.IsNull() )
1376 SH2M.Bind(aShape, TopTools_ListOfShape());
1377 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1378 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1380 aSewing.Add( aShape );
1383 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1385 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1386 for (; anExp.More(); anExp.Next() )
1388 aSewing.Add( anExp.Current() );
1389 LM.Append(anExp.Current());
1391 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1392 for (; anExp.More(); anExp.Next() )
1394 aSewing.Add( anExp.Current() );
1395 LM.Append(anExp.Current());
1401 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1403 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1405 for ( int i = 1; i <= aShToName.Extent(); i++ )
1407 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1408 const QString& Qstr = aShToName.FindFromIndex(i);
1409 const TopTools_ListOfShape& LM = SH2M(CurShape);
1410 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1412 const TopoDS_Shape& csh = it.Value();
1413 if (aSewing.IsModified(csh))
1414 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1416 aFacesToNameModif.Add(csh, Qstr);
1421 // If the sewed shape is empty - return false
1422 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1425 #ifdef DEB_CALCULATION
1426 BRepTools::Write(aSewedShape ,"Sew.brep");
1427 #endif // Publish the sewed shape
1428 QString aName = EXPORT_NAME;
1429 GEOM::GEOM_Object_ptr aMainShape =
1430 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1432 if ( aMainShape->_is_nil() )
1435 if ( theGroupsDefs.IsEmpty() )
1439 TopTools_IndexedMapOfShape aMapOfSubShapes;
1440 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1442 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1444 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1446 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1448 NCollection_Sequence<int> aGroupIndexes;
1449 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1451 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1452 #ifdef DEB_CALCULATION
1453 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1456 TopoDS_Shape aModifiedShape = aShape;
1457 if ( aSewing.IsModified( aShape ) )
1458 aModifiedShape = aSewing.Modified( aShape );
1459 else if ( aSewing.IsModifiedSubShape( aShape ) )
1460 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1462 #ifdef DEB_CALCULATION
1463 const TopLoc_Location& aL1 = aShape.Location();
1464 const TopLoc_Location& aL2 = aModifiedShape.Location();
1465 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1468 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1469 if ( anIndex > 0 ) {
1470 aGroupIndexes.Append( anIndex );
1472 #ifdef DEB_CALCULATION
1473 TCollection_AsciiString aNam("Lost_");
1474 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1475 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1477 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1478 if ( aModifiedShape.IsPartner( aS ) )
1480 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1481 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1482 BRepTools::Write(aS ,aName.ToCString());
1490 if ( !aGroupIndexes.IsEmpty() )
1491 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1494 if ( !aGroupsData.IsEmpty() )
1496 GEOM::GEOM_IGroupOperations_var aGroupOp =
1497 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1499 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1500 for ( ; aMapIt.More(); aMapIt.Next() )
1502 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1503 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1505 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1506 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1509 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1510 aGeomIndexes->length( aGroupIndexes.Length() );
1512 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1513 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1515 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1516 if ( aGroupOp->IsDone() )
1518 SALOMEDS::SObject_var aGroupSO =
1519 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1528 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1529 const bool theIsSetToUpdate )
1531 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1532 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1534 // Indicate model of the need to update splitting
1535 if ( theIsSetToUpdate ) {
1540 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1541 HYDROData_PriorityType thePriority,
1542 const Handle(HYDROData_Entity)& theObject2,
1543 HYDROData_Zone::MergeType theMergeType,
1544 HYDROData_CalculationCase::DataTag theDataTag )
1546 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1547 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1549 // Indicate model of the need to update splitting
1553 QString HYDROData_CalculationCase::DumpRules() const
1555 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1556 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1559 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1561 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1562 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1563 anAttr->SetID(TDataStd_Integer::GetID());
1564 // Indicate model of the need to update splitting
1568 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1570 Handle(TDataStd_Integer) aModeAttr;
1571 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1573 return ( AssignmentMode ) aModeAttr->Get();
1578 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1579 QStringList& theScript ) const
1581 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1582 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1585 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1587 return myLastWarning;
1590 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1592 myLastWarning.Type = theType;
1593 myLastWarning.Data = theData;
1596 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1597 const QString& theOldCaseName,
1598 const QString& theName )
1600 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1601 for ( ; anIter.More(); anIter.Next() )
1603 Handle(HYDROData_Region) aRegion =
1604 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1605 if ( aRegion.IsNull() )
1608 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1610 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1611 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1612 for ( ; anIter.More(); anIter.Next() )
1614 Handle(HYDROData_Zone) aRegZone =
1615 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1616 if ( aRegZone.IsNull() )
1619 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1624 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1625 const QString& thePyScriptPath,
1626 MapOfTreatedObjects& theTreatedObjects,
1627 const HYDROData_SequenceOfObjects& theRegions ) const
1629 HYDROData_SequenceOfObjects::Iterator anIter;
1630 anIter.Init(theRegions);
1631 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1633 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1634 if (aRegion.IsNull())
1636 QString defRegName = this->GetName();
1637 QString regSuffix = QString("_Reg_%1").arg(ireg);
1638 defRegName += regSuffix;
1639 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1640 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1641 theResList << aRegDump;
1643 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1645 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1646 if (aRegion.IsNull())
1648 QStringList aRegDump;
1649 aRegion->SetNameInDumpPython(aRegDump);
1650 theResList << aRegDump;
1654 bool HYDROData_CalculationCase::GetRule( int theIndex,
1655 Handle(HYDROData_Entity)& theObject1,
1656 HYDROData_PriorityType& thePriority,
1657 Handle(HYDROData_Entity)& theObject2,
1658 HYDROData_Zone::MergeType& theMergeType,
1659 HYDROData_CalculationCase::DataTag& theDataTag) const
1661 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1662 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1663 theObject1, thePriority, theObject2, theMergeType );
1666 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1668 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1670 if ( HasReference( theInterPolyline, aDataTag ) )
1673 AddReferenceObject( theInterPolyline, aDataTag );
1680 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1682 return GetReferenceObjects( DataTag_InterPoly );
1685 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1687 if ( theInterPolyline.IsNull() )
1690 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1695 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1697 HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1699 if ( HasReference( theBCPolygon, aDataTag ) )
1702 AddReferenceObject( theBCPolygon, aDataTag );
1709 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1711 return GetReferenceObjects( DataTag_BCPolygon );
1714 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1716 if ( theBCPolygon.IsNull() )
1719 RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );