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 #include <SALOME_NamingService.hxx>
73 #include <SALOME_LifeCycleCORBA.hxx>
76 #include "HYDRO_trace.hxx"
78 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
79 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
81 HYDROData_CalculationCase::HYDROData_CalculationCase()
86 HYDROData_CalculationCase::~HYDROData_CalculationCase()
90 void HYDROData_CalculationCase::SetName( const QString& theName )
92 QString anOldCaseName = GetName();
93 if ( anOldCaseName != theName )
95 // Update names of regions and its zones
96 UpdateRegionsNames( GetRegions( false ), anOldCaseName, theName );
97 // Update names of land cover regions and its zones
98 UpdateRegionsNames( GetRegions( true ), anOldCaseName, theName );
100 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
102 HYDROData_SequenceOfObjects::Iterator anIter;
103 anIter.Init( aGroups );
104 for ( ; anIter.More(); anIter.Next() )
106 Handle(HYDROData_SplittedShapesGroup) aGroup =
107 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
108 if ( aGroup.IsNull() )
111 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
115 HYDROData_Entity::SetName( theName );
118 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
120 QStringList aResList = dumpObjectCreation( theTreatedObjects );
121 aResList.prepend( "# Calculation case" );
123 QString aCalculName = GetObjPyName();
125 AssignmentMode aMode = GetAssignmentMode();
126 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
127 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
129 AssignmentMode aModeLC = GetAssignmentLandCoverMode();
130 QString aModeLCStr = aModeLC==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
131 aResList << QString( "%0.SetAssignmentLandCoverMode( %1 )" ).arg( aCalculName ).arg( aModeLCStr );
133 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
134 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
135 for ( ; anIter.More(); anIter.Next() )
137 Handle(HYDROData_Object) aRefGeomObj =
138 Handle(HYDROData_Object)::DownCast( anIter.Value() );
139 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
141 aResList << QString( "" );
143 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
145 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
146 anIter.Init( aGeomGroups );
147 for ( ; anIter.More(); anIter.Next() )
149 Handle(HYDROData_ShapesGroup) aGeomGroup =
150 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
151 if ( aGeomGroup.IsNull() )
154 Handle(HYDROData_Object) aFatherGeom =
155 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
156 if ( aFatherGeom.IsNull() )
159 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
160 aResList << QString( "%1 = %2.GetGroup( %3 );" )
161 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
163 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
166 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
167 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
169 if( aMode==AUTOMATIC )
170 DumpRulesToPython( aCalculName, aResList );
171 if( aModeLC==AUTOMATIC )
172 DumpLandCoverRulesToPython( aCalculName, aResList );
174 aResList << QString( "" );
175 aResList << "# Start the algorithm of the partition and assignment";
176 aResList << QString( "%1.Update();" ).arg( aCalculName );
180 // Now we restore the
181 // - regions and zones order
182 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) );
185 if( aModeLC==MANUAL )
187 // Now we restore the
188 // - land cover regions and zones order
189 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( true ) );
192 // Export calculation case
193 aResList << QString( "" );
194 aResList << "# Export of the calculation case";
195 QString aStudyName = "theStudy";
196 QString anEntryVar = aCalculName + "_entry";
197 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
199 // Get geometry object and print debug information
201 aResList << "# Get geometry shape and print debug information";
202 aResList << "import GEOM";
203 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
204 QString aGeomShapeName = aCalculName + "_geom";
205 aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
206 aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
207 aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
209 DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
211 aResList << QString( "" );
215 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
216 const QString& theStudyName,
217 const QString& theGeomShapeName,
218 const QString& theMeshName ) const
221 theResList << "# Meshing";
222 theResList << "import SMESH, SALOMEDS";
223 theResList << "from salome.smesh import smeshBuilder";
224 theResList << "from salome.geom import geomBuilder";
226 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
227 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
228 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
229 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
230 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
231 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
232 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
235 theResList << "# Set names of Mesh objects";
236 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
237 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
238 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
239 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
240 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
243 theResList << "# Greate SMESH groups";
244 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
245 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
246 theResList << QString( "for group in geom_groups:" );
247 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
249 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
250 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
253 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
255 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
257 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
258 if ( !aBoundaryPolyline.IsNull() )
259 aResSeq.Append( aBoundaryPolyline );
262 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions( false );
263 aResSeq.Append( aSeqOfRegions );
265 // Land cover regions
266 HYDROData_SequenceOfObjects aSeqOfLandCoverRegions = GetRegions( true );
267 aResSeq.Append( aSeqOfLandCoverRegions );
272 void HYDROData_CalculationCase::Update()
274 HYDROData_Entity::Update();
277 // At first we remove previously created objects
278 RemoveRegions( false );
279 RemoveRegions( true );
280 RemoveSplittedGroups();
282 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
283 if ( aDocument.IsNull() )
287 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
289 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
290 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
291 if ( !aGeomObjects.IsEmpty() ) {
292 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
294 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
295 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
296 if ( !aSplitObjects.isEmpty() ) {
297 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
298 while( anIter.hasNext() ) {
299 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
300 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
301 aZonesList.append( aSplitData );
302 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
303 anEdgesList.append( aSplitData );
308 // Split to land cover zones
309 HYDROData_SplitToZonesTool::SplitDataList aLandCoverZonesList;
311 HYDROData_SequenceOfObjects aLandCovers = GetLandCovers();
312 if ( !aLandCovers.IsEmpty() ) {
313 HYDROData_SplitToZonesTool::SplitDataList aSplitLandCoverObjects =
314 HYDROData_SplitToZonesTool::Split( aLandCovers );
315 if ( !aSplitLandCoverObjects.isEmpty() ) {
316 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitLandCoverObjects );
317 while( anIter.hasNext() ) {
318 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
319 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
320 aLandCoverZonesList.append( aSplitData );
325 switch( GetAssignmentMode() )
328 CreateRegionsDef( aDocument, aZonesList, false );
331 CreateRegionsAuto( aDocument, aZonesList, false );
335 switch( GetAssignmentLandCoverMode() )
338 CreateRegionsDef( aDocument, aLandCoverZonesList, true );
341 CreateRegionsAuto( aDocument, aLandCoverZonesList, true );
345 CreateEdgeGroupsDef( aDocument, anEdgesList );
348 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
349 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
350 const bool theLandCover )
352 // Create result regions for case, by default one zone for one region
353 QString aRegsPref = CALCULATION_REGIONS_PREF;
354 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
356 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
357 while( anIter.hasNext() )
359 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
361 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref, theLandCover );
363 // Add the zone for region
364 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
368 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
369 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
370 const bool theLandCover )
372 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
373 QMap<QString, QString> aRegionNameToObjNameMap;
374 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
375 HYDROData_PriorityQueue aPr( this, theLandCover ? DataTag_CustomLandCoverRules : DataTag_CustomRules );
377 // 1. First we create a default region for each object included into the calculation case
378 HYDROData_SequenceOfObjects anObjects = theLandCover ? GetLandCovers() : GetGeometryObjects();
379 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
381 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
384 QString anObjName = anObj->GetName();
385 QString aRegName = anObjName + "_reg";
386 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, theLandCover, false );
387 aRegionsMap.insert( anObjName, aRegion );
388 aRegionNameToObjNameMap.insert( aRegName, anObjName );
391 // 2. Now for each zone it is necessary to determine the most priority object
392 // and assign to zone to corresponding region
393 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
394 while( anIter.hasNext() )
396 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
397 HYDROData_Zone::MergeType aMergeType;
398 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
399 if( aRegObj.IsNull() )
401 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
402 if( aRegion.IsNull() )
404 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
406 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
408 qDebug( "Error in algorithm: unresolved conflicts" );
411 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
412 if ( !theLandCover ) {
413 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
414 if ( !aMergeObject.IsNull() ) {
415 aMergeEntity = aMergeObject->GetAltitudeObject();
421 case HYDROData_Zone::Merge_ZMIN:
422 case HYDROData_Zone::Merge_ZMAX:
423 aRegionZone->SetMergeType( aMergeType );
425 case HYDROData_Zone::Merge_Object:
426 aRegionZone->SetMergeType( aMergeType );
427 aRegionZone->RemoveMergeObject();
428 aRegionZone->SetMergeObject( aMergeEntity );
433 QStringList anObjectsWithEmptyRegions;
434 QMap<QString, Handle(HYDROData_Region)>::const_iterator
435 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
436 for( ; anIt!=aLast; anIt++ )
438 Handle(HYDROData_Region) aRegion = anIt.value();
439 if( aRegion->GetZones().IsEmpty() )
441 QString aRegName = aRegion->GetName();
442 QString anObjName = aRegionNameToObjNameMap[aRegName];
443 anObjectsWithEmptyRegions.append( anObjName );
447 if( !anObjectsWithEmptyRegions.empty() )
449 QString aData = anObjectsWithEmptyRegions.join( ", " );
450 SetWarning( WARN_EMPTY_REGIONS, aData );
454 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
455 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
457 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
459 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
460 while( anIter.hasNext() )
462 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
463 // Create new edges group
464 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
467 QString anObjName = aSplitData.ObjectNames.first();
468 if ( anObjName.isEmpty() )
470 #ifdef DEB_CALCULATION
471 QString aStr = aSplitData.ObjectNames.join(" ");
472 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
474 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
475 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
477 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
478 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
482 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
484 if ( aSplittedGroup.IsNull() )
487 aSplittedGroup->AddShape( aSplitData.Shape );
491 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
493 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
494 return false; // Wrong type of object
496 if ( HasReference( theObject, DataTag_GeometryObject ) )
497 return false; // Object is already in reference list
499 AddReferenceObject( theObject, DataTag_GeometryObject );
501 // Indicate model of the need to update splitting
507 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
509 return GetReferenceObjects( DataTag_GeometryObject );
512 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
514 if ( theObject.IsNull() )
517 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
519 // Indicate model of the need to update splitting
523 void HYDROData_CalculationCase::RemoveGeometryObjects()
525 ClearReferenceObjects( DataTag_GeometryObject );
527 // Indicate model of the need to update splitting
531 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
533 if ( theGroup.IsNull() )
536 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
537 return false; // Object is already in reference list
539 AddReferenceObject( theGroup, DataTag_GeometryGroup );
541 // Indicate model of the need to update splitting
547 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
549 return GetReferenceObjects( DataTag_GeometryGroup );
552 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
554 if ( theGroup.IsNull() )
557 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
559 // Indicate model of the need to update splitting
563 void HYDROData_CalculationCase::RemoveGeometryGroups()
565 ClearReferenceObjects( DataTag_GeometryGroup );
567 // Indicate model of the need to update splitting
571 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
573 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
575 SetReferenceObject( thePolyline, DataTag_Polyline );
577 // Indicate model of the need to update zones splitting
578 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
581 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
583 return Handle(HYDROData_PolylineXY)::DownCast(
584 GetReferenceObject( DataTag_Polyline ) );
587 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
589 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
591 ClearReferenceObjects( DataTag_Polyline );
593 // Indicate model of the need to update zones splitting
594 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
597 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
599 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
601 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
603 // Indicate model of the need to update land covers partition
604 SetToUpdate( !IsEqual( aPrevStricklerTable, theStricklerTable ) || IsMustBeUpdated() );
607 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
609 return Handle(HYDROData_StricklerTable)::DownCast(
610 GetReferenceObject( DataTag_StricklerTable ) );
613 void HYDROData_CalculationCase::RemoveStricklerTable()
615 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
617 ClearReferenceObjects( DataTag_StricklerTable );
619 // Indicate model of the need to update land covers partition
620 SetToUpdate( !aPrevStricklerTable.IsNull() || IsMustBeUpdated() );
623 bool HYDROData_CalculationCase::AddLandCover( const Handle(HYDROData_LandCover)& theLandCover )
625 if ( HasReference( theLandCover, DataTag_LandCover ) )
626 return false; // Land cover is already in reference list
628 AddReferenceObject( theLandCover, DataTag_LandCover );
630 // Indicate model of the need to update land covers partition
636 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetLandCovers() const
638 return GetReferenceObjects( DataTag_LandCover );
641 void HYDROData_CalculationCase::RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover )
643 if ( theLandCover.IsNull() )
646 RemoveReferenceObject( theLandCover->Label(), DataTag_LandCover );
648 // Indicate model of the need to update land cover partition
652 void HYDROData_CalculationCase::RemoveLandCovers()
654 ClearReferenceObjects( DataTag_LandCover );
656 // Indicate model of the need to update land cover partition
660 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone,
661 const bool theLandCover )
663 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
664 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
665 if ( aNewRegion.IsNull() )
668 aNewRegion->AddZone( theZone );
673 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion,
674 const bool theLandCover )
676 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
678 if ( theRegion.IsNull() )
681 HYDROData_CalculationCase::DataTag aDataTag =
682 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
684 if ( HasReference( theRegion, aDataTag ) )
685 return false; // Object is already in reference list
687 // Move the region from other calculation
688 Handle(HYDROData_CalculationCase) aFatherCalc =
689 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
690 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
692 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
693 theRegion->CopyTo( aNewRegion );
695 aFatherCalc->RemoveRegion( theRegion, theLandCover );
697 theRegion->SetLabel( aNewRegion->Label() );
701 AddReferenceObject( theRegion, aDataTag );
707 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions( const bool theLandCover ) const
709 return GetReferenceObjects( theLandCover ? DataTag_LandCoverRegion : DataTag_Region );
712 void HYDROData_CalculationCase::UpdateRegionsOrder()
714 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
715 if ( aDocument.IsNull() )
718 HYDROData_SequenceOfObjects aRegions = GetRegions( false );
719 HYDROData_SequenceOfObjects aRegionsLC = GetRegions( true );
720 aRegions.Append( aRegionsLC );
722 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
723 for ( ; anIter.More(); anIter.Next() )
725 Handle(HYDROData_Region) aRegion =
726 Handle(HYDROData_Region)::DownCast( anIter.Value() );
727 if ( aRegion.IsNull() )
730 aRegion->SetName( "" );
733 QString aRegsPref = CALCULATION_REGIONS_PREF;
735 anIter.Init( aRegions );
736 for ( ; anIter.More(); anIter.Next() )
738 Handle(HYDROData_Region) aRegion =
739 Handle(HYDROData_Region)::DownCast( anIter.Value() );
740 if ( aRegion.IsNull() )
743 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
744 aRegion->SetName( aRegionName );
748 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion,
749 const bool theLandCover )
751 if ( theRegion.IsNull() )
754 HYDROData_CalculationCase::DataTag aDataTag =
755 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
756 RemoveReferenceObject( theRegion->Label(), aDataTag );
758 // Remove region from data model
759 Handle(HYDROData_CalculationCase) aFatherCalc =
760 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
761 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
765 void HYDROData_CalculationCase::RemoveRegions( const bool theLandCover )
767 myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).ForgetAllAttributes();
770 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
772 return GetReferenceObjects( DataTag_SplittedGroups );
775 void HYDROData_CalculationCase::RemoveSplittedGroups()
777 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
780 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
782 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
783 return GetAltitudeForPoint( thePoint, aZone );
786 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
787 const Handle(HYDROData_Region)& theRegion ) const
789 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
791 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
792 if ( !aZone.IsNull() )
794 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
795 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
796 if ( IsEqual( aRefRegion, theRegion ) )
797 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
800 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
801 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
806 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
812 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
813 const Handle(HYDROData_Zone)& theZone ) const
815 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
816 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
817 if ( theZone.IsNull() )
820 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
821 if ( !theZone->IsMergingNeed() )
823 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
825 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
830 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
831 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
833 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
834 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
835 if ( !aMergeAltitude.IsNull() )
837 if ( aZoneInterpolator != NULL )
839 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
840 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
843 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
848 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
849 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
850 for ( ; anIter.More(); anIter.Next() )
852 Handle(HYDROData_Object) aZoneObj =
853 Handle(HYDROData_Object)::DownCast( anIter.Value() );
854 if ( aZoneObj.IsNull() )
857 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
858 if ( anObjAltitude.IsNull() )
861 double aPointAltitude = 0.0;
862 if ( aZoneInterpolator != NULL )
864 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
865 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
868 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
870 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
873 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
875 aResAltitude = aPointAltitude;
878 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
880 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
881 aResAltitude > aPointAltitude )
883 aResAltitude = aPointAltitude;
886 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
888 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
889 aResAltitude < aPointAltitude )
891 aResAltitude = aPointAltitude;
900 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
901 const NCollection_Sequence<gp_XY>& thePoints,
902 const Handle(HYDROData_Region)& theRegion ) const
904 //DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
905 NCollection_Sequence<double> aResSeq;
907 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
909 const gp_XY& thePnt = thePoints.Value( i );
911 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
912 aResSeq.Append( anAltitude );
918 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
919 const NCollection_Sequence<gp_XY>& thePoints,
920 const Handle(HYDROData_Zone)& theZone ) const
922 NCollection_Sequence<double> aResSeq;
924 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
926 const gp_XY& thePnt = thePoints.Value( i );
928 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
929 aResSeq.Append( anAltitude );
935 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint,
936 const bool theLandCover ) const
938 Handle(HYDROData_Region) aResRegion;
940 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, theLandCover );
941 if ( !aZone.IsNull() )
942 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
947 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint,
948 const bool theLandCover ) const
950 Handle(HYDROData_Zone) aResZone;
952 HYDROData_SequenceOfObjects aRegions = GetRegions( theLandCover );
954 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
955 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
957 Handle(HYDROData_Region) aRegion =
958 Handle(HYDROData_Region)::DownCast( anIter.Value() );
959 if ( aRegion.IsNull() )
962 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
963 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
964 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
966 Handle(HYDROData_Zone) aRegZone =
967 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
968 if ( aRegZone.IsNull() )
971 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
972 if ( aPointRelation != POINT_OUT )
973 aResZone = aRegZone; // We found the desired zone
980 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
981 const gp_XY& thePoint,
982 const Handle(HYDROData_Zone)& theZone ) const
984 PointClassification aRes = POINT_OUT;
985 if ( theZone.IsNull() )
988 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
989 if ( aZoneFace.IsNull() )
992 TopoDS_Compound aCmp;
994 aBB.MakeCompound(aCmp);
995 aBB.Add(aCmp, aZoneFace);
996 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
997 BRepBuilderAPI_MakeVertex aMk(aPnt);
998 aBB.Add(aCmp, aMk.Vertex());
999 BRepTools::Write(aCmp, "FCL2d.brep");
1001 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1002 if (State == TopAbs_OUT)
1004 else if(State == TopAbs_IN)
1006 else if(State == TopAbs_ON)
1011 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1012 const QString& thePrefixOrName,
1013 const bool theLandCover,
1016 TDF_Label aNewLab = myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).NewChild();
1017 int aTag = aNewLab.Tag();
1019 Handle(HYDROData_Region) aNewRegion =
1020 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1021 AddRegion( aNewRegion, theLandCover );
1023 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1024 aNewRegion->SetName( aRegionName );
1029 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
1031 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
1033 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
1034 Handle(HYDROData_SplittedShapesGroup)::DownCast(
1035 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
1036 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
1038 aNewGroup->SetName( theName );
1043 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1045 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1046 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1048 QString aGeomObjEntry, anErrorMsg;
1049 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1050 return isOK ? aGeomObjEntry : QString();
1053 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1054 SALOMEDS::Study_ptr theStudy,
1055 QString& theGeomObjEntry,
1056 QString& theErrorMsg ) const
1058 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1060 // Get groups definitions
1061 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
1063 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
1064 for ( ; anIter.More(); anIter.Next() )
1067 Handle(HYDROData_ShapesGroup) aGroup =
1068 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1069 if ( aGroup.IsNull() )
1072 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1074 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1075 aGroup->GetShapes( aGroupDef.Shapes );
1077 aSeqOfGroupsDefs.Append( aGroupDef );
1081 bool isAllNotSubmersible = true;
1082 TopTools_ListOfShape aFaces;
1083 HYDROData_SequenceOfObjects aCaseRegions = GetRegions( false );
1084 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1085 for ( ; aRegionIter.More(); aRegionIter.Next() )
1087 Handle(HYDROData_Region) aRegion =
1088 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1089 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1092 if ( isAllNotSubmersible )
1093 isAllNotSubmersible = false;
1095 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1096 aFaces.Append( aRegionShape );
1101 if ( aCaseRegions.IsEmpty() ) {
1102 theErrorMsg = QString("the list of regions is empty.");
1103 } else if ( isAllNotSubmersible ) {
1104 theErrorMsg = QString("there are no submersible regions.");
1106 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1112 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1113 SALOMEDS::Study_ptr theStudy,
1114 const TopTools_ListOfShape& theFaces,
1115 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1116 QString& theGeomObjEntry ) const
1119 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1120 aSewing.SetNonManifoldMode( Standard_False );
1121 #ifdef DEB_CALCULATION
1122 TCollection_AsciiString aNam("Sh_");
1125 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1126 for ( ; aFaceIter.More(); aFaceIter.Next() )
1128 TopoDS_Shape aShape = aFaceIter.Value();
1129 if ( aShape.IsNull() )
1132 if ( aShape.ShapeType() == TopAbs_FACE )
1134 aSewing.Add( aShape );
1135 #ifdef DEB_CALCULATION
1136 TCollection_AsciiString aName = aNam + ++i + ".brep";
1137 BRepTools::Write(aShape ,aName.ToCString());
1142 #ifdef DEB_CALCULATION
1145 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1146 for (; anExp.More(); anExp.Next() ) {
1147 aSewing.Add( anExp.Current() );
1148 #ifdef DEB_CALCULATION
1150 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1151 BRepTools::Write(anExp.Current() ,aName.ToCString());
1158 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1160 // If the sewed shape is empty - return false
1161 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1164 #ifdef DEB_CALCULATION
1165 BRepTools::Write(aSewedShape ,"Sew.brep");
1167 // Publish the sewed shape
1168 QString aName = EXPORT_NAME;
1169 GEOM::GEOM_Object_ptr aMainShape =
1170 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1172 if ( aMainShape->_is_nil() )
1175 if ( theGroupsDefs.IsEmpty() )
1179 TopTools_IndexedMapOfShape aMapOfSubShapes;
1180 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1182 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1184 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1186 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1188 NCollection_Sequence<int> aGroupIndexes;
1189 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1191 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1192 #ifdef DEB_CALCULATION
1193 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1196 TopoDS_Shape aModifiedShape = aShape;
1197 if ( aSewing.IsModified( aShape ) )
1198 aModifiedShape = aSewing.Modified( aShape );
1199 else if ( aSewing.IsModifiedSubShape( aShape ) )
1200 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1202 #ifdef DEB_CALCULATION
1203 const TopLoc_Location& aL1 = aShape.Location();
1204 const TopLoc_Location& aL2 = aModifiedShape.Location();
1205 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1208 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1209 if ( anIndex > 0 ) {
1210 aGroupIndexes.Append( anIndex );
1212 #ifdef DEB_CALCULATION
1213 TCollection_AsciiString aNam("Lost_");
1214 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1215 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1217 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1218 if ( aModifiedShape.IsPartner( aS ) )
1220 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1221 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1222 BRepTools::Write(aS ,aName.ToCString());
1230 if ( !aGroupIndexes.IsEmpty() )
1231 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1234 if ( !aGroupsData.IsEmpty() )
1236 GEOM::GEOM_IGroupOperations_var aGroupOp =
1237 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1239 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1240 for ( ; aMapIt.More(); aMapIt.Next() )
1242 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1243 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1245 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1246 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1249 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1250 aGeomIndexes->length( aGroupIndexes.Length() );
1252 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1253 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1255 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1256 if ( aGroupOp->IsDone() )
1258 SALOMEDS::SObject_var aGroupSO =
1259 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1267 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1268 const bool theIsSetToUpdate )
1270 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1271 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1273 // Indicate model of the need to update splitting
1274 if ( theIsSetToUpdate ) {
1275 SetToUpdate( true );
1279 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1280 HYDROData_PriorityType thePriority,
1281 const Handle(HYDROData_Entity)& theObject2,
1282 HYDROData_Zone::MergeType theMergeType,
1283 HYDROData_CalculationCase::DataTag theDataTag )
1285 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1286 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1288 // Indicate model of the need to update splitting
1289 SetToUpdate( true );
1292 QString HYDROData_CalculationCase::DumpRules() const
1294 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1295 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1298 QString HYDROData_CalculationCase::DumpLandCoverRules() const
1300 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1301 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1304 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1306 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1307 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1309 // Indicate model of the need to update splitting
1310 SetToUpdate( true );
1313 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1315 Handle(TDataStd_Integer) aModeAttr;
1316 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1318 return ( AssignmentMode ) aModeAttr->Get();
1323 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1324 QStringList& theScript ) const
1326 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1327 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1330 void HYDROData_CalculationCase::DumpLandCoverRulesToPython( const QString& theCalcCaseName,
1331 QStringList& theScript ) const
1333 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1334 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1337 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1339 return myLastWarning;
1342 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1344 myLastWarning.Type = theType;
1345 myLastWarning.Data = theData;
1348 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1349 const QString& theOldCaseName,
1350 const QString& theName )
1352 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1353 for ( ; anIter.More(); anIter.Next() )
1355 Handle(HYDROData_Region) aRegion =
1356 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1357 if ( aRegion.IsNull() )
1360 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1362 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1363 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1364 for ( ; anIter.More(); anIter.Next() )
1366 Handle(HYDROData_Zone) aRegZone =
1367 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1368 if ( aRegZone.IsNull() )
1371 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1376 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1377 MapOfTreatedObjects& theTreatedObjects,
1378 const HYDROData_SequenceOfObjects& theRegions ) const
1380 HYDROData_SequenceOfObjects::Iterator anIter;
1381 anIter.Init( theRegions );
1382 for ( ; anIter.More(); anIter.Next() )
1384 Handle(HYDROData_Region) aRegion =
1385 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1386 if ( aRegion.IsNull() )
1389 theTreatedObjects.insert( aRegion->GetName(), aRegion );
1390 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
1391 theResList << aRegDump;
1395 bool HYDROData_CalculationCase::GetRule( int theIndex,
1396 Handle(HYDROData_Entity)& theObject1,
1397 HYDROData_PriorityType& thePriority,
1398 Handle(HYDROData_Entity)& theObject2,
1399 HYDROData_Zone::MergeType& theMergeType,
1400 HYDROData_CalculationCase::DataTag& theDataTag) const
1402 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1403 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1404 theObject1, thePriority, theObject2, theMergeType );
1407 void HYDROData_CalculationCase::SetAssignmentLandCoverMode( AssignmentMode theMode )
1409 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentLandCoverMode );
1410 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1412 // Indicate model of the need to update land covers partition
1413 SetToUpdate( true );
1416 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentLandCoverMode() const
1418 Handle(TDataStd_Integer) aModeAttr;
1419 bool isOK = myLab.FindChild( DataTag_AssignmentLandCoverMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1421 return ( AssignmentMode ) aModeAttr->Get();