+bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy )
+{
+ // Get faces
+ TopTools_ListOfShape aFaces;
+ HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
+ HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
+ for ( ; aRegionIter.More(); aRegionIter.Next() ) {
+ Handle(HYDROData_Region) aRegion =
+ Handle(HYDROData_Region)::DownCast( aRegionIter.Value() );
+ if( aRegion.IsNull() ) {
+ continue;
+ }
+
+ TopoDS_Shape aRegionShape = aRegion->GetShape();
+ aFaces.Append( aRegionShape );
+ }
+
+ // Get groups
+ HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
+
+ return Export( theGeomEngine, theStudy, aFaces, aSplittedGroups );
+}
+
+bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
+ SALOMEDS::Study_ptr theStudy,
+ const TopTools_ListOfShape& theFaces,
+ const HYDROData_SequenceOfObjects& theSplittedGroups )
+{
+ // Sew faces
+ BRepBuilderAPI_Sewing aSewing( Precision::Confusion()*10.0 );
+ aSewing.SetNonManifoldMode( Standard_True );
+
+ TopTools_ListIteratorOfListOfShape aFaceIter( theFaces );
+ for ( ; aFaceIter.More(); aFaceIter.Next() ) {
+ TopoDS_Shape aShape = aFaceIter.Value();
+ if ( !aShape.IsNull() && (aShape.ShapeType() == TopAbs_FACE) ) {
+ TopoDS_Face aFace = TopoDS::Face( aShape );
+ if ( !aFace.IsNull() ) {
+ aSewing.Add( aFace );
+ }
+ } else {
+ TopExp_Explorer anExp( aShape, TopAbs_FACE );
+ for ( ; anExp.More(); anExp.Next() ) {
+ TopoDS_Face aFace = TopoDS::Face( anExp.Current() );
+ if ( !aFace.IsNull() ) {
+ aSewing.Add( aFace );
+ }
+ }
+ }
+ } // faces iterator
+
+ aSewing.Perform();
+ TopoDS_Shape aSewedShape = aSewing.SewedShape();
+
+ // If the sewed shape is empty - return false
+ if ( aSewedShape.IsNull() || !TopoDS_Iterator(aSewedShape).More() ) {
+ return false;
+ }
+
+ // Publish the sewed shape
+ QString aName = EXPORT_NAME;
+ GEOM::GEOM_Object_ptr aMainShape =
+ publishShapeInGEOM( theGeomEngine, theStudy, aSewedShape, aName );
+
+ if ( aMainShape->_is_nil() ) {
+ return false;
+ }
+
+ // Create groups
+ TopTools_IndexedMapOfShape aMapOfSubShapes;
+ TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
+
+ QHash<QString, QSet<int> > aGroupsData;
+
+ HYDROData_SequenceOfObjects::Iterator anIter( theSplittedGroups );
+ for ( ; anIter.More(); anIter.Next() ) {
+ // Get shapes group
+ Handle(HYDROData_ShapesGroup) aGroup =
+ Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
+ if ( aGroup.IsNull() ) {
+ continue;
+ }
+
+ QSet<int> anIndexes;
+
+ // Get shapes of the group
+ TopTools_SequenceOfShape aShapes;
+ aGroup->GetShapes( aShapes );
+ for( int i = 1, aNbShapes = aShapes.Length(); i <= aNbShapes; i++ ) {
+ const TopoDS_Shape& aShape = aShapes.Value( i );
+ const TopoDS_Shape ModifiedShape = aSewing.Modified( aShape );
+ if ( !ModifiedShape.IsNull() ) {
+ int anIndex = aMapOfSubShapes.FindIndex( ModifiedShape );
+ if ( anIndex > 0 ) {
+ anIndexes << anIndex;
+ }
+ }
+ }
+
+ if ( anIndexes.count() > 0 ) {
+ aGroupsData.insert( aGroup->GetName(), anIndexes );
+ }
+ }
+
+ if ( !aGroupsData.isEmpty() ) {
+ GEOM::GEOM_IGroupOperations_var aGroupOp =
+ theGeomEngine->GetIGroupOperations( theStudy->StudyId() );
+
+ foreach ( const QString& aGroupName, aGroupsData.keys() ) {
+ QSet<int> aGroupIndexes = aGroupsData.value( aGroupName );
+
+ GEOM::GEOM_Object_var aGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
+ if ( !CORBA::is_nil(aGroup) && aGroupOp->IsDone() ) {
+ GEOM::ListOfLong_var anIndexes = new GEOM::ListOfLong;
+ anIndexes->length( aGroupIndexes.count() );
+ int aListIndex = 0;
+ foreach ( const int anIndex, aGroupIndexes ) {
+ anIndexes[aListIndex++] = anIndex;
+ }
+
+ aGroupOp->UnionIDs( aGroup, anIndexes );
+ if ( aGroupOp->IsDone() ) {
+ SALOMEDS::SObject_var aGroupSO =
+ theGeomEngine->AddInStudy( theStudy, aGroup, qPrintable( aGroupName ), aMainShape );
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
+ GEOM::GEOM_Gen_var theGeomEngine, SALOMEDS::Study_ptr theStudy,
+ const TopoDS_Shape& theShape, const QString& theName )
+{
+ GEOM::GEOM_Object_var aGeomObj;
+
+ if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
+ theShape.IsNull() ) {
+ return aGeomObj._retn();
+ }
+
+ std::ostringstream aStreamShape;
+ // Write TopoDS_Shape in ASCII format to the stream
+ BRepTools::Write( theShape, aStreamShape );
+ // Returns the number of bytes that have been stored in the stream's buffer.
+ int aSize = aStreamShape.str().size();
+ // Allocate octect buffer of required size
+ CORBA::Octet* anOctetBuf = SALOMEDS::TMPFile::allocbuf( aSize );
+ // Copy ostrstream content to the octect buffer
+ memcpy( anOctetBuf, aStreamShape.str().c_str(), aSize );
+ // Create TMPFile
+ SALOMEDS::TMPFile_var aSeqFile = new SALOMEDS::TMPFile( aSize, aSize, anOctetBuf, 1 );
+
+ // Restore shape from the stream and get the GEOM object
+ GEOM::GEOM_IInsertOperations_var anInsOp = theGeomEngine->GetIInsertOperations( theStudy->StudyId() );
+ aGeomObj = anInsOp->RestoreShape( aSeqFile );
+
+ // Puplish the GEOM object
+ if ( !aGeomObj->_is_nil() ) {
+ QString aName = GEOMBase::GetDefaultName( theName );
+
+ SALOMEDS::SObject_var aResultSO =
+ theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(),
+ aGeomObj, qPrintable( aName ) );
+ if ( aResultSO->_is_nil() ) {
+ aGeomObj = GEOM::GEOM_Object::_nil();
+ }
+ }