+ TListOfNewGroups& aNewGroups = anIter->second;
+ string aNewGroupName;
+ if (aNewGroups.size() == 1) {
+ aNewGroupName = string(aGroupName) + "_1";
+ aNewGroups.front()->SetName(aNewGroupName.c_str());
+ }
+ char aGroupNum[128];
+ sprintf(aGroupNum, "%u", aNewGroups.size()+1);
+ aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
+ aNewGroup->SetName(aNewGroupName.c_str());
+ aNewGroups.push_back(aNewGroup);
+ }
+ }//groups loop
+ }
+ }
+ }//meshes loop
+
+ if (theMergeNodesAndElements) {
+ // merge nodes
+ set<const SMDS_MeshNode*> aMeshNodes; // no input nodes
+ SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
+ aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
+ aNewEditor.MergeNodes( aGroupsOfNodes );
+ // merge elements
+ aNewEditor.MergeEqualElements();
+ }
+ }
+ }
+
+ // Update Python script
+ aPythonDump << aNewMesh << " = " << this << ".Concatenate(";
+ aPythonDump << "[";
+ for ( int i = 0; i < theMeshesArray.length(); i++) {
+ if (i > 0) aPythonDump << ", ";
+ aPythonDump << theMeshesArray[i];
+ }
+ aPythonDump << "], ";
+ aPythonDump << theUniteIdenticalGroups << ", "
+ << theMergeNodesAndElements << ", "
+ << theMergeTolerance << ")";
+
+ return aNewMesh._retn();
+}
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::Save
+ *
+ * Save SMESH module's data
+ */
+//=============================================================================
+SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
+ const char* theURL,
+ bool isMultiFile )
+{
+ INFOS( "SMESH_Gen_i::Save" );
+
+ // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
+ // san -- in case <myCurrentStudy> differs from theComponent's study,
+ // use that of the component
+ if ( myCurrentStudy->_is_nil() ||
+ theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
+ SetCurrentStudy( theComponent->GetStudy() );
+
+ // Store study contents as a set of python commands
+ SavePython(myCurrentStudy);
+
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+
+ // Declare a byte stream
+ SALOMEDS::TMPFile_var aStreamFile;
+
+ // Obtain a temporary dir
+ TCollection_AsciiString tmpDir =
+ ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
+
+ // Create a sequence of files processed
+ SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
+ aFileSeq->length( NUM_TMP_FILES );
+
+ TCollection_AsciiString aStudyName( "" );
+ if ( isMultiFile )
+ aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
+
+ // Set names of temporary files
+ TCollection_AsciiString filename =
+ aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
+ TCollection_AsciiString meshfile =
+ aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
+ aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
+ aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
+ filename = tmpDir + filename;
+ meshfile = tmpDir + meshfile;
+
+ HDFfile* aFile;
+ HDFdataset* aDataset;
+ HDFgroup* aTopGroup;
+ HDFgroup* aGroup;
+ HDFgroup* aSubGroup;
+ HDFgroup* aSubSubGroup;
+ hdf_size aSize[ 1 ];
+
+
+ //Remove the files if they exist: BugID: 11225
+#ifndef WNT /* unix functionality */
+ TCollection_AsciiString cmd("rm -f \"");
+#else /* windows */
+ TCollection_AsciiString cmd("del /F \"");
+#endif
+
+ cmd+=filename;
+ cmd+="\" \"";
+ cmd+=meshfile;
+ cmd+="\"";
+ system(cmd.ToCString());
+
+ // MED writer to be used by storage process
+ DriverMED_W_SMESHDS_Mesh myWriter;
+ myWriter.SetFile( meshfile.ToCString() );
+
+ // Write data
+ // ---> create HDF file
+ aFile = new HDFfile( filename.ToCString() );
+ aFile->CreateOnDisk();
+
+ // --> iterator for top-level objects
+ SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
+ for ( ; itBig->More(); itBig->Next() ) {
+ SALOMEDS::SObject_var gotBranch = itBig->Value();
+
+ // --> hypotheses root branch (only one for the study)
+ if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
+ // create hypotheses root HDF group
+ aTopGroup = new HDFgroup( "Hypotheses", aFile );
+ aTopGroup->CreateOnDisk();
+
+ // iterator for all hypotheses
+ SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
+ for ( ; it->More(); it->Next() ) {
+ SALOMEDS::SObject_var mySObject = it->Value();
+ CORBA::Object_var anObject = SObjectToObject( mySObject );
+ if ( !CORBA::is_nil( anObject ) ) {
+ SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
+ if ( !myHyp->_is_nil() ) {
+ SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
+ if ( myImpl ) {
+ string hypname = string( myHyp->GetName() );
+ string libname = string( myHyp->GetLibName() );
+ // BUG SWP13062
+ // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
+ // WNT and ".so" for X-system) must be deleted
+ int libname_len = libname.length();
+#ifdef WNT
+ if( libname_len > 4 )
+ libname.resize( libname_len - 4 );
+#else
+ // PAL17753 (Regresion: missing hypothesis in restored study)
+ // "lib" also should be removed from the beginning
+ //if( libname_len > 3 )
+ //libname.resize( libname_len - 3 );
+ if( libname_len > 6 )
+ libname = libname.substr( 3, libname_len - 3 - 3 );
+#endif
+ CORBA::String_var objStr = GetORB()->object_to_string( anObject );
+ int id = myStudyContext->findId( string( objStr.in() ) );
+ string hypdata = string( myImpl->SaveTo() );
+
+ // for each hypothesis create HDF group basing on its id
+ char hypGrpName[30];
+ sprintf( hypGrpName, "Hypothesis %d", id );
+ aGroup = new HDFgroup( hypGrpName, aTopGroup );
+ aGroup->CreateOnDisk();
+ // --> type name of hypothesis
+ aSize[ 0 ] = hypname.length() + 1;
+ aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
+ aDataset->CloseOnDisk();
+ // --> server plugin library name of hypothesis
+ aSize[ 0 ] = libname.length() + 1;
+ aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
+ aDataset->CloseOnDisk();
+ // --> persistent data of hypothesis
+ aSize[ 0 ] = hypdata.length() + 1;
+ aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
+ aDataset->CloseOnDisk();
+ // close hypothesis HDF group
+ aGroup->CloseOnDisk();
+ }
+ }
+ }
+ }
+ // close hypotheses root HDF group
+ aTopGroup->CloseOnDisk();
+ }
+ // --> algorithms root branch (only one for the study)
+ else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
+ // create algorithms root HDF group
+ aTopGroup = new HDFgroup( "Algorithms", aFile );
+ aTopGroup->CreateOnDisk();
+
+ // iterator for all algorithms
+ SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
+ for ( ; it->More(); it->Next() ) {
+ SALOMEDS::SObject_var mySObject = it->Value();
+ CORBA::Object_var anObject = SObjectToObject( mySObject );
+ if ( !CORBA::is_nil( anObject ) ) {
+ SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
+ if ( !myHyp->_is_nil() ) {
+ SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
+ if ( myImpl ) {
+ string hypname = string( myHyp->GetName() );
+ string libname = string( myHyp->GetLibName() );
+ // BUG SWP13062
+ // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
+ // WNT and ".so" for X-system) must be deleted
+ int libname_len = libname.length();
+#ifdef WNT
+ if( libname_len > 4 )
+ libname.resize( libname_len - 4 );
+#else
+ // PAL17753 (Regresion: missing hypothesis in restored study)
+ // "lib" also should be removed from the beginning
+ //if( libname_len > 3 )
+ //libname.resize( libname_len - 3 );
+ if( libname_len > 6 )
+ libname = libname.substr( 3, libname_len - 3 - 3 );
+#endif
+ CORBA::String_var objStr = GetORB()->object_to_string( anObject );
+ int id = myStudyContext->findId( string( objStr.in() ) );
+ string hypdata = string( myImpl->SaveTo() );
+
+ // for each algorithm create HDF group basing on its id
+ char hypGrpName[30];
+ sprintf( hypGrpName, "Algorithm %d", id );
+ aGroup = new HDFgroup( hypGrpName, aTopGroup );
+ aGroup->CreateOnDisk();
+ // --> type name of algorithm
+ aSize[0] = hypname.length() + 1;
+ aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
+ aDataset->CloseOnDisk();
+ // --> server plugin library name of hypothesis
+ aSize[0] = libname.length() + 1;
+ aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
+ aDataset->CloseOnDisk();
+ // --> persistent data of algorithm
+ aSize[0] = hypdata.length() + 1;
+ aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
+ aDataset->CloseOnDisk();
+ // close algorithm HDF group
+ aGroup->CloseOnDisk();
+ }
+ }
+ }
+ }
+ // close algorithms root HDF group
+ aTopGroup->CloseOnDisk();
+ }
+ // --> mesh objects roots branches
+ else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
+ CORBA::Object_var anObject = SObjectToObject( gotBranch );
+ if ( !CORBA::is_nil( anObject ) ) {
+ SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
+ if ( !myMesh->_is_nil() ) {
+ SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
+ if ( myImpl ) {
+ CORBA::String_var objStr = GetORB()->object_to_string( anObject );
+ int id = myStudyContext->findId( string( objStr.in() ) );
+ ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
+ SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
+ bool hasShape = myLocMesh.HasShapeToMesh();
+
+ // for each mesh open the HDF group basing on its id
+ char meshGrpName[ 30 ];
+ sprintf( meshGrpName, "Mesh %d", id );
+ aTopGroup = new HDFgroup( meshGrpName, aFile );
+ aTopGroup->CreateOnDisk();
+
+ // --> put dataset to hdf file which is a flag that mesh has data
+ string strHasData = "0";
+ // check if the mesh is not empty
+ if ( mySMESHDSMesh->NbNodes() > 0 ) {
+ // write mesh data to med file
+ myWriter.SetMesh( mySMESHDSMesh );
+ myWriter.SetMeshId( id );
+ strHasData = "1";
+ }
+ aSize[ 0 ] = strHasData.length() + 1;
+ aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
+ aDataset->CloseOnDisk();
+
+ // ouv : NPAL12872
+ // for each mesh open the HDF group basing on its auto color parameter
+ char meshAutoColorName[ 30 ];
+ sprintf( meshAutoColorName, "AutoColorMesh %d", id );
+ int anAutoColor[1];
+ anAutoColor[0] = myImpl->GetAutoColor();
+ aSize[ 0 ] = 1;
+ aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( anAutoColor );
+ aDataset->CloseOnDisk();
+
+ // write reference on a shape if exists
+ SALOMEDS::SObject_var myRef;
+ bool shapeRefFound = false;
+ bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
+ if ( found ) {
+ SALOMEDS::SObject_var myShape;
+ bool ok = myRef->ReferencedObject( myShape );
+ if ( ok ) {
+ shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
+ string myRefOnObject = myShape->GetID();
+ if ( shapeRefFound && myRefOnObject.length() > 0 ) {
+ aSize[ 0 ] = myRefOnObject.length() + 1;
+ aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->CloseOnDisk();
+ }
+ }
+ }
+
+ // write applied hypotheses if exist
+ SALOMEDS::SObject_var myHypBranch;
+ found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
+ if ( found && !shapeRefFound && hasShape) { // remove applied hyps
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
+ }
+ if ( found && (shapeRefFound || !hasShape) ) {
+ aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
+ aGroup->CreateOnDisk();
+
+ SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
+ int hypNb = 0;
+ for ( ; it->More(); it->Next() ) {
+ SALOMEDS::SObject_var mySObject = it->Value();
+ SALOMEDS::SObject_var myRefOnHyp;
+ bool ok = mySObject->ReferencedObject( myRefOnHyp );
+ if ( ok ) {
+ // san - it is impossible to recover applied hypotheses
+ // using their entries within Load() method,
+ // for there are no AttributeIORs in the study when Load() is working.
+ // Hence, it is better to store persistent IDs of hypotheses as references to them
+
+ //string myRefOnObject = myRefOnHyp->GetID();
+ CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
+ CORBA::String_var objStr = GetORB()->object_to_string( anObject );
+ int id = myStudyContext->findId( string( objStr.in() ) );
+ //if ( myRefOnObject.length() > 0 ) {
+ //aSize[ 0 ] = myRefOnObject.length() + 1;
+ char hypName[ 30 ], hypId[ 30 ];
+ sprintf( hypName, "Hyp %d", ++hypNb );
+ sprintf( hypId, "%d", id );
+ aSize[ 0 ] = strlen( hypId ) + 1;
+ aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->WriteOnDisk( hypId );
+ aDataset->CloseOnDisk();
+ //}
+ }
+ }
+ aGroup->CloseOnDisk();
+ }
+
+ // write applied algorithms if exist
+ SALOMEDS::SObject_var myAlgoBranch;
+ found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
+ if ( found && !shapeRefFound && hasShape) { // remove applied algos
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
+ }
+ if ( found && (shapeRefFound || !hasShape)) {
+ aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
+ aGroup->CreateOnDisk();
+
+ SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
+ int algoNb = 0;
+ for ( ; it->More(); it->Next() ) {
+ SALOMEDS::SObject_var mySObject = it->Value();
+ SALOMEDS::SObject_var myRefOnAlgo;
+ bool ok = mySObject->ReferencedObject( myRefOnAlgo );
+ if ( ok ) {
+ // san - it is impossible to recover applied algorithms
+ // using their entries within Load() method,
+ // for there are no AttributeIORs in the study when Load() is working.
+ // Hence, it is better to store persistent IDs of algorithms as references to them
+
+ //string myRefOnObject = myRefOnAlgo->GetID();
+ CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
+ CORBA::String_var objStr = GetORB()->object_to_string( anObject );
+ int id = myStudyContext->findId( string( objStr.in() ) );
+ //if ( myRefOnObject.length() > 0 ) {
+ //aSize[ 0 ] = myRefOnObject.length() + 1;
+ char algoName[ 30 ], algoId[ 30 ];
+ sprintf( algoName, "Algo %d", ++algoNb );
+ sprintf( algoId, "%d", id );
+ aSize[ 0 ] = strlen( algoId ) + 1;
+ aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->WriteOnDisk( algoId );
+ aDataset->CloseOnDisk();
+ //}
+ }
+ }
+ aGroup->CloseOnDisk();
+ }
+
+ // --> submesh objects sub-branches
+
+ for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
+ SALOMEDS::SObject_var mySubmeshBranch;
+ found = gotBranch->FindSubObject( i, mySubmeshBranch );
+
+ if ( found ) // check if there is shape reference in submeshes
+ {
+ bool hasShapeRef = false;
+ SALOMEDS::ChildIterator_var itSM =
+ myCurrentStudy->NewChildIterator( mySubmeshBranch );
+ for ( ; itSM->More(); itSM->Next() ) {
+ SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
+ if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
+ mySubRef->ReferencedObject( myShape );
+ if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
+ hasShapeRef = true;
+ else
+ { // remove one submesh
+ if ( shapeRefFound )
+ { // unassign hypothesis
+ SMESH::SMESH_subMesh_var mySubMesh =
+ SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
+ if ( !mySubMesh->_is_nil() ) {
+ int shapeID = mySubMesh->GetId();
+ TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
+ const list<const SMESHDS_Hypothesis*>& hypList =
+ mySMESHDSMesh->GetHypothesis( S );
+ list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
+ while ( hyp != hypList.end() ) {
+ int hypID = (*hyp++)->GetID(); // goto next hyp here because
+ myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
+ }
+ }
+ }
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
+ }
+ } // loop on submeshes of a type
+ if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
+ myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
+ found = false;
+ }
+ } // end check if there is shape reference in submeshes
+ if ( found ) {
+ char name_meshgroup[ 30 ];
+ if ( i == GetSubMeshOnVertexTag() )
+ strcpy( name_meshgroup, "SubMeshes On Vertex" );
+ else if ( i == GetSubMeshOnEdgeTag() )
+ strcpy( name_meshgroup, "SubMeshes On Edge" );
+ else if ( i == GetSubMeshOnWireTag() )
+ strcpy( name_meshgroup, "SubMeshes On Wire" );
+ else if ( i == GetSubMeshOnFaceTag() )
+ strcpy( name_meshgroup, "SubMeshes On Face" );
+ else if ( i == GetSubMeshOnShellTag() )
+ strcpy( name_meshgroup, "SubMeshes On Shell" );
+ else if ( i == GetSubMeshOnSolidTag() )
+ strcpy( name_meshgroup, "SubMeshes On Solid" );
+ else if ( i == GetSubMeshOnCompoundTag() )
+ strcpy( name_meshgroup, "SubMeshes On Compound" );
+
+ // for each type of submeshes create container HDF group
+ aGroup = new HDFgroup( name_meshgroup, aTopGroup );
+ aGroup->CreateOnDisk();
+
+ // iterator for all submeshes of given type
+ SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
+ for ( ; itSM->More(); itSM->Next() ) {
+ SALOMEDS::SObject_var mySObject = itSM->Value();
+ CORBA::Object_var anSubObject = SObjectToObject( mySObject );
+ if ( !CORBA::is_nil( anSubObject ))
+ {
+ SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
+ CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
+ int subid = myStudyContext->findId( string( objStr.in() ) );
+
+ // for each mesh open the HDF group basing on its id
+ char submeshGrpName[ 30 ];
+ sprintf( submeshGrpName, "SubMesh %d", subid );
+ aSubGroup = new HDFgroup( submeshGrpName, aGroup );
+ aSubGroup->CreateOnDisk();
+
+ // write reference on a shape, already checked if it exists
+ SALOMEDS::SObject_var mySubRef, myShape;
+ if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
+ mySubRef->ReferencedObject( myShape );
+ string myRefOnObject = myShape->GetID();
+ if ( myRefOnObject.length() > 0 ) {
+ aSize[ 0 ] = myRefOnObject.length() + 1;
+ aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->CloseOnDisk();
+ }
+
+ // write applied hypotheses if exist
+ SALOMEDS::SObject_var mySubHypBranch;
+ found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
+ if ( found ) {
+ aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
+ aSubSubGroup->CreateOnDisk();
+
+ SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
+ int hypNb = 0;
+ for ( ; it->More(); it->Next() ) {
+ SALOMEDS::SObject_var mySubSObject = it->Value();
+ SALOMEDS::SObject_var myRefOnHyp;
+ bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
+ if ( ok ) {
+ //string myRefOnObject = myRefOnHyp->GetID();
+ CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
+ CORBA::String_var objStr = GetORB()->object_to_string( anObject );
+ int id = myStudyContext->findId( string( objStr.in() ) );
+ //if ( myRefOnObject.length() > 0 ) {
+ //aSize[ 0 ] = myRefOnObject.length() + 1;
+ char hypName[ 30 ], hypId[ 30 ];
+ sprintf( hypName, "Hyp %d", ++hypNb );
+ sprintf( hypId, "%d", id );
+ aSize[ 0 ] = strlen( hypId ) + 1;
+ aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->WriteOnDisk( hypId );
+ aDataset->CloseOnDisk();
+ //}
+ }
+ }
+ aSubSubGroup->CloseOnDisk();
+ }
+
+ // write applied algorithms if exist
+ SALOMEDS::SObject_var mySubAlgoBranch;
+ found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
+ if ( found ) {
+ aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
+ aSubSubGroup->CreateOnDisk();
+
+ SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
+ int algoNb = 0;
+ for ( ; it->More(); it->Next() ) {
+ SALOMEDS::SObject_var mySubSObject = it->Value();
+ SALOMEDS::SObject_var myRefOnAlgo;
+ bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
+ if ( ok ) {
+ //string myRefOnObject = myRefOnAlgo->GetID();
+ CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
+ CORBA::String_var objStr = GetORB()->object_to_string( anObject );
+ int id = myStudyContext->findId( string( objStr.in() ) );
+ //if ( myRefOnObject.length() > 0 ) {
+ //aSize[ 0 ] = myRefOnObject.length() + 1;
+ char algoName[ 30 ], algoId[ 30 ];
+ sprintf( algoName, "Algo %d", ++algoNb );
+ sprintf( algoId, "%d", id );
+ aSize[ 0 ] = strlen( algoId ) + 1;
+ aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->WriteOnDisk( algoId );
+ aDataset->CloseOnDisk();
+ //}
+ }
+ }
+ aSubSubGroup->CloseOnDisk();
+ }
+ // close submesh HDF group
+ aSubGroup->CloseOnDisk();
+ }
+ }
+ // close container of submeshes by type HDF group
+ aGroup->CloseOnDisk();
+ }
+ }
+ // All sub-meshes will be stored in MED file
+ // .. will NOT (PAL 12992)
+ //if ( shapeRefFound )
+ //myWriter.AddAllSubMeshes();
+
+ // groups root sub-branch
+ SALOMEDS::SObject_var myGroupsBranch;
+ for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
+ found = gotBranch->FindSubObject( i, myGroupsBranch );
+ if ( found ) {
+ char name_group[ 30 ];
+ if ( i == GetNodeGroupsTag() )
+ strcpy( name_group, "Groups of Nodes" );
+ else if ( i == GetEdgeGroupsTag() )
+ strcpy( name_group, "Groups of Edges" );
+ else if ( i == GetFaceGroupsTag() )
+ strcpy( name_group, "Groups of Faces" );
+ else if ( i == GetVolumeGroupsTag() )
+ strcpy( name_group, "Groups of Volumes" );
+
+ aGroup = new HDFgroup( name_group, aTopGroup );
+ aGroup->CreateOnDisk();
+
+ SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
+ for ( ; it->More(); it->Next() ) {
+ SALOMEDS::SObject_var mySObject = it->Value();
+ CORBA::Object_var aSubObject = SObjectToObject( mySObject );
+ if ( !CORBA::is_nil( aSubObject ) ) {
+ SMESH_GroupBase_i* myGroupImpl =
+ dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
+ if ( !myGroupImpl )
+ continue;
+
+ CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
+ int anId = myStudyContext->findId( string( objStr.in() ) );
+
+ // For each group, create a dataset named "Group <group_persistent_id>"
+ // and store the group's user name into it
+ char grpName[ 30 ];
+ sprintf( grpName, "Group %d", anId );
+ char* aUserName = myGroupImpl->GetName();
+ aSize[ 0 ] = strlen( aUserName ) + 1;
+
+ aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( aUserName );
+ aDataset->CloseOnDisk();
+
+ // ouv : NPAL12872
+ // For each group, create a dataset named "Group <group_persistent_id> Color"
+ // and store the group's color into it
+ char grpColorName[ 30 ];
+ sprintf( grpColorName, "ColorGroup %d", anId );
+ SALOMEDS::Color aColor = myGroupImpl->GetColor();
+ double anRGB[3];
+ anRGB[ 0 ] = aColor.R;
+ anRGB[ 1 ] = aColor.G;
+ anRGB[ 2 ] = aColor.B;
+ aSize[ 0 ] = 3;
+ aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( anRGB );
+ aDataset->CloseOnDisk();
+
+ // Store the group contents into MED file
+ if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
+
+ if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
+ << grpName << " to MED file" );
+ SMESHDS_GroupBase* aGrpBaseDS =
+ myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
+ aGrpBaseDS->SetStoreName( grpName );
+
+ // Pass SMESHDS_Group to MED writer
+ SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
+ if ( aGrpDS )
+ myWriter.AddGroup( aGrpDS );
+
+ // write reference on a shape if exists
+ SMESHDS_GroupOnGeom* aGeomGrp =
+ dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
+ if ( aGeomGrp ) {
+ SALOMEDS::SObject_var mySubRef, myShape;
+ if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
+ mySubRef->ReferencedObject( myShape ) &&
+ !CORBA::is_nil( myShape->GetObject() ))
+ {
+ string myRefOnObject = myShape->GetID();
+ if ( myRefOnObject.length() > 0 ) {
+ char aRefName[ 30 ];
+ sprintf( aRefName, "Ref on shape %d", anId);
+ aSize[ 0 ] = myRefOnObject.length() + 1;
+ aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
+ aDataset->CreateOnDisk();
+ aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
+ aDataset->CloseOnDisk();
+ }
+ }
+ else // shape ref is invalid:
+ {
+ // save a group on geometry as ordinary group
+ myWriter.AddGroup( aGeomGrp );
+ }
+ }
+ }