Salome HOME
Debug
authorouv <ouv@opencascade.com>
Mon, 21 Dec 2009 10:29:57 +0000 (10:29 +0000)
committerouv <ouv@opencascade.com>
Mon, 21 Dec 2009 10:29:57 +0000 (10:29 +0000)
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_I/SMESH_Hypothesis_i.cxx
src/SMESH_I/SMESH_Hypothesis_i.hxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx

index a97fde5c20811085db7be0fb1da978ae87bf27ea..3fad1a3145d653dc38c48de68719e53024dbff53 100644 (file)
@@ -420,6 +420,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName
     myHypothesis_i =
       myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
     myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
+    myHypothesis_i->SetNotebook(GetNotebook(GetCurrentStudyID()));
   }
   catch (SALOME_Exception& S_ex)
   {
@@ -456,7 +457,8 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
   // Get or create the GEOM_Client instance
   try {
     // create a new mesh object servant, store it in a map in study context
-    SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
+    SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID(),
+                                                  GetNotebook( GetCurrentStudyID() ) );
     // create a new mesh object
     meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
 
@@ -607,6 +609,20 @@ SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
   return SALOMEDS::Study::_duplicate( myCurrentStudy );
 }
 
+//=============================================================================
+/*!
+ *  SMESH_Gen_i::GetStudyContext 
+ *
+ *  Get study context by study id
+ */
+//=============================================================================
+StudyContext* SMESH_Gen_i::GetStudyContext( int theStudyId )
+{
+  if ( myStudyContextMap.find( theStudyId ) != myStudyContextMap.end() )
+    return myStudyContextMap[ theStudyId ];
+  return 0;
+}
+
 //=============================================================================
 /*!
  *  SMESH_Gen_i::GetCurrentStudyContext 
@@ -616,11 +632,9 @@ SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
 //=============================================================================
 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
 {
-  if ( !CORBA::is_nil( myCurrentStudy ) &&
-      myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
-    return myStudyContextMap[ myCurrentStudy->StudyId() ];
-  else
-    return 0;
+  if ( !CORBA::is_nil( myCurrentStudy ) )
+    return GetStudyContext( GetCurrentStudyID() );
+  return 0;
 }
 
 //=============================================================================
@@ -4364,6 +4378,36 @@ SALOME::Notebook_ptr SMESH_Gen_i::GetNotebook( CORBA::Long theStudyID )
   return aNotebook._retn();
 }
 
+//=================================================================================
+// function : FindObjectByInternalEntry()
+// purpose  :
+//=================================================================================
+SALOME::GenericObj_ptr SMESH_Gen_i::FindObjectByInternalEntry( CORBA::Long theStudyID, const char* theEntry )
+{
+  map<int, StudyContext*>::iterator it = myStudyContextMap.find( theStudyID );
+  if ( it == myStudyContextMap.end() )
+    return NULL;
+
+  StudyContext* aStudyContext = it->second;
+  if ( !aStudyContext )
+    return NULL;
+
+  int id = atoi( theEntry );
+  string anIOR = aStudyContext->getIORbyId( id );
+  if ( !anIOR.empty() ) {
+    CORBA::Object_var anObject = GetORB()->string_to_object( anIOR.c_str() );
+    if ( !CORBA::is_nil( anObject ) ) {
+      SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
+      if ( !aHyp->_is_nil() )
+        return aHyp._retn();
+      SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( anObject );
+      if ( !aMesh->_is_nil() )
+        return aMesh._retn();
+    }
+  }
+  return NULL;
+}
+
 //=============================================================================
 /*! 
  *  SMESHEngine_factory
index 1a43e4b3e27fa18da6fe06a1c9e48344632931d0..fb00207992e089fa874fbee79ef6eaa0cbfb2b2e 100644 (file)
@@ -102,7 +102,11 @@ public:
   }
   // maps old object id to the new one (used when restoring data)
   void mapOldToNew( const int oldId, const int newId ) {
-    mapIdToId[ oldId ] = newId;
+    if ( mapIdToIOR.find( newId ) != mapIdToIOR.end() ) {
+      mapIdToIOR[ oldId ] = mapIdToIOR[ newId ];
+      mapIdToIOR.erase( newId );
+    }
+    mapIdToId[ oldId ] = oldId;
   }
   // get old id by a new one
   int getOldId( const int newId ) {
@@ -476,7 +480,10 @@ public:
   static void SetPixMap(SALOMEDS::SObject_ptr theSObject,
                         const char*           thePixMap);
 
-  //  Get study context
+  // Get study context
+  StudyContext* GetStudyContext( int theStudyId );
+
+  // Get current study context
   StudyContext* GetCurrentStudyContext();
 
   // Register an object in a StudyContext; return object id
@@ -508,6 +515,8 @@ public:
   SALOMEDS::Study_ptr GetStudy(CORBA::Long theStudyID);
   SALOME::Notebook_ptr GetNotebook(CORBA::Long theStudyID);
 
+  virtual SALOME::GenericObj_ptr FindObjectByInternalEntry( CORBA::Long theStudyID, const char* theEntry );
+
 private:
   // Create hypothesis of given type
   SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,
index 6ff3ad77a43bba4488749ecde511ee5a5797acc4..c90f693cffa5aaa6290f9aa38a7b7c68abf2fa59 100644 (file)
@@ -42,7 +42,7 @@ using namespace std;
 //=============================================================================
 
 SMESH_Hypothesis_i::SMESH_Hypothesis_i( PortableServer::POA_ptr thePOA )
-     : SALOME::GenericObj_i( thePOA )
+     : SALOME_ParameterizedObject()
 {
   MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Début" );
   myBaseImpl = 0;
@@ -145,8 +145,23 @@ bool SMESH_Hypothesis_i::IsPublished(){
 //=============================================================================
 char* SMESH_Hypothesis_i::GetEntry()
 {
+  int anId = 0;
+  SALOME::Notebook_ptr aNotebook = GetNotebook();
+  if( !CORBA::is_nil( aNotebook ) )
+  {
+    SALOMEDS::Study_ptr aStudy = aNotebook->GetStudy();
+    if( SMESH_Gen_i* aGen = SMESH_Gen_i::GetSMESHGen() )
+    {
+      if( StudyContext* aStudyContext = aGen->GetStudyContext( aStudy->StudyId() ) )
+      {
+        CORBA::String_var anIOR = aGen->GetORB()->object_to_string( _this() );
+        anId = aStudyContext->findId( anIOR.in() );
+      }
+    }
+  }
+
   char aBuf[100];
-  sprintf( aBuf, "%i", GetId() );
+  sprintf( aBuf, "%i", anId );
   return CORBA::string_dup( aBuf );
 }
 
index 939c55c3a5013986a945eb52b04adc6fab29ac65..3fc6107881c83190ad536111b508fd29e4deeb5b 100644 (file)
@@ -34,7 +34,7 @@
 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
 
 #include "SMESH_Hypothesis.hxx"
-#include "SALOME_GenericObj_i.hh"
+#include "SALOME_ParameterizedObject.hxx"
 
 #include "SMESH_Gen.hxx"
 
@@ -43,7 +43,7 @@
 // ======================================================
 class SMESH_I_EXPORT SMESH_Hypothesis_i:
   public virtual POA_SMESH::SMESH_Hypothesis,
-  public virtual SALOME::GenericObj_i
+  public virtual SALOME_ParameterizedObject
 {
 public:
   // Constructor : placed in protected section to prohibit creation of generic class instance
index 01d394dcf022ba5559fbcc496cc96161b657a661..a74ddb487b39cf2b97b4f26000a0d6a1567304b4 100644 (file)
@@ -96,8 +96,9 @@ int SMESH_Mesh_i::myIdGenerator = 0;
 
 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
                             SMESH_Gen_i*            gen_i,
-                            CORBA::Long studyId )
-: SALOME::GenericObj_i( thePOA )
+                            CORBA::Long             studyId,
+                            SALOME::Notebook_ptr    theNotebook )
+: SALOME_ParameterizedObject( theNotebook )
 {
   MESSAGE("SMESH_Mesh_i");
   _impl = NULL;
@@ -417,9 +418,11 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubS
   Unexpect aCatch(SALOME_SalomeException);
   SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
 
-  if ( !SMESH_Hypothesis::IsStatusFatal(status) )
+  if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
     _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
                                  aSubShapeObject, anHyp );
+    StoreDependencies( GetNotebook() );
+  }
 
   if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
 
@@ -3385,8 +3388,20 @@ void SMESH_Mesh_i::checkGroupNames()
 //=============================================================================
 char* SMESH_Mesh_i::GetEntry()
 {
+  int anId = 0;
+  SALOME::Notebook_ptr aNotebook = GetNotebook();
+  if( !CORBA::is_nil( aNotebook ) )
+  {
+    SALOMEDS::Study_ptr aStudy = aNotebook->GetStudy();
+    if( StudyContext* aStudyContext = GetGen()->GetStudyContext( aStudy->StudyId() ) )
+    {
+      CORBA::String_var anIOR = GetGen()->GetORB()->object_to_string( _this() );
+      anId = aStudyContext->findId( anIOR.in() );
+    }
+  }
+
   char aBuf[100];
-  sprintf( aBuf, "%i", GetId() );
+  sprintf( aBuf, "%i", anId );
   return CORBA::string_dup( aBuf );
 }
 
@@ -3495,6 +3510,51 @@ void SMESH_Mesh_i::UpdateStringAttribute( const SALOME::StringArray& theParamete
   aStringAttrib->Destroy();
 }
 
+//=============================================================================
+/*!
+ * \brief Internal method for storing dependencies for mesh
+ */
+//=============================================================================
+void SMESH_Mesh_i::StoreDependenciesForShape( SALOME::Notebook_ptr theNotebook,
+                                              GEOM::GEOM_Object_ptr theShapeObject,
+                                              bool theIsStoreShape )
+{
+  SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theShapeObject );
+  for( int i = 0, n = aHypList->length(); i < n; i++ )
+  {
+    SMESH::SMESH_Hypothesis_ptr aHypothesis = aHypList[i];
+    if( CORBA::is_nil( aHypothesis ) )
+      continue;
+    SMESH::SMESH_Algo_ptr anAlgo = SMESH::SMESH_Algo::_narrow( aHypothesis );
+    if( !CORBA::is_nil( anAlgo ) ) // don't take into account algorithms
+      continue;
+    theNotebook->AddDependency( _this(), aHypothesis );
+  }
+
+  if( theIsStoreShape )
+    theNotebook->AddDependency( _this(), theShapeObject );
+}
+
+//=============================================================================
+/*!
+ * \brief Store dependencies for mesh
+ */
+//=============================================================================
+void SMESH_Mesh_i::StoreDependencies( SALOME::Notebook_ptr theNotebook )
+{
+  theNotebook->ClearDependencies( _this(), SALOME::Objects );
+
+  GEOM::GEOM_Object_ptr aShapeObject = GetShapeToMesh();
+  StoreDependenciesForShape( theNotebook, aShapeObject, true );
+
+  std::map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.begin(), itEnd = _mapSubMeshIor.end();
+  for( ; it != itEnd; it++ ) {
+    SMESH::SMESH_subMesh_ptr aSubMesh = it->second;
+    GEOM::GEOM_Object_ptr aSubShape = aSubMesh->GetSubShape();
+    StoreDependenciesForShape( theNotebook, aSubShape, false );
+  }
+}
+
 //=============================================================================
 /*!
  * \brief Returns statistic of mesh elements
index 13862b9a117370a72cd5ac9eb1310939c33f9d61..1f89035ae0cc8b60fa102a5e1d530f3980a9477c 100644 (file)
@@ -41,7 +41,7 @@
 //#include "SMESH_subMesh_i.hxx"
 #include "SMESH_subMesh.hxx"
 
-#include "SALOME_GenericObj_i.hh"
+#include "SALOME_ParameterizedObject.hxx"
 
 class SMESH_Gen_i;
 class SMESH_GroupBase_i;
@@ -51,14 +51,15 @@ class SMESH_subMesh_i;
 
 class SMESH_I_EXPORT SMESH_Mesh_i:
   public virtual POA_SMESH::SMESH_Mesh,
-  public virtual SALOME::GenericObj_i
+  public virtual SALOME_ParameterizedObject
 {
   SMESH_Mesh_i();
   SMESH_Mesh_i(const SMESH_Mesh_i&);
 public:
   SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
                 SMESH_Gen_i*            myGen_i,
-              CORBA::Long             studyId );
+                CORBA::Long             studyId,
+                SALOME::Notebook_ptr    theNotebook );
 
   virtual ~SMESH_Mesh_i();
 
@@ -506,6 +507,11 @@ public:
    */
   virtual void UpdateStringAttribute( const SALOME::StringArray& theParameters );
 
+  /*!
+   * Store dependencies for mesh
+   */
+  virtual void StoreDependencies( SALOME::Notebook_ptr theNotebook );
+
   /*!
    * Returns statistic of mesh elements
    * Result array of number enityties
@@ -529,6 +535,13 @@ private:
    */
   void checkGroupNames();
 
+  /*!
+   * Store dependencies for mesh
+   */
+  virtual void StoreDependenciesForShape( SALOME::Notebook_ptr theNotebook,
+                                          GEOM::GEOM_Object_ptr theShapeObject,
+                                          bool theIsStoreShape );
+
 private:
 
   static int myIdGenerator;