Salome HOME
Copyright update 2021
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_LayerDistribution_i.cxx
index bfdc329479c30bb60574748fbd9cb913dcfd1901..05fb2f526d2e30f3d7616da457131654adbdf46f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -45,14 +45,11 @@ using namespace std;
 //=============================================================================
 
 StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i( PortableServer::POA_ptr thePOA,
-                                                          int                     theStudyId,
-                                                          ::SMESH_Gen*            theGenImpl )
-  : SALOME::GenericObj_i( thePOA ), 
+                                                                ::SMESH_Gen*            theGenImpl )
+  : SALOME::GenericObj_i( thePOA ),
     SMESH_Hypothesis_i( thePOA )
 {
-  MESSAGE( "StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i" );
   myBaseImpl = new ::StdMeshers_LayerDistribution( theGenImpl->GetANewId(),
-                                                   theStudyId,
                                                    theGenImpl );
 }
 
@@ -66,19 +63,19 @@ StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i( PortableServer::
 
 StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i()
 {
-  MESSAGE( "StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i" );
+  if ( !myHyp->_is_nil() )
+    myHyp->UnRegister();
 }
 
 //=============================================================================
 /*!
  *  StdMeshers_LayerDistribution_i::SetLayerDistribution
  *
+
  */
 //=============================================================================
 
 void StdMeshers_LayerDistribution_i::SetLayerDistribution(SMESH::SMESH_Hypothesis_ptr hyp1D)
-     throw ( SALOME::SALOME_Exception )
 {
   ASSERT( myBaseImpl );
   try {
@@ -86,14 +83,14 @@ void StdMeshers_LayerDistribution_i::SetLayerDistribution(SMESH::SMESH_Hypothesi
     bool isNewHyp = ( hyp_i->GetImpl() != this->GetImpl()->GetLayerDistribution() );
     this->GetImpl()->SetLayerDistribution( hyp_i->GetImpl() );
     myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp1D );
+    myHyp->Register();
     // Remove SO of 1D hypothesis if it was published
     if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen())
     {
-      SALOMEDS::Study_var study = gen->GetCurrentStudy();
-      SALOMEDS::SObject_var  SO = gen->ObjectToSObject( study, hyp1D );
+      SALOMEDS::SObject_var  SO = gen->ObjectToSObject( hyp1D );
       if ( ! SO->_is_nil() )
       {
-        SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
+        SALOMEDS::StudyBuilder_var builder = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
         builder->RemoveObjectWithChildren( SO );
         SO->UnRegister();
       }
@@ -142,12 +139,13 @@ SMESH::SMESH_Hypothesis_ptr StdMeshers_LayerDistribution_i::GetLayerDistribution
 //================================================================================
 /*!
  * \brief Verify whether hypothesis supports given entity type 
 * \param type - dimension (see SMESH::Dimension enumeration)
 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
 \param type - dimension (see SMESH::Dimension enumeration)
 \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
  * 
  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
  */
 //================================================================================  
+
 CORBA::Boolean StdMeshers_LayerDistribution_i::IsDimSupported( SMESH::Dimension type )
 {
   return type == SMESH::DIM_3D;
@@ -156,7 +154,7 @@ CORBA::Boolean StdMeshers_LayerDistribution_i::IsDimSupported( SMESH::Dimension
 //================================================================================
 /*!
  * \brief Write parameters in a string
 * \retval char* - resulting string
 \retval char* - resulting string
  */
 //================================================================================
 
@@ -182,7 +180,7 @@ char* StdMeshers_LayerDistribution_i::SaveTo()
 //================================================================================
 /*!
  * \brief Retrieve parameters from the string
 * \param theStream - the input string
 \param theStream - the input string
  */
 //================================================================================
 
@@ -196,8 +194,7 @@ void StdMeshers_LayerDistribution_i::LoadFrom( const char* theStream )
        is >> libName )
   {
     SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var curStudy = gen->GetCurrentStudy();
-    gen->SetCurrentStudy( SALOMEDS::Study::_nil() ); // prevent hypo publishing
+    gen->SetEnablePublish( false ); // prevent hypo publishing
 
     try {
       SMESH::SMESH_Hypothesis_var hyp1D =
@@ -219,7 +216,7 @@ void StdMeshers_LayerDistribution_i::LoadFrom( const char* theStream )
     }
     catch (...) {
     }
-    gen->SetCurrentStudy( curStudy );  // enable hypo publishing
+    gen->SetEnablePublish( true );  // enable hypo publishing
   }
 }