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 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
175 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
177 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
178 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
180 if( aMode==AUTOMATIC )
181 DumpRulesToPython( aCalculName, aResList );
183 aResList << QString( "" );
184 aResList << "# Start the algorithm of the partition and assignment";
185 aResList << QString( "%1.Update()" ).arg( aCalculName );
189 // Now we restore the
190 // - regions and zones order
191 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
194 // Export calculation case
195 aResList << QString( "" );
196 aResList << "# Export of the calculation case";
197 QString aStudyName = "theStudy";
198 QString anEntryVar = aCalculName + "_entry";
199 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
201 // Get geometry object and print debug information
203 aResList << "# Get geometry shape and print debug information";
204 aResList << "import GEOM";
205 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
206 QString aGeomShapeName = aCalculName + "_geom";
207 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
208 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
209 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
212 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
214 aResList << QString( "" );
218 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
219 const QString& theStudyName,
220 const QString& theGeomShapeName,
221 const QString& theMeshName ) const
224 theResList << "# Meshing";
225 theResList << "import SMESH, SALOMEDS";
226 theResList << "from salome.smesh import smeshBuilder";
227 theResList << "from salome.geom import geomBuilder";
229 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
230 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
231 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
232 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
233 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
234 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
235 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
238 theResList << "# Set names of Mesh objects";
239 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
240 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
241 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
242 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
243 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
246 theResList << "# Greate SMESH groups";
247 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
248 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
249 theResList << QString( "for group in geom_groups:" );
250 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
252 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
253 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
256 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
258 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
260 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
261 if ( !aBoundaryPolyline.IsNull() )
262 aResSeq.Append( aBoundaryPolyline );
264 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
265 aResSeq.Append( aSeqOfGeomObjs );
268 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
269 aResSeq.Append( aSeqOfRegions );
274 void HYDROData_CalculationCase::Update()
276 HYDROData_Entity::Update();
279 // At first we remove previously created objects
283 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
284 if ( aDocument.IsNull() )
288 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
290 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
292 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
294 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
295 if ( !aGeomObjects.IsEmpty() ) {
296 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
298 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
299 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
300 if ( !aSplitObjects.isEmpty() ) {
301 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
302 while( anIter.hasNext() ) {
303 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
304 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
305 aZonesList.append( aSplitData );
306 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
307 anEdgesList.append( aSplitData );
312 switch( GetAssignmentMode() )
315 CreateRegionsDef( aDocument, aZonesList );
318 CreateRegionsAuto( aDocument, aZonesList );
322 CreateEdgeGroupsDef( aDocument, anEdgesList );
325 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
326 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
328 // Create result regions for case, by default one zone for one region
329 QString aRegsPref = CALCULATION_REGIONS_PREF;
330 QString aZonesPref = CALCULATION_ZONES_PREF;
332 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
333 while( anIter.hasNext() )
335 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
337 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
339 // Add the zone for region
340 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
344 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
345 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
347 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
348 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
349 QMap<QString, QString> aRegionNameToObjNameMap;
350 QString aZonesPref = CALCULATION_ZONES_PREF;
351 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
353 // 1. First we create a default region for each object included into the calculation case
354 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
355 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
357 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
360 QString anObjName = anObj->GetName();
361 QString aRegName = anObjName + "_reg";
362 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
363 aRegionsMap.insert( anObjName, aRegion );
364 aRegionNameToObjNameMap.insert( aRegName, anObjName );
367 // 2. Now for each zone it is necessary to determine the most priority object
368 // and assign to zone to corresponding region
369 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
370 while( anIter.hasNext() )
372 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
373 HYDROData_Zone::MergeType aMergeType;
374 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
375 if( aRegObj.IsNull() )
377 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
378 if( aRegion.IsNull() )
380 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
382 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
384 qDebug( "Error in algorithm: unresolved conflicts" );
387 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
388 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
389 if ( !aMergeObject.IsNull() ) {
390 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
391 aMergeEntity = aMergeObject->GetAltitudeObject();
396 case HYDROData_Zone::Merge_ZMIN:
397 case HYDROData_Zone::Merge_ZMAX:
398 aRegionZone->SetMergeType( aMergeType );
400 case HYDROData_Zone::Merge_Object:
401 aRegionZone->SetMergeType( aMergeType );
402 aRegionZone->RemoveMergeObject();
403 aRegionZone->SetMergeObject( aMergeEntity );
408 QStringList anObjectsWithEmptyRegions;
409 QMap<QString, Handle(HYDROData_Region)>::const_iterator
410 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
411 for( ; anIt!=aLast; anIt++ )
413 Handle(HYDROData_Region) aRegion = anIt.value();
414 if( aRegion->GetZones().IsEmpty() )
416 QString aRegName = aRegion->GetName();
417 QString anObjName = aRegionNameToObjNameMap[aRegName];
418 anObjectsWithEmptyRegions.append( anObjName );
422 if( !anObjectsWithEmptyRegions.empty() )
424 QString aData = anObjectsWithEmptyRegions.join( ", " );
425 SetWarning( WARN_EMPTY_REGIONS, aData );
429 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
430 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
432 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
434 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
435 while( anIter.hasNext() )
437 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
438 // Create new edges group
439 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
442 QString anObjName = aSplitData.ObjectNames.first();
443 if ( anObjName.isEmpty() )
445 #ifdef DEB_CALCULATION
446 QString aStr = aSplitData.ObjectNames.join(" ");
447 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
449 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
450 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
452 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
453 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
457 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
459 if ( aSplitGroup.IsNull() )
462 aSplitGroup->AddShape( aSplitData.Shape );
466 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
468 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
469 return false; // Wrong type of object
471 if ( HasReference( theObject, DataTag_GeometryObject ) )
472 return false; // Object is already in reference list
474 AddReferenceObject( theObject, DataTag_GeometryObject );
476 // Indicate model of the need to update splitting
482 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
484 return GetReferenceObjects( DataTag_GeometryObject );
487 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
489 if ( theObject.IsNull() )
492 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
494 // Indicate model of the need to update splitting
498 void HYDROData_CalculationCase::RemoveGeometryObjects()
500 ClearReferenceObjects( DataTag_GeometryObject );
502 // Indicate model of the need to update splitting
506 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
508 if ( theGroup.IsNull() )
511 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
512 return false; // Object is already in reference list
514 AddReferenceObject( theGroup, DataTag_GeometryGroup );
516 // Indicate model of the need to update splitting
517 Changed( Geom_Groups );
522 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
524 return GetReferenceObjects( DataTag_GeometryGroup );
527 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
529 if ( theGroup.IsNull() )
532 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
534 // Indicate model of the need to update splitting
535 Changed( Geom_Groups );
538 void HYDROData_CalculationCase::RemoveGeometryGroups()
540 ClearReferenceObjects( DataTag_GeometryGroup );
542 // Indicate model of the need to update splitting
543 Changed( Geom_Groups );
546 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
548 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
550 SetReferenceObject( thePolyline, DataTag_Polyline );
552 // Indicate model of the need to update zones splitting
553 if( !IsEqual( aPrevPolyline, thePolyline ) )
557 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
559 return Handle(HYDROData_PolylineXY)::DownCast(
560 GetReferenceObject( DataTag_Polyline ) );
563 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
565 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
567 ClearReferenceObjects( DataTag_Polyline );
569 // Indicate model of the need to update zones splitting
573 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
575 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
577 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
579 // Indicate model of the need to update land covers partition
580 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
584 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
586 return Handle(HYDROData_StricklerTable)::DownCast(
587 GetReferenceObject( DataTag_StricklerTable ) );
590 void HYDROData_CalculationCase::RemoveStricklerTable()
592 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
594 ClearReferenceObjects( DataTag_StricklerTable );
596 // Indicate model of the need to update land covers partition
600 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
602 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
603 GetReferenceObject( DataTag_LandCoverMap ) );
607 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
609 SetReferenceObject( theMap, DataTag_LandCoverMap );
612 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
617 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
618 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
619 if ( aNewRegion.IsNull() )
622 aNewRegion->AddZone( theZone );
627 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
629 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
631 if ( theRegion.IsNull() )
634 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
636 if ( HasReference( theRegion, aDataTag ) )
637 return false; // Object is already in reference list
639 // Move the region from other calculation
640 Handle(HYDROData_CalculationCase) aFatherCalc =
641 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
642 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
644 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
645 theRegion->CopyTo( aNewRegion, true );
647 aFatherCalc->RemoveRegion( theRegion );
649 theRegion->SetLabel( aNewRegion->Label() );
653 AddReferenceObject( theRegion, aDataTag );
659 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
661 return GetReferenceObjects( DataTag_Region );
664 void HYDROData_CalculationCase::UpdateRegionsOrder()
666 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
667 if ( aDocument.IsNull() )
670 HYDROData_SequenceOfObjects aRegions = GetRegions();
671 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
672 for ( ; anIter.More(); anIter.Next() )
674 Handle(HYDROData_Region) aRegion =
675 Handle(HYDROData_Region)::DownCast( anIter.Value() );
676 if ( aRegion.IsNull() )
679 aRegion->SetName( "" );
682 QString aRegsPref = CALCULATION_REGIONS_PREF;
684 anIter.Init( aRegions );
685 for ( ; anIter.More(); anIter.Next() )
687 Handle(HYDROData_Region) aRegion =
688 Handle(HYDROData_Region)::DownCast( anIter.Value() );
689 if ( aRegion.IsNull() )
692 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
693 aRegion->SetName( aRegionName );
697 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
699 if ( theRegion.IsNull() )
702 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
703 RemoveReferenceObject( theRegion->Label(), aDataTag );
705 // Remove region from data model
706 Handle(HYDROData_CalculationCase) aFatherCalc =
707 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
708 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
712 void HYDROData_CalculationCase::RemoveRegions()
714 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
717 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
719 return GetReferenceObjects( DataTag_SplitGroups );
722 void HYDROData_CalculationCase::RemoveSplitGroups()
724 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
727 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
729 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
730 return GetAltitudeForPoint( thePoint, aZone );
733 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
734 const Handle(HYDROData_Region)& theRegion,
737 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
739 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
740 if ( !aZone.IsNull() )
742 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
743 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
744 if ( IsEqual( aRefRegion, theRegion ) )
745 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
748 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
749 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
754 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
760 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
761 const Handle(HYDROData_Zone)& theZone,
764 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
765 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
766 if ( theZone.IsNull() )
768 DEBTRACE("Zone nulle");
772 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
773 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
774 if ( !theZone->IsMergingNeed() )
776 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
779 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
781 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
785 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
786 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
788 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
789 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
790 if ( !aMergeAltitude.IsNull() )
792 if ( aZoneInterpolator != NULL )
794 DEBTRACE("aZoneInterpolator != NULL");
795 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
796 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
800 DEBTRACE("aZoneInterpolator == NULL");
801 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
807 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
808 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
809 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
810 for ( ; anIter.More(); anIter.Next() )
812 Handle(HYDROData_Object) aZoneObj =
813 Handle(HYDROData_Object)::DownCast( anIter.Value() );
814 if ( aZoneObj.IsNull() )
817 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
818 if ( anObjAltitude.IsNull() )
821 double aPointAltitude = 0.0;
822 if ( aZoneInterpolator != NULL )
824 DEBTRACE("aZoneInterpolator != NULL");
825 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
826 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
830 //DEBTRACE("aZoneInterpolator == NULL");
831 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
834 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
837 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
839 aResAltitude = aPointAltitude;
842 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
844 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
845 aResAltitude > aPointAltitude )
847 aResAltitude = aPointAltitude;
850 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
852 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
853 aResAltitude < aPointAltitude )
855 aResAltitude = aPointAltitude;
864 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
865 const NCollection_Sequence<gp_XY>& thePoints,
866 const Handle(HYDROData_Region)& theRegion,
869 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
870 NCollection_Sequence<double> aResSeq;
872 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
874 const gp_XY& thePnt = thePoints.Value( i );
876 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
877 aResSeq.Append( anAltitude );
883 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
884 const NCollection_Sequence<gp_XY>& thePoints,
885 const Handle(HYDROData_Zone)& theZone,
888 NCollection_Sequence<double> aResSeq;
890 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
892 const gp_XY& thePnt = thePoints.Value( i );
894 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
895 aResSeq.Append( anAltitude );
901 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
903 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
904 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
909 aMap->FindByPoint( thePoint, aType );
910 double aCoeff = aTable->Get( aType, 0.0 );
914 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
915 double DefValue, bool UseMax ) const
917 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
918 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
919 std::vector<double> theCoeffs;
920 if( aLCM.IsNull() || aTable.IsNull() )
923 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
928 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
930 Handle(HYDROData_Region) aResRegion;
932 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
933 if ( !aZone.IsNull() )
934 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
939 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
941 Handle(HYDROData_Zone) aResZone;
943 HYDROData_SequenceOfObjects aRegions = GetRegions();
945 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
946 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
948 Handle(HYDROData_Region) aRegion =
949 Handle(HYDROData_Region)::DownCast( anIter.Value() );
950 if ( aRegion.IsNull() )
953 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
954 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
955 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
957 Handle(HYDROData_Zone) aRegZone =
958 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
959 if ( aRegZone.IsNull() )
962 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
963 if ( aPointRelation != POINT_OUT )
964 aResZone = aRegZone; // We found the desired zone
971 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
972 const gp_XY& thePoint,
973 const Handle(HYDROData_Zone)& theZone ) const
975 PointClassification aRes = POINT_OUT;
976 if ( theZone.IsNull() )
979 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
980 if ( aZoneFace.IsNull() )
983 TopoDS_Compound aCmp;
985 aBB.MakeCompound(aCmp);
986 aBB.Add(aCmp, aZoneFace);
987 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
988 BRepBuilderAPI_MakeVertex aMk(aPnt);
989 aBB.Add(aCmp, aMk.Vertex());
990 BRepTools::Write(aCmp, "FCL2d.brep");
992 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
993 if (State == TopAbs_OUT)
995 else if(State == TopAbs_IN)
997 else if(State == TopAbs_ON)
1002 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1003 const QString& thePrefixOrName,
1006 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1007 int aTag = aNewLab.Tag();
1009 Handle(HYDROData_Region) aNewRegion =
1010 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1011 AddRegion( aNewRegion );
1013 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1014 aNewRegion->SetName( aRegionName, true );
1019 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1021 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1023 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1024 Handle(HYDROData_SplitShapesGroup)::DownCast(
1025 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1026 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1028 aNewGroup->SetName( theName );
1033 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1038 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1039 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1041 QString aGeomObjEntry, anErrorMsg;
1042 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1043 return isOK ? aGeomObjEntry : QString();
1048 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1049 SALOMEDS::Study_ptr theStudy,
1050 QString& theGeomObjEntry,
1051 QString& theErrorMsg ) const
1053 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1055 // Get groups definitions
1056 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1058 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1059 for ( ; anIter.More(); anIter.Next() )
1062 Handle(HYDROData_ShapesGroup) aGroup =
1063 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1064 if ( aGroup.IsNull() )
1067 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1069 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1070 aGroup->GetShapes( aGroupDef.Shapes );
1072 aSeqOfGroupsDefs.Append( aGroupDef );
1076 bool isAllNotSubmersible = true;
1077 TopTools_ListOfShape aFaces;
1078 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1079 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1080 for ( ; aRegionIter.More(); aRegionIter.Next() )
1082 Handle(HYDROData_Region) aRegion =
1083 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1084 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1087 if ( isAllNotSubmersible )
1088 isAllNotSubmersible = false;
1090 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1091 aFaces.Append( aRegionShape );
1096 if ( aCaseRegions.IsEmpty() ) {
1097 theErrorMsg = QString("the list of regions is empty.");
1098 } else if ( isAllNotSubmersible ) {
1099 theErrorMsg = QString("there are no submersible regions.");
1101 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1104 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1106 QString aTelemacFileName = GetName() + ".telemac";
1107 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable() );
1112 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1113 SALOMEDS::Study_ptr theStudy,
1114 const TopTools_ListOfShape& theFaces,
1115 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1116 QString& theGeomObjEntry ) const
1119 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1120 aSewing.SetNonManifoldMode( Standard_False );
1121 #ifdef DEB_CALCULATION
1122 TCollection_AsciiString aNam("Sh_");
1125 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1126 for ( ; aFaceIter.More(); aFaceIter.Next() )
1128 TopoDS_Shape aShape = aFaceIter.Value();
1129 if ( aShape.IsNull() )
1132 if ( aShape.ShapeType() == TopAbs_FACE )
1134 aSewing.Add( aShape );
1135 #ifdef DEB_CALCULATION
1136 TCollection_AsciiString aName = aNam + ++i + ".brep";
1137 BRepTools::Write(aShape ,aName.ToCString());
1142 #ifdef DEB_CALCULATION
1145 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1146 for (; anExp.More(); anExp.Next() ) {
1147 aSewing.Add( anExp.Current() );
1148 #ifdef DEB_CALCULATION
1150 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1151 BRepTools::Write(anExp.Current() ,aName.ToCString());
1158 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1160 // If the sewed shape is empty - return false
1161 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1164 #ifdef DEB_CALCULATION
1165 BRepTools::Write(aSewedShape ,"Sew.brep");
1167 // Publish the sewed shape
1168 QString aName = EXPORT_NAME;
1169 GEOM::GEOM_Object_ptr aMainShape =
1170 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1172 if ( aMainShape->_is_nil() )
1175 if ( theGroupsDefs.IsEmpty() )
1179 TopTools_IndexedMapOfShape aMapOfSubShapes;
1180 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1182 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1184 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1186 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1188 NCollection_Sequence<int> aGroupIndexes;
1189 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1191 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1192 #ifdef DEB_CALCULATION
1193 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1196 TopoDS_Shape aModifiedShape = aShape;
1197 if ( aSewing.IsModified( aShape ) )
1198 aModifiedShape = aSewing.Modified( aShape );
1199 else if ( aSewing.IsModifiedSubShape( aShape ) )
1200 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1202 #ifdef DEB_CALCULATION
1203 const TopLoc_Location& aL1 = aShape.Location();
1204 const TopLoc_Location& aL2 = aModifiedShape.Location();
1205 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1208 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1209 if ( anIndex > 0 ) {
1210 aGroupIndexes.Append( anIndex );
1212 #ifdef DEB_CALCULATION
1213 TCollection_AsciiString aNam("Lost_");
1214 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1215 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1217 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1218 if ( aModifiedShape.IsPartner( aS ) )
1220 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1221 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1222 BRepTools::Write(aS ,aName.ToCString());
1230 if ( !aGroupIndexes.IsEmpty() )
1231 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1234 if ( !aGroupsData.IsEmpty() )
1236 GEOM::GEOM_IGroupOperations_var aGroupOp =
1237 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1239 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1240 for ( ; aMapIt.More(); aMapIt.Next() )
1242 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1243 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1245 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1246 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1249 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1250 aGeomIndexes->length( aGroupIndexes.Length() );
1252 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1253 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1255 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1256 if ( aGroupOp->IsDone() )
1258 SALOMEDS::SObject_var aGroupSO =
1259 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1268 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1269 const bool theIsSetToUpdate )
1271 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1272 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1274 // Indicate model of the need to update splitting
1275 if ( theIsSetToUpdate ) {
1280 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1281 HYDROData_PriorityType thePriority,
1282 const Handle(HYDROData_Entity)& theObject2,
1283 HYDROData_Zone::MergeType theMergeType,
1284 HYDROData_CalculationCase::DataTag theDataTag )
1286 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1287 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1289 // Indicate model of the need to update splitting
1293 QString HYDROData_CalculationCase::DumpRules() const
1295 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1296 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1299 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1301 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1302 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1304 // Indicate model of the need to update splitting
1308 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1310 Handle(TDataStd_Integer) aModeAttr;
1311 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1313 return ( AssignmentMode ) aModeAttr->Get();
1318 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1319 QStringList& theScript ) const
1321 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1322 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1325 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1327 return myLastWarning;
1330 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1332 myLastWarning.Type = theType;
1333 myLastWarning.Data = theData;
1336 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1337 const QString& theOldCaseName,
1338 const QString& theName )
1340 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1341 for ( ; anIter.More(); anIter.Next() )
1343 Handle(HYDROData_Region) aRegion =
1344 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1345 if ( aRegion.IsNull() )
1348 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1350 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1351 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1352 for ( ; anIter.More(); anIter.Next() )
1354 Handle(HYDROData_Zone) aRegZone =
1355 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1356 if ( aRegZone.IsNull() )
1359 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1364 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1365 const QString& thePyScriptPath,
1366 MapOfTreatedObjects& theTreatedObjects,
1367 const HYDROData_SequenceOfObjects& theRegions ) const
1369 HYDROData_SequenceOfObjects::Iterator anIter;
1370 anIter.Init(theRegions);
1371 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1373 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1374 if (aRegion.IsNull())
1376 QString defRegName = this->GetName();
1377 QString regSuffix = QString("_Reg_%1").arg(ireg);
1378 defRegName += regSuffix;
1379 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1380 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1381 theResList << aRegDump;
1383 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1385 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1386 if (aRegion.IsNull())
1388 QStringList aRegDump;
1389 aRegion->SetNameInDumpPython(aRegDump);
1390 theResList << aRegDump;
1394 bool HYDROData_CalculationCase::GetRule( int theIndex,
1395 Handle(HYDROData_Entity)& theObject1,
1396 HYDROData_PriorityType& thePriority,
1397 Handle(HYDROData_Entity)& theObject2,
1398 HYDROData_Zone::MergeType& theMergeType,
1399 HYDROData_CalculationCase::DataTag& theDataTag) const
1401 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1402 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1403 theObject1, thePriority, theObject2, theMergeType );
1406 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1408 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1410 if ( HasReference( theInterPolyline, aDataTag ) )
1413 AddReferenceObject( theInterPolyline, aDataTag );
1418 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1420 return GetReferenceObjects( DataTag_InterPoly );
1423 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1425 if ( theInterPolyline.IsNull() )
1428 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );