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 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
52 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
54 HYDROData_CalculationCase::HYDROData_CalculationCase()
59 HYDROData_CalculationCase::~HYDROData_CalculationCase()
63 void HYDROData_CalculationCase::SetName( const QString& theName )
65 QString anOldCaseName = GetName();
66 if ( anOldCaseName != theName )
68 HYDROData_SequenceOfObjects aRegions = GetRegions();
70 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
71 for ( ; anIter.More(); anIter.Next() )
73 Handle(HYDROData_Region) aRegion =
74 Handle(HYDROData_Region)::DownCast( anIter.Value() );
75 if ( aRegion.IsNull() )
78 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
80 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
81 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
82 for ( ; anIter.More(); anIter.Next() )
84 Handle(HYDROData_Zone) aRegZone =
85 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
86 if ( aRegZone.IsNull() )
89 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
93 HYDROData_SequenceOfObjects aGroups = GetSplittedGroups();
95 anIter.Init( aGroups );
96 for ( ; anIter.More(); anIter.Next() )
98 Handle(HYDROData_SplittedShapesGroup) aGroup =
99 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
100 if ( aGroup.IsNull() )
103 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
107 HYDROData_Entity::SetName( theName );
110 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
112 QStringList aResList = dumpObjectCreation( theTreatedObjects );
114 QString aCalculName = GetObjPyName();
116 AssignmentMode aMode = GetAssignmentMode();
117 QString aModeStr = aMode==MANUAL ? "MANUAL" : "AUTOMATIC";
118 aResList << QString( "%0.SetAssignmentMode( %1 )" ).arg( aCalculName ).arg( aModeStr );
120 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
121 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
122 for ( ; anIter.More(); anIter.Next() )
124 Handle(HYDROData_Object) aRefGeomObj =
125 Handle(HYDROData_Object)::DownCast( anIter.Value() );
126 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
128 aResList << QString( "" );
130 QString aGroupName = HYDROData_Tool::GenerateNameForPython( theTreatedObjects, "case_geom_group" );
132 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
133 anIter.Init( aGeomGroups );
134 for ( ; anIter.More(); anIter.Next() )
136 Handle(HYDROData_ShapesGroup) aGeomGroup =
137 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
138 if ( aGeomGroup.IsNull() )
141 Handle(HYDROData_Object) aFatherGeom =
142 Handle(HYDROData_Object)::DownCast( aGeomGroup->GetFatherObject() );
143 if ( aFatherGeom.IsNull() )
146 int aGroupId = aFatherGeom->GetGroupId( aGeomGroup );
147 aResList << QString( "%1 = %2.GetGroup( %3 );" )
148 .arg( aGroupName ).arg( aFatherGeom->GetObjPyName() ).arg( aGroupId );
150 aResList << QString( "%1.AddGeometryGroup( %2 );" ).arg( aCalculName ).arg( aGroupName );
152 aResList << QString( "" );
154 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
155 setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" );
156 aResList << QString( "" );
158 if( aMode==AUTOMATIC )
159 DumpRulesToPython( aCalculName, aResList );
161 aResList << QString( "" );
162 aResList << QString( "%1.Update();" ).arg( aCalculName );
163 aResList << QString( "" );
167 // Now we restore the regions and zones order
168 HYDROData_SequenceOfObjects aRegions = GetRegions();
169 anIter.Init( aRegions );
170 for ( ; anIter.More(); anIter.Next() )
172 Handle(HYDROData_Region) aRegion =
173 Handle(HYDROData_Region)::DownCast( anIter.Value() );
174 if ( aRegion.IsNull() )
177 QString aRegionName = aRegion->GetName();
179 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
180 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
181 for ( ; aZonesIter.More(); aZonesIter.Next() )
183 Handle(HYDROData_Zone) aRegZone =
184 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
185 if ( aRegZone.IsNull() )
193 aResList << QString( "" );
197 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
199 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
201 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
202 if ( !aBoundaryPolyline.IsNull() )
203 aResSeq.Append( aBoundaryPolyline );
205 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
206 aResSeq.Append( aSeqOfRegions );
211 void HYDROData_CalculationCase::Update()
213 HYDROData_Entity::Update();
216 // At first we remove previously created objects
218 RemoveSplittedGroups();
220 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
221 if ( aDocument.IsNull() )
224 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
225 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
226 if ( aGeomObjects.IsEmpty() )
229 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
231 HYDROData_SplitToZonesTool::SplitDataList aSplitObjects =
232 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
233 if ( aSplitObjects.isEmpty() )
236 HYDROData_SplitToZonesTool::SplitDataList aZonesList, anEdgesList;
238 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitObjects );
239 while( anIter.hasNext() )
241 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
242 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
243 aZonesList.append( aSplitData );
244 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
245 anEdgesList.append( aSplitData );
248 switch( GetAssignmentMode() )
251 CreateRegionsDef( aDocument, aZonesList );
254 CreateRegionsAuto( aDocument, aZonesList );
257 CreateEdgeGroupsDef( aDocument, anEdgesList );
260 void HYDROData_CalculationCase::CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
261 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
263 // Create result regions for case, by default one zone for one region
264 QString aRegsPref = CALCULATION_REGIONS_PREF;
265 QString aZonesPref = CALCULATION_ZONES_PREF;
267 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
268 while( anIter.hasNext() )
270 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
272 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegsPref );
274 // Add the zone for region
275 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
279 void HYDROData_CalculationCase::CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
280 const HYDROData_SplitToZonesTool::SplitDataList& theZones )
282 QMap<QString, Handle(HYDROData_Region)> aRegionsMap; //object name to region
283 QMap<QString, QString> aRegionNameToObjNameMap;
284 QString aZonesPref = CALCULATION_ZONES_PREF;
285 HYDROData_PriorityQueue aPr( this );
287 // 1. First we create a default region for each object included into the calculation case
288 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
289 for( int i=aGeomObjects.Lower(), n=aGeomObjects.Upper(); i<=n; i++ )
291 Handle(HYDROData_Object) anObj = Handle(HYDROData_Object)::DownCast( aGeomObjects.Value( i ) );
294 QString anObjName = anObj->GetName();
295 QString aRegName = anObjName + "_reg";
296 Handle(HYDROData_Region) aRegion = addNewRegion( theDoc, aRegName, false );
297 aRegionsMap.insert( anObjName, aRegion );
298 aRegionNameToObjNameMap.insert( aRegName, anObjName );
301 // 2. Now for each zone it is necessary to determine the most priority object
302 // and assign to zone to corresponding region
303 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theZones );
304 while( anIter.hasNext() )
306 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
307 HYDROData_Zone::MergeAltitudesType aMergeType;
308 Handle(HYDROData_Object) aRegObj = aPr.GetMostPriorityObject( aSplitData.ObjectNames, aMergeType );
309 if( aRegObj.IsNull() )
311 Handle(HYDROData_Region) aRegion = aRegionsMap[aRegObj->GetName()];
312 if( aRegion.IsNull() )
314 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( theDoc, aZonesPref, aSplitData.Face(), aSplitData.ObjectNames );
317 case HYDROData_Zone::Merge_ZMIN:
318 case HYDROData_Zone::Merge_ZMAX:
319 aRegionZone->SetMergeType( aMergeType );
321 case HYDROData_Zone::Merge_Object:
322 aRegionZone->SetMergeType( aMergeType );
323 aRegionZone->RemoveMergeAltitude();
324 aRegionZone->SetMergeAltitude( aRegObj->GetAltitudeObject() );
329 QStringList anObjectsWithEmptyRegions;
330 QMap<QString, Handle(HYDROData_Region)>::const_iterator
331 anIt = aRegionsMap.begin(), aLast = aRegionsMap.end();
332 for( ; anIt!=aLast; anIt++ )
334 Handle(HYDROData_Region) aRegion = anIt.value();
335 if( aRegion->GetZones().IsEmpty() )
337 QString aRegName = aRegion->GetName();
338 QString anObjName = aRegionNameToObjNameMap[aRegName];
339 anObjectsWithEmptyRegions.append( anObjName );
343 if( !anObjectsWithEmptyRegions.empty() )
345 QString aData = anObjectsWithEmptyRegions.join( ", " );
346 SetWarning( WARN_EMPTY_REGIONS, aData );
350 void HYDROData_CalculationCase::CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
351 const HYDROData_SplitToZonesTool::SplitDataList& theEdges )
353 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
355 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( theEdges );
356 while( anIter.hasNext() )
358 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
359 // Create new edges group
360 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
363 QString anObjName = aSplitData.ObjectNames.first();
364 if ( anObjName.isEmpty() )
366 #ifdef DEB_CALCULATION
367 QString aStr = aSplitData.ObjectNames.join(" ");
368 cout << " CCase: Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;
370 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
371 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
373 aSplittedGroup = addNewSplittedGroup( CALCULATION_GROUPS_PREF + anObjName );
374 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
378 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
380 if ( aSplittedGroup.IsNull() )
383 aSplittedGroup->AddShape( aSplitData.Shape );
387 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
389 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
390 return false; // Wrong type of object
392 if ( HasReference( theObject, DataTag_GeometryObject ) )
393 return false; // Object is already in reference list
395 AddReferenceObject( theObject, DataTag_GeometryObject );
397 // Indicate model of the need to update splitting
403 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
405 return GetReferenceObjects( DataTag_GeometryObject );
408 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
410 if ( theObject.IsNull() )
413 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
415 // Indicate model of the need to update splitting
419 void HYDROData_CalculationCase::RemoveGeometryObjects()
421 ClearReferenceObjects( DataTag_GeometryObject );
423 // Indicate model of the need to update splitting
427 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
429 if ( theGroup.IsNull() )
432 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
433 return false; // Object is already in reference list
435 AddReferenceObject( theGroup, DataTag_GeometryGroup );
437 // Indicate model of the need to update splitting
443 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
445 return GetReferenceObjects( DataTag_GeometryGroup );
448 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
450 if ( theGroup.IsNull() )
453 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
455 // Indicate model of the need to update splitting
459 void HYDROData_CalculationCase::RemoveGeometryGroups()
461 ClearReferenceObjects( DataTag_GeometryGroup );
463 // Indicate model of the need to update splitting
467 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
469 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
471 SetReferenceObject( thePolyline, DataTag_Polyline );
473 // Indicate model of the need to update zones splitting
474 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
477 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
479 return Handle(HYDROData_PolylineXY)::DownCast(
480 GetReferenceObject( DataTag_Polyline ) );
483 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
485 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
487 ClearReferenceObjects( DataTag_Polyline );
489 // Indicate model of the need to update zones splitting
490 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
493 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
495 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
496 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
497 if ( aNewRegion.IsNull() )
500 aNewRegion->AddZone( theZone );
505 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
507 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
509 if ( theRegion.IsNull() )
512 if ( HasReference( theRegion, DataTag_Region ) )
513 return false; // Object is already in reference list
515 // Move the region from other calculation
516 Handle(HYDROData_CalculationCase) aFatherCalc =
517 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
518 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
520 Handle(HYDROData_Region) aNewRegion = addNewRegion( aDocument, CALCULATION_REGIONS_PREF );
521 theRegion->CopyTo( aNewRegion );
523 aFatherCalc->RemoveRegion( theRegion );
525 theRegion->SetLabel( aNewRegion->Label() );
529 AddReferenceObject( theRegion, DataTag_Region );
535 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
537 return GetReferenceObjects( DataTag_Region );
540 void HYDROData_CalculationCase::UpdateRegionsOrder()
542 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
543 if ( aDocument.IsNull() )
546 HYDROData_SequenceOfObjects aRegions = GetRegions();
548 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
549 for ( ; anIter.More(); anIter.Next() )
551 Handle(HYDROData_Region) aRegion =
552 Handle(HYDROData_Region)::DownCast( anIter.Value() );
553 if ( aRegion.IsNull() )
556 aRegion->SetName( "" );
559 QString aRegsPref = CALCULATION_REGIONS_PREF;
561 anIter.Init( aRegions );
562 for ( ; anIter.More(); anIter.Next() )
564 Handle(HYDROData_Region) aRegion =
565 Handle(HYDROData_Region)::DownCast( anIter.Value() );
566 if ( aRegion.IsNull() )
569 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
570 aRegion->SetName( aRegionName );
574 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
576 if ( theRegion.IsNull() )
579 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
581 // Remove region from data model
582 Handle(HYDROData_CalculationCase) aFatherCalc =
583 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
584 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
588 void HYDROData_CalculationCase::RemoveRegions()
590 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
593 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
595 return GetReferenceObjects( DataTag_SplittedGroups );
598 void HYDROData_CalculationCase::RemoveSplittedGroups()
600 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
603 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
605 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
606 return GetAltitudeForPoint( thePoint, aZone );
609 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
610 const Handle(HYDROData_Region)& theRegion ) const
612 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
614 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
615 if ( !aZone.IsNull() )
617 Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
618 if ( IsEqual( aRefRegion, theRegion ) )
619 aResAltitude = GetAltitudeForPoint( thePoint, aZone );
625 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint,
626 const Handle(HYDROData_Zone)& theZone ) const
628 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
629 if ( theZone.IsNull() )
632 HYDROData_Zone::MergeAltitudesType aZoneMergeType = theZone->GetMergeType();
633 if ( !theZone->IsMergingNeed() )
635 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
637 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
642 HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator();
643 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
645 Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude();
646 if ( !aMergeAltitude.IsNull() )
648 if ( aZoneInterpolator != NULL )
650 aZoneInterpolator->SetAltitudeObject( aMergeAltitude );
651 aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
654 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
659 HYDROData_SequenceOfObjects aZoneObjects = theZone->GetGeometryObjects();
660 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
661 for ( ; anIter.More(); anIter.Next() )
663 Handle(HYDROData_Object) aZoneObj =
664 Handle(HYDROData_Object)::DownCast( anIter.Value() );
665 if ( aZoneObj.IsNull() )
668 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
669 if ( anObjAltitude.IsNull() )
672 double aPointAltitude = 0.0;
673 if ( aZoneInterpolator != NULL )
675 aZoneInterpolator->SetAltitudeObject( anObjAltitude );
676 aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint );
679 aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
681 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
684 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
686 aResAltitude = aPointAltitude;
689 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
691 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
692 aResAltitude > aPointAltitude )
694 aResAltitude = aPointAltitude;
697 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
699 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
700 aResAltitude < aPointAltitude )
702 aResAltitude = aPointAltitude;
711 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
712 const NCollection_Sequence<gp_XY>& thePoints,
713 const Handle(HYDROData_Region)& theRegion ) const
715 NCollection_Sequence<double> aResSeq;
717 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
719 const gp_XY& thePnt = thePoints.Value( i );
721 double anAltitude = GetAltitudeForPoint( thePnt, theRegion );
722 aResSeq.Append( anAltitude );
728 NCollection_Sequence<double> HYDROData_CalculationCase::GetAltitudesForPoints(
729 const NCollection_Sequence<gp_XY>& thePoints,
730 const Handle(HYDROData_Zone)& theZone ) const
732 NCollection_Sequence<double> aResSeq;
734 for ( int i = 1, n = thePoints.Length(); i <= n; ++i )
736 const gp_XY& thePnt = thePoints.Value( i );
738 double anAltitude = GetAltitudeForPoint( thePnt, theZone );
739 aResSeq.Append( anAltitude );
745 Handle(HYDROData_Region) HYDROData_CalculationCase::GetRegionFromPoint( const gp_XY& thePoint ) const
747 Handle(HYDROData_Region) aResRegion;
749 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
750 if ( !aZone.IsNull() )
751 aResRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() );
756 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
758 Handle(HYDROData_Zone) aResZone;
760 HYDROData_SequenceOfObjects aRegions = GetRegions();
762 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
763 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
765 Handle(HYDROData_Region) aRegion =
766 Handle(HYDROData_Region)::DownCast( anIter.Value() );
767 if ( aRegion.IsNull() )
770 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
771 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
772 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
774 Handle(HYDROData_Zone) aRegZone =
775 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
776 if ( aRegZone.IsNull() )
779 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
780 if ( aPointRelation != POINT_OUT )
781 aResZone = aRegZone; // We found the desired zone
788 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
789 const gp_XY& thePoint,
790 const Handle(HYDROData_Zone)& theZone ) const
792 PointClassification aRes = POINT_OUT;
793 if ( theZone.IsNull() )
796 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
797 if ( aZoneFace.IsNull() )
800 TopoDS_Compound aCmp;
802 aBB.MakeCompound(aCmp);
803 aBB.Add(aCmp, aZoneFace);
804 gp_Pnt aPnt (thePoint.X(), thePoint.Y(), 0.);
805 BRepBuilderAPI_MakeVertex aMk(aPnt);
806 aBB.Add(aCmp, aMk.Vertex());
807 BRepTools::Write(aCmp, "FCL2d.brep");
809 TopAbs_State State = HYDROData_Tool::ComputePointState(thePoint, aZoneFace);
810 if (State == TopAbs_OUT)
812 else if(State == TopAbs_IN)
814 else if(State == TopAbs_ON)
819 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion( const Handle(HYDROData_Document)& theDoc,
820 const QString& thePrefixOrName,
823 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
825 Handle(HYDROData_Region) aNewRegion =
826 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
827 AddRegion( aNewRegion );
829 QString aRegionName = isPrefix ? HYDROData_Tool::GenerateObjectName( theDoc, thePrefixOrName ) : thePrefixOrName;
830 aNewRegion->SetName( aRegionName );
835 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup( const QString& theName )
837 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
839 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
840 Handle(HYDROData_SplittedShapesGroup)::DownCast(
841 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
842 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
844 aNewGroup->SetName( theName );
849 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
850 SALOMEDS::Study_ptr theStudy ) const
852 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
854 // Get groups definitions
855 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
857 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
858 for ( ; anIter.More(); anIter.Next() )
861 Handle(HYDROData_ShapesGroup) aGroup =
862 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
863 if ( aGroup.IsNull() )
866 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
868 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
869 aGroup->GetShapes( aGroupDef.Shapes );
871 aSeqOfGroupsDefs.Append( aGroupDef );
875 TopTools_ListOfShape aFaces;
876 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
877 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
878 for ( ; aRegionIter.More(); aRegionIter.Next() )
880 Handle(HYDROData_Region) aRegion =
881 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
882 if( aRegion.IsNull() )
885 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
886 aFaces.Append( aRegionShape );
889 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
892 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
893 SALOMEDS::Study_ptr theStudy,
894 const TopTools_ListOfShape& theFaces,
895 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
898 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
899 aSewing.SetNonManifoldMode( Standard_False );
900 #ifdef DEB_CALCULATION
901 TCollection_AsciiString aNam("Sh_");
904 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
905 for ( ; aFaceIter.More(); aFaceIter.Next() )
907 TopoDS_Shape aShape = aFaceIter.Value();
908 if ( aShape.IsNull() )
911 if ( aShape.ShapeType() == TopAbs_FACE )
913 aSewing.Add( aShape );
914 #ifdef DEB_CALCULATION
915 TCollection_AsciiString aName = aNam + ++i + ".brep";
916 BRepTools::Write(aShape ,aName.ToCString());
921 #ifdef DEB_CALCULATION
924 TopExp_Explorer anExp( aShape, TopAbs_FACE );
925 for (; anExp.More(); anExp.Next() ) {
926 aSewing.Add( anExp.Current() );
927 #ifdef DEB_CALCULATION
929 TCollection_AsciiString aName = aNam + i + "_" + ++j + ".brep";
930 BRepTools::Write(anExp.Current() ,aName.ToCString());
937 TopoDS_Shape aSewedShape = aSewing.SewedShape();
939 // If the sewed shape is empty - return false
940 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
943 #ifdef DEB_CALCULATION
944 BRepTools::Write(aSewedShape ,"Sew.brep");
946 // Publish the sewed shape
947 QString aName = EXPORT_NAME;
948 GEOM::GEOM_Object_ptr aMainShape =
949 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
951 if ( aMainShape->_is_nil() )
954 if ( theGroupsDefs.IsEmpty() )
958 TopTools_IndexedMapOfShape aMapOfSubShapes;
959 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
961 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
963 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
965 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
967 NCollection_Sequence<int> aGroupIndexes;
968 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
970 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
971 #ifdef DEB_CALCULATION
972 cout << "\nOld shape(" << i << ") = " << aShape.TShape() <<endl;
975 TopoDS_Shape aModifiedShape = aShape;
976 if ( aSewing.IsModified( aShape ) )
977 aModifiedShape = aSewing.Modified( aShape );
978 else if ( aSewing.IsModifiedSubShape( aShape ) )
979 aModifiedShape = aSewing.ModifiedSubShape( aShape );
981 #ifdef DEB_CALCULATION
982 const TopLoc_Location& aL1 = aShape.Location();
983 const TopLoc_Location& aL2 = aModifiedShape.Location();
984 cout << "\nNew shape(" << i << ") = " << aModifiedShape.TShape() << " Location is Equal = " << aL1.IsEqual(aL2)<<endl;
987 int anIndex = aMapOfSubShapes.FindIndex(aModifiedShape);
989 aGroupIndexes.Append( anIndex );
991 #ifdef DEB_CALCULATION
992 TCollection_AsciiString aNam("Lost_");
993 if(!aMapOfSubShapes.Contains(aModifiedShape)) {
994 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
996 const TopoDS_Shape& aS = aMapOfSubShapes.FindKey( anIndex );
997 if ( aModifiedShape.IsPartner( aS ) )
999 cout <<"\nIndex in Map = " << anIndex << "TShape = " << aS.TShape() <<endl;
1000 TCollection_AsciiString aName = aNam + i + "_" + anIndex + ".brep";
1001 BRepTools::Write(aS ,aName.ToCString());
1009 if ( !aGroupIndexes.IsEmpty() )
1010 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
1013 if ( !aGroupsData.IsEmpty() )
1015 GEOM::GEOM_IGroupOperations_var aGroupOp =
1016 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
1018 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
1019 for ( ; aMapIt.More(); aMapIt.Next() )
1021 const TCollection_AsciiString& aGroupName = aMapIt.Key();
1022 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
1024 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
1025 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
1028 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
1029 aGeomIndexes->length( aGroupIndexes.Length() );
1031 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
1032 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
1034 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
1035 if ( aGroupOp->IsDone() )
1037 SALOMEDS::SObject_var aGroupSO =
1038 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
1046 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
1047 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
1048 const TopoDS_Shape& theShape, const QString& theName ) const
1050 GEOM::GEOM_Object_var aGeomObj;
1052 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
1053 theShape.IsNull() ) {
1054 return aGeomObj._retn();
1057 std::ostringstream aStreamShape;
1058 // Write TopoDS_Shape in ASCII format to the stream
1059 BRepTools::Write( theShape, aStreamShape );
1060 // Returns the number of bytes that have been stored in the stream's buffer.
1061 int aSize = aStreamShape.str().size();
1062 // Allocate octect buffer of required size
1063 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
1064 // Copy ostrstream content to the octect buffer
1065 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
1067 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
1069 // Restore shape from the stream and get the GEOM object
1070 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
1071 aGeomObj = anInsOp->RestoreShape( aSeqFile );
1073 // Puplish the GEOM object
1074 if ( !aGeomObj->_is_nil() ) {
1075 QString aName = GEOMBase::GetDefaultName( theName );
1077 SALOMEDS::SObject_var aResultSO =
1078 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
1079 aGeomObj, qPrintable( aName ) );
1080 if ( aResultSO->_is_nil() ) {
1081 aGeomObj = GEOM::GEOM_Object::_nil();
1085 return aGeomObj._retn();
1088 void HYDROData_CalculationCase::ClearRules()
1090 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1091 HYDROData_PriorityQueue::ClearRules( aRulesLab );
1094 void HYDROData_CalculationCase::AddRule( const Handle(HYDROData_Object)& theObject1,
1095 HYDROData_PriorityType thePriority,
1096 const Handle(HYDROData_Object)& theObject2,
1097 HYDROData_Zone::MergeAltitudesType theMergeType )
1099 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1100 HYDROData_PriorityQueue::AddRule( aRulesLab, theObject1, thePriority, theObject2, theMergeType );
1103 QString HYDROData_CalculationCase::DumpRules() const
1105 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1106 return HYDROData_PriorityQueue::DumpRules( aRulesLab );
1109 void HYDROData_CalculationCase::SetAssignmentMode( AssignmentMode theMode )
1111 TDF_Label aModeLab = myLab.FindChild( DataTag_AssignmentMode );
1112 TDataStd_Integer::Set( aModeLab, ( int ) theMode );
1115 HYDROData_CalculationCase::AssignmentMode HYDROData_CalculationCase::GetAssignmentMode() const
1117 Handle(TDataStd_Integer) aModeAttr;
1118 bool isOK = myLab.FindChild( DataTag_AssignmentMode ).FindAttribute( TDataStd_Integer::GetID(), aModeAttr );
1120 return ( AssignmentMode ) aModeAttr->Get();
1125 void HYDROData_CalculationCase::DumpRulesToPython( const QString& theCalcCaseName,
1126 QStringList& theScript ) const
1128 TDF_Label aRulesLab = myLab.FindChild( DataTag_CustomRules );
1129 HYDROData_PriorityQueue::DumpRulesToPython( aRulesLab, theCalcCaseName, theScript );
1132 HYDROData_Warning HYDROData_CalculationCase::GetLastWarning() const
1134 return myLastWarning;
1137 void HYDROData_CalculationCase::SetWarning( HYDROData_WarningType theType, const QString& theData )
1139 myLastWarning.Type = theType;
1140 myLastWarning.Data = theData;