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"
35 #pragma warning ( disable: 4251 )
43 #pragma warning ( default: 4251 )
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Edge.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRepBuilderAPI_Sewing.hxx>
54 #include <BRepTopAdaptor_FClass2d.hxx>
56 #include <BRepTools.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <TopTools_ListOfShape.hxx>
62 #include <TopTools_ListIteratorOfListOfShape.hxx>
63 #include <TDataStd_Integer.hxx>
65 //#define DEB_CALCULATION 1
66 #ifdef DEB_CALCULATION
67 #include <BRepTools.hxx>
68 #include <TopLoc_Location.hxx>
70 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
71 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
72 #define CALCULATION_GROUPS_PREF GetName() + "_"
73 //#define DEB_CLASS2D 1
75 #include <BRepBuilderAPI_MakeVertex.hxx>
78 #define EXPORT_NAME "HYDRO_" + GetName()
81 #include <SALOME_NamingService.hxx>
82 #include <SALOME_LifeCycleCORBA.hxx>
86 #include "HYDRO_trace.hxx"
88 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
89 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
91 HYDROData_CalculationCase::HYDROData_CalculationCase()
92 : HYDROData_Entity( Geom_2d_and_groups )
96 HYDROData_CalculationCase::~HYDROData_CalculationCase()
100 void HYDROData_CalculationCase::SetName( const QString& theName )
102 QString anOldCaseName = GetName();
103 if ( anOldCaseName != theName )
105 // Update names of regions and its zones
106 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
108 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
110 HYDROData_SequenceOfObjects::Iterator anIter;
111 anIter.Init( aGroups );
112 for ( ; anIter.More(); anIter.Next() )
114 Handle(HYDROData_SplitShapesGroup) aGroup =
115 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
116 if ( aGroup.IsNull() )
119 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
123 HYDROData_Entity::SetName( theName );
126 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
127 MapOfTreatedObjects& theTreatedObjects ) const
129 QStringList aResList = dumpObjectCreation( theTreatedObjects );
130 aResList.prepend( "# Calculation case" );
132 QString aCalculName = GetObjPyName();
134 AssignmentMode aMode = GetAssignmentMode();
135 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
136 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
138 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
139 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
140 for ( ; anIter.More(); anIter.Next() )
142 Handle(HYDROData_Object) aRefGeomObj =
143 Handle(HYDROData_Object)::DownCast( anIter.Value() );
144 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
146 aResList << QString( "" );
148 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
150 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
151 anIter.Init( aGeomGroups );
152 for ( ; anIter.More(); anIter.Next() )
154 Handle(HYDROData_ShapesGroup) aGeomGroup =
155 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
156 if ( aGeomGroup.IsNull() )
159 Handle(HYDROData_Object) aFatherGeom =
160 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
161 if ( aFatherGeom.IsNull() )
164 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
165 aResList << QString( "%1 = %2.GetGroup( %3 )" )
166 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
168 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
171 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
172 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
174 if( aMode==AUTOMATIC )
175 DumpRulesToPython( aCalculName, aResList );
177 aResList << QString( "" );
178 aResList << "# Start the algorithm of the partition and assignment";
179 aResList << QString( "%1.Update()" ).arg( aCalculName );
183 // Now we restore the
184 // - regions and zones order
185 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
188 // Export calculation case
189 aResList << QString( "" );
190 aResList << "# Export of the calculation case";
191 QString aStudyName = "theStudy";
192 QString anEntryVar = aCalculName + "_entry";
193 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
195 // Get geometry object and print debug information
197 aResList << "# Get geometry shape and print debug information";
198 aResList << "import GEOM";
199 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
200 QString aGeomShapeName = aCalculName + "_geom";
201 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
202 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
203 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
206 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
208 aResList << QString( "" );
212 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
213 const QString& theStudyName,
214 const QString& theGeomShapeName,
215 const QString& theMeshName ) const
218 theResList << "# Meshing";
219 theResList << "import SMESH, SALOMEDS";
220 theResList << "from salome.smesh import smeshBuilder";
221 theResList << "from salome.geom import geomBuilder";
223 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
224 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
225 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
226 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
227 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
228 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
229 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
232 theResList << "# Set names of Mesh objects";
233 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
234 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
235 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
236 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
237 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
240 theResList << "# Greate SMESH groups";
241 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
242 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
243 theResList << QString( "for group in geom_groups:" );
244 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
246 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
247 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
250 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
252 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
254 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
255 if ( !aBoundaryPolyline.IsNull() )
256 aResSeq.Append( aBoundaryPolyline );
258 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
259 aResSeq.Append( aSeqOfGeomObjs );
262 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
263 aResSeq.Append( aSeqOfRegions );
268 void HYDROData_CalculationCase::Update()
270 HYDROData_Entity::Update();
273 // At first we remove previously created objects
277 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
278 if ( aDocument.IsNull() )
282 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
284 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
286 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
288 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
289 if ( !aGeomObjects.IsEmpty() ) {
290 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
292 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
293 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
294 if ( !aSplitObjects.isEmpty() ) {
295 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
296 while( anIter.hasNext() ) {
297 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
298 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
299 aZonesList.append( aSplitData );
300 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
301 anEdgesList.append( aSplitData );
306 switch( GetAssignmentMode() )
309 CreateRegionsDef( aDocument, aZonesList );
312 CreateRegionsAuto( aDocument, aZonesList );
316 CreateEdgeGroupsDef( aDocument, anEdgesList );
319 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
320 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
322 // Create result regions for case, by default one zone for one region
323 QString aRegsPref = CALCULATION_REGIONS_PREF;
324 QString aZonesPref = CALCULATION_ZONES_PREF;
326 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
327 while( anIter.hasNext() )
329 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
331 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
333 // Add the zone for region
334 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
338 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
339 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
341 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
342 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
343 QMap<QString, QString> aRegionNameToObjNameMap;
344 QString aZonesPref = CALCULATION_ZONES_PREF;
345 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
347 // 1. First we create a default region for each object included into the calculation case
348 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
349 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
351 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
354 QString anObjName = anObj->GetName();
355 QString aRegName = anObjName + "_reg";
356 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
357 aRegionsMap.insert( anObjName, aRegion );
358 aRegionNameToObjNameMap.insert( aRegName, anObjName );
361 // 2. Now for each zone it is necessary to determine the most priority object
362 // and assign to zone to corresponding region
363 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
364 while( anIter.hasNext() )
366 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
367 HYDROData_Zone::MergeType aMergeType;
368 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
369 if( aRegObj.IsNull() )
371 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
372 if( aRegion.IsNull() )
374 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
376 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
378 qDebug( "Error in algorithm: unresolved conflicts" );
381 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
382 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
383 if ( !aMergeObject.IsNull() ) {
384 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
385 aMergeEntity = aMergeObject->GetAltitudeObject();
390 case HYDROData_Zone::Merge_ZMIN:
391 case HYDROData_Zone::Merge_ZMAX:
392 aRegionZone->SetMergeType( aMergeType );
394 case HYDROData_Zone::Merge_Object:
395 aRegionZone->SetMergeType( aMergeType );
396 aRegionZone->RemoveMergeObject();
397 aRegionZone->SetMergeObject( aMergeEntity );
402 QStringList anObjectsWithEmptyRegions;
403 QMap<QString, Handle(HYDROData_Region)>::const_iterator
404 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
405 for( ; anIt!=aLast; anIt++ )
407 Handle(HYDROData_Region) aRegion = anIt.value();
408 if( aRegion->GetZones().IsEmpty() )
410 QString aRegName = aRegion->GetName();
411 QString anObjName = aRegionNameToObjNameMap[aRegName];
412 anObjectsWithEmptyRegions.append( anObjName );
416 if( !anObjectsWithEmptyRegions.empty() )
418 QString aData = anObjectsWithEmptyRegions.join( ", " );
419 SetWarning( WARN_EMPTY_REGIONS, aData );
423 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
424 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
426 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
428 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
429 while( anIter.hasNext() )
431 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
432 // Create new edges group
433 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
436 QString anObjName = aSplitData.ObjectNames.first();
437 if ( anObjName.isEmpty() )
439 #ifdef DEB_CALCULATION
440 QString aStr = aSplitData.ObjectNames.join(" ");
441 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
443 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
444 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
446 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
447 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
451 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
453 if ( aSplitGroup.IsNull() )
456 aSplitGroup->AddShape( aSplitData.Shape );
460 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
462 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
463 return false; // Wrong type of object
465 if ( HasReference( theObject, DataTag_GeometryObject ) )
466 return false; // Object is already in reference list
468 AddReferenceObject( theObject, DataTag_GeometryObject );
470 // Indicate model of the need to update splitting
476 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
478 return GetReferenceObjects( DataTag_GeometryObject );
481 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
483 if ( theObject.IsNull() )
486 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
488 // Indicate model of the need to update splitting
492 void HYDROData_CalculationCase::RemoveGeometryObjects()
494 ClearReferenceObjects( DataTag_GeometryObject );
496 // Indicate model of the need to update splitting
500 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
502 if ( theGroup.IsNull() )
505 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
506 return false; // Object is already in reference list
508 AddReferenceObject( theGroup, DataTag_GeometryGroup );
510 // Indicate model of the need to update splitting
511 Changed( Geom_Groups );
516 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
518 return GetReferenceObjects( DataTag_GeometryGroup );
521 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
523 if ( theGroup.IsNull() )
526 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
528 // Indicate model of the need to update splitting
529 Changed( Geom_Groups );
532 void HYDROData_CalculationCase::RemoveGeometryGroups()
534 ClearReferenceObjects( DataTag_GeometryGroup );
536 // Indicate model of the need to update splitting
537 Changed( Geom_Groups );
540 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
542 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
544 SetReferenceObject( thePolyline, DataTag_Polyline );
546 // Indicate model of the need to update zones splitting
547 if( !IsEqual( aPrevPolyline, thePolyline ) )
551 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
553 return Handle(HYDROData_PolylineXY)::DownCast(
554 GetReferenceObject( DataTag_Polyline ) );
557 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
559 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
561 ClearReferenceObjects( DataTag_Polyline );
563 // Indicate model of the need to update zones splitting
567 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
569 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
571 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
573 // Indicate model of the need to update land covers partition
574 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
578 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
580 return Handle(HYDROData_StricklerTable)::DownCast(
581 GetReferenceObject( DataTag_StricklerTable ) );
584 void HYDROData_CalculationCase::RemoveStricklerTable()
586 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
588 ClearReferenceObjects( DataTag_StricklerTable );
590 // Indicate model of the need to update land covers partition
594 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
596 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
597 GetReferenceObject( DataTag_LandCoverMap ) );
601 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
603 SetReferenceObject( theMap, DataTag_LandCoverMap );
606 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
611 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
612 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
613 if ( aNewRegion.IsNull() )
616 aNewRegion->AddZone( theZone );
621 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
623 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
625 if ( theRegion.IsNull() )
628 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
630 if ( HasReference( theRegion, aDataTag ) )
631 return false; // Object is already in reference list
633 // Move the region from other calculation
634 Handle(HYDROData_CalculationCase) aFatherCalc =
635 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
636 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
638 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
639 theRegion->CopyTo( aNewRegion, true );
641 aFatherCalc->RemoveRegion( theRegion );
643 theRegion->SetLabel( aNewRegion->Label() );
647 AddReferenceObject( theRegion, aDataTag );
653 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
655 return GetReferenceObjects( DataTag_Region );
658 void HYDROData_CalculationCase::UpdateRegionsOrder()
660 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
661 if ( aDocument.IsNull() )
664 HYDROData_SequenceOfObjects aRegions = GetRegions();
665 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
666 for ( ; anIter.More(); anIter.Next() )
668 Handle(HYDROData_Region) aRegion =
669 Handle(HYDROData_Region)::DownCast( anIter.Value() );
670 if ( aRegion.IsNull() )
673 aRegion->SetName( "" );
676 QString aRegsPref = CALCULATION_REGIONS_PREF;
678 anIter.Init( aRegions );
679 for ( ; anIter.More(); anIter.Next() )
681 Handle(HYDROData_Region) aRegion =
682 Handle(HYDROData_Region)::DownCast( anIter.Value() );
683 if ( aRegion.IsNull() )
686 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
687 aRegion->SetName( aRegionName );
691 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
693 if ( theRegion.IsNull() )
696 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
697 RemoveReferenceObject( theRegion->Label(), aDataTag );
699 // Remove region from data model
700 Handle(HYDROData_CalculationCase) aFatherCalc =
701 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
702 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
706 void HYDROData_CalculationCase::RemoveRegions()
708 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
711 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
713 return GetReferenceObjects( DataTag_SplitGroups );
716 void HYDROData_CalculationCase::RemoveSplitGroups()
718 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
721 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
723 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
724 return GetAltitudeForPoint( thePoint, aZone );
727 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
728 const Handle(HYDROData_Region)& theRegion,
731 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
733 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
734 if ( !aZone.IsNull() )
736 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
737 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
738 if ( IsEqual( aRefRegion, theRegion ) )
739 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
742 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
743 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
748 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
754 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
755 const Handle(HYDROData_Zone)& theZone,
758 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
759 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
760 if ( theZone.IsNull() )
762 DEBTRACE("Zone nulle");
766 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
767 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
768 if ( !theZone->IsMergingNeed() )
770 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
773 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
775 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
779 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
780 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
782 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
783 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
784 if ( !aMergeAltitude.IsNull() )
786 if ( aZoneInterpolator != NULL )
788 DEBTRACE("aZoneInterpolator != NULL");
789 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
790 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
794 DEBTRACE("aZoneInterpolator == NULL");
795 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
801 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
802 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
803 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
804 for ( ; anIter.More(); anIter.Next() )
806 Handle(HYDROData_Object) aZoneObj =
807 Handle(HYDROData_Object)::DownCast( anIter.Value() );
808 if ( aZoneObj.IsNull() )
811 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
812 if ( anObjAltitude.IsNull() )
815 double aPointAltitude = 0.0;
816 if ( aZoneInterpolator != NULL )
818 DEBTRACE("aZoneInterpolator != NULL");
819 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
820 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
824 //DEBTRACE("aZoneInterpolator == NULL");
825 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
828 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
831 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
833 aResAltitude = aPointAltitude;
836 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
838 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
839 aResAltitude > aPointAltitude )
841 aResAltitude = aPointAltitude;
844 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
846 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
847 aResAltitude < aPointAltitude )
849 aResAltitude = aPointAltitude;
858 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
859 const NCollection_Sequence<gp_XY>& thePoints,
860 const Handle(HYDROData_Region)& theRegion,
863 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
864 NCollection_Sequence<double> aResSeq;
866 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
868 const gp_XY& thePnt = thePoints.Value( i );
870 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
871 aResSeq.Append( anAltitude );
877 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
878 const NCollection_Sequence<gp_XY>& thePoints,
879 const Handle(HYDROData_Zone)& theZone,
882 NCollection_Sequence<double> aResSeq;
884 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
886 const gp_XY& thePnt = thePoints.Value( i );
888 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
889 aResSeq.Append( anAltitude );
895 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
897 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
898 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
903 aMap->FindByPoint( thePoint, aType );
904 double aCoeff = aTable->Get( aType, 0.0 );
908 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
909 double DefValue, bool UseMax ) const
911 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
912 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
913 std::vector<double> theCoeffs;
914 if( aLCM.IsNull() || aTable.IsNull() )
917 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
922 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
924 Handle(HYDROData_Region) aResRegion;
926 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
927 if ( !aZone.IsNull() )
928 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
933 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
935 Handle(HYDROData_Zone) aResZone;
937 HYDROData_SequenceOfObjects aRegions = GetRegions();
939 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
940 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
942 Handle(HYDROData_Region) aRegion =
943 Handle(HYDROData_Region)::DownCast( anIter.Value() );
944 if ( aRegion.IsNull() )
947 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
948 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
949 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
951 Handle(HYDROData_Zone) aRegZone =
952 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
953 if ( aRegZone.IsNull() )
956 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
957 if ( aPointRelation != POINT_OUT )
958 aResZone = aRegZone; // We found the desired zone
965 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
966 const gp_XY& thePoint,
967 const Handle(HYDROData_Zone)& theZone ) const
969 PointClassification aRes = POINT_OUT;
970 if ( theZone.IsNull() )
973 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
974 if ( aZoneFace.IsNull() )
977 TopoDS_Compound aCmp;
979 aBB.MakeCompound(aCmp);
980 aBB.Add(aCmp, aZoneFace);
981 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
982 BRepBuilderAPI_MakeVertex aMk(aPnt);
983 aBB.Add(aCmp, aMk.Vertex());
984 BRepTools::Write(aCmp, "FCL2d.brep");
986 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
987 if (State == TopAbs_OUT)
989 else if(State == TopAbs_IN)
991 else if(State == TopAbs_ON)
996 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
997 const QString& thePrefixOrName,
1000 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1001 int aTag = aNewLab.Tag();
1003 Handle(HYDROData_Region) aNewRegion =
1004 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1005 AddRegion( aNewRegion );
1007 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1008 aNewRegion->SetName( aRegionName, true );
1013 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1015 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1017 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1018 Handle(HYDROData_SplitShapesGroup)::DownCast(
1019 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1020 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1022 aNewGroup->SetName( theName );
1027 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1032 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1033 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1035 QString aGeomObjEntry, anErrorMsg;
1036 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1037 return isOK ? aGeomObjEntry : QString();
1042 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1043 SALOMEDS::Study_ptr theStudy,
1044 QString& theGeomObjEntry,
1045 QString& theErrorMsg ) const
1047 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1049 // Get groups definitions
1050 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1052 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1053 for ( ; anIter.More(); anIter.Next() )
1056 Handle(HYDROData_ShapesGroup) aGroup =
1057 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1058 if ( aGroup.IsNull() )
1061 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1063 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1064 aGroup->GetShapes( aGroupDef.Shapes );
1066 aSeqOfGroupsDefs.Append( aGroupDef );
1070 bool isAllNotSubmersible = true;
1071 TopTools_ListOfShape aFaces;
1072 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1073 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1074 for ( ; aRegionIter.More(); aRegionIter.Next() )
1076 Handle(HYDROData_Region) aRegion =
1077 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1078 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1081 if ( isAllNotSubmersible )
1082 isAllNotSubmersible = false;
1084 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1085 aFaces.Append( aRegionShape );
1090 if ( aCaseRegions.IsEmpty() ) {
1091 theErrorMsg = QString("the list of regions is empty.");
1092 } else if ( isAllNotSubmersible ) {
1093 theErrorMsg = QString("there are no submersible regions.");
1095 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1098 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1100 QString aTelemacFileName = GetName() + ".telemac";
1101 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable() );
1106 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1107 SALOMEDS::Study_ptr theStudy,
1108 const TopTools_ListOfShape& theFaces,
1109 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1110 QString& theGeomObjEntry ) const
1113 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1114 aSewing.SetNonManifoldMode( Standard_False );
1115 #ifdef DEB_CALCULATION
1116 TCollection_AsciiString aNam("Sh_");
1119 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1120 for ( ; aFaceIter.More(); aFaceIter.Next() )
1122 TopoDS_Shape aShape = aFaceIter.Value();
1123 if ( aShape.IsNull() )
1126 if ( aShape.ShapeType() == TopAbs_FACE )
1128 aSewing.Add( aShape );
1129 #ifdef DEB_CALCULATION
1130 TCollection_AsciiString aName = aNam + ++i + ".brep";
1131 BRepTools::Write(aShape ,aName.ToCString());
1136 #ifdef DEB_CALCULATION
1139 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1140 for (; anExp.More(); anExp.Next() ) {
1141 aSewing.Add( anExp.Current() );
1142 #ifdef DEB_CALCULATION
1144 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1145 BRepTools::Write(anExp.Current() ,aName.ToCString());
1152 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1154 // If the sewed shape is empty - return false
1155 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1158 #ifdef DEB_CALCULATION
1159 BRepTools::Write(aSewedShape ,"Sew.brep");
1161 // Publish the sewed shape
1162 QString aName = EXPORT_NAME;
1163 GEOM::GEOM_Object_ptr aMainShape =
1164 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1166 if ( aMainShape->_is_nil() )
1169 if ( theGroupsDefs.IsEmpty() )
1173 TopTools_IndexedMapOfShape aMapOfSubShapes;
1174 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1176 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1178 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1180 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1182 NCollection_Sequence<int> aGroupIndexes;
1183 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1185 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1186 #ifdef DEB_CALCULATION
1187 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1190 TopoDS_Shape aModifiedShape = aShape;
1191 if ( aSewing.IsModified( aShape ) )
1192 aModifiedShape = aSewing.Modified( aShape );
1193 else if ( aSewing.IsModifiedSubShape( aShape ) )
1194 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1196 #ifdef DEB_CALCULATION
1197 const TopLoc_Location& aL1 = aShape.Location();
1198 const TopLoc_Location& aL2 = aModifiedShape.Location();
1199 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1202 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1203 if ( anIndex > 0 ) {
1204 aGroupIndexes.Append( anIndex );
1206 #ifdef DEB_CALCULATION
1207 TCollection_AsciiString aNam("Lost_");
1208 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1209 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1211 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1212 if ( aModifiedShape.IsPartner( aS ) )
1214 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1215 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1216 BRepTools::Write(aS ,aName.ToCString());
1224 if ( !aGroupIndexes.IsEmpty() )
1225 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1228 if ( !aGroupsData.IsEmpty() )
1230 GEOM::GEOM_IGroupOperations_var aGroupOp =
1231 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1233 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1234 for ( ; aMapIt.More(); aMapIt.Next() )
1236 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1237 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1239 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1240 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1243 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1244 aGeomIndexes->length( aGroupIndexes.Length() );
1246 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1247 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1249 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1250 if ( aGroupOp->IsDone() )
1252 SALOMEDS::SObject_var aGroupSO =
1253 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1262 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1263 const bool theIsSetToUpdate )
1265 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1266 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1268 // Indicate model of the need to update splitting
1269 if ( theIsSetToUpdate ) {
1274 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1275 HYDROData_PriorityType thePriority,
1276 const Handle(HYDROData_Entity)& theObject2,
1277 HYDROData_Zone::MergeType theMergeType,
1278 HYDROData_CalculationCase::DataTag theDataTag )
1280 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1281 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1283 // Indicate model of the need to update splitting
1287 QString HYDROData_CalculationCase::DumpRules() const
1289 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1290 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1293 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1295 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1296 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1298 // Indicate model of the need to update splitting
1302 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1304 Handle(TDataStd_Integer) aModeAttr;
1305 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1307 return ( AssignmentMode ) aModeAttr->Get();
1312 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1313 QStringList& theScript ) const
1315 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1316 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1319 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1321 return myLastWarning;
1324 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1326 myLastWarning.Type = theType;
1327 myLastWarning.Data = theData;
1330 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1331 const QString& theOldCaseName,
1332 const QString& theName )
1334 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1335 for ( ; anIter.More(); anIter.Next() )
1337 Handle(HYDROData_Region) aRegion =
1338 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1339 if ( aRegion.IsNull() )
1342 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1344 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1345 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1346 for ( ; anIter.More(); anIter.Next() )
1348 Handle(HYDROData_Zone) aRegZone =
1349 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1350 if ( aRegZone.IsNull() )
1353 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1358 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1359 const QString& thePyScriptPath,
1360 MapOfTreatedObjects& theTreatedObjects,
1361 const HYDROData_SequenceOfObjects& theRegions ) const
1363 HYDROData_SequenceOfObjects::Iterator anIter;
1364 anIter.Init(theRegions);
1365 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1367 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1368 if (aRegion.IsNull())
1370 QString defRegName = this->GetName();
1371 QString regSuffix = QString("_Reg_%1").arg(ireg);
1372 defRegName += regSuffix;
1373 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1374 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1375 theResList << aRegDump;
1377 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1379 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1380 if (aRegion.IsNull())
1382 QStringList aRegDump;
1383 aRegion->SetNameInDumpPython(aRegDump);
1384 theResList << aRegDump;
1388 bool HYDROData_CalculationCase::GetRule( int theIndex,
1389 Handle(HYDROData_Entity)& theObject1,
1390 HYDROData_PriorityType& thePriority,
1391 Handle(HYDROData_Entity)& theObject2,
1392 HYDROData_Zone::MergeType& theMergeType,
1393 HYDROData_CalculationCase::DataTag& theDataTag) const
1395 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1396 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1397 theObject1, thePriority, theObject2, theMergeType );
1400 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1402 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1404 if ( HasReference( theInterPolyline, aDataTag ) )
1407 AddReferenceObject( theInterPolyline, aDataTag );
1412 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1414 return GetReferenceObjects( DataTag_InterPoly );
1417 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1419 if ( theInterPolyline.IsNull() )
1422 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );