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 //#define DEB_CALCULATION 1
74 #ifdef DEB_CALCULATION
75 #include <BRepTools.hxx>
76 #include <TopLoc_Location.hxx>
78 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
79 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
80 #define CALCULATION_GROUPS_PREF GetName() + "_"
81 //#define DEB_CLASS2D 1
83 #include <BRepBuilderAPI_MakeVertex.hxx>
86 #define EXPORT_NAME "HYDRO_" + GetName()
89 #include <SALOME_NamingService.hxx>
90 #include <SALOME_LifeCycleCORBA.hxx>
94 #include "HYDRO_trace.hxx"
96 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
98 HYDROData_CalculationCase::HYDROData_CalculationCase()
99 : HYDROData_Entity( Geom_2d_and_groups )
103 HYDROData_CalculationCase::~HYDROData_CalculationCase()
107 void HYDROData_CalculationCase::SetName( const QString& theName )
109 QString anOldCaseName = GetName();
110 if ( anOldCaseName != theName )
112 // Update names of regions and its zones
113 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
115 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
117 HYDROData_SequenceOfObjects::Iterator anIter;
118 anIter.Init( aGroups );
119 for ( ; anIter.More(); anIter.Next() )
121 Handle(HYDROData_SplitShapesGroup) aGroup =
122 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
123 if ( aGroup.IsNull() )
126 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
130 HYDROData_Entity::SetName( theName );
133 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
134 MapOfTreatedObjects& theTreatedObjects ) const
136 QStringList aResList = dumpObjectCreation( theTreatedObjects );
137 aResList.prepend( "# Calculation case" );
139 QString aCalculName = GetObjPyName();
141 AssignmentMode aMode = GetAssignmentMode();
142 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
143 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
145 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
146 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
147 for ( ; anIter.More(); anIter.Next() )
149 Handle(HYDROData_Object) aRefGeomObj =
150 Handle(HYDROData_Object)::DownCast( anIter.Value() );
151 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
153 aResList << QString( "" );
155 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
157 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
158 anIter.Init( aGeomGroups );
159 for ( ; anIter.More(); anIter.Next() )
161 Handle(HYDROData_ShapesGroup) aGeomGroup =
162 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
163 if ( aGeomGroup.IsNull() )
166 Handle(HYDROData_Object) aFatherGeom =
167 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
168 if ( aFatherGeom.IsNull() )
171 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
172 aResList << QString( "%1 = %2.GetGroup( %3 )" )
173 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
175 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
178 HYDROData_SequenceOfObjects aBPolygons = GetBoundaryPolygons();
179 for (int i = 1; i <= aBPolygons.Size(); i++ )
181 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBPolygons(i) );
182 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBCPoly, "AddBoundaryPolygon" );
184 aResList << QString( "" );
186 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
187 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
189 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
190 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
192 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
193 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
195 if( aMode==AUTOMATIC )
196 DumpRulesToPython( aCalculName, aResList );
198 aResList << QString( "" );
199 aResList << "# Start the algorithm of the partition and assignment";
200 aResList << QString( "%1.Update()" ).arg( aCalculName );
204 // Now we restore the
205 // - regions and zones order
206 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
209 // Export calculation case
210 aResList << QString( "" );
211 aResList << "# Export of the calculation case";
212 QString aStudyName = "theStudy";
213 QString anEntryVar = aCalculName + "_entry";
214 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
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, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
229 aResList << QString( "" );
233 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
234 const QString& theStudyName,
235 const QString& theGeomShapeName,
236 const QString& theMeshName ) const
239 theResList << "# Meshing";
240 theResList << "import SMESH, SALOMEDS";
241 theResList << "from salome.smesh import smeshBuilder";
242 theResList << "from salome.geom import geomBuilder";
244 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
245 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
246 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
247 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
248 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
249 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
250 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
253 theResList << "# Set names of Mesh objects";
254 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
255 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
256 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
257 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
258 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
261 theResList << "# Greate SMESH groups";
262 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
263 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
264 theResList << QString( "for group in geom_groups:" );
265 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
267 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
268 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
271 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
273 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
275 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
276 if ( !aBoundaryPolyline.IsNull() )
277 aResSeq.Append( aBoundaryPolyline );
279 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
280 aResSeq.Append( aSeqOfGeomObjs );
283 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
284 aResSeq.Append( aSeqOfRegions );
289 static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
290 HYDROData_SequenceOfObjects aBoundaryPolygons,
291 HYDROData_SplitToZonesTool::SplitDataList& outEdgesList)
293 //perform boundary condition polygons on EdgesList
294 TopTools_SequenceOfShape IncTools, SelectionTools;
295 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
296 for (int i=1; i<=aBoundaryPolygons.Size();i++)
298 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
299 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
300 int bType = aBCPoly->GetBoundaryType();
302 IncTools.Append(aPolyTopShape);
304 SelectionTools.Append(aPolyTopShape);
307 while( anIter.hasNext() )
309 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
310 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
312 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
314 if (HYDROData_BoundaryPolygonTools::IncludeTool(IncTools, aSplitData.Shape) && HYDROData_BoundaryPolygonTools::SelectionTool(SelectionTools, aSplitData.Shape))
315 outEdgesList.append(aSplitData);
320 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
321 const HYDROData_SequenceOfObjects& aBoundaryPolygons,
322 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes)
324 //perform boundary condition polygons on EdgesList
325 TopTools_SequenceOfShape CutTools;
327 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
328 for (int i=1; i<=aBoundaryPolygons.Size();i++)
330 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
331 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
332 int bType = aBCPoly->GetBoundaryType();
334 CutTools.Append(aPolyTopShape);
337 while( anIter.hasNext() )
339 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
340 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
342 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
344 ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
347 HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes);
351 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
352 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
353 HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
355 HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList );
356 BRepTools_ReShape reshaper;
359 const HYDROData_SplitToZonesTool::SplitData& aSplitData = it.next();
360 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
363 TopoDS_Shape mS = aSplitData.Shape;
364 for (int i=1; i<=ObjToRes.Extent();i++)
366 TopoDS_Shape K = ObjToRes.FindKey(i);
367 TopoDS_Shape V = ObjToRes.FindFromIndex(i);
368 if (V.ShapeType() != TopAbs_EDGE && V.ShapeType() != TopAbs_WIRE && V.ShapeType() != TopAbs_COMPOUND)
370 if (V.ShapeType() == TopAbs_COMPOUND)
372 TopExp_Explorer exp(V, TopAbs_EDGE);
373 TopTools_ListOfShape lE;
374 for (;exp.More();exp.Next())
375 lE.Append(exp.Current());
376 if (lE.Extent() == 1)
378 else if (lE.Extent() > 1)
390 reshaper.Replace(K, V);
392 TopoDS_Shape nS = reshaper.Apply(mS);
393 HYDROData_SplitToZonesTool::SplitData aNS(aSplitData.Type, nS, aSplitData.ObjectNames);
394 outZoneList.append(aNS);
398 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
399 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
400 HYDROData_SplitToZonesTool::SplitDataList& newEdges)
402 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
403 while( anIter.hasNext() )
405 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
406 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
409 const TopoDS_Shape* aDivShape = ObjToRes.Seek(aSplitData.Shape);
412 TopExp_Explorer exp(*aDivShape, TopAbs_EDGE);
413 for (;exp.More();exp.Next())
415 HYDROData_SplitToZonesTool::SplitData anNewSData(aSplitData.Type, exp.Current(), aSplitData.ObjectNames);
416 newEdges.append(anNewSData);
420 newEdges.append(aSplitData);
425 void HYDROData_CalculationCase::Update()
427 HYDROData_Entity::Update();
430 // At first we remove previously created objects
434 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
435 if ( aDocument.IsNull() )
439 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
441 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
443 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
445 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
446 if ( !aGeomObjects.IsEmpty() ) {
447 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
449 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
450 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
451 if ( !aSplitObjects.isEmpty() ) {
452 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
453 while( anIter.hasNext() ) {
454 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
455 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
456 aZonesList.append( aSplitData );
457 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
458 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
459 anEdgesList.append( aSplitData );
465 //split edges by boundary polygons
466 HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
467 //edge to splitted edge (compound of edges or original edge)
468 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape> ObjToRes;
469 //split edge list by BP
470 SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes);
471 HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
472 //replace splitted edges in zone list (faces)
473 PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
475 //create new edges list based on splitting info from ObjToRes
476 HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
477 CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
478 //filter out edges list by include&selection tools
479 FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
481 switch( GetAssignmentMode() )
484 CreateRegionsDef( aDocument,aNewZonesList );
487 CreateRegionsAuto( aDocument,aNewZonesList );
491 CreateEdgeGroupsDef( aDocument, newEdgesList2 );
494 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
495 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
497 // Create result regions for case, by default one zone for one region
498 QString aRegsPref = CALCULATION_REGIONS_PREF;
499 QString aZonesPref = CALCULATION_ZONES_PREF;
501 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
502 while( anIter.hasNext() )
504 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
506 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
508 // Add the zone for region
509 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
513 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
514 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
516 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
517 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
518 QMap<QString, QString> aRegionNameToObjNameMap;
519 QString aZonesPref = CALCULATION_ZONES_PREF;
520 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
522 // 1. First we create a default region for each object included into the calculation case
523 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
524 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
526 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
529 QString anObjName = anObj->GetName();
530 QString aRegName = anObjName + "_reg";
531 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
532 aRegionsMap.insert( anObjName, aRegion );
533 aRegionNameToObjNameMap.insert( aRegName, anObjName );
536 // 2. Now for each zone it is necessary to determine the most priority object
537 // and assign to zone to corresponding region
538 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
539 while( anIter.hasNext() )
541 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
542 HYDROData_Zone::MergeType aMergeType;
543 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
544 if( aRegObj.IsNull() )
546 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
547 if( aRegion.IsNull() )
549 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
551 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
553 qDebug( "Error in algorithm: unresolved conflicts" );
556 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
557 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
558 if ( !aMergeObject.IsNull() ) {
559 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
560 aMergeEntity = aMergeObject->GetAltitudeObject();
565 case HYDROData_Zone::Merge_ZMIN:
566 case HYDROData_Zone::Merge_ZMAX:
567 aRegionZone->SetMergeType( aMergeType );
569 case HYDROData_Zone::Merge_Object:
570 aRegionZone->SetMergeType( aMergeType );
571 aRegionZone->RemoveMergeObject();
572 aRegionZone->SetMergeObject( aMergeEntity );
577 QStringList anObjectsWithEmptyRegions;
578 QMap<QString, Handle(HYDROData_Region)>::const_iterator
579 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
580 for( ; anIt!=aLast; anIt++ )
582 Handle(HYDROData_Region) aRegion = anIt.value();
583 if( aRegion->GetZones().IsEmpty() )
585 QString aRegName = aRegion->GetName();
586 QString anObjName = aRegionNameToObjNameMap[aRegName];
587 anObjectsWithEmptyRegions.append( anObjName );
591 if( !anObjectsWithEmptyRegions.empty() )
593 QString aData = anObjectsWithEmptyRegions.join( ", " );
594 SetWarning( WARN_EMPTY_REGIONS, aData );
598 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
599 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
601 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
603 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
604 while( anIter.hasNext() )
606 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
607 // Create new edges group
608 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
611 QString anObjName = aSplitData.ObjectNames.first();
612 if ( anObjName.isEmpty() )
614 #ifdef DEB_CALCULATION
615 QString aStr = aSplitData.ObjectNames.join(" ");
616 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
618 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
619 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
621 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
622 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
626 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
628 if ( aSplitGroup.IsNull() )
631 aSplitGroup->AddShape( aSplitData.Shape );
633 TopTools_SequenceOfShape theShapes;
634 aSplitGroup->GetShapes(theShapes);
636 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
637 aSplitGroup->SetInternal(true);
641 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
643 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
644 return false; // Wrong type of object
646 if ( HasReference( theObject, DataTag_GeometryObject ) )
647 return false; // Object is already in reference list
649 AddReferenceObject( theObject, DataTag_GeometryObject );
651 // Indicate model of the need to update splitting
657 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
659 return GetReferenceObjects( DataTag_GeometryObject );
662 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
664 if ( theObject.IsNull() )
667 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
669 // Indicate model of the need to update splitting
673 void HYDROData_CalculationCase::RemoveGeometryObjects()
675 ClearReferenceObjects( DataTag_GeometryObject );
677 // Indicate model of the need to update splitting
681 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
683 if ( theGroup.IsNull() )
686 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
687 return false; // Object is already in reference list
689 AddReferenceObject( theGroup, DataTag_GeometryGroup );
691 // Indicate model of the need to update splitting
692 Changed( Geom_Groups );
697 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
699 return GetReferenceObjects( DataTag_GeometryGroup );
702 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
704 if ( theGroup.IsNull() )
707 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
709 // Indicate model of the need to update splitting
710 Changed( Geom_Groups );
713 void HYDROData_CalculationCase::RemoveGeometryGroups()
715 ClearReferenceObjects( DataTag_GeometryGroup );
717 // Indicate model of the need to update splitting
718 Changed( Geom_Groups );
721 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
723 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
725 SetReferenceObject( thePolyline, DataTag_Polyline );
727 // Indicate model of the need to update zones splitting
728 if( !IsEqual( aPrevPolyline, thePolyline ) )
732 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
734 return Handle(HYDROData_PolylineXY)::DownCast(
735 GetReferenceObject( DataTag_Polyline ) );
738 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
740 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
742 ClearReferenceObjects( DataTag_Polyline );
744 // Indicate model of the need to update zones splitting
748 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
750 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
752 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
754 // Indicate model of the need to update land covers partition
755 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
759 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
761 return Handle(HYDROData_StricklerTable)::DownCast(
762 GetReferenceObject( DataTag_StricklerTable ) );
765 void HYDROData_CalculationCase::RemoveStricklerTable()
767 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
769 ClearReferenceObjects( DataTag_StricklerTable );
771 // Indicate model of the need to update land covers partition
775 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
777 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
778 GetReferenceObject( DataTag_LandCoverMap ) );
779 DEBTRACE("GetLandCoverMap " << aMap.IsNull());
783 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
785 SetReferenceObject( theMap, DataTag_LandCoverMap );
788 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
793 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
794 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
795 if ( aNewRegion.IsNull() )
798 aNewRegion->AddZone( theZone );
803 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
805 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
807 if ( theRegion.IsNull() )
810 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
812 if ( HasReference( theRegion, aDataTag ) )
813 return false; // Object is already in reference list
815 // Move the region from other calculation
816 Handle(HYDROData_CalculationCase) aFatherCalc =
817 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
818 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
820 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
821 theRegion->CopyTo( aNewRegion, true );
823 aFatherCalc->RemoveRegion( theRegion );
825 theRegion->SetLabel( aNewRegion->Label() );
829 AddReferenceObject( theRegion, aDataTag );
835 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
837 return GetReferenceObjects( DataTag_Region );
840 void HYDROData_CalculationCase::UpdateRegionsOrder()
842 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
843 if ( aDocument.IsNull() )
846 QString aRegsPref = CALCULATION_REGIONS_PREF;
847 std::map<int, Handle(HYDROData_Region)> IndToRegion; //index in the name of region to region itself
848 HYDROData_SequenceOfObjects aRegions = GetRegions();
849 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
852 for ( ; anIter.More(); anIter.Next() )
854 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() );
855 if ( aRegion.IsNull() )
858 if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref)
859 IndToRegion[aVal] = aRegion;
862 int nbR = aRegions.Length();
863 std::map<int, Handle(HYDROData_Region)>::iterator it = IndToRegion.begin();
864 for( int i = 1; it != IndToRegion.end(); ++it )
865 if (it->first <= nbR + 1)
867 QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i));
868 it->second->SetName(aNewName);
873 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
875 if ( theRegion.IsNull() )
878 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
879 RemoveReferenceObject( theRegion->Label(), aDataTag );
881 // Remove region from data model
882 Handle(HYDROData_CalculationCase) aFatherCalc =
883 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
884 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
888 void HYDROData_CalculationCase::RemoveRegions()
890 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
893 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
895 return GetReferenceObjects( DataTag_SplitGroups );
898 void HYDROData_CalculationCase::RemoveSplitGroups()
900 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
903 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
905 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
906 return GetAltitudeForPoint( thePoint, aZone );
909 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
910 const Handle(HYDROData_Region)& theRegion,
913 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
915 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
916 if ( !aZone.IsNull() )
918 DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
919 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
920 if ( IsEqual( aRefRegion, theRegion ) )
921 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
924 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
925 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
930 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
936 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
937 const Handle(HYDROData_Zone)& theZone,
940 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
941 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
942 if ( theZone.IsNull() )
944 DEBTRACE("Zone nulle");
948 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
949 DEBTRACE("aZoneMergeType " << aZoneMergeType);
950 if ( !theZone->IsMergingNeed() )
952 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
955 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
957 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
961 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
962 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
964 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
965 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
966 if ( !aMergeAltitude.IsNull() )
968 if ( aZoneInterpolator != NULL )
970 DEBTRACE("aZoneInterpolator != NULL");
971 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
972 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
976 DEBTRACE("aZoneInterpolator == NULL");
977 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
983 DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
984 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
985 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
986 for ( ; anIter.More(); anIter.Next() )
988 Handle(HYDROData_Object) aZoneObj =
989 Handle(HYDROData_Object)::DownCast( anIter.Value() );
990 if ( aZoneObj.IsNull() )
993 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
994 if ( anObjAltitude.IsNull() )
997 double aPointAltitude = 0.0;
998 if ( aZoneInterpolator != NULL )
1000 DEBTRACE("aZoneInterpolator != NULL");
1001 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
1002 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1006 DEBTRACE("aZoneInterpolator == NULL");
1007 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
1010 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
1013 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
1015 aResAltitude = aPointAltitude;
1018 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
1020 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1021 aResAltitude > aPointAltitude )
1023 aResAltitude = aPointAltitude;
1026 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
1028 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1029 aResAltitude < aPointAltitude )
1031 aResAltitude = aPointAltitude;
1037 return aResAltitude;
1040 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1041 const NCollection_Sequence<gp_XY>& thePoints,
1042 const Handle(HYDROData_Region)& theRegion,
1043 int theMethod) const
1045 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
1046 NCollection_Sequence<double> aResSeq;
1048 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1050 const gp_XY& thePnt = thePoints.Value( i );
1052 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
1053 aResSeq.Append( anAltitude );
1059 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1060 const NCollection_Sequence<gp_XY>& thePoints,
1061 const Handle(HYDROData_Zone)& theZone,
1062 int theMethod) const
1064 NCollection_Sequence<double> aResSeq;
1066 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1068 const gp_XY& thePnt = thePoints.Value( i );
1070 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
1071 aResSeq.Append( anAltitude );
1077 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
1079 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
1080 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1085 aMap->FindByPoint( thePoint, aType );
1086 double aCoeff = aTable->Get( aType, 0.0 );
1090 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
1091 double DefValue, bool UseMax ) const
1093 DEBTRACE("GetStricklerCoefficientForPoints");
1094 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1095 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1096 std::vector<double> theCoeffs;
1097 DEBTRACE("aLCM.IsNull() " << aLCM.IsNull());
1098 DEBTRACE("aTable.IsNull() "<< aTable.IsNull());
1099 if( aLCM.IsNull() || aTable.IsNull() )
1102 Handle(Message_ProgressIndicator) aSIProgress = HYDROData_Tool::GetSIProgress();
1103 if ( aSIProgress ) {
1104 aSIProgress->Reset();
1107 QFuture<void> aFuture = QtConcurrent::run([&]() {
1108 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
1111 while( aFuture.isRunning() ) {
1112 if ( aSIProgress ) {
1113 aSIProgress->Show( Standard_True );
1114 QThread::usleep(500);
1121 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
1123 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1124 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1125 std::vector<int> types;
1126 if( aLCM.IsNull() || aTable.IsNull() )
1129 aLCM->ClassifyPoints(thePoints, aTable, types );
1133 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
1135 Handle(HYDROData_Region) aResRegion;
1137 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
1138 if ( !aZone.IsNull() )
1139 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1144 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
1146 Handle(HYDROData_Zone) aResZone;
1148 HYDROData_SequenceOfObjects aRegions = GetRegions();
1150 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1151 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1153 Handle(HYDROData_Region) aRegion =
1154 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1155 if ( aRegion.IsNull() )
1158 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1159 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1160 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1162 Handle(HYDROData_Zone) aRegZone =
1163 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1164 if ( aRegZone.IsNull() )
1167 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1168 if ( aPointRelation != POINT_OUT )
1169 aResZone = aRegZone; // We found the desired zone
1176 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1177 const gp_XY& thePoint,
1178 const Handle(HYDROData_Zone)& theZone ) const
1180 PointClassification aRes = POINT_OUT;
1181 if ( theZone.IsNull() )
1184 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1185 if ( aZoneFace.IsNull() )
1188 TopoDS_Compound aCmp;
1190 aBB.MakeCompound(aCmp);
1191 aBB.Add(aCmp, aZoneFace);
1192 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1193 BRepBuilderAPI_MakeVertex aMk(aPnt);
1194 aBB.Add(aCmp, aMk.Vertex());
1195 BRepTools::Write(aCmp, "FCL2d.brep");
1197 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1198 if (State == TopAbs_OUT)
1200 else if(State == TopAbs_IN)
1202 else if(State == TopAbs_ON)
1207 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1208 const QString& thePrefixOrName,
1211 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1212 int aTag = aNewLab.Tag();
1214 Handle(HYDROData_Region) aNewRegion =
1215 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1216 AddRegion( aNewRegion );
1218 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1219 aNewRegion->SetName( aRegionName, true );
1224 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1226 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1228 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1229 Handle(HYDROData_SplitShapesGroup)::DownCast(
1230 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1231 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1233 aNewGroup->SetName( theName );
1238 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1243 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1244 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1246 QString aGeomObjEntry, anErrorMsg;
1248 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg, statMess );
1249 return isOK ? aGeomObjEntry : QString();
1254 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1255 SALOMEDS::Study_ptr theStudy,
1256 QString& theGeomObjEntry,
1257 QString& theErrorMsg,
1258 QString& statMess) const
1261 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1263 // Get groups definitions
1264 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1266 TopTools_SequenceOfShape IntSh; //internal edges
1267 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1268 for ( ; anIter.More(); anIter.Next() )
1271 Handle(HYDROData_ShapesGroup) aGroup =
1272 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1273 if ( aGroup.IsNull() )
1276 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1278 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1279 aGroup->GetShapes( aGroupDef.Shapes );
1281 aSeqOfGroupsDefs.Append( aGroupDef );
1283 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1284 TopTools_SequenceOfShape dummy;
1285 if (!aSSGroup.IsNull())
1286 if (aSSGroup->GetInternal())
1288 aSSGroup->GetShapes(dummy);
1289 IntSh.Append(dummy);
1295 bool isAllNotSubmersible = true;
1296 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1297 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1298 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1299 for ( ; aRegionIter.More(); aRegionIter.Next() )
1301 Handle(HYDROData_Region) aRegion =
1302 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1303 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1306 if ( isAllNotSubmersible )
1307 isAllNotSubmersible = false;
1309 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1310 aShToNames.Add( aRegionShape, aRegion->GetName() );
1315 if ( aCaseRegions.IsEmpty() ) {
1316 theErrorMsg = QString("the list of regions is empty.");
1317 } else if ( isAllNotSubmersible ) {
1318 theErrorMsg = QString("there are no submersible regions.");
1320 aRes = Export( theGeomEngine, theStudy, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1323 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1325 QString aTelemacFileName = GetName() + ".telemac";
1326 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1328 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1333 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1334 SALOMEDS::Study_ptr theStudy,
1335 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1336 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1337 QString& theGeomObjEntry ) const
1340 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1341 aSewing.SetNonManifoldMode( Standard_False );
1342 #ifdef DEB_CALCULATION
1343 TCollection_AsciiString aNam("Sh_");
1346 TopTools_DataMapOfShapeListOfShape SH2M;
1347 for ( int i = 1; i <= aShToName.Extent(); i++ )
1349 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1350 if ( aShape.IsNull() )
1353 SH2M.Bind(aShape, TopTools_ListOfShape());
1354 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1355 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1357 aSewing.Add( aShape );
1360 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1362 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1363 for (; anExp.More(); anExp.Next() )
1365 aSewing.Add( anExp.Current() );
1366 LM.Append(anExp.Current());
1368 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1369 for (; anExp.More(); anExp.Next() )
1371 aSewing.Add( anExp.Current() );
1372 LM.Append(anExp.Current());
1378 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1380 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1382 for ( int i = 1; i <= aShToName.Extent(); i++ )
1384 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1385 const QString& Qstr = aShToName.FindFromIndex(i);
1386 const TopTools_ListOfShape& LM = SH2M(CurShape);
1387 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1389 const TopoDS_Shape& csh = it.Value();
1390 if (aSewing.IsModified(csh))
1391 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1393 aFacesToNameModif.Add(csh, Qstr);
1398 // If the sewed shape is empty - return false
1399 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1402 #ifdef DEB_CALCULATION
1403 BRepTools::Write(aSewedShape ,"Sew.brep");
1404 #endif // Publish the sewed shape
1405 QString aName = EXPORT_NAME;
1406 GEOM::GEOM_Object_ptr aMainShape =
1407 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1409 if ( aMainShape->_is_nil() )
1412 if ( theGroupsDefs.IsEmpty() )
1416 TopTools_IndexedMapOfShape aMapOfSubShapes;
1417 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1419 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1421 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1423 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1425 NCollection_Sequence<int> aGroupIndexes;
1426 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1428 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1429 #ifdef DEB_CALCULATION
1430 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1433 TopoDS_Shape aModifiedShape = aShape;
1434 if ( aSewing.IsModified( aShape ) )
1435 aModifiedShape = aSewing.Modified( aShape );
1436 else if ( aSewing.IsModifiedSubShape( aShape ) )
1437 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1439 #ifdef DEB_CALCULATION
1440 const TopLoc_Location& aL1 = aShape.Location();
1441 const TopLoc_Location& aL2 = aModifiedShape.Location();
1442 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1445 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1446 if ( anIndex > 0 ) {
1447 aGroupIndexes.Append( anIndex );
1449 #ifdef DEB_CALCULATION
1450 TCollection_AsciiString aNam("Lost_");
1451 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1452 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1454 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1455 if ( aModifiedShape.IsPartner( aS ) )
1457 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1458 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1459 BRepTools::Write(aS ,aName.ToCString());
1467 if ( !aGroupIndexes.IsEmpty() )
1468 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1471 if ( !aGroupsData.IsEmpty() )
1473 GEOM::GEOM_IGroupOperations_var aGroupOp =
1474 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1476 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1477 for ( ; aMapIt.More(); aMapIt.Next() )
1479 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1480 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1482 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1483 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1486 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1487 aGeomIndexes->length( aGroupIndexes.Length() );
1489 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1490 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1492 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1493 if ( aGroupOp->IsDone() )
1495 SALOMEDS::SObject_var aGroupSO =
1496 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1505 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1506 const bool theIsSetToUpdate )
1508 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1509 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1511 // Indicate model of the need to update splitting
1512 if ( theIsSetToUpdate ) {
1517 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1518 HYDROData_PriorityType thePriority,
1519 const Handle(HYDROData_Entity)& theObject2,
1520 HYDROData_Zone::MergeType theMergeType,
1521 HYDROData_CalculationCase::DataTag theDataTag )
1523 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1524 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1526 // Indicate model of the need to update splitting
1530 QString HYDROData_CalculationCase::DumpRules() const
1532 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1533 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1536 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1538 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1539 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1540 anAttr->SetID(TDataStd_Integer::GetID());
1541 // Indicate model of the need to update splitting
1545 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1547 Handle(TDataStd_Integer) aModeAttr;
1548 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1550 return ( AssignmentMode ) aModeAttr->Get();
1555 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1556 QStringList& theScript ) const
1558 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1559 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1562 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1564 return myLastWarning;
1567 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1569 myLastWarning.Type = theType;
1570 myLastWarning.Data = theData;
1573 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1574 const QString& theOldCaseName,
1575 const QString& theName )
1577 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1578 for ( ; anIter.More(); anIter.Next() )
1580 Handle(HYDROData_Region) aRegion =
1581 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1582 if ( aRegion.IsNull() )
1585 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1587 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1588 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1589 for ( ; anIter.More(); anIter.Next() )
1591 Handle(HYDROData_Zone) aRegZone =
1592 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1593 if ( aRegZone.IsNull() )
1596 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1601 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1602 const QString& thePyScriptPath,
1603 MapOfTreatedObjects& theTreatedObjects,
1604 const HYDROData_SequenceOfObjects& theRegions ) const
1606 HYDROData_SequenceOfObjects::Iterator anIter;
1607 anIter.Init(theRegions);
1608 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1610 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1611 if (aRegion.IsNull())
1613 QString defRegName = this->GetName();
1614 QString regSuffix = QString("_Reg_%1").arg(ireg);
1615 defRegName += regSuffix;
1616 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1617 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1618 theResList << aRegDump;
1620 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1622 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1623 if (aRegion.IsNull())
1625 QStringList aRegDump;
1626 aRegion->SetNameInDumpPython(aRegDump);
1627 theResList << aRegDump;
1631 bool HYDROData_CalculationCase::GetRule( int theIndex,
1632 Handle(HYDROData_Entity)& theObject1,
1633 HYDROData_PriorityType& thePriority,
1634 Handle(HYDROData_Entity)& theObject2,
1635 HYDROData_Zone::MergeType& theMergeType,
1636 HYDROData_CalculationCase::DataTag& theDataTag) const
1638 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1639 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1640 theObject1, thePriority, theObject2, theMergeType );
1643 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1645 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1647 if ( HasReference( theInterPolyline, aDataTag ) )
1650 AddReferenceObject( theInterPolyline, aDataTag );
1657 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1659 return GetReferenceObjects( DataTag_InterPoly );
1662 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1664 if ( theInterPolyline.IsNull() )
1667 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1672 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1674 HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1676 if ( HasReference( theBCPolygon, aDataTag ) )
1679 AddReferenceObject( theBCPolygon, aDataTag );
1686 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1688 return GetReferenceObjects( DataTag_BCPolygon );
1691 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1693 if ( theBCPolygon.IsNull() )
1696 RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );