Salome HOME
Merge from BR_V5_IMP_P8
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index d511701400528d9486e37e7ff56105ee65ba402e..ec08a297e222f5fcf41897719d716ba40ebf9520 100644 (file)
@@ -894,13 +894,14 @@ SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
     !myIsMesh :
     myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).count(':') > nbColonsInMeshEntry;
 
+  // get mesh and geom object
+  SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
+  GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
+
+  QString anEntry;
   if ( isSubMesh )
   {
-    // get mesh and geom object
-    SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil();
-    GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
-
-    QString anEntry = myDlg->selectedObject
+    anEntry = myDlg->selectedObject
       ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj );
     if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
     {
@@ -921,13 +922,35 @@ SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType,
         }
       }
     }
-
-    if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() )
-      return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
-                                                                    aServerLib.toLatin1().data(),
-                                                                    aMeshVar,
-                                                                    aGeomVar );
   }
+  else // mesh
+  {
+    if ( !myToCreate ) // mesh to edit can be selected
+    {
+      anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
+      if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
+      {
+        aMeshVar = SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() );
+        if ( !aMeshVar->_is_nil() )
+          aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pMesh );
+      }
+    }
+    if ( aGeomVar->_is_nil() ) {
+      anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+      if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
+      {
+        aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
+      }
+    }
+  }
+
+  if ( (!isSubMesh || !aMeshVar->_is_nil()) && !aGeomVar->_is_nil() )
+    return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType.toLatin1().data(),
+                                                                  aServerLib.toLatin1().data(),
+                                                                  aMeshVar,
+                                                                  aGeomVar,
+                                                                  /*byMesh = */isSubMesh);
+
   return SMESH::SMESH_Hypothesis::_nil();
 }
 
@@ -1039,8 +1062,7 @@ void SMESHGUI_MeshOp::createHypothesis (const int theDim,
 
     // Create hypothesis
     if (aCreator) {
-      // When create or edit a submesh, try to initialize a new hypothesis
-      // with values used to mesh a subshape
+      // Get parameters appropriate to initialize a new hypothesis
       SMESH::SMESH_Hypothesis_var initParamHyp =
         getInitParamsHypothesis(theTypeName, aData->ServerLibName);
       myDlg->setEnabled( false );
@@ -1089,7 +1111,11 @@ void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
 
   SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHyp->GetName() );
   if ( aCreator ) {
+    // Get initial parameters
+    SMESH::SMESH_Hypothesis_var initParamHyp =
+      getInitParamsHypothesis( aHyp->GetName(), aHyp->GetLibName());
     myDlg->setEnabled( false );
+    aCreator->setInitParamsHypothesis( initParamHyp );
     aCreator->edit( aHyp.in(), aHypItem.second, dlg() );
     myDlg->setEnabled( true );
   }
@@ -1497,6 +1523,9 @@ bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
 
   // create sub-mesh
   SMESH::SMESH_subMesh_var aSubMeshVar = aMeshVar->GetSubMesh( aGeomVar, aName.toLatin1().data() );
+  _PTR(SObject) aSubMeshSO = SMESH::FindSObject( aSubMeshVar.in() );
+  if ( aSubMeshSO )
+    SMESH::SetName( aSubMeshSO, aName.toLatin1().data() );
 
   for ( int aDim = SMESH::DIM_0D; aDim <= SMESH::DIM_3D; aDim++ )
   {