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
20 #pragma warning ( disable: 4251 )
23 #include "HYDROData_CalculationCase.h"
24 #include "HYDROData_ArtificialObject.h"
25 #include "HYDROData_IAltitudeObject.h"
26 #include "HYDROData_Document.h"
27 #include "HYDROData_ShapesGroup.h"
28 #include "HYDROData_Iterator.h"
29 #include "HYDROData_NaturalObject.h"
30 #include "HYDROData_PolylineXY.h"
31 #include "HYDROData_StricklerTable.h"
32 #include "HYDROData_LandCover.h"
33 #include "HYDROData_SplittedShapesGroup.h"
34 #include "HYDROData_Region.h"
35 #include "HYDROData_Tool.h"
36 #include "HYDROData_GeomTool.h"
45 #include <TopoDS_Shell.hxx>
46 #include <TopoDS_Edge.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRepBuilderAPI_Sewing.hxx>
50 #include <BRepTopAdaptor_FClass2d.hxx>
52 #include <BRepTools.hxx>
55 #include <TopExp_Explorer.hxx>
57 #include <TopTools_ListOfShape.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TDataStd_Integer.hxx>
61 //#define DEB_CALCULATION 1
62 #ifdef DEB_CALCULATION
63 #include <BRepTools.hxx>
64 #include <TopLoc_Location.hxx>
66 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
67 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
68 #define CALCULATION_LANDCOVER_ZONES_PREF GetName() + "_LandCoverZone"
69 #define CALCULATION_GROUPS_PREF GetName() + "_"
70 //#define DEB_CLASS2D 1
72 #include <BRepBuilderAPI_MakeVertex.hxx>
76 #pragma warning ( default: 4251 )
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()
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 );
265 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions( false );
266 aResSeq.Append( aSeqOfRegions );
268 // Land cover regions
269 HYDROData_SequenceOfObjects aSeqOfLandCoverRegions = GetRegions( true );
270 aResSeq.Append( aSeqOfLandCoverRegions );
275 void HYDROData_CalculationCase::Update()
277 HYDROData_Entity::Update();
280 // At first we remove previously created objects
281 RemoveRegions( false );
282 RemoveRegions( true );
283 RemoveSplittedGroups();
285 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
286 if ( aDocument.IsNull() )
290 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
292 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
293 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
294 if ( !aGeomObjects.IsEmpty() ) {
295 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
297 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
298 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
299 if ( !aSplitObjects.isEmpty() ) {
300 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
301 while( anIter.hasNext() ) {
302 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
303 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
304 aZonesList.append( aSplitData );
305 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
306 anEdgesList.append( aSplitData );
311 // Split to land cover zones
312 HYDROData_SplitToZonesTool::SplitDataList aLandCoverZonesList;
314 HYDROData_SequenceOfObjects aLandCovers = GetLandCovers();
315 if ( !aLandCovers.IsEmpty() ) {
316 HYDROData_SplitToZonesTool::SplitDataList aSplitLandCoverObjects =
317 HYDROData_SplitToZonesTool::Split( aLandCovers );
318 if ( !aSplitLandCoverObjects.isEmpty() ) {
319 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitLandCoverObjects );
320 while( anIter.hasNext() ) {
321 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
322 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
323 aLandCoverZonesList.append( aSplitData );
328 switch( GetAssignmentMode() )
331 CreateRegionsDef( aDocument, aZonesList, false );
334 CreateRegionsAuto( aDocument, aZonesList, false );
338 switch( GetAssignmentLandCoverMode() )
341 CreateRegionsDef( aDocument, aLandCoverZonesList, true );
344 CreateRegionsAuto( aDocument, aLandCoverZonesList, true );
348 CreateEdgeGroupsDef( aDocument, anEdgesList );
351 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
352 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
353 const bool theLandCover )
355 // Create result regions for case, by default one zone for one region
356 QString aRegsPref = CALCULATION_REGIONS_PREF;
357 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
359 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
360 while( anIter.hasNext() )
362 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
364 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref, theLandCover );
366 // Add the zone for region
367 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
371 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
372 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
373 const bool theLandCover )
375 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
376 QMap<QString, QString> aRegionNameToObjNameMap;
377 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
378 HYDROData_PriorityQueue aPr( this, theLandCover ? DataTag_CustomLandCoverRules : DataTag_CustomRules );
380 // 1. First we create a default region for each object included into the calculation case
381 HYDROData_SequenceOfObjects anObjects = theLandCover ? GetLandCovers() : GetGeometryObjects();
382 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
384 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
387 QString anObjName = anObj->GetName();
388 QString aRegName = anObjName + "_reg";
389 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, theLandCover, false );
390 aRegionsMap.insert( anObjName, aRegion );
391 aRegionNameToObjNameMap.insert( aRegName, anObjName );
394 // 2. Now for each zone it is necessary to determine the most priority object
395 // and assign to zone to corresponding region
396 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
397 while( anIter.hasNext() )
399 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
400 HYDROData_Zone::MergeType aMergeType;
401 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
402 if( aRegObj.IsNull() )
404 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
405 if( aRegion.IsNull() )
407 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
409 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
411 qDebug( "Error in algorithm: unresolved conflicts" );
414 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
415 if ( !theLandCover ) {
416 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
417 if ( !aMergeObject.IsNull() ) {
418 aMergeEntity = aMergeObject->GetAltitudeObject();
424 case HYDROData_Zone::Merge_ZMIN:
425 case HYDROData_Zone::Merge_ZMAX:
426 aRegionZone->SetMergeType( aMergeType );
428 case HYDROData_Zone::Merge_Object:
429 aRegionZone->SetMergeType( aMergeType );
430 aRegionZone->RemoveMergeObject();
431 aRegionZone->SetMergeObject( aMergeEntity );
436 QStringList anObjectsWithEmptyRegions;
437 QMap<QString, Handle(HYDROData_Region)>::const_iterator
438 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
439 for( ; anIt!=aLast; anIt++ )
441 Handle(HYDROData_Region) aRegion = anIt.value();
442 if( aRegion->GetZones().IsEmpty() )
444 QString aRegName = aRegion->GetName();
445 QString anObjName = aRegionNameToObjNameMap[aRegName];
446 anObjectsWithEmptyRegions.append( anObjName );
450 if( !anObjectsWithEmptyRegions.empty() )
452 QString aData = anObjectsWithEmptyRegions.join( ", " );
453 SetWarning( WARN_EMPTY_REGIONS, aData );
457 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
458 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
460 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
462 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
463 while( anIter.hasNext() )
465 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
466 // Create new edges group
467 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
470 QString anObjName = aSplitData.ObjectNames.first();
471 if ( anObjName.isEmpty() )
473 #ifdef DEB_CALCULATION
474 QString aStr = aSplitData.ObjectNames.join(" ");
475 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
477 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
478 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
480 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
481 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
485 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
487 if ( aSplittedGroup.IsNull() )
490 aSplittedGroup->AddShape( aSplitData.Shape );
494 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
496 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
497 return false; // Wrong type of object
499 if ( HasReference( theObject, DataTag_GeometryObject ) )
500 return false; // Object is already in reference list
502 AddReferenceObject( theObject, DataTag_GeometryObject );
504 // Indicate model of the need to update splitting
510 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
512 return GetReferenceObjects( DataTag_GeometryObject );
515 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
517 if ( theObject.IsNull() )
520 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
522 // Indicate model of the need to update splitting
526 void HYDROData_CalculationCase::RemoveGeometryObjects()
528 ClearReferenceObjects( DataTag_GeometryObject );
530 // Indicate model of the need to update splitting
534 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
536 if ( theGroup.IsNull() )
539 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
540 return false; // Object is already in reference list
542 AddReferenceObject( theGroup, DataTag_GeometryGroup );
544 // Indicate model of the need to update splitting
550 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
552 return GetReferenceObjects( DataTag_GeometryGroup );
555 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
557 if ( theGroup.IsNull() )
560 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
562 // Indicate model of the need to update splitting
566 void HYDROData_CalculationCase::RemoveGeometryGroups()
568 ClearReferenceObjects( DataTag_GeometryGroup );
570 // Indicate model of the need to update splitting
574 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
576 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
578 SetReferenceObject( thePolyline, DataTag_Polyline );
580 // Indicate model of the need to update zones splitting
581 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
584 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
586 return Handle(HYDROData_PolylineXY)::DownCast(
587 GetReferenceObject( DataTag_Polyline ) );
590 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
592 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
594 ClearReferenceObjects( DataTag_Polyline );
596 // Indicate model of the need to update zones splitting
597 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
600 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
602 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
604 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
606 // Indicate model of the need to update land covers partition
607 SetToUpdate( !IsEqual( aPrevStricklerTable, theStricklerTable ) || IsMustBeUpdated() );
610 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
612 return Handle(HYDROData_StricklerTable)::DownCast(
613 GetReferenceObject( DataTag_StricklerTable ) );
616 void HYDROData_CalculationCase::RemoveStricklerTable()
618 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
620 ClearReferenceObjects( DataTag_StricklerTable );
622 // Indicate model of the need to update land covers partition
623 SetToUpdate( !aPrevStricklerTable.IsNull() || IsMustBeUpdated() );
626 bool HYDROData_CalculationCase::AddLandCover( const Handle(HYDROData_LandCover)& theLandCover )
628 if ( HasReference( theLandCover, DataTag_LandCover ) )
629 return false; // Land cover is already in reference list
631 AddReferenceObject( theLandCover, DataTag_LandCover );
633 // Indicate model of the need to update land covers partition
639 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetLandCovers() const
641 return GetReferenceObjects( DataTag_LandCover );
644 void HYDROData_CalculationCase::RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover )
646 if ( theLandCover.IsNull() )
649 RemoveReferenceObject( theLandCover->Label(), DataTag_LandCover );
651 // Indicate model of the need to update land cover partition
655 void HYDROData_CalculationCase::RemoveLandCovers()
657 ClearReferenceObjects( DataTag_LandCover );
659 // Indicate model of the need to update land cover partition
663 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone,
664 const bool theLandCover )
666 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
667 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
668 if ( aNewRegion.IsNull() )
671 aNewRegion->AddZone( theZone );
676 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion,
677 const bool theLandCover )
679 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
681 if ( theRegion.IsNull() )
684 HYDROData_CalculationCase::DataTag aDataTag =
685 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
687 if ( HasReference( theRegion, aDataTag ) )
688 return false; // Object is already in reference list
690 // Move the region from other calculation
691 Handle(HYDROData_CalculationCase) aFatherCalc =
692 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
693 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
695 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
696 theRegion->CopyTo( aNewRegion, true );
698 aFatherCalc->RemoveRegion( theRegion, theLandCover );
700 theRegion->SetLabel( aNewRegion->Label() );
704 AddReferenceObject( theRegion, aDataTag );
710 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions( const bool theLandCover ) const
712 return GetReferenceObjects( theLandCover ? DataTag_LandCoverRegion : DataTag_Region );
715 void HYDROData_CalculationCase::UpdateRegionsOrder()
717 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
718 if ( aDocument.IsNull() )
721 HYDROData_SequenceOfObjects aRegions = GetRegions( false );
722 HYDROData_SequenceOfObjects aRegionsLC = GetRegions( true );
723 aRegions.Append( aRegionsLC );
725 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
726 for ( ; anIter.More(); anIter.Next() )
728 Handle(HYDROData_Region) aRegion =
729 Handle(HYDROData_Region)::DownCast( anIter.Value() );
730 if ( aRegion.IsNull() )
733 aRegion->SetName( "" );
736 QString aRegsPref = CALCULATION_REGIONS_PREF;
738 anIter.Init( aRegions );
739 for ( ; anIter.More(); anIter.Next() )
741 Handle(HYDROData_Region) aRegion =
742 Handle(HYDROData_Region)::DownCast( anIter.Value() );
743 if ( aRegion.IsNull() )
746 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
747 aRegion->SetName( aRegionName );
751 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion,
752 const bool theLandCover )
754 if ( theRegion.IsNull() )
757 HYDROData_CalculationCase::DataTag aDataTag =
758 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
759 RemoveReferenceObject( theRegion->Label(), aDataTag );
761 // Remove region from data model
762 Handle(HYDROData_CalculationCase) aFatherCalc =
763 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
764 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
768 void HYDROData_CalculationCase::RemoveRegions( const bool theLandCover )
770 myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).ForgetAllAttributes();
773 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
775 return GetReferenceObjects( DataTag_SplittedGroups );
778 void HYDROData_CalculationCase::RemoveSplittedGroups()
780 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
783 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
785 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
786 return GetAltitudeForPoint( thePoint, aZone );
789 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
790 const Handle(HYDROData_Region)& theRegion ) const
792 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
794 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
795 if ( !aZone.IsNull() )
797 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
798 if ( IsEqual( aRefRegion, theRegion ) )
799 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
805 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
806 const Handle(HYDROData_Zone)& theZone ) const
808 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
809 if ( theZone.IsNull() )
812 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
813 if ( !theZone->IsMergingNeed() )
815 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
817 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
822 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
823 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
825 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
826 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
827 if ( !aMergeAltitude.IsNull() )
829 if ( aZoneInterpolator != NULL )
831 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
832 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
835 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
840 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
841 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
842 for ( ; anIter.More(); anIter.Next() )
844 Handle(HYDROData_Object) aZoneObj =
845 Handle(HYDROData_Object)::DownCast( anIter.Value() );
846 if ( aZoneObj.IsNull() )
849 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
850 if ( anObjAltitude.IsNull() )
853 double aPointAltitude = 0.0;
854 if ( aZoneInterpolator != NULL )
856 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
857 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
860 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
862 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
865 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
867 aResAltitude = aPointAltitude;
870 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
872 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
873 aResAltitude > aPointAltitude )
875 aResAltitude = aPointAltitude;
878 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
880 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
881 aResAltitude < aPointAltitude )
883 aResAltitude = aPointAltitude;
892 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
893 const NCollection_Sequence<gp_XY>& thePoints,
894 const Handle(HYDROData_Region)& theRegion ) const
896 NCollection_Sequence<double> aResSeq;
898 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
900 const gp_XY& thePnt = thePoints.Value( i );
902 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
903 aResSeq.Append( anAltitude );
909 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
910 const NCollection_Sequence<gp_XY>& thePoints,
911 const Handle(HYDROData_Zone)& theZone ) const
913 NCollection_Sequence<double> aResSeq;
915 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
917 const gp_XY& thePnt = thePoints.Value( i );
919 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
920 aResSeq.Append( anAltitude );
926 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
929 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
930 if ( !aDocument.IsNull() )
931 aCoeff = aDocument->GetDefaultStricklerCoefficient();
933 Handle(HYDROData_LandCover) aLandCover;
934 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, Standard_True );
935 if ( !aZone.IsNull() )
937 HYDROData_SequenceOfObjects anObjList = aZone->GetObjects();
938 if ( anObjList.Length() == 1 )
939 aLandCover = Handle(HYDROData_LandCover)::DownCast( anObjList.First() );
941 aLandCover = Handle(HYDROData_LandCover)::DownCast( aZone->GetMergeObject() );
944 if ( !aLandCover.IsNull() )
946 QString aType = aLandCover->GetStricklerType();
947 Handle(HYDROData_StricklerTable) aTable = GetStricklerTable();
948 if ( !aTable.IsNull() )
950 if ( aTable->GetTypes().contains( aType ) )
951 aCoeff = aTable->Get( aType, aCoeff );
958 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint,
959 const bool theLandCover ) const
961 Handle(HYDROData_Region) aResRegion;
963 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, theLandCover );
964 if ( !aZone.IsNull() )
965 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
970 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint,
971 const bool theLandCover ) const
973 Handle(HYDROData_Zone) aResZone;
975 HYDROData_SequenceOfObjects aRegions = GetRegions( theLandCover );
977 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
978 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
980 Handle(HYDROData_Region) aRegion =
981 Handle(HYDROData_Region)::DownCast( anIter.Value() );
982 if ( aRegion.IsNull() )
985 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
986 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
987 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
989 Handle(HYDROData_Zone) aRegZone =
990 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
991 if ( aRegZone.IsNull() )
994 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
995 if ( aPointRelation != POINT_OUT )
996 aResZone = aRegZone; // We found the desired zone
1003 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1004 const gp_XY& thePoint,
1005 const Handle(HYDROData_Zone)& theZone ) const
1007 PointClassification aRes = POINT_OUT;
1008 if ( theZone.IsNull() )
1011 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1012 if ( aZoneFace.IsNull() )
1015 TopoDS_Compound aCmp;
1017 aBB.MakeCompound(aCmp);
1018 aBB.Add(aCmp, aZoneFace);
1019 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1020 BRepBuilderAPI_MakeVertex aMk(aPnt);
1021 aBB.Add(aCmp, aMk.Vertex());
1022 BRepTools::Write(aCmp, "FCL2d.brep");
1024 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1025 if (State == TopAbs_OUT)
1027 else if(State == TopAbs_IN)
1029 else if(State == TopAbs_ON)
1034 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1035 const QString& thePrefixOrName,
1036 const bool theLandCover,
1039 TDF_Label aNewLab = myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).NewChild();
1040 int aTag = aNewLab.Tag();
1042 Handle(HYDROData_Region) aNewRegion =
1043 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1044 AddRegion( aNewRegion, theLandCover );
1046 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1047 aNewRegion->SetName( aRegionName );
1052 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
1054 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
1056 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
1057 Handle(HYDROData_SplittedShapesGroup)::DownCast(
1058 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
1059 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
1061 aNewGroup->SetName( theName );
1066 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1071 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1072 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1074 QString aGeomObjEntry, anErrorMsg;
1075 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1076 return isOK ? aGeomObjEntry : QString();
1081 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1082 SALOMEDS::Study_ptr theStudy,
1083 QString& theGeomObjEntry,
1084 QString& theErrorMsg ) const
1086 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1088 // Get groups definitions
1089 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
1091 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
1092 for ( ; anIter.More(); anIter.Next() )
1095 Handle(HYDROData_ShapesGroup) aGroup =
1096 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1097 if ( aGroup.IsNull() )
1100 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1102 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1103 aGroup->GetShapes( aGroupDef.Shapes );
1105 aSeqOfGroupsDefs.Append( aGroupDef );
1109 bool isAllNotSubmersible = true;
1110 TopTools_ListOfShape aFaces;
1111 HYDROData_SequenceOfObjects aCaseRegions = GetRegions( false );
1112 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1113 for ( ; aRegionIter.More(); aRegionIter.Next() )
1115 Handle(HYDROData_Region) aRegion =
1116 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1117 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1120 if ( isAllNotSubmersible )
1121 isAllNotSubmersible = false;
1123 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1124 aFaces.Append( aRegionShape );
1129 if ( aCaseRegions.IsEmpty() ) {
1130 theErrorMsg = QString("the list of regions is empty.");
1131 } else if ( isAllNotSubmersible ) {
1132 theErrorMsg = QString("there are no submersible regions.");
1134 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1140 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1141 SALOMEDS::Study_ptr theStudy,
1142 const TopTools_ListOfShape& theFaces,
1143 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1144 QString& theGeomObjEntry ) const
1147 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1148 aSewing.SetNonManifoldMode( Standard_False );
1149 #ifdef DEB_CALCULATION
1150 TCollection_AsciiString aNam("Sh_");
1153 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1154 for ( ; aFaceIter.More(); aFaceIter.Next() )
1156 TopoDS_Shape aShape = aFaceIter.Value();
1157 if ( aShape.IsNull() )
1160 if ( aShape.ShapeType() == TopAbs_FACE )
1162 aSewing.Add( aShape );
1163 #ifdef DEB_CALCULATION
1164 TCollection_AsciiString aName = aNam + ++i + ".brep";
1165 BRepTools::Write(aShape ,aName.ToCString());
1170 #ifdef DEB_CALCULATION
1173 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1174 for (; anExp.More(); anExp.Next() ) {
1175 aSewing.Add( anExp.Current() );
1176 #ifdef DEB_CALCULATION
1178 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1179 BRepTools::Write(anExp.Current() ,aName.ToCString());
1186 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1188 // If the sewed shape is empty - return false
1189 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1192 #ifdef DEB_CALCULATION
1193 BRepTools::Write(aSewedShape ,"Sew.brep");
1195 // Publish the sewed shape
1196 QString aName = EXPORT_NAME;
1197 GEOM::GEOM_Object_ptr aMainShape =
1198 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1200 if ( aMainShape->_is_nil() )
1203 if ( theGroupsDefs.IsEmpty() )
1207 TopTools_IndexedMapOfShape aMapOfSubShapes;
1208 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1210 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1212 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1214 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1216 NCollection_Sequence<int> aGroupIndexes;
1217 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1219 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1220 #ifdef DEB_CALCULATION
1221 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1224 TopoDS_Shape aModifiedShape = aShape;
1225 if ( aSewing.IsModified( aShape ) )
1226 aModifiedShape = aSewing.Modified( aShape );
1227 else if ( aSewing.IsModifiedSubShape( aShape ) )
1228 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1230 #ifdef DEB_CALCULATION
1231 const TopLoc_Location& aL1 = aShape.Location();
1232 const TopLoc_Location& aL2 = aModifiedShape.Location();
1233 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1236 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1237 if ( anIndex > 0 ) {
1238 aGroupIndexes.Append( anIndex );
1240 #ifdef DEB_CALCULATION
1241 TCollection_AsciiString aNam("Lost_");
1242 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1243 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1245 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1246 if ( aModifiedShape.IsPartner( aS ) )
1248 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1249 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1250 BRepTools::Write(aS ,aName.ToCString());
1258 if ( !aGroupIndexes.IsEmpty() )
1259 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1262 if ( !aGroupsData.IsEmpty() )
1264 GEOM::GEOM_IGroupOperations_var aGroupOp =
1265 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1267 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1268 for ( ; aMapIt.More(); aMapIt.Next() )
1270 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1271 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1273 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1274 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1277 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1278 aGeomIndexes->length( aGroupIndexes.Length() );
1280 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1281 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1283 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1284 if ( aGroupOp->IsDone() )
1286 SALOMEDS::SObject_var aGroupSO =
1287 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1296 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1297 const bool theIsSetToUpdate )
1299 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1300 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1302 // Indicate model of the need to update splitting
1303 if ( theIsSetToUpdate ) {
1304 SetToUpdate( true );
1308 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1309 HYDROData_PriorityType thePriority,
1310 const Handle(HYDROData_Entity)& theObject2,
1311 HYDROData_Zone::MergeType theMergeType,
1312 HYDROData_CalculationCase::DataTag theDataTag )
1314 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1315 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1317 // Indicate model of the need to update splitting
1318 SetToUpdate( true );
1321 QString HYDROData_CalculationCase::DumpRules() const
1323 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1324 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1327 QString HYDROData_CalculationCase::DumpLandCoverRules() const
1329 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1330 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1333 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1335 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1336 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1338 // Indicate model of the need to update splitting
1339 SetToUpdate( true );
1342 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1344 Handle(TDataStd_Integer) aModeAttr;
1345 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1347 return ( AssignmentMode ) aModeAttr->Get();
1352 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1353 QStringList& theScript ) const
1355 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1356 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1359 void HYDROData_CalculationCase::DumpLandCoverRulesToPython( const QString& theCalcCaseName,
1360 QStringList& theScript ) const
1362 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1363 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1366 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1368 return myLastWarning;
1371 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1373 myLastWarning.Type = theType;
1374 myLastWarning.Data = theData;
1377 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1378 const QString& theOldCaseName,
1379 const QString& theName )
1381 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1382 for ( ; anIter.More(); anIter.Next() )
1384 Handle(HYDROData_Region) aRegion =
1385 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1386 if ( aRegion.IsNull() )
1389 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1391 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1392 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1393 for ( ; anIter.More(); anIter.Next() )
1395 Handle(HYDROData_Zone) aRegZone =
1396 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1397 if ( aRegZone.IsNull() )
1400 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1405 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1406 MapOfTreatedObjects& theTreatedObjects,
1407 const HYDROData_SequenceOfObjects& theRegions ) const
1409 HYDROData_SequenceOfObjects::Iterator anIter;
1410 anIter.Init( theRegions );
1411 for ( ; anIter.More(); anIter.Next() )
1413 Handle(HYDROData_Region) aRegion =
1414 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1415 if ( aRegion.IsNull() )
1418 theTreatedObjects.insert( aRegion->GetName(), aRegion );
1419 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
1420 theResList << aRegDump;
1424 bool HYDROData_CalculationCase::GetRule( int theIndex,
1425 Handle(HYDROData_Entity)& theObject1,
1426 HYDROData_PriorityType& thePriority,
1427 Handle(HYDROData_Entity)& theObject2,
1428 HYDROData_Zone::MergeType& theMergeType,
1429 HYDROData_CalculationCase::DataTag& theDataTag) const
1431 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1432 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1433 theObject1, thePriority, theObject2, theMergeType );
1436 void HYDROData_CalculationCase::SetAssignmentLandCoverMode( AssignmentMode theMode )
1438 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentLandCoverMode );
1439 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1441 // Indicate model of the need to update land covers partition
1442 SetToUpdate( true );
1445 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentLandCoverMode() const
1447 Handle(TDataStd_Integer) aModeAttr;
1448 bool isOK = myLab.FindChild( DataTag_AssignmentLandCoverMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1450 return ( AssignmentMode ) aModeAttr->Get();