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_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
90 HYDROData_CalculationCase::HYDROData_CalculationCase()
91 : HYDROData_Entity( Geom_2d_and_groups )
95 HYDROData_CalculationCase::~HYDROData_CalculationCase()
99 void HYDROData_CalculationCase::SetName( const QString& theName )
101 QString anOldCaseName = GetName();
102 if ( anOldCaseName != theName )
104 // Update names of regions and its zones
105 UpdateRegionsNames( GetRegions(), anOldCaseName, theName );
107 HYDROData_SequenceOfObjects aGroups = GetSplitGroups();
109 HYDROData_SequenceOfObjects::Iterator anIter;
110 anIter.Init( aGroups );
111 for ( ; anIter.More(); anIter.Next() )
113 Handle(HYDROData_SplitShapesGroup) aGroup =
114 Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
115 if ( aGroup.IsNull() )
118 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
122 HYDROData_Entity::SetName( theName );
125 QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath,
126 MapOfTreatedObjects& theTreatedObjects ) const
128 QStringList aResList = dumpObjectCreation( theTreatedObjects );
129 aResList.prepend( "# Calculation case" );
131 QString aCalculName = GetObjPyName();
133 AssignmentMode aMode = GetAssignmentMode();
134 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
135 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
137 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
138 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
139 for ( ; anIter.More(); anIter.Next() )
141 Handle(HYDROData_Object) aRefGeomObj =
142 Handle(HYDROData_Object)::DownCast( anIter.Value() );
143 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
145 aResList << QString( "" );
147 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
149 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
150 anIter.Init( aGeomGroups );
151 for ( ; anIter.More(); anIter.Next() )
153 Handle(HYDROData_ShapesGroup) aGeomGroup =
154 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
155 if ( aGeomGroup.IsNull() )
158 Handle(HYDROData_Object) aFatherGeom =
159 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
160 if ( aFatherGeom.IsNull() )
163 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
164 aResList << QString( "%1 = %2.GetGroup( %3 )" )
165 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
167 aResList << QString( "%1.AddGeometryGroup( %2 )" ).arg( aCalculName ).arg( aGroupName );
170 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
171 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
173 Handle(HYDROData_StricklerTable) aStricklerTable = GetStricklerTable();
174 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aStricklerTable, "SetStricklerTable" );
176 Handle(HYDROData_LandCoverMap) aLandCoverMap = GetLandCoverMap();
177 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aLandCoverMap, "SetLandCoverMap" );
179 if( aMode==AUTOMATIC )
180 DumpRulesToPython( aCalculName, aResList );
182 aResList << QString( "" );
183 aResList << "# Start the algorithm of the partition and assignment";
184 aResList << QString( "%1.Update()" ).arg( aCalculName );
188 // Now we restore the
189 // - regions and zones order
190 DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() );
193 // Export calculation case
194 aResList << QString( "" );
195 aResList << "# Export of the calculation case";
196 QString aStudyName = "theStudy";
197 QString anEntryVar = aCalculName + "_entry";
198 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
200 // Get geometry object and print debug information
202 aResList << "# Get geometry shape and print debug information";
203 aResList << "import GEOM";
204 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
205 QString aGeomShapeName = aCalculName + "_geom";
206 aResList << QString( "HYDRO_%1 = salome.IDToObject( str( %2 ) )" ).arg( GetName() ).arg( anEntryVar );
207 aResList << QString( "print \"Geom shape:\", HYDRO_%1" ).arg( GetName() );
208 aResList << QString( "print \"Geom shape name:\", HYDRO_%1.GetName()" ).arg( GetName() );
211 //DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
213 aResList << QString( "" );
217 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
218 const QString& theStudyName,
219 const QString& theGeomShapeName,
220 const QString& theMeshName ) const
223 theResList << "# Meshing";
224 theResList << "import SMESH, SALOMEDS";
225 theResList << "from salome.smesh import smeshBuilder";
226 theResList << "from salome.geom import geomBuilder";
228 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
229 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
230 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
231 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
232 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
233 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
234 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
237 theResList << "# Set names of Mesh objects";
238 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
239 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
240 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
241 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
242 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
245 theResList << "# Greate SMESH groups";
246 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
247 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
248 theResList << QString( "for group in geom_groups:" );
249 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
251 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
252 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
255 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
257 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
259 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
260 if ( !aBoundaryPolyline.IsNull() )
261 aResSeq.Append( aBoundaryPolyline );
263 HYDROData_SequenceOfObjects aSeqOfGeomObjs = GetGeometryObjects();
264 aResSeq.Append( aSeqOfGeomObjs );
267 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
268 aResSeq.Append( aSeqOfRegions );
273 void HYDROData_CalculationCase::Update()
275 HYDROData_Entity::Update();
278 // At first we remove previously created objects
282 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
283 if ( aDocument.IsNull() )
287 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
289 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
291 HYDROData_SequenceOfObjects InterPolys = GetInterPolyObjects();
293 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
294 if ( !aGeomObjects.IsEmpty() ) {
295 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
297 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
298 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline, InterPolys );
299 if ( !aSplitObjects.isEmpty() ) {
300 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
301 while( anIter.hasNext() ) {
302 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
303 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
304 aZonesList.append( aSplitData );
305 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge ||
306 aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
307 anEdgesList.append( aSplitData );
312 switch( GetAssignmentMode() )
315 CreateRegionsDef( aDocument, aZonesList );
318 CreateRegionsAuto( aDocument, aZonesList );
322 CreateEdgeGroupsDef( aDocument, anEdgesList );
325 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
326 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
328 // Create result regions for case, by default one zone for one region
329 QString aRegsPref = CALCULATION_REGIONS_PREF;
330 QString aZonesPref = CALCULATION_ZONES_PREF;
332 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
333 while( anIter.hasNext() )
335 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
337 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
339 // Add the zone for region
340 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
344 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
345 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
347 DEBTRACE("HYDROData_CalculationCase::CreateRegionsAuto");
348 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
349 QMap<QString, QString> aRegionNameToObjNameMap;
350 QString aZonesPref = CALCULATION_ZONES_PREF;
351 HYDROData_PriorityQueue aPr( this, DataTag_CustomRules );
353 // 1. First we create a default region for each object included into the calculation case
354 HYDROData_SequenceOfObjects anObjects = GetGeometryObjects();
355 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
357 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
360 QString anObjName = anObj->GetName();
361 QString aRegName = anObjName + "_reg";
362 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
363 aRegionsMap.insert( anObjName, aRegion );
364 aRegionNameToObjNameMap.insert( aRegName, anObjName );
367 // 2. Now for each zone it is necessary to determine the most priority object
368 // and assign to zone to corresponding region
369 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
370 while( anIter.hasNext() )
372 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
373 HYDROData_Zone::MergeType aMergeType;
374 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
375 if( aRegObj.IsNull() )
377 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
378 if( aRegion.IsNull() )
380 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
382 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
384 qDebug( "Error in algorithm: unresolved conflicts" );
387 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
388 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
389 if ( !aMergeObject.IsNull() ) {
390 DEBTRACE("aMergeEntity " << aMergeEntity->GetName().toStdString());
391 aMergeEntity = aMergeObject->GetAltitudeObject();
396 case HYDROData_Zone::Merge_ZMIN:
397 case HYDROData_Zone::Merge_ZMAX:
398 aRegionZone->SetMergeType( aMergeType );
400 case HYDROData_Zone::Merge_Object:
401 aRegionZone->SetMergeType( aMergeType );
402 aRegionZone->RemoveMergeObject();
403 aRegionZone->SetMergeObject( aMergeEntity );
408 QStringList anObjectsWithEmptyRegions;
409 QMap<QString, Handle(HYDROData_Region)>::const_iterator
410 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
411 for( ; anIt!=aLast; anIt++ )
413 Handle(HYDROData_Region) aRegion = anIt.value();
414 if( aRegion->GetZones().IsEmpty() )
416 QString aRegName = aRegion->GetName();
417 QString anObjName = aRegionNameToObjNameMap[aRegName];
418 anObjectsWithEmptyRegions.append( anObjName );
422 if( !anObjectsWithEmptyRegions.empty() )
424 QString aData = anObjectsWithEmptyRegions.join( ", " );
425 SetWarning( WARN_EMPTY_REGIONS, aData );
429 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
430 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
432 QMap<QString,Handle(HYDROData_SplitShapesGroup)> aSplitEdgesGroupsMap;
434 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
435 while( anIter.hasNext() )
437 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
438 // Create new edges group
439 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
442 QString anObjName = aSplitData.ObjectNames.first();
443 if ( anObjName.isEmpty() )
445 #ifdef DEB_CALCULATION
446 QString aStr = aSplitData.ObjectNames.join(" ");
447 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
449 Handle(HYDROData_SplitShapesGroup) aSplitGroup;
450 if ( !aSplitEdgesGroupsMap.contains( anObjName ) )
452 aSplitGroup = addNewSplitGroup( CALCULATION_GROUPS_PREF + anObjName );
453 aSplitEdgesGroupsMap.insert( anObjName, aSplitGroup );
457 aSplitGroup = aSplitEdgesGroupsMap[ anObjName ];
459 if ( aSplitGroup.IsNull() )
462 aSplitGroup->AddShape( aSplitData.Shape );
464 TopTools_SequenceOfShape theShapes;
465 aSplitGroup->GetShapes(theShapes);
467 if (aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_IntEdge)
468 aSplitGroup->SetInternal(true);
472 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
474 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
475 return false; // Wrong type of object
477 if ( HasReference( theObject, DataTag_GeometryObject ) )
478 return false; // Object is already in reference list
480 AddReferenceObject( theObject, DataTag_GeometryObject );
482 // Indicate model of the need to update splitting
488 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
490 return GetReferenceObjects( DataTag_GeometryObject );
493 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
495 if ( theObject.IsNull() )
498 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
500 // Indicate model of the need to update splitting
504 void HYDROData_CalculationCase::RemoveGeometryObjects()
506 ClearReferenceObjects( DataTag_GeometryObject );
508 // Indicate model of the need to update splitting
512 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
514 if ( theGroup.IsNull() )
517 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
518 return false; // Object is already in reference list
520 AddReferenceObject( theGroup, DataTag_GeometryGroup );
522 // Indicate model of the need to update splitting
523 Changed( Geom_Groups );
528 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
530 return GetReferenceObjects( DataTag_GeometryGroup );
533 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
535 if ( theGroup.IsNull() )
538 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
540 // Indicate model of the need to update splitting
541 Changed( Geom_Groups );
544 void HYDROData_CalculationCase::RemoveGeometryGroups()
546 ClearReferenceObjects( DataTag_GeometryGroup );
548 // Indicate model of the need to update splitting
549 Changed( Geom_Groups );
552 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
554 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
556 SetReferenceObject( thePolyline, DataTag_Polyline );
558 // Indicate model of the need to update zones splitting
559 if( !IsEqual( aPrevPolyline, thePolyline ) )
563 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
565 return Handle(HYDROData_PolylineXY)::DownCast(
566 GetReferenceObject( DataTag_Polyline ) );
569 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
571 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
573 ClearReferenceObjects( DataTag_Polyline );
575 // Indicate model of the need to update zones splitting
579 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
581 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
583 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
585 // Indicate model of the need to update land covers partition
586 if( !IsEqual( aPrevStricklerTable, theStricklerTable ) )
590 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
592 return Handle(HYDROData_StricklerTable)::DownCast(
593 GetReferenceObject( DataTag_StricklerTable ) );
596 void HYDROData_CalculationCase::RemoveStricklerTable()
598 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
600 ClearReferenceObjects( DataTag_StricklerTable );
602 // Indicate model of the need to update land covers partition
606 Handle(HYDROData_LandCoverMap) HYDROData_CalculationCase::GetLandCoverMap() const
608 Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast(
609 GetReferenceObject( DataTag_LandCoverMap ) );
613 void HYDROData_CalculationCase::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
615 SetReferenceObject( theMap, DataTag_LandCoverMap );
618 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
623 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
624 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
625 if ( aNewRegion.IsNull() )
628 aNewRegion->AddZone( theZone );
633 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
635 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
637 if ( theRegion.IsNull() )
640 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
642 if ( HasReference( theRegion, aDataTag ) )
643 return false; // Object is already in reference list
645 // Move the region from other calculation
646 Handle(HYDROData_CalculationCase) aFatherCalc =
647 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
648 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
650 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
651 theRegion->CopyTo( aNewRegion, true );
653 aFatherCalc->RemoveRegion( theRegion );
655 theRegion->SetLabel( aNewRegion->Label() );
659 AddReferenceObject( theRegion, aDataTag );
665 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
667 return GetReferenceObjects( DataTag_Region );
670 void HYDROData_CalculationCase::UpdateRegionsOrder()
672 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
673 if ( aDocument.IsNull() )
676 HYDROData_SequenceOfObjects aRegions = GetRegions();
677 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
678 for ( ; anIter.More(); anIter.Next() )
680 Handle(HYDROData_Region) aRegion =
681 Handle(HYDROData_Region)::DownCast( anIter.Value() );
682 if ( aRegion.IsNull() )
685 aRegion->SetName( "" );
688 QString aRegsPref = CALCULATION_REGIONS_PREF;
690 anIter.Init( aRegions );
691 for ( ; anIter.More(); anIter.Next() )
693 Handle(HYDROData_Region) aRegion =
694 Handle(HYDROData_Region)::DownCast( anIter.Value() );
695 if ( aRegion.IsNull() )
698 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
699 aRegion->SetName( aRegionName );
703 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
705 if ( theRegion.IsNull() )
708 HYDROData_CalculationCase::DataTag aDataTag = DataTag_Region;
709 RemoveReferenceObject( theRegion->Label(), aDataTag );
711 // Remove region from data model
712 Handle(HYDROData_CalculationCase) aFatherCalc =
713 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
714 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
718 void HYDROData_CalculationCase::RemoveRegions()
720 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
723 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplitGroups() const
725 return GetReferenceObjects( DataTag_SplitGroups );
728 void HYDROData_CalculationCase::RemoveSplitGroups()
730 myLab.FindChild( DataTag_SplitGroups ).ForgetAllAttributes();
733 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
735 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
736 return GetAltitudeForPoint( thePoint, aZone );
739 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
740 const Handle(HYDROData_Region)& theRegion,
743 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
745 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
746 if ( !aZone.IsNull() )
748 //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString());
749 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
750 if ( IsEqual( aRefRegion, theRegion ) )
751 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
754 DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------");
755 aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod );
760 DEBTRACE(" --- GetAltitudeForPoint No Zone ---");
766 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
767 const Handle(HYDROData_Zone)& theZone,
770 //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString());
771 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
772 if ( theZone.IsNull() )
774 DEBTRACE("Zone nulle");
778 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
779 //DEBTRACE("aZoneMergeType " << aZoneMergeType);
780 if ( !theZone->IsMergingNeed() )
782 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
785 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
787 DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString() << " Merge_UNKNOWN");
791 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
792 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
794 Handle(HYDROData_IAltitudeObject) aMergeAltitude =
795 Handle(HYDROData_IAltitudeObject)::DownCast( theZone->GetMergeObject() );
796 if ( !aMergeAltitude.IsNull() )
798 if ( aZoneInterpolator != NULL )
800 DEBTRACE("aZoneInterpolator != NULL");
801 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
802 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
806 DEBTRACE("aZoneInterpolator == NULL");
807 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
813 //DEBTRACE("aZoneMergeType != HYDROData_Zone::Merge_Object");
814 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
815 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
816 for ( ; anIter.More(); anIter.Next() )
818 Handle(HYDROData_Object) aZoneObj =
819 Handle(HYDROData_Object)::DownCast( anIter.Value() );
820 if ( aZoneObj.IsNull() )
823 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
824 if ( anObjAltitude.IsNull() )
827 double aPointAltitude = 0.0;
828 if ( aZoneInterpolator != NULL )
830 DEBTRACE("aZoneInterpolator != NULL");
831 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
832 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
836 //DEBTRACE("aZoneInterpolator == NULL");
837 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod );
840 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
843 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
845 aResAltitude = aPointAltitude;
848 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
850 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
851 aResAltitude > aPointAltitude )
853 aResAltitude = aPointAltitude;
856 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
858 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
859 aResAltitude < aPointAltitude )
861 aResAltitude = aPointAltitude;
870 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
871 const NCollection_Sequence<gp_XY>& thePoints,
872 const Handle(HYDROData_Region)& theRegion,
875 DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString());
876 NCollection_Sequence<double> aResSeq;
878 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
880 const gp_XY& thePnt = thePoints.Value( i );
882 double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod );
883 aResSeq.Append( anAltitude );
889 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
890 const NCollection_Sequence<gp_XY>& thePoints,
891 const Handle(HYDROData_Zone)& theZone,
894 NCollection_Sequence<double> aResSeq;
896 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
898 const gp_XY& thePnt = thePoints.Value( i );
900 double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod );
901 aResSeq.Append( anAltitude );
907 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
909 Handle( HYDROData_LandCoverMap ) aMap = GetLandCoverMap();
910 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
915 aMap->FindByPoint( thePoint, aType );
916 double aCoeff = aTable->Get( aType, 0.0 );
920 std::vector<double> HYDROData_CalculationCase::GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
921 double DefValue, bool UseMax ) const
923 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
924 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
925 std::vector<double> theCoeffs;
926 if( aLCM.IsNull() || aTable.IsNull() )
929 aLCM->ClassifyPoints(thePoints, aTable, theCoeffs, DefValue, UseMax );
934 std::vector<int> HYDROData_CalculationCase::GetStricklerTypeForPoints( const std::vector<gp_XY>& thePoints ) const
936 Handle( HYDROData_LandCoverMap ) aLCM = GetLandCoverMap();
937 Handle( HYDROData_StricklerTable ) aTable = GetStricklerTable();
938 std::vector<int> types;
939 if( aLCM.IsNull() || aTable.IsNull() )
942 aLCM->ClassifyPoints(thePoints, aTable, types );
946 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
948 Handle(HYDROData_Region) aResRegion;
950 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
951 if ( !aZone.IsNull() )
952 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
957 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
959 Handle(HYDROData_Zone) aResZone;
961 HYDROData_SequenceOfObjects aRegions = GetRegions();
963 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
964 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
966 Handle(HYDROData_Region) aRegion =
967 Handle(HYDROData_Region)::DownCast( anIter.Value() );
968 if ( aRegion.IsNull() )
971 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
972 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
973 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
975 Handle(HYDROData_Zone) aRegZone =
976 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
977 if ( aRegZone.IsNull() )
980 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
981 if ( aPointRelation != POINT_OUT )
982 aResZone = aRegZone; // We found the desired zone
989 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
990 const gp_XY& thePoint,
991 const Handle(HYDROData_Zone)& theZone ) const
993 PointClassification aRes = POINT_OUT;
994 if ( theZone.IsNull() )
997 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
998 if ( aZoneFace.IsNull() )
1001 TopoDS_Compound aCmp;
1003 aBB.MakeCompound(aCmp);
1004 aBB.Add(aCmp, aZoneFace);
1005 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
1006 BRepBuilderAPI_MakeVertex aMk(aPnt);
1007 aBB.Add(aCmp, aMk.Vertex());
1008 BRepTools::Write(aCmp, "FCL2d.brep");
1010 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
1011 if (State == TopAbs_OUT)
1013 else if(State == TopAbs_IN)
1015 else if(State == TopAbs_ON)
1020 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1021 const QString& thePrefixOrName,
1024 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
1025 int aTag = aNewLab.Tag();
1027 Handle(HYDROData_Region) aNewRegion =
1028 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1029 AddRegion( aNewRegion );
1031 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1032 aNewRegion->SetName( aRegionName, true );
1037 Handle(HYDROData_SplitShapesGroup) HYDROData_CalculationCase::addNewSplitGroup( const QString& theName )
1039 TDF_Label aNewLab = myLab.FindChild( DataTag_SplitGroups ).NewChild();
1041 Handle(HYDROData_SplitShapesGroup) aNewGroup =
1042 Handle(HYDROData_SplitShapesGroup)::DownCast(
1043 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLIT_GROUP ) );
1044 AddReferenceObject( aNewGroup, DataTag_SplitGroups );
1046 aNewGroup->SetName( theName );
1051 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1056 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1057 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1059 QString aGeomObjEntry, anErrorMsg;
1061 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry, anErrorMsg, statMess );
1062 return isOK ? aGeomObjEntry : QString();
1067 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1068 SALOMEDS::Study_ptr theStudy,
1069 QString& theGeomObjEntry,
1070 QString& theErrorMsg,
1071 QString& statMess) const
1073 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1075 // Get groups definitions
1076 HYDROData_SequenceOfObjects aSplitGroups = GetSplitGroups();
1078 TopTools_SequenceOfShape IntSh; //internal edges
1079 HYDROData_SequenceOfObjects::Iterator anIter( aSplitGroups );
1080 for ( ; anIter.More(); anIter.Next() )
1083 Handle(HYDROData_ShapesGroup) aGroup =
1084 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1085 if ( aGroup.IsNull() )
1088 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1090 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1091 aGroup->GetShapes( aGroupDef.Shapes );
1093 aSeqOfGroupsDefs.Append( aGroupDef );
1095 Handle(HYDROData_SplitShapesGroup) aSSGroup = Handle(HYDROData_SplitShapesGroup)::DownCast( anIter.Value() );
1096 TopTools_SequenceOfShape dummy;
1097 if (!aSSGroup.IsNull())
1098 if (aSSGroup->GetInternal())
1100 aSSGroup->GetShapes(dummy);
1101 IntSh.Append(dummy);
1107 bool isAllNotSubmersible = true;
1108 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
1109 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1110 NCollection_IndexedDataMap<TopoDS_Shape, QString> aShToNames;
1111 for ( ; aRegionIter.More(); aRegionIter.Next() )
1113 Handle(HYDROData_Region) aRegion =
1114 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1115 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1118 if ( isAllNotSubmersible )
1119 isAllNotSubmersible = false;
1121 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs, &IntSh );
1122 aShToNames.Add( aRegionShape, aRegion->GetName() );
1127 if ( aCaseRegions.IsEmpty() ) {
1128 theErrorMsg = QString("the list of regions is empty.");
1129 } else if ( isAllNotSubmersible ) {
1130 theErrorMsg = QString("there are no submersible regions.");
1132 aRes = Export( theGeomEngine, theStudy, aShToNames, aSeqOfGroupsDefs, theGeomObjEntry );;
1135 if( aRes && !GetLandCoverMap().IsNull() && !GetStricklerTable().IsNull() )
1137 QString aTelemacFileName = GetName() + ".telemac";
1138 aRes = GetLandCoverMap()->ExportTelemac( aTelemacFileName, 1E-2, GetStricklerTable(), statMess );
1140 theErrorMsg = QString( "The export to TELEMAC %1 failed" ).arg( aTelemacFileName );
1145 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1146 SALOMEDS::Study_ptr theStudy,
1147 const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aShToName,
1148 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1149 QString& theGeomObjEntry ) const
1152 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1153 aSewing.SetNonManifoldMode( Standard_False );
1154 #ifdef DEB_CALCULATION
1155 TCollection_AsciiString aNam("Sh_");
1158 TopTools_DataMapOfShapeListOfShape SH2M;
1159 for ( int i = 1; i <= aShToName.Extent(); i++ )
1161 const TopoDS_Shape& aShape = aShToName.FindKey(i);
1162 if ( aShape.IsNull() )
1165 SH2M.Bind(aShape, TopTools_ListOfShape());
1166 TopTools_ListOfShape& LM = SH2M.ChangeFind(aShape);
1167 if ( aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL )
1169 aSewing.Add( aShape );
1172 else if (aShape.ShapeType() == TopAbs_COMPOUND)
1174 TopExp_Explorer anExp( aShape, TopAbs_SHELL );
1175 for (; anExp.More(); anExp.Next() )
1177 aSewing.Add( anExp.Current() );
1178 LM.Append(anExp.Current());
1180 anExp.Init( aShape, TopAbs_FACE, TopAbs_SHELL );
1182 aSewing.Add( anExp.Current() );
1183 LM.Append(anExp.Current());
1189 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1191 NCollection_IndexedDataMap<TopoDS_Shape, QString, TopTools_ShapeMapHasher> aFacesToNameModif;
1193 for ( int i = 1; i <= aShToName.Extent(); i++ )
1195 const TopoDS_Shape& CurShape = aShToName.FindKey(i);
1196 const QString& Qstr = aShToName.FindFromIndex(i);
1197 const TopTools_ListOfShape& LM = SH2M(CurShape);
1198 for (TopTools_ListIteratorOfListOfShape it(LM); it.More(); it.Next())
1200 const TopoDS_Shape& csh = it.Value();
1201 if (aSewing.IsModified(csh))
1202 aFacesToNameModif.Add(aSewing.Modified(csh), Qstr);
1204 aFacesToNameModif.Add(csh, Qstr);
1209 // If the sewed shape is empty - return false
1210 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1213 #ifdef DEB_CALCULATION
1214 BRepTools::Write(aSewedShape ,"Sew.brep");
1216 // Publish the sewed shape
1217 QString aName = EXPORT_NAME;
1218 GEOM::GEOM_Object_ptr aMainShape =
1219 HYDROData_GeomTool::ExplodeShapeInGEOMandPublish( theGeomEngine, theStudy, aSewedShape, aFacesToNameModif, aName, theGeomObjEntry );
1221 if ( aMainShape->_is_nil() )
1224 if ( theGroupsDefs.IsEmpty() )
1228 TopTools_IndexedMapOfShape aMapOfSubShapes;
1229 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1231 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1233 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1235 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1237 NCollection_Sequence<int> aGroupIndexes;
1238 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1240 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1241 #ifdef DEB_CALCULATION
1242 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1245 TopoDS_Shape aModifiedShape = aShape;
1246 if ( aSewing.IsModified( aShape ) )
1247 aModifiedShape = aSewing.Modified( aShape );
1248 else if ( aSewing.IsModifiedSubShape( aShape ) )
1249 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1251 #ifdef DEB_CALCULATION
1252 const TopLoc_Location& aL1 = aShape.Location();
1253 const TopLoc_Location& aL2 = aModifiedShape.Location();
1254 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1257 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1258 if ( anIndex > 0 ) {
1259 aGroupIndexes.Append( anIndex );
1261 #ifdef DEB_CALCULATION
1262 TCollection_AsciiString aNam("Lost_");
1263 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1264 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1266 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1267 if ( aModifiedShape.IsPartner( aS ) )
1269 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1270 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1271 BRepTools::Write(aS ,aName.ToCString());
1279 if ( !aGroupIndexes.IsEmpty() )
1280 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1283 if ( !aGroupsData.IsEmpty() )
1285 GEOM::GEOM_IGroupOperations_var aGroupOp =
1286 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1288 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1289 for ( ; aMapIt.More(); aMapIt.Next() )
1291 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1292 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1294 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1295 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1298 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1299 aGeomIndexes->length( aGroupIndexes.Length() );
1301 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1302 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1304 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1305 if ( aGroupOp->IsDone() )
1307 SALOMEDS::SObject_var aGroupSO =
1308 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1317 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1318 const bool theIsSetToUpdate )
1320 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1321 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1323 // Indicate model of the need to update splitting
1324 if ( theIsSetToUpdate ) {
1329 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1330 HYDROData_PriorityType thePriority,
1331 const Handle(HYDROData_Entity)& theObject2,
1332 HYDROData_Zone::MergeType theMergeType,
1333 HYDROData_CalculationCase::DataTag theDataTag )
1335 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1336 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1338 // Indicate model of the need to update splitting
1342 QString HYDROData_CalculationCase::DumpRules() const
1344 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1345 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1348 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1350 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1351 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1353 // Indicate model of the need to update splitting
1357 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1359 Handle(TDataStd_Integer) aModeAttr;
1360 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1362 return ( AssignmentMode ) aModeAttr->Get();
1367 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1368 QStringList& theScript ) const
1370 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1371 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1374 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1376 return myLastWarning;
1379 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1381 myLastWarning.Type = theType;
1382 myLastWarning.Data = theData;
1385 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1386 const QString& theOldCaseName,
1387 const QString& theName )
1389 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1390 for ( ; anIter.More(); anIter.Next() )
1392 Handle(HYDROData_Region) aRegion =
1393 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1394 if ( aRegion.IsNull() )
1397 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1399 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1400 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1401 for ( ; anIter.More(); anIter.Next() )
1403 Handle(HYDROData_Zone) aRegZone =
1404 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1405 if ( aRegZone.IsNull() )
1408 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1413 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1414 const QString& thePyScriptPath,
1415 MapOfTreatedObjects& theTreatedObjects,
1416 const HYDROData_SequenceOfObjects& theRegions ) const
1418 HYDROData_SequenceOfObjects::Iterator anIter;
1419 anIter.Init(theRegions);
1420 for (int ireg = 1; anIter.More(); anIter.Next(), ireg++)
1422 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1423 if (aRegion.IsNull())
1425 QString defRegName = this->GetName();
1426 QString regSuffix = QString("_Reg_%1").arg(ireg);
1427 defRegName += regSuffix;
1428 theTreatedObjects.insert(aRegion->GetName(), aRegion);
1429 QStringList aRegDump = aRegion->DumpToPython(thePyScriptPath, theTreatedObjects, defRegName);
1430 theResList << aRegDump;
1432 for (anIter.Init(theRegions); anIter.More(); anIter.Next())
1434 Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast(anIter.Value());
1435 if (aRegion.IsNull())
1437 QStringList aRegDump;
1438 aRegion->SetNameInDumpPython(aRegDump);
1439 theResList << aRegDump;
1443 bool HYDROData_CalculationCase::GetRule( int theIndex,
1444 Handle(HYDROData_Entity)& theObject1,
1445 HYDROData_PriorityType& thePriority,
1446 Handle(HYDROData_Entity)& theObject2,
1447 HYDROData_Zone::MergeType& theMergeType,
1448 HYDROData_CalculationCase::DataTag& theDataTag) const
1450 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1451 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1452 theObject1, thePriority, theObject2, theMergeType );
1455 bool HYDROData_CalculationCase::AddInterPoly( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1457 HYDROData_CalculationCase::DataTag aDataTag = DataTag_InterPoly;
1459 if ( HasReference( theInterPolyline, aDataTag ) )
1462 AddReferenceObject( theInterPolyline, aDataTag );
1469 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetInterPolyObjects() const
1471 return GetReferenceObjects( DataTag_InterPoly );
1474 void HYDROData_CalculationCase::RemoveInterPolyObject( const Handle(HYDROData_PolylineXY)& theInterPolyline )
1476 if ( theInterPolyline.IsNull() )
1479 RemoveReferenceObject( theInterPolyline->Label(), DataTag_InterPoly );