1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_CalculationCase.h"
20 #include "HYDROData_ArtificialObject.h"
21 #include "HYDROData_IAltitudeObject.h"
22 #include "HYDROData_Document.h"
23 #include "HYDROData_ShapesGroup.h"
24 #include "HYDROData_Iterator.h"
25 #include "HYDROData_NaturalObject.h"
26 #include "HYDROData_PolylineXY.h"
27 #include "HYDROData_StricklerTable.h"
28 #include "HYDROData_LandCoverMap.h"
29 #include "HYDROData_SplitShapesGroup.h"
30 #include "HYDROData_Region.h"
31 #include "HYDROData_Tool.h"
32 #include "HYDROData_GeomTool.h"
35 #pragma warning ( disable: 4251 )
43 #pragma warning ( default: 4251 )
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Edge.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRepBuilderAPI_Sewing.hxx>
54 #include <BRepTopAdaptor_FClass2d.hxx>
56 #include <BRepTools.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <TopTools_ListOfShape.hxx>
62 #include <TopTools_ListIteratorOfListOfShape.hxx>
63 #include <TDataStd_Integer.hxx>
65 //#define DEB_CALCULATION 1
66 #ifdef DEB_CALCULATION
67 #include <BRepTools.hxx>
68 #include <TopLoc_Location.hxx>
70 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
71 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
72 #define CALCULATION_GROUPS_PREF GetName() + "_"
73 //#define DEB_CLASS2D 1
75 #include <BRepBuilderAPI_MakeVertex.hxx>
78 #define EXPORT_NAME "HYDRO_" + GetName()
81 #include <SALOME_NamingService.hxx>
82 #include <SALOME_LifeCycleCORBA.hxx>
86 #include "HYDRO_trace.hxx"
88 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
89 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
91 HYDROData_CalculationCase::HYDROData_CalculationCase()
92 : HYDROData_Entity( Geom_2d_and_groups )
96 HYDROData_CalculationCase::~HYDROData_CalculationCase()
100 void HYDROData_CalculationCase::SetName( const QString& theName )
102 QString anOldCaseName = GetName();
103 if ( anOldCaseName != theName )
105 // Update names of regions and its zones
106 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
108 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
110 HYDROData_SequenceOfObjects::Iterator anIter;
111 anIter.Init( aGroups );
112 for ( ; anIter.More(); anIter.Next() )
114 Handle(HYDROData_SplitShapesGroup) aGroup =
115 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
116 if ( aGroup.IsNull() )
119 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
123 HYDROData_Entity::SetName( theName );
126 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
127 MapOfTreatedObjects& theTreatedObjects ) const
129 QStringList aResList = dumpObjectCreation( theTreatedObjects );
130 aResList.prepend( "# Calculation case" );
132 QString aCalculName = GetObjPyName();
134 AssignmentMode aMode = GetAssignmentMode();
135 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
136 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
138 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
139 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
140 for ( ; anIter.More(); anIter.Next() )
142 Handle(HYDROData_Object) aRefGeomObj =
143 Handle(HYDROData_Object)::DownCast( anIter.Value() );
144 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
146 aResList << QString( "" );
148 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
150 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
151 anIter.Init( aGeomGroups );
152 for ( ; anIter.More(); anIter.Next() )
154 Handle(HYDROData_ShapesGroup) aGeomGroup =
155 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
156 if ( aGeomGroup.IsNull() )
159 Handle(HYDROData_Object) aFatherGeom =
160 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
161 if ( aFatherGeom.IsNull() )
164 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
165 aResList << QString( "%1 = %2.GetGroup( %3 )" )
166 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
168 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
171 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
172 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
174 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
175 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
177 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
178 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
180 if( aMode==AUTOMATIC )
181 DumpRulesToPython( aCalculName, aResList );
183 aResList << QString( "" );
184 aResList << "# Start the algorithm of the partition and assignment";
185 aResList << QString( "%1.Update()" ).arg( aCalculName );
189 // Now we restore the
190 // - regions and zones order
191 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
194 // Export calculation case
195 aResList << QString( "" );
196 aResList << "# Export of the calculation case";
197 QString aStudyName = "theStudy";
198 QString anEntryVar = aCalculName + "_entry";
199 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
201 // Get geometry object and print debug information
203 aResList << "# Get geometry shape and print debug information";
204 aResList << "import GEOM";
205 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
206 QString aGeomShapeName = aCalculName + "_geom";
207 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
208 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
209 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
212 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
214 aResList << QString( "" );
218 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
219 const QString& theStudyName,
220 const QString& theGeomShapeName,
221 const QString& theMeshName ) const
224 theResList << "# Meshing";
225 theResList << "import SMESH, SALOMEDS";
226 theResList << "from salome.smesh import smeshBuilder";
227 theResList << "from salome.geom import geomBuilder";
229 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
230 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
231 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
232 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
233 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
234 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
235 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
238 theResList << "# Set names of Mesh objects";
239 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
240 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
241 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
242 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
243 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
246 theResList << "# Greate SMESH groups";
247 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
248 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
249 theResList << QString( "for group in geom_groups:" );
250 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
252 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
253 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
256 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
258 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
260 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
261 if ( !aBoundaryPolyline.IsNull() )
262 aResSeq.Append( aBoundaryPolyline );
264 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
265 aResSeq.Append( aSeqOfGeomObjs );
268 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
269 aResSeq.Append( aSeqOfRegions );
274 void HYDROData_CalculationCase::Update()
276 HYDROData_Entity::Update();
279 // At first we remove previously created objects
283 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
284 if ( aDocument.IsNull() )
288 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
290 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
292 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
294 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
295 if ( !aGeomObjects.IsEmpty() ) {
296 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
298 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
299 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
300 if ( !aSplitObjects.isEmpty() ) {
301 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
302 while( anIter.hasNext() ) {
303 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
304 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
305 aZonesList.append( aSplitData );
306 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
307 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
308 anEdgesList.append( aSplitData );
313 switch( GetAssignmentMode() )
316 CreateRegionsDef( aDocument, aZonesList );
319 CreateRegionsAuto( aDocument, aZonesList );
323 CreateEdgeGroupsDef( aDocument, anEdgesList );
326 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
327 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
329 // Create result regions for case, by default one zone for one region
330 QString aRegsPref = CALCULATION_REGIONS_PREF;
331 QString aZonesPref = CALCULATION_ZONES_PREF;
333 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
334 while( anIter.hasNext() )
336 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
338 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
340 // Add the zone for region
341 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
345 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
346 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
348 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
349 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
350 QMap<QString, QString> aRegionNameToObjNameMap;
351 QString aZonesPref = CALCULATION_ZONES_PREF;
352 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
354 // 1. First we create a default region for each object included into the calculation case
355 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
356 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
358 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
361 QString anObjName = anObj->GetName();
362 QString aRegName = anObjName + "_reg";
363 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
364 aRegionsMap.insert( anObjName, aRegion );
365 aRegionNameToObjNameMap.insert( aRegName, anObjName );
368 // 2. Now for each zone it is necessary to determine the most priority object
369 // and assign to zone to corresponding region
370 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
371 while( anIter.hasNext() )
373 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
374 HYDROData_Zone::MergeType aMergeType;
375 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
376 if( aRegObj.IsNull() )
378 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
379 if( aRegion.IsNull() )
381 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
383 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
385 qDebug( "Error in algorithm: unresolved conflicts" );
388 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
389 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
390 if ( !aMergeObject.IsNull() ) {
391 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
392 aMergeEntity = aMergeObject->GetAltitudeObject();
397 case HYDROData_Zone::Merge_ZMIN:
398 case HYDROData_Zone::Merge_ZMAX:
399 aRegionZone->SetMergeType( aMergeType );
401 case HYDROData_Zone::Merge_Object:
402 aRegionZone->SetMergeType( aMergeType );
403 aRegionZone->RemoveMergeObject();
404 aRegionZone->SetMergeObject( aMergeEntity );
409 QStringList anObjectsWithEmptyRegions;
410 QMap<QString, Handle(HYDROData_Region)>::const_iterator
411 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
412 for( ; anIt!=aLast; anIt++ )
414 Handle(HYDROData_Region) aRegion = anIt.value();
415 if( aRegion->GetZones().IsEmpty() )
417 QString aRegName = aRegion->GetName();
418 QString anObjName = aRegionNameToObjNameMap[aRegName];
419 anObjectsWithEmptyRegions.append( anObjName );
423 if( !anObjectsWithEmptyRegions.empty() )
425 QString aData = anObjectsWithEmptyRegions.join( ", " );
426 SetWarning( WARN_EMPTY_REGIONS, aData );
430 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
431 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
433 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
435 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
436 while( anIter.hasNext() )
438 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
439 // Create new edges group
440 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
443 QString anObjName = aSplitData.ObjectNames.first();
444 if ( anObjName.isEmpty() )
446 #ifdef DEB_CALCULATION
447 QString aStr = aSplitData.ObjectNames.join(" ");
448 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
450 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
451 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
453 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
454 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
458 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
460 if ( aSplitGroup.IsNull() )
463 aSplitGroup->AddShape( aSplitData.Shape );
465 TopTools_SequenceOfShape theShapes;
466 aSplitGroup->GetShapes(theShapes);
468 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
469 aSplitGroup->SetInternal(true);
473 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
475 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
476 return false; // Wrong type of object
478 if ( HasReference( theObject, DataTag_GeometryObject ) )
479 return false; // Object is already in reference list
481 AddReferenceObject( theObject, DataTag_GeometryObject );
483 // Indicate model of the need to update splitting
489 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
491 return GetReferenceObjects( DataTag_GeometryObject );
494 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
496 if ( theObject.IsNull() )
499 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
501 // Indicate model of the need to update splitting
505 void HYDROData_CalculationCase::RemoveGeometryObjects()
507 ClearReferenceObjects( DataTag_GeometryObject );
509 // Indicate model of the need to update splitting
513 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
515 if ( theGroup.IsNull() )
518 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
519 return false; // Object is already in reference list
521 AddReferenceObject( theGroup, DataTag_GeometryGroup );
523 // Indicate model of the need to update splitting
524 Changed( Geom_Groups );
529 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
531 return GetReferenceObjects( DataTag_GeometryGroup );
534 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
536 if ( theGroup.IsNull() )
539 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
541 // Indicate model of the need to update splitting
542 Changed( Geom_Groups );
545 void HYDROData_CalculationCase::RemoveGeometryGroups()
547 ClearReferenceObjects( DataTag_GeometryGroup );
549 // Indicate model of the need to update splitting
550 Changed( Geom_Groups );
553 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
555 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
557 SetReferenceObject( thePolyline, DataTag_Polyline );
559 // Indicate model of the need to update zones splitting
560 if( !IsEqual( aPrevPolyline, thePolyline ) )
564 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
566 return Handle(HYDROData_PolylineXY)::DownCast(
567 GetReferenceObject( DataTag_Polyline ) );
570 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
572 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
574 ClearReferenceObjects( DataTag_Polyline );
576 // Indicate model of the need to update zones splitting
580 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
582 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
584 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
586 // Indicate model of the need to update land covers partition
587 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
591 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
593 return Handle(HYDROData_StricklerTable)::DownCast(
594 GetReferenceObject( DataTag_StricklerTable ) );
597 void HYDROData_CalculationCase::RemoveStricklerTable()
599 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
601 ClearReferenceObjects( DataTag_StricklerTable );
603 // Indicate model of the need to update land covers partition
607 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
609 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
610 GetReferenceObject( DataTag_LandCoverMap ) );
614 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
616 SetReferenceObject( theMap, DataTag_LandCoverMap );
619 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
624 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
625 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
626 if ( aNewRegion.IsNull() )
629 aNewRegion->AddZone( theZone );
634 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
636 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
638 if ( theRegion.IsNull() )
641 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
643 if ( HasReference( theRegion, aDataTag ) )
644 return false; // Object is already in reference list
646 // Move the region from other calculation
647 Handle(HYDROData_CalculationCase) aFatherCalc =
648 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
649 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
651 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
652 theRegion->CopyTo( aNewRegion, true );
654 aFatherCalc->RemoveRegion( theRegion );
656 theRegion->SetLabel( aNewRegion->Label() );
660 AddReferenceObject( theRegion, aDataTag );
666 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
668 return GetReferenceObjects( DataTag_Region );
671 void HYDROData_CalculationCase::UpdateRegionsOrder()
673 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
674 if ( aDocument.IsNull() )
677 HYDROData_SequenceOfObjects aRegions = GetRegions();
678 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
679 for ( ; anIter.More(); anIter.Next() )
681 Handle(HYDROData_Region) aRegion =
682 Handle(HYDROData_Region)::DownCast( anIter.Value() );
683 if ( aRegion.IsNull() )
686 aRegion->SetName( "" );
689 QString aRegsPref = CALCULATION_REGIONS_PREF;
691 anIter.Init( aRegions );
692 for ( ; anIter.More(); anIter.Next() )
694 Handle(HYDROData_Region) aRegion =
695 Handle(HYDROData_Region)::DownCast( anIter.Value() );
696 if ( aRegion.IsNull() )
699 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
700 aRegion->SetName( aRegionName );
704 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
706 if ( theRegion.IsNull() )
709 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
710 RemoveReferenceObject( theRegion->Label(), aDataTag );
712 // Remove region from data model
713 Handle(HYDROData_CalculationCase) aFatherCalc =
714 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
715 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
719 void HYDROData_CalculationCase::RemoveRegions()
721 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
724 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
726 return GetReferenceObjects( DataTag_SplitGroups );
729 void HYDROData_CalculationCase::RemoveSplitGroups()
731 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
734 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
736 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
737 return GetAltitudeForPoint( thePoint, aZone );
740 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
741 const Handle(HYDROData_Region)& theRegion,
744 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
746 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
747 if ( !aZone.IsNull() )
749 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
750 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
751 if ( IsEqual( aRefRegion, theRegion ) )
752 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
755 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
756 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
761 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
767 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
768 const Handle(HYDROData_Zone)& theZone,
771 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
772 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
773 if ( theZone.IsNull() )
775 DEBTRACE("Zone nulle");
779 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
780 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
781 if ( !theZone->IsMergingNeed() )
783 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
786 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
788 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
792 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
793 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
795 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
796 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
797 if ( !aMergeAltitude.IsNull() )
799 if ( aZoneInterpolator != NULL )
801 DEBTRACE("aZoneInterpolator != NULL");
802 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
803 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
807 DEBTRACE("aZoneInterpolator == NULL");
808 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
814 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
815 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
816 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
817 for ( ; anIter.More(); anIter.Next() )
819 Handle(HYDROData_Object) aZoneObj =
820 Handle(HYDROData_Object)::DownCast( anIter.Value() );
821 if ( aZoneObj.IsNull() )
824 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
825 if ( anObjAltitude.IsNull() )
828 double aPointAltitude = 0.0;
829 if ( aZoneInterpolator != NULL )
831 DEBTRACE("aZoneInterpolator != NULL");
832 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
833 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
837 //DEBTRACE("aZoneInterpolator == NULL");
838 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
841 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
844 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
846 aResAltitude = aPointAltitude;
849 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
851 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
852 aResAltitude > aPointAltitude )
854 aResAltitude = aPointAltitude;
857 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
859 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
860 aResAltitude < aPointAltitude )
862 aResAltitude = aPointAltitude;
871 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
872 const NCollection_Sequence<gp_XY>& thePoints,
873 const Handle(HYDROData_Region)& theRegion,
876 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
877 NCollection_Sequence<double> aResSeq;
879 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
881 const gp_XY& thePnt = thePoints.Value( i );
883 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
884 aResSeq.Append( anAltitude );
890 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
891 const NCollection_Sequence<gp_XY>& thePoints,
892 const Handle(HYDROData_Zone)& theZone,
895 NCollection_Sequence<double> aResSeq;
897 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
899 const gp_XY& thePnt = thePoints.Value( i );
901 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
902 aResSeq.Append( anAltitude );
908 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
910 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
911 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
916 aMap->FindByPoint( thePoint, aType );
917 double aCoeff = aTable->Get( aType, 0.0 );
921 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
922 double DefValue, bool UseMax ) const
924 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
925 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
926 std::vector<double> theCoeffs;
927 if( aLCM.IsNull() || aTable.IsNull() )
930 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
935 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
937 Handle(HYDROData_Region) aResRegion;
939 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
940 if ( !aZone.IsNull() )
941 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
946 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
948 Handle(HYDROData_Zone) aResZone;
950 HYDROData_SequenceOfObjects aRegions = GetRegions();
952 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
953 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
955 Handle(HYDROData_Region) aRegion =
956 Handle(HYDROData_Region)::DownCast( anIter.Value() );
957 if ( aRegion.IsNull() )
960 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
961 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
962 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
964 Handle(HYDROData_Zone) aRegZone =
965 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
966 if ( aRegZone.IsNull() )
969 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
970 if ( aPointRelation != POINT_OUT )
971 aResZone = aRegZone; // We found the desired zone
978 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
979 const gp_XY& thePoint,
980 const Handle(HYDROData_Zone)& theZone ) const
982 PointClassification aRes = POINT_OUT;
983 if ( theZone.IsNull() )
986 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
987 if ( aZoneFace.IsNull() )
990 TopoDS_Compound aCmp;
992 aBB.MakeCompound(aCmp);
993 aBB.Add(aCmp, aZoneFace);
994 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
995 BRepBuilderAPI_MakeVertex aMk(aPnt);
996 aBB.Add(aCmp, aMk.Vertex());
997 BRepTools::Write(aCmp, "FCL2d.brep");
999 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1000 if (State == TopAbs_OUT)
1002 else if(State == TopAbs_IN)
1004 else if(State == TopAbs_ON)
1009 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1010 const QString& thePrefixOrName,
1013 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1014 int aTag = aNewLab.Tag();
1016 Handle(HYDROData_Region) aNewRegion =
1017 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1018 AddRegion( aNewRegion );
1020 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1021 aNewRegion->SetName( aRegionName, true );
1026 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1028 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1030 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1031 Handle(HYDROData_SplitShapesGroup)::DownCast(
1032 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1033 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1035 aNewGroup->SetName( theName );
1040 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1045 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1046 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1048 QString aGeomObjEntry, anErrorMsg;
1049 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg );
1050 return isOK ? aGeomObjEntry : QString();
1055 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1056 SALOMEDS::Study_ptr theStudy,
1057 QString& theGeomObjEntry,
1058 QString& theErrorMsg ) const
1060 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1062 // Get groups definitions
1063 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1065 TopTools_SequenceOfShape IntSh; //internal edges
1066 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1067 for ( ; anIter.More(); anIter.Next() )
1070 Handle(HYDROData_ShapesGroup) aGroup =
1071 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1072 if ( aGroup.IsNull() )
1075 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1077 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1078 aGroup->GetShapes( aGroupDef.Shapes );
1080 aSeqOfGroupsDefs.Append( aGroupDef );
1082 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1083 TopTools_SequenceOfShape dummy;
1084 if (!aSSGroup.IsNull())
1085 if (aSSGroup->GetInternal())
1087 aSSGroup->GetShapes(dummy);
1088 IntSh.Append(dummy);
1094 bool isAllNotSubmersible = true;
1095 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1096 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1097 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1098 for ( ; aRegionIter.More(); aRegionIter.Next() )
1100 Handle(HYDROData_Region) aRegion =
1101 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1102 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1105 if ( isAllNotSubmersible )
1106 isAllNotSubmersible = false;
1108 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1109 aShToNames.Add( aRegionShape, aRegion->GetName() );
1114 if ( aCaseRegions.IsEmpty() ) {
1115 theErrorMsg = QString("the list of regions is empty.");
1116 } else if ( isAllNotSubmersible ) {
1117 theErrorMsg = QString("there are no submersible regions.");
1119 aRes = Export( theGeomEngine, theStudy, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1122 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1124 QString aTelemacFileName = GetName() + ".telemac";
1125 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable() );
1126 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1131 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1132 SALOMEDS::Study_ptr theStudy,
1133 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1134 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1135 QString& theGeomObjEntry ) const
1138 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1139 aSewing.SetNonManifoldMode( Standard_False );
1140 #ifdef DEB_CALCULATION
1141 TCollection_AsciiString aNam("Sh_");
1144 TopTools_DataMapOfShapeListOfShape SH2M;
1145 for ( int i = 1; i <= aShToName.Extent(); i++ )
1147 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1148 if ( aShape.IsNull() )
1151 SH2M.Bind(aShape, TopTools_ListOfShape());
1152 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1153 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1155 aSewing.Add( aShape );
1158 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1160 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1161 for (; anExp.More(); anExp.Next() )
1163 aSewing.Add( anExp.Current() );
1164 LM.Append(anExp.Current());
1166 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1168 aSewing.Add( anExp.Current() );
1169 LM.Append(anExp.Current());
1175 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1177 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1179 for ( int i = 1; i <= aShToName.Extent(); i++ )
1181 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1182 const QString& Qstr = aShToName.FindFromIndex(i);
1183 const TopTools_ListOfShape& LM = SH2M(CurShape);
1184 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1186 const TopoDS_Shape& csh = it.Value();
1187 if (aSewing.IsModified(csh))
1188 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1190 aFacesToNameModif.Add(csh, Qstr);
1195 // If the sewed shape is empty - return false
1196 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1199 #ifdef DEB_CALCULATION
1200 BRepTools::Write(aSewedShape ,"Sew.brep");
1202 // Publish the sewed shape
1203 QString aName = EXPORT_NAME;
1204 GEOM::GEOM_Object_ptr aMainShape =
1205 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1207 if ( aMainShape->_is_nil() )
1210 if ( theGroupsDefs.IsEmpty() )
1214 TopTools_IndexedMapOfShape aMapOfSubShapes;
1215 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1217 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1219 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1221 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1223 NCollection_Sequence<int> aGroupIndexes;
1224 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1226 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1227 #ifdef DEB_CALCULATION
1228 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1231 TopoDS_Shape aModifiedShape = aShape;
1232 if ( aSewing.IsModified( aShape ) )
1233 aModifiedShape = aSewing.Modified( aShape );
1234 else if ( aSewing.IsModifiedSubShape( aShape ) )
1235 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1237 #ifdef DEB_CALCULATION
1238 const TopLoc_Location& aL1 = aShape.Location();
1239 const TopLoc_Location& aL2 = aModifiedShape.Location();
1240 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1243 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1244 if ( anIndex > 0 ) {
1245 aGroupIndexes.Append( anIndex );
1247 #ifdef DEB_CALCULATION
1248 TCollection_AsciiString aNam("Lost_");
1249 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1250 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1252 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1253 if ( aModifiedShape.IsPartner( aS ) )
1255 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1256 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1257 BRepTools::Write(aS ,aName.ToCString());
1265 if ( !aGroupIndexes.IsEmpty() )
1266 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1269 if ( !aGroupsData.IsEmpty() )
1271 GEOM::GEOM_IGroupOperations_var aGroupOp =
1272 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1274 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1275 for ( ; aMapIt.More(); aMapIt.Next() )
1277 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1278 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1280 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1281 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1284 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1285 aGeomIndexes->length( aGroupIndexes.Length() );
1287 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1288 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1290 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1291 if ( aGroupOp->IsDone() )
1293 SALOMEDS::SObject_var aGroupSO =
1294 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1303 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1304 const bool theIsSetToUpdate )
1306 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1307 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1309 // Indicate model of the need to update splitting
1310 if ( theIsSetToUpdate ) {
1315 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1316 HYDROData_PriorityType thePriority,
1317 const Handle(HYDROData_Entity)& theObject2,
1318 HYDROData_Zone::MergeType theMergeType,
1319 HYDROData_CalculationCase::DataTag theDataTag )
1321 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1322 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1324 // Indicate model of the need to update splitting
1328 QString HYDROData_CalculationCase::DumpRules() const
1330 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1331 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1334 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1336 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1337 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1339 // Indicate model of the need to update splitting
1343 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1345 Handle(TDataStd_Integer) aModeAttr;
1346 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1348 return ( AssignmentMode ) aModeAttr->Get();
1353 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1354 QStringList& theScript ) const
1356 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1357 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1360 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1362 return myLastWarning;
1365 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1367 myLastWarning.Type = theType;
1368 myLastWarning.Data = theData;
1371 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1372 const QString& theOldCaseName,
1373 const QString& theName )
1375 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1376 for ( ; anIter.More(); anIter.Next() )
1378 Handle(HYDROData_Region) aRegion =
1379 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1380 if ( aRegion.IsNull() )
1383 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1385 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1386 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1387 for ( ; anIter.More(); anIter.Next() )
1389 Handle(HYDROData_Zone) aRegZone =
1390 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1391 if ( aRegZone.IsNull() )
1394 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1399 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1400 const QString& thePyScriptPath,
1401 MapOfTreatedObjects& theTreatedObjects,
1402 const HYDROData_SequenceOfObjects& theRegions ) const
1404 HYDROData_SequenceOfObjects::Iterator anIter;
1405 anIter.Init(theRegions);
1406 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1408 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1409 if (aRegion.IsNull())
1411 QString defRegName = this->GetName();
1412 QString regSuffix = QString("_Reg_%1").arg(ireg);
1413 defRegName += regSuffix;
1414 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1415 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1416 theResList << aRegDump;
1418 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1420 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1421 if (aRegion.IsNull())
1423 QStringList aRegDump;
1424 aRegion->SetNameInDumpPython(aRegDump);
1425 theResList << aRegDump;
1429 bool HYDROData_CalculationCase::GetRule( int theIndex,
1430 Handle(HYDROData_Entity)& theObject1,
1431 HYDROData_PriorityType& thePriority,
1432 Handle(HYDROData_Entity)& theObject2,
1433 HYDROData_Zone::MergeType& theMergeType,
1434 HYDROData_CalculationCase::DataTag& theDataTag) const
1436 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1437 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1438 theObject1, thePriority, theObject2, theMergeType );
1441 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1443 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1445 if ( HasReference( theInterPolyline, aDataTag ) )
1448 AddReferenceObject( theInterPolyline, aDataTag );
1455 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1457 return GetReferenceObjects( DataTag_InterPoly );
1460 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1462 if ( theInterPolyline.IsNull() )
1465 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );