Salome HOME
#18963 Minimize compiler warnings
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
index f16b06011819e3d5c59ec359aed926e3fa3de51e..b8d2c886392e1b25e5ef0be9c4864b489feda5ec 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  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
@@ -378,10 +378,51 @@ namespace {
   }
 }
 
+//================================================================================
+/*!
+ * \brief Remove a group, whose name is stored by hypothesis, upon group name modification
+ *  \param [in] oldName - old group name
+ *  \param [in] newName - new group name
+ *  \param [in] type - group type
+ */
+//================================================================================
+
+void StdMeshersGUI_StdHypothesisCreator::
+removeOldGroup(const char* oldName, const char* newName, SMESH::ElementType type) const
+{
+  if ( !oldName || !oldName[0] )
+    return; // old name undefined
+  if ( newName && strcmp( oldName, newName ) == 0 )
+    return; // same name
+
+  SMESH::SMESH_Hypothesis_var h = hypothesis();
+  SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( h );
+  for ( size_t i = 0; i < listSOmesh.size(); i++ )
+  {
+    _PTR(SObject) submSO = listSOmesh[i];
+    SMESH::SMESH_Mesh_var       mesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>( submSO );
+    SMESH::SMESH_subMesh_var subMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>( submSO );
+    if( !subMesh->_is_nil() )
+      mesh = subMesh->GetFather();
+    if ( mesh->_is_nil() )
+      continue;
+    SMESH::ListOfGroups_var groups = mesh->GetGroups();
+    for ( CORBA::ULong iG = 0; iG < groups->length(); iG++ )
+    {
+      if ( groups[iG]->GetType() != type )
+        continue;
+      CORBA::String_var name = groups[iG]->GetName();
+      if ( strcmp( name.in(), oldName ))
+        continue;
+      mesh->RemoveGroup( groups[iG] );
+    }
+  }
+}
+
 //================================================================================
 /*!
  * \brief Check parameter values before accept()
 * \retval bool - true if OK
 \retval bool - true if OK
  */
 //================================================================================
 
@@ -423,7 +464,7 @@ bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
       // then the FACE must have only one VERTEX
       GEOM::GEOM_Object_var face = w->GetObject< GEOM::GEOM_Object >();
 
-      GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
+      GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen( face );
       _PTR(Study)         aStudy = SMESH::getStudy();
       GEOM::GEOM_IShapesOperations_wrap shapeOp;
       if ( !geomGen->_is_nil() && aStudy )
@@ -733,7 +774,10 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       if ( StdMeshersGUI_NameCheckableGrpWdg* nameWg =
            widget< StdMeshersGUI_NameCheckableGrpWdg >( 6 ))
       {
+        CORBA::String_var oldName = h->GetGroupName();
         h->SetGroupName( nameWg->getName().toUtf8().data() );
+        CORBA::String_var newName = h->GetGroupName();
+        removeOldGroup( oldName, newName, SMESH::VOLUME );
       }
     }
     else if( hypType()=="ViscousLayers2D" )
@@ -757,7 +801,10 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       if ( StdMeshersGUI_NameCheckableGrpWdg* nameWg =
            widget< StdMeshersGUI_NameCheckableGrpWdg >( 5 ))
       {
+        CORBA::String_var oldName = h->GetGroupName();
         h->SetGroupName( nameWg->getName().toUtf8().data() );
+        CORBA::String_var newName = h->GetGroupName();
+        removeOldGroup( oldName, newName, SMESH::FACE );
       }
     }
     // else if( hypType()=="QuadrangleParams" )
@@ -1524,7 +1571,7 @@ QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) cons
 //purpose  : is called from buildStdFrame()
 //=======================================================================
 
-QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
+QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & /*param*/,
                                                               QWidget*         parent,
                                                               const int        index) const
 {
@@ -1687,7 +1734,7 @@ void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
  */
 //================================================================================
 
-bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::SMESH_Hypothesis_var theHyp
+bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::SMESH_Hypothesis_var /*theHyp*/
                                                           StdParam &                  theParams, 
                                                           const char*                 theMethod) const
 {