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 );
121 QString aCalculName = GetObjPyName();
123 AssignmentMode aMode = GetAssignmentMode();
124 QString aModeStr = aMode==MANUAL ? "HYDROData_CalculationCase.MANUAL" : "HYDROData_CalculationCase.AUTOMATIC";
125 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
127 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
128 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
129 for ( ; anIter.More(); anIter.Next() )
131 Handle(HYDROData_Object) aRefGeomObj =
132 Handle(HYDROData_Object)::DownCast( anIter.Value() );
133 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
135 aResList << QString( "" );
137 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
139 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
140 anIter.Init( aGeomGroups );
141 for ( ; anIter.More(); anIter.Next() )
143 Handle(HYDROData_ShapesGroup) aGeomGroup =
144 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
145 if ( aGeomGroup.IsNull() )
148 Handle(HYDROData_Object) aFatherGeom =
149 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
150 if ( aFatherGeom.IsNull() )
153 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
154 aResList << QString( "%1 = %2.GetGroup( %3 );" )
155 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
157 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
159 aResList << QString( "" );
161 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
162 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
163 aResList << QString( "" );
165 if( aMode==AUTOMATIC )
166 DumpRulesToPython( aCalculName, aResList );
168 aResList << QString( "" );
169 aResList << QString( "%1.Update();" ).arg( aCalculName );
170 aResList << QString( "" );
174 // Now we restore the regions and zones order
175 HYDROData_SequenceOfObjects aRegions = GetRegions();
176 anIter.Init( aRegions );
177 for ( ; anIter.More(); anIter.Next() )
179 Handle(HYDROData_Region) aRegion =
180 Handle(HYDROData_Region)::DownCast( anIter.Value() );
181 if ( aRegion.IsNull() )
184 QString aRegionName = aRegion->GetName();
186 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
187 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
188 for ( ; aZonesIter.More(); aZonesIter.Next() )
190 Handle(HYDROData_Zone) aRegZone =
191 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
192 if ( aRegZone.IsNull() )
200 aResList << QString( "" );
204 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
206 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
208 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
209 if ( !aBoundaryPolyline.IsNull() )
210 aResSeq.Append( aBoundaryPolyline );
212 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
213 aResSeq.Append( aSeqOfRegions );
218 void HYDROData_CalculationCase::Update()
220 HYDROData_Entity::Update();
223 // At first we remove previously created objects
225 RemoveSplittedGroups();
227 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
228 if ( aDocument.IsNull() )
231 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
232 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
233 if ( aGeomObjects.IsEmpty() )
236 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
238 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
239 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
240 if ( aSplitObjects.isEmpty() )
243 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
245 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
246 while( anIter.hasNext() )
248 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
249 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
250 aZonesList.append( aSplitData );
251 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
252 anEdgesList.append( aSplitData );
255 switch( GetAssignmentMode() )
258 CreateRegionsDef( aDocument, aZonesList );
261 CreateRegionsAuto( aDocument, aZonesList );
264 CreateEdgeGroupsDef( aDocument, anEdgesList );
267 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
268 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
270 // Create result regions for case, by default one zone for one region
271 QString aRegsPref = CALCULATION_REGIONS_PREF;
272 QString aZonesPref = CALCULATION_ZONES_PREF;
274 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
275 while( anIter.hasNext() )
277 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
279 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
281 // Add the zone for region
282 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
286 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
287 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
289 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
290 QMap<QString, QString> aRegionNameToObjNameMap;
291 QString aZonesPref = CALCULATION_ZONES_PREF;
292 HYDROData_PriorityQueue aPr( this );
294 // 1. First we create a default region for each object included into the calculation case
295 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
296 for( int i=aGeomObjects.Lower(), n=aGeomObjects.Upper(); i<=n; i++ )
298 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( aGeomObjects.Value( i ) );
301 QString anObjName = anObj->GetName();
302 QString aRegName = anObjName + "_reg";
303 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
304 aRegionsMap.insert( anObjName, aRegion );
305 aRegionNameToObjNameMap.insert( aRegName, anObjName );
308 // 2. Now for each zone it is necessary to determine the most priority object
309 // and assign to zone to corresponding region
310 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
311 while( anIter.hasNext() )
313 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
314 HYDROData_Zone::MergeAltitudesType aMergeType;
315 Handle(HYDROData_Object) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
316 if( aRegObj.IsNull() )
318 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
319 if( aRegion.IsNull() )
321 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
323 if( aSplitData.ObjectNames.count() > 1 && aMergeType==HYDROData_Zone::Merge_UNKNOWN )
325 qDebug( "Error in algorithm: unresolved conflicts" );
330 case HYDROData_Zone::Merge_ZMIN:
331 case HYDROData_Zone::Merge_ZMAX:
332 aRegionZone->SetMergeType( aMergeType );
334 case HYDROData_Zone::Merge_Object:
335 aRegionZone->SetMergeType( aMergeType );
336 aRegionZone->RemoveMergeAltitude();
337 aRegionZone->SetMergeAltitude( aRegObj->GetAltitudeObject() );
342 QStringList anObjectsWithEmptyRegions;
343 QMap<QString, Handle(HYDROData_Region)>::const_iterator
344 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
345 for( ; anIt!=aLast; anIt++ )
347 Handle(HYDROData_Region) aRegion = anIt.value();
348 if( aRegion->GetZones().IsEmpty() )
350 QString aRegName = aRegion->GetName();
351 QString anObjName = aRegionNameToObjNameMap[aRegName];
352 anObjectsWithEmptyRegions.append( anObjName );
356 if( !anObjectsWithEmptyRegions.empty() )
358 QString aData = anObjectsWithEmptyRegions.join( ", " );
359 SetWarning( WARN_EMPTY_REGIONS, aData );
363 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
364 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
366 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
368 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
369 while( anIter.hasNext() )
371 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
372 // Create new edges group
373 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
376 QString anObjName = aSplitData.ObjectNames.first();
377 if ( anObjName.isEmpty() )
379 #ifdef DEB_CALCULATION
380 QString aStr = aSplitData.ObjectNames.join(" ");
381 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
383 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
384 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
386 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
387 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
391 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
393 if ( aSplittedGroup.IsNull() )
396 aSplittedGroup->AddShape( aSplitData.Shape );
400 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
402 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
403 return false; // Wrong type of object
405 if ( HasReference( theObject, DataTag_GeometryObject ) )
406 return false; // Object is already in reference list
408 AddReferenceObject( theObject, DataTag_GeometryObject );
410 // Indicate model of the need to update splitting
416 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
418 return GetReferenceObjects( DataTag_GeometryObject );
421 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
423 if ( theObject.IsNull() )
426 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
428 // Indicate model of the need to update splitting
432 void HYDROData_CalculationCase::RemoveGeometryObjects()
434 ClearReferenceObjects( DataTag_GeometryObject );
436 // Indicate model of the need to update splitting
440 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
442 if ( theGroup.IsNull() )
445 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
446 return false; // Object is already in reference list
448 AddReferenceObject( theGroup, DataTag_GeometryGroup );
450 // Indicate model of the need to update splitting
456 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
458 return GetReferenceObjects( DataTag_GeometryGroup );
461 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
463 if ( theGroup.IsNull() )
466 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
468 // Indicate model of the need to update splitting
472 void HYDROData_CalculationCase::RemoveGeometryGroups()
474 ClearReferenceObjects( DataTag_GeometryGroup );
476 // Indicate model of the need to update splitting
480 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
482 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
484 SetReferenceObject( thePolyline, DataTag_Polyline );
486 // Indicate model of the need to update zones splitting
487 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
490 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
492 return Handle(HYDROData_PolylineXY)::DownCast(
493 GetReferenceObject( DataTag_Polyline ) );
496 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
498 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
500 ClearReferenceObjects( DataTag_Polyline );
502 // Indicate model of the need to update zones splitting
503 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
506 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
508 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
509 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
510 if ( aNewRegion.IsNull() )
513 aNewRegion->AddZone( theZone );
518 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
520 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
522 if ( theRegion.IsNull() )
525 if ( HasReference( theRegion, DataTag_Region ) )
526 return false; // Object is already in reference list
528 // Move the region from other calculation
529 Handle(HYDROData_CalculationCase) aFatherCalc =
530 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
531 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
533 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
534 theRegion->CopyTo( aNewRegion );
536 aFatherCalc->RemoveRegion( theRegion );
538 theRegion->SetLabel( aNewRegion->Label() );
542 AddReferenceObject( theRegion, DataTag_Region );
548 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
550 return GetReferenceObjects( DataTag_Region );
553 void HYDROData_CalculationCase::UpdateRegionsOrder()
555 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
556 if ( aDocument.IsNull() )
559 HYDROData_SequenceOfObjects aRegions = GetRegions();
561 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
562 for ( ; anIter.More(); anIter.Next() )
564 Handle(HYDROData_Region) aRegion =
565 Handle(HYDROData_Region)::DownCast( anIter.Value() );
566 if ( aRegion.IsNull() )
569 aRegion->SetName( "" );
572 QString aRegsPref = CALCULATION_REGIONS_PREF;
574 anIter.Init( aRegions );
575 for ( ; anIter.More(); anIter.Next() )
577 Handle(HYDROData_Region) aRegion =
578 Handle(HYDROData_Region)::DownCast( anIter.Value() );
579 if ( aRegion.IsNull() )
582 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
583 aRegion->SetName( aRegionName );
587 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
589 if ( theRegion.IsNull() )
592 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
594 // Remove region from data model
595 Handle(HYDROData_CalculationCase) aFatherCalc =
596 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
597 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
601 void HYDROData_CalculationCase::RemoveRegions()
603 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
606 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
608 return GetReferenceObjects( DataTag_SplittedGroups );
611 void HYDROData_CalculationCase::RemoveSplittedGroups()
613 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
616 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
618 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
619 return GetAltitudeForPoint( thePoint, aZone );
622 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
623 const Handle(HYDROData_Region)& theRegion ) const
625 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
627 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
628 if ( !aZone.IsNull() )
630 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
631 if ( IsEqual( aRefRegion, theRegion ) )
632 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
638 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
639 const Handle(HYDROData_Zone)& theZone ) const
641 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
642 if ( theZone.IsNull() )
645 HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
646 if ( !theZone->IsMergingNeed() )
648 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
650 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
655 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
656 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
658 Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
659 if ( !aMergeAltitude.IsNull() )
661 if ( aZoneInterpolator != NULL )
663 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
664 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
667 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
672 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
673 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
674 for ( ; anIter.More(); anIter.Next() )
676 Handle(HYDROData_Object) aZoneObj =
677 Handle(HYDROData_Object)::DownCast( anIter.Value() );
678 if ( aZoneObj.IsNull() )
681 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
682 if ( anObjAltitude.IsNull() )
685 double aPointAltitude = 0.0;
686 if ( aZoneInterpolator != NULL )
688 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
689 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
692 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
694 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
697 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
699 aResAltitude = aPointAltitude;
702 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
704 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
705 aResAltitude > aPointAltitude )
707 aResAltitude = aPointAltitude;
710 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
712 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
713 aResAltitude < aPointAltitude )
715 aResAltitude = aPointAltitude;
724 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
725 const NCollection_Sequence<gp_XY>& thePoints,
726 const Handle(HYDROData_Region)& theRegion ) const
728 NCollection_Sequence<double> aResSeq;
730 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
732 const gp_XY& thePnt = thePoints.Value( i );
734 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
735 aResSeq.Append( anAltitude );
741 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
742 const NCollection_Sequence<gp_XY>& thePoints,
743 const Handle(HYDROData_Zone)& theZone ) const
745 NCollection_Sequence<double> aResSeq;
747 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
749 const gp_XY& thePnt = thePoints.Value( i );
751 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
752 aResSeq.Append( anAltitude );
758 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
760 Handle(HYDROData_Region) aResRegion;
762 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
763 if ( !aZone.IsNull() )
764 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
769 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
771 Handle(HYDROData_Zone) aResZone;
773 HYDROData_SequenceOfObjects aRegions = GetRegions();
775 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
776 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
778 Handle(HYDROData_Region) aRegion =
779 Handle(HYDROData_Region)::DownCast( anIter.Value() );
780 if ( aRegion.IsNull() )
783 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
784 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
785 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
787 Handle(HYDROData_Zone) aRegZone =
788 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
789 if ( aRegZone.IsNull() )
792 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
793 if ( aPointRelation != POINT_OUT )
794 aResZone = aRegZone; // We found the desired zone
801 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
802 const gp_XY& thePoint,
803 const Handle(HYDROData_Zone)& theZone ) const
805 PointClassification aRes = POINT_OUT;
806 if ( theZone.IsNull() )
809 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
810 if ( aZoneFace.IsNull() )
813 TopoDS_Compound aCmp;
815 aBB.MakeCompound(aCmp);
816 aBB.Add(aCmp, aZoneFace);
817 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
818 BRepBuilderAPI_MakeVertex aMk(aPnt);
819 aBB.Add(aCmp, aMk.Vertex());
820 BRepTools::Write(aCmp, "FCL2d.brep");
822 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
823 if (State == TopAbs_OUT)
825 else if(State == TopAbs_IN)
827 else if(State == TopAbs_ON)
832 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
833 const QString& thePrefixOrName,
836 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
838 Handle(HYDROData_Region) aNewRegion =
839 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
840 AddRegion( aNewRegion );
842 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
843 aNewRegion->SetName( aRegionName );
848 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
850 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
852 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
853 Handle(HYDROData_SplittedShapesGroup)::DownCast(
854 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
855 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
857 aNewGroup->SetName( theName );
862 QString HYDROData_CalculationCase::Export( int theStudyId ) const
866 CORBA::ORB_var anORB = CORBA::ORB_init( argc, argv, "omniORB4"/*CORBA::ORB_ID*/ );
867 SALOME_NamingService aNameService( anORB );
868 SALOME_LifeCycleCORBA aLCC( &aNameService );
869 Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component( "FactoryServer", "GEOM" );
870 GEOM::GEOM_Gen_var aGEOMEngine = GEOM::GEOM_Gen::_narrow( aComponent );
872 CORBA::Object_var aSMObject = aNameService.Resolve("/myStudyManager");
873 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
874 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID( theStudyId );
876 QString aGeomObjEntry;
877 bool isOK = Export( aGEOMEngine, aDSStudy, aGeomObjEntry );
878 return isOK ? aGeomObjEntry : QString();
881 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
882 SALOMEDS::Study_ptr theStudy,
883 QString& theGeomObjEntry ) const
885 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
887 // Get groups definitions
888 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
890 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
891 for ( ; anIter.More(); anIter.Next() )
894 Handle(HYDROData_ShapesGroup) aGroup =
895 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
896 if ( aGroup.IsNull() )
899 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
901 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
902 aGroup->GetShapes( aGroupDef.Shapes );
904 aSeqOfGroupsDefs.Append( aGroupDef );
908 TopTools_ListOfShape aFaces;
909 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
910 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
911 for ( ; aRegionIter.More(); aRegionIter.Next() )
913 Handle(HYDROData_Region) aRegion =
914 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
915 if( aRegion.IsNull() )
918 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
919 aFaces.Append( aRegionShape );
922 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs, theGeomObjEntry );
925 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
926 SALOMEDS::Study_ptr theStudy,
927 const TopTools_ListOfShape& theFaces,
928 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
929 QString& theGeomObjEntry ) const
932 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
933 aSewing.SetNonManifoldMode( Standard_False );
934 #ifdef DEB_CALCULATION
935 TCollection_AsciiString aNam("Sh_");
938 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
939 for ( ; aFaceIter.More(); aFaceIter.Next() )
941 TopoDS_Shape aShape = aFaceIter.Value();
942 if ( aShape.IsNull() )
945 if ( aShape.ShapeType() == TopAbs_FACE )
947 aSewing.Add( aShape );
948 #ifdef DEB_CALCULATION
949 TCollection_AsciiString aName = aNam + ++i + ".brep";
950 BRepTools::Write(aShape ,aName.ToCString());
955 #ifdef DEB_CALCULATION
958 TopExp_Explorer anExp( aShape, TopAbs_FACE );
959 for (; anExp.More(); anExp.Next() ) {
960 aSewing.Add( anExp.Current() );
961 #ifdef DEB_CALCULATION
963 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
964 BRepTools::Write(anExp.Current() ,aName.ToCString());
971 TopoDS_Shape aSewedShape = aSewing.SewedShape();
973 // If the sewed shape is empty - return false
974 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
977 #ifdef DEB_CALCULATION
978 BRepTools::Write(aSewedShape ,"Sew.brep");
980 // Publish the sewed shape
981 QString aName = EXPORT_NAME;
982 GEOM::GEOM_Object_ptr aMainShape =
983 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName, theGeomObjEntry );
985 if ( aMainShape->_is_nil() )
988 if ( theGroupsDefs.IsEmpty() )
992 TopTools_IndexedMapOfShape aMapOfSubShapes;
993 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
995 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
997 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
999 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
1001 NCollection_Sequence<int> aGroupIndexes;
1002 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
1004 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
1005 #ifdef DEB_CALCULATION
1006 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
1009 TopoDS_Shape aModifiedShape = aShape;
1010 if ( aSewing.IsModified( aShape ) )
1011 aModifiedShape = aSewing.Modified( aShape );
1012 else if ( aSewing.IsModifiedSubShape( aShape ) )
1013 aModifiedShape = aSewing.ModifiedSubShape( aShape );
1015 #ifdef DEB_CALCULATION
1016 const TopLoc_Location& aL1 = aShape.Location();
1017 const TopLoc_Location& aL2 = aModifiedShape.Location();
1018 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
1021 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
1022 if ( anIndex > 0 ) {
1023 aGroupIndexes.Append( anIndex );
1025 #ifdef DEB_CALCULATION
1026 TCollection_AsciiString aNam("Lost_");
1027 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
1028 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
1030 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
1031 if ( aModifiedShape.IsPartner( aS ) )
1033 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1034 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1035 BRepTools::Write(aS ,aName.ToCString());
1043 if ( !aGroupIndexes.IsEmpty() )
1044 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1047 if ( !aGroupsData.IsEmpty() )
1049 GEOM::GEOM_IGroupOperations_var aGroupOp =
1050 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1052 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1053 for ( ; aMapIt.More(); aMapIt.Next() )
1055 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1056 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1058 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1059 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1062 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1063 aGeomIndexes->length( aGroupIndexes.Length() );
1065 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1066 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1068 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1069 if ( aGroupOp->IsDone() )
1071 SALOMEDS::SObject_var aGroupSO =
1072 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1080 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
1081 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
1082 const TopoDS_Shape& theShape, const QString& theName,
1083 QString& theGeomObjEntry ) const
1085 theGeomObjEntry = "";
1086 GEOM::GEOM_Object_var aGeomObj;
1088 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
1089 theShape.IsNull() ) {
1090 return aGeomObj._retn();
1093 std::ostringstream aStreamShape;
1094 // Write TopoDS_Shape in ASCII format to the stream
1095 BRepTools::Write( theShape, aStreamShape );
1096 // Returns the number of bytes that have been stored in the stream's buffer.
1097 int aSize = aStreamShape.str().size();
1098 // Allocate octect buffer of required size
1099 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
1100 // Copy ostrstream content to the octect buffer
1101 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
1103 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
1105 // Restore shape from the stream and get the GEOM object
1106 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
1107 aGeomObj = anInsOp->RestoreShape( aSeqFile );
1109 // Puplish the GEOM object
1110 if ( !aGeomObj->_is_nil() ) {
1111 QString aName = GEOMBase::GetDefaultName( theName );
1113 SALOMEDS::SObject_var aResultSO =
1114 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
1115 aGeomObj, qPrintable( aName ) );
1116 if ( aResultSO->_is_nil() ) {
1117 aGeomObj = GEOM::GEOM_Object::_nil();
1120 theGeomObjEntry = aResultSO->GetID();
1123 return aGeomObj._retn();
1126 void HYDROData_CalculationCase::ClearRules( const bool theIsSetToUpdate )
1128 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1129 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1131 // Indicate model of the need to update splitting
1132 if ( theIsSetToUpdate ) {
1133 SetToUpdate( true );
1137 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)& theObject1,
1138 HYDROData_PriorityType thePriority,
1139 const Handle(HYDROData_Object)& theObject2,
1140 HYDROData_Zone::MergeAltitudesType theMergeType )
1142 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1143 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1145 // Indicate model of the need to update splitting
1146 SetToUpdate( true );
1149 QString HYDROData_CalculationCase::DumpRules() const
1151 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1152 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1155 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1157 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1158 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1160 // Indicate model of the need to update splitting
1161 SetToUpdate( true );
1164 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1166 Handle(TDataStd_Integer) aModeAttr;
1167 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1169 return ( AssignmentMode ) aModeAttr->Get();
1174 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1175 QStringList& theScript ) const
1177 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1178 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1181 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1183 return myLastWarning;
1186 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1188 myLastWarning.Type = theType;
1189 myLastWarning.Data = theData;
1192 bool HYDROData_CalculationCase::GetRule( int theIndex,
1193 Handle(HYDROData_Object)& theObject1,
1194 HYDROData_PriorityType& thePriority,
1195 Handle(HYDROData_Object)& theObject2,
1196 HYDROData_Zone::MergeAltitudesType& theMergeType ) const
1198 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1199 return HYDROData_PriorityQueue::GetRule( aRulesLab, theIndex,
1200 theObject1, thePriority, theObject2, theMergeType );