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_SplitToZonesTool.h"
12 #include "HYDROData_SplittedShapesGroup.h"
13 #include "HYDROData_Region.h"
14 #include "HYDROData_Tool.h"
15 #include "HYDROData_Zone.h"
22 #include <TopoDS_Shell.hxx>
23 #include <TopoDS_Edge.hxx>
25 #include <BRep_Builder.hxx>
26 #include <BRepBuilderAPI_Sewing.hxx>
27 #include <BRepTopAdaptor_FClass2d.hxx>
29 #include <BRepTools.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #define CALCULATION_REGIONS_PREF GetName() + "_Reg"
39 #define CALCULATION_ZONES_PREF GetName() + "_Zone"
40 #define CALCULATION_GROUPS_PREF GetName() + "_"
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 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
73 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
74 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
75 for ( ; anIter.More(); anIter.Next() )
77 Handle(HYDROData_Zone) aRegZone =
78 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
79 if ( aRegZone.IsNull() )
82 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
86 HYDROData_SequenceOfObjects aGroups = GetGeometryGroups();
88 anIter.Init( aGroups );
89 for ( ; anIter.More(); anIter.Next() )
91 Handle(HYDROData_SplittedShapesGroup) aGroup =
92 Handle(HYDROData_SplittedShapesGroup)::DownCast( anIter.Value() );
93 if ( aGroup.IsNull() )
96 HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
100 HYDROData_Entity::SetName( theName );
103 QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
105 QStringList aResList = dumpObjectCreation( theTreatedObjects );
106 QString aCalculName = GetName();
108 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
109 HYDROData_SequenceOfObjects::Iterator anIter( aGeomObjects );
110 for ( ; anIter.More(); anIter.Next() )
112 Handle(HYDROData_Object) aRefGeomObj =
113 Handle(HYDROData_Object)::DownCast( anIter.Value() );
114 if ( !aRefGeomObj.IsNull() )
115 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
117 aResList << QString( "" );
119 aResList << QString( "%1.SplitGeometryObjects();" ).arg( aCalculName );
120 aResList << QString( "" );
122 // Now we restore the regions and zones order
123 HYDROData_SequenceOfObjects aRegions = GetRegions();
124 anIter.Init( aRegions );
125 for ( ; anIter.More(); anIter.Next() )
127 Handle(HYDROData_Region) aRegion =
128 Handle(HYDROData_Region)::DownCast( anIter.Value() );
129 if ( aRegion.IsNull() )
132 QString aRegionName = aRegion->GetName();
139 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetAllReferenceObjects() const
141 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
143 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
144 if ( !aBoundaryPolyline.IsNull() )
145 aResSeq.Append( aBoundaryPolyline );
147 HYDROData_SequenceOfObjects aSeqOfRegions = GetRegions();
148 aResSeq.Append( aSeqOfRegions );
153 void HYDROData_CalculationCase::Update()
155 HYDROData_Entity::Update();
157 // At first we remove previously created objects
159 RemoveSplittedGroups();
161 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
162 if ( aDocument.IsNull() )
165 Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline();
166 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
167 if ( aGeomObjects.IsEmpty() )
170 HYDROData_SequenceOfObjects aGeomGroups = GetGeometryGroups();
172 HYDROData_SplitToZonesTool::SplitDataList aSplitedObjects =
173 HYDROData_SplitToZonesTool::Split( aGeomObjects, aGeomGroups, aBoundaryPolyline );
174 if ( aSplitedObjects.isEmpty() )
177 QString aRegsPref = CALCULATION_REGIONS_PREF;
178 QString aZonesPref = CALCULATION_ZONES_PREF;
180 QMap<QString,Handle(HYDROData_SplittedShapesGroup)> aSplittedEdgesGroupsMap;
182 // Create result regions for case, by default one zone for one region
183 HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedObjects );
184 while( anIter.hasNext() )
186 const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
188 if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Zone )
191 Handle(HYDROData_Region) aRegion = addNewRegion();
193 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
194 aRegion->SetName( aRegionName );
196 // Add the zone for region
197 Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
199 QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
200 aRegionZone->SetName( aZoneName );
202 aRegionZone->SetShape( aSplitData.Face() );
204 // Add the reference object for zone
205 for ( int i = 0, n = aSplitData.ObjectNames.length(); i < n; ++i )
207 const QString& anObjName = aSplitData.ObjectNames.at( i );
209 Handle(HYDROData_Object) aRefObject = Handle(HYDROData_Object)::DownCast(
210 HYDROData_Tool::FindObjectByName( aDocument, anObjName ) );
211 if ( aRefObject.IsNull() )
214 aRegionZone->AddGeometryObject( aRefObject );
217 else if ( aSplitData.Type == HYDROData_SplitToZonesTool::SplitData::Data_Edge )
219 // Create new edges group
220 if ( aSplitData.ObjectNames.isEmpty() || aSplitData.Shape.IsNull() )
223 QString anObjName = aSplitData.ObjectNames.first();
224 if ( anObjName.isEmpty() )
227 Handle(HYDROData_SplittedShapesGroup) aSplittedGroup;
228 if ( !aSplittedEdgesGroupsMap.contains( anObjName ) )
230 aSplittedGroup = addNewSplittedGroup();
232 QString aCalcGroupName = CALCULATION_GROUPS_PREF + anObjName;
233 aSplittedGroup->SetName( aCalcGroupName );
235 aSplittedEdgesGroupsMap.insert( anObjName, aSplittedGroup );
239 aSplittedGroup = aSplittedEdgesGroupsMap[ anObjName ];
242 if ( aSplittedGroup.IsNull() )
245 aSplittedGroup->AddShape( aSplitData.Shape );
250 bool HYDROData_CalculationCase::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
252 if ( !HYDROData_Tool::IsGeometryObject( theObject ) )
253 return false; // Wrong type of object
255 if ( HasReference( theObject, DataTag_GeometryObject ) )
256 return false; // Object is already in reference list
258 AddReferenceObject( theObject, DataTag_GeometryObject );
260 // Indicate model of the need to update splitting
266 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryObjects() const
268 return GetReferenceObjects( DataTag_GeometryObject );
271 void HYDROData_CalculationCase::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject )
273 if ( theObject.IsNull() )
276 RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject );
278 // Indicate model of the need to update splitting
282 void HYDROData_CalculationCase::RemoveGeometryObjects()
284 ClearReferenceObjects( DataTag_GeometryObject );
286 // Indicate model of the need to update splitting
290 bool HYDROData_CalculationCase::AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
292 if ( theGroup.IsNull() )
295 if ( HasReference( theGroup, DataTag_GeometryGroup ) )
296 return false; // Object is already in reference list
298 AddReferenceObject( theGroup, DataTag_GeometryGroup );
300 // Indicate model of the need to update splitting
306 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetGeometryGroups() const
308 return GetReferenceObjects( DataTag_GeometryGroup );
311 void HYDROData_CalculationCase::RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup )
313 if ( theGroup.IsNull() )
316 RemoveReferenceObject( theGroup->Label(), DataTag_GeometryGroup );
318 // Indicate model of the need to update splitting
322 void HYDROData_CalculationCase::RemoveGeometryGroups()
324 ClearReferenceObjects( DataTag_GeometryGroup );
326 // Indicate model of the need to update splitting
330 void HYDROData_CalculationCase::SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline )
332 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
334 SetReferenceObject( thePolyline, DataTag_Polyline );
336 // Indicate model of the need to update zones splitting
337 SetToUpdate( !IsEqual( aPrevPolyline, thePolyline ) || IsMustBeUpdated() );
340 Handle(HYDROData_PolylineXY) HYDROData_CalculationCase::GetBoundaryPolyline() const
342 return Handle(HYDROData_PolylineXY)::DownCast(
343 GetReferenceObject( DataTag_Polyline ) );
346 void HYDROData_CalculationCase::RemoveBoundaryPolyline()
348 Handle(HYDROData_PolylineXY) aPrevPolyline = GetBoundaryPolyline();
350 ClearReferenceObjects( DataTag_Polyline );
352 // Indicate model of the need to update zones splitting
353 SetToUpdate( !aPrevPolyline.IsNull() || IsMustBeUpdated() );
356 Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
358 Handle(HYDROData_Region) aNewRegion = addNewRegion();
359 if ( aNewRegion.IsNull() )
362 // Generate new name for new region
363 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
364 if ( !aDocument.IsNull() )
366 QString aRegsPref = CALCULATION_REGIONS_PREF;
368 QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
369 aNewRegion->SetName( aNewRegionName );
372 aNewRegion->AddZone( theZone );
377 bool HYDROData_CalculationCase::AddRegion( const Handle(HYDROData_Region)& theRegion )
379 if ( theRegion.IsNull() )
382 if ( HasReference( theRegion, DataTag_Region ) )
383 return false; // Object is already in reference list
385 // Move the region from other calculation
386 Handle(HYDROData_CalculationCase) aFatherCalc =
387 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
388 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
390 Handle(HYDROData_Region) aNewRegion = addNewRegion();
391 theRegion->CopyTo( aNewRegion );
393 aFatherCalc->RemoveRegion( theRegion );
395 theRegion->SetLabel( aNewRegion->Label() );
399 AddReferenceObject( theRegion, DataTag_Region );
405 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
407 return GetReferenceObjects( DataTag_Region );
410 void HYDROData_CalculationCase::UpdateRegionsOrder()
412 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
413 if ( aDocument.IsNull() )
416 HYDROData_SequenceOfObjects aRegions = GetRegions();
418 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
419 for ( ; anIter.More(); anIter.Next() )
421 Handle(HYDROData_Region) aRegion =
422 Handle(HYDROData_Region)::DownCast( anIter.Value() );
423 if ( aRegion.IsNull() )
426 aRegion->SetName( "" );
429 QString aRegsPref = CALCULATION_REGIONS_PREF;
431 anIter.Init( aRegions );
432 for ( ; anIter.More(); anIter.Next() )
434 Handle(HYDROData_Region) aRegion =
435 Handle(HYDROData_Region)::DownCast( anIter.Value() );
436 if ( aRegion.IsNull() )
439 QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
440 aRegion->SetName( aRegionName );
444 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
446 if ( theRegion.IsNull() )
449 RemoveReferenceObject( theRegion->Label(), DataTag_Region );
451 // Remove region from data model
452 Handle(HYDROData_CalculationCase) aFatherCalc =
453 Handle(HYDROData_CalculationCase)::DownCast( theRegion->GetFatherObject() );
454 if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
458 void HYDROData_CalculationCase::RemoveRegions()
460 myLab.FindChild( DataTag_ChildRegion ).ForgetAllAttributes();
463 HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetSplittedGroups() const
465 return GetReferenceObjects( DataTag_SplittedGroups );
468 void HYDROData_CalculationCase::RemoveSplittedGroups()
470 myLab.FindChild( DataTag_SplittedGroups ).ForgetAllAttributes();
473 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
475 double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
477 Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
478 if ( aZone.IsNull() )
481 HYDROData_Zone::MergeAltitudesType aZoneMergeType = aZone->GetMergeType();
482 if ( !aZone->IsMergingNeed() )
484 aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
486 else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
491 if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
493 Handle(HYDROData_IAltitudeObject) aMergeAltitude = aZone->GetMergeAltitude();
494 if ( !aMergeAltitude.IsNull() )
495 aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
499 HYDROData_SequenceOfObjects aZoneObjects = aZone->GetGeometryObjects();
500 HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
501 for ( ; anIter.More(); anIter.Next() )
503 Handle(HYDROData_Object) aZoneObj =
504 Handle(HYDROData_Object)::DownCast( anIter.Value() );
505 if ( aZoneObj.IsNull() )
508 Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
509 if ( anObjAltitude.IsNull() )
512 double aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
513 if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
516 if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
518 aResAltitude = aPointAltitude;
521 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
523 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
524 aResAltitude > aPointAltitude )
526 aResAltitude = aPointAltitude;
529 else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
531 if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
532 aResAltitude < aPointAltitude )
534 aResAltitude = aPointAltitude;
543 Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
545 Handle(HYDROData_Zone) aResZone;
547 HYDROData_SequenceOfObjects aRegions = GetRegions();
549 HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
550 for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
552 Handle(HYDROData_Region) aRegion =
553 Handle(HYDROData_Region)::DownCast( anIter.Value() );
554 if ( aRegion.IsNull() )
557 HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
558 HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
559 for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
561 Handle(HYDROData_Zone) aRegZone =
562 Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
563 if ( aRegZone.IsNull() )
566 PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
567 if ( aPointRelation != POINT_OUT )
568 aResZone = aRegZone; // We found the desired zone
575 HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
576 const gp_XY& thePoint,
577 const Handle(HYDROData_Zone)& theZone ) const
579 PointClassification aRes = POINT_OUT;
580 if ( theZone.IsNull() )
583 TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
584 if ( aZoneFace.IsNull() )
587 BRepTopAdaptor_FClass2d aClassifier( aZoneFace, Precision::Confusion() );
588 TopAbs_State State = aClassifier.Perform( gp_Pnt2d(thePoint), Standard_False );
589 if (State == TopAbs_OUT)
591 else if(State == TopAbs_IN)
593 else if(State == TopAbs_ON)
598 Handle(HYDROData_Region) HYDROData_CalculationCase::addNewRegion()
600 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildRegion ).NewChild();
602 Handle(HYDROData_Region) aNewRegion =
603 Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
604 AddRegion( aNewRegion );
609 Handle(HYDROData_SplittedShapesGroup) HYDROData_CalculationCase::addNewSplittedGroup()
611 TDF_Label aNewLab = myLab.FindChild( DataTag_SplittedGroups ).NewChild();
613 Handle(HYDROData_SplittedShapesGroup) aNewGroup =
614 Handle(HYDROData_SplittedShapesGroup)::DownCast(
615 HYDROData_Iterator::CreateObject( aNewLab, KIND_SPLITTED_GROUP ) );
616 AddReferenceObject( aNewGroup, DataTag_SplittedGroups );
621 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
622 SALOMEDS::Study_ptr theStudy ) const
624 HYDROData_ShapesGroup::SeqOfGroupsDefs aSeqOfGroupsDefs;
626 // Get groups definitions
627 HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
629 HYDROData_SequenceOfObjects::Iterator anIter( aSplittedGroups );
630 for ( ; anIter.More(); anIter.Next() )
633 Handle(HYDROData_ShapesGroup) aGroup =
634 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
635 if ( aGroup.IsNull() )
638 HYDROData_ShapesGroup::GroupDefinition aGroupDef;
640 aGroupDef.Name = aGroup->GetName().toLatin1().constData();
641 aGroup->GetShapes( aGroupDef.Shapes );
643 aSeqOfGroupsDefs.Append( aGroupDef );
647 TopTools_ListOfShape aFaces;
648 HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
649 HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
650 for ( ; aRegionIter.More(); aRegionIter.Next() )
652 Handle(HYDROData_Region) aRegion =
653 Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
654 if( aRegion.IsNull() )
657 TopoDS_Shape aRegionShape = aRegion->GetShape( &aSeqOfGroupsDefs );
658 aFaces.Append( aRegionShape );
661 return Export( theGeomEngine, theStudy, aFaces, aSeqOfGroupsDefs );
664 bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
665 SALOMEDS::Study_ptr theStudy,
666 const TopTools_ListOfShape& theFaces,
667 const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs ) const
670 BRepBuilderAPI_Sewing aSewing( Precision::Confusion() * 10.0 );
671 aSewing.SetNonManifoldMode( Standard_True );
673 TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
674 for ( ; aFaceIter.More(); aFaceIter.Next() )
676 TopoDS_Shape aShape = aFaceIter.Value();
677 if ( aShape.IsNull() )
680 if ( aShape.ShapeType() == TopAbs_FACE )
682 aSewing.Add( aShape );
686 TopExp_Explorer anExp( aShape, TopAbs_FACE );
687 for ( ; anExp.More(); anExp.Next() )
688 aSewing.Add( anExp.Current() );
693 TopoDS_Shape aSewedShape = aSewing.SewedShape();
695 // If the sewed shape is empty - return false
696 if ( aSewedShape.IsNull() || !TopoDS_Iterator( aSewedShape ).More() )
699 // Publish the sewed shape
700 QString aName = EXPORT_NAME;
701 GEOM::GEOM_Object_ptr aMainShape =
702 publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
704 if ( aMainShape->_is_nil() )
707 if ( theGroupsDefs.IsEmpty() )
711 TopTools_IndexedMapOfShape aMapOfSubShapes;
712 TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
714 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> > aGroupsData;
716 for ( int aGrId = 1, nbGroups = theGroupsDefs.Length(); aGrId <= nbGroups; ++aGrId )
718 const HYDROData_ShapesGroup::GroupDefinition& aGroupDef = theGroupsDefs.Value( aGrId );
720 NCollection_Sequence<int> aGroupIndexes;
721 for( int i = 1, n = aGroupDef.Shapes.Length(); i <= n; i++ )
723 const TopoDS_Shape& aShape = aGroupDef.Shapes.Value( i );
725 const TopoDS_Shape& aModifiedShape = aSewing.Modified( aShape );
726 if ( aModifiedShape.IsNull() )
729 // Workaround for TopTools_IndexedMapOfShape::FindIndex()
730 for ( int anIndex = 1; anIndex <= aMapOfSubShapes.Extent(); anIndex++ )
732 if ( aModifiedShape.IsPartner( aMapOfSubShapes.FindKey( anIndex ) ) )
734 aGroupIndexes.Append( anIndex );
740 if ( !aGroupIndexes.IsEmpty() )
741 aGroupsData.Bind( aGroupDef.Name, aGroupIndexes );
744 if ( !aGroupsData.IsEmpty() )
746 GEOM::GEOM_IGroupOperations_var aGroupOp =
747 theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
749 NCollection_DataMap< TCollection_AsciiString, NCollection_Sequence<int> >::Iterator aMapIt( aGroupsData );
750 for ( ; aMapIt.More(); aMapIt.Next() )
752 const TCollection_AsciiString& aGroupName = aMapIt.Key();
753 const NCollection_Sequence<int>& aGroupIndexes = aMapIt.Value();
755 GEOM::GEOM_Object_var aGeomGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
756 if ( CORBA::is_nil( aGeomGroup ) || !aGroupOp->IsDone() )
759 GEOM::ListOfLong_var aGeomIndexes = new GEOM::ListOfLong;
760 aGeomIndexes->length( aGroupIndexes.Length() );
762 for( int i = 1, n = aGroupIndexes.Length(); i <= n; i++ )
763 aGeomIndexes[ i - 1 ] = aGroupIndexes.Value( i );
765 aGroupOp->UnionIDs( aGeomGroup, aGeomIndexes );
766 if ( aGroupOp->IsDone() )
768 SALOMEDS::SObject_var aGroupSO =
769 theGeomEngine->AddInStudy( theStudy, aGeomGroup, aGroupName.ToCString(), aMainShape );
777 GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
778 GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
779 const TopoDS_Shape& theShape, const QString& theName ) const
781 GEOM::GEOM_Object_var aGeomObj;
783 if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
784 theShape.IsNull() ) {
785 return aGeomObj._retn();
788 std::ostringstream aStreamShape;
789 // Write TopoDS_Shape in ASCII format to the stream
790 BRepTools::Write( theShape, aStreamShape );
791 // Returns the number of bytes that have been stored in the stream's buffer.
792 int aSize = aStreamShape.str().size();
793 // Allocate octect buffer of required size
794 CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
795 // Copy ostrstream content to the octect buffer
796 memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
798 SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
800 // Restore shape from the stream and get the GEOM object
801 GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
802 aGeomObj = anInsOp->RestoreShape( aSeqFile );
804 // Puplish the GEOM object
805 if ( !aGeomObj->_is_nil() ) {
806 QString aName = GEOMBase::GetDefaultName( theName );
808 SALOMEDS::SObject_var aResultSO =
809 theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
810 aGeomObj, qPrintable( aName ) );
811 if ( aResultSO->_is_nil() ) {
812 aGeomObj = GEOM::GEOM_Object::_nil();
816 return aGeomObj._retn();