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"
21 #include "HYDROData_ArtificialObject.h"
22 #include "HYDROData_IAltitudeObject.h"
23 #include "HYDROData_Document.h"
24 #include "HYDROData_ShapesGroup.h"
25 #include "HYDROData_Iterator.h"
26 #include "HYDROData_NaturalObject.h"
27 #include "HYDROData_PolylineXY.h"
28 #include "HYDROData_StricklerTable.h"
29 #include "HYDROData_LandCover.h"
30 #include "HYDROData_SplittedShapesGroup.h"
31 #include "HYDROData_Region.h"
32 #include "HYDROData_Tool.h"
33 #include "HYDROData_GeomTool.h"
40 #include <TopoDS_Shell.hxx>
41 #include <TopoDS_Edge.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRepBuilderAPI_Sewing.hxx>
45 #include <BRepTopAdaptor_FClass2d.hxx>
47 #include <BRepTools.hxx>
50 #include <TopExp_Explorer.hxx>
52 #include <TopTools_ListOfShape.hxx>
53 #include <TopTools_ListIteratorOfListOfShape.hxx>
54 #include <TDataStd_Integer.hxx>
56 //#define DEB_CALCULATION 1
57 #ifdef DEB_CALCULATION
58 #include <BRepTools.hxx>
59 #include <TopLoc_Location.hxx>
61 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
62 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
63 #define CALCULATION_LANDCOVER_ZONES_PREF GetName() + "_LandCoverZone"
64 #define CALCULATION_GROUPS_PREF GetName() + "_"
65 //#define DEB_CLASS2D 1
67 #include <BRepBuilderAPI_MakeVertex.hxx>
70 #define EXPORT_NAME "HYDRO_" + GetName()
72 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
73 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
75 HYDROData_CalculationCase::HYDROData_CalculationCase()
80 HYDROData_CalculationCase::~HYDROData_CalculationCase()
84 void HYDROData_CalculationCase::SetName( const QString& theName )
86 QString anOldCaseName = GetName();
87 if ( anOldCaseName != theName )
89 // Update names of regions and its zones
90 UpdateRegionsNames( GetRegions( false ), anOldCaseName, theName );
91 // Update names of land cover regions and its zones
92 UpdateRegionsNames( GetRegions( true ), anOldCaseName, theName );
94 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
96 HYDROData_SequenceOfObjects::Iterator anIter;
97 anIter.Init( aGroups );
98 for ( ; anIter.More(); anIter.Next() )
100 Handle(HYDROData_SplittedShapesGroup) aGroup =
101 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
102 if ( aGroup.IsNull() )
105 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
109 HYDROData_Entity::SetName( theName );
112 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
114 QStringList aResList = dumpObjectCreation( theTreatedObjects );
115 aResList.prepend( "# Calculation case" );
117 QString aCalculName = GetObjPyName();
119 AssignmentMode aMode = GetAssignmentMode();
120 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
121 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
123 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
124 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
125 for ( ; anIter.More(); anIter.Next() )
127 Handle(HYDROData_Object) aRefGeomObj =
128 Handle(HYDROData_Object)::DownCast( anIter.Value() );
129 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
131 aResList << QString( "" );
133 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
135 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
136 anIter.Init( aGeomGroups );
137 for ( ; anIter.More(); anIter.Next() )
139 Handle(HYDROData_ShapesGroup) aGeomGroup =
140 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
141 if ( aGeomGroup.IsNull() )
144 Handle(HYDROData_Object) aFatherGeom =
145 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
146 if ( aFatherGeom.IsNull() )
149 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
150 aResList << QString( "%1 = %2.GetGroup( %3 );" )
151 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
153 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
156 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
157 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
159 if( aMode==AUTOMATIC )
160 DumpRulesToPython( aCalculName, aResList );
162 aResList << QString( "" );
163 aResList << "# Start the algorithm of the partition and assignment";
164 aResList << QString( "%1.Update();" ).arg( aCalculName );
168 // Now we restore the
169 // - regions and zones order
170 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( false ) );
171 // - land cover regions and zones order
172 DumpRegionsToPython( aResList, theTreatedObjects, GetRegions( true ) );
175 // Export calculation case
176 aResList << QString( "" );
177 aResList << "# Export of the calculation case";
178 QString aStudyName = "theStudy";
179 QString anEntryVar = aCalculName + "_entry";
180 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
182 // Get geometry object and print debug information
184 aResList << "# Get geometry shape and print debug information";
185 aResList << "import GEOM";
186 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
187 QString aGeomShapeName = aCalculName + "_geom";
188 aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
189 aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
190 aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
192 DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
194 aResList << QString( "" );
198 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
199 const QString& theStudyName,
200 const QString& theGeomShapeName,
201 const QString& theMeshName ) const
204 theResList << "# Meshing";
205 theResList << "import SMESH, SALOMEDS";
206 theResList << "from salome.smesh import smeshBuilder";
207 theResList << "from salome.geom import geomBuilder";
209 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
210 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
211 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
212 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
213 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
214 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
215 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
218 theResList << "# Set names of Mesh objects";
219 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
220 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
221 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
222 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
223 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
226 theResList << "# Greate SMESH groups";
227 theResList << QString( "geompy = geomBuilder.New( %1 )" ).arg( theStudyName );
228 theResList << QString( "geom_groups = geompy.GetGroups( %1 )" ).arg( theGeomShapeName );
229 theResList << QString( "for group in geom_groups:" );
230 theResList << QString( " smesh_group = %1.GroupOnGeom(group, group.GetName(), SMESH.EDGE)" )
232 theResList << QString( " smesh.SetName(smesh_group, group.GetName())" );
233 theResList << QString( " print \"SMESH group '%s': %s\" % (smesh_group.GetName(), smesh_group)" );
236 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
238 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
240 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
241 if ( !aBoundaryPolyline.IsNull() )
242 aResSeq.Append( aBoundaryPolyline );
245 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions( false );
246 aResSeq.Append( aSeqOfRegions );
248 // Land cover regions
249 HYDROData_SequenceOfObjects aSeqOfLandCoverRegions = GetRegions( true );
250 aResSeq.Append( aSeqOfLandCoverRegions );
255 void HYDROData_CalculationCase::Update()
257 HYDROData_Entity::Update();
260 // At first we remove previously created objects
261 RemoveRegions( false );
262 RemoveRegions( true );
263 RemoveSplittedGroups();
265 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
266 if ( aDocument.IsNull() )
270 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
272 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
273 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
274 if ( !aGeomObjects.IsEmpty() ) {
275 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
277 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
278 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
279 if ( !aSplitObjects.isEmpty() ) {
280 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
281 while( anIter.hasNext() ) {
282 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
283 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
284 aZonesList.append( aSplitData );
285 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
286 anEdgesList.append( aSplitData );
291 // Split to land cover zones
292 HYDROData_SplitToZonesTool::SplitDataList aLandCoverZonesList;
294 HYDROData_SequenceOfObjects aLandCovers = GetLandCovers();
295 if ( !aLandCovers.IsEmpty() ) {
296 HYDROData_SplitToZonesTool::SplitDataList aSplitLandCoverObjects =
297 HYDROData_SplitToZonesTool::Split( aLandCovers );
298 if ( !aSplitLandCoverObjects.isEmpty() ) {
299 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitLandCoverObjects );
300 while( anIter.hasNext() ) {
301 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
302 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
303 aLandCoverZonesList.append( aSplitData );
308 switch( GetAssignmentMode() )
311 CreateRegionsDef( aDocument, aZonesList, false );
312 CreateRegionsDef( aDocument, aLandCoverZonesList, true );
315 CreateRegionsAuto( aDocument, aZonesList, false );
316 CreateRegionsAuto( aDocument, aLandCoverZonesList, true );
319 CreateEdgeGroupsDef( aDocument, anEdgesList );
322 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
323 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
324 const bool theLandCover )
326 // Create result regions for case, by default one zone for one region
327 QString aRegsPref = CALCULATION_REGIONS_PREF;
328 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
330 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
331 while( anIter.hasNext() )
333 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
335 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref, theLandCover );
337 // Add the zone for region
338 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
342 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
343 const HYDROData_SplitToZonesTool::SplitDataList& theZones,
344 const bool theLandCover )
346 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
347 QMap<QString, QString> aRegionNameToObjNameMap;
348 QString aZonesPref = theLandCover ? CALCULATION_LANDCOVER_ZONES_PREF : CALCULATION_ZONES_PREF;
349 HYDROData_PriorityQueue aPr( this, theLandCover ? DataTag_CustomLandCoverRules : DataTag_CustomRules );
351 // 1. First we create a default region for each object included into the calculation case
352 HYDROData_SequenceOfObjects anObjects = theLandCover ? GetLandCovers() : GetGeometryObjects();
353 for( int i = anObjects.Lower(), n = anObjects.Upper(); i<=n; i++ )
355 Handle(HYDROData_Entity) anObj = anObjects.Value( i );
358 QString anObjName = anObj->GetName();
359 QString aRegName = anObjName + "_reg";
360 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, theLandCover, false );
361 aRegionsMap.insert( anObjName, aRegion );
362 aRegionNameToObjNameMap.insert( aRegName, anObjName );
365 // 2. Now for each zone it is necessary to determine the most priority object
366 // and assign to zone to corresponding region
367 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
368 while( anIter.hasNext() )
370 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
371 HYDROData_Zone::MergeType aMergeType;
372 Handle(HYDROData_Entity) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
373 if( aRegObj.IsNull() )
375 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
376 if( aRegion.IsNull() )
378 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
380 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
382 qDebug( "Error in algorithm: unresolved conflicts" );
385 Handle(HYDROData_Entity) aMergeEntity = aRegObj;
386 if ( !theLandCover ) {
387 Handle(HYDROData_Object) aMergeObject = Handle(HYDROData_Object)::DownCast( aMergeEntity );
388 if ( !aMergeObject.IsNull() ) {
389 aMergeEntity = aMergeObject->GetAltitudeObject();
395 case HYDROData_Zone::Merge_ZMIN:
396 case HYDROData_Zone::Merge_ZMAX:
397 aRegionZone->SetMergeType( aMergeType );
399 case HYDROData_Zone::Merge_Object:
400 aRegionZone->SetMergeType( aMergeType );
401 aRegionZone->RemoveMergeObject();
402 aRegionZone->SetMergeObject( aMergeEntity );
407 QStringList anObjectsWithEmptyRegions;
408 QMap<QString, Handle(HYDROData_Region)>::const_iterator
409 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
410 for( ; anIt!=aLast; anIt++ )
412 Handle(HYDROData_Region) aRegion = anIt.value();
413 if( aRegion->GetZones().IsEmpty() )
415 QString aRegName = aRegion->GetName();
416 QString anObjName = aRegionNameToObjNameMap[aRegName];
417 anObjectsWithEmptyRegions.append( anObjName );
421 if( !anObjectsWithEmptyRegions.empty() )
423 QString aData = anObjectsWithEmptyRegions.join( ", " );
424 SetWarning( WARN_EMPTY_REGIONS, aData );
428 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
429 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
431 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
433 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
434 while( anIter.hasNext() )
436 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
437 // Create new edges group
438 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
441 QString anObjName = aSplitData.ObjectNames.first();
442 if ( anObjName.isEmpty() )
444 #ifdef DEB_CALCULATION
445 QString aStr = aSplitData.ObjectNames.join(" ");
446 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
448 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
449 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
451 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
452 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
456 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
458 if ( aSplittedGroup.IsNull() )
461 aSplittedGroup->AddShape( aSplitData.Shape );
465 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
467 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
468 return false; // Wrong type of object
470 if ( HasReference( theObject, DataTag_GeometryObject ) )
471 return false; // Object is already in reference list
473 AddReferenceObject( theObject, DataTag_GeometryObject );
475 // Indicate model of the need to update splitting
481 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
483 return GetReferenceObjects( DataTag_GeometryObject );
486 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
488 if ( theObject.IsNull() )
491 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
493 // Indicate model of the need to update splitting
497 void HYDROData_CalculationCase::RemoveGeometryObjects()
499 ClearReferenceObjects( DataTag_GeometryObject );
501 // Indicate model of the need to update splitting
505 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
507 if ( theGroup.IsNull() )
510 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
511 return false; // Object is already in reference list
513 AddReferenceObject( theGroup, DataTag_GeometryGroup );
515 // Indicate model of the need to update splitting
521 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
523 return GetReferenceObjects( DataTag_GeometryGroup );
526 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
528 if ( theGroup.IsNull() )
531 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
533 // Indicate model of the need to update splitting
537 void HYDROData_CalculationCase::RemoveGeometryGroups()
539 ClearReferenceObjects( DataTag_GeometryGroup );
541 // Indicate model of the need to update splitting
545 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
547 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
549 SetReferenceObject( thePolyline, DataTag_Polyline );
551 // Indicate model of the need to update zones splitting
552 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
555 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
557 return Handle(HYDROData_PolylineXY)::DownCast(
558 GetReferenceObject( DataTag_Polyline ) );
561 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
563 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
565 ClearReferenceObjects( DataTag_Polyline );
567 // Indicate model of the need to update zones splitting
568 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
571 void HYDROData_CalculationCase::SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable )
573 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
575 SetReferenceObject( theStricklerTable, DataTag_StricklerTable );
577 // Indicate model of the need to update land covers partition
578 SetToUpdate( !IsEqual( aPrevStricklerTable, theStricklerTable ) || IsMustBeUpdated() );
581 Handle(HYDROData_StricklerTable) HYDROData_CalculationCase::GetStricklerTable() const
583 return Handle(HYDROData_StricklerTable)::DownCast(
584 GetReferenceObject( DataTag_StricklerTable ) );
587 void HYDROData_CalculationCase::RemoveStricklerTable()
589 Handle(HYDROData_StricklerTable) aPrevStricklerTable = GetStricklerTable();
591 ClearReferenceObjects( DataTag_StricklerTable );
593 // Indicate model of the need to update land covers partition
594 SetToUpdate( !aPrevStricklerTable.IsNull() || IsMustBeUpdated() );
597 bool HYDROData_CalculationCase::AddLandCover( const Handle(HYDROData_LandCover)& theLandCover )
599 if ( HasReference( theLandCover, DataTag_LandCover ) )
600 return false; // Land cover is already in reference list
602 AddReferenceObject( theLandCover, DataTag_LandCover );
604 // Indicate model of the need to update land covers partition
610 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetLandCovers() const
612 return GetReferenceObjects( DataTag_LandCover );
615 void HYDROData_CalculationCase::RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover )
617 if ( theLandCover.IsNull() )
620 RemoveReferenceObject( theLandCover->Label(), DataTag_LandCover );
622 // Indicate model of the need to update land cover partition
626 void HYDROData_CalculationCase::RemoveLandCovers()
628 ClearReferenceObjects( DataTag_LandCover );
630 // Indicate model of the need to update land cover partition
634 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone,
635 const bool theLandCover )
637 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
638 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
639 if ( aNewRegion.IsNull() )
642 aNewRegion->AddZone( theZone );
647 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion,
648 const bool theLandCover )
650 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
652 if ( theRegion.IsNull() )
655 HYDROData_CalculationCase::DataTag aDataTag =
656 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
658 if ( HasReference( theRegion, aDataTag ) )
659 return false; // Object is already in reference list
661 // Move the region from other calculation
662 Handle(HYDROData_CalculationCase) aFatherCalc =
663 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
664 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
666 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF, theLandCover );
667 theRegion->CopyTo( aNewRegion );
669 aFatherCalc->RemoveRegion( theRegion, theLandCover );
671 theRegion->SetLabel( aNewRegion->Label() );
675 AddReferenceObject( theRegion, aDataTag );
681 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions( const bool theLandCover ) const
683 return GetReferenceObjects( theLandCover ? DataTag_LandCoverRegion : DataTag_Region );
686 void HYDROData_CalculationCase::UpdateRegionsOrder()
688 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
689 if ( aDocument.IsNull() )
692 HYDROData_SequenceOfObjects aRegions = GetRegions( false );
693 aRegions.Append( GetRegions( true ) );
695 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
696 for ( ; anIter.More(); anIter.Next() )
698 Handle(HYDROData_Region) aRegion =
699 Handle(HYDROData_Region)::DownCast( anIter.Value() );
700 if ( aRegion.IsNull() )
703 aRegion->SetName( "" );
706 QString aRegsPref = CALCULATION_REGIONS_PREF;
708 anIter.Init( aRegions );
709 for ( ; anIter.More(); anIter.Next() )
711 Handle(HYDROData_Region) aRegion =
712 Handle(HYDROData_Region)::DownCast( anIter.Value() );
713 if ( aRegion.IsNull() )
716 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
717 aRegion->SetName( aRegionName );
721 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion,
722 const bool theLandCover )
724 if ( theRegion.IsNull() )
727 HYDROData_CalculationCase::DataTag aDataTag =
728 theLandCover ? DataTag_LandCoverRegion : DataTag_Region;
729 RemoveReferenceObject( theRegion->Label(), aDataTag );
731 // Remove region from data model
732 Handle(HYDROData_CalculationCase) aFatherCalc =
733 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
734 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
738 void HYDROData_CalculationCase::RemoveRegions( const bool theLandCover )
740 myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).ForgetAllAttributes();
743 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
745 return GetReferenceObjects( DataTag_SplittedGroups );
748 void HYDROData_CalculationCase::RemoveSplittedGroups()
750 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
753 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
755 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
756 return GetAltitudeForPoint( thePoint, aZone );
759 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
760 const Handle(HYDROData_Region)& theRegion ) const
762 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
764 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, false );
765 if ( !aZone.IsNull() )
767 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
768 if ( IsEqual( aRefRegion, theRegion ) )
769 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
775 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
776 const Handle(HYDROData_Zone)& theZone ) const
778 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
779 if ( theZone.IsNull() )
782 HYDROData_Zone::MergeType aZoneMergeType = theZone->GetMergeType();
783 if ( !theZone->IsMergingNeed() )
785 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
787 else if ( aZoneMergeType == HYDROData_Zone::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 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
802 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
805 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
810 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetObjects();
811 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
812 for ( ; anIter.More(); anIter.Next() )
814 Handle(HYDROData_Object) aZoneObj =
815 Handle(HYDROData_Object)::DownCast( anIter.Value() );
816 if ( aZoneObj.IsNull() )
819 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
820 if ( anObjAltitude.IsNull() )
823 double aPointAltitude = 0.0;
824 if ( aZoneInterpolator != NULL )
826 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
827 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
830 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
832 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
835 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
837 aResAltitude = aPointAltitude;
840 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
842 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
843 aResAltitude > aPointAltitude )
845 aResAltitude = aPointAltitude;
848 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
850 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
851 aResAltitude < aPointAltitude )
853 aResAltitude = aPointAltitude;
862 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
863 const NCollection_Sequence<gp_XY>& thePoints,
864 const Handle(HYDROData_Region)& theRegion ) const
866 NCollection_Sequence<double> aResSeq;
868 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
870 const gp_XY& thePnt = thePoints.Value( i );
872 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
873 aResSeq.Append( anAltitude );
879 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
880 const NCollection_Sequence<gp_XY>& thePoints,
881 const Handle(HYDROData_Zone)& theZone ) const
883 NCollection_Sequence<double> aResSeq;
885 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
887 const gp_XY& thePnt = thePoints.Value( i );
889 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
890 aResSeq.Append( anAltitude );
896 double HYDROData_CalculationCase::GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const
899 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
900 if ( !aDocument.IsNull() )
901 aCoeff = aDocument->GetDefaultStricklerCoefficient();
903 Handle(HYDROData_LandCover) aLandCover;
904 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, Standard_True );
905 if ( !aZone.IsNull() )
907 HYDROData_SequenceOfObjects anObjList = aZone->GetObjects();
908 if ( anObjList.Length() == 1 )
909 aLandCover = Handle(HYDROData_LandCover)::DownCast( anObjList.First() );
911 aLandCover = Handle(HYDROData_LandCover)::DownCast( aZone->GetMergeObject() );
914 if ( !aLandCover.IsNull() )
916 QString aType = aLandCover->GetStricklerType();
917 Handle(HYDROData_StricklerTable) aTable = GetStricklerTable();
918 if ( !aTable.IsNull() )
920 if ( aTable->GetTypes().contains( aType ) )
921 aCoeff = aTable->Get( aType, aCoeff );
928 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint,
929 const bool theLandCover ) const
931 Handle(HYDROData_Region) aResRegion;
933 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint, theLandCover );
934 if ( !aZone.IsNull() )
935 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
940 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint,
941 const bool theLandCover ) const
943 Handle(HYDROData_Zone) aResZone;
945 HYDROData_SequenceOfObjects aRegions = GetRegions( theLandCover );
947 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
948 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
950 Handle(HYDROData_Region) aRegion =
951 Handle(HYDROData_Region)::DownCast( anIter.Value() );
952 if ( aRegion.IsNull() )
955 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
956 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
957 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
959 Handle(HYDROData_Zone) aRegZone =
960 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
961 if ( aRegZone.IsNull() )
964 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
965 if ( aPointRelation != POINT_OUT )
966 aResZone = aRegZone; // We found the desired zone
973 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
974 const gp_XY& thePoint,
975 const Handle(HYDROData_Zone)& theZone ) const
977 PointClassification aRes = POINT_OUT;
978 if ( theZone.IsNull() )
981 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
982 if ( aZoneFace.IsNull() )
985 TopoDS_Compound aCmp;
987 aBB.MakeCompound(aCmp);
988 aBB.Add(aCmp, aZoneFace);
989 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
990 BRepBuilderAPI_MakeVertex aMk(aPnt);
991 aBB.Add(aCmp, aMk.Vertex());
992 BRepTools::Write(aCmp, "FCL2d.brep");
994 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
995 if (State == TopAbs_OUT)
997 else if(State == TopAbs_IN)
999 else if(State == TopAbs_ON)
1004 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
1005 const QString& thePrefixOrName,
1006 const bool theLandCover,
1009 TDF_Label aNewLab = myLab.FindChild( theLandCover ? DataTag_ChildLandCoverRegion : DataTag_ChildRegion ).NewChild();
1010 int aTag = aNewLab.Tag();
1012 Handle(HYDROData_Region) aNewRegion =
1013 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
1014 AddRegion( aNewRegion, theLandCover );
1016 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
1017 aNewRegion->SetName( aRegionName );
1022 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
1024 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
1026 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
1027 Handle(HYDROData_SplittedShapesGroup)::DownCast(
1028 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
1029 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
1031 aNewGroup->SetName( theName );
1036 QString HYDROData_CalculationCase::Export( int theStudyId ) const
1038 GEOM::GEOM_Gen_var aGEOMEngine = HYDROData_GeomTool::GetGeomGen();
1039 SALOMEDS::Study_var aDSStudy = HYDROData_GeomTool::GetStudyByID( theStudyId );
1041 QString aGeomObjEntry;
1042 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry );
1043 return isOK ? aGeomObjEntry : QString();
1046 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1047 SALOMEDS::Study_ptr theStudy,
1048 QString& theGeomObjEntry ) const
1050 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
1052 // Get groups definitions
1053 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
1055 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
1056 for ( ; anIter.More(); anIter.Next() )
1059 Handle(HYDROData_ShapesGroup) aGroup =
1060 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
1061 if ( aGroup.IsNull() )
1064 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
1066 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
1067 aGroup->GetShapes( aGroupDef.Shapes );
1069 aSeqOfGroupsDefs.Append( aGroupDef );
1073 TopTools_ListOfShape aFaces;
1074 HYDROData_SequenceOfObjects aCaseRegions = GetRegions( false );
1075 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
1076 for ( ; aRegionIter.More(); aRegionIter.Next() )
1078 Handle(HYDROData_Region) aRegion =
1079 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
1080 if( aRegion.IsNull() || !aRegion->IsSubmersible() )
1083 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
1084 aFaces.Append( aRegionShape );
1087 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );
1090 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
1091 SALOMEDS::Study_ptr theStudy,
1092 const TopTools_ListOfShape& theFaces,
1093 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
1094 QString& theGeomObjEntry ) const
1097 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
1098 aSewing.SetNonManifoldMode( Standard_False );
1099 #ifdef DEB_CALCULATION
1100 TCollection_AsciiString aNam("Sh_");
1103 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
1104 for ( ; aFaceIter.More(); aFaceIter.Next() )
1106 TopoDS_Shape aShape = aFaceIter.Value();
1107 if ( aShape.IsNull() )
1110 if ( aShape.ShapeType() == TopAbs_FACE )
1112 aSewing.Add( aShape );
1113 #ifdef DEB_CALCULATION
1114 TCollection_AsciiString aName = aNam + ++i + ".brep";
1115 BRepTools::Write(aShape ,aName.ToCString());
1120 #ifdef DEB_CALCULATION
1123 TopExp_Explorer anExp( aShape, TopAbs_FACE );
1124 for (; anExp.More(); anExp.Next() ) {
1125 aSewing.Add( anExp.Current() );
1126 #ifdef DEB_CALCULATION
1128 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1129 BRepTools::Write(anExp.Current() ,aName.ToCString());
1136 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1138 // If the sewed shape is empty - return false
1139 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1142 #ifdef DEB_CALCULATION
1143 BRepTools::Write(aSewedShape ,"Sew.brep");
1145 // Publish the sewed shape
1146 QString aName = EXPORT_NAME;
1147 GEOM::GEOM_Object_ptr aMainShape =
1148 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1150 if ( aMainShape->_is_nil() )
1153 if ( theGroupsDefs.IsEmpty() )
1157 TopTools_IndexedMapOfShape aMapOfSubShapes;
1158 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1160 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1162 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1164 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1166 NCollection_Sequence<int> aGroupIndexes;
1167 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1169 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1170 #ifdef DEB_CALCULATION
1171 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1174 TopoDS_Shape aModifiedShape = aShape;
1175 if ( aSewing.IsModified( aShape ) )
1176 aModifiedShape = aSewing.Modified( aShape );
1177 else if ( aSewing.IsModifiedSubShape( aShape ) )
1178 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1180 #ifdef DEB_CALCULATION
1181 const TopLoc_Location& aL1 = aShape.Location();
1182 const TopLoc_Location& aL2 = aModifiedShape.Location();
1183 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1186 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1187 if ( anIndex > 0 ) {
1188 aGroupIndexes.Append( anIndex );
1190 #ifdef DEB_CALCULATION
1191 TCollection_AsciiString aNam("Lost_");
1192 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1193 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1195 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1196 if ( aModifiedShape.IsPartner( aS ) )
1198 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1199 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1200 BRepTools::Write(aS ,aName.ToCString());
1208 if ( !aGroupIndexes.IsEmpty() )
1209 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1212 if ( !aGroupsData.IsEmpty() )
1214 GEOM::GEOM_IGroupOperations_var aGroupOp =
1215 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1217 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1218 for ( ; aMapIt.More(); aMapIt.Next() )
1220 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1221 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1223 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1224 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1227 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1228 aGeomIndexes->length( aGroupIndexes.Length() );
1230 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1231 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1233 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1234 if ( aGroupOp->IsDone() )
1236 SALOMEDS::SObject_var aGroupSO =
1237 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1245 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
1246 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
1247 const TopoDS_Shape& theShape, const QString& theName,
1248 QString& theGeomObjEntry ) const
1250 theGeomObjEntry = "";
1251 GEOM::GEOM_Object_var aGeomObj;
1253 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
1254 theShape.IsNull() ) {
1255 return aGeomObj._retn();
1258 std::ostringstream aStreamShape;
1259 // Write TopoDS_Shape in ASCII format to the stream
1260 BRepTools::Write( theShape, aStreamShape );
1261 // Returns the number of bytes that have been stored in the stream's buffer.
1262 int aSize = aStreamShape.str().size();
1263 // Allocate octect buffer of required size
1264 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
1265 // Copy ostrstream content to the octect buffer
1266 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
1268 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
1270 // Restore shape from the stream and get the GEOM object
1271 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
1272 aGeomObj = anInsOp->RestoreShape( aSeqFile );
1274 // Puplish the GEOM object
1275 if ( !aGeomObj->_is_nil() ) {
1276 QString aName = HYDROData_GeomTool::GetFreeName( theStudy, theName );
1278 SALOMEDS::SObject_var aResultSO =
1279 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
1280 aGeomObj, qPrintable( aName ) );
1281 if ( aResultSO->_is_nil() ) {
1282 aGeomObj = GEOM::GEOM_Object::_nil();
1285 theGeomObjEntry = aResultSO->GetID();
1288 return aGeomObj._retn();
1291 void HYDROData_CalculationCase::ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
1292 const bool theIsSetToUpdate )
1294 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1295 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1297 // Indicate model of the need to update splitting
1298 if ( theIsSetToUpdate ) {
1299 SetToUpdate( true );
1303 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Entity)& theObject1,
1304 HYDROData_PriorityType thePriority,
1305 const Handle(HYDROData_Entity)& theObject2,
1306 HYDROData_Zone::MergeType theMergeType,
1307 HYDROData_CalculationCase::DataTag theDataTag )
1309 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1310 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1312 // Indicate model of the need to update splitting
1313 SetToUpdate( true );
1316 QString HYDROData_CalculationCase::DumpRules() const
1318 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1319 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1322 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1324 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1325 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1327 // Indicate model of the need to update splitting
1328 SetToUpdate( true );
1331 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1333 Handle(TDataStd_Integer) aModeAttr;
1334 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1336 return ( AssignmentMode ) aModeAttr->Get();
1341 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1342 QStringList& theScript ) const
1344 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1345 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1348 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1350 return myLastWarning;
1353 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1355 myLastWarning.Type = theType;
1356 myLastWarning.Data = theData;
1359 void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
1360 const QString& theOldCaseName,
1361 const QString& theName )
1363 HYDROData_SequenceOfObjects::Iterator anIter( theRegions );
1364 for ( ; anIter.More(); anIter.Next() )
1366 Handle(HYDROData_Region) aRegion =
1367 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1368 if ( aRegion.IsNull() )
1371 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegion );
1373 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
1374 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
1375 for ( ; anIter.More(); anIter.Next() )
1377 Handle(HYDROData_Zone) aRegZone =
1378 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
1379 if ( aRegZone.IsNull() )
1382 HYDROData_Tool::UpdateChildObjectName( theOldCaseName, theName, aRegZone );
1387 void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList,
1388 MapOfTreatedObjects& theTreatedObjects,
1389 const HYDROData_SequenceOfObjects& theRegions ) const
1391 HYDROData_SequenceOfObjects::Iterator anIter;
1392 anIter.Init( theRegions );
1393 for ( ; anIter.More(); anIter.Next() )
1395 Handle(HYDROData_Region) aRegion =
1396 Handle(HYDROData_Region)::DownCast( anIter.Value() );
1397 if ( aRegion.IsNull() )
1400 theTreatedObjects.insert( aRegion->GetName(), aRegion );
1401 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
1402 theResList << aRegDump;
1406 bool HYDROData_CalculationCase::GetRule( int theIndex,
1407 Handle(HYDROData_Entity)& theObject1,
1408 HYDROData_PriorityType& thePriority,
1409 Handle(HYDROData_Entity)& theObject2,
1410 HYDROData_Zone::MergeType& theMergeType,
1411 HYDROData_CalculationCase::DataTag& theDataTag) const
1413 TDF_Label aRulesLab = myLab.FindChild( theDataTag );
1414 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1415 theObject1, thePriority, theObject2, theMergeType );
1418 void HYDROData_CalculationCase::SetAssignmentLandCoverMode( AssignmentMode theMode )
1420 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentLandCoverMode );
1421 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1423 // Indicate model of the need to update land covers partition
1424 SetToUpdate( true );
1427 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentLandCoverMode() const
1429 Handle(TDataStd_Integer) aModeAttr;
1430 bool isOK = myLab.FindChild( DataTag_AssignmentLandCoverMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1432 return ( AssignmentMode ) aModeAttr->Get();