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();
285 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
286 if ( !aGeomObjects.IsEmpty() ) {
287 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
289 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
290 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
291 if ( !aSplitObjects.isEmpty() ) {
292 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
293 while( anIter.hasNext() ) {
294 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
295 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
296 aZonesList.append( aSplitData );
297 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
298 anEdgesList.append( aSplitData );
303 switch( GetAssignmentMode() )
306 CreateRegionsDef( aDocument, aZonesList );
309 CreateRegionsAuto( aDocument, aZonesList );
313 CreateEdgeGroupsDef( aDocument, anEdgesList );
316 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
317 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
319 // Create result regions for case, by default one zone for one region
320 QString aRegsPref = CALCULATION_REGIONS_PREF;
321 QString aZonesPref = CALCULATION_ZONES_PREF;
323 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
324 while( anIter.hasNext() )
326 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
328 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
330 // Add the zone for region
331 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
335 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
336 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
338 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
339 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
340 QMap<QString, QString> aRegionNameToObjNameMap;
341 QString aZonesPref = CALCULATION_ZONES_PREF;
342 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
344 // 1. First we create a default region for each object included into the calculation case
345 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
346 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
348 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
351 QString anObjName = anObj->GetName();
352 QString aRegName = anObjName + "_reg";
353 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
354 aRegionsMap.insert( anObjName, aRegion );
355 aRegionNameToObjNameMap.insert( aRegName, anObjName );
358 // 2. Now for each zone it is necessary to determine the most priority object
359 // and assign to zone to corresponding region
360 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
361 while( anIter.hasNext() )
363 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
364 HYDROData_Zone::MergeType aMergeType;
365 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
366 if( aRegObj.IsNull() )
368 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
369 if( aRegion.IsNull() )
371 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
373 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
375 qDebug( "Error in algorithm: unresolved conflicts" );
378 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
379 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
380 if ( !aMergeObject.IsNull() ) {
381 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
382 aMergeEntity = aMergeObject->GetAltitudeObject();
387 case HYDROData_Zone::Merge_ZMIN:
388 case HYDROData_Zone::Merge_ZMAX:
389 aRegionZone->SetMergeType( aMergeType );
391 case HYDROData_Zone::Merge_Object:
392 aRegionZone->SetMergeType( aMergeType );
393 aRegionZone->RemoveMergeObject();
394 aRegionZone->SetMergeObject( aMergeEntity );
399 QStringList anObjectsWithEmptyRegions;
400 QMap<QString, Handle(HYDROData_Region)>::const_iterator
401 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
402 for( ; anIt!=aLast; anIt++ )
404 Handle(HYDROData_Region) aRegion = anIt.value();
405 if( aRegion->GetZones().IsEmpty() )
407 QString aRegName = aRegion->GetName();
408 QString anObjName = aRegionNameToObjNameMap[aRegName];
409 anObjectsWithEmptyRegions.append( anObjName );
413 if( !anObjectsWithEmptyRegions.empty() )
415 QString aData = anObjectsWithEmptyRegions.join( ", " );
416 SetWarning( WARN_EMPTY_REGIONS, aData );
420 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
421 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
423 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
425 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
426 while( anIter.hasNext() )
428 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
429 // Create new edges group
430 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
433 QString anObjName = aSplitData.ObjectNames.first();
434 if ( anObjName.isEmpty() )
436 #ifdef DEB_CALCULATION
437 QString aStr = aSplitData.ObjectNames.join(" ");
438 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
440 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
441 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
443 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
444 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
448 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
450 if ( aSplitGroup.IsNull() )
453 aSplitGroup->AddShape( aSplitData.Shape );
457 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
459 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
460 return false; // Wrong type of object
462 if ( HasReference( theObject, DataTag_GeometryObject ) )
463 return false; // Object is already in reference list
465 AddReferenceObject( theObject, DataTag_GeometryObject );
467 // Indicate model of the need to update splitting
473 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
475 return GetReferenceObjects( DataTag_GeometryObject );
478 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
480 if ( theObject.IsNull() )
483 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
485 // Indicate model of the need to update splitting
489 void HYDROData_CalculationCase::RemoveGeometryObjects()
491 ClearReferenceObjects( DataTag_GeometryObject );
493 // Indicate model of the need to update splitting
497 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
499 if ( theGroup.IsNull() )
502 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
503 return false; // Object is already in reference list
505 AddReferenceObject( theGroup, DataTag_GeometryGroup );
507 // Indicate model of the need to update splitting
508 Changed( Geom_Groups );
513 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
515 return GetReferenceObjects( DataTag_GeometryGroup );
518 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
520 if ( theGroup.IsNull() )
523 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
525 // Indicate model of the need to update splitting
526 Changed( Geom_Groups );
529 void HYDROData_CalculationCase::RemoveGeometryGroups()
531 ClearReferenceObjects( DataTag_GeometryGroup );
533 // Indicate model of the need to update splitting
534 Changed( Geom_Groups );
537 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
539 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
541 SetReferenceObject( thePolyline, DataTag_Polyline );
543 // Indicate model of the need to update zones splitting
544 if( !IsEqual( aPrevPolyline, thePolyline ) )
548 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
550 return Handle(HYDROData_PolylineXY)::DownCast(
551 GetReferenceObject( DataTag_Polyline ) );
554 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
556 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
558 ClearReferenceObjects( DataTag_Polyline );
560 // Indicate model of the need to update zones splitting
564 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
566 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
568 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
570 // Indicate model of the need to update land covers partition
571 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
575 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
577 return Handle(HYDROData_StricklerTable)::DownCast(
578 GetReferenceObject( DataTag_StricklerTable ) );
581 void HYDROData_CalculationCase::RemoveStricklerTable()
583 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
585 ClearReferenceObjects( DataTag_StricklerTable );
587 // Indicate model of the need to update land covers partition
591 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
593 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
594 GetReferenceObject( DataTag_LandCoverMap ) );
598 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
600 SetReferenceObject( theMap, DataTag_LandCoverMap );
603 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
608 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
609 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
610 if ( aNewRegion.IsNull() )
613 aNewRegion->AddZone( theZone );
618 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
620 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
622 if ( theRegion.IsNull() )
625 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
627 if ( HasReference( theRegion, aDataTag ) )
628 return false; // Object is already in reference list
630 // Move the region from other calculation
631 Handle(HYDROData_CalculationCase) aFatherCalc =
632 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
633 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
635 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
636 theRegion->CopyTo( aNewRegion, true );
638 aFatherCalc->RemoveRegion( theRegion );
640 theRegion->SetLabel( aNewRegion->Label() );
644 AddReferenceObject( theRegion, aDataTag );
650 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
652 return GetReferenceObjects( DataTag_Region );
655 void HYDROData_CalculationCase::UpdateRegionsOrder()
657 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
658 if ( aDocument.IsNull() )
661 HYDROData_SequenceOfObjects aRegions = GetRegions();
662 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
663 for ( ; anIter.More(); anIter.Next() )
665 Handle(HYDROData_Region) aRegion =
666 Handle(HYDROData_Region)::DownCast( anIter.Value() );
667 if ( aRegion.IsNull() )
670 aRegion->SetName( "" );
673 QString aRegsPref = CALCULATION_REGIONS_PREF;
675 anIter.Init( aRegions );
676 for ( ; anIter.More(); anIter.Next() )
678 Handle(HYDROData_Region) aRegion =
679 Handle(HYDROData_Region)::DownCast( anIter.Value() );
680 if ( aRegion.IsNull() )
683 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
684 aRegion->SetName( aRegionName );
688 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
690 if ( theRegion.IsNull() )
693 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
694 RemoveReferenceObject( theRegion->Label(), aDataTag );
696 // Remove region from data model
697 Handle(HYDROData_CalculationCase) aFatherCalc =
698 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
699 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
703 void HYDROData_CalculationCase::RemoveRegions()
705 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
708 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
710 return GetReferenceObjects( DataTag_SplitGroups );
713 void HYDROData_CalculationCase::RemoveSplitGroups()
715 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
718 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
720 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
721 return GetAltitudeForPoint( thePoint, aZone );
724 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
725 const Handle(HYDROData_Region)& theRegion,
728 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
730 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
731 if ( !aZone.IsNull() )
733 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
734 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
735 if ( IsEqual( aRefRegion, theRegion ) )
736 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
739 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
740 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
745 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
751 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
752 const Handle(HYDROData_Zone)& theZone,
755 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
756 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
757 if ( theZone.IsNull() )
759 DEBTRACE("Zone nulle");
763 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
764 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
765 if ( !theZone->IsMergingNeed() )
767 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
770 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
772 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
776 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
777 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
779 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
780 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
781 if ( !aMergeAltitude.IsNull() )
783 if ( aZoneInterpolator != NULL )
785 DEBTRACE("aZoneInterpolator != NULL");
786 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
787 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
791 DEBTRACE("aZoneInterpolator == NULL");
792 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
798 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
799 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
800 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
801 for ( ; anIter.More(); anIter.Next() )
803 Handle(HYDROData_Object) aZoneObj =
804 Handle(HYDROData_Object)::DownCast( anIter.Value() );
805 if ( aZoneObj.IsNull() )
808 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
809 if ( anObjAltitude.IsNull() )
812 double aPointAltitude = 0.0;
813 if ( aZoneInterpolator != NULL )
815 DEBTRACE("aZoneInterpolator != NULL");
816 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
817 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
821 //DEBTRACE("aZoneInterpolator == NULL");
822 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
825 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
828 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
830 aResAltitude = aPointAltitude;
833 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
835 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
836 aResAltitude > aPointAltitude )
838 aResAltitude = aPointAltitude;
841 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
843 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
844 aResAltitude < aPointAltitude )
846 aResAltitude = aPointAltitude;
855 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
856 const NCollection_Sequence<gp_XY>& thePoints,
857 const Handle(HYDROData_Region)& theRegion,
860 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
861 NCollection_Sequence<double> aResSeq;
863 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
865 const gp_XY& thePnt = thePoints.Value( i );
867 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
868 aResSeq.Append( anAltitude );
874 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
875 const NCollection_Sequence<gp_XY>& thePoints,
876 const Handle(HYDROData_Zone)& theZone,
879 NCollection_Sequence<double> aResSeq;
881 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
883 const gp_XY& thePnt = thePoints.Value( i );
885 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
886 aResSeq.Append( anAltitude );
892 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
894 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
895 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
900 aMap->FindByPoint( thePoint, aType );
901 double aCoeff = aTable->Get( aType, 0.0 );
905 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
907 Handle(HYDROData_Region) aResRegion;
909 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
910 if ( !aZone.IsNull() )
911 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
916 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
918 Handle(HYDROData_Zone) aResZone;
920 HYDROData_SequenceOfObjects aRegions = GetRegions();
922 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
923 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
925 Handle(HYDROData_Region) aRegion =
926 Handle(HYDROData_Region)::DownCast( anIter.Value() );
927 if ( aRegion.IsNull() )
930 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
931 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
932 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
934 Handle(HYDROData_Zone) aRegZone =
935 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
936 if ( aRegZone.IsNull() )
939 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
940 if ( aPointRelation != POINT_OUT )
941 aResZone = aRegZone; // We found the desired zone
948 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
949 const gp_XY& thePoint,
950 const Handle(HYDROData_Zone)& theZone ) const
952 PointClassification aRes = POINT_OUT;
953 if ( theZone.IsNull() )
956 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
957 if ( aZoneFace.IsNull() )
960 TopoDS_Compound aCmp;
962 aBB.MakeCompound(aCmp);
963 aBB.Add(aCmp, aZoneFace);
964 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
965 BRepBuilderAPI_MakeVertex aMk(aPnt);
966 aBB.Add(aCmp, aMk.Vertex());
967 BRepTools::Write(aCmp, "FCL2d.brep");
969 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
970 if (State == TopAbs_OUT)
972 else if(State == TopAbs_IN)
974 else if(State == TopAbs_ON)
979 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
980 const QString& thePrefixOrName,
983 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
984 int aTag = aNewLab.Tag();
986 Handle(HYDROData_Region) aNewRegion =
987 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
988 AddRegion( aNewRegion );
990 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
991 aNewRegion->SetName( aRegionName, true );
996 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
998 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1000 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1001 Handle(HYDROData_SplitShapesGroup)::DownCast(
1002 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1003 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1005 aNewGroup->SetName( theName );
1010 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1015 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1016 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1018 QString aGeomObjEntry, anErrorMsg;
1019 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1020 return isOK ? aGeomObjEntry : QString();
1025 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1026 SALOMEDS::Study_ptr theStudy,
1027 QString& theGeomObjEntry,
1028 QString& theErrorMsg ) const
1030 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1032 // Get groups definitions
1033 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1035 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1036 for ( ; anIter.More(); anIter.Next() )
1039 Handle(HYDROData_ShapesGroup) aGroup =
1040 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1041 if ( aGroup.IsNull() )
1044 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1046 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1047 aGroup->GetShapes( aGroupDef.Shapes );
1049 aSeqOfGroupsDefs.Append( aGroupDef );
1053 bool isAllNotSubmersible = true;
1054 TopTools_ListOfShape aFaces;
1055 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1056 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1057 for ( ; aRegionIter.More(); aRegionIter.Next() )
1059 Handle(HYDROData_Region) aRegion =
1060 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1061 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1064 if ( isAllNotSubmersible )
1065 isAllNotSubmersible = false;
1067 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1068 aFaces.Append( aRegionShape );
1073 if ( aCaseRegions.IsEmpty() ) {
1074 theErrorMsg = QString("the list of regions is empty.");
1075 } else if ( isAllNotSubmersible ) {
1076 theErrorMsg = QString("there are no submersible regions.");
1078 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1081 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1083 QString aTelemacFileName = GetName() + ".telemac";
1084 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable() );
1089 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1090 SALOMEDS::Study_ptr theStudy,
1091 const TopTools_ListOfShape& theFaces,
1092 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1093 QString& theGeomObjEntry ) const
1096 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1097 aSewing.SetNonManifoldMode( Standard_False );
1098 #ifdef DEB_CALCULATION
1099 TCollection_AsciiString aNam("Sh_");
1102 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1103 for ( ; aFaceIter.More(); aFaceIter.Next() )
1105 TopoDS_Shape aShape = aFaceIter.Value();
1106 if ( aShape.IsNull() )
1109 if ( aShape.ShapeType() == TopAbs_FACE )
1111 aSewing.Add( aShape );
1112 #ifdef DEB_CALCULATION
1113 TCollection_AsciiString aName = aNam + ++i + ".brep";
1114 BRepTools::Write(aShape ,aName.ToCString());
1119 #ifdef DEB_CALCULATION
1122 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1123 for (; anExp.More(); anExp.Next() ) {
1124 aSewing.Add( anExp.Current() );
1125 #ifdef DEB_CALCULATION
1127 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1128 BRepTools::Write(anExp.Current() ,aName.ToCString());
1135 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1137 // If the sewed shape is empty - return false
1138 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1141 #ifdef DEB_CALCULATION
1142 BRepTools::Write(aSewedShape ,"Sew.brep");
1144 // Publish the sewed shape
1145 QString aName = EXPORT_NAME;
1146 GEOM::GEOM_Object_ptr aMainShape =
1147 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1149 if ( aMainShape->_is_nil() )
1152 if ( theGroupsDefs.IsEmpty() )
1156 TopTools_IndexedMapOfShape aMapOfSubShapes;
1157 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1159 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1161 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1163 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1165 NCollection_Sequence<int> aGroupIndexes;
1166 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1168 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1169 #ifdef DEB_CALCULATION
1170 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1173 TopoDS_Shape aModifiedShape = aShape;
1174 if ( aSewing.IsModified( aShape ) )
1175 aModifiedShape = aSewing.Modified( aShape );
1176 else if ( aSewing.IsModifiedSubShape( aShape ) )
1177 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1179 #ifdef DEB_CALCULATION
1180 const TopLoc_Location& aL1 = aShape.Location();
1181 const TopLoc_Location& aL2 = aModifiedShape.Location();
1182 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1185 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1186 if ( anIndex > 0 ) {
1187 aGroupIndexes.Append( anIndex );
1189 #ifdef DEB_CALCULATION
1190 TCollection_AsciiString aNam("Lost_");
1191 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1192 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1194 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1195 if ( aModifiedShape.IsPartner( aS ) )
1197 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1198 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1199 BRepTools::Write(aS ,aName.ToCString());
1207 if ( !aGroupIndexes.IsEmpty() )
1208 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1211 if ( !aGroupsData.IsEmpty() )
1213 GEOM::GEOM_IGroupOperations_var aGroupOp =
1214 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1216 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1217 for ( ; aMapIt.More(); aMapIt.Next() )
1219 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1220 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1222 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1223 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1226 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1227 aGeomIndexes->length( aGroupIndexes.Length() );
1229 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1230 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1232 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1233 if ( aGroupOp->IsDone() )
1235 SALOMEDS::SObject_var aGroupSO =
1236 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1245 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1246 const bool theIsSetToUpdate )
1248 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1249 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1251 // Indicate model of the need to update splitting
1252 if ( theIsSetToUpdate ) {
1257 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1258 HYDROData_PriorityType thePriority,
1259 const Handle(HYDROData_Entity)& theObject2,
1260 HYDROData_Zone::MergeType theMergeType,
1261 HYDROData_CalculationCase::DataTag theDataTag )
1263 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1264 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1266 // Indicate model of the need to update splitting
1270 QString HYDROData_CalculationCase::DumpRules() const
1272 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1273 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1276 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1278 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1279 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1281 // Indicate model of the need to update splitting
1285 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1287 Handle(TDataStd_Integer) aModeAttr;
1288 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1290 return ( AssignmentMode ) aModeAttr->Get();
1295 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1296 QStringList& theScript ) const
1298 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1299 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1302 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1304 return myLastWarning;
1307 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1309 myLastWarning.Type = theType;
1310 myLastWarning.Data = theData;
1313 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1314 const QString& theOldCaseName,
1315 const QString& theName )
1317 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1318 for ( ; anIter.More(); anIter.Next() )
1320 Handle(HYDROData_Region) aRegion =
1321 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1322 if ( aRegion.IsNull() )
1325 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1327 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1328 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1329 for ( ; anIter.More(); anIter.Next() )
1331 Handle(HYDROData_Zone) aRegZone =
1332 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1333 if ( aRegZone.IsNull() )
1336 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1341 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1342 const QString& thePyScriptPath,
1343 MapOfTreatedObjects& theTreatedObjects,
1344 const HYDROData_SequenceOfObjects& theRegions ) const
1346 HYDROData_SequenceOfObjects::Iterator anIter;
1347 anIter.Init(theRegions);
1348 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1350 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1351 if (aRegion.IsNull())
1353 QString defRegName = this->GetName();
1354 QString regSuffix = QString("_Reg_%1").arg(ireg);
1355 defRegName += regSuffix;
1356 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1357 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1358 theResList << aRegDump;
1360 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1362 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1363 if (aRegion.IsNull())
1365 QStringList aRegDump;
1366 aRegion->SetNameInDumpPython(aRegDump);
1367 theResList << aRegDump;
1371 bool HYDROData_CalculationCase::GetRule( int theIndex,
1372 Handle(HYDROData_Entity)& theObject1,
1373 HYDROData_PriorityType& thePriority,
1374 Handle(HYDROData_Entity)& theObject2,
1375 HYDROData_Zone::MergeType& theMergeType,
1376 HYDROData_CalculationCase::DataTag& theDataTag) const
1378 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1379 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1380 theObject1, thePriority, theObject2, theMergeType );