1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_CalculationCase.h"
20 #include "HYDROData_ArtificialObject.h"
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_Iterator.h"
25 #include "HYDROData_NaturalObject.h"
26 #include "HYDROData_PolylineXY.h"
27 #include "HYDROData_StricklerTable.h"
28 #include "HYDROData_LandCover.h"
29 #include "HYDROData_SplittedShapesGroup.h"
30 #include "HYDROData_Region.h"
31 #include "HYDROData_Tool.h"
32 #include "HYDROData_GeomTool.h"
35 #pragma warning ( disable: 4251 )
43 #pragma warning ( default: 4251 )
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Edge.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRepBuilderAPI_Sewing.hxx>
54 #include <BRepTopAdaptor_FClass2d.hxx>
56 #include <BRepTools.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <TopTools_ListOfShape.hxx>
62 #include <TopTools_ListIteratorOfListOfShape.hxx>
63 #include <TDataStd_Integer.hxx>
65 //#define DEB_CALCULATION 1
66 #ifdef DEB_CALCULATION
67 #include <BRepTools.hxx>
68 #include <TopLoc_Location.hxx>
70 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
71 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
72 #define CALCULATION_LANDCOVER_ZONES_PREF GetName() + "_LandCoverZone"
73 #define CALCULATION_GROUPS_PREF GetName() + "_"
74 //#define DEB_CLASS2D 1
76 #include <BRepBuilderAPI_MakeVertex.hxx>
79 #define EXPORT_NAME "HYDRO_" + GetName()
81 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
82 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
84 HYDROData_CalculationCase::HYDROData_CalculationCase()
85 : HYDROData_Entity( Geom_2d_and_groups )
89 HYDROData_CalculationCase::~HYDROData_CalculationCase()
93 void HYDROData_CalculationCase::SetName( const QString& theName )
95 QString anOldCaseName = GetName();
96 if ( anOldCaseName != theName )
98 // Update names of regions and its zones
99 UpdateRegionsNames( GetRegions( false ), anOldCaseName, theName );
100 // Update names of land cover regions and its zones
101 UpdateRegionsNames( GetRegions( true ), anOldCaseName, theName );
103 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
105 HYDROData_SequenceOfObjects::Iterator anIter;
106 anIter.Init( aGroups );
107 for ( ; anIter.More(); anIter.Next() )
109 Handle(HYDROData_SplittedShapesGroup) aGroup =
110 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
111 if ( aGroup.IsNull() )
114 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
118 HYDROData_Entity::SetName( theName );
121 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
123 QStringList aResList = dumpObjectCreation( theTreatedObjects );
124 aResList.prepend( "# Calculation case" );
126 QString aCalculName = GetObjPyName();
128 AssignmentMode aMode = GetAssignmentMode();
129 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
130 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
132 AssignmentMode aModeLC = GetAssignmentLandCoverMode();
133 QString aModeLCStr = aModeLC==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
134 aResList << QString( "%0.SetAssignmentLandCoverMode( %1 )" ).arg( aCalculName ).arg( aModeLCStr );
136 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
137 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
138 for ( ; anIter.More(); anIter.Next() )
140 Handle(HYDROData_Object) aRefGeomObj =
141 Handle(HYDROData_Object)::DownCast( anIter.Value() );
142 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
144 aResList << QString( "" );
146 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
148 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
149 anIter.Init( aGeomGroups );
150 for ( ; anIter.More(); anIter.Next() )
152 Handle(HYDROData_ShapesGroup) aGeomGroup =
153 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
154 if ( aGeomGroup.IsNull() )
157 Handle(HYDROData_Object) aFatherGeom =
158 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
159 if ( aFatherGeom.IsNull() )
162 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
163 aResList << QString( "%1 = %2.GetGroup( %3 );" )
164 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
166 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
169 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
170 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
172 if( aMode==AUTOMATIC )
173 DumpRulesToPython( aCalculName, aResList );
174 if( aModeLC==AUTOMATIC )
175 DumpLandCoverRulesToPython( aCalculName, aResList );
177 aResList << QString( "" );
178 aResList << "# Start the algorithm of the partition and assignment";
179 aResList << QString( "%1.Update();" ).arg( aCalculName );
183 // Now we restore the
184 // - regions and zones order
185 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) );
188 if( aModeLC==MANUAL )
190 // Now we restore the
191 // - land cover regions and zones order
192 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( true ) );
195 // Export calculation case
196 aResList << QString( "" );
197 aResList << "# Export of the calculation case";
198 QString aStudyName = "theStudy";
199 QString anEntryVar = aCalculName + "_entry";
200 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
202 // Get geometry object and print debug information
204 aResList << "# Get geometry shape and print debug information";
205 aResList << "import GEOM";
206 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
207 QString aGeomShapeName = aCalculName + "_geom";
208 aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
209 aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
210 aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
212 DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
214 aResList << QString( "" );
218 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
219 const QString& theStudyName,
220 const QString& theGeomShapeName,
221 const QString& theMeshName ) const
224 theResList << "# Meshing";
225 theResList << "import SMESH, SALOMEDS";
226 theResList << "from salome.smesh import smeshBuilder";
227 theResList << "from salome.geom import geomBuilder";
229 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
230 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
231 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
232 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
233 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
234 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
235 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
238 theResList << "# Set names of Mesh objects";
239 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
240 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
241 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
242 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
243 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
246 theResList << "# Greate SMESH groups";
247 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
248 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
249 theResList << QString( "for group in geom_groups:" );
250 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
252 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
253 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
256 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
258 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
260 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
261 if ( !aBoundaryPolyline.IsNull() )
262 aResSeq.Append( aBoundaryPolyline );
264 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
265 aResSeq.Append( aSeqOfGeomObjs );
268 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions( false );
269 aResSeq.Append( aSeqOfRegions );
271 // Land cover regions
272 HYDROData_SequenceOfObjects aSeqOfLandCoverRegions = GetRegions( true );
273 aResSeq.Append( aSeqOfLandCoverRegions );
278 void HYDROData_CalculationCase::Update()
280 HYDROData_Entity::Update();
283 // At first we remove previously created objects
284 RemoveRegions( false );
285 RemoveRegions( true );
286 RemoveSplittedGroups();
288 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
289 if ( aDocument.IsNull() )
293 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
295 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
296 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
297 if ( !aGeomObjects.IsEmpty() ) {
298 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
300 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
301 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
302 if ( !aSplitObjects.isEmpty() ) {
303 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
304 while( anIter.hasNext() ) {
305 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
306 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
307 aZonesList.append( aSplitData );
308 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
309 anEdgesList.append( aSplitData );
314 // Split to land cover zones
315 HYDROData_SplitToZonesTool::SplitDataList aLandCoverZonesList;
317 HYDROData_SequenceOfObjects aLandCovers = GetLandCovers();
318 if ( !aLandCovers.IsEmpty() ) {
319 HYDROData_SplitToZonesTool::SplitDataList aSplitLandCoverObjects =
320 HYDROData_SplitToZonesTool::Split( aLandCovers );
321 if ( !aSplitLandCoverObjects.isEmpty() ) {
322 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitLandCoverObjects );
323 while( anIter.hasNext() ) {
324 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
325 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
326 aLandCoverZonesList.append( aSplitData );
331 switch( GetAssignmentMode() )
334 CreateRegionsDef( aDocument, aZonesList, false );
337 CreateRegionsAuto( aDocument, aZonesList, false );
341 switch( GetAssignmentLandCoverMode() )
344 CreateRegionsDef( aDocument, aLandCoverZonesList, true );
347 CreateRegionsAuto( aDocument, aLandCoverZonesList, true );
351 CreateEdgeGroupsDef( aDocument, anEdgesList );
354 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
355 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
356 const bool theLandCover )
358 // Create result regions for case, by default one zone for one region
359 QString aRegsPref = CALCULATION_REGIONS_PREF;
360 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
362 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
363 while( anIter.hasNext() )
365 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
367 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref, theLandCover );
369 // Add the zone for region
370 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
374 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
375 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
376 const bool theLandCover )
378 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
379 QMap<QString, QString> aRegionNameToObjNameMap;
380 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
381 HYDROData_PriorityQueue aPr( this, theLandCover ? DataTag_CustomLandCoverRules : DataTag_CustomRules );
383 // 1. First we create a default region for each object included into the calculation case
384 HYDROData_SequenceOfObjects anObjects = theLandCover ? GetLandCovers() : GetGeometryObjects();
385 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
387 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
390 QString anObjName = anObj->GetName();
391 QString aRegName = anObjName + "_reg";
392 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, theLandCover, false );
393 aRegionsMap.insert( anObjName, aRegion );
394 aRegionNameToObjNameMap.insert( aRegName, anObjName );
397 // 2. Now for each zone it is necessary to determine the most priority object
398 // and assign to zone to corresponding region
399 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
400 while( anIter.hasNext() )
402 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
403 HYDROData_Zone::MergeType aMergeType;
404 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
405 if( aRegObj.IsNull() )
407 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
408 if( aRegion.IsNull() )
410 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
412 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
414 qDebug( "Error in algorithm: unresolved conflicts" );
417 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
418 if ( !theLandCover ) {
419 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
420 if ( !aMergeObject.IsNull() ) {
421 aMergeEntity = aMergeObject->GetAltitudeObject();
427 case HYDROData_Zone::Merge_ZMIN:
428 case HYDROData_Zone::Merge_ZMAX:
429 aRegionZone->SetMergeType( aMergeType );
431 case HYDROData_Zone::Merge_Object:
432 aRegionZone->SetMergeType( aMergeType );
433 aRegionZone->RemoveMergeObject();
434 aRegionZone->SetMergeObject( aMergeEntity );
439 QStringList anObjectsWithEmptyRegions;
440 QMap<QString, Handle(HYDROData_Region)>::const_iterator
441 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
442 for( ; anIt!=aLast; anIt++ )
444 Handle(HYDROData_Region) aRegion = anIt.value();
445 if( aRegion->GetZones().IsEmpty() )
447 QString aRegName = aRegion->GetName();
448 QString anObjName = aRegionNameToObjNameMap[aRegName];
449 anObjectsWithEmptyRegions.append( anObjName );
453 if( !anObjectsWithEmptyRegions.empty() )
455 QString aData = anObjectsWithEmptyRegions.join( ", " );
456 SetWarning( WARN_EMPTY_REGIONS, aData );
460 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
461 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
463 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
465 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
466 while( anIter.hasNext() )
468 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
469 // Create new edges group
470 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
473 QString anObjName = aSplitData.ObjectNames.first();
474 if ( anObjName.isEmpty() )
476 #ifdef DEB_CALCULATION
477 QString aStr = aSplitData.ObjectNames.join(" ");
478 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
480 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
481 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
483 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
484 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
488 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
490 if ( aSplittedGroup.IsNull() )
493 aSplittedGroup->AddShape( aSplitData.Shape );
497 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
499 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
500 return false; // Wrong type of object
502 if ( HasReference( theObject, DataTag_GeometryObject ) )
503 return false; // Object is already in reference list
505 AddReferenceObject( theObject, DataTag_GeometryObject );
507 // Indicate model of the need to update splitting
513 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
515 return GetReferenceObjects( DataTag_GeometryObject );
518 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
520 if ( theObject.IsNull() )
523 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
525 // Indicate model of the need to update splitting
529 void HYDROData_CalculationCase::RemoveGeometryObjects()
531 ClearReferenceObjects( DataTag_GeometryObject );
533 // Indicate model of the need to update splitting
537 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
539 if ( theGroup.IsNull() )
542 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
543 return false; // Object is already in reference list
545 AddReferenceObject( theGroup, DataTag_GeometryGroup );
547 // Indicate model of the need to update splitting
548 Changed( Geom_Groups );
553 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
555 return GetReferenceObjects( DataTag_GeometryGroup );
558 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
560 if ( theGroup.IsNull() )
563 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
565 // Indicate model of the need to update splitting
566 Changed( Geom_Groups );
569 void HYDROData_CalculationCase::RemoveGeometryGroups()
571 ClearReferenceObjects( DataTag_GeometryGroup );
573 // Indicate model of the need to update splitting
574 Changed( Geom_Groups );
577 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
579 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
581 SetReferenceObject( thePolyline, DataTag_Polyline );
583 // Indicate model of the need to update zones splitting
584 if( !IsEqual( aPrevPolyline, thePolyline ) )
588 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
590 return Handle(HYDROData_PolylineXY)::DownCast(
591 GetReferenceObject( DataTag_Polyline ) );
594 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
596 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
598 ClearReferenceObjects( DataTag_Polyline );
600 // Indicate model of the need to update zones splitting
604 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
606 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
608 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
610 // Indicate model of the need to update land covers partition
611 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
615 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
617 return Handle(HYDROData_StricklerTable)::DownCast(
618 GetReferenceObject( DataTag_StricklerTable ) );
621 void HYDROData_CalculationCase::RemoveStricklerTable()
623 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
625 ClearReferenceObjects( DataTag_StricklerTable );
627 // Indicate model of the need to update land covers partition
631 bool HYDROData_CalculationCase::AddLandCover( const Handle(HYDROData_LandCover)& theLandCover )
633 if ( HasReference( theLandCover, DataTag_LandCover ) )
634 return false; // Land cover is already in reference list
636 AddReferenceObject( theLandCover, DataTag_LandCover );
638 // Indicate model of the need to update land covers partition
644 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetLandCovers() const
646 return GetReferenceObjects( DataTag_LandCover );
649 void HYDROData_CalculationCase::RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover )
651 if ( theLandCover.IsNull() )
654 RemoveReferenceObject( theLandCover->Label(), DataTag_LandCover );
656 // Indicate model of the need to update land cover partition
660 void HYDROData_CalculationCase::RemoveLandCovers()
662 ClearReferenceObjects( DataTag_LandCover );
664 // Indicate model of the need to update land cover partition
668 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone,
669 const bool theLandCover )
671 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
672 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
673 if ( aNewRegion.IsNull() )
676 aNewRegion->AddZone( theZone );
681 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion,
682 const bool theLandCover )
684 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
686 if ( theRegion.IsNull() )
689 HYDROData_CalculationCase::DataTag aDataTag =
690 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
692 if ( HasReference( theRegion, aDataTag ) )
693 return false; // Object is already in reference list
695 // Move the region from other calculation
696 Handle(HYDROData_CalculationCase) aFatherCalc =
697 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
698 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
700 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
701 theRegion->CopyTo( aNewRegion, true );
703 aFatherCalc->RemoveRegion( theRegion, theLandCover );
705 theRegion->SetLabel( aNewRegion->Label() );
709 AddReferenceObject( theRegion, aDataTag );
715 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions( const bool theLandCover ) const
717 return GetReferenceObjects( theLandCover ? DataTag_LandCoverRegion : DataTag_Region );
720 void HYDROData_CalculationCase::UpdateRegionsOrder()
722 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
723 if ( aDocument.IsNull() )
726 HYDROData_SequenceOfObjects aRegions = GetRegions( false );
727 HYDROData_SequenceOfObjects aRegionsLC = GetRegions( true );
728 aRegions.Append( aRegionsLC );
730 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
731 for ( ; anIter.More(); anIter.Next() )
733 Handle(HYDROData_Region) aRegion =
734 Handle(HYDROData_Region)::DownCast( anIter.Value() );
735 if ( aRegion.IsNull() )
738 aRegion->SetName( "" );
741 QString aRegsPref = CALCULATION_REGIONS_PREF;
743 anIter.Init( aRegions );
744 for ( ; anIter.More(); anIter.Next() )
746 Handle(HYDROData_Region) aRegion =
747 Handle(HYDROData_Region)::DownCast( anIter.Value() );
748 if ( aRegion.IsNull() )
751 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
752 aRegion->SetName( aRegionName );
756 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion,
757 const bool theLandCover )
759 if ( theRegion.IsNull() )
762 HYDROData_CalculationCase::DataTag aDataTag =
763 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
764 RemoveReferenceObject( theRegion->Label(), aDataTag );
766 // Remove region from data model
767 Handle(HYDROData_CalculationCase) aFatherCalc =
768 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
769 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
773 void HYDROData_CalculationCase::RemoveRegions( const bool theLandCover )
775 myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).ForgetAllAttributes();
778 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
780 return GetReferenceObjects( DataTag_SplittedGroups );
783 void HYDROData_CalculationCase::RemoveSplittedGroups()
785 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
788 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
790 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
791 return GetAltitudeForPoint( thePoint, aZone );
794 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
795 const Handle(HYDROData_Region)& theRegion ) const
797 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
799 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
800 if ( !aZone.IsNull() )
802 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
803 if ( IsEqual( aRefRegion, theRegion ) )
804 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
810 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
811 const Handle(HYDROData_Zone)& theZone ) const
813 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
814 if ( theZone.IsNull() )
817 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
818 if ( !theZone->IsMergingNeed() )
820 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
822 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
827 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
828 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
830 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
831 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
832 if ( !aMergeAltitude.IsNull() )
834 if ( aZoneInterpolator != NULL )
836 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
837 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
840 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
845 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
846 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
847 for ( ; anIter.More(); anIter.Next() )
849 Handle(HYDROData_Object) aZoneObj =
850 Handle(HYDROData_Object)::DownCast( anIter.Value() );
851 if ( aZoneObj.IsNull() )
854 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
855 if ( anObjAltitude.IsNull() )
858 double aPointAltitude = 0.0;
859 if ( aZoneInterpolator != NULL )
861 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
862 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
865 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
867 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
870 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
872 aResAltitude = aPointAltitude;
875 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
877 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
878 aResAltitude > aPointAltitude )
880 aResAltitude = aPointAltitude;
883 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
885 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
886 aResAltitude < aPointAltitude )
888 aResAltitude = aPointAltitude;
897 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
898 const NCollection_Sequence<gp_XY>& thePoints,
899 const Handle(HYDROData_Region)& theRegion ) const
901 NCollection_Sequence<double> aResSeq;
903 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
905 const gp_XY& thePnt = thePoints.Value( i );
907 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
908 aResSeq.Append( anAltitude );
914 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
915 const NCollection_Sequence<gp_XY>& thePoints,
916 const Handle(HYDROData_Zone)& theZone ) const
918 NCollection_Sequence<double> aResSeq;
920 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
922 const gp_XY& thePnt = thePoints.Value( i );
924 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
925 aResSeq.Append( anAltitude );
931 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
934 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
935 if ( !aDocument.IsNull() )
936 aCoeff = aDocument->GetDefaultStricklerCoefficient();
938 Handle(HYDROData_LandCover) aLandCover;
939 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, Standard_True );
940 if ( !aZone.IsNull() )
942 HYDROData_SequenceOfObjects anObjList = aZone->GetObjects();
943 if ( anObjList.Length() == 1 )
944 aLandCover = Handle(HYDROData_LandCover)::DownCast( anObjList.First() );
946 aLandCover = Handle(HYDROData_LandCover)::DownCast( aZone->GetMergeObject() );
949 if ( !aLandCover.IsNull() )
951 QString aType = aLandCover->GetStricklerType();
952 Handle(HYDROData_StricklerTable) aTable = GetStricklerTable();
953 if ( !aTable.IsNull() )
955 if ( aTable->GetTypes().contains( aType ) )
956 aCoeff = aTable->Get( aType, aCoeff );
963 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint,
964 const bool theLandCover ) const
966 Handle(HYDROData_Region) aResRegion;
968 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, theLandCover );
969 if ( !aZone.IsNull() )
970 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
975 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint,
976 const bool theLandCover ) const
978 Handle(HYDROData_Zone) aResZone;
980 HYDROData_SequenceOfObjects aRegions = GetRegions( theLandCover );
982 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
983 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
985 Handle(HYDROData_Region) aRegion =
986 Handle(HYDROData_Region)::DownCast( anIter.Value() );
987 if ( aRegion.IsNull() )
990 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
991 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
992 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
994 Handle(HYDROData_Zone) aRegZone =
995 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
996 if ( aRegZone.IsNull() )
999 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1000 if ( aPointRelation != POINT_OUT )
1001 aResZone = aRegZone; // We found the desired zone
1008 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1009 const gp_XY& thePoint,
1010 const Handle(HYDROData_Zone)& theZone ) const
1012 PointClassification aRes = POINT_OUT;
1013 if ( theZone.IsNull() )
1016 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1017 if ( aZoneFace.IsNull() )
1020 TopoDS_Compound aCmp;
1022 aBB.MakeCompound(aCmp);
1023 aBB.Add(aCmp, aZoneFace);
1024 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1025 BRepBuilderAPI_MakeVertex aMk(aPnt);
1026 aBB.Add(aCmp, aMk.Vertex());
1027 BRepTools::Write(aCmp, "FCL2d.brep");
1029 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1030 if (State == TopAbs_OUT)
1032 else if(State == TopAbs_IN)
1034 else if(State == TopAbs_ON)
1039 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1040 const QString& thePrefixOrName,
1041 const bool theLandCover,
1044 TDF_Label aNewLab = myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).NewChild();
1045 int aTag = aNewLab.Tag();
1047 Handle(HYDROData_Region) aNewRegion =
1048 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1049 AddRegion( aNewRegion, theLandCover );
1051 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1052 aNewRegion->SetName( aRegionName );
1057 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
1059 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
1061 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
1062 Handle(HYDROData_SplittedShapesGroup)::DownCast(
1063 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
1064 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
1066 aNewGroup->SetName( theName );
1071 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1076 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1077 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1079 QString aGeomObjEntry, anErrorMsg;
1080 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1081 return isOK ? aGeomObjEntry : QString();
1086 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1087 SALOMEDS::Study_ptr theStudy,
1088 QString& theGeomObjEntry,
1089 QString& theErrorMsg ) const
1091 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1093 // Get groups definitions
1094 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
1096 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
1097 for ( ; anIter.More(); anIter.Next() )
1100 Handle(HYDROData_ShapesGroup) aGroup =
1101 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1102 if ( aGroup.IsNull() )
1105 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1107 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1108 aGroup->GetShapes( aGroupDef.Shapes );
1110 aSeqOfGroupsDefs.Append( aGroupDef );
1114 bool isAllNotSubmersible = true;
1115 TopTools_ListOfShape aFaces;
1116 HYDROData_SequenceOfObjects aCaseRegions = GetRegions( false );
1117 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1118 for ( ; aRegionIter.More(); aRegionIter.Next() )
1120 Handle(HYDROData_Region) aRegion =
1121 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1122 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1125 if ( isAllNotSubmersible )
1126 isAllNotSubmersible = false;
1128 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1129 aFaces.Append( aRegionShape );
1134 if ( aCaseRegions.IsEmpty() ) {
1135 theErrorMsg = QString("the list of regions is empty.");
1136 } else if ( isAllNotSubmersible ) {
1137 theErrorMsg = QString("there are no submersible regions.");
1139 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1145 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1146 SALOMEDS::Study_ptr theStudy,
1147 const TopTools_ListOfShape& theFaces,
1148 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1149 QString& theGeomObjEntry ) const
1152 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1153 aSewing.SetNonManifoldMode( Standard_False );
1154 #ifdef DEB_CALCULATION
1155 TCollection_AsciiString aNam("Sh_");
1158 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1159 for ( ; aFaceIter.More(); aFaceIter.Next() )
1161 TopoDS_Shape aShape = aFaceIter.Value();
1162 if ( aShape.IsNull() )
1165 if ( aShape.ShapeType() == TopAbs_FACE )
1167 aSewing.Add( aShape );
1168 #ifdef DEB_CALCULATION
1169 TCollection_AsciiString aName = aNam + ++i + ".brep";
1170 BRepTools::Write(aShape ,aName.ToCString());
1175 #ifdef DEB_CALCULATION
1178 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1179 for (; anExp.More(); anExp.Next() ) {
1180 aSewing.Add( anExp.Current() );
1181 #ifdef DEB_CALCULATION
1183 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1184 BRepTools::Write(anExp.Current() ,aName.ToCString());
1191 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1193 // If the sewed shape is empty - return false
1194 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1197 #ifdef DEB_CALCULATION
1198 BRepTools::Write(aSewedShape ,"Sew.brep");
1200 // Publish the sewed shape
1201 QString aName = EXPORT_NAME;
1202 GEOM::GEOM_Object_ptr aMainShape =
1203 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1205 if ( aMainShape->_is_nil() )
1208 if ( theGroupsDefs.IsEmpty() )
1212 TopTools_IndexedMapOfShape aMapOfSubShapes;
1213 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1215 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1217 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1219 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1221 NCollection_Sequence<int> aGroupIndexes;
1222 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1224 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1225 #ifdef DEB_CALCULATION
1226 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1229 TopoDS_Shape aModifiedShape = aShape;
1230 if ( aSewing.IsModified( aShape ) )
1231 aModifiedShape = aSewing.Modified( aShape );
1232 else if ( aSewing.IsModifiedSubShape( aShape ) )
1233 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1235 #ifdef DEB_CALCULATION
1236 const TopLoc_Location& aL1 = aShape.Location();
1237 const TopLoc_Location& aL2 = aModifiedShape.Location();
1238 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1241 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1242 if ( anIndex > 0 ) {
1243 aGroupIndexes.Append( anIndex );
1245 #ifdef DEB_CALCULATION
1246 TCollection_AsciiString aNam("Lost_");
1247 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1248 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1250 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1251 if ( aModifiedShape.IsPartner( aS ) )
1253 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1254 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1255 BRepTools::Write(aS ,aName.ToCString());
1263 if ( !aGroupIndexes.IsEmpty() )
1264 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1267 if ( !aGroupsData.IsEmpty() )
1269 GEOM::GEOM_IGroupOperations_var aGroupOp =
1270 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1272 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1273 for ( ; aMapIt.More(); aMapIt.Next() )
1275 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1276 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1278 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1279 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1282 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1283 aGeomIndexes->length( aGroupIndexes.Length() );
1285 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1286 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1288 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1289 if ( aGroupOp->IsDone() )
1291 SALOMEDS::SObject_var aGroupSO =
1292 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1301 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1302 const bool theIsSetToUpdate )
1304 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1305 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1307 // Indicate model of the need to update splitting
1308 if ( theIsSetToUpdate ) {
1313 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1314 HYDROData_PriorityType thePriority,
1315 const Handle(HYDROData_Entity)& theObject2,
1316 HYDROData_Zone::MergeType theMergeType,
1317 HYDROData_CalculationCase::DataTag theDataTag )
1319 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1320 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1322 // Indicate model of the need to update splitting
1326 QString HYDROData_CalculationCase::DumpRules() const
1328 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1329 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1332 QString HYDROData_CalculationCase::DumpLandCoverRules() const
1334 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1335 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1338 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1340 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1341 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1343 // Indicate model of the need to update splitting
1347 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1349 Handle(TDataStd_Integer) aModeAttr;
1350 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1352 return ( AssignmentMode ) aModeAttr->Get();
1357 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1358 QStringList& theScript ) const
1360 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1361 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1364 void HYDROData_CalculationCase::DumpLandCoverRulesToPython( const QString& theCalcCaseName,
1365 QStringList& theScript ) const
1367 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1368 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1371 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1373 return myLastWarning;
1376 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1378 myLastWarning.Type = theType;
1379 myLastWarning.Data = theData;
1382 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1383 const QString& theOldCaseName,
1384 const QString& theName )
1386 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1387 for ( ; anIter.More(); anIter.Next() )
1389 Handle(HYDROData_Region) aRegion =
1390 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1391 if ( aRegion.IsNull() )
1394 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1396 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1397 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1398 for ( ; anIter.More(); anIter.Next() )
1400 Handle(HYDROData_Zone) aRegZone =
1401 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1402 if ( aRegZone.IsNull() )
1405 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1410 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1411 MapOfTreatedObjects& theTreatedObjects,
1412 const HYDROData_SequenceOfObjects& theRegions ) const
1414 HYDROData_SequenceOfObjects::Iterator anIter;
1415 anIter.Init( theRegions );
1416 for ( ; anIter.More(); anIter.Next() )
1418 Handle(HYDROData_Region) aRegion =
1419 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1420 if ( aRegion.IsNull() )
1423 theTreatedObjects.insert( aRegion->GetName(), aRegion );
1424 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
1425 theResList << aRegDump;
1429 bool HYDROData_CalculationCase::GetRule( int theIndex,
1430 Handle(HYDROData_Entity)& theObject1,
1431 HYDROData_PriorityType& thePriority,
1432 Handle(HYDROData_Entity)& theObject2,
1433 HYDROData_Zone::MergeType& theMergeType,
1434 HYDROData_CalculationCase::DataTag& theDataTag) const
1436 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1437 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1438 theObject1, thePriority, theObject2, theMergeType );
1441 void HYDROData_CalculationCase::SetAssignmentLandCoverMode( AssignmentMode theMode )
1443 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentLandCoverMode );
1444 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1446 // Indicate model of the need to update land covers partition
1450 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentLandCoverMode() const
1452 Handle(TDataStd_Integer) aModeAttr;
1453 bool isOK = myLab.FindChild( DataTag_AssignmentLandCoverMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1455 return ( AssignmentMode ) aModeAttr->Get();