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"
21 #include "HYDROData_ArtificialObject.h"
22 #include "HYDROData_IAltitudeObject.h"
23 #include "HYDROData_Document.h"
24 #include "HYDROData_ShapesGroup.h"
25 #include "HYDROData_Iterator.h"
26 #include "HYDROData_NaturalObject.h"
27 #include "HYDROData_PolylineXY.h"
28 #include "HYDROData_StricklerTable.h"
29 #include "HYDROData_LandCover.h"
30 #include "HYDROData_SplittedShapesGroup.h"
31 #include "HYDROData_Region.h"
32 #include "HYDROData_Tool.h"
33 #include "HYDROData_GeomTool.h"
40 #include <TopoDS_Shell.hxx>
41 #include <TopoDS_Edge.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRepBuilderAPI_Sewing.hxx>
45 #include <BRepTopAdaptor_FClass2d.hxx>
47 #include <BRepTools.hxx>
50 #include <TopExp_Explorer.hxx>
52 #include <TopTools_ListOfShape.hxx>
53 #include <TopTools_ListIteratorOfListOfShape.hxx>
54 #include <TDataStd_Integer.hxx>
56 //#define DEB_CALCULATION 1
57 #ifdef DEB_CALCULATION
58 #include <BRepTools.hxx>
59 #include <TopLoc_Location.hxx>
61 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
62 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
63 #define CALCULATION_LANDCOVER_ZONES_PREF GetName() + "_LandCoverZone"
64 #define CALCULATION_GROUPS_PREF GetName() + "_"
65 //#define DEB_CLASS2D 1
67 #include <BRepBuilderAPI_MakeVertex.hxx>
70 #define EXPORT_NAME "HYDRO_" + GetName()
72 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
73 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
75 HYDROData_CalculationCase::HYDROData_CalculationCase()
80 HYDROData_CalculationCase::~HYDROData_CalculationCase()
84 void HYDROData_CalculationCase::SetName( const QString& theName )
86 QString anOldCaseName = GetName();
87 if ( anOldCaseName != theName )
89 // Update names of regions and its zones
90 UpdateRegionsNames( GetRegions( false ), anOldCaseName, theName );
91 // Update names of land cover regions and its zones
92 UpdateRegionsNames( GetRegions( true ), anOldCaseName, theName );
94 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
96 HYDROData_SequenceOfObjects::Iterator anIter;
97 anIter.Init( aGroups );
98 for ( ; anIter.More(); anIter.Next() )
100 Handle(HYDROData_SplittedShapesGroup) aGroup =
101 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
102 if ( aGroup.IsNull() )
105 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
109 HYDROData_Entity::SetName( theName );
112 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
114 QStringList aResList = dumpObjectCreation( theTreatedObjects );
115 aResList.prepend( "# Calculation case" );
117 QString aCalculName = GetObjPyName();
119 AssignmentMode aMode = GetAssignmentMode();
120 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
121 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
123 AssignmentMode aModeLC = GetAssignmentLandCoverMode();
124 QString aModeLCStr = aModeLC==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
125 aResList << QString( "%0.SetAssignmentLandCoverMode( %1 )" ).arg( aCalculName ).arg( aModeLCStr );
127 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
128 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
129 for ( ; anIter.More(); anIter.Next() )
131 Handle(HYDROData_Object) aRefGeomObj =
132 Handle(HYDROData_Object)::DownCast( anIter.Value() );
133 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
135 aResList << QString( "" );
137 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
139 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
140 anIter.Init( aGeomGroups );
141 for ( ; anIter.More(); anIter.Next() )
143 Handle(HYDROData_ShapesGroup) aGeomGroup =
144 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
145 if ( aGeomGroup.IsNull() )
148 Handle(HYDROData_Object) aFatherGeom =
149 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
150 if ( aFatherGeom.IsNull() )
153 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
154 aResList << QString( "%1 = %2.GetGroup( %3 );" )
155 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
157 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
160 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
161 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
163 if( aMode==AUTOMATIC )
164 DumpRulesToPython( aCalculName, aResList );
165 if( aModeLC==AUTOMATIC )
166 DumpLandCoverRulesToPython( aCalculName, aResList );
168 aResList << QString( "" );
169 aResList << "# Start the algorithm of the partition and assignment";
170 aResList << QString( "%1.Update();" ).arg( aCalculName );
174 // Now we restore the
175 // - regions and zones order
176 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) );
179 if( aModeLC==MANUAL )
181 // Now we restore the
182 // - land cover regions and zones order
183 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( true ) );
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 );
256 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions( false );
257 aResSeq.Append( aSeqOfRegions );
259 // Land cover regions
260 HYDROData_SequenceOfObjects aSeqOfLandCoverRegions = GetRegions( true );
261 aResSeq.Append( aSeqOfLandCoverRegions );
266 void HYDROData_CalculationCase::Update()
268 HYDROData_Entity::Update();
271 // At first we remove previously created objects
272 RemoveRegions( false );
273 RemoveRegions( true );
274 RemoveSplittedGroups();
276 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
277 if ( aDocument.IsNull() )
281 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
283 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
284 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
285 if ( !aGeomObjects.IsEmpty() ) {
286 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
288 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
289 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
290 if ( !aSplitObjects.isEmpty() ) {
291 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
292 while( anIter.hasNext() ) {
293 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
294 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
295 aZonesList.append( aSplitData );
296 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
297 anEdgesList.append( aSplitData );
302 // Split to land cover zones
303 HYDROData_SplitToZonesTool::SplitDataList aLandCoverZonesList;
305 HYDROData_SequenceOfObjects aLandCovers = GetLandCovers();
306 if ( !aLandCovers.IsEmpty() ) {
307 HYDROData_SplitToZonesTool::SplitDataList aSplitLandCoverObjects =
308 HYDROData_SplitToZonesTool::Split( aLandCovers );
309 if ( !aSplitLandCoverObjects.isEmpty() ) {
310 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitLandCoverObjects );
311 while( anIter.hasNext() ) {
312 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
313 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
314 aLandCoverZonesList.append( aSplitData );
319 switch( GetAssignmentMode() )
322 CreateRegionsDef( aDocument, aZonesList, false );
325 CreateRegionsAuto( aDocument, aZonesList, false );
329 switch( GetAssignmentLandCoverMode() )
332 CreateRegionsDef( aDocument, aLandCoverZonesList, true );
335 CreateRegionsAuto( aDocument, aLandCoverZonesList, true );
339 CreateEdgeGroupsDef( aDocument, anEdgesList );
342 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
343 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
344 const bool theLandCover )
346 // Create result regions for case, by default one zone for one region
347 QString aRegsPref = CALCULATION_REGIONS_PREF;
348 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
350 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
351 while( anIter.hasNext() )
353 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
355 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref, theLandCover );
357 // Add the zone for region
358 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
362 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
363 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
364 const bool theLandCover )
366 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
367 QMap<QString, QString> aRegionNameToObjNameMap;
368 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
369 HYDROData_PriorityQueue aPr( this, theLandCover ? DataTag_CustomLandCoverRules : DataTag_CustomRules );
371 // 1. First we create a default region for each object included into the calculation case
372 HYDROData_SequenceOfObjects anObjects = theLandCover ? GetLandCovers() : GetGeometryObjects();
373 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
375 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
378 QString anObjName = anObj->GetName();
379 QString aRegName = anObjName + "_reg";
380 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, theLandCover, false );
381 aRegionsMap.insert( anObjName, aRegion );
382 aRegionNameToObjNameMap.insert( aRegName, anObjName );
385 // 2. Now for each zone it is necessary to determine the most priority object
386 // and assign to zone to corresponding region
387 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
388 while( anIter.hasNext() )
390 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
391 HYDROData_Zone::MergeType aMergeType;
392 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
393 if( aRegObj.IsNull() )
395 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
396 if( aRegion.IsNull() )
398 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
400 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
402 qDebug( "Error in algorithm: unresolved conflicts" );
405 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
406 if ( !theLandCover ) {
407 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
408 if ( !aMergeObject.IsNull() ) {
409 aMergeEntity = aMergeObject->GetAltitudeObject();
415 case HYDROData_Zone::Merge_ZMIN:
416 case HYDROData_Zone::Merge_ZMAX:
417 aRegionZone->SetMergeType( aMergeType );
419 case HYDROData_Zone::Merge_Object:
420 aRegionZone->SetMergeType( aMergeType );
421 aRegionZone->RemoveMergeObject();
422 aRegionZone->SetMergeObject( aMergeEntity );
427 QStringList anObjectsWithEmptyRegions;
428 QMap<QString, Handle(HYDROData_Region)>::const_iterator
429 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
430 for( ; anIt!=aLast; anIt++ )
432 Handle(HYDROData_Region) aRegion = anIt.value();
433 if( aRegion->GetZones().IsEmpty() )
435 QString aRegName = aRegion->GetName();
436 QString anObjName = aRegionNameToObjNameMap[aRegName];
437 anObjectsWithEmptyRegions.append( anObjName );
441 if( !anObjectsWithEmptyRegions.empty() )
443 QString aData = anObjectsWithEmptyRegions.join( ", " );
444 SetWarning( WARN_EMPTY_REGIONS, aData );
448 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
449 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
451 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
453 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
454 while( anIter.hasNext() )
456 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
457 // Create new edges group
458 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
461 QString anObjName = aSplitData.ObjectNames.first();
462 if ( anObjName.isEmpty() )
464 #ifdef DEB_CALCULATION
465 QString aStr = aSplitData.ObjectNames.join(" ");
466 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
468 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
469 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
471 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
472 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
476 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
478 if ( aSplittedGroup.IsNull() )
481 aSplittedGroup->AddShape( aSplitData.Shape );
485 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
487 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
488 return false; // Wrong type of object
490 if ( HasReference( theObject, DataTag_GeometryObject ) )
491 return false; // Object is already in reference list
493 AddReferenceObject( theObject, DataTag_GeometryObject );
495 // Indicate model of the need to update splitting
501 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
503 return GetReferenceObjects( DataTag_GeometryObject );
506 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
508 if ( theObject.IsNull() )
511 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
513 // Indicate model of the need to update splitting
517 void HYDROData_CalculationCase::RemoveGeometryObjects()
519 ClearReferenceObjects( DataTag_GeometryObject );
521 // Indicate model of the need to update splitting
525 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
527 if ( theGroup.IsNull() )
530 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
531 return false; // Object is already in reference list
533 AddReferenceObject( theGroup, DataTag_GeometryGroup );
535 // Indicate model of the need to update splitting
541 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
543 return GetReferenceObjects( DataTag_GeometryGroup );
546 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
548 if ( theGroup.IsNull() )
551 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
553 // Indicate model of the need to update splitting
557 void HYDROData_CalculationCase::RemoveGeometryGroups()
559 ClearReferenceObjects( DataTag_GeometryGroup );
561 // Indicate model of the need to update splitting
565 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
567 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
569 SetReferenceObject( thePolyline, DataTag_Polyline );
571 // Indicate model of the need to update zones splitting
572 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
575 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
577 return Handle(HYDROData_PolylineXY)::DownCast(
578 GetReferenceObject( DataTag_Polyline ) );
581 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
583 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
585 ClearReferenceObjects( DataTag_Polyline );
587 // Indicate model of the need to update zones splitting
588 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
591 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
593 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
595 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
597 // Indicate model of the need to update land covers partition
598 SetToUpdate( !IsEqual( aPrevStricklerTable, theStricklerTable ) || IsMustBeUpdated() );
601 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
603 return Handle(HYDROData_StricklerTable)::DownCast(
604 GetReferenceObject( DataTag_StricklerTable ) );
607 void HYDROData_CalculationCase::RemoveStricklerTable()
609 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
611 ClearReferenceObjects( DataTag_StricklerTable );
613 // Indicate model of the need to update land covers partition
614 SetToUpdate( !aPrevStricklerTable.IsNull() || IsMustBeUpdated() );
617 bool HYDROData_CalculationCase::AddLandCover( const Handle(HYDROData_LandCover)& theLandCover )
619 if ( HasReference( theLandCover, DataTag_LandCover ) )
620 return false; // Land cover is already in reference list
622 AddReferenceObject( theLandCover, DataTag_LandCover );
624 // Indicate model of the need to update land covers partition
630 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetLandCovers() const
632 return GetReferenceObjects( DataTag_LandCover );
635 void HYDROData_CalculationCase::RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover )
637 if ( theLandCover.IsNull() )
640 RemoveReferenceObject( theLandCover->Label(), DataTag_LandCover );
642 // Indicate model of the need to update land cover partition
646 void HYDROData_CalculationCase::RemoveLandCovers()
648 ClearReferenceObjects( DataTag_LandCover );
650 // Indicate model of the need to update land cover partition
654 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone,
655 const bool theLandCover )
657 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
658 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
659 if ( aNewRegion.IsNull() )
662 aNewRegion->AddZone( theZone );
667 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion,
668 const bool theLandCover )
670 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
672 if ( theRegion.IsNull() )
675 HYDROData_CalculationCase::DataTag aDataTag =
676 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
678 if ( HasReference( theRegion, aDataTag ) )
679 return false; // Object is already in reference list
681 // Move the region from other calculation
682 Handle(HYDROData_CalculationCase) aFatherCalc =
683 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
684 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
686 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
687 theRegion->CopyTo( aNewRegion );
689 aFatherCalc->RemoveRegion( theRegion, theLandCover );
691 theRegion->SetLabel( aNewRegion->Label() );
695 AddReferenceObject( theRegion, aDataTag );
701 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions( const bool theLandCover ) const
703 return GetReferenceObjects( theLandCover ? DataTag_LandCoverRegion : DataTag_Region );
706 void HYDROData_CalculationCase::UpdateRegionsOrder()
708 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
709 if ( aDocument.IsNull() )
712 HYDROData_SequenceOfObjects aRegions = GetRegions( false );
713 HYDROData_SequenceOfObjects aRegionsLC = GetRegions( true );
714 aRegions.Append( aRegionsLC );
716 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
717 for ( ; anIter.More(); anIter.Next() )
719 Handle(HYDROData_Region) aRegion =
720 Handle(HYDROData_Region)::DownCast( anIter.Value() );
721 if ( aRegion.IsNull() )
724 aRegion->SetName( "" );
727 QString aRegsPref = CALCULATION_REGIONS_PREF;
729 anIter.Init( aRegions );
730 for ( ; anIter.More(); anIter.Next() )
732 Handle(HYDROData_Region) aRegion =
733 Handle(HYDROData_Region)::DownCast( anIter.Value() );
734 if ( aRegion.IsNull() )
737 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
738 aRegion->SetName( aRegionName );
742 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion,
743 const bool theLandCover )
745 if ( theRegion.IsNull() )
748 HYDROData_CalculationCase::DataTag aDataTag =
749 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
750 RemoveReferenceObject( theRegion->Label(), aDataTag );
752 // Remove region from data model
753 Handle(HYDROData_CalculationCase) aFatherCalc =
754 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
755 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
759 void HYDROData_CalculationCase::RemoveRegions( const bool theLandCover )
761 myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).ForgetAllAttributes();
764 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
766 return GetReferenceObjects( DataTag_SplittedGroups );
769 void HYDROData_CalculationCase::RemoveSplittedGroups()
771 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
774 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
776 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
777 return GetAltitudeForPoint( thePoint, aZone );
780 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
781 const Handle(HYDROData_Region)& theRegion ) const
783 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
785 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
786 if ( !aZone.IsNull() )
788 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
789 if ( IsEqual( aRefRegion, theRegion ) )
790 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
796 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
797 const Handle(HYDROData_Zone)& theZone ) const
799 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
800 if ( theZone.IsNull() )
803 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
804 if ( !theZone->IsMergingNeed() )
806 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
808 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
813 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
814 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
816 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
817 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
818 if ( !aMergeAltitude.IsNull() )
820 if ( aZoneInterpolator != NULL )
822 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
823 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
826 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
831 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
832 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
833 for ( ; anIter.More(); anIter.Next() )
835 Handle(HYDROData_Object) aZoneObj =
836 Handle(HYDROData_Object)::DownCast( anIter.Value() );
837 if ( aZoneObj.IsNull() )
840 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
841 if ( anObjAltitude.IsNull() )
844 double aPointAltitude = 0.0;
845 if ( aZoneInterpolator != NULL )
847 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
848 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
851 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
853 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
856 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
858 aResAltitude = aPointAltitude;
861 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
863 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
864 aResAltitude > aPointAltitude )
866 aResAltitude = aPointAltitude;
869 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
871 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
872 aResAltitude < aPointAltitude )
874 aResAltitude = aPointAltitude;
883 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
884 const NCollection_Sequence<gp_XY>& thePoints,
885 const Handle(HYDROData_Region)& theRegion ) const
887 NCollection_Sequence<double> aResSeq;
889 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
891 const gp_XY& thePnt = thePoints.Value( i );
893 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
894 aResSeq.Append( anAltitude );
900 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
901 const NCollection_Sequence<gp_XY>& thePoints,
902 const Handle(HYDROData_Zone)& theZone ) const
904 NCollection_Sequence<double> aResSeq;
906 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
908 const gp_XY& thePnt = thePoints.Value( i );
910 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
911 aResSeq.Append( anAltitude );
917 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint,
918 const bool theLandCover ) const
920 Handle(HYDROData_Region) aResRegion;
922 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, theLandCover );
923 if ( !aZone.IsNull() )
924 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
929 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint,
930 const bool theLandCover ) const
932 Handle(HYDROData_Zone) aResZone;
934 HYDROData_SequenceOfObjects aRegions = GetRegions( theLandCover );
936 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
937 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
939 Handle(HYDROData_Region) aRegion =
940 Handle(HYDROData_Region)::DownCast( anIter.Value() );
941 if ( aRegion.IsNull() )
944 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
945 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
946 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
948 Handle(HYDROData_Zone) aRegZone =
949 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
950 if ( aRegZone.IsNull() )
953 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
954 if ( aPointRelation != POINT_OUT )
955 aResZone = aRegZone; // We found the desired zone
962 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
963 const gp_XY& thePoint,
964 const Handle(HYDROData_Zone)& theZone ) const
966 PointClassification aRes = POINT_OUT;
967 if ( theZone.IsNull() )
970 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
971 if ( aZoneFace.IsNull() )
974 TopoDS_Compound aCmp;
976 aBB.MakeCompound(aCmp);
977 aBB.Add(aCmp, aZoneFace);
978 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
979 BRepBuilderAPI_MakeVertex aMk(aPnt);
980 aBB.Add(aCmp, aMk.Vertex());
981 BRepTools::Write(aCmp, "FCL2d.brep");
983 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
984 if (State == TopAbs_OUT)
986 else if(State == TopAbs_IN)
988 else if(State == TopAbs_ON)
993 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
994 const QString& thePrefixOrName,
995 const bool theLandCover,
998 TDF_Label aNewLab = myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).NewChild();
999 int aTag = aNewLab.Tag();
1001 Handle(HYDROData_Region) aNewRegion =
1002 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1003 AddRegion( aNewRegion, theLandCover );
1005 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1006 aNewRegion->SetName( aRegionName );
1011 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
1013 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
1015 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
1016 Handle(HYDROData_SplittedShapesGroup)::DownCast(
1017 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
1018 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
1020 aNewGroup->SetName( theName );
1025 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1027 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1028 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1030 QString aGeomObjEntry, anErrorMsg;
1031 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1032 return isOK ? aGeomObjEntry : QString();
1035 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1036 SALOMEDS::Study_ptr theStudy,
1037 QString& theGeomObjEntry,
1038 QString& theErrorMsg ) const
1040 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1042 // Get groups definitions
1043 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
1045 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
1046 for ( ; anIter.More(); anIter.Next() )
1049 Handle(HYDROData_ShapesGroup) aGroup =
1050 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1051 if ( aGroup.IsNull() )
1054 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1056 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1057 aGroup->GetShapes( aGroupDef.Shapes );
1059 aSeqOfGroupsDefs.Append( aGroupDef );
1063 bool isAllNotSubmersible = true;
1064 TopTools_ListOfShape aFaces;
1065 HYDROData_SequenceOfObjects aCaseRegions = GetRegions( false );
1066 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1067 for ( ; aRegionIter.More(); aRegionIter.Next() )
1069 Handle(HYDROData_Region) aRegion =
1070 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1071 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1074 if ( isAllNotSubmersible )
1075 isAllNotSubmersible = false;
1077 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1078 aFaces.Append( aRegionShape );
1083 if ( aCaseRegions.IsEmpty() ) {
1084 theErrorMsg = QString("the list of regions is empty.");
1085 } else if ( isAllNotSubmersible ) {
1086 theErrorMsg = QString("there are no submersible regions.");
1088 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1094 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1095 SALOMEDS::Study_ptr theStudy,
1096 const TopTools_ListOfShape& theFaces,
1097 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1098 QString& theGeomObjEntry ) const
1101 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1102 aSewing.SetNonManifoldMode( Standard_False );
1103 #ifdef DEB_CALCULATION
1104 TCollection_AsciiString aNam("Sh_");
1107 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1108 for ( ; aFaceIter.More(); aFaceIter.Next() )
1110 TopoDS_Shape aShape = aFaceIter.Value();
1111 if ( aShape.IsNull() )
1114 if ( aShape.ShapeType() == TopAbs_FACE )
1116 aSewing.Add( aShape );
1117 #ifdef DEB_CALCULATION
1118 TCollection_AsciiString aName = aNam + ++i + ".brep";
1119 BRepTools::Write(aShape ,aName.ToCString());
1124 #ifdef DEB_CALCULATION
1127 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1128 for (; anExp.More(); anExp.Next() ) {
1129 aSewing.Add( anExp.Current() );
1130 #ifdef DEB_CALCULATION
1132 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1133 BRepTools::Write(anExp.Current() ,aName.ToCString());
1140 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1142 // If the sewed shape is empty - return false
1143 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1146 #ifdef DEB_CALCULATION
1147 BRepTools::Write(aSewedShape ,"Sew.brep");
1149 // Publish the sewed shape
1150 QString aName = EXPORT_NAME;
1151 GEOM::GEOM_Object_ptr aMainShape =
1152 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1154 if ( aMainShape->_is_nil() )
1157 if ( theGroupsDefs.IsEmpty() )
1161 TopTools_IndexedMapOfShape aMapOfSubShapes;
1162 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1164 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1166 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1168 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1170 NCollection_Sequence<int> aGroupIndexes;
1171 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1173 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1174 #ifdef DEB_CALCULATION
1175 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1178 TopoDS_Shape aModifiedShape = aShape;
1179 if ( aSewing.IsModified( aShape ) )
1180 aModifiedShape = aSewing.Modified( aShape );
1181 else if ( aSewing.IsModifiedSubShape( aShape ) )
1182 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1184 #ifdef DEB_CALCULATION
1185 const TopLoc_Location& aL1 = aShape.Location();
1186 const TopLoc_Location& aL2 = aModifiedShape.Location();
1187 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1190 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1191 if ( anIndex > 0 ) {
1192 aGroupIndexes.Append( anIndex );
1194 #ifdef DEB_CALCULATION
1195 TCollection_AsciiString aNam("Lost_");
1196 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1197 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1199 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1200 if ( aModifiedShape.IsPartner( aS ) )
1202 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1203 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1204 BRepTools::Write(aS ,aName.ToCString());
1212 if ( !aGroupIndexes.IsEmpty() )
1213 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1216 if ( !aGroupsData.IsEmpty() )
1218 GEOM::GEOM_IGroupOperations_var aGroupOp =
1219 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1221 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1222 for ( ; aMapIt.More(); aMapIt.Next() )
1224 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1225 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1227 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1228 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1231 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1232 aGeomIndexes->length( aGroupIndexes.Length() );
1234 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1235 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1237 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1238 if ( aGroupOp->IsDone() )
1240 SALOMEDS::SObject_var aGroupSO =
1241 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1249 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1250 const bool theIsSetToUpdate )
1252 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1253 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1255 // Indicate model of the need to update splitting
1256 if ( theIsSetToUpdate ) {
1257 SetToUpdate( true );
1261 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1262 HYDROData_PriorityType thePriority,
1263 const Handle(HYDROData_Entity)& theObject2,
1264 HYDROData_Zone::MergeType theMergeType,
1265 HYDROData_CalculationCase::DataTag theDataTag )
1267 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1268 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1270 // Indicate model of the need to update splitting
1271 SetToUpdate( true );
1274 QString HYDROData_CalculationCase::DumpRules() const
1276 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1277 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1280 QString HYDROData_CalculationCase::DumpLandCoverRules() const
1282 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1283 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1286 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1288 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1289 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1291 // Indicate model of the need to update splitting
1292 SetToUpdate( true );
1295 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1297 Handle(TDataStd_Integer) aModeAttr;
1298 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1300 return ( AssignmentMode ) aModeAttr->Get();
1305 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1306 QStringList& theScript ) const
1308 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1309 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1312 void HYDROData_CalculationCase::DumpLandCoverRulesToPython( const QString& theCalcCaseName,
1313 QStringList& theScript ) const
1315 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1316 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1319 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1321 return myLastWarning;
1324 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1326 myLastWarning.Type = theType;
1327 myLastWarning.Data = theData;
1330 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1331 const QString& theOldCaseName,
1332 const QString& theName )
1334 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1335 for ( ; anIter.More(); anIter.Next() )
1337 Handle(HYDROData_Region) aRegion =
1338 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1339 if ( aRegion.IsNull() )
1342 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1344 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1345 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1346 for ( ; anIter.More(); anIter.Next() )
1348 Handle(HYDROData_Zone) aRegZone =
1349 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1350 if ( aRegZone.IsNull() )
1353 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1358 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1359 MapOfTreatedObjects& theTreatedObjects,
1360 const HYDROData_SequenceOfObjects& theRegions ) const
1362 HYDROData_SequenceOfObjects::Iterator anIter;
1363 anIter.Init( theRegions );
1364 for ( ; anIter.More(); anIter.Next() )
1366 Handle(HYDROData_Region) aRegion =
1367 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1368 if ( aRegion.IsNull() )
1371 theTreatedObjects.insert( aRegion->GetName(), aRegion );
1372 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
1373 theResList << aRegDump;
1377 bool HYDROData_CalculationCase::GetRule( int theIndex,
1378 Handle(HYDROData_Entity)& theObject1,
1379 HYDROData_PriorityType& thePriority,
1380 Handle(HYDROData_Entity)& theObject2,
1381 HYDROData_Zone::MergeType& theMergeType,
1382 HYDROData_CalculationCase::DataTag& theDataTag) const
1384 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1385 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1386 theObject1, thePriority, theObject2, theMergeType );
1389 void HYDROData_CalculationCase::SetAssignmentLandCoverMode( AssignmentMode theMode )
1391 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentLandCoverMode );
1392 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1394 // Indicate model of the need to update land covers partition
1395 SetToUpdate( true );
1398 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentLandCoverMode() const
1400 Handle(TDataStd_Integer) aModeAttr;
1401 bool isOK = myLab.FindChild( DataTag_AssignmentLandCoverMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1403 return ( AssignmentMode ) aModeAttr->Get();