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_GROUPS_PREF GetName() + "_"
64 //#define DEB_CLASS2D 1
66 #include <BRepBuilderAPI_MakeVertex.hxx>
69 #define EXPORT_NAME "HYDRO_" + GetName()
71 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
72 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
74 HYDROData_CalculationCase::HYDROData_CalculationCase()
79 HYDROData_CalculationCase::~HYDROData_CalculationCase()
83 void HYDROData_CalculationCase::SetName( const QString& theName )
85 QString anOldCaseName = GetName();
86 if ( anOldCaseName != theName )
88 HYDROData_SequenceOfObjects aRegions = GetRegions();
90 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
91 for ( ; anIter.More(); anIter.Next() )
93 Handle(HYDROData_Region) aRegion =
94 Handle(HYDROData_Region)::DownCast( anIter.Value() );
95 if ( aRegion.IsNull() )
98 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
100 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
101 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
102 for ( ; anIter.More(); anIter.Next() )
104 Handle(HYDROData_Zone) aRegZone =
105 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
106 if ( aRegZone.IsNull() )
109 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
113 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
115 anIter.Init( aGroups );
116 for ( ; anIter.More(); anIter.Next() )
118 Handle(HYDROData_SplittedShapesGroup) aGroup =
119 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
120 if ( aGroup.IsNull() )
123 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
127 HYDROData_Entity::SetName( theName );
130 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
132 QStringList aResList = dumpObjectCreation( theTreatedObjects );
133 aResList.prepend( "# Calculation case" );
135 QString aCalculName = GetObjPyName();
137 AssignmentMode aMode = GetAssignmentMode();
138 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
139 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
141 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
142 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
143 for ( ; anIter.More(); anIter.Next() )
145 Handle(HYDROData_Object) aRefGeomObj =
146 Handle(HYDROData_Object)::DownCast( anIter.Value() );
147 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
149 aResList << QString( "" );
151 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
153 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
154 anIter.Init( aGeomGroups );
155 for ( ; anIter.More(); anIter.Next() )
157 Handle(HYDROData_ShapesGroup) aGeomGroup =
158 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
159 if ( aGeomGroup.IsNull() )
162 Handle(HYDROData_Object) aFatherGeom =
163 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
164 if ( aFatherGeom.IsNull() )
167 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
168 aResList << QString( "%1 = %2.GetGroup( %3 );" )
169 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
171 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
174 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
175 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
177 if( aMode==AUTOMATIC )
178 DumpRulesToPython( aCalculName, aResList );
180 aResList << QString( "" );
181 aResList << "# Start the algorithm of the partition and assignment";
182 aResList << QString( "%1.Update();" ).arg( aCalculName );
186 // Now we restore the regions and zones order
187 HYDROData_SequenceOfObjects aRegions = GetRegions();
188 anIter.Init( aRegions );
189 for ( ; anIter.More(); anIter.Next() )
191 Handle(HYDROData_Region) aRegion =
192 Handle(HYDROData_Region)::DownCast( anIter.Value() );
193 if ( aRegion.IsNull() )
196 theTreatedObjects.insert( aRegion->GetName(), aRegion );
197 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
198 aResList << aRegDump;
202 // Export calculation case
203 aResList << QString( "" );
204 aResList << "# Export of the calculation case";
205 QString aStudyName = "theStudy";
206 QString anEntryVar = aCalculName + "_entry";
207 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
209 // Get geometry object and print debug information
211 aResList << "# Get geometry shape and print debug information";
212 aResList << "import GEOM";
213 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
214 QString aGeomShapeName = aCalculName + "_geom";
215 aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
216 aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
217 aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
219 DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
221 aResList << QString( "" );
225 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
226 const QString& theStudyName,
227 const QString& theGeomShapeName,
228 const QString& theMeshName ) const
231 theResList << "# Meshing";
232 theResList << "import SMESH, SALOMEDS";
233 theResList << "from salome.smesh import smeshBuilder";
234 theResList << "from salome.geom import geomBuilder";
236 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
237 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
238 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
239 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
240 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
241 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
242 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
245 theResList << "# Set names of Mesh objects";
246 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
247 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
248 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
249 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
250 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
253 theResList << "# Greate SMESH groups";
254 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
255 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
256 theResList << QString( "for group in geom_groups:" );
257 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
259 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
260 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
263 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
265 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
267 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
268 if ( !aBoundaryPolyline.IsNull() )
269 aResSeq.Append( aBoundaryPolyline );
271 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
272 aResSeq.Append( aSeqOfRegions );
277 void HYDROData_CalculationCase::Update()
279 HYDROData_Entity::Update();
282 // At first we remove previously created objects
284 RemoveSplittedGroups();
286 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
287 if ( aDocument.IsNull() )
290 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
291 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
292 if ( aGeomObjects.IsEmpty() )
295 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
297 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
298 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
299 if ( aSplitObjects.isEmpty() )
302 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
304 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
305 while( anIter.hasNext() )
307 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
308 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
309 aZonesList.append( aSplitData );
310 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
311 anEdgesList.append( aSplitData );
314 switch( GetAssignmentMode() )
317 CreateRegionsDef( aDocument, aZonesList );
320 CreateRegionsAuto( aDocument, aZonesList );
323 CreateEdgeGroupsDef( aDocument, anEdgesList );
326 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
327 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
329 // Create result regions for case, by default one zone for one region
330 QString aRegsPref = CALCULATION_REGIONS_PREF;
331 QString aZonesPref = CALCULATION_ZONES_PREF;
333 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
334 while( anIter.hasNext() )
336 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
338 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
340 // Add the zone for region
341 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
345 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
346 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
348 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
349 QMap<QString, QString> aRegionNameToObjNameMap;
350 QString aZonesPref = CALCULATION_ZONES_PREF;
351 HYDROData_PriorityQueue aPr( this );
353 // 1. First we create a default region for each object included into the calculation case
354 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
355 for( int i=aGeomObjects.Lower(), n=aGeomObjects.Upper(); i<=n; i++ )
357 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( aGeomObjects.Value( i ) );
360 QString anObjName = anObj->GetName();
361 QString aRegName = anObjName + "_reg";
362 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
363 aRegionsMap.insert( anObjName, aRegion );
364 aRegionNameToObjNameMap.insert( aRegName, anObjName );
367 // 2. Now for each zone it is necessary to determine the most priority object
368 // and assign to zone to corresponding region
369 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
370 while( anIter.hasNext() )
372 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
373 HYDROData_Zone::MergeAltitudesType aMergeType;
374 Handle(HYDROData_Object) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
375 if( aRegObj.IsNull() )
377 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
378 if( aRegion.IsNull() )
380 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
382 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
384 qDebug( "Error in algorithm: unresolved conflicts" );
389 case HYDROData_Zone::Merge_ZMIN:
390 case HYDROData_Zone::Merge_ZMAX:
391 aRegionZone->SetMergeType( aMergeType );
393 case HYDROData_Zone::Merge_Object:
394 aRegionZone->SetMergeType( aMergeType );
395 aRegionZone->RemoveMergeAltitude();
396 aRegionZone->SetMergeAltitude( aRegObj->GetAltitudeObject() );
401 QStringList anObjectsWithEmptyRegions;
402 QMap<QString, Handle(HYDROData_Region)>::const_iterator
403 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
404 for( ; anIt!=aLast; anIt++ )
406 Handle(HYDROData_Region) aRegion = anIt.value();
407 if( aRegion->GetZones().IsEmpty() )
409 QString aRegName = aRegion->GetName();
410 QString anObjName = aRegionNameToObjNameMap[aRegName];
411 anObjectsWithEmptyRegions.append( anObjName );
415 if( !anObjectsWithEmptyRegions.empty() )
417 QString aData = anObjectsWithEmptyRegions.join( ", " );
418 SetWarning( WARN_EMPTY_REGIONS, aData );
422 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
423 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
425 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
427 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
428 while( anIter.hasNext() )
430 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
431 // Create new edges group
432 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
435 QString anObjName = aSplitData.ObjectNames.first();
436 if ( anObjName.isEmpty() )
438 #ifdef DEB_CALCULATION
439 QString aStr = aSplitData.ObjectNames.join(" ");
440 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
442 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
443 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
445 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
446 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
450 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
452 if ( aSplittedGroup.IsNull() )
455 aSplittedGroup->AddShape( aSplitData.Shape );
459 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
461 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
462 return false; // Wrong type of object
464 if ( HasReference( theObject, DataTag_GeometryObject ) )
465 return false; // Object is already in reference list
467 AddReferenceObject( theObject, DataTag_GeometryObject );
469 // Indicate model of the need to update splitting
475 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
477 return GetReferenceObjects( DataTag_GeometryObject );
480 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
482 if ( theObject.IsNull() )
485 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
487 // Indicate model of the need to update splitting
491 void HYDROData_CalculationCase::RemoveGeometryObjects()
493 ClearReferenceObjects( DataTag_GeometryObject );
495 // Indicate model of the need to update splitting
499 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
501 if ( theGroup.IsNull() )
504 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
505 return false; // Object is already in reference list
507 AddReferenceObject( theGroup, DataTag_GeometryGroup );
509 // Indicate model of the need to update splitting
515 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
517 return GetReferenceObjects( DataTag_GeometryGroup );
520 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
522 if ( theGroup.IsNull() )
525 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
527 // Indicate model of the need to update splitting
531 void HYDROData_CalculationCase::RemoveGeometryGroups()
533 ClearReferenceObjects( DataTag_GeometryGroup );
535 // Indicate model of the need to update splitting
539 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
541 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
543 SetReferenceObject( thePolyline, DataTag_Polyline );
545 // Indicate model of the need to update zones splitting
546 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
549 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
551 return Handle(HYDROData_PolylineXY)::DownCast(
552 GetReferenceObject( DataTag_Polyline ) );
555 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
557 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
559 ClearReferenceObjects( DataTag_Polyline );
561 // Indicate model of the need to update zones splitting
562 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
565 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
567 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
569 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
571 // Indicate model of the need to update land covers partition
572 SetToUpdate( !IsEqual( aPrevStricklerTable, theStricklerTable ) || IsMustBeUpdated() );
575 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
577 return Handle(HYDROData_StricklerTable)::DownCast(
578 GetReferenceObject( DataTag_StricklerTable ) );
581 void HYDROData_CalculationCase::RemoveStricklerTable()
583 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
585 ClearReferenceObjects( DataTag_StricklerTable );
587 // Indicate model of the need to update land covers partition
588 SetToUpdate( !aPrevStricklerTable.IsNull() || IsMustBeUpdated() );
591 bool HYDROData_CalculationCase::AddLandCover( const Handle(HYDROData_LandCover)& theLandCover )
593 if ( HasReference( theLandCover, DataTag_LandCover ) )
594 return false; // Land cover is already in reference list
596 AddReferenceObject( theLandCover, DataTag_LandCover );
598 // Indicate model of the need to update land covers partition
604 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetLandCovers() const
606 return GetReferenceObjects( DataTag_LandCover );
609 void HYDROData_CalculationCase::RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover )
611 if ( theLandCover.IsNull() )
614 RemoveReferenceObject( theLandCover->Label(), DataTag_LandCover );
616 // Indicate model of the need to update land cover partition
620 void HYDROData_CalculationCase::RemoveLandCovers()
622 ClearReferenceObjects( DataTag_LandCover );
624 // Indicate model of the need to update land cover partition
628 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
630 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
631 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
632 if ( aNewRegion.IsNull() )
635 aNewRegion->AddZone( theZone );
640 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
642 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
644 if ( theRegion.IsNull() )
647 if ( HasReference( theRegion, DataTag_Region ) )
648 return false; // Object is already in reference list
650 // Move the region from other calculation
651 Handle(HYDROData_CalculationCase) aFatherCalc =
652 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
653 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
655 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
656 theRegion->CopyTo( aNewRegion );
658 aFatherCalc->RemoveRegion( theRegion );
660 theRegion->SetLabel( aNewRegion->Label() );
664 AddReferenceObject( theRegion, DataTag_Region );
670 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
672 return GetReferenceObjects( DataTag_Region );
675 void HYDROData_CalculationCase::UpdateRegionsOrder()
677 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
678 if ( aDocument.IsNull() )
681 HYDROData_SequenceOfObjects aRegions = GetRegions();
683 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
684 for ( ; anIter.More(); anIter.Next() )
686 Handle(HYDROData_Region) aRegion =
687 Handle(HYDROData_Region)::DownCast( anIter.Value() );
688 if ( aRegion.IsNull() )
691 aRegion->SetName( "" );
694 QString aRegsPref = CALCULATION_REGIONS_PREF;
696 anIter.Init( aRegions );
697 for ( ; anIter.More(); anIter.Next() )
699 Handle(HYDROData_Region) aRegion =
700 Handle(HYDROData_Region)::DownCast( anIter.Value() );
701 if ( aRegion.IsNull() )
704 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
705 aRegion->SetName( aRegionName );
709 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
711 if ( theRegion.IsNull() )
714 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
716 // Remove region from data model
717 Handle(HYDROData_CalculationCase) aFatherCalc =
718 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
719 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
723 void HYDROData_CalculationCase::RemoveRegions()
725 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
728 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
730 return GetReferenceObjects( DataTag_SplittedGroups );
733 void HYDROData_CalculationCase::RemoveSplittedGroups()
735 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
738 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
740 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
741 return GetAltitudeForPoint( thePoint, aZone );
744 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
745 const Handle(HYDROData_Region)& theRegion ) const
747 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
749 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
750 if ( !aZone.IsNull() )
752 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
753 if ( IsEqual( aRefRegion, theRegion ) )
754 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
760 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
761 const Handle(HYDROData_Zone)& theZone ) const
763 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
764 if ( theZone.IsNull() )
767 HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
768 if ( !theZone->IsMergingNeed() )
770 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
772 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
777 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
778 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
780 Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
781 if ( !aMergeAltitude.IsNull() )
783 if ( aZoneInterpolator != NULL )
785 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
786 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
789 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
794 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
795 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
796 for ( ; anIter.More(); anIter.Next() )
798 Handle(HYDROData_Object) aZoneObj =
799 Handle(HYDROData_Object)::DownCast( anIter.Value() );
800 if ( aZoneObj.IsNull() )
803 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
804 if ( anObjAltitude.IsNull() )
807 double aPointAltitude = 0.0;
808 if ( aZoneInterpolator != NULL )
810 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
811 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
814 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
816 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
819 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
821 aResAltitude = aPointAltitude;
824 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
826 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
827 aResAltitude > aPointAltitude )
829 aResAltitude = aPointAltitude;
832 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
834 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
835 aResAltitude < aPointAltitude )
837 aResAltitude = aPointAltitude;
846 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
847 const NCollection_Sequence<gp_XY>& thePoints,
848 const Handle(HYDROData_Region)& theRegion ) const
850 NCollection_Sequence<double> aResSeq;
852 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
854 const gp_XY& thePnt = thePoints.Value( i );
856 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
857 aResSeq.Append( anAltitude );
863 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
864 const NCollection_Sequence<gp_XY>& thePoints,
865 const Handle(HYDROData_Zone)& theZone ) const
867 NCollection_Sequence<double> aResSeq;
869 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
871 const gp_XY& thePnt = thePoints.Value( i );
873 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
874 aResSeq.Append( anAltitude );
880 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
882 Handle(HYDROData_Region) aResRegion;
884 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
885 if ( !aZone.IsNull() )
886 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
891 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
893 Handle(HYDROData_Zone) aResZone;
895 HYDROData_SequenceOfObjects aRegions = GetRegions();
897 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
898 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
900 Handle(HYDROData_Region) aRegion =
901 Handle(HYDROData_Region)::DownCast( anIter.Value() );
902 if ( aRegion.IsNull() )
905 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
906 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
907 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
909 Handle(HYDROData_Zone) aRegZone =
910 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
911 if ( aRegZone.IsNull() )
914 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
915 if ( aPointRelation != POINT_OUT )
916 aResZone = aRegZone; // We found the desired zone
923 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
924 const gp_XY& thePoint,
925 const Handle(HYDROData_Zone)& theZone ) const
927 PointClassification aRes = POINT_OUT;
928 if ( theZone.IsNull() )
931 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
932 if ( aZoneFace.IsNull() )
935 TopoDS_Compound aCmp;
937 aBB.MakeCompound(aCmp);
938 aBB.Add(aCmp, aZoneFace);
939 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
940 BRepBuilderAPI_MakeVertex aMk(aPnt);
941 aBB.Add(aCmp, aMk.Vertex());
942 BRepTools::Write(aCmp, "FCL2d.brep");
944 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
945 if (State == TopAbs_OUT)
947 else if(State == TopAbs_IN)
949 else if(State == TopAbs_ON)
954 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
955 const QString& thePrefixOrName,
958 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
959 int aTag = aNewLab.Tag();
961 Handle(HYDROData_Region) aNewRegion =
962 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
963 AddRegion( aNewRegion );
965 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
966 aNewRegion->SetName( aRegionName );
971 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
973 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
975 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
976 Handle(HYDROData_SplittedShapesGroup)::DownCast(
977 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
978 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
980 aNewGroup->SetName( theName );
985 QString HYDROData_CalculationCase::Export( int theStudyId ) const
987 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
988 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
990 QString aGeomObjEntry;
991 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry );
992 return isOK ? aGeomObjEntry : QString();
995 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
996 SALOMEDS::Study_ptr theStudy,
997 QString& theGeomObjEntry ) const
999 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1001 // Get groups definitions
1002 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
1004 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
1005 for ( ; anIter.More(); anIter.Next() )
1008 Handle(HYDROData_ShapesGroup) aGroup =
1009 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1010 if ( aGroup.IsNull() )
1013 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1015 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1016 aGroup->GetShapes( aGroupDef.Shapes );
1018 aSeqOfGroupsDefs.Append( aGroupDef );
1022 TopTools_ListOfShape aFaces;
1023 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1024 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1025 for ( ; aRegionIter.More(); aRegionIter.Next() )
1027 Handle(HYDROData_Region) aRegion =
1028 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1029 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1032 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1033 aFaces.Append( aRegionShape );
1036 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );
1039 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1040 SALOMEDS::Study_ptr theStudy,
1041 const TopTools_ListOfShape& theFaces,
1042 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1043 QString& theGeomObjEntry ) const
1046 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1047 aSewing.SetNonManifoldMode( Standard_False );
1048 #ifdef DEB_CALCULATION
1049 TCollection_AsciiString aNam("Sh_");
1052 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1053 for ( ; aFaceIter.More(); aFaceIter.Next() )
1055 TopoDS_Shape aShape = aFaceIter.Value();
1056 if ( aShape.IsNull() )
1059 if ( aShape.ShapeType() == TopAbs_FACE )
1061 aSewing.Add( aShape );
1062 #ifdef DEB_CALCULATION
1063 TCollection_AsciiString aName = aNam + ++i + ".brep";
1064 BRepTools::Write(aShape ,aName.ToCString());
1069 #ifdef DEB_CALCULATION
1072 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1073 for (; anExp.More(); anExp.Next() ) {
1074 aSewing.Add( anExp.Current() );
1075 #ifdef DEB_CALCULATION
1077 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1078 BRepTools::Write(anExp.Current() ,aName.ToCString());
1085 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1087 // If the sewed shape is empty - return false
1088 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1091 #ifdef DEB_CALCULATION
1092 BRepTools::Write(aSewedShape ,"Sew.brep");
1094 // Publish the sewed shape
1095 QString aName = EXPORT_NAME;
1096 GEOM::GEOM_Object_ptr aMainShape =
1097 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1099 if ( aMainShape->_is_nil() )
1102 if ( theGroupsDefs.IsEmpty() )
1106 TopTools_IndexedMapOfShape aMapOfSubShapes;
1107 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1109 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1111 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1113 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1115 NCollection_Sequence<int> aGroupIndexes;
1116 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1118 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1119 #ifdef DEB_CALCULATION
1120 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1123 TopoDS_Shape aModifiedShape = aShape;
1124 if ( aSewing.IsModified( aShape ) )
1125 aModifiedShape = aSewing.Modified( aShape );
1126 else if ( aSewing.IsModifiedSubShape( aShape ) )
1127 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1129 #ifdef DEB_CALCULATION
1130 const TopLoc_Location& aL1 = aShape.Location();
1131 const TopLoc_Location& aL2 = aModifiedShape.Location();
1132 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1135 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1136 if ( anIndex > 0 ) {
1137 aGroupIndexes.Append( anIndex );
1139 #ifdef DEB_CALCULATION
1140 TCollection_AsciiString aNam("Lost_");
1141 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1142 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1144 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1145 if ( aModifiedShape.IsPartner( aS ) )
1147 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1148 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1149 BRepTools::Write(aS ,aName.ToCString());
1157 if ( !aGroupIndexes.IsEmpty() )
1158 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1161 if ( !aGroupsData.IsEmpty() )
1163 GEOM::GEOM_IGroupOperations_var aGroupOp =
1164 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1166 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1167 for ( ; aMapIt.More(); aMapIt.Next() )
1169 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1170 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1172 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1173 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1176 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1177 aGeomIndexes->length( aGroupIndexes.Length() );
1179 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1180 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1182 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1183 if ( aGroupOp->IsDone() )
1185 SALOMEDS::SObject_var aGroupSO =
1186 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1194 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
1195 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
1196 const TopoDS_Shape& theShape, const QString& theName,
1197 QString& theGeomObjEntry ) const
1199 theGeomObjEntry = "";
1200 GEOM::GEOM_Object_var aGeomObj;
1202 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
1203 theShape.IsNull() ) {
1204 return aGeomObj._retn();
1207 std::ostringstream aStreamShape;
1208 // Write TopoDS_Shape in ASCII format to the stream
1209 BRepTools::Write( theShape, aStreamShape );
1210 // Returns the number of bytes that have been stored in the stream's buffer.
1211 int aSize = aStreamShape.str().size();
1212 // Allocate octect buffer of required size
1213 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
1214 // Copy ostrstream content to the octect buffer
1215 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
1217 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
1219 // Restore shape from the stream and get the GEOM object
1220 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
1221 aGeomObj = anInsOp->RestoreShape( aSeqFile );
1223 // Puplish the GEOM object
1224 if ( !aGeomObj->_is_nil() ) {
1225 QString aName = HYDROData_GeomTool::GetFreeName( theStudy, theName );
1227 SALOMEDS::SObject_var aResultSO =
1228 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
1229 aGeomObj, qPrintable( aName ) );
1230 if ( aResultSO->_is_nil() ) {
1231 aGeomObj = GEOM::GEOM_Object::_nil();
1234 theGeomObjEntry = aResultSO->GetID();
1237 return aGeomObj._retn();
1240 void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate )
1242 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1243 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1245 // Indicate model of the need to update splitting
1246 if ( theIsSetToUpdate ) {
1247 SetToUpdate( true );
1251 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)& theObject1,
1252 HYDROData_PriorityType thePriority,
1253 const Handle(HYDROData_Object)& theObject2,
1254 HYDROData_Zone::MergeAltitudesType theMergeType )
1256 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1257 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1259 // Indicate model of the need to update splitting
1260 SetToUpdate( true );
1263 QString HYDROData_CalculationCase::DumpRules() const
1265 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1266 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1269 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1271 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1272 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1274 // Indicate model of the need to update splitting
1275 SetToUpdate( true );
1278 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1280 Handle(TDataStd_Integer) aModeAttr;
1281 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1283 return ( AssignmentMode ) aModeAttr->Get();
1288 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1289 QStringList& theScript ) const
1291 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1292 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1295 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1297 return myLastWarning;
1300 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1302 myLastWarning.Type = theType;
1303 myLastWarning.Data = theData;
1306 bool HYDROData_CalculationCase::GetRule( int theIndex,
1307 Handle(HYDROData_Object)& theObject1,
1308 HYDROData_PriorityType& thePriority,
1309 Handle(HYDROData_Object)& theObject2,
1310 HYDROData_Zone::MergeAltitudesType& theMergeType ) const
1312 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1313 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1314 theObject1, thePriority, theObject2, theMergeType );
1317 void HYDROData_CalculationCase::SetAssignmentLandCoverMode( AssignmentMode theMode )
1319 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentLandCoverMode );
1320 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1322 // Indicate model of the need to update land covers partition
1323 SetToUpdate( true );
1326 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentLandCoverMode() const
1328 Handle(TDataStd_Integer) aModeAttr;
1329 bool isOK = myLab.FindChild( DataTag_AssignmentLandCoverMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1331 return ( AssignmentMode ) aModeAttr->Get();
1336 void HYDROData_CalculationCase::ClearLandCoverRules( const bool theIsSetToUpdate )
1338 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1339 // TODO: adapt HYDROData_PriorityQueue to use with land covers
1340 //HYDROData_PriorityQueue::ClearRules( aRulesLab );
1342 // Indicate model of the need to update land covers partition
1343 if ( theIsSetToUpdate ) {
1344 SetToUpdate( true );
1348 void HYDROData_CalculationCase::AddLandCoverRule( const Handle(HYDROData_LandCover)& theLandCover1,
1349 HYDROData_PriorityType thePriority,
1350 const Handle(HYDROData_LandCover)& theLandCover2/*,
1351 HYDROData_LandCover::MergeStricklerCoefficientType theMergeType*/ )
1353 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1354 // TODO: adapt HYDROData_PriorityQueue to use with land covers
1355 //HYDROData_PriorityQueue::AddRule( aRulesLab, theLandCover1, thePriority, theLandCover2, theMergeType );
1357 // Indicate model of the need to update splitting
1358 SetToUpdate( true );
1361 bool HYDROData_CalculationCase::GetLandCoverRule( int theIndex,
1362 Handle(HYDROData_LandCover)& theLandCover1,
1363 HYDROData_PriorityType& thePriority,
1364 Handle(HYDROData_LandCover)& theLandCover2/*,
1365 HYDROData_LandCover::MergeStricklerCoefficientType& theMergeType*/ ) const
1367 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1368 // TODO: adapt HYDROData_PriorityQueue to use with land covers
1369 //return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1370 // theLandCover1, thePriority, theLandCover2, theMergeType );