2 #include "HYDROData_CalculationCase.h"
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_Bathymetry.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_EdgesGroup.h"
8 #include "HYDROData_Iterator.h"
9 #include "HYDROData_NaturalObject.h"
10 #include "HYDROData_PolylineXY.h"
11 #include "HYDROData_SplitToZonesTool.h"
12 #include "HYDROData_SplittedEdgesGroup.h"
13 #include "HYDROData_Region.h"
14 #include "HYDROData_Tool.h"
15 #include "HYDROData_Zone.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>
36 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
37 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
38 #define CALCULATION_GROUPS_PREF GetName() + "_"
40 #define PYTHON_CALCULATION_ID "KIND_CALCULATION"
42 #define EXPORT_NAME "HYDRO_" + GetName()
44 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
45 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_CalculationCase, HYDROData_Entity)
47 HYDROData_CalculationCase::HYDROData_CalculationCase()
52 HYDROData_CalculationCase::~HYDROData_CalculationCase()
56 void HYDROData_CalculationCase::SetName( const QString& theName )
58 QString anOldCaseName = GetName();
59 if ( anOldCaseName != theName )
61 HYDROData_SequenceOfObjects aRegions = GetRegions();
63 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
64 for ( ; anIter.More(); anIter.Next() )
66 Handle(HYDROData_Region) aRegion =
67 Handle(HYDROData_Region)::DownCast( anIter.Value() );
68 if ( aRegion.IsNull() )
71 QString aRegionName = aRegion->GetName();
72 if ( aRegionName.startsWith( anOldCaseName ) )
74 aRegionName.replace( anOldCaseName, theName );
75 aRegion->SetName( aRegionName );
78 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
79 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
80 for ( ; anIter.More(); anIter.Next() )
82 Handle(HYDROData_Zone) aRegZone =
83 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
84 if ( aRegZone.IsNull() )
87 QString aRegionZoneName = aRegZone->GetName();
88 if ( aRegionZoneName.startsWith( anOldCaseName ) )
90 aRegionZoneName.replace( anOldCaseName, theName );
91 aRegZone->SetName( aRegionZoneName );
96 HYDROData_SequenceOfObjects aGroups = GetGeometryGroups();
98 anIter.Init( aGroups );
99 for ( ; anIter.More(); anIter.Next() )
101 Handle(HYDROData_SplittedEdgesGroup) aGroup =
102 Handle(HYDROData_SplittedEdgesGroup)::DownCast( anIter.Value() );
103 if ( aGroup.IsNull() )
106 QString aGroupName = aGroup->GetName();
107 if ( aGroupName.startsWith( anOldCaseName ) )
109 aGroupName.replace( anOldCaseName, theName );
110 aGroup->SetName( aGroupName );
115 HYDROData_Entity::SetName( theName );
118 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
120 QStringList aResList;
122 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
123 if ( aDocument.IsNull() )
126 QString aDocName = aDocument->GetDocPyName();
127 QString aCalculName = GetName();
129 aResList << QString( "%1 = %2.CreateObject( %3 );" )
130 .arg( aCalculName ).arg( aDocName ).arg( PYTHON_CALCULATION_ID );
131 aResList << QString( "%1.SetName( \"%2\" );" )
132 .arg( aCalculName ).arg( aCalculName );
133 aResList << QString( "" );
135 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
136 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
137 for ( ; anIter.More(); anIter.Next() )
139 Handle(HYDROData_Object) aRefGeomObj =
140 Handle(HYDROData_Object)::DownCast( anIter.Value() );
141 if ( !aRefGeomObj.IsNull() )
142 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
144 aResList << QString( "" );
146 aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName );
147 aResList << QString( "" );
149 // Now we restore the regions and zones order
150 HYDROData_SequenceOfObjects aRegions = GetRegions();
151 anIter.Init( aRegions );
152 for ( ; anIter.More(); anIter.Next() )
154 Handle(HYDROData_Region) aRegion =
155 Handle(HYDROData_Region)::DownCast( anIter.Value() );
156 if ( aRegion.IsNull() )
159 QString aRegionName = aRegion->GetName();
166 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
168 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
170 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
171 if ( !aBoundaryPolyline.IsNull() )
172 aResSeq.Append( aBoundaryPolyline );
174 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
175 aResSeq.Append( aSeqOfRegions );
180 void HYDROData_CalculationCase::Update()
182 HYDROData_Entity::Update();
184 // At first we remove previously created objects
186 RemoveSplittedGroups();
188 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
189 if ( aDocument.IsNull() )
192 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
193 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
194 if ( aGeomObjects.IsEmpty() )
197 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
199 HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
200 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
201 if ( aSplitedObjects.isEmpty() )
204 QString aRegsPref = CALCULATION_REGIONS_PREF;
205 QString aZonesPref = CALCULATION_ZONES_PREF;
207 QMap<QString,Handle(HYDROData_SplittedEdgesGroup)> aSplittedEdgesGroupsMap;
209 // Create result regions for case, by default one zone for one region
210 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
211 while( anIter.hasNext() )
213 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
215 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
218 Handle(HYDROData_Region) aRegion = addNewRegion();
220 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
221 aRegion->SetName( aRegionName );
223 // Add the zone for region
224 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
226 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
227 aRegionZone->SetName( aZoneName );
229 aRegionZone->SetShape( aSplitData.Face() );
231 // Add the reference object for zone
232 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
234 const QString& anObjName = aSplitData.ObjectNames.at( i );
236 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
237 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
238 if ( aRefObject.IsNull() )
241 aRegionZone->AddGeometryObject( aRefObject );
244 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
246 // Create new edges group
247 if ( aSplitData.ObjectNames.isEmpty() ||
248 aSplitData.Shape.IsNull() || aSplitData.Shape.ShapeType() != TopAbs_EDGE )
251 QString anObjName = aSplitData.ObjectNames.first();
252 if ( anObjName.isEmpty() )
255 Handle(HYDROData_SplittedEdgesGroup) aSplittedGroup;
256 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
258 aSplittedGroup = addNewSplittedGroup();
260 QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
261 aSplittedGroup->SetName( aCalcGroupName );
263 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
267 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
270 if ( aSplittedGroup.IsNull() )
273 TopoDS_Edge anEdge = TopoDS::Edge( aSplitData.Shape );
274 aSplittedGroup->AddEdge( anEdge );
279 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
281 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
282 return false; // Wrong type of object
284 if ( HasReference( theObject, DataTag_GeometryObject ) )
285 return false; // Object is already in reference list
287 AddReferenceObject( theObject, DataTag_GeometryObject );
289 // Indicate model of the need to update splitting
295 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
297 return GetReferenceObjects( DataTag_GeometryObject );
300 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
302 if ( theObject.IsNull() )
305 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
307 // Indicate model of the need to update splitting
311 void HYDROData_CalculationCase::RemoveGeometryObjects()
313 ClearReferenceObjects( DataTag_GeometryObject );
315 // Indicate model of the need to update splitting
319 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_EdgesGroup)& theGroup )
321 if ( theGroup.IsNull() )
324 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
325 return false; // Object is already in reference list
327 AddReferenceObject( theGroup, DataTag_GeometryGroup );
329 // Indicate model of the need to update splitting
335 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
337 return GetReferenceObjects( DataTag_GeometryGroup );
340 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_EdgesGroup)& theGroup )
342 if ( theGroup.IsNull() )
345 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
347 // Indicate model of the need to update splitting
351 void HYDROData_CalculationCase::RemoveGeometryGroups()
353 ClearReferenceObjects( DataTag_GeometryGroup );
355 // Indicate model of the need to update splitting
359 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
361 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
363 SetReferenceObject( thePolyline, DataTag_Polyline );
365 // Indicate model of the need to update zones splitting
366 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
369 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
371 return Handle(HYDROData_PolylineXY)::DownCast(
372 GetReferenceObject( DataTag_Polyline ) );
375 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
377 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
379 ClearReferenceObjects( DataTag_Polyline );
381 // Indicate model of the need to update zones splitting
382 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
385 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
387 Handle(HYDROData_Region) aNewRegion = addNewRegion();
388 if ( aNewRegion.IsNull() )
391 // Generate new name for new region
392 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
393 if ( !aDocument.IsNull() )
395 QString aRegsPref = CALCULATION_REGIONS_PREF;
397 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
398 aNewRegion->SetName( aNewRegionName );
401 aNewRegion->AddZone( theZone );
406 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
408 if ( theRegion.IsNull() )
411 if ( HasReference( theRegion, DataTag_Region ) )
412 return false; // Object is already in reference list
414 // Move the region from other calculation
415 Handle(HYDROData_CalculationCase) aFatherCalc =
416 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
417 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
419 Handle(HYDROData_Region) aNewRegion = addNewRegion();
420 theRegion->CopyTo( aNewRegion );
422 aFatherCalc->RemoveRegion( theRegion );
424 theRegion->SetLabel( aNewRegion->Label() );
428 AddReferenceObject( theRegion, DataTag_Region );
434 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
436 return GetReferenceObjects( DataTag_Region );
439 void HYDROData_CalculationCase::UpdateRegionsOrder()
441 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
442 if ( aDocument.IsNull() )
445 HYDROData_SequenceOfObjects aRegions = GetRegions();
447 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
448 for ( ; anIter.More(); anIter.Next() )
450 Handle(HYDROData_Region) aRegion =
451 Handle(HYDROData_Region)::DownCast( anIter.Value() );
452 if ( aRegion.IsNull() )
455 aRegion->SetName( "" );
458 QString aRegsPref = CALCULATION_REGIONS_PREF;
460 anIter.Init( aRegions );
461 for ( ; anIter.More(); anIter.Next() )
463 Handle(HYDROData_Region) aRegion =
464 Handle(HYDROData_Region)::DownCast( anIter.Value() );
465 if ( aRegion.IsNull() )
468 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
469 aRegion->SetName( aRegionName );
473 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
475 if ( theRegion.IsNull() )
478 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
480 // Remove region from data model
481 Handle(HYDROData_CalculationCase) aFatherCalc =
482 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
483 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
487 void HYDROData_CalculationCase::RemoveRegions()
489 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
492 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
494 return GetReferenceObjects( DataTag_SplittedGroups );
497 void HYDROData_CalculationCase::RemoveSplittedGroups()
499 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
502 TopoDS_Shell HYDROData_CalculationCase::GetShell()
506 TopTools_ListOfShape aFacesList;
508 // Make shell containing all region shapes
509 BRepBuilderAPI_Sewing aSewing( Precision::Confusion()*10.0 );
511 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
512 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
513 for ( ; aRegionIter.More(); aRegionIter.Next() ) {
514 Handle(HYDROData_Region) aRegion =
515 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
516 if( aRegion.IsNull() ) {
520 TopoDS_Shape aRegionShape = aRegion->GetShape();
521 if( !aRegionShape.IsNull() ) {
522 if ( aRegionShape.ShapeType() == TopAbs_FACE ) {
523 TopoDS_Face aFace = TopoDS::Face( aRegionShape );
524 if ( !aFace.IsNull() ) {
525 aFacesList.Append( aFace );
526 aSewing.Add( aFace );
529 TopExp_Explorer anExp( aRegionShape, TopAbs_FACE );
530 for ( ; anExp.More(); anExp.Next() ) {
531 TopoDS_Face aFace = TopoDS::Face( anExp.Current() );
532 if ( !aFace.IsNull() ) {
533 aFacesList.Append( aFace );
534 aSewing.Add( aFace );
539 } // regions iterator
542 TopoDS_Shape aSewedShape = aSewing.SewedShape();
544 if ( !aSewedShape.IsNull() )
546 if ( aSewedShape.ShapeType() == TopAbs_FACE && aCaseRegions.Length() ==1 ) {
547 // create shell from one face
548 BRep_Builder aBuilder;
549 aBuilder.MakeShell( aShell );
550 aBuilder.Add( aShell, aSewedShape);
552 TopExp_Explorer anExpShells( aSewedShape, TopAbs_SHELL );
553 Standard_Integer aNbOfShells = 0;
554 for ( ; anExpShells.More(); anExpShells.Next() ) {
555 aShell = TopoDS::Shell( anExpShells.Current() );
559 if ( aNbOfShells != 1 ) {
561 BRep_Builder aBuilder;
562 aBuilder.MakeShell( aShell );
564 TopExp_Explorer anExpFaces( aSewedShape, TopAbs_FACE );
565 for ( ; anExpFaces.More(); anExpFaces.Next() ) {
566 TopoDS_Face aFace = TopoDS::Face( anExpFaces.Current() );
567 if ( !aFace.IsNull() ) {
568 aBuilder.Add( aShell, aFace );
575 if ( !aShell.IsNull() ) {
576 TopTools_IndexedMapOfShape aMapOfFaces;
577 TopExp::MapShapes( aShell, TopAbs_FACE, aMapOfFaces );
578 if ( aMapOfFaces.Extent() != aFacesList.Extent() ) {
580 BRep_Builder aBuilder;
581 aBuilder.MakeShell( aShell );
583 TopTools_ListIteratorOfListOfShape anIter( aFacesList );
584 for ( ; anIter.More(); anIter.Next() ) {
585 TopoDS_Face aFace = TopoDS::Face( anIter.Value() );
586 aBuilder.Add( aShell, aFace );
593 BRep_Builder aBuilder;
594 aBuilder.MakeShell( aShell );
596 // Make shell containing all region shapes
597 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
598 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
599 for ( ; aRegionIter.More(); aRegionIter.Next() ) {
600 Handle(HYDROData_Region) aRegion =
601 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
602 if( aRegion.IsNull() ) {
606 TopoDS_Shape aRegionShape = aRegion->GetShape();
608 // Add shape (face or shell) corresponding to the region into the shell
609 if( !aRegionShape.IsNull() ) {
610 if ( aRegionShape.ShapeType() == TopAbs_FACE ) {
611 aBuilder.Add( aShell, aRegionShape );
613 TopExp_Explorer anExp( aRegionShape, TopAbs_FACE );
614 for( ; anExp.More(); anExp.Next() ) {
615 TopoDS_Face aFace = TopoDS::Face( anExp.Current() );
616 if( !aFace.IsNull() ) {
617 aBuilder.Add( aShell, aFace );
622 } // regions iterator
625 // Nullify shell if it is empty
626 if ( !aShell.IsNull() && !TopoDS_Iterator(aShell).More() ) {
633 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
635 double aResAltitude = HYDROData_Bathymetry::GetInvalidAltitude();
637 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
638 if ( aZone.IsNull() )
641 HYDROData_Zone::MergeBathymetriesType aZoneMergeType = aZone->GetMergeType();
642 if ( !aZone->IsMergingNeed() )
644 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
646 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
651 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
653 Handle(HYDROData_Bathymetry) aMergeBathymetry = aZone->GetMergeBathymetry();
654 if ( !aMergeBathymetry.IsNull() )
655 aResAltitude = aMergeBathymetry->GetAltitudeForPoint( thePoint );
659 HYDROData_SequenceOfObjects aZoneObjects = aZone->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_Bathymetry) anObjBathymetry = aZoneObj->GetBathymetry();
669 if ( anObjBathymetry.IsNull() )
672 double aPointAltitude = anObjBathymetry->GetAltitudeForPoint( thePoint );
673 if ( ValuesEquals( aPointAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) )
676 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
678 aResAltitude = aPointAltitude;
681 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
683 if ( ValuesEquals( aResAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ||
684 aResAltitude > aPointAltitude )
686 aResAltitude = aPointAltitude;
689 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
691 if ( ValuesEquals( aResAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ||
692 aResAltitude < aPointAltitude )
694 aResAltitude = aPointAltitude;
703 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
705 Handle(HYDROData_Zone) aResZone;
707 HYDROData_SequenceOfObjects aRegions = GetRegions();
709 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
710 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
712 Handle(HYDROData_Region) aRegion =
713 Handle(HYDROData_Region)::DownCast( anIter.Value() );
714 if ( aRegion.IsNull() )
717 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
718 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
719 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
721 Handle(HYDROData_Zone) aRegZone =
722 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
723 if ( aRegZone.IsNull() )
726 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
727 if ( aPointRelation != POINT_OUT )
728 aResZone = aRegZone; // We found the desired zone
735 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
736 const gp_XY& thePoint,
737 const Handle(HYDROData_Zone)& theZone ) const
739 PointClassification aRes = POINT_OUT;
740 if ( theZone.IsNull() )
743 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
744 if ( aZoneFace.IsNull() )
747 BRepTopAdaptor_FClass2d aClassifier( aZoneFace, Precision::Confusion() );
748 TopAbs_State State = aClassifier.Perform( gp_Pnt2d(thePoint), Standard_False );
749 if (State == TopAbs_OUT)
751 else if(State == TopAbs_IN)
753 else if(State == TopAbs_ON)
758 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
760 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
762 Handle(HYDROData_Region) aNewRegion =
763 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
764 AddRegion( aNewRegion );
769 Handle(HYDROData_SplittedEdgesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
771 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
773 Handle(HYDROData_SplittedEdgesGroup) aNewGroup =
774 Handle(HYDROData_SplittedEdgesGroup)::DownCast(
775 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
776 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
781 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
782 SALOMEDS::Study_ptr theStudy )
786 TopTools_ListOfShape aFaces;
790 HYDROData_SequenceOfObjects aSplittedGroups;
792 return Export( theGeomEngine, theStudy, aFaces, aSplittedGroups );
795 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
796 SALOMEDS::Study_ptr theStudy,
797 const TopTools_ListOfShape& theFaces,
798 const HYDROData_SequenceOfObjects& theSplittedGroups )
800 // Make shell from the faces
802 TopTools_ListOfShape aFacesList;
804 BRepBuilderAPI_Sewing aSewing( Precision::Confusion()*10.0 );
806 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
807 for ( ; aFaceIter.More(); aFaceIter.Next() ) {
808 TopoDS_Shape aShape = aFaceIter.Value();
809 if ( !aShape.IsNull() && (aShape.ShapeType() == TopAbs_FACE) ) {
810 TopoDS_Face aFace = TopoDS::Face( aShape );
811 if ( !aFace.IsNull() ) {
812 aFacesList.Append( aFace );
813 aSewing.Add( aFace );
816 TopExp_Explorer anExp( aShape, TopAbs_FACE );
817 for ( ; anExp.More(); anExp.Next() ) {
818 TopoDS_Face aFace = TopoDS::Face( anExp.Current() );
819 if ( !aFace.IsNull() ) {
820 aFacesList.Append( aFace );
821 aSewing.Add( aFace );
828 TopoDS_Shape aSewedShape = aSewing.SewedShape();
830 if ( !aSewedShape.IsNull() ) {
831 if ( aSewedShape.ShapeType() == TopAbs_FACE && theFaces.Extent() ==1 ) {
832 // create shell from one face
833 BRep_Builder aBuilder;
834 aBuilder.MakeShell( aShell );
835 aBuilder.Add( aShell, aSewedShape);
837 TopExp_Explorer anExpShells( aSewedShape, TopAbs_SHELL );
838 Standard_Integer aNbOfShells = 0;
839 for ( ; anExpShells.More(); anExpShells.Next() ) {
840 aShell = TopoDS::Shell( anExpShells.Current() );
844 if ( aNbOfShells != 1 ) {
846 BRep_Builder aBuilder;
847 aBuilder.MakeShell( aShell );
849 TopExp_Explorer anExpFaces( aSewedShape, TopAbs_FACE );
850 for ( ; anExpFaces.More(); anExpFaces.Next() ) {
851 TopoDS_Face aFace = TopoDS::Face( anExpFaces.Current() );
852 if ( !aFace.IsNull() ) {
853 aBuilder.Add( aShell, aFace );
860 if ( !aShell.IsNull() ) {
861 TopTools_IndexedMapOfShape aMapOfFaces;
862 TopExp::MapShapes( aShell, TopAbs_FACE, aMapOfFaces );
863 if ( aMapOfFaces.Extent() != aFacesList.Extent() ) {
865 BRep_Builder aBuilder;
866 aBuilder.MakeShell( aShell );
868 TopTools_ListIteratorOfListOfShape anIter( aFacesList );
869 for ( ; anIter.More(); anIter.Next() ) {
870 TopoDS_Face aFace = TopoDS::Face( anIter.Value() );
871 aBuilder.Add( aShell, aFace );
876 // If the shell is empty - return false
877 if ( aShell.IsNull() || !TopoDS_Iterator(aShell).More() ) {
882 QString aName = EXPORT_NAME;
883 GEOM::GEOM_Object_ptr aPublishedObj =
884 publishShapeInGEOM( theGeomEngine, theStudy, aShell, aName );
886 if ( aPublishedObj->_is_nil() ) {
891 GEOM::GEOM_IGroupOperations_var aGroupOp =
892 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
894 GEOM::GEOM_Object_var aGroup = aGroupOp->CreateGroup( aPublishedObj, TopAbs_EDGE );
895 if ( !CORBA::is_nil(aGroup) && aGroupOp->IsDone() ) {
896 GEOM::ListOfLong_var anIndexes = new GEOM::ListOfLong;
897 aGroupOp->UnionIDs( aGroup, anIndexes );
898 if ( aGroupOp->IsDone() ) {
899 SALOMEDS::SObject_var aGroupSO =
900 theGeomEngine->AddInStudy( theStudy, aGroup, qPrintable( aName ), aPublishedObj );
907 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
908 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
909 const TopoDS_Shape& theShape, const QString& theName )
911 GEOM::GEOM_Object_var aGeomObj;
913 bool isNil = aGeomObj->_is_nil(); ///@MZN
915 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
916 theShape.IsNull() ) {
917 return aGeomObj._retn();
920 std::ostringstream aStreamShape;
921 // Write TopoDS_Shape in ASCII format to the stream
922 BRepTools::Write( theShape, aStreamShape );
923 // Returns the number of bytes that have been stored in the stream's buffer.
924 int aSize = aStreamShape.str().size();
925 // Allocate octect buffer of required size
926 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
927 // Copy ostrstream content to the octect buffer
928 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
930 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
932 // Restore shape from the stream and get the GEOM object
933 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
934 aGeomObj = anInsOp->RestoreShape( aSeqFile );
936 // Puplish the GEOM object
937 if ( !aGeomObj->_is_nil() ) {
938 QString aName = GEOMBase::GetDefaultName( theName );
940 SALOMEDS::SObject_var aResultSO =
941 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
942 aGeomObj, qPrintable( theName ) );
943 if ( aResultSO->_is_nil() ) {
944 aGeomObj = GEOM::GEOM_Object::_nil();
948 return aGeomObj._retn();