2 #include "HYDROData_CalculationCase.h"
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_IAltitudeObject.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_ShapesGroup.h"
8 #include "HYDROData_Iterator.h"
9 #include "HYDROData_NaturalObject.h"
10 #include "HYDROData_PolylineXY.h"
11 #include "HYDROData_SplittedShapesGroup.h"
12 #include "HYDROData_Region.h"
13 #include "HYDROData_Tool.h"
20 #include <TopoDS_Shell.hxx>
21 #include <TopoDS_Edge.hxx>
23 #include <BRep_Builder.hxx>
24 #include <BRepBuilderAPI_Sewing.hxx>
25 #include <BRepTopAdaptor_FClass2d.hxx>
27 #include <BRepTools.hxx>
30 #include <TopExp_Explorer.hxx>
32 #include <TopTools_ListOfShape.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
34 #include <TDataStd_Integer.hxx>
36 //#define DEB_CALCULATION 1
37 #ifdef DEB_CALCULATION
38 #include <BRepTools.hxx>
39 #include <TopLoc_Location.hxx>
41 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
42 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
43 #define CALCULATION_GROUPS_PREF GetName() + "_"
44 //#define DEB_CLASS2D 1
46 #include <BRepBuilderAPI_MakeVertex.hxx>
49 #define EXPORT_NAME "HYDRO_" + GetName()
51 #include <SALOME_NamingService.hxx>
52 #include <SALOME_LifeCycleCORBA.hxx>
58 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
59 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
61 HYDROData_CalculationCase::HYDROData_CalculationCase()
66 HYDROData_CalculationCase::~HYDROData_CalculationCase()
70 void HYDROData_CalculationCase::SetName( const QString& theName )
72 QString anOldCaseName = GetName();
73 if ( anOldCaseName != theName )
75 HYDROData_SequenceOfObjects aRegions = GetRegions();
77 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
78 for ( ; anIter.More(); anIter.Next() )
80 Handle(HYDROData_Region) aRegion =
81 Handle(HYDROData_Region)::DownCast( anIter.Value() );
82 if ( aRegion.IsNull() )
85 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
87 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
88 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
89 for ( ; anIter.More(); anIter.Next() )
91 Handle(HYDROData_Zone) aRegZone =
92 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
93 if ( aRegZone.IsNull() )
96 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
100 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
102 anIter.Init( aGroups );
103 for ( ; anIter.More(); anIter.Next() )
105 Handle(HYDROData_SplittedShapesGroup) aGroup =
106 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
107 if ( aGroup.IsNull() )
110 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
114 HYDROData_Entity::SetName( theName );
117 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
119 QStringList aResList = dumpObjectCreation( theTreatedObjects );
120 aResList.prepend( "# Calculation case" );
122 QString aCalculName = GetObjPyName();
124 AssignmentMode aMode = GetAssignmentMode();
125 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
126 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
128 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
129 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
130 for ( ; anIter.More(); anIter.Next() )
132 Handle(HYDROData_Object) aRefGeomObj =
133 Handle(HYDROData_Object)::DownCast( anIter.Value() );
134 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
136 aResList << QString( "" );
138 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
140 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
141 anIter.Init( aGeomGroups );
142 for ( ; anIter.More(); anIter.Next() )
144 Handle(HYDROData_ShapesGroup) aGeomGroup =
145 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
146 if ( aGeomGroup.IsNull() )
149 Handle(HYDROData_Object) aFatherGeom =
150 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
151 if ( aFatherGeom.IsNull() )
154 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
155 aResList << QString( "%1 = %2.GetGroup( %3 );" )
156 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
158 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
161 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
162 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
164 if( aMode==AUTOMATIC )
165 DumpRulesToPython( aCalculName, aResList );
167 aResList << QString( "" );
168 aResList << "# Start the algorithm of the partition and assignment";
169 aResList << QString( "%1.Update();" ).arg( aCalculName );
173 // Now we restore the regions and zones order
174 HYDROData_SequenceOfObjects aRegions = GetRegions();
175 anIter.Init( aRegions );
176 for ( ; anIter.More(); anIter.Next() )
178 Handle(HYDROData_Region) aRegion =
179 Handle(HYDROData_Region)::DownCast( anIter.Value() );
180 if ( aRegion.IsNull() )
183 theTreatedObjects.insert( aRegion->GetName(), aRegion );
184 QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects );
185 aResList << aRegDump;
189 // Export calculation case
190 aResList << QString( "" );
191 aResList << "# Export of the calculation case";
192 QString aStudyName = "theStudy";
193 QString anEntryVar = aCalculName + "_entry";
194 aResList << QString( "%1 = %2.Export( %3._get_StudyId() )" ).arg( anEntryVar ).arg( aCalculName ).arg( aStudyName );
196 // Get geometry object and print debug information
198 aResList << "# Get geometry shape and print debug information";
199 aResList << "import GEOM";
200 aResList << QString( "print \"Entry:\", %1" ).arg( anEntryVar );
201 QString aGeomShapeName = aCalculName + "_geom";
202 aResList << QString( "%1 = salome.IDToObject( str( %2 ) )" ).arg( aGeomShapeName ).arg( anEntryVar );
203 aResList << QString( "print \"Geom shape:\", %1" ).arg( aGeomShapeName );
204 aResList << QString( "print \"Geom shape name:\", %1.GetName()" ).arg( aGeomShapeName );
206 DumpSampleMeshing( aResList, aStudyName, aGeomShapeName, aCalculName+"_mesh" );
208 aResList << QString( "" );
212 void HYDROData_CalculationCase::DumpSampleMeshing( QStringList& theResList,
213 const QString& theStudyName,
214 const QString& theGeomShapeName,
215 const QString& theMeshName ) const
218 theResList << "# Meshing";
219 theResList << "import SMESH, SALOMEDS";
220 theResList << "from salome.smesh import smeshBuilder";
222 theResList << QString( "smesh = smeshBuilder.New( %1 )" ).arg( theStudyName );
223 theResList << QString( "%1 = smesh.Mesh( %2 )" ).arg( theMeshName ).arg( theGeomShapeName );
224 theResList << QString( "MEFISTO_2D = %1.Triangle( algo=smeshBuilder.MEFISTO )" ).arg( theMeshName );
225 theResList << "Max_Element_Area_1 = MEFISTO_2D.MaxElementArea( 10 )";
226 theResList << QString( "Regular_1D = %1.Segment()" ).arg( theMeshName );
227 theResList << "Max_Size_1 = Regular_1D.MaxSize(10)";
228 theResList << QString( "isDone = %1.Compute()" ).arg( theMeshName );
231 theResList << "# Set names of Mesh objects";
232 theResList << "smesh.SetName( MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D' )";
233 theResList << "smesh.SetName( Regular_1D.GetAlgorithm(), 'Regular_1D' )";
234 theResList << "smesh.SetName( Max_Size_1, 'Max Size_1' )";
235 theResList << "smesh.SetName( Max_Element_Area_1, 'Max. Element Area_1' )";
236 theResList << QString( "smesh.SetName( %1.GetMesh(), '%1' )" ).arg( theMeshName );
239 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
241 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
243 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
244 if ( !aBoundaryPolyline.IsNull() )
245 aResSeq.Append( aBoundaryPolyline );
247 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
248 aResSeq.Append( aSeqOfRegions );
253 void HYDROData_CalculationCase::Update()
255 HYDROData_Entity::Update();
258 // At first we remove previously created objects
260 RemoveSplittedGroups();
262 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
263 if ( aDocument.IsNull() )
266 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
267 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
268 if ( aGeomObjects.IsEmpty() )
271 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
273 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
274 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
275 if ( aSplitObjects.isEmpty() )
278 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
280 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
281 while( anIter.hasNext() )
283 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
284 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
285 aZonesList.append( aSplitData );
286 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
287 anEdgesList.append( aSplitData );
290 switch( GetAssignmentMode() )
293 CreateRegionsDef( aDocument, aZonesList );
296 CreateRegionsAuto( aDocument, aZonesList );
299 CreateEdgeGroupsDef( aDocument, anEdgesList );
302 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
303 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
305 // Create result regions for case, by default one zone for one region
306 QString aRegsPref = CALCULATION_REGIONS_PREF;
307 QString aZonesPref = CALCULATION_ZONES_PREF;
309 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
310 while( anIter.hasNext() )
312 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
314 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
316 // Add the zone for region
317 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
321 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
322 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
324 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
325 QMap<QString, QString> aRegionNameToObjNameMap;
326 QString aZonesPref = CALCULATION_ZONES_PREF;
327 HYDROData_PriorityQueue aPr( this );
329 // 1. First we create a default region for each object included into the calculation case
330 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
331 for( int i=aGeomObjects.Lower(), n=aGeomObjects.Upper(); i<=n; i++ )
333 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( aGeomObjects.Value( i ) );
336 QString anObjName = anObj->GetName();
337 QString aRegName = anObjName + "_reg";
338 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
339 aRegionsMap.insert( anObjName, aRegion );
340 aRegionNameToObjNameMap.insert( aRegName, anObjName );
343 // 2. Now for each zone it is necessary to determine the most priority object
344 // and assign to zone to corresponding region
345 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
346 while( anIter.hasNext() )
348 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
349 HYDROData_Zone::MergeAltitudesType aMergeType;
350 Handle(HYDROData_Object) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
351 if( aRegObj.IsNull() )
353 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
354 if( aRegion.IsNull() )
356 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
358 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
360 qDebug( "Error in algorithm: unresolved conflicts" );
365 case HYDROData_Zone::Merge_ZMIN:
366 case HYDROData_Zone::Merge_ZMAX:
367 aRegionZone->SetMergeType( aMergeType );
369 case HYDROData_Zone::Merge_Object:
370 aRegionZone->SetMergeType( aMergeType );
371 aRegionZone->RemoveMergeAltitude();
372 aRegionZone->SetMergeAltitude( aRegObj->GetAltitudeObject() );
377 QStringList anObjectsWithEmptyRegions;
378 QMap<QString, Handle(HYDROData_Region)>::const_iterator
379 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
380 for( ; anIt!=aLast; anIt++ )
382 Handle(HYDROData_Region) aRegion = anIt.value();
383 if( aRegion->GetZones().IsEmpty() )
385 QString aRegName = aRegion->GetName();
386 QString anObjName = aRegionNameToObjNameMap[aRegName];
387 anObjectsWithEmptyRegions.append( anObjName );
391 if( !anObjectsWithEmptyRegions.empty() )
393 QString aData = anObjectsWithEmptyRegions.join( ", " );
394 SetWarning( WARN_EMPTY_REGIONS, aData );
398 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
399 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
401 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
403 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
404 while( anIter.hasNext() )
406 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
407 // Create new edges group
408 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
411 QString anObjName = aSplitData.ObjectNames.first();
412 if ( anObjName.isEmpty() )
414 #ifdef DEB_CALCULATION
415 QString aStr = aSplitData.ObjectNames.join(" ");
416 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
418 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
419 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
421 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
422 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
426 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
428 if ( aSplittedGroup.IsNull() )
431 aSplittedGroup->AddShape( aSplitData.Shape );
435 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
437 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
438 return false; // Wrong type of object
440 if ( HasReference( theObject, DataTag_GeometryObject ) )
441 return false; // Object is already in reference list
443 AddReferenceObject( theObject, DataTag_GeometryObject );
445 // Indicate model of the need to update splitting
451 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
453 return GetReferenceObjects( DataTag_GeometryObject );
456 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
458 if ( theObject.IsNull() )
461 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
463 // Indicate model of the need to update splitting
467 void HYDROData_CalculationCase::RemoveGeometryObjects()
469 ClearReferenceObjects( DataTag_GeometryObject );
471 // Indicate model of the need to update splitting
475 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
477 if ( theGroup.IsNull() )
480 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
481 return false; // Object is already in reference list
483 AddReferenceObject( theGroup, DataTag_GeometryGroup );
485 // Indicate model of the need to update splitting
491 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
493 return GetReferenceObjects( DataTag_GeometryGroup );
496 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
498 if ( theGroup.IsNull() )
501 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
503 // Indicate model of the need to update splitting
507 void HYDROData_CalculationCase::RemoveGeometryGroups()
509 ClearReferenceObjects( DataTag_GeometryGroup );
511 // Indicate model of the need to update splitting
515 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
517 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
519 SetReferenceObject( thePolyline, DataTag_Polyline );
521 // Indicate model of the need to update zones splitting
522 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
525 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
527 return Handle(HYDROData_PolylineXY)::DownCast(
528 GetReferenceObject( DataTag_Polyline ) );
531 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
533 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
535 ClearReferenceObjects( DataTag_Polyline );
537 // Indicate model of the need to update zones splitting
538 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
541 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
543 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
544 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
545 if ( aNewRegion.IsNull() )
548 aNewRegion->AddZone( theZone );
553 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
555 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
557 if ( theRegion.IsNull() )
560 if ( HasReference( theRegion, DataTag_Region ) )
561 return false; // Object is already in reference list
563 // Move the region from other calculation
564 Handle(HYDROData_CalculationCase) aFatherCalc =
565 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
566 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
568 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
569 theRegion->CopyTo( aNewRegion );
571 aFatherCalc->RemoveRegion( theRegion );
573 theRegion->SetLabel( aNewRegion->Label() );
577 AddReferenceObject( theRegion, DataTag_Region );
583 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
585 return GetReferenceObjects( DataTag_Region );
588 void HYDROData_CalculationCase::UpdateRegionsOrder()
590 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
591 if ( aDocument.IsNull() )
594 HYDROData_SequenceOfObjects aRegions = GetRegions();
596 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
597 for ( ; anIter.More(); anIter.Next() )
599 Handle(HYDROData_Region) aRegion =
600 Handle(HYDROData_Region)::DownCast( anIter.Value() );
601 if ( aRegion.IsNull() )
604 aRegion->SetName( "" );
607 QString aRegsPref = CALCULATION_REGIONS_PREF;
609 anIter.Init( aRegions );
610 for ( ; anIter.More(); anIter.Next() )
612 Handle(HYDROData_Region) aRegion =
613 Handle(HYDROData_Region)::DownCast( anIter.Value() );
614 if ( aRegion.IsNull() )
617 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
618 aRegion->SetName( aRegionName );
622 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
624 if ( theRegion.IsNull() )
627 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
629 // Remove region from data model
630 Handle(HYDROData_CalculationCase) aFatherCalc =
631 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
632 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
636 void HYDROData_CalculationCase::RemoveRegions()
638 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
641 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
643 return GetReferenceObjects( DataTag_SplittedGroups );
646 void HYDROData_CalculationCase::RemoveSplittedGroups()
648 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
651 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
653 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
654 return GetAltitudeForPoint( thePoint, aZone );
657 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
658 const Handle(HYDROData_Region)& theRegion ) const
660 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
662 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
663 if ( !aZone.IsNull() )
665 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
666 if ( IsEqual( aRefRegion, theRegion ) )
667 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
673 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
674 const Handle(HYDROData_Zone)& theZone ) const
676 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
677 if ( theZone.IsNull() )
680 HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
681 if ( !theZone->IsMergingNeed() )
683 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
685 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
690 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
691 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
693 Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
694 if ( !aMergeAltitude.IsNull() )
696 if ( aZoneInterpolator != NULL )
698 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
699 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
702 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
707 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
708 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
709 for ( ; anIter.More(); anIter.Next() )
711 Handle(HYDROData_Object) aZoneObj =
712 Handle(HYDROData_Object)::DownCast( anIter.Value() );
713 if ( aZoneObj.IsNull() )
716 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
717 if ( anObjAltitude.IsNull() )
720 double aPointAltitude = 0.0;
721 if ( aZoneInterpolator != NULL )
723 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
724 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
727 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
729 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
732 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
734 aResAltitude = aPointAltitude;
737 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
739 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
740 aResAltitude > aPointAltitude )
742 aResAltitude = aPointAltitude;
745 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
747 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
748 aResAltitude < aPointAltitude )
750 aResAltitude = aPointAltitude;
759 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
760 const NCollection_Sequence<gp_XY>& thePoints,
761 const Handle(HYDROData_Region)& theRegion ) const
763 NCollection_Sequence<double> aResSeq;
765 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
767 const gp_XY& thePnt = thePoints.Value( i );
769 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
770 aResSeq.Append( anAltitude );
776 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
777 const NCollection_Sequence<gp_XY>& thePoints,
778 const Handle(HYDROData_Zone)& theZone ) const
780 NCollection_Sequence<double> aResSeq;
782 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
784 const gp_XY& thePnt = thePoints.Value( i );
786 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
787 aResSeq.Append( anAltitude );
793 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
795 Handle(HYDROData_Region) aResRegion;
797 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
798 if ( !aZone.IsNull() )
799 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
804 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
806 Handle(HYDROData_Zone) aResZone;
808 HYDROData_SequenceOfObjects aRegions = GetRegions();
810 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
811 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
813 Handle(HYDROData_Region) aRegion =
814 Handle(HYDROData_Region)::DownCast( anIter.Value() );
815 if ( aRegion.IsNull() )
818 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
819 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
820 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
822 Handle(HYDROData_Zone) aRegZone =
823 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
824 if ( aRegZone.IsNull() )
827 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
828 if ( aPointRelation != POINT_OUT )
829 aResZone = aRegZone; // We found the desired zone
836 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
837 const gp_XY& thePoint,
838 const Handle(HYDROData_Zone)& theZone ) const
840 PointClassification aRes = POINT_OUT;
841 if ( theZone.IsNull() )
844 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
845 if ( aZoneFace.IsNull() )
848 TopoDS_Compound aCmp;
850 aBB.MakeCompound(aCmp);
851 aBB.Add(aCmp, aZoneFace);
852 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
853 BRepBuilderAPI_MakeVertex aMk(aPnt);
854 aBB.Add(aCmp, aMk.Vertex());
855 BRepTools::Write(aCmp, "FCL2d.brep");
857 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
858 if (State == TopAbs_OUT)
860 else if(State == TopAbs_IN)
862 else if(State == TopAbs_ON)
867 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
868 const QString& thePrefixOrName,
871 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
872 int aTag = aNewLab.Tag();
874 Handle(HYDROData_Region) aNewRegion =
875 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
876 AddRegion( aNewRegion );
878 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
879 aNewRegion->SetName( aRegionName );
884 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
886 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
888 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
889 Handle(HYDROData_SplittedShapesGroup)::DownCast(
890 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
891 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
893 aNewGroup->SetName( theName );
898 QString HYDROData_CalculationCase::Export( int theStudyId ) const
902 CORBA::ORB_var anORB = CORBA::ORB_init( argc, argv, "omniORB4"/*CORBA::ORB_ID*/ );
903 SALOME_NamingService aNameService( anORB );
904 SALOME_LifeCycleCORBA aLCC( &aNameService );
905 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component( "FactoryServer", "GEOM" );
906 GEOM::GEOM_Gen_var aGEOMEngine = GEOM::GEOM_Gen::_narrow( aComponent );
908 CORBA::Object_var aSMObject = aNameService.Resolve("/myStudyManager");
909 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
910 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( theStudyId );
912 QString aGeomObjEntry;
913 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry );
914 return isOK ? aGeomObjEntry : QString();
917 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
918 SALOMEDS::Study_ptr theStudy,
919 QString& theGeomObjEntry ) const
921 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
923 // Get groups definitions
924 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
926 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
927 for ( ; anIter.More(); anIter.Next() )
930 Handle(HYDROData_ShapesGroup) aGroup =
931 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
932 if ( aGroup.IsNull() )
935 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
937 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
938 aGroup->GetShapes( aGroupDef.Shapes );
940 aSeqOfGroupsDefs.Append( aGroupDef );
944 TopTools_ListOfShape aFaces;
945 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
946 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
947 for ( ; aRegionIter.More(); aRegionIter.Next() )
949 Handle(HYDROData_Region) aRegion =
950 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
951 if( aRegion.IsNull() )
954 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
955 aFaces.Append( aRegionShape );
958 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );
961 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
962 SALOMEDS::Study_ptr theStudy,
963 const TopTools_ListOfShape& theFaces,
964 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
965 QString& theGeomObjEntry ) const
968 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
969 aSewing.SetNonManifoldMode( Standard_False );
970 #ifdef DEB_CALCULATION
971 TCollection_AsciiString aNam("Sh_");
974 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
975 for ( ; aFaceIter.More(); aFaceIter.Next() )
977 TopoDS_Shape aShape = aFaceIter.Value();
978 if ( aShape.IsNull() )
981 if ( aShape.ShapeType() == TopAbs_FACE )
983 aSewing.Add( aShape );
984 #ifdef DEB_CALCULATION
985 TCollection_AsciiString aName = aNam + ++i + ".brep";
986 BRepTools::Write(aShape ,aName.ToCString());
991 #ifdef DEB_CALCULATION
994 TopExp_Explorer anExp( aShape, TopAbs_FACE );
995 for (; anExp.More(); anExp.Next() ) {
996 aSewing.Add( anExp.Current() );
997 #ifdef DEB_CALCULATION
999 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
1000 BRepTools::Write(anExp.Current() ,aName.ToCString());
1007 TopoDS_Shape aSewedShape = aSewing.SewedShape();
1009 // If the sewed shape is empty - return false
1010 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
1013 #ifdef DEB_CALCULATION
1014 BRepTools::Write(aSewedShape ,"Sew.brep");
1016 // Publish the sewed shape
1017 QString aName = EXPORT_NAME;
1018 GEOM::GEOM_Object_ptr aMainShape =
1019 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
1021 if ( aMainShape->_is_nil() )
1024 if ( theGroupsDefs.IsEmpty() )
1028 TopTools_IndexedMapOfShape aMapOfSubShapes;
1029 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
1031 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
1033 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
1035 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1037 NCollection_Sequence<int> aGroupIndexes;
1038 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1040 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1041 #ifdef DEB_CALCULATION
1042 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1045 TopoDS_Shape aModifiedShape = aShape;
1046 if ( aSewing.IsModified( aShape ) )
1047 aModifiedShape = aSewing.Modified( aShape );
1048 else if ( aSewing.IsModifiedSubShape( aShape ) )
1049 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1051 #ifdef DEB_CALCULATION
1052 const TopLoc_Location& aL1 = aShape.Location();
1053 const TopLoc_Location& aL2 = aModifiedShape.Location();
1054 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1057 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1058 if ( anIndex > 0 ) {
1059 aGroupIndexes.Append( anIndex );
1061 #ifdef DEB_CALCULATION
1062 TCollection_AsciiString aNam("Lost_");
1063 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1064 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1066 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1067 if ( aModifiedShape.IsPartner( aS ) )
1069 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1070 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1071 BRepTools::Write(aS ,aName.ToCString());
1079 if ( !aGroupIndexes.IsEmpty() )
1080 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1083 if ( !aGroupsData.IsEmpty() )
1085 GEOM::GEOM_IGroupOperations_var aGroupOp =
1086 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1088 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1089 for ( ; aMapIt.More(); aMapIt.Next() )
1091 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1092 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1094 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1095 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1098 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1099 aGeomIndexes->length( aGroupIndexes.Length() );
1101 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1102 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1104 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1105 if ( aGroupOp->IsDone() )
1107 SALOMEDS::SObject_var aGroupSO =
1108 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1116 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
1117 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
1118 const TopoDS_Shape& theShape, const QString& theName,
1119 QString& theGeomObjEntry ) const
1121 theGeomObjEntry = "";
1122 GEOM::GEOM_Object_var aGeomObj;
1124 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
1125 theShape.IsNull() ) {
1126 return aGeomObj._retn();
1129 std::ostringstream aStreamShape;
1130 // Write TopoDS_Shape in ASCII format to the stream
1131 BRepTools::Write( theShape, aStreamShape );
1132 // Returns the number of bytes that have been stored in the stream's buffer.
1133 int aSize = aStreamShape.str().size();
1134 // Allocate octect buffer of required size
1135 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
1136 // Copy ostrstream content to the octect buffer
1137 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
1139 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
1141 // Restore shape from the stream and get the GEOM object
1142 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
1143 aGeomObj = anInsOp->RestoreShape( aSeqFile );
1145 // Puplish the GEOM object
1146 if ( !aGeomObj->_is_nil() ) {
1147 QString aName = GEOMBase::GetDefaultName( theName );
1149 SALOMEDS::SObject_var aResultSO =
1150 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
1151 aGeomObj, qPrintable( aName ) );
1152 if ( aResultSO->_is_nil() ) {
1153 aGeomObj = GEOM::GEOM_Object::_nil();
1156 theGeomObjEntry = aResultSO->GetID();
1159 return aGeomObj._retn();
1162 void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate )
1164 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1165 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1167 // Indicate model of the need to update splitting
1168 if ( theIsSetToUpdate ) {
1169 SetToUpdate( true );
1173 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)& theObject1,
1174 HYDROData_PriorityType thePriority,
1175 const Handle(HYDROData_Object)& theObject2,
1176 HYDROData_Zone::MergeAltitudesType theMergeType )
1178 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1179 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1181 // Indicate model of the need to update splitting
1182 SetToUpdate( true );
1185 QString HYDROData_CalculationCase::DumpRules() const
1187 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1188 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1191 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1193 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1194 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1196 // Indicate model of the need to update splitting
1197 SetToUpdate( true );
1200 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1202 Handle(TDataStd_Integer) aModeAttr;
1203 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1205 return ( AssignmentMode ) aModeAttr->Get();
1210 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1211 QStringList& theScript ) const
1213 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1214 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1217 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1219 return myLastWarning;
1222 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1224 myLastWarning.Type = theType;
1225 myLastWarning.Data = theData;
1228 bool HYDROData_CalculationCase::GetRule( int theIndex,
1229 Handle(HYDROData_Object)& theObject1,
1230 HYDROData_PriorityType& thePriority,
1231 Handle(HYDROData_Object)& theObject2,
1232 HYDROData_Zone::MergeAltitudesType& theMergeType ) const
1234 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1235 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1236 theObject1, thePriority, theObject2, theMergeType );