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=49e74979e063b731abec74d48216229f69410cdd;hp=c9b43633cbba20c5b671f4db37b25a167d3d1e78;hb=8d297d6698f361d4f2dde723050bcfbaea050920;hpb=d5029840731bccaa1718e65f0abf3b19198c7293 diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index c9b43633c..49e74979e 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -165,7 +165,7 @@ bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) { if(MYDEBUG) MESSAGE("CanPublishInStudy - "<SetValue( objStr.in() ); - // UnRegister() !!! + // UnRegister() !!! --> random problems when meshing in parallel (yacs foreach) in + // distributed python scripts, because simultaneously created meshes are + // published into the same SO; as a result the mesh published first dies SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR ); if ( !genObj->_is_nil() ) genObj->UnRegister(); @@ -396,7 +398,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 = @@ -479,6 +481,8 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObje { Unexpect aCatch(SALOME_SalomeException); SALOMEDS::SObject_wrap aSO; + if ( !myIsEnablePublish ) + return aSO._retn(); if ( CORBA::is_nil( theIOR )) return aSO._retn(); if(MYDEBUG) MESSAGE("PublishInStudy"); @@ -499,7 +503,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); @@ -521,12 +525,29 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObje SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent() { if(MYDEBUG) MESSAGE("PublishComponent"); + if ( !myIsEnablePublish ) + return SALOMEDS::SComponent::_nil(); SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder(); SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = getStudyServant()->GetUseCaseBuilder(); - CORBA::String_var compDataType = ComponentDataType(); - SALOMEDS::SComponent_wrap father = getStudyServant()->FindComponent( compDataType.in() ); + std::string compDataType = ComponentDataType(); // SMESH module's data type + std::string ior = SMESH_Gen_i::GetORB()->object_to_string( SMESH_Gen::_this() ); // IOR of this SMESH engine + + // Find study component which corresponds to this SMESH engine + + SALOMEDS::SComponent_wrap father; + SALOMEDS::SComponentIterator_wrap citer = getStudyServant()->NewComponentIterator(); + for ( ; citer->More(); citer->Next()) { + SALOMEDS::SComponent_wrap f_i = citer->Value(); + CORBA::String_var ior_i; + bool ok = f_i->ComponentIOR(ior_i.out()); + if ( ok && compDataType == f_i->ComponentDataType() && ior == ior_i.in()) { + father = f_i; + break; + } + } + if ( !CORBA::is_nil( father ) ) { // check that the component is added to the use case browser if ( !useCaseBuilder->IsUseCaseNode( father ) ) { @@ -536,19 +557,21 @@ SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent() return father._retn(); } + // If component for this SMESH engine does not exist in the study, create it + SALOME_ModuleCatalog::ModuleCatalog_var aCat = SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") ); if ( CORBA::is_nil( aCat ) ) return father._retn(); - SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.in() ); + SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.c_str() ); if ( CORBA::is_nil( aComp ) ) return father._retn(); SALOMEDS::GenericAttribute_wrap anAttr; SALOMEDS::AttributePixMap_wrap aPixmap; - father = aStudyBuilder->NewComponent( compDataType.in() ); + father = aStudyBuilder->NewComponent( compDataType.c_str() ); aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() ); anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" ); aPixmap = anAttr; @@ -572,8 +595,10 @@ SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent() SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh, const char* theName) { + if ( !myIsEnablePublish ) + return SALOMEDS::SObject::_nil(); if ( CORBA::is_nil( theMesh )) - return SALOMEDS::SComponent::_nil(); + return SALOMEDS::SObject::_nil(); if(MYDEBUG) MESSAGE("PublishMesh--IN"); // find or publish a mesh @@ -592,7 +617,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SMESH::SMESH_Mesh_ptr theMesh, else aTag++; - aMeshSO = publish ( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" ); + aMeshSO = publish( theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" ); if ( aMeshSO->_is_nil() ) return aMeshSO._retn(); } @@ -659,6 +684,8 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theM GEOM::GEOM_Object_ptr theShapeObject, const char* theName) { + if ( !myIsEnablePublish ) + return SALOMEDS::SObject::_nil(); if ( theMesh->_is_nil() || theSubMesh->_is_nil() || theShapeObject->_is_nil() ) return SALOMEDS::SObject::_nil(); @@ -725,7 +752,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SMESH::SMESH_Mesh_ptr theM // Add reference to theShapeObject - addReference( aSubMeshSO, theShapeObject, 1 ); + addReference( aSubMeshSO, theShapeObject, GetRefOnShapeTag() ); // Publish hypothesis @@ -749,6 +776,8 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh, GEOM::GEOM_Object_ptr theShapeObject, const char* theName) { + if ( !myIsEnablePublish ) + return SALOMEDS::SObject::_nil(); if (theMesh->_is_nil() || theGroup->_is_nil() ) return SALOMEDS::SObject::_nil(); @@ -808,7 +837,7 @@ SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SMESH::SMESH_Mesh_ptr theMesh, //Add reference to geometry if ( !theShapeObject->_is_nil() ) - addReference( aGroupSO, theShapeObject, 1 ); + addReference( aGroupSO, theShapeObject, GetRefOnShapeTag() ); return aGroupSO._retn(); } @@ -823,6 +852,8 @@ SALOMEDS::SObject_ptr const char* theName) { if(MYDEBUG) MESSAGE("PublishHypothesis") + if ( !myIsEnablePublish ) + return SALOMEDS::SObject::_nil(); if (theHyp->_is_nil()) return SALOMEDS::SObject::_nil(); @@ -859,14 +890,89 @@ 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 if ( mesh_i->HasShapeToMesh() ) + SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" ); + else + SetPixMap( so, "ICON_SMESH_TREE_MESH_IMPORTED" ); + + // 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; @@ -1002,7 +1108,7 @@ bool SMESH_Gen_i::RemoveHypothesisFromShape(SMESH::SMESH_Mesh_ptr theMesh, * \brief Stores names of variables that WILL be passes as parameters when calling * some method of a given object. * \param [in] theObject - the object whose a method WILL be called with \a theParameters. - * \param [in] theParameters - a string contating parameters separated by ':'. + * \param [in] theParameters - a string containing parameters separated by ':'. */ //================================================================================ @@ -1013,7 +1119,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 +1148,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 +1338,96 @@ 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; +} + +//======================================================================= +//function : Clear +//purpose : clear data +//======================================================================= + +void StudyContext::Clear() +{ + mapIdToIOR.Clear(); + mapIdToId.Clear(); +}