1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_CalculationCase.h"
20 #include "HYDROData_ArtificialObject.h"
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_Iterator.h"
25 #include "HYDROData_NaturalObject.h"
26 #include "HYDROData_PolylineXY.h"
27 #include "HYDROData_StricklerTable.h"
28 #include "HYDROData_LandCoverMap.h"
29 #include "HYDROData_SplitShapesGroup.h"
30 #include "HYDROData_Region.h"
31 #include "HYDROData_Tool.h"
32 #include "HYDROData_GeomTool.h"
35 #pragma warning ( disable: 4251 )
43 #pragma warning ( default: 4251 )
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Edge.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRepBuilderAPI_Sewing.hxx>
54 #include <BRepTopAdaptor_FClass2d.hxx>
56 #include <BRepTools.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <TopTools_ListOfShape.hxx>
62 #include <TopTools_ListIteratorOfListOfShape.hxx>
63 #include <TDataStd_Integer.hxx>
65 //#define DEB_CALCULATION 1
66 #ifdef DEB_CALCULATION
67 #include <BRepTools.hxx>
68 #include <TopLoc_Location.hxx>
70 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
71 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
72 #define CALCULATION_GROUPS_PREF GetName() + "_"
73 //#define DEB_CLASS2D 1
75 #include <BRepBuilderAPI_MakeVertex.hxx>
78 #define EXPORT_NAME "HYDRO_" + GetName()
81 #include <SALOME_NamingService.hxx>
82 #include <SALOME_LifeCycleCORBA.hxx>
86 #include "HYDRO_trace.hxx"
88 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
89 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
91 HYDROData_CalculationCase::HYDROData_CalculationCase()
92 : HYDROData_Entity( Geom_2d_and_groups )
96 HYDROData_CalculationCase::~HYDROData_CalculationCase()
100 void HYDROData_CalculationCase::SetName( const QString& theName )
102 QString anOldCaseName = GetName();
103 if ( anOldCaseName != theName )
105 // Update names of regions and its zones
106 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
108 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
110 HYDROData_SequenceOfObjects::Iterator anIter;
111 anIter.Init( aGroups );
112 for ( ; anIter.More(); anIter.Next() )
114 Handle(HYDROData_SplitShapesGroup) aGroup =
115 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
116 if ( aGroup.IsNull() )
119 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
123 HYDROData_Entity::SetName( theName );
126 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
127 MapOfTreatedObjects& theTreatedObjects ) const
129 QStringList aResList = dumpObjectCreation( theTreatedObjects );
130 aResList.prepend( "# Calculation case" );
132 QString aCalculName = GetObjPyName();
134 AssignmentMode aMode = GetAssignmentMode();
135 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
136 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
138 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
139 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
140 for ( ; anIter.More(); anIter.Next() )
142 Handle(HYDROData_Object) aRefGeomObj =
143 Handle(HYDROData_Object)::DownCast( anIter.Value() );
144 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
146 aResList << QString( "" );
148 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
150 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
151 anIter.Init( aGeomGroups );
152 for ( ; anIter.More(); anIter.Next() )
154 Handle(HYDROData_ShapesGroup) aGeomGroup =
155 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
156 if ( aGeomGroup.IsNull() )
159 Handle(HYDROData_Object) aFatherGeom =
160 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
161 if ( aFatherGeom.IsNull() )
164 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
165 aResList << QString( "%1 = %2.GetGroup( %3 )" )
166 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
168 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
171 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
172 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
174 if( aMode==AUTOMATIC )
175 DumpRulesToPython( aCalculName, aResList );
177 aResList << QString( "" );
178 aResList << "# Start the algorithm of the partition and assignment";
179 aResList << QString( "%1.Update()" ).arg( aCalculName );
183 // Now we restore the
184 // - regions and zones order
185 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
188 // Export calculation case
189 aResList << QString( "" );
190 aResList << "# Export of the calculation case";
191 QString aStudyName = "theStudy";
192 QString anEntryVar = aCalculName + "_entry";
193 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
195 // Get geometry object and print debug information
197 aResList << "# Get geometry shape and print debug information";
198 aResList << "import GEOM";
199 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
200 QString aGeomShapeName = aCalculName + "_geom";
201 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
202 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
203 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
206 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
208 aResList << QString( "" );
212 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
213 const QString& theStudyName,
214 const QString& theGeomShapeName,
215 const QString& theMeshName ) const
218 theResList << "# Meshing";
219 theResList << "import SMESH, SALOMEDS";
220 theResList << "from salome.smesh import smeshBuilder";
221 theResList << "from salome.geom import geomBuilder";
223 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
224 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
225 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
226 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
227 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
228 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
229 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
232 theResList << "# Set names of Mesh objects";
233 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
234 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
235 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
236 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
237 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
240 theResList << "# Greate SMESH groups";
241 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
242 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
243 theResList << QString( "for group in geom_groups:" );
244 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
246 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
247 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
250 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
252 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
254 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
255 if ( !aBoundaryPolyline.IsNull() )
256 aResSeq.Append( aBoundaryPolyline );
258 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
259 aResSeq.Append( aSeqOfGeomObjs );
262 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
263 aResSeq.Append( aSeqOfRegions );
268 void HYDROData_CalculationCase::Update()
270 HYDROData_Entity::Update();
273 // At first we remove previously created objects
277 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
278 if ( aDocument.IsNull() )
282 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
284 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
286 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
288 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
289 if ( !aGeomObjects.IsEmpty() ) {
290 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
292 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
293 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
294 if ( !aSplitObjects.isEmpty() ) {
295 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
296 while( anIter.hasNext() ) {
297 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
298 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
299 aZonesList.append( aSplitData );
300 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
301 anEdgesList.append( aSplitData );
306 switch( GetAssignmentMode() )
309 CreateRegionsDef( aDocument, aZonesList );
312 CreateRegionsAuto( aDocument, aZonesList );
316 CreateEdgeGroupsDef( aDocument, anEdgesList );
319 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
320 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
322 // Create result regions for case, by default one zone for one region
323 QString aRegsPref = CALCULATION_REGIONS_PREF;
324 QString aZonesPref = CALCULATION_ZONES_PREF;
326 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
327 while( anIter.hasNext() )
329 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
331 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
333 // Add the zone for region
334 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
338 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
339 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
341 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
342 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
343 QMap<QString, QString> aRegionNameToObjNameMap;
344 QString aZonesPref = CALCULATION_ZONES_PREF;
345 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
347 // 1. First we create a default region for each object included into the calculation case
348 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
349 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
351 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
354 QString anObjName = anObj->GetName();
355 QString aRegName = anObjName + "_reg";
356 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
357 aRegionsMap.insert( anObjName, aRegion );
358 aRegionNameToObjNameMap.insert( aRegName, anObjName );
361 // 2. Now for each zone it is necessary to determine the most priority object
362 // and assign to zone to corresponding region
363 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
364 while( anIter.hasNext() )
366 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
367 HYDROData_Zone::MergeType aMergeType;
368 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
369 if( aRegObj.IsNull() )
371 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
372 if( aRegion.IsNull() )
374 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
376 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
378 qDebug( "Error in algorithm: unresolved conflicts" );
381 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
382 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
383 if ( !aMergeObject.IsNull() ) {
384 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
385 aMergeEntity = aMergeObject->GetAltitudeObject();
390 case HYDROData_Zone::Merge_ZMIN:
391 case HYDROData_Zone::Merge_ZMAX:
392 aRegionZone->SetMergeType( aMergeType );
394 case HYDROData_Zone::Merge_Object:
395 aRegionZone->SetMergeType( aMergeType );
396 aRegionZone->RemoveMergeObject();
397 aRegionZone->SetMergeObject( aMergeEntity );
402 QStringList anObjectsWithEmptyRegions;
403 QMap<QString, Handle(HYDROData_Region)>::const_iterator
404 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
405 for( ; anIt!=aLast; anIt++ )
407 Handle(HYDROData_Region) aRegion = anIt.value();
408 if( aRegion->GetZones().IsEmpty() )
410 QString aRegName = aRegion->GetName();
411 QString anObjName = aRegionNameToObjNameMap[aRegName];
412 anObjectsWithEmptyRegions.append( anObjName );
416 if( !anObjectsWithEmptyRegions.empty() )
418 QString aData = anObjectsWithEmptyRegions.join( ", " );
419 SetWarning( WARN_EMPTY_REGIONS, aData );
423 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
424 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
426 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
428 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
429 while( anIter.hasNext() )
431 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
432 // Create new edges group
433 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
436 QString anObjName = aSplitData.ObjectNames.first();
437 if ( anObjName.isEmpty() )
439 #ifdef DEB_CALCULATION
440 QString aStr = aSplitData.ObjectNames.join(" ");
441 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
443 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
444 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
446 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
447 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
451 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
453 if ( aSplitGroup.IsNull() )
456 aSplitGroup->AddShape( aSplitData.Shape );
460 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
462 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
463 return false; // Wrong type of object
465 if ( HasReference( theObject, DataTag_GeometryObject ) )
466 return false; // Object is already in reference list
468 AddReferenceObject( theObject, DataTag_GeometryObject );
470 // Indicate model of the need to update splitting
476 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
478 return GetReferenceObjects( DataTag_GeometryObject );
481 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
483 if ( theObject.IsNull() )
486 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
488 // Indicate model of the need to update splitting
492 void HYDROData_CalculationCase::RemoveGeometryObjects()
494 ClearReferenceObjects( DataTag_GeometryObject );
496 // Indicate model of the need to update splitting
500 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
502 if ( theGroup.IsNull() )
505 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
506 return false; // Object is already in reference list
508 AddReferenceObject( theGroup, DataTag_GeometryGroup );
510 // Indicate model of the need to update splitting
511 Changed( Geom_Groups );
516 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
518 return GetReferenceObjects( DataTag_GeometryGroup );
521 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
523 if ( theGroup.IsNull() )
526 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
528 // Indicate model of the need to update splitting
529 Changed( Geom_Groups );
532 void HYDROData_CalculationCase::RemoveGeometryGroups()
534 ClearReferenceObjects( DataTag_GeometryGroup );
536 // Indicate model of the need to update splitting
537 Changed( Geom_Groups );
540 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
542 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
544 SetReferenceObject( thePolyline, DataTag_Polyline );
546 // Indicate model of the need to update zones splitting
547 if( !IsEqual( aPrevPolyline, thePolyline ) )
551 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
553 return Handle(HYDROData_PolylineXY)::DownCast(
554 GetReferenceObject( DataTag_Polyline ) );
557 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
559 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
561 ClearReferenceObjects( DataTag_Polyline );
563 // Indicate model of the need to update zones splitting
567 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
569 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
571 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
573 // Indicate model of the need to update land covers partition
574 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
578 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
580 return Handle(HYDROData_StricklerTable)::DownCast(
581 GetReferenceObject( DataTag_StricklerTable ) );
584 void HYDROData_CalculationCase::RemoveStricklerTable()
586 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
588 ClearReferenceObjects( DataTag_StricklerTable );
590 // Indicate model of the need to update land covers partition
594 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
596 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
597 GetReferenceObject( DataTag_LandCoverMap ) );
601 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
603 SetReferenceObject( theMap, DataTag_LandCoverMap );
606 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
611 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
612 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
613 if ( aNewRegion.IsNull() )
616 aNewRegion->AddZone( theZone );
621 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
623 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
625 if ( theRegion.IsNull() )
628 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
630 if ( HasReference( theRegion, aDataTag ) )
631 return false; // Object is already in reference list
633 // Move the region from other calculation
634 Handle(HYDROData_CalculationCase) aFatherCalc =
635 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
636 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
638 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
639 theRegion->CopyTo( aNewRegion, true );
641 aFatherCalc->RemoveRegion( theRegion );
643 theRegion->SetLabel( aNewRegion->Label() );
647 AddReferenceObject( theRegion, aDataTag );
653 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
655 return GetReferenceObjects( DataTag_Region );
658 void HYDROData_CalculationCase::UpdateRegionsOrder()
660 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
661 if ( aDocument.IsNull() )
664 HYDROData_SequenceOfObjects aRegions = GetRegions();
665 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
666 for ( ; anIter.More(); anIter.Next() )
668 Handle(HYDROData_Region) aRegion =
669 Handle(HYDROData_Region)::DownCast( anIter.Value() );
670 if ( aRegion.IsNull() )
673 aRegion->SetName( "" );
676 QString aRegsPref = CALCULATION_REGIONS_PREF;
678 anIter.Init( aRegions );
679 for ( ; anIter.More(); anIter.Next() )
681 Handle(HYDROData_Region) aRegion =
682 Handle(HYDROData_Region)::DownCast( anIter.Value() );
683 if ( aRegion.IsNull() )
686 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
687 aRegion->SetName( aRegionName );
691 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
693 if ( theRegion.IsNull() )
696 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
697 RemoveReferenceObject( theRegion->Label(), aDataTag );
699 // Remove region from data model
700 Handle(HYDROData_CalculationCase) aFatherCalc =
701 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
702 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
706 void HYDROData_CalculationCase::RemoveRegions()
708 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
711 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
713 return GetReferenceObjects( DataTag_SplitGroups );
716 void HYDROData_CalculationCase::RemoveSplitGroups()
718 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
721 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
723 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
724 return GetAltitudeForPoint( thePoint, aZone );
727 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
728 const Handle(HYDROData_Region)& theRegion,
731 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
733 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
734 if ( !aZone.IsNull() )
736 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
737 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
738 if ( IsEqual( aRefRegion, theRegion ) )
739 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
742 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
743 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
748 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
754 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
755 const Handle(HYDROData_Zone)& theZone,
758 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
759 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
760 if ( theZone.IsNull() )
762 DEBTRACE("Zone nulle");
766 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
767 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
768 if ( !theZone->IsMergingNeed() )
770 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
773 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
775 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
779 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
780 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
782 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
783 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
784 if ( !aMergeAltitude.IsNull() )
786 if ( aZoneInterpolator != NULL )
788 DEBTRACE("aZoneInterpolator != NULL");
789 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
790 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
794 DEBTRACE("aZoneInterpolator == NULL");
795 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
801 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
802 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
803 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
804 for ( ; anIter.More(); anIter.Next() )
806 Handle(HYDROData_Object) aZoneObj =
807 Handle(HYDROData_Object)::DownCast( anIter.Value() );
808 if ( aZoneObj.IsNull() )
811 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
812 if ( anObjAltitude.IsNull() )
815 double aPointAltitude = 0.0;
816 if ( aZoneInterpolator != NULL )
818 DEBTRACE("aZoneInterpolator != NULL");
819 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
820 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
824 //DEBTRACE("aZoneInterpolator == NULL");
825 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
828 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
831 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
833 aResAltitude = aPointAltitude;
836 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
838 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
839 aResAltitude > aPointAltitude )
841 aResAltitude = aPointAltitude;
844 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
846 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
847 aResAltitude < aPointAltitude )
849 aResAltitude = aPointAltitude;
858 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
859 const NCollection_Sequence<gp_XY>& thePoints,
860 const Handle(HYDROData_Region)& theRegion,
863 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
864 NCollection_Sequence<double> aResSeq;
866 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
868 const gp_XY& thePnt = thePoints.Value( i );
870 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
871 aResSeq.Append( anAltitude );
877 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
878 const NCollection_Sequence<gp_XY>& thePoints,
879 const Handle(HYDROData_Zone)& theZone,
882 NCollection_Sequence<double> aResSeq;
884 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
886 const gp_XY& thePnt = thePoints.Value( i );
888 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
889 aResSeq.Append( anAltitude );
895 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
897 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
898 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
903 aMap->FindByPoint( thePoint, aType );
904 double aCoeff = aTable->Get( aType, 0.0 );
908 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
910 Handle(HYDROData_Region) aResRegion;
912 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
913 if ( !aZone.IsNull() )
914 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
919 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
921 Handle(HYDROData_Zone) aResZone;
923 HYDROData_SequenceOfObjects aRegions = GetRegions();
925 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
926 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
928 Handle(HYDROData_Region) aRegion =
929 Handle(HYDROData_Region)::DownCast( anIter.Value() );
930 if ( aRegion.IsNull() )
933 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
934 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
935 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
937 Handle(HYDROData_Zone) aRegZone =
938 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
939 if ( aRegZone.IsNull() )
942 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
943 if ( aPointRelation != POINT_OUT )
944 aResZone = aRegZone; // We found the desired zone
951 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
952 const gp_XY& thePoint,
953 const Handle(HYDROData_Zone)& theZone ) const
955 PointClassification aRes = POINT_OUT;
956 if ( theZone.IsNull() )
959 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
960 if ( aZoneFace.IsNull() )
963 TopoDS_Compound aCmp;
965 aBB.MakeCompound(aCmp);
966 aBB.Add(aCmp, aZoneFace);
967 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
968 BRepBuilderAPI_MakeVertex aMk(aPnt);
969 aBB.Add(aCmp, aMk.Vertex());
970 BRepTools::Write(aCmp, "FCL2d.brep");
972 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
973 if (State == TopAbs_OUT)
975 else if(State == TopAbs_IN)
977 else if(State == TopAbs_ON)
982 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
983 const QString& thePrefixOrName,
986 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
987 int aTag = aNewLab.Tag();
989 Handle(HYDROData_Region) aNewRegion =
990 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
991 AddRegion( aNewRegion );
993 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
994 aNewRegion->SetName( aRegionName, true );
999 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1001 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1003 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1004 Handle(HYDROData_SplitShapesGroup)::DownCast(
1005 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1006 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1008 aNewGroup->SetName( theName );
1013 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1018 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1019 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1021 QString aGeomObjEntry, anErrorMsg;
1022 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1023 return isOK ? aGeomObjEntry : QString();
1028 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1029 SALOMEDS::Study_ptr theStudy,
1030 QString& theGeomObjEntry,
1031 QString& theErrorMsg ) const
1033 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1035 // Get groups definitions
1036 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1038 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1039 for ( ; anIter.More(); anIter.Next() )
1042 Handle(HYDROData_ShapesGroup) aGroup =
1043 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1044 if ( aGroup.IsNull() )
1047 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1049 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1050 aGroup->GetShapes( aGroupDef.Shapes );
1052 aSeqOfGroupsDefs.Append( aGroupDef );
1056 bool isAllNotSubmersible = true;
1057 TopTools_ListOfShape aFaces;
1058 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1059 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1060 for ( ; aRegionIter.More(); aRegionIter.Next() )
1062 Handle(HYDROData_Region) aRegion =
1063 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1064 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1067 if ( isAllNotSubmersible )
1068 isAllNotSubmersible = false;
1070 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1071 aFaces.Append( aRegionShape );
1076 if ( aCaseRegions.IsEmpty() ) {
1077 theErrorMsg = QString("the list of regions is empty.");
1078 } else if ( isAllNotSubmersible ) {
1079 theErrorMsg = QString("there are no submersible regions.");
1081 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1084 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1086 QString aTelemacFileName = GetName() + ".telemac";
1087 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable() );
1092 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1093 SALOMEDS::Study_ptr theStudy,
1094 const TopTools_ListOfShape& theFaces,
1095 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1096 QString& theGeomObjEntry ) const
1099 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1100 aSewing.SetNonManifoldMode( Standard_False );
1101 #ifdef DEB_CALCULATION
1102 TCollection_AsciiString aNam("Sh_");
1105 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1106 for ( ; aFaceIter.More(); aFaceIter.Next() )
1108 TopoDS_Shape aShape = aFaceIter.Value();
1109 if ( aShape.IsNull() )
1112 if ( aShape.ShapeType() == TopAbs_FACE )
1114 aSewing.Add( aShape );
1115 #ifdef DEB_CALCULATION
1116 TCollection_AsciiString aName = aNam + ++i + ".brep";
1117 BRepTools::Write(aShape ,aName.ToCString());
1122 #ifdef DEB_CALCULATION
1125 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1126 for (; anExp.More(); anExp.Next() ) {
1127 aSewing.Add( anExp.Current() );
1128 #ifdef DEB_CALCULATION
1130 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1131 BRepTools::Write(anExp.Current() ,aName.ToCString());
1138 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1140 // If the sewed shape is empty - return false
1141 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1144 #ifdef DEB_CALCULATION
1145 BRepTools::Write(aSewedShape ,"Sew.brep");
1147 // Publish the sewed shape
1148 QString aName = EXPORT_NAME;
1149 GEOM::GEOM_Object_ptr aMainShape =
1150 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1152 if ( aMainShape->_is_nil() )
1155 if ( theGroupsDefs.IsEmpty() )
1159 TopTools_IndexedMapOfShape aMapOfSubShapes;
1160 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1162 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1164 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1166 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1168 NCollection_Sequence<int> aGroupIndexes;
1169 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1171 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1172 #ifdef DEB_CALCULATION
1173 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1176 TopoDS_Shape aModifiedShape = aShape;
1177 if ( aSewing.IsModified( aShape ) )
1178 aModifiedShape = aSewing.Modified( aShape );
1179 else if ( aSewing.IsModifiedSubShape( aShape ) )
1180 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1182 #ifdef DEB_CALCULATION
1183 const TopLoc_Location& aL1 = aShape.Location();
1184 const TopLoc_Location& aL2 = aModifiedShape.Location();
1185 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1188 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1189 if ( anIndex > 0 ) {
1190 aGroupIndexes.Append( anIndex );
1192 #ifdef DEB_CALCULATION
1193 TCollection_AsciiString aNam("Lost_");
1194 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1195 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1197 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1198 if ( aModifiedShape.IsPartner( aS ) )
1200 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1201 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1202 BRepTools::Write(aS ,aName.ToCString());
1210 if ( !aGroupIndexes.IsEmpty() )
1211 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1214 if ( !aGroupsData.IsEmpty() )
1216 GEOM::GEOM_IGroupOperations_var aGroupOp =
1217 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1219 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1220 for ( ; aMapIt.More(); aMapIt.Next() )
1222 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1223 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1225 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1226 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1229 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1230 aGeomIndexes->length( aGroupIndexes.Length() );
1232 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1233 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1235 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1236 if ( aGroupOp->IsDone() )
1238 SALOMEDS::SObject_var aGroupSO =
1239 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1248 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1249 const bool theIsSetToUpdate )
1251 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1252 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1254 // Indicate model of the need to update splitting
1255 if ( theIsSetToUpdate ) {
1260 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1261 HYDROData_PriorityType thePriority,
1262 const Handle(HYDROData_Entity)& theObject2,
1263 HYDROData_Zone::MergeType theMergeType,
1264 HYDROData_CalculationCase::DataTag theDataTag )
1266 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1267 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1269 // Indicate model of the need to update splitting
1273 QString HYDROData_CalculationCase::DumpRules() const
1275 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1276 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1279 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1281 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1282 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1284 // Indicate model of the need to update splitting
1288 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1290 Handle(TDataStd_Integer) aModeAttr;
1291 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1293 return ( AssignmentMode ) aModeAttr->Get();
1298 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1299 QStringList& theScript ) const
1301 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1302 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1305 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1307 return myLastWarning;
1310 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1312 myLastWarning.Type = theType;
1313 myLastWarning.Data = theData;
1316 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1317 const QString& theOldCaseName,
1318 const QString& theName )
1320 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1321 for ( ; anIter.More(); anIter.Next() )
1323 Handle(HYDROData_Region) aRegion =
1324 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1325 if ( aRegion.IsNull() )
1328 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1330 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1331 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1332 for ( ; anIter.More(); anIter.Next() )
1334 Handle(HYDROData_Zone) aRegZone =
1335 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1336 if ( aRegZone.IsNull() )
1339 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1344 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1345 const QString& thePyScriptPath,
1346 MapOfTreatedObjects& theTreatedObjects,
1347 const HYDROData_SequenceOfObjects& theRegions ) const
1349 HYDROData_SequenceOfObjects::Iterator anIter;
1350 anIter.Init(theRegions);
1351 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1353 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1354 if (aRegion.IsNull())
1356 QString defRegName = this->GetName();
1357 QString regSuffix = QString("_Reg_%1").arg(ireg);
1358 defRegName += regSuffix;
1359 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1360 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1361 theResList << aRegDump;
1363 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1365 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1366 if (aRegion.IsNull())
1368 QStringList aRegDump;
1369 aRegion->SetNameInDumpPython(aRegDump);
1370 theResList << aRegDump;
1374 bool HYDROData_CalculationCase::GetRule( int theIndex,
1375 Handle(HYDROData_Entity)& theObject1,
1376 HYDROData_PriorityType& thePriority,
1377 Handle(HYDROData_Entity)& theObject2,
1378 HYDROData_Zone::MergeType& theMergeType,
1379 HYDROData_CalculationCase::DataTag& theDataTag) const
1381 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1382 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1383 theObject1, thePriority, theObject2, theMergeType );
1386 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1388 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1390 if ( HasReference( theInterPolyline, aDataTag ) )
1393 AddReferenceObject( theInterPolyline, aDataTag );
1398 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1400 return GetReferenceObjects( DataTag_InterPoly );
1403 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1405 if ( theInterPolyline.IsNull() )
1408 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );