Salome HOME
Update of CheckDone
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
index c2ffde107dec7b878fd6a55aa2352f4ca5566b7a..cc20acacade46f59d609d2d0c31e3278ebd67504 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -30,7 +30,6 @@
 #include <SMESHGUI_HypothesesUtils.h>
 #include <SMESHGUI_Utils.h>
 #include <SMESHGUI_GEOMGenUtils.h>
-
 #include <SMESH_TypeFilter.hxx>
 #include <SMESH_NumberFilter.hxx>
 
@@ -40,6 +39,7 @@
 #include "StdMeshersGUI_PropagationHelperWdg.h"
 #include "StdMeshersGUI_QuadrangleParamWdg.h"
 #include "StdMeshersGUI_RadioButtonsGrpWdg.h"
+#include "StdMeshersGUI_NameCheckableGrpWdg.h"
 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
 
 #include <SALOMEDSClient_Study.hxx>
@@ -47,8 +47,9 @@
 #include <GEOM_wrap.hxx>
 
 // SALOME GUI includes
-#include <SUIT_ResourceMgr.h>
 #include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
+#include <SalomeApp_IntSpinBox.h>
 
 // IDL includes
 #include <SALOMEconfig.h>
@@ -126,7 +127,7 @@ QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
 
 //================================================================================
 /*!
- * \brief Allow modifing myCustomWidgets in const methods
+ * \brief Allow modifying myCustomWidgets in const methods
   * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
  */
 //================================================================================
@@ -377,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
  */
 //================================================================================
 
@@ -422,11 +464,11 @@ 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();
-      _PTR(Study)         aStudy = SMESH::GetActiveStudyDocument();
+      GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen( face );
+      _PTR(Study)         aStudy = SMESH::getStudy();
       GEOM::GEOM_IShapesOperations_wrap shapeOp;
       if ( !geomGen->_is_nil() && aStudy )
-        shapeOp = geomGen->GetIShapesOperations( aStudy->StudyId() );
+        shapeOp = geomGen->GetIShapesOperations();
       if ( !shapeOp->_is_nil() )
       {
         GEOM::ListOfLong_var vertices =
@@ -467,7 +509,7 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
   bool res = getStdParamFromDlg( params );
   if( isCreation() )
   {
-    SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
+    SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toUtf8().data() );
     params.erase( params.begin() );
   }
 
@@ -728,6 +770,15 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       {
         h->SetFaces( idsWg->GetListOfIDs(), params[4].myValue.toInt() );
       }
+
+      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" )
     {
@@ -746,6 +797,15 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       {
         h->SetEdges( idsWg->GetListOfIDs(), params[3].myValue.toInt() );
       }
+
+      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" )
     // {
@@ -841,7 +901,7 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
     item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
     p.append( item );
     QCheckBox* aQCheckBox = new QCheckBox(dlg());
-    if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
+    if ( h->HavePreestimatedLength() ) {
       aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
       connect( aQCheckBox, SIGNAL(  stateChanged(int) ), this, SLOT( onValueChanged() ) );
     }
@@ -1250,6 +1310,19 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
       }
       customWidgets()->append ( idsWg );
     }
+
+    item.setNoName();
+    p.append( item );
+    StdMeshersGUI_NameCheckableGrpWdg* nameWdg =
+      new StdMeshersGUI_NameCheckableGrpWdg( tr( "CREATE_GROUPS_FROM_LAYERS" ),
+                                             tr( "GROUP_NAME" ));
+    nameWdg->setName( h->GetGroupName() );
+    if ( nameWdg->getName().isEmpty() )
+    {
+      nameWdg->setDefaultName( type() );
+      nameWdg->setChecked( false );
+    }
+    customWidgets()->append ( nameWdg );
   }
   else if( hypType()=="ViscousLayers2D" )
   {
@@ -1308,6 +1381,19 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
       }
       customWidgets()->append ( idsWg );
     }
+
+    item.setNoName();
+    p.append( item );
+    StdMeshersGUI_NameCheckableGrpWdg* nameWdg =
+      new StdMeshersGUI_NameCheckableGrpWdg( tr( "CREATE_GROUPS_FROM_LAYERS" ),
+                                             tr( "GROUP_NAME" ));
+    nameWdg->setName( h->GetGroupName() );
+    if ( nameWdg->getName().isEmpty() )
+    {
+      nameWdg->setDefaultName( type() );
+      nameWdg->setChecked( false );
+    }
+    customWidgets()->append ( nameWdg );
   }
   else
     res = false;
@@ -1349,6 +1435,7 @@ void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int)
     {
       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
       sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
+      sb->setMinimumWidth( 150 );
     }
     else if( hypType()=="MaxElementArea" )
     {
@@ -1382,6 +1469,14 @@ void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int)
       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
     }
   }
+  else if ( SalomeApp_IntSpinBox* sb = qobject_cast< SalomeApp_IntSpinBox* >( w ))
+  {
+    if ( hypType().startsWith( "NumberOfLayers" ) ||
+         hypType().startsWith( "ViscousLayers" ))
+    {
+      sb->setMinimum( 1 );
+    }
+  }
 }
 
 //================================================================================
@@ -1424,7 +1519,7 @@ QString StdMeshersGUI_StdHypothesisCreator::type() const
 //================================================================================
 /*!
  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
- * from message resouce file
+ * from message resource file
   * \param t - hypothesis type
   * \retval QString - result string
  */
@@ -1476,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
 {
@@ -1565,6 +1660,10 @@ bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & pa
     param.myValue = w->checkedId();
     return true;
   }
+  if ( widget->inherits( "StdMeshersGUI_NameCheckableGrpWdg" ))
+  {
+    return true;
+  }
   return false;
 }
 
@@ -1635,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
 {