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"
43 #include <TopoDS_Shell.hxx>
44 #include <TopoDS_Edge.hxx>
46 #include <BRep_Builder.hxx>
47 #include <BRepBuilderAPI_Sewing.hxx>
48 #include <BRepTopAdaptor_FClass2d.hxx>
50 #include <BRepTools.hxx>
53 #include <TopExp_Explorer.hxx>
55 #include <TopTools_ListOfShape.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TDataStd_Integer.hxx>
59 //#define DEB_CALCULATION 1
60 #ifdef DEB_CALCULATION
61 #include <BRepTools.hxx>
62 #include <TopLoc_Location.hxx>
64 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
65 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
66 #define CALCULATION_LANDCOVER_ZONES_PREF GetName() + "_LandCoverZone"
67 #define CALCULATION_GROUPS_PREF GetName() + "_"
68 //#define DEB_CLASS2D 1
70 #include <BRepBuilderAPI_MakeVertex.hxx>
74 #pragma warning ( default: 4251 )
77 #define EXPORT_NAME "HYDRO_" + GetName()
79 #include <SALOME_NamingService.hxx>
80 #include <SALOME_LifeCycleCORBA.hxx>
83 #include "HYDRO_trace.hxx"
85 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
86 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
88 HYDROData_CalculationCase::HYDROData_CalculationCase()
93 HYDROData_CalculationCase::~HYDROData_CalculationCase()
97 void HYDROData_CalculationCase::SetName( const QString& theName )
99 QString anOldCaseName = GetName();
100 if ( anOldCaseName != theName )
102 // Update names of regions and its zones
103 UpdateRegionsNames( GetRegions( false ), anOldCaseName, theName );
104 // Update names of land cover regions and its zones
105 UpdateRegionsNames( GetRegions( true ), anOldCaseName, theName );
107 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
109 HYDROData_SequenceOfObjects::Iterator anIter;
110 anIter.Init( aGroups );
111 for ( ; anIter.More(); anIter.Next() )
113 Handle(HYDROData_SplittedShapesGroup) aGroup =
114 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
115 if ( aGroup.IsNull() )
118 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
122 HYDROData_Entity::SetName( theName );
125 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
127 QStringList aResList = dumpObjectCreation( theTreatedObjects );
128 aResList.prepend( "# Calculation case" );
130 QString aCalculName = GetObjPyName();
132 AssignmentMode aMode = GetAssignmentMode();
133 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
134 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
136 AssignmentMode aModeLC = GetAssignmentLandCoverMode();
137 QString aModeLCStr = aModeLC==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
138 aResList << QString( "%0.SetAssignmentLandCoverMode( %1 )" ).arg( aCalculName ).arg( aModeLCStr );
140 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
141 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
142 for ( ; anIter.More(); anIter.Next() )
144 Handle(HYDROData_Object) aRefGeomObj =
145 Handle(HYDROData_Object)::DownCast( anIter.Value() );
146 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
148 aResList << QString( "" );
150 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
152 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
153 anIter.Init( aGeomGroups );
154 for ( ; anIter.More(); anIter.Next() )
156 Handle(HYDROData_ShapesGroup) aGeomGroup =
157 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
158 if ( aGeomGroup.IsNull() )
161 Handle(HYDROData_Object) aFatherGeom =
162 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
163 if ( aFatherGeom.IsNull() )
166 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
167 aResList << QString( "%1 = %2.GetGroup( %3 );" )
168 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
170 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
173 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
174 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
176 if( aMode==AUTOMATIC )
177 DumpRulesToPython( aCalculName, aResList );
178 if( aModeLC==AUTOMATIC )
179 DumpLandCoverRulesToPython( aCalculName, aResList );
181 aResList << QString( "" );
182 aResList << "# Start the algorithm of the partition and assignment";
183 aResList << QString( "%1.Update();" ).arg( aCalculName );
187 // Now we restore the
188 // - regions and zones order
189 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) );
192 if( aModeLC==MANUAL )
194 // Now we restore the
195 // - land cover regions and zones order
196 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( true ) );
199 // Export calculation case
200 aResList << QString( "" );
201 aResList << "# Export of the calculation case";
202 QString aStudyName = "theStudy";
203 QString anEntryVar = aCalculName + "_entry";
204 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
206 // Get geometry object and print debug information
208 aResList << "# Get geometry shape and print debug information";
209 aResList << "import GEOM";
210 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
211 QString aGeomShapeName = aCalculName + "_geom";
212 aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
213 aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
214 aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
216 DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
218 aResList << QString( "" );
222 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
223 const QString& theStudyName,
224 const QString& theGeomShapeName,
225 const QString& theMeshName ) const
228 theResList << "# Meshing";
229 theResList << "import SMESH, SALOMEDS";
230 theResList << "from salome.smesh import smeshBuilder";
231 theResList << "from salome.geom import geomBuilder";
233 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
234 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
235 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
236 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
237 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
238 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
239 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
242 theResList << "# Set names of Mesh objects";
243 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
244 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
245 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
246 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
247 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
250 theResList << "# Greate SMESH groups";
251 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
252 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
253 theResList << QString( "for group in geom_groups:" );
254 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
256 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
257 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
260 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
262 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
264 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
265 if ( !aBoundaryPolyline.IsNull() )
266 aResSeq.Append( aBoundaryPolyline );
269 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions( false );
270 aResSeq.Append( aSeqOfRegions );
272 // Land cover regions
273 HYDROData_SequenceOfObjects aSeqOfLandCoverRegions = GetRegions( true );
274 aResSeq.Append( aSeqOfLandCoverRegions );
279 void HYDROData_CalculationCase::Update()
281 HYDROData_Entity::Update();
284 // At first we remove previously created objects
285 RemoveRegions( false );
286 RemoveRegions( true );
287 RemoveSplittedGroups();
289 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
290 if ( aDocument.IsNull() )
294 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
296 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
297 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
298 if ( !aGeomObjects.IsEmpty() ) {
299 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
301 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
302 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
303 if ( !aSplitObjects.isEmpty() ) {
304 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
305 while( anIter.hasNext() ) {
306 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
307 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
308 aZonesList.append( aSplitData );
309 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
310 anEdgesList.append( aSplitData );
315 // Split to land cover zones
316 HYDROData_SplitToZonesTool::SplitDataList aLandCoverZonesList;
318 HYDROData_SequenceOfObjects aLandCovers = GetLandCovers();
319 if ( !aLandCovers.IsEmpty() ) {
320 HYDROData_SplitToZonesTool::SplitDataList aSplitLandCoverObjects =
321 HYDROData_SplitToZonesTool::Split( aLandCovers );
322 if ( !aSplitLandCoverObjects.isEmpty() ) {
323 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitLandCoverObjects );
324 while( anIter.hasNext() ) {
325 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
326 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
327 aLandCoverZonesList.append( aSplitData );
332 switch( GetAssignmentMode() )
335 CreateRegionsDef( aDocument, aZonesList, false );
338 CreateRegionsAuto( aDocument, aZonesList, false );
342 switch( GetAssignmentLandCoverMode() )
345 CreateRegionsDef( aDocument, aLandCoverZonesList, true );
348 CreateRegionsAuto( aDocument, aLandCoverZonesList, true );
352 CreateEdgeGroupsDef( aDocument, anEdgesList );
355 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
356 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
357 const bool theLandCover )
359 // Create result regions for case, by default one zone for one region
360 QString aRegsPref = CALCULATION_REGIONS_PREF;
361 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
363 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
364 while( anIter.hasNext() )
366 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
368 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref, theLandCover );
370 // Add the zone for region
371 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
375 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
376 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
377 const bool theLandCover )
379 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
380 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
381 QMap<QString, QString> aRegionNameToObjNameMap;
382 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
383 HYDROData_PriorityQueue aPr( this, theLandCover ? DataTag_CustomLandCoverRules : DataTag_CustomRules );
385 // 1. First we create a default region for each object included into the calculation case
386 HYDROData_SequenceOfObjects anObjects = theLandCover ? GetLandCovers() : GetGeometryObjects();
387 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
389 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
392 QString anObjName = anObj->GetName();
393 QString aRegName = anObjName + "_reg";
394 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, theLandCover, false );
395 aRegionsMap.insert( anObjName, aRegion );
396 aRegionNameToObjNameMap.insert( aRegName, anObjName );
399 // 2. Now for each zone it is necessary to determine the most priority object
400 // and assign to zone to corresponding region
401 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
402 while( anIter.hasNext() )
404 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
405 HYDROData_Zone::MergeType aMergeType;
406 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
407 if( aRegObj.IsNull() )
409 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
410 if( aRegion.IsNull() )
412 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
414 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
416 qDebug( "Error in algorithm: unresolved conflicts" );
419 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
420 if ( !theLandCover ) {
421 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
422 if ( !aMergeObject.IsNull() ) {
423 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
424 aMergeEntity = aMergeObject->GetAltitudeObject();
430 case HYDROData_Zone::Merge_ZMIN:
431 case HYDROData_Zone::Merge_ZMAX:
432 aRegionZone->SetMergeType( aMergeType );
434 case HYDROData_Zone::Merge_Object:
435 aRegionZone->SetMergeType( aMergeType );
436 aRegionZone->RemoveMergeObject();
437 aRegionZone->SetMergeObject( aMergeEntity );
442 QStringList anObjectsWithEmptyRegions;
443 QMap<QString, Handle(HYDROData_Region)>::const_iterator
444 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
445 for( ; anIt!=aLast; anIt++ )
447 Handle(HYDROData_Region) aRegion = anIt.value();
448 if( aRegion->GetZones().IsEmpty() )
450 QString aRegName = aRegion->GetName();
451 QString anObjName = aRegionNameToObjNameMap[aRegName];
452 anObjectsWithEmptyRegions.append( anObjName );
456 if( !anObjectsWithEmptyRegions.empty() )
458 QString aData = anObjectsWithEmptyRegions.join( ", " );
459 SetWarning( WARN_EMPTY_REGIONS, aData );
463 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
464 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
466 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
468 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
469 while( anIter.hasNext() )
471 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
472 // Create new edges group
473 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
476 QString anObjName = aSplitData.ObjectNames.first();
477 if ( anObjName.isEmpty() )
479 #ifdef DEB_CALCULATION
480 QString aStr = aSplitData.ObjectNames.join(" ");
481 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
483 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
484 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
486 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
487 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
491 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
493 if ( aSplittedGroup.IsNull() )
496 aSplittedGroup->AddShape( aSplitData.Shape );
500 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
502 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
503 return false; // Wrong type of object
505 if ( HasReference( theObject, DataTag_GeometryObject ) )
506 return false; // Object is already in reference list
508 AddReferenceObject( theObject, DataTag_GeometryObject );
510 // Indicate model of the need to update splitting
516 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
518 return GetReferenceObjects( DataTag_GeometryObject );
521 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
523 if ( theObject.IsNull() )
526 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
528 // Indicate model of the need to update splitting
532 void HYDROData_CalculationCase::RemoveGeometryObjects()
534 ClearReferenceObjects( DataTag_GeometryObject );
536 // Indicate model of the need to update splitting
540 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
542 if ( theGroup.IsNull() )
545 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
546 return false; // Object is already in reference list
548 AddReferenceObject( theGroup, DataTag_GeometryGroup );
550 // Indicate model of the need to update splitting
556 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
558 return GetReferenceObjects( DataTag_GeometryGroup );
561 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
563 if ( theGroup.IsNull() )
566 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
568 // Indicate model of the need to update splitting
572 void HYDROData_CalculationCase::RemoveGeometryGroups()
574 ClearReferenceObjects( DataTag_GeometryGroup );
576 // Indicate model of the need to update splitting
580 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
582 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
584 SetReferenceObject( thePolyline, DataTag_Polyline );
586 // Indicate model of the need to update zones splitting
587 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
590 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
592 return Handle(HYDROData_PolylineXY)::DownCast(
593 GetReferenceObject( DataTag_Polyline ) );
596 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
598 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
600 ClearReferenceObjects( DataTag_Polyline );
602 // Indicate model of the need to update zones splitting
603 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
606 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
608 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
610 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
612 // Indicate model of the need to update land covers partition
613 SetToUpdate( !IsEqual( aPrevStricklerTable, theStricklerTable ) || IsMustBeUpdated() );
616 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
618 return Handle(HYDROData_StricklerTable)::DownCast(
619 GetReferenceObject( DataTag_StricklerTable ) );
622 void HYDROData_CalculationCase::RemoveStricklerTable()
624 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
626 ClearReferenceObjects( DataTag_StricklerTable );
628 // Indicate model of the need to update land covers partition
629 SetToUpdate( !aPrevStricklerTable.IsNull() || IsMustBeUpdated() );
632 bool HYDROData_CalculationCase::AddLandCover( const Handle(HYDROData_LandCover)& theLandCover )
634 if ( HasReference( theLandCover, DataTag_LandCover ) )
635 return false; // Land cover is already in reference list
637 AddReferenceObject( theLandCover, DataTag_LandCover );
639 // Indicate model of the need to update land covers partition
645 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetLandCovers() const
647 return GetReferenceObjects( DataTag_LandCover );
650 void HYDROData_CalculationCase::RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover )
652 if ( theLandCover.IsNull() )
655 RemoveReferenceObject( theLandCover->Label(), DataTag_LandCover );
657 // Indicate model of the need to update land cover partition
661 void HYDROData_CalculationCase::RemoveLandCovers()
663 ClearReferenceObjects( DataTag_LandCover );
665 // Indicate model of the need to update land cover partition
669 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone,
670 const bool theLandCover )
672 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
673 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
674 if ( aNewRegion.IsNull() )
677 aNewRegion->AddZone( theZone );
682 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion,
683 const bool theLandCover )
685 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
687 if ( theRegion.IsNull() )
690 HYDROData_CalculationCase::DataTag aDataTag =
691 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
693 if ( HasReference( theRegion, aDataTag ) )
694 return false; // Object is already in reference list
696 // Move the region from other calculation
697 Handle(HYDROData_CalculationCase) aFatherCalc =
698 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
699 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
701 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
702 theRegion->CopyTo( aNewRegion );
704 aFatherCalc->RemoveRegion( theRegion, theLandCover );
706 theRegion->SetLabel( aNewRegion->Label() );
710 AddReferenceObject( theRegion, aDataTag );
716 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions( const bool theLandCover ) const
718 return GetReferenceObjects( theLandCover ? DataTag_LandCoverRegion : DataTag_Region );
721 void HYDROData_CalculationCase::UpdateRegionsOrder()
723 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
724 if ( aDocument.IsNull() )
727 HYDROData_SequenceOfObjects aRegions = GetRegions( false );
728 HYDROData_SequenceOfObjects aRegionsLC = GetRegions( true );
729 aRegions.Append( aRegionsLC );
731 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
732 for ( ; anIter.More(); anIter.Next() )
734 Handle(HYDROData_Region) aRegion =
735 Handle(HYDROData_Region)::DownCast( anIter.Value() );
736 if ( aRegion.IsNull() )
739 aRegion->SetName( "" );
742 QString aRegsPref = CALCULATION_REGIONS_PREF;
744 anIter.Init( aRegions );
745 for ( ; anIter.More(); anIter.Next() )
747 Handle(HYDROData_Region) aRegion =
748 Handle(HYDROData_Region)::DownCast( anIter.Value() );
749 if ( aRegion.IsNull() )
752 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
753 aRegion->SetName( aRegionName );
757 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion,
758 const bool theLandCover )
760 if ( theRegion.IsNull() )
763 HYDROData_CalculationCase::DataTag aDataTag =
764 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
765 RemoveReferenceObject( theRegion->Label(), aDataTag );
767 // Remove region from data model
768 Handle(HYDROData_CalculationCase) aFatherCalc =
769 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
770 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
774 void HYDROData_CalculationCase::RemoveRegions( const bool theLandCover )
776 myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).ForgetAllAttributes();
779 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
781 return GetReferenceObjects( DataTag_SplittedGroups );
784 void HYDROData_CalculationCase::RemoveSplittedGroups()
786 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
789 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
791 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
792 return GetAltitudeForPoint( thePoint, aZone );
795 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
796 const Handle(HYDROData_Region)& theRegion ) const
798 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
800 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
801 if ( !aZone.IsNull() )
803 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
804 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
805 if ( IsEqual( aRefRegion, theRegion ) )
806 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
809 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
810 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
815 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
821 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
822 const Handle(HYDROData_Zone)& theZone ) const
824 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
825 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
826 if ( theZone.IsNull() )
828 DEBTRACE("Zone nulle");
832 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
833 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
834 if ( !theZone->IsMergingNeed() )
836 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
839 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
841 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
845 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
846 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
848 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
849 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
850 if ( !aMergeAltitude.IsNull() )
852 if ( aZoneInterpolator != NULL )
854 DEBTRACE("aZoneInterpolator != NULL");
855 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
856 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
860 DEBTRACE("aZoneInterpolator == NULL");
861 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
867 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
868 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
869 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
870 for ( ; anIter.More(); anIter.Next() )
872 Handle(HYDROData_Object) aZoneObj =
873 Handle(HYDROData_Object)::DownCast( anIter.Value() );
874 if ( aZoneObj.IsNull() )
877 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
878 if ( anObjAltitude.IsNull() )
881 double aPointAltitude = 0.0;
882 if ( aZoneInterpolator != NULL )
884 DEBTRACE("aZoneInterpolator != NULL");
885 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
886 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
890 //DEBTRACE("aZoneInterpolator == NULL");
891 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
894 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
897 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
899 aResAltitude = aPointAltitude;
902 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
904 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
905 aResAltitude > aPointAltitude )
907 aResAltitude = aPointAltitude;
910 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
912 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
913 aResAltitude < aPointAltitude )
915 aResAltitude = aPointAltitude;
924 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
925 const NCollection_Sequence<gp_XY>& thePoints,
926 const Handle(HYDROData_Region)& theRegion ) const
928 //DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
929 NCollection_Sequence<double> aResSeq;
931 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
933 const gp_XY& thePnt = thePoints.Value( i );
935 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
936 aResSeq.Append( anAltitude );
942 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
943 const NCollection_Sequence<gp_XY>& thePoints,
944 const Handle(HYDROData_Zone)& theZone ) const
946 NCollection_Sequence<double> aResSeq;
948 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
950 const gp_XY& thePnt = thePoints.Value( i );
952 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
953 aResSeq.Append( anAltitude );
959 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
962 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
963 if ( !aDocument.IsNull() )
964 aCoeff = aDocument->GetDefaultStricklerCoefficient();
966 Handle(HYDROData_LandCover) aLandCover;
967 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, Standard_True );
968 if ( !aZone.IsNull() )
970 HYDROData_SequenceOfObjects anObjList = aZone->GetObjects();
971 if ( anObjList.Length() == 1 )
972 aLandCover = Handle(HYDROData_LandCover)::DownCast( anObjList.First() );
974 aLandCover = Handle(HYDROData_LandCover)::DownCast( aZone->GetMergeObject() );
977 if ( !aLandCover.IsNull() )
979 QString aType = aLandCover->GetStricklerType();
980 Handle(HYDROData_StricklerTable) aTable = GetStricklerTable();
981 if ( !aTable.IsNull() )
983 if ( aTable->GetTypes().contains( aType ) )
984 aCoeff = aTable->Get( aType, aCoeff );
991 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint,
992 const bool theLandCover ) const
994 Handle(HYDROData_Region) aResRegion;
996 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, theLandCover );
997 if ( !aZone.IsNull() )
998 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
1003 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint,
1004 const bool theLandCover ) const
1006 Handle(HYDROData_Zone) aResZone;
1008 HYDROData_SequenceOfObjects aRegions = GetRegions( theLandCover );
1010 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
1011 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
1013 Handle(HYDROData_Region) aRegion =
1014 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1015 if ( aRegion.IsNull() )
1018 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1019 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
1020 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
1022 Handle(HYDROData_Zone) aRegZone =
1023 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
1024 if ( aRegZone.IsNull() )
1027 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
1028 if ( aPointRelation != POINT_OUT )
1029 aResZone = aRegZone; // We found the desired zone
1036 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
1037 const gp_XY& thePoint,
1038 const Handle(HYDROData_Zone)& theZone ) const
1040 PointClassification aRes = POINT_OUT;
1041 if ( theZone.IsNull() )
1044 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
1045 if ( aZoneFace.IsNull() )
1048 TopoDS_Compound aCmp;
1050 aBB.MakeCompound(aCmp);
1051 aBB.Add(aCmp, aZoneFace);
1052 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1053 BRepBuilderAPI_MakeVertex aMk(aPnt);
1054 aBB.Add(aCmp, aMk.Vertex());
1055 BRepTools::Write(aCmp, "FCL2d.brep");
1057 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1058 if (State == TopAbs_OUT)
1060 else if(State == TopAbs_IN)
1062 else if(State == TopAbs_ON)
1067 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1068 const QString& thePrefixOrName,
1069 const bool theLandCover,
1072 TDF_Label aNewLab = myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).NewChild();
1073 int aTag = aNewLab.Tag();
1075 Handle(HYDROData_Region) aNewRegion =
1076 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1077 AddRegion( aNewRegion, theLandCover );
1079 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1080 aNewRegion->SetName( aRegionName );
1085 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
1087 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
1089 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
1090 Handle(HYDROData_SplittedShapesGroup)::DownCast(
1091 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
1092 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
1094 aNewGroup->SetName( theName );
1099 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1101 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1102 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1104 QString aGeomObjEntry, anErrorMsg;
1105 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1106 return isOK ? aGeomObjEntry : QString();
1109 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1110 SALOMEDS::Study_ptr theStudy,
1111 QString& theGeomObjEntry,
1112 QString& theErrorMsg ) const
1114 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1116 // Get groups definitions
1117 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
1119 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
1120 for ( ; anIter.More(); anIter.Next() )
1123 Handle(HYDROData_ShapesGroup) aGroup =
1124 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1125 if ( aGroup.IsNull() )
1128 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1130 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1131 aGroup->GetShapes( aGroupDef.Shapes );
1133 aSeqOfGroupsDefs.Append( aGroupDef );
1137 bool isAllNotSubmersible = true;
1138 TopTools_ListOfShape aFaces;
1139 HYDROData_SequenceOfObjects aCaseRegions = GetRegions( false );
1140 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1141 for ( ; aRegionIter.More(); aRegionIter.Next() )
1143 Handle(HYDROData_Region) aRegion =
1144 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1145 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1148 if ( isAllNotSubmersible )
1149 isAllNotSubmersible = false;
1151 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1152 aFaces.Append( aRegionShape );
1157 if ( aCaseRegions.IsEmpty() ) {
1158 theErrorMsg = QString("the list of regions is empty.");
1159 } else if ( isAllNotSubmersible ) {
1160 theErrorMsg = QString("there are no submersible regions.");
1162 aRes = Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );;
1168 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1169 SALOMEDS::Study_ptr theStudy,
1170 const TopTools_ListOfShape& theFaces,
1171 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1172 QString& theGeomObjEntry ) const
1175 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1176 aSewing.SetNonManifoldMode( Standard_False );
1177 #ifdef DEB_CALCULATION
1178 TCollection_AsciiString aNam("Sh_");
1181 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1182 for ( ; aFaceIter.More(); aFaceIter.Next() )
1184 TopoDS_Shape aShape = aFaceIter.Value();
1185 if ( aShape.IsNull() )
1188 if ( aShape.ShapeType() == TopAbs_FACE )
1190 aSewing.Add( aShape );
1191 #ifdef DEB_CALCULATION
1192 TCollection_AsciiString aName = aNam + ++i + ".brep";
1193 BRepTools::Write(aShape ,aName.ToCString());
1198 #ifdef DEB_CALCULATION
1201 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1202 for (; anExp.More(); anExp.Next() ) {
1203 aSewing.Add( anExp.Current() );
1204 #ifdef DEB_CALCULATION
1206 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1207 BRepTools::Write(anExp.Current() ,aName.ToCString());
1214 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1216 // If the sewed shape is empty - return false
1217 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1220 #ifdef DEB_CALCULATION
1221 BRepTools::Write(aSewedShape ,"Sew.brep");
1223 // Publish the sewed shape
1224 QString aName = EXPORT_NAME;
1225 GEOM::GEOM_Object_ptr aMainShape =
1226 HYDROData_GeomTool::publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1228 if ( aMainShape->_is_nil() )
1231 if ( theGroupsDefs.IsEmpty() )
1235 TopTools_IndexedMapOfShape aMapOfSubShapes;
1236 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1238 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1240 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1242 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1244 NCollection_Sequence<int> aGroupIndexes;
1245 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1247 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1248 #ifdef DEB_CALCULATION
1249 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1252 TopoDS_Shape aModifiedShape = aShape;
1253 if ( aSewing.IsModified( aShape ) )
1254 aModifiedShape = aSewing.Modified( aShape );
1255 else if ( aSewing.IsModifiedSubShape( aShape ) )
1256 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1258 #ifdef DEB_CALCULATION
1259 const TopLoc_Location& aL1 = aShape.Location();
1260 const TopLoc_Location& aL2 = aModifiedShape.Location();
1261 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1264 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1265 if ( anIndex > 0 ) {
1266 aGroupIndexes.Append( anIndex );
1268 #ifdef DEB_CALCULATION
1269 TCollection_AsciiString aNam("Lost_");
1270 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1271 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1273 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1274 if ( aModifiedShape.IsPartner( aS ) )
1276 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1277 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1278 BRepTools::Write(aS ,aName.ToCString());
1286 if ( !aGroupIndexes.IsEmpty() )
1287 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1290 if ( !aGroupsData.IsEmpty() )
1292 GEOM::GEOM_IGroupOperations_var aGroupOp =
1293 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1295 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1296 for ( ; aMapIt.More(); aMapIt.Next() )
1298 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1299 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1301 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1302 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1305 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1306 aGeomIndexes->length( aGroupIndexes.Length() );
1308 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1309 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1311 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1312 if ( aGroupOp->IsDone() )
1314 SALOMEDS::SObject_var aGroupSO =
1315 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1323 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1324 const bool theIsSetToUpdate )
1326 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1327 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1329 // Indicate model of the need to update splitting
1330 if ( theIsSetToUpdate ) {
1331 SetToUpdate( true );
1335 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1336 HYDROData_PriorityType thePriority,
1337 const Handle(HYDROData_Entity)& theObject2,
1338 HYDROData_Zone::MergeType theMergeType,
1339 HYDROData_CalculationCase::DataTag theDataTag )
1341 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1342 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1344 // Indicate model of the need to update splitting
1345 SetToUpdate( true );
1348 QString HYDROData_CalculationCase::DumpRules() const
1350 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1351 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1354 QString HYDROData_CalculationCase::DumpLandCoverRules() const
1356 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1357 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1360 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1362 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1363 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1365 // Indicate model of the need to update splitting
1366 SetToUpdate( true );
1369 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1371 Handle(TDataStd_Integer) aModeAttr;
1372 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1374 return ( AssignmentMode ) aModeAttr->Get();
1379 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1380 QStringList& theScript ) const
1382 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1383 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1386 void HYDROData_CalculationCase::DumpLandCoverRulesToPython( const QString& theCalcCaseName,
1387 QStringList& theScript ) const
1389 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomLandCoverRules );
1390 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1393 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1395 return myLastWarning;
1398 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1400 myLastWarning.Type = theType;
1401 myLastWarning.Data = theData;
1404 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1405 const QString& theOldCaseName,
1406 const QString& theName )
1408 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1409 for ( ; anIter.More(); anIter.Next() )
1411 Handle(HYDROData_Region) aRegion =
1412 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1413 if ( aRegion.IsNull() )
1416 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1418 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1419 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1420 for ( ; anIter.More(); anIter.Next() )
1422 Handle(HYDROData_Zone) aRegZone =
1423 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1424 if ( aRegZone.IsNull() )
1427 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1432 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1433 MapOfTreatedObjects& theTreatedObjects,
1434 const HYDROData_SequenceOfObjects& theRegions ) const
1436 HYDROData_SequenceOfObjects::Iterator anIter;
1437 anIter.Init( theRegions );
1438 for ( ; anIter.More(); anIter.Next() )
1440 Handle(HYDROData_Region) aRegion =
1441 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1442 if ( aRegion.IsNull() )
1445 theTreatedObjects.insert( aRegion->GetName(), aRegion );
1446 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
1447 theResList << aRegDump;
1451 bool HYDROData_CalculationCase::GetRule( int theIndex,
1452 Handle(HYDROData_Entity)& theObject1,
1453 HYDROData_PriorityType& thePriority,
1454 Handle(HYDROData_Entity)& theObject2,
1455 HYDROData_Zone::MergeType& theMergeType,
1456 HYDROData_CalculationCase::DataTag& theDataTag) const
1458 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1459 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1460 theObject1, thePriority, theObject2, theMergeType );
1463 void HYDROData_CalculationCase::SetAssignmentLandCoverMode( AssignmentMode theMode )
1465 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentLandCoverMode );
1466 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1468 // Indicate model of the need to update land covers partition
1469 SetToUpdate( true );
1472 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentLandCoverMode() const
1474 Handle(TDataStd_Integer) aModeAttr;
1475 bool isOK = myLab.FindChild( DataTag_AssignmentLandCoverMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1477 return ( AssignmentMode ) aModeAttr->Get();