X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Gen_i_1.cxx;h=dc21b915cd32f6004ffd9ad9220fec1df464efd9;hp=6b3da78a1efcc5e3c0909a379c9bd534f64de8b7;hb=1b80c8bc605eaea62874a92d75613657bf664e9e;hpb=7a3ecab720cc517ace17c5c4677fd3c20c0051ee diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index 6b3da78a1..dc21b915c 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -208,7 +208,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(CORBA::Object_ptr theObject) //function : GetStudyPtr //purpose : Get study from naming service //======================================================================= -SALOMEDS::Study_ptr SMESH_Gen_i::getStudyServant() +SALOMEDS::Study_var SMESH_Gen_i::getStudyServant() { return SALOMEDS::Study::_duplicate(KERNEL::getStudyServant()); } @@ -308,10 +308,10 @@ static SALOMEDS::SObject_ptr publish(CORBA::Object_ptr theIOR, if ( !sameIOR ) { iorAttr->SetValue( objStr.in() ); - // UnRegister() !!! - SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR ); - if ( !genObj->_is_nil() ) - genObj->UnRegister(); + // UnRegister() !!! --> No: random problems when meshing in parallel (yacs foreach) in distributed python scripts +// SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR ); +// if ( !genObj->_is_nil() ) +// genObj->UnRegister(); } } @@ -396,7 +396,7 @@ void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject, void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject, const char* thePixMap) { - if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap )) + if ( !theSObject->_is_nil() && thePixMap && thePixMap && thePixMap[0] ) { SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder(); SALOMEDS::GenericAttribute_wrap anAttr = @@ -499,7 +499,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObje // Publishing a hypothesis or algorithm SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR ); if ( aSO->_is_nil() && !aHyp->_is_nil() ) - aSO = PublishHypothesis( aHyp ); + aSO = PublishHypothesis( aHyp, theName ); // Publishing a group SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR); @@ -859,14 +859,87 @@ SALOMEDS::SObject_ptr return aHypSO._retn(); } +//======================================================================= +//function : UpdateIcons +//purpose : update icons of a mesh and its children upon mesh modification +//======================================================================= + +void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh ) +{ + SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh ); + if ( ! mesh_i ) + return; + + SALOMEDS::SObject_wrap so = ObjectToSObject( theMesh ); + if ( so->_is_nil() ) + return; + + // set icon of the mesh + if ( mesh_i->NbNodes() == 0 ) + SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN" ); + else if ( mesh_i->IsComputedOK() ) + SetPixMap( so, "ICON_SMESH_TREE_MESH" ); + else + SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" ); + + // set icons of sub-objects + SALOMEDS::Study_var study = getStudyServant(); + SALOMEDS::ChildIterator_wrap iter = study->NewChildIterator( so ); + for ( ; iter->More(); iter->Next() ) + { + so = iter->Value(); // 1st level child - root of algos, hyps, sub-meshes or groups + if ( so->Tag() < SMESH::Tag_FirstSubMesh ) + continue; + + SALOMEDS::ChildIterator_wrap subIter = study->NewChildIterator( so ); + for ( ; subIter->More(); subIter->Next() ) + { + so = subIter->Value(); // 2nd level child - a sub-mesh or group + + CORBA::Object_var obj = SObjectToObject( so ); + SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj ); + if ( idSrc->_is_nil() ) + continue; + + SMESH::SMESH_GroupBase_var grp = SMESH::SMESH_GroupBase::_narrow( obj ); + SMESH::SMESH_GroupOnFilter_var gof = SMESH::SMESH_GroupOnFilter::_narrow( obj ); + const bool isGroup = !grp->_is_nil(); + const bool isGroupOnFilter = !gof->_is_nil(); + + bool isEmpty = ( mesh_i->NbNodes() == 0 ); + if ( !isEmpty ) + { + if ( isGroupOnFilter ) // GetTypes() can be very long on GroupOnFilter! + { + SMESH::long_array_var nbByType = mesh_i->GetNbElementsByType(); + isEmpty = ( nbByType[ grp->GetType() ] == 0 ); + } + else + { + SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes(); + isEmpty = ( elemTypes->length() == 0 ); + } + } + if ( isEmpty ) + SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN"); + else if ( !isGroup ) + SetPixMap( so, "ICON_SMESH_TREE_MESH" ); + else if ( isGroupOnFilter ) + SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" ); + else + SetPixMap( so, "ICON_SMESH_TREE_GROUP" ); + } + } +} + //======================================================================= //function : GetMeshOrSubmeshByShape //purpose : //======================================================================= SALOMEDS::SObject_ptr - SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh, - GEOM::GEOM_Object_ptr theShape) +SMESH_Gen_i::GetMeshOrSubmeshByShape (SMESH::SMESH_Mesh_ptr theMesh, + GEOM::GEOM_Object_ptr theShape) { if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape") SALOMEDS::SObject_wrap aMeshOrSubMesh; @@ -1013,7 +1086,7 @@ void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theP myLastObj.clear(); myLastParameters.clear(); myLastParamIndex.clear(); /* vector holding indices of virables within the string - of all varibles used for theObject */ + of all variables used for theObject */ int nbVars = 0; int pos = 0, prevPos = 0, len = strlen( theParameters ); if ( len == 0 ) return; @@ -1042,7 +1115,7 @@ void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theP return; // store - // (1) variable names in the string of all varibles used for theObject and + // (1) variable names in the string of all variables used for theObject and // (2) indices of found variables in myLastParamIndex. // remember theObject @@ -1232,3 +1305,85 @@ char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject) } return aResult._retn(); } + + + +// ============== +// Study context +// ============== + +//======================================================================= +//function : addObject +//purpose : register object in the internal map and return its id +//======================================================================= + +int StudyContext::addObject( const std::string& theIOR ) +{ + int nextId = getNextId(); + mapIdToIOR.Bind( nextId, theIOR ); + return nextId; +} + +//======================================================================= +//function : findId +//purpose : find the object id in the internal map by the IOR +//======================================================================= + +int StudyContext::findId( const std::string& theIOR ) +{ + TInt2StringMap::iterator imap; + for ( imap = mapIdToIOR.begin(); imap != mapIdToIOR.end(); ++imap ) { + if ( *imap == theIOR ) + return imap.Iterator().Key(); + } + return 0; +} + +//======================================================================= +//function : getIORbyId +//purpose : get object's IOR by id +//======================================================================= + +std::string StudyContext::getIORbyId( const int theId ) +{ + if ( mapIdToIOR.IsBound( theId ) ) + return mapIdToIOR( theId ); + return std::string(); +} + +//======================================================================= +//function : getIORbyOldId +//purpose : get object's IOR by old id +//======================================================================= + +std::string StudyContext::getIORbyOldId( const int theOldId ) +{ + if ( mapIdToId.IsBound( theOldId ) ) + return getIORbyId( mapIdToId( theOldId )); + return std::string(); +} + +//======================================================================= +//function : mapOldToNew +//purpose : maps old object id to the new one (used when restoring data) +//======================================================================= + +void StudyContext::mapOldToNew( const int oldId, const int newId ) +{ + mapIdToId.Bind( oldId, newId ); +} + +//======================================================================= +//function : getOldId +//purpose : get old id by a new one +//======================================================================= + +int StudyContext::getOldId( const int newId ) +{ + TInt2IntMap::iterator imap; + for ( imap = mapIdToId.begin(); imap != mapIdToId.end(); ++imap ) { + if ( *imap == newId ) + return imap.Iterator().Key(); + } + return 0; +}