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 )
52 #include <TopoDS_Shell.hxx>
53 #include <TopoDS_Edge.hxx>
55 #include <BRep_Builder.hxx>
56 #include <BRepBuilderAPI_Sewing.hxx>
57 #include <BRepTopAdaptor_FClass2d.hxx>
58 #include <BRepTools_ReShape.hxx>
59 #include <BRepLib_MakeWire.hxx>
61 #include <BRepTools.hxx>
64 #include <TopExp_Explorer.hxx>
66 #include <TopTools_ListOfShape.hxx>
67 #include <TopTools_ListIteratorOfListOfShape.hxx>
68 #include <TDataStd_Integer.hxx>
70 //#define DEB_CALCULATION 1
71 #ifdef DEB_CALCULATION
72 #include <BRepTools.hxx>
73 #include <TopLoc_Location.hxx>
75 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
76 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
77 #define CALCULATION_GROUPS_PREF GetName() + "_"
78 //#define DEB_CLASS2D 1
80 #include <BRepBuilderAPI_MakeVertex.hxx>
83 #define EXPORT_NAME "HYDRO_" + GetName()
86 #include <SALOME_NamingService.hxx>
87 #include <SALOME_LifeCycleCORBA.hxx>
91 #include "HYDRO_trace.hxx"
93 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
95 HYDROData_CalculationCase::HYDROData_CalculationCase()
96 : HYDROData_Entity( Geom_2d_and_groups )
100 HYDROData_CalculationCase::~HYDROData_CalculationCase()
104 void HYDROData_CalculationCase::SetName( const QString& theName )
106 QString anOldCaseName = GetName();
107 if ( anOldCaseName != theName )
109 // Update names of regions and its zones
110 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
112 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
114 HYDROData_SequenceOfObjects::Iterator anIter;
115 anIter.Init( aGroups );
116 for ( ; anIter.More(); anIter.Next() )
118 Handle(HYDROData_SplitShapesGroup) aGroup =
119 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
120 if ( aGroup.IsNull() )
123 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
127 HYDROData_Entity::SetName( theName );
130 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
131 MapOfTreatedObjects& theTreatedObjects ) const
133 QStringList aResList = dumpObjectCreation( theTreatedObjects );
134 aResList.prepend( "# Calculation case" );
136 QString aCalculName = GetObjPyName();
138 AssignmentMode aMode = GetAssignmentMode();
139 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
140 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
142 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
143 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
144 for ( ; anIter.More(); anIter.Next() )
146 Handle(HYDROData_Object) aRefGeomObj =
147 Handle(HYDROData_Object)::DownCast( anIter.Value() );
148 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
150 aResList << QString( "" );
152 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
154 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
155 anIter.Init( aGeomGroups );
156 for ( ; anIter.More(); anIter.Next() )
158 Handle(HYDROData_ShapesGroup) aGeomGroup =
159 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
160 if ( aGeomGroup.IsNull() )
163 Handle(HYDROData_Object) aFatherGeom =
164 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
165 if ( aFatherGeom.IsNull() )
168 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
169 aResList << QString( "%1 = %2.GetGroup( %3 )" )
170 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
172 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
175 HYDROData_SequenceOfObjects aBPolygons = GetBoundaryPolygons();
176 for (int i = 1; i <= aBPolygons.Size(); i++ )
178 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBPolygons(i) );
179 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBCPoly, "AddBoundaryPolygon" );
181 aResList << QString( "" );
183 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
184 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
186 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
187 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
189 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
190 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
192 if( aMode==AUTOMATIC )
193 DumpRulesToPython( aCalculName, aResList );
195 aResList << QString( "" );
196 aResList << "# Start the algorithm of the partition and assignment";
197 aResList << QString( "%1.Update()" ).arg( aCalculName );
201 // Now we restore the
202 // - regions and zones order
203 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
206 // Export calculation case
207 aResList << QString( "" );
208 aResList << "# Export of the calculation case";
209 QString aStudyName = "theStudy";
210 QString anEntryVar = aCalculName + "_entry";
211 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
213 // Get geometry object and print debug information
215 aResList << "# Get geometry shape and print debug information";
216 aResList << "import GEOM";
217 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
218 QString aGeomShapeName = aCalculName + "_geom";
219 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
220 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
221 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
224 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
226 aResList << QString( "" );
230 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
231 const QString& theStudyName,
232 const QString& theGeomShapeName,
233 const QString& theMeshName ) const
236 theResList << "# Meshing";
237 theResList << "import SMESH, SALOMEDS";
238 theResList << "from salome.smesh import smeshBuilder";
239 theResList << "from salome.geom import geomBuilder";
241 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
242 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
243 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
244 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
245 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
246 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
247 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
250 theResList << "# Set names of Mesh objects";
251 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
252 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
253 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
254 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
255 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
258 theResList << "# Greate SMESH groups";
259 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
260 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
261 theResList << QString( "for group in geom_groups:" );
262 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
264 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
265 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
268 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
270 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
272 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
273 if ( !aBoundaryPolyline.IsNull() )
274 aResSeq.Append( aBoundaryPolyline );
276 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
277 aResSeq.Append( aSeqOfGeomObjs );
280 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
281 aResSeq.Append( aSeqOfRegions );
286 static void FilterEdgesByIncludeSelectionBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
287 HYDROData_SequenceOfObjects aBoundaryPolygons,
288 HYDROData_SplitToZonesTool::SplitDataList& outEdgesList)
290 //perform boundary condition polygons on EdgesList
291 TopTools_SequenceOfShape IncTools, SelectionTools;
292 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
293 for (int i=1; i<=aBoundaryPolygons.Size();i++)
295 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
296 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
297 int bType = aBCPoly->GetBoundaryType();
299 IncTools.Append(aPolyTopShape);
301 SelectionTools.Append(aPolyTopShape);
304 while( anIter.hasNext() )
306 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
307 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
309 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
311 if (HYDROData_BoundaryPolygonTools::IncludeTool(IncTools, aSplitData.Shape) && HYDROData_BoundaryPolygonTools::SelectionTool(SelectionTools, aSplitData.Shape))
312 outEdgesList.append(aSplitData);
317 static void SplitEdgesByBoundaryPolygons( const HYDROData_SplitToZonesTool::SplitDataList& anEdgesList,
318 const HYDROData_SequenceOfObjects& aBoundaryPolygons,
319 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes)
321 //perform boundary condition polygons on EdgesList
322 TopTools_SequenceOfShape CutTools;
324 HYDROData_SplitToZonesTool::SplitDataListIterator anIter(anEdgesList);
325 for (int i=1; i<=aBoundaryPolygons.Size();i++)
327 Handle(HYDROData_BCPolygon) aBCPoly = Handle(HYDROData_BCPolygon)::DownCast( aBoundaryPolygons(i));
328 TopoDS_Shape aPolyTopShape = aBCPoly->GetTopShape();
329 int bType = aBCPoly->GetBoundaryType();
331 CutTools.Append(aPolyTopShape);
334 while( anIter.hasNext() )
336 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
337 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
339 if (aSplitData.Shape.ShapeType() != TopAbs_EDGE)
341 ObjToRes.Add(aSplitData.Shape, TopoDS_Shape());
344 HYDROData_BoundaryPolygonTools::CutTool(CutTools, ObjToRes);
348 static void PerformEdgeReplInZones(const HYDROData_SplitToZonesTool::SplitDataList& ZoneList,
349 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
350 HYDROData_SplitToZonesTool::SplitDataList& outZoneList)
352 HYDROData_SplitToZonesTool::SplitDataListIterator it( ZoneList );
353 BRepTools_ReShape reshaper;
356 const HYDROData_SplitToZonesTool::SplitData& aSplitData = it.next();
357 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
360 TopoDS_Shape mS = aSplitData.Shape;
361 for (int i=1; i<=ObjToRes.Extent();i++)
363 TopoDS_Shape K = ObjToRes.FindKey(i);
364 TopoDS_Shape V = ObjToRes.FindFromIndex(i);
365 if (V.ShapeType() != TopAbs_EDGE && V.ShapeType() != TopAbs_WIRE && V.ShapeType() != TopAbs_COMPOUND)
367 if (V.ShapeType() == TopAbs_COMPOUND)
369 TopExp_Explorer exp(V, TopAbs_EDGE);
370 TopTools_ListOfShape lE;
371 for (;exp.More();exp.Next())
372 lE.Append(exp.Current());
373 if (lE.Extent() == 1)
375 else if (lE.Extent() > 1)
387 reshaper.Replace(K, V);
389 TopoDS_Shape nS = reshaper.Apply(mS);
390 HYDROData_SplitToZonesTool::SplitData aNS(aSplitData.Type, nS, aSplitData.ObjectNames);
391 outZoneList.append(aNS);
395 static void CreateNewEdgeList( const HYDROData_SplitToZonesTool::SplitDataList& theEdges,
396 const NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape>& ObjToRes,
397 HYDROData_SplitToZonesTool::SplitDataList& newEdges)
399 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
400 while( anIter.hasNext() )
402 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
403 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
406 const TopoDS_Shape* aDivShape = ObjToRes.Seek(aSplitData.Shape);
409 TopExp_Explorer exp(*aDivShape, TopAbs_EDGE);
410 for (;exp.More();exp.Next())
412 HYDROData_SplitToZonesTool::SplitData anNewSData(aSplitData.Type, exp.Current(), aSplitData.ObjectNames);
413 newEdges.append(anNewSData);
417 newEdges.append(aSplitData);
422 void HYDROData_CalculationCase::Update()
424 HYDROData_Entity::Update();
427 // At first we remove previously created objects
431 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
432 if ( aDocument.IsNull() )
436 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
438 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
440 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
442 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
443 if ( !aGeomObjects.IsEmpty() ) {
444 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
446 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
447 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
448 if ( !aSplitObjects.isEmpty() ) {
449 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
450 while( anIter.hasNext() ) {
451 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
452 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
453 aZonesList.append( aSplitData );
454 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
455 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
456 anEdgesList.append( aSplitData );
462 //split edges by boundary polygons
463 HYDROData_SequenceOfObjects aBoundaryPolygons = GetBoundaryPolygons();
464 //edge to splitted edge (compound of edges or original edge)
465 NCollection_IndexedDataMap<TopoDS_Shape, TopoDS_Shape> ObjToRes;
466 //split edge list by BP
467 SplitEdgesByBoundaryPolygons(anEdgesList, aBoundaryPolygons, ObjToRes);
468 HYDROData_SplitToZonesTool::SplitDataList aNewZonesList;
469 //replace splitted edges in zone list (faces)
470 PerformEdgeReplInZones(aZonesList, ObjToRes, aNewZonesList);
472 //create new edges list based on splitting info from ObjToRes
473 HYDROData_SplitToZonesTool::SplitDataList newEdgesList1,newEdgesList2;
474 CreateNewEdgeList(anEdgesList, ObjToRes, newEdgesList1);
475 //filter out edges list by include&selection tools
476 FilterEdgesByIncludeSelectionBoundaryPolygons(newEdgesList1,aBoundaryPolygons,newEdgesList2);
478 switch( GetAssignmentMode() )
481 CreateRegionsDef( aDocument,aNewZonesList );
484 CreateRegionsAuto( aDocument,aNewZonesList );
488 CreateEdgeGroupsDef( aDocument, newEdgesList2 );
491 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
492 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
494 // Create result regions for case, by default one zone for one region
495 QString aRegsPref = CALCULATION_REGIONS_PREF;
496 QString aZonesPref = CALCULATION_ZONES_PREF;
498 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
499 while( anIter.hasNext() )
501 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
503 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
505 // Add the zone for region
506 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
510 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
511 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
513 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
514 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
515 QMap<QString, QString> aRegionNameToObjNameMap;
516 QString aZonesPref = CALCULATION_ZONES_PREF;
517 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
519 // 1. First we create a default region for each object included into the calculation case
520 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
521 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
523 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
526 QString anObjName = anObj->GetName();
527 QString aRegName = anObjName + "_reg";
528 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
529 aRegionsMap.insert( anObjName, aRegion );
530 aRegionNameToObjNameMap.insert( aRegName, anObjName );
533 // 2. Now for each zone it is necessary to determine the most priority object
534 // and assign to zone to corresponding region
535 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
536 while( anIter.hasNext() )
538 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
539 HYDROData_Zone::MergeType aMergeType;
540 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
541 if( aRegObj.IsNull() )
543 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
544 if( aRegion.IsNull() )
546 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
548 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
550 qDebug( "Error in algorithm: unresolved conflicts" );
553 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
554 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
555 if ( !aMergeObject.IsNull() ) {
556 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
557 aMergeEntity = aMergeObject->GetAltitudeObject();
562 case HYDROData_Zone::Merge_ZMIN:
563 case HYDROData_Zone::Merge_ZMAX:
564 aRegionZone->SetMergeType( aMergeType );
566 case HYDROData_Zone::Merge_Object:
567 aRegionZone->SetMergeType( aMergeType );
568 aRegionZone->RemoveMergeObject();
569 aRegionZone->SetMergeObject( aMergeEntity );
574 QStringList anObjectsWithEmptyRegions;
575 QMap<QString, Handle(HYDROData_Region)>::const_iterator
576 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
577 for( ; anIt!=aLast; anIt++ )
579 Handle(HYDROData_Region) aRegion = anIt.value();
580 if( aRegion->GetZones().IsEmpty() )
582 QString aRegName = aRegion->GetName();
583 QString anObjName = aRegionNameToObjNameMap[aRegName];
584 anObjectsWithEmptyRegions.append( anObjName );
588 if( !anObjectsWithEmptyRegions.empty() )
590 QString aData = anObjectsWithEmptyRegions.join( ", " );
591 SetWarning( WARN_EMPTY_REGIONS, aData );
595 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
596 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
598 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
600 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
601 while( anIter.hasNext() )
603 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
604 // Create new edges group
605 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
608 QString anObjName = aSplitData.ObjectNames.first();
609 if ( anObjName.isEmpty() )
611 #ifdef DEB_CALCULATION
612 QString aStr = aSplitData.ObjectNames.join(" ");
613 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
615 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
616 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
618 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
619 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
623 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
625 if ( aSplitGroup.IsNull() )
628 aSplitGroup->AddShape( aSplitData.Shape );
630 TopTools_SequenceOfShape theShapes;
631 aSplitGroup->GetShapes(theShapes);
633 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
634 aSplitGroup->SetInternal(true);
638 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
640 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
641 return false; // Wrong type of object
643 if ( HasReference( theObject, DataTag_GeometryObject ) )
644 return false; // Object is already in reference list
646 AddReferenceObject( theObject, DataTag_GeometryObject );
648 // Indicate model of the need to update splitting
654 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
656 return GetReferenceObjects( DataTag_GeometryObject );
659 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
661 if ( theObject.IsNull() )
664 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
666 // Indicate model of the need to update splitting
670 void HYDROData_CalculationCase::RemoveGeometryObjects()
672 ClearReferenceObjects( DataTag_GeometryObject );
674 // Indicate model of the need to update splitting
678 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
680 if ( theGroup.IsNull() )
683 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
684 return false; // Object is already in reference list
686 AddReferenceObject( theGroup, DataTag_GeometryGroup );
688 // Indicate model of the need to update splitting
689 Changed( Geom_Groups );
694 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
696 return GetReferenceObjects( DataTag_GeometryGroup );
699 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
701 if ( theGroup.IsNull() )
704 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
706 // Indicate model of the need to update splitting
707 Changed( Geom_Groups );
710 void HYDROData_CalculationCase::RemoveGeometryGroups()
712 ClearReferenceObjects( DataTag_GeometryGroup );
714 // Indicate model of the need to update splitting
715 Changed( Geom_Groups );
718 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
720 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
722 SetReferenceObject( thePolyline, DataTag_Polyline );
724 // Indicate model of the need to update zones splitting
725 if( !IsEqual( aPrevPolyline, thePolyline ) )
729 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
731 return Handle(HYDROData_PolylineXY)::DownCast(
732 GetReferenceObject( DataTag_Polyline ) );
735 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
737 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
739 ClearReferenceObjects( DataTag_Polyline );
741 // Indicate model of the need to update zones splitting
745 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
747 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
749 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
751 // Indicate model of the need to update land covers partition
752 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
756 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
758 return Handle(HYDROData_StricklerTable)::DownCast(
759 GetReferenceObject( DataTag_StricklerTable ) );
762 void HYDROData_CalculationCase::RemoveStricklerTable()
764 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
766 ClearReferenceObjects( DataTag_StricklerTable );
768 // Indicate model of the need to update land covers partition
772 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
774 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
775 GetReferenceObject( DataTag_LandCoverMap ) );
776 DEBTRACE("GetLandCoverMap " << aMap.IsNull());
780 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
782 SetReferenceObject( theMap, DataTag_LandCoverMap );
785 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
790 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
791 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
792 if ( aNewRegion.IsNull() )
795 aNewRegion->AddZone( theZone );
800 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
802 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
804 if ( theRegion.IsNull() )
807 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
809 if ( HasReference( theRegion, aDataTag ) )
810 return false; // Object is already in reference list
812 // Move the region from other calculation
813 Handle(HYDROData_CalculationCase) aFatherCalc =
814 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
815 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
817 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
818 theRegion->CopyTo( aNewRegion, true );
820 aFatherCalc->RemoveRegion( theRegion );
822 theRegion->SetLabel( aNewRegion->Label() );
826 AddReferenceObject( theRegion, aDataTag );
832 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
834 return GetReferenceObjects( DataTag_Region );
837 void HYDROData_CalculationCase::UpdateRegionsOrder()
839 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
840 if ( aDocument.IsNull() )
843 QString aRegsPref = CALCULATION_REGIONS_PREF;
844 std::map<int, Handle(HYDROData_Region)> IndToRegion; //index in the name of region to region itself
845 HYDROData_SequenceOfObjects aRegions = GetRegions();
846 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
849 for ( ; anIter.More(); anIter.Next() )
851 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() );
852 if ( aRegion.IsNull() )
855 if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref)
856 IndToRegion[aVal] = aRegion;
859 int nbR = aRegions.Length();
860 std::map<int, Handle(HYDROData_Region)>::iterator it = IndToRegion.begin();
861 for( int i = 1; it != IndToRegion.end(); ++it )
862 if (it->first <= nbR + 1)
864 QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i));
865 it->second->SetName(aNewName);
870 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
872 if ( theRegion.IsNull() )
875 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
876 RemoveReferenceObject( theRegion->Label(), aDataTag );
878 // Remove region from data model
879 Handle(HYDROData_CalculationCase) aFatherCalc =
880 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
881 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
885 void HYDROData_CalculationCase::RemoveRegions()
887 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
890 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
892 return GetReferenceObjects( DataTag_SplitGroups );
895 void HYDROData_CalculationCase::RemoveSplitGroups()
897 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
900 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
902 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
903 return GetAltitudeForPoint( thePoint, aZone );
906 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
907 const Handle(HYDROData_Region)& theRegion,
910 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
912 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
913 if ( !aZone.IsNull() )
915 DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
916 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
917 if ( IsEqual( aRefRegion, theRegion ) )
918 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
921 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
922 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
927 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
933 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
934 const Handle(HYDROData_Zone)& theZone,
937 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
938 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
939 if ( theZone.IsNull() )
941 DEBTRACE("Zone nulle");
945 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
946 DEBTRACE("aZoneMergeType " << aZoneMergeType);
947 if ( !theZone->IsMergingNeed() )
949 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
952 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
954 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
958 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
959 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
961 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
962 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
963 if ( !aMergeAltitude.IsNull() )
965 if ( aZoneInterpolator != NULL )
967 DEBTRACE("aZoneInterpolator != NULL");
968 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
969 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
973 DEBTRACE("aZoneInterpolator == NULL");
974 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
980 DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
981 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
982 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
983 for ( ; anIter.More(); anIter.Next() )
985 Handle(HYDROData_Object) aZoneObj =
986 Handle(HYDROData_Object)::DownCast( anIter.Value() );
987 if ( aZoneObj.IsNull() )
990 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
991 if ( anObjAltitude.IsNull() )
994 double aPointAltitude = 0.0;
995 if ( aZoneInterpolator != NULL )
997 DEBTRACE("aZoneInterpolator != NULL");
998 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
999 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
1003 DEBTRACE("aZoneInterpolator == NULL");
1004 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
1007 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
1010 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
1012 aResAltitude = aPointAltitude;
1015 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
1017 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1018 aResAltitude > aPointAltitude )
1020 aResAltitude = aPointAltitude;
1023 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
1025 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
1026 aResAltitude < aPointAltitude )
1028 aResAltitude = aPointAltitude;
1034 return aResAltitude;
1037 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1038 const NCollection_Sequence<gp_XY>& thePoints,
1039 const Handle(HYDROData_Region)& theRegion,
1040 int theMethod) const
1042 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
1043 NCollection_Sequence<double> aResSeq;
1045 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1047 const gp_XY& thePnt = thePoints.Value( i );
1049 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
1050 aResSeq.Append( anAltitude );
1056 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
1057 const NCollection_Sequence<gp_XY>& thePoints,
1058 const Handle(HYDROData_Zone)& theZone,
1059 int theMethod) const
1061 NCollection_Sequence<double> aResSeq;
1063 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
1065 const gp_XY& thePnt = thePoints.Value( i );
1067 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
1068 aResSeq.Append( anAltitude );
1074 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
1076 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
1077 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1082 aMap->FindByPoint( thePoint, aType );
1083 double aCoeff = aTable->Get( aType, 0.0 );
1087 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
1088 double DefValue, bool UseMax ) const
1090 DEBTRACE("GetStricklerCoefficientForPoints");
1091 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1092 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1093 std::vector<double> theCoeffs;
1094 DEBTRACE("aLCM.IsNull() " << aLCM.IsNull());
1095 DEBTRACE("aTable.IsNull() "<< aTable.IsNull());
1096 if( aLCM.IsNull() || aTable.IsNull() )
1099 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
1104 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
1106 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
1107 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
1108 std::vector<int> types;
1109 if( aLCM.IsNull() || aTable.IsNull() )
1112 aLCM->ClassifyPoints(thePoints, aTable, types );
1116 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
1118 Handle(HYDROData_Region) aResRegion;
1120 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
1121 if ( !aZone.IsNull() )
1122 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1127 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
1129 Handle(HYDROData_Zone) aResZone;
1131 HYDROData_SequenceOfObjects aRegions = GetRegions();
1133 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1134 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1136 Handle(HYDROData_Region) aRegion =
1137 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1138 if ( aRegion.IsNull() )
1141 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1142 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1143 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1145 Handle(HYDROData_Zone) aRegZone =
1146 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1147 if ( aRegZone.IsNull() )
1150 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1151 if ( aPointRelation != POINT_OUT )
1152 aResZone = aRegZone; // We found the desired zone
1159 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1160 const gp_XY& thePoint,
1161 const Handle(HYDROData_Zone)& theZone ) const
1163 PointClassification aRes = POINT_OUT;
1164 if ( theZone.IsNull() )
1167 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1168 if ( aZoneFace.IsNull() )
1171 TopoDS_Compound aCmp;
1173 aBB.MakeCompound(aCmp);
1174 aBB.Add(aCmp, aZoneFace);
1175 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1176 BRepBuilderAPI_MakeVertex aMk(aPnt);
1177 aBB.Add(aCmp, aMk.Vertex());
1178 BRepTools::Write(aCmp, "FCL2d.brep");
1180 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1181 if (State == TopAbs_OUT)
1183 else if(State == TopAbs_IN)
1185 else if(State == TopAbs_ON)
1190 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1191 const QString& thePrefixOrName,
1194 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1195 int aTag = aNewLab.Tag();
1197 Handle(HYDROData_Region) aNewRegion =
1198 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1199 AddRegion( aNewRegion );
1201 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1202 aNewRegion->SetName( aRegionName, true );
1207 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1209 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1211 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1212 Handle(HYDROData_SplitShapesGroup)::DownCast(
1213 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1214 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1216 aNewGroup->SetName( theName );
1221 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1226 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1227 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1229 QString aGeomObjEntry, anErrorMsg;
1231 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg, statMess );
1232 return isOK ? aGeomObjEntry : QString();
1237 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1238 SALOMEDS::Study_ptr theStudy,
1239 QString& theGeomObjEntry,
1240 QString& theErrorMsg,
1241 QString& statMess) const
1244 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1246 // Get groups definitions
1247 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1249 TopTools_SequenceOfShape IntSh; //internal edges
1250 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1251 for ( ; anIter.More(); anIter.Next() )
1254 Handle(HYDROData_ShapesGroup) aGroup =
1255 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1256 if ( aGroup.IsNull() )
1259 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1261 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1262 aGroup->GetShapes( aGroupDef.Shapes );
1264 aSeqOfGroupsDefs.Append( aGroupDef );
1266 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1267 TopTools_SequenceOfShape dummy;
1268 if (!aSSGroup.IsNull())
1269 if (aSSGroup->GetInternal())
1271 aSSGroup->GetShapes(dummy);
1272 IntSh.Append(dummy);
1278 bool isAllNotSubmersible = true;
1279 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1280 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1281 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1282 for ( ; aRegionIter.More(); aRegionIter.Next() )
1284 Handle(HYDROData_Region) aRegion =
1285 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1286 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1289 if ( isAllNotSubmersible )
1290 isAllNotSubmersible = false;
1292 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1293 aShToNames.Add( aRegionShape, aRegion->GetName() );
1298 if ( aCaseRegions.IsEmpty() ) {
1299 theErrorMsg = QString("the list of regions is empty.");
1300 } else if ( isAllNotSubmersible ) {
1301 theErrorMsg = QString("there are no submersible regions.");
1303 aRes = Export( theGeomEngine, theStudy, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1306 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1308 QString aTelemacFileName = GetName() + ".telemac";
1309 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1311 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1316 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1317 SALOMEDS::Study_ptr theStudy,
1318 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1319 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1320 QString& theGeomObjEntry ) const
1323 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1324 aSewing.SetNonManifoldMode( Standard_False );
1325 #ifdef DEB_CALCULATION
1326 TCollection_AsciiString aNam("Sh_");
1329 TopTools_DataMapOfShapeListOfShape SH2M;
1330 for ( int i = 1; i <= aShToName.Extent(); i++ )
1332 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1333 if ( aShape.IsNull() )
1336 SH2M.Bind(aShape, TopTools_ListOfShape());
1337 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1338 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1340 aSewing.Add( aShape );
1343 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1345 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1346 for (; anExp.More(); anExp.Next() )
1348 aSewing.Add( anExp.Current() );
1349 LM.Append(anExp.Current());
1351 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1352 for (; anExp.More(); anExp.Next() )
1354 aSewing.Add( anExp.Current() );
1355 LM.Append(anExp.Current());
1361 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1363 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1365 for ( int i = 1; i <= aShToName.Extent(); i++ )
1367 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1368 const QString& Qstr = aShToName.FindFromIndex(i);
1369 const TopTools_ListOfShape& LM = SH2M(CurShape);
1370 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1372 const TopoDS_Shape& csh = it.Value();
1373 if (aSewing.IsModified(csh))
1374 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1376 aFacesToNameModif.Add(csh, Qstr);
1381 // If the sewed shape is empty - return false
1382 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1385 #ifdef DEB_CALCULATION
1386 BRepTools::Write(aSewedShape ,"Sew.brep");
1387 #endif // Publish the sewed shape
1388 QString aName = EXPORT_NAME;
1389 GEOM::GEOM_Object_ptr aMainShape =
1390 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1392 if ( aMainShape->_is_nil() )
1395 if ( theGroupsDefs.IsEmpty() )
1399 TopTools_IndexedMapOfShape aMapOfSubShapes;
1400 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1402 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1404 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1406 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1408 NCollection_Sequence<int> aGroupIndexes;
1409 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1411 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1412 #ifdef DEB_CALCULATION
1413 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1416 TopoDS_Shape aModifiedShape = aShape;
1417 if ( aSewing.IsModified( aShape ) )
1418 aModifiedShape = aSewing.Modified( aShape );
1419 else if ( aSewing.IsModifiedSubShape( aShape ) )
1420 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1422 #ifdef DEB_CALCULATION
1423 const TopLoc_Location& aL1 = aShape.Location();
1424 const TopLoc_Location& aL2 = aModifiedShape.Location();
1425 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1428 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1429 if ( anIndex > 0 ) {
1430 aGroupIndexes.Append( anIndex );
1432 #ifdef DEB_CALCULATION
1433 TCollection_AsciiString aNam("Lost_");
1434 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1435 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1437 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1438 if ( aModifiedShape.IsPartner( aS ) )
1440 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1441 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1442 BRepTools::Write(aS ,aName.ToCString());
1450 if ( !aGroupIndexes.IsEmpty() )
1451 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1454 if ( !aGroupsData.IsEmpty() )
1456 GEOM::GEOM_IGroupOperations_var aGroupOp =
1457 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1459 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1460 for ( ; aMapIt.More(); aMapIt.Next() )
1462 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1463 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1465 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1466 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1469 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1470 aGeomIndexes->length( aGroupIndexes.Length() );
1472 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1473 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1475 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1476 if ( aGroupOp->IsDone() )
1478 SALOMEDS::SObject_var aGroupSO =
1479 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1488 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1489 const bool theIsSetToUpdate )
1491 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1492 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1494 // Indicate model of the need to update splitting
1495 if ( theIsSetToUpdate ) {
1500 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1501 HYDROData_PriorityType thePriority,
1502 const Handle(HYDROData_Entity)& theObject2,
1503 HYDROData_Zone::MergeType theMergeType,
1504 HYDROData_CalculationCase::DataTag theDataTag )
1506 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1507 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1509 // Indicate model of the need to update splitting
1513 QString HYDROData_CalculationCase::DumpRules() const
1515 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1516 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1519 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1521 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1522 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1523 anAttr->SetID(TDataStd_Integer::GetID());
1524 // Indicate model of the need to update splitting
1528 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1530 Handle(TDataStd_Integer) aModeAttr;
1531 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1533 return ( AssignmentMode ) aModeAttr->Get();
1538 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1539 QStringList& theScript ) const
1541 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1542 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1545 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1547 return myLastWarning;
1550 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1552 myLastWarning.Type = theType;
1553 myLastWarning.Data = theData;
1556 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1557 const QString& theOldCaseName,
1558 const QString& theName )
1560 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1561 for ( ; anIter.More(); anIter.Next() )
1563 Handle(HYDROData_Region) aRegion =
1564 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1565 if ( aRegion.IsNull() )
1568 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1570 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1571 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1572 for ( ; anIter.More(); anIter.Next() )
1574 Handle(HYDROData_Zone) aRegZone =
1575 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1576 if ( aRegZone.IsNull() )
1579 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1584 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1585 const QString& thePyScriptPath,
1586 MapOfTreatedObjects& theTreatedObjects,
1587 const HYDROData_SequenceOfObjects& theRegions ) const
1589 HYDROData_SequenceOfObjects::Iterator anIter;
1590 anIter.Init(theRegions);
1591 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1593 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1594 if (aRegion.IsNull())
1596 QString defRegName = this->GetName();
1597 QString regSuffix = QString("_Reg_%1").arg(ireg);
1598 defRegName += regSuffix;
1599 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1600 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1601 theResList << aRegDump;
1603 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1605 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1606 if (aRegion.IsNull())
1608 QStringList aRegDump;
1609 aRegion->SetNameInDumpPython(aRegDump);
1610 theResList << aRegDump;
1614 bool HYDROData_CalculationCase::GetRule( int theIndex,
1615 Handle(HYDROData_Entity)& theObject1,
1616 HYDROData_PriorityType& thePriority,
1617 Handle(HYDROData_Entity)& theObject2,
1618 HYDROData_Zone::MergeType& theMergeType,
1619 HYDROData_CalculationCase::DataTag& theDataTag) const
1621 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1622 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1623 theObject1, thePriority, theObject2, theMergeType );
1626 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1628 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1630 if ( HasReference( theInterPolyline, aDataTag ) )
1633 AddReferenceObject( theInterPolyline, aDataTag );
1640 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1642 return GetReferenceObjects( DataTag_InterPoly );
1645 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1647 if ( theInterPolyline.IsNull() )
1650 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );
1655 bool HYDROData_CalculationCase::AddBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1657 HYDROData_CalculationCase::DataTag aDataTag = DataTag_BCPolygon;
1659 if ( HasReference( theBCPolygon, aDataTag ) )
1662 AddReferenceObject( theBCPolygon, aDataTag );
1669 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetBoundaryPolygons() const
1671 return GetReferenceObjects( DataTag_BCPolygon );
1674 void HYDROData_CalculationCase::RemoveBoundaryPolygon( const Handle(HYDROData_BCPolygon)& theBCPolygon )
1676 if ( theBCPolygon.IsNull() )
1679 RemoveReferenceObject( theBCPolygon->Label(), DataTag_BCPolygon );