- SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR);
- if( !aMesh->_is_nil() )
- return true;
-
- SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
- if( !aSubMesh->_is_nil() )
- return true;
-
- SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR);
- if( !aHyp->_is_nil() )
- return true;
-
- SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(theIOR);
- if( !aGroup->_is_nil() )
- return true;
-
- return false;
-}
-
-//=============================================================================
-/*!
- * SMESH_Gen_i::PublishInStudy
- *
- * Publish object in the study
- */
-//=============================================================================
-
-SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
- SALOMEDS::SObject_ptr theSObject,
- CORBA::Object_ptr theIOR,
- const char* theName)
-throw (SALOME::SALOME_Exception)
-{
- Unexpect aCatch(SALOME_SalomeException);
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy()" );
- SALOMEDS::SObject_var aSO;
-
- // san - first try to find SObject corresponding to SMESH component in theStudy
- // It is dangerous to use FindComponent("MESH") for this, as some other component
- // of type "MESH" might be present in theStudy.
- // So component's user name obtained from ModuleCatalog is passed to FindObject()...
- SALOME_ModuleCatalog::ModuleCatalog_var aCat =
- SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
- if ( CORBA::is_nil( aCat ) )
- return aSO._retn();
-
- SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( "SMESH" );
- if ( CORBA::is_nil( aComp ) )
- return aSO._retn();
-
- SALOMEDS::SComponent_var father =
- SALOMEDS::SComponent::_narrow( theStudy->FindObject( strdup( aComp->componentusername() ) ) );
- SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
-
- SALOMEDS::GenericAttribute_var anAttr;
- SALOMEDS::AttributeName_var aName;
- SALOMEDS::AttributePixMap_var aPixmap;
-
- if ( father->_is_nil() ) {
- father = aStudyBuilder->NewComponent( "MESH" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( strdup( aComp->componentusername() ) );
- anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" );
- aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
- }
-
- if ( father->_is_nil() )
- return aSO._retn();
-
- SALOMEDS::AttributeIOR_var anIOR;
- SALOMEDS::AttributeSelectable_var aSelAttr;
- TCollection_AsciiString anObjName("obj");
-
- // Publishing a mesh
- SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
- if( !aMesh->_is_nil() ) {
- // Find correct free tag
- long aTag = FindMaxChildTag( father.in() );
- if ( aTag <= GetAlgorithmsRootTag() )
- aTag = GetAlgorithmsRootTag() + 1;
- else
- aTag++;
- // Add New Mesh
- SALOMEDS::SObject_var newMesh = aStudyBuilder->NewObjectToTag( father, aTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_SMESH_TREE_MESH" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- anIOR ->SetValue( GetORB()->object_to_string( aMesh ) );
- aSO = SALOMEDS::SObject::_narrow( newMesh );
- anObjName = TCollection_AsciiString( "Mesh" );
- }
-
- // Publishing a sub-mesh
- SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
- if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
- // try to obtain a parent mesh's SObject
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing submesh..." );
- SALOMEDS::SObject_var aParentSO;
- SMESH::SMESH_Mesh_var aParentMesh;
- SMESH_subMesh_i* aServant = dynamic_cast<SMESH_subMesh_i*>( GetServant( aSubMesh ).in() );
- if ( aServant != NULL ) {
- aParentMesh = aServant->_mesh_i->_this();
- if ( !aParentMesh->_is_nil() ) {
- aParentSO = theStudy->FindObjectIOR( GetORB()->object_to_string( aParentMesh ) );
- }
- }
-
- // Find submesh sub-tree tag
- if ( !aParentSO->_is_nil() ) {
- long aRootTag = GetSubMeshOnVertexTag();
- char* aRootName = "";
-
- SMESH_Mesh_i* aMeshServant = aServant->_mesh_i;
- if ( aMeshServant->_mapSubMesh.find( aServant->GetId() ) != aMeshServant->_mapSubMesh.end() ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): local submesh found" )
- SMESH_subMesh* aLocalSubMesh = aMeshServant->_mapSubMesh[aServant->GetId()];
- switch ( aLocalSubMesh->GetSubShape().ShapeType() ) {
- case TopAbs_VERTEX:
- aRootTag = GetSubMeshOnVertexTag();
- aRootName = "SubMeshes on Vertex";
- break;
- case TopAbs_EDGE:
- aRootTag = GetSubMeshOnEdgeTag();
- aRootName = "SubMeshes on Edge";
- break;
- case TopAbs_FACE:
- aRootTag = GetSubMeshOnFaceTag();
- aRootName = "SubMeshes on Face";
- break;
- case TopAbs_SOLID:
- aRootTag = GetSubMeshOnSolidTag();
- aRootName = "SubMeshes on Solid";
- break;
- default:
- aRootTag = GetSubMeshOnCompoundTag();
- aRootName = "SubMeshes on Compound";
- break;
- }
- }
-
- // Find or create submesh root
- SALOMEDS::SObject_var aRootSO;
- if ( !aParentSO->FindSubObject ( aRootTag, aRootSO ) ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): creating submesh root..." )
- aRootSO = aStudyBuilder->NewObjectToTag( aParentSO, aRootTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( aRootName );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeSelectable" );
- aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
- aSelAttr ->SetSelectable( false );
- }
-
- // Add new submesh to corresponding sub-tree
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): adding submesh to study..." )
- SALOMEDS::SObject_var newMesh = aStudyBuilder->NewObject( aRootSO );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_SMESH_TREE_MESH" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- anIOR ->SetValue( GetORB()->object_to_string( aSubMesh ) );
- aSO = SALOMEDS::SObject::_narrow( newMesh );
- anObjName = TCollection_AsciiString( "SubMesh" );
- }
- }
-
- // Publishing a hypothesis or algorithm
- SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
- if( aSO->_is_nil() && !aHyp->_is_nil() ) {
- //Find or Create Hypothesis root
- SALOMEDS::SObject_var HypothesisRoot;
- Standard_Integer aRootTag =
- SMESH::SMESH_Algo::_narrow( theIOR )->_is_nil() ? GetHypothesisRootTag() : GetAlgorithmsRootTag();
-
- if ( !father->FindSubObject ( aRootTag, HypothesisRoot ) ) {
- HypothesisRoot = aStudyBuilder->NewObjectToTag( father, aRootTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( aRootTag == GetHypothesisRootTag() ? "Hypotheses" : "Algorithms" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributeSelectable" );
- aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
- aSelAttr ->SetSelectable( false );
- anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( aRootTag == GetHypothesisRootTag() ? "ICON_SMESH_TREE_HYPO" : "ICON_SMESH_TREE_ALGO" );
- }
-
- // Add New Hypothesis
- string aPmName;
- SALOMEDS::SObject_var newHypo = aStudyBuilder->NewObject( HypothesisRoot );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newHypo, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPmName = ( aRootTag == GetHypothesisRootTag() ? "ICON_SMESH_TREE_HYPO_" : "ICON_SMESH_TREE_ALGO_" );
- aPmName += aHyp->GetName();
- aPixmap ->SetPixMap( aPmName.c_str() );
- anAttr = aStudyBuilder->FindOrCreateAttribute( newHypo, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
- anIOR ->SetValue( GetORB()->object_to_string( aHyp ) );
- aSO = SALOMEDS::SObject::_narrow( newHypo );
- anObjName = TCollection_AsciiString( aHyp->GetName() );
- }
-
- // Publishing a group
- SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(theIOR);
- if( aSO->_is_nil() && !aGroup->_is_nil() ) {
- // try to obtain a parent mesh's SObject
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group..." );
- SALOMEDS::SObject_var aParentSO;
- SMESH::SMESH_Mesh_var aParentMesh;
- SMESH_Group_i* aServant = dynamic_cast<SMESH_Group_i*>( GetServant( aGroup ).in() );
- if ( aServant != NULL ) {
- aParentMesh = SMESH::SMESH_Mesh::_narrow( GetPOA()->servant_to_reference( aServant->GetMeshServant() ) );
- if ( !aParentMesh->_is_nil() ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: refernce to mesh is OK" );
- string anIOR = GetORB()->object_to_string( aParentMesh );
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: mesh IOR = "<<anIOR.c_str() );
- aParentSO = theStudy->FindObjectIOR( anIOR.c_str() );
- }
- }
-
- // Find proper group sub-tree tag
- if ( !aParentSO->_is_nil() ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: parent mesh found" );
- int aType = (int)aGroup->GetType();
- const char* aRootNames[] = { "Compound Groups", "Groups of Nodes", "Groups of Edges", "Groups of Faces", "Groups of Volumes" };
-
- // Currently, groups with heterogenous content are not supported
- if ( aType != SMESH::ALL ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: group type OK" );
- long aRootTag = GetNodeGroupsTag() + aType - 1;
-
- // Find or create groups root
- SALOMEDS::SObject_var aRootSO;
- if ( !aParentSO->FindSubObject ( aRootTag, aRootSO ) ) {
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): creating groups root..." )
- aRootSO = aStudyBuilder->NewObjectToTag( aParentSO, aRootTag );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( aRootNames[aType] );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeSelectable" );
- aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
- aSelAttr ->SetSelectable( false );
- }
-
- // Add new group to corresponding sub-tree
- MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): adding group to study..." )
- SALOMEDS::SObject_var aGroupSO = aStudyBuilder->NewObject( aRootSO );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
- aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
- aPixmap ->SetPixMap( "ICON_SMESH_TREE_GROUP" );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aGroupSO, "AttributeIOR" );
- anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
- anIOR ->SetValue( GetORB()->object_to_string( aGroup ) );
- aSO = SALOMEDS::SObject::_narrow( aGroupSO );
- anObjName = TCollection_AsciiString( "Group" );
- }
- }
- }
-
- // Setting SObject's name
- if ( !aSO->_is_nil() ) {
- if ( strlen( theName ) == 0 )
- anObjName += TCollection_AsciiString( "_" ) + TCollection_AsciiString( aSO->Tag() );
- else
- anObjName = TCollection_AsciiString( strdup( theName ) );
- anAttr = aStudyBuilder->FindOrCreateAttribute( aSO, "AttributeName" );
- aName = SALOMEDS::AttributeName::_narrow( anAttr );
- aName ->SetValue( anObjName.ToCString() );