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()
80 #include <SALOME_NamingService.hxx>
81 #include <SALOME_LifeCycleCORBA.hxx>
84 #include "HYDRO_trace.hxx"
86 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
87 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
89 HYDROData_CalculationCase::HYDROData_CalculationCase()
90 : HYDROData_Entity( Geom_2d_and_groups )
94 HYDROData_CalculationCase::~HYDROData_CalculationCase()
98 void HYDROData_CalculationCase::SetName( const QString& theName )
100 QString anOldCaseName = GetName();
101 if ( anOldCaseName != theName )
103 // Update names of regions and its zones
104 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
106 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
108 HYDROData_SequenceOfObjects::Iterator anIter;
109 anIter.Init( aGroups );
110 for ( ; anIter.More(); anIter.Next() )
112 Handle(HYDROData_SplitShapesGroup) aGroup =
113 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
114 if ( aGroup.IsNull() )
117 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
121 HYDROData_Entity::SetName( theName );
124 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
125 MapOfTreatedObjects& theTreatedObjects ) const
127 QStringList aResList = dumpObjectCreation( theTreatedObjects );
128 aResList.prepend( "# Calculation case" );
130 QString aCalculName = GetObjPyName();
132 AssignmentMode aMode = GetAssignmentMode();
133 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
134 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
136 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
137 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
138 for ( ; anIter.More(); anIter.Next() )
140 Handle(HYDROData_Object) aRefGeomObj =
141 Handle(HYDROData_Object)::DownCast( anIter.Value() );
142 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
144 aResList << QString( "" );
146 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
148 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
149 anIter.Init( aGeomGroups );
150 for ( ; anIter.More(); anIter.Next() )
152 Handle(HYDROData_ShapesGroup) aGeomGroup =
153 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
154 if ( aGeomGroup.IsNull() )
157 Handle(HYDROData_Object) aFatherGeom =
158 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
159 if ( aFatherGeom.IsNull() )
162 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
163 aResList << QString( "%1 = %2.GetGroup( %3 )" )
164 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
166 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
169 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
170 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
172 if( aMode==AUTOMATIC )
173 DumpRulesToPython( aCalculName, aResList );
175 aResList << QString( "" );
176 aResList << "# Start the algorithm of the partition and assignment";
177 aResList << QString( "%1.Update()" ).arg( aCalculName );
181 // Now we restore the
182 // - regions and zones order
183 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
186 // Export calculation case
187 aResList << QString( "" );
188 aResList << "# Export of the calculation case";
189 QString aStudyName = "theStudy";
190 QString anEntryVar = aCalculName + "_entry";
191 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
193 // Get geometry object and print debug information
195 aResList << "# Get geometry shape and print debug information";
196 aResList << "import GEOM";
197 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
198 QString aGeomShapeName = aCalculName + "_geom";
199 aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
200 aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
201 aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
203 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
205 aResList << QString( "" );
209 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
210 const QString& theStudyName,
211 const QString& theGeomShapeName,
212 const QString& theMeshName ) const
215 theResList << "# Meshing";
216 theResList << "import SMESH, SALOMEDS";
217 theResList << "from salome.smesh import smeshBuilder";
218 theResList << "from salome.geom import geomBuilder";
220 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
221 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
222 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
223 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
224 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
225 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
226 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
229 theResList << "# Set names of Mesh objects";
230 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
231 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
232 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
233 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
234 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
237 theResList << "# Greate SMESH groups";
238 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
239 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
240 theResList << QString( "for group in geom_groups:" );
241 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
243 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
244 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
247 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
249 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
251 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
252 if ( !aBoundaryPolyline.IsNull() )
253 aResSeq.Append( aBoundaryPolyline );
255 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
256 aResSeq.Append( aSeqOfGeomObjs );
259 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
260 aResSeq.Append( aSeqOfRegions );
265 void HYDROData_CalculationCase::Update()
267 HYDROData_Entity::Update();
270 // At first we remove previously created objects
274 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
275 if ( aDocument.IsNull() )
279 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
281 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
282 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
283 if ( !aGeomObjects.IsEmpty() ) {
284 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
286 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
287 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
288 if ( !aSplitObjects.isEmpty() ) {
289 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
290 while( anIter.hasNext() ) {
291 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
292 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
293 aZonesList.append( aSplitData );
294 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
295 anEdgesList.append( aSplitData );
300 switch( GetAssignmentMode() )
303 CreateRegionsDef( aDocument, aZonesList );
306 CreateRegionsAuto( aDocument, aZonesList );
310 CreateEdgeGroupsDef( aDocument, anEdgesList );
313 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
314 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
316 // Create result regions for case, by default one zone for one region
317 QString aRegsPref = CALCULATION_REGIONS_PREF;
318 QString aZonesPref = CALCULATION_ZONES_PREF;
320 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
321 while( anIter.hasNext() )
323 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
325 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
327 // Add the zone for region
328 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
332 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
333 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
335 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
336 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
337 QMap<QString, QString> aRegionNameToObjNameMap;
338 QString aZonesPref = CALCULATION_ZONES_PREF;
339 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
341 // 1. First we create a default region for each object included into the calculation case
342 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
343 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
345 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
348 QString anObjName = anObj->GetName();
349 QString aRegName = anObjName + "_reg";
350 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
351 aRegionsMap.insert( anObjName, aRegion );
352 aRegionNameToObjNameMap.insert( aRegName, anObjName );
355 // 2. Now for each zone it is necessary to determine the most priority object
356 // and assign to zone to corresponding region
357 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
358 while( anIter.hasNext() )
360 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
361 HYDROData_Zone::MergeType aMergeType;
362 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
363 if( aRegObj.IsNull() )
365 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
366 if( aRegion.IsNull() )
368 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
370 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
372 qDebug( "Error in algorithm: unresolved conflicts" );
375 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
376 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
377 if ( !aMergeObject.IsNull() ) {
378 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
379 aMergeEntity = aMergeObject->GetAltitudeObject();
384 case HYDROData_Zone::Merge_ZMIN:
385 case HYDROData_Zone::Merge_ZMAX:
386 aRegionZone->SetMergeType( aMergeType );
388 case HYDROData_Zone::Merge_Object:
389 aRegionZone->SetMergeType( aMergeType );
390 aRegionZone->RemoveMergeObject();
391 aRegionZone->SetMergeObject( aMergeEntity );
396 QStringList anObjectsWithEmptyRegions;
397 QMap<QString, Handle(HYDROData_Region)>::const_iterator
398 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
399 for( ; anIt!=aLast; anIt++ )
401 Handle(HYDROData_Region) aRegion = anIt.value();
402 if( aRegion->GetZones().IsEmpty() )
404 QString aRegName = aRegion->GetName();
405 QString anObjName = aRegionNameToObjNameMap[aRegName];
406 anObjectsWithEmptyRegions.append( anObjName );
410 if( !anObjectsWithEmptyRegions.empty() )
412 QString aData = anObjectsWithEmptyRegions.join( ", " );
413 SetWarning( WARN_EMPTY_REGIONS, aData );
417 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
418 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
420 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
422 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
423 while( anIter.hasNext() )
425 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
426 // Create new edges group
427 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
430 QString anObjName = aSplitData.ObjectNames.first();
431 if ( anObjName.isEmpty() )
433 #ifdef DEB_CALCULATION
434 QString aStr = aSplitData.ObjectNames.join(" ");
435 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
437 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
438 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
440 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
441 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
445 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
447 if ( aSplitGroup.IsNull() )
450 aSplitGroup->AddShape( aSplitData.Shape );
454 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
456 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
457 return false; // Wrong type of object
459 if ( HasReference( theObject, DataTag_GeometryObject ) )
460 return false; // Object is already in reference list
462 AddReferenceObject( theObject, DataTag_GeometryObject );
464 // Indicate model of the need to update splitting
470 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
472 return GetReferenceObjects( DataTag_GeometryObject );
475 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
477 if ( theObject.IsNull() )
480 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
482 // Indicate model of the need to update splitting
486 void HYDROData_CalculationCase::RemoveGeometryObjects()
488 ClearReferenceObjects( DataTag_GeometryObject );
490 // Indicate model of the need to update splitting
494 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
496 if ( theGroup.IsNull() )
499 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
500 return false; // Object is already in reference list
502 AddReferenceObject( theGroup, DataTag_GeometryGroup );
504 // Indicate model of the need to update splitting
505 Changed( Geom_Groups );
510 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
512 return GetReferenceObjects( DataTag_GeometryGroup );
515 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
517 if ( theGroup.IsNull() )
520 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
522 // Indicate model of the need to update splitting
523 Changed( Geom_Groups );
526 void HYDROData_CalculationCase::RemoveGeometryGroups()
528 ClearReferenceObjects( DataTag_GeometryGroup );
530 // Indicate model of the need to update splitting
531 Changed( Geom_Groups );
534 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
536 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
538 SetReferenceObject( thePolyline, DataTag_Polyline );
540 // Indicate model of the need to update zones splitting
541 if( !IsEqual( aPrevPolyline, thePolyline ) )
545 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
547 return Handle(HYDROData_PolylineXY)::DownCast(
548 GetReferenceObject( DataTag_Polyline ) );
551 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
553 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
555 ClearReferenceObjects( DataTag_Polyline );
557 // Indicate model of the need to update zones splitting
561 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
563 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
565 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
567 // Indicate model of the need to update land covers partition
568 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
572 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
574 return Handle(HYDROData_StricklerTable)::DownCast(
575 GetReferenceObject( DataTag_StricklerTable ) );
578 void HYDROData_CalculationCase::RemoveStricklerTable()
580 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
582 ClearReferenceObjects( DataTag_StricklerTable );
584 // Indicate model of the need to update land covers partition
588 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
590 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
591 GetReferenceObject( DataTag_LandCoverMap ) );
595 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
597 SetReferenceObject( theMap, DataTag_LandCoverMap );
600 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
605 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
606 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
607 if ( aNewRegion.IsNull() )
610 aNewRegion->AddZone( theZone );
615 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
617 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
619 if ( theRegion.IsNull() )
622 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
624 if ( HasReference( theRegion, aDataTag ) )
625 return false; // Object is already in reference list
627 // Move the region from other calculation
628 Handle(HYDROData_CalculationCase) aFatherCalc =
629 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
630 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
632 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
633 theRegion->CopyTo( aNewRegion, true );
635 aFatherCalc->RemoveRegion( theRegion );
637 theRegion->SetLabel( aNewRegion->Label() );
641 AddReferenceObject( theRegion, aDataTag );
647 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
649 return GetReferenceObjects( DataTag_Region );
652 void HYDROData_CalculationCase::UpdateRegionsOrder()
654 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
655 if ( aDocument.IsNull() )
658 HYDROData_SequenceOfObjects aRegions = GetRegions();
659 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
660 for ( ; anIter.More(); anIter.Next() )
662 Handle(HYDROData_Region) aRegion =
663 Handle(HYDROData_Region)::DownCast( anIter.Value() );
664 if ( aRegion.IsNull() )
667 aRegion->SetName( "" );
670 QString aRegsPref = CALCULATION_REGIONS_PREF;
672 anIter.Init( aRegions );
673 for ( ; anIter.More(); anIter.Next() )
675 Handle(HYDROData_Region) aRegion =
676 Handle(HYDROData_Region)::DownCast( anIter.Value() );
677 if ( aRegion.IsNull() )
680 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
681 aRegion->SetName( aRegionName );
685 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
687 if ( theRegion.IsNull() )
690 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
691 RemoveReferenceObject( theRegion->Label(), aDataTag );
693 // Remove region from data model
694 Handle(HYDROData_CalculationCase) aFatherCalc =
695 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
696 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
700 void HYDROData_CalculationCase::RemoveRegions()
702 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
705 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
707 return GetReferenceObjects( DataTag_SplitGroups );
710 void HYDROData_CalculationCase::RemoveSplitGroups()
712 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
715 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
717 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
718 return GetAltitudeForPoint( thePoint, aZone );
721 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
722 const Handle(HYDROData_Region)& theRegion,
725 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
727 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
728 if ( !aZone.IsNull() )
730 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
731 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
732 if ( IsEqual( aRefRegion, theRegion ) )
733 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
736 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
737 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
742 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
748 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
749 const Handle(HYDROData_Zone)& theZone,
752 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
753 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
754 if ( theZone.IsNull() )
756 DEBTRACE("Zone nulle");
760 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
761 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
762 if ( !theZone->IsMergingNeed() )
764 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
767 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
769 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
773 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
774 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
776 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
777 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
778 if ( !aMergeAltitude.IsNull() )
780 if ( aZoneInterpolator != NULL )
782 DEBTRACE("aZoneInterpolator != NULL");
783 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
784 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
788 DEBTRACE("aZoneInterpolator == NULL");
789 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
795 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
796 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
797 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
798 for ( ; anIter.More(); anIter.Next() )
800 Handle(HYDROData_Object) aZoneObj =
801 Handle(HYDROData_Object)::DownCast( anIter.Value() );
802 if ( aZoneObj.IsNull() )
805 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
806 if ( anObjAltitude.IsNull() )
809 double aPointAltitude = 0.0;
810 if ( aZoneInterpolator != NULL )
812 DEBTRACE("aZoneInterpolator != NULL");
813 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
814 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
818 //DEBTRACE("aZoneInterpolator == NULL");
819 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
822 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
825 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
827 aResAltitude = aPointAltitude;
830 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
832 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
833 aResAltitude > aPointAltitude )
835 aResAltitude = aPointAltitude;
838 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
840 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
841 aResAltitude < aPointAltitude )
843 aResAltitude = aPointAltitude;
852 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
853 const NCollection_Sequence<gp_XY>& thePoints,
854 const Handle(HYDROData_Region)& theRegion,
857 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
858 NCollection_Sequence<double> aResSeq;
860 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
862 const gp_XY& thePnt = thePoints.Value( i );
864 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
865 aResSeq.Append( anAltitude );
871 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
872 const NCollection_Sequence<gp_XY>& thePoints,
873 const Handle(HYDROData_Zone)& theZone,
876 NCollection_Sequence<double> aResSeq;
878 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
880 const gp_XY& thePnt = thePoints.Value( i );
882 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
883 aResSeq.Append( anAltitude );
889 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
891 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
892 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
897 aMap->FindByPoint( thePoint, aType );
898 double aCoeff = aTable->Get( aType, 0.0 );
902 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
904 Handle(HYDROData_Region) aResRegion;
906 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
907 if ( !aZone.IsNull() )
908 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
913 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
915 Handle(HYDROData_Zone) aResZone;
917 HYDROData_SequenceOfObjects aRegions = GetRegions();
919 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
920 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
922 Handle(HYDROData_Region) aRegion =
923 Handle(HYDROData_Region)::DownCast( anIter.Value() );
924 if ( aRegion.IsNull() )
927 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
928 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
929 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
931 Handle(HYDROData_Zone) aRegZone =
932 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
933 if ( aRegZone.IsNull() )
936 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
937 if ( aPointRelation != POINT_OUT )
938 aResZone = aRegZone; // We found the desired zone
945 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
946 const gp_XY& thePoint,
947 const Handle(HYDROData_Zone)& theZone ) const
949 PointClassification aRes = POINT_OUT;
950 if ( theZone.IsNull() )
953 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
954 if ( aZoneFace.IsNull() )
957 TopoDS_Compound aCmp;
959 aBB.MakeCompound(aCmp);
960 aBB.Add(aCmp, aZoneFace);
961 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
962 BRepBuilderAPI_MakeVertex aMk(aPnt);
963 aBB.Add(aCmp, aMk.Vertex());
964 BRepTools::Write(aCmp, "FCL2d.brep");
966 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
967 if (State == TopAbs_OUT)
969 else if(State == TopAbs_IN)
971 else if(State == TopAbs_ON)
976 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
977 const QString& thePrefixOrName,
980 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
981 int aTag = aNewLab.Tag();
983 Handle(HYDROData_Region) aNewRegion =
984 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
985 AddRegion( aNewRegion );
987 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
988 aNewRegion->SetName( aRegionName, true );
993 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
995 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
997 Handle(HYDROData_SplitShapesGroup) aNewGroup =
998 Handle(HYDROData_SplitShapesGroup)::DownCast(
999 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1000 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1002 aNewGroup->SetName( theName );
1007 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1012 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1013 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1015 QString aGeomObjEntry, anErrorMsg;
1016 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1017 return isOK ? aGeomObjEntry : QString();
1022 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1023 SALOMEDS::Study_ptr theStudy,
1024 QString& theGeomObjEntry,
1025 QString& theErrorMsg ) const
1027 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1029 // Get groups definitions
1030 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1032 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1033 for ( ; anIter.More(); anIter.Next() )
1036 Handle(HYDROData_ShapesGroup) aGroup =
1037 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1038 if ( aGroup.IsNull() )
1041 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1043 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1044 aGroup->GetShapes( aGroupDef.Shapes );
1046 aSeqOfGroupsDefs.Append( aGroupDef );
1050 bool isAllNotSubmersible = true;
1051 TopTools_ListOfShape aFaces;
1052 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1053 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1054 for ( ; aRegionIter.More(); aRegionIter.Next() )
1056 Handle(HYDROData_Region) aRegion =
1057 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1058 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1061 if ( isAllNotSubmersible )
1062 isAllNotSubmersible = false;
1064 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1065 aFaces.Append( aRegionShape );
1070 if ( aCaseRegions.IsEmpty() ) {
1071 theErrorMsg = QString("the list of regions is empty.");
1072 } else if ( isAllNotSubmersible ) {
1073 theErrorMsg = QString("there are no submersible regions.");
1075 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1078 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1080 QString aTelemacFileName = GetName() + ".telemac";
1081 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable() );
1086 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1087 SALOMEDS::Study_ptr theStudy,
1088 const TopTools_ListOfShape& theFaces,
1089 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1090 QString& theGeomObjEntry ) const
1093 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1094 aSewing.SetNonManifoldMode( Standard_False );
1095 #ifdef DEB_CALCULATION
1096 TCollection_AsciiString aNam("Sh_");
1099 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1100 for ( ; aFaceIter.More(); aFaceIter.Next() )
1102 TopoDS_Shape aShape = aFaceIter.Value();
1103 if ( aShape.IsNull() )
1106 if ( aShape.ShapeType() == TopAbs_FACE )
1108 aSewing.Add( aShape );
1109 #ifdef DEB_CALCULATION
1110 TCollection_AsciiString aName = aNam + ++i + ".brep";
1111 BRepTools::Write(aShape ,aName.ToCString());
1116 #ifdef DEB_CALCULATION
1119 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1120 for (; anExp.More(); anExp.Next() ) {
1121 aSewing.Add( anExp.Current() );
1122 #ifdef DEB_CALCULATION
1124 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1125 BRepTools::Write(anExp.Current() ,aName.ToCString());
1132 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1134 // If the sewed shape is empty - return false
1135 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1138 #ifdef DEB_CALCULATION
1139 BRepTools::Write(aSewedShape ,"Sew.brep");
1141 // Publish the sewed shape
1142 QString aName = EXPORT_NAME;
1143 GEOM::GEOM_Object_ptr aMainShape =
1144 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1146 if ( aMainShape->_is_nil() )
1149 if ( theGroupsDefs.IsEmpty() )
1153 TopTools_IndexedMapOfShape aMapOfSubShapes;
1154 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1156 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1158 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1160 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1162 NCollection_Sequence<int> aGroupIndexes;
1163 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1165 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1166 #ifdef DEB_CALCULATION
1167 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1170 TopoDS_Shape aModifiedShape = aShape;
1171 if ( aSewing.IsModified( aShape ) )
1172 aModifiedShape = aSewing.Modified( aShape );
1173 else if ( aSewing.IsModifiedSubShape( aShape ) )
1174 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1176 #ifdef DEB_CALCULATION
1177 const TopLoc_Location& aL1 = aShape.Location();
1178 const TopLoc_Location& aL2 = aModifiedShape.Location();
1179 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1182 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1183 if ( anIndex > 0 ) {
1184 aGroupIndexes.Append( anIndex );
1186 #ifdef DEB_CALCULATION
1187 TCollection_AsciiString aNam("Lost_");
1188 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1189 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1191 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1192 if ( aModifiedShape.IsPartner( aS ) )
1194 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1195 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1196 BRepTools::Write(aS ,aName.ToCString());
1204 if ( !aGroupIndexes.IsEmpty() )
1205 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1208 if ( !aGroupsData.IsEmpty() )
1210 GEOM::GEOM_IGroupOperations_var aGroupOp =
1211 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1213 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1214 for ( ; aMapIt.More(); aMapIt.Next() )
1216 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1217 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1219 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1220 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1223 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1224 aGeomIndexes->length( aGroupIndexes.Length() );
1226 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1227 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1229 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1230 if ( aGroupOp->IsDone() )
1232 SALOMEDS::SObject_var aGroupSO =
1233 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1242 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1243 const bool theIsSetToUpdate )
1245 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1246 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1248 // Indicate model of the need to update splitting
1249 if ( theIsSetToUpdate ) {
1254 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1255 HYDROData_PriorityType thePriority,
1256 const Handle(HYDROData_Entity)& theObject2,
1257 HYDROData_Zone::MergeType theMergeType,
1258 HYDROData_CalculationCase::DataTag theDataTag )
1260 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1261 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1263 // Indicate model of the need to update splitting
1267 QString HYDROData_CalculationCase::DumpRules() const
1269 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1270 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1273 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1275 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1276 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1278 // Indicate model of the need to update splitting
1282 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1284 Handle(TDataStd_Integer) aModeAttr;
1285 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1287 return ( AssignmentMode ) aModeAttr->Get();
1292 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1293 QStringList& theScript ) const
1295 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1296 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1299 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1301 return myLastWarning;
1304 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1306 myLastWarning.Type = theType;
1307 myLastWarning.Data = theData;
1310 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1311 const QString& theOldCaseName,
1312 const QString& theName )
1314 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1315 for ( ; anIter.More(); anIter.Next() )
1317 Handle(HYDROData_Region) aRegion =
1318 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1319 if ( aRegion.IsNull() )
1322 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1324 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1325 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1326 for ( ; anIter.More(); anIter.Next() )
1328 Handle(HYDROData_Zone) aRegZone =
1329 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1330 if ( aRegZone.IsNull() )
1333 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1338 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1339 const QString& thePyScriptPath,
1340 MapOfTreatedObjects& theTreatedObjects,
1341 const HYDROData_SequenceOfObjects& theRegions ) const
1343 HYDROData_SequenceOfObjects::Iterator anIter;
1344 anIter.Init(theRegions);
1345 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1347 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1348 if (aRegion.IsNull())
1350 QString defRegName = this->GetName();
1351 QString regSuffix = QString("_Reg_%1").arg(ireg);
1352 defRegName += regSuffix;
1353 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1354 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1355 theResList << aRegDump;
1357 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1359 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1360 if (aRegion.IsNull())
1362 QStringList aRegDump;
1363 aRegion->SetNameInDumpPython(aRegDump);
1364 theResList << aRegDump;
1368 bool HYDROData_CalculationCase::GetRule( int theIndex,
1369 Handle(HYDROData_Entity)& theObject1,
1370 HYDROData_PriorityType& thePriority,
1371 Handle(HYDROData_Entity)& theObject2,
1372 HYDROData_Zone::MergeType& theMergeType,
1373 HYDROData_CalculationCase::DataTag& theDataTag) const
1375 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1376 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1377 theObject1, thePriority, theObject2, theMergeType );