Salome HOME
Update copyright information
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ShapeByMeshDlg.cxx
index 0a43b137caff1b5b34279f6ff7f9f489b9a262b9..3f4d65bf9bd1665c4d6e8ee40bf662d2e753cbe8 100644 (file)
@@ -1,6 +1,6 @@
-//  SMESH SMESHGUI : GUI for SMESH component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
-//
-//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  SMESH SMESHGUI : GUI for SMESH component
 //  File   : SMESHGUI_ShapeByMeshDlg.cxx
 //  Author : Edward AGAPOV
 //  Module : SMESH
-
+//
 #include "SMESHGUI_ShapeByMeshDlg.h"
 
 #include "SMESHGUI.h"
@@ -67,6 +66,8 @@
 #include <qapplication.h>
 #include <qstringlist.h>
 
+using namespace std;
+
 #define SPACING 5
 #define MARGIN  10
 
@@ -76,28 +77,18 @@ enum { EDGE = 0, FACE, VOLUME };
  * \brief Dialog to publish a sub-shape of the mesh main shape
  *        by selecting mesh elements
  */
-SMESHGUI_ShapeByMeshDlg::SMESHGUI_ShapeByMeshDlg( SMESHGUI*   theModule,
-                                                  const char* theName)
-     : QDialog( SMESH::GetDesktop( theModule ), theName, false,
-                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-     mySMESHGUI( theModule ),
-     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
+SMESHGUI_ShapeByMeshDlg::SMESHGUI_ShapeByMeshDlg()
+  : SMESHGUI_Dialog( 0, false, true, OK | Close )
 {
   setCaption(tr("CAPTION"));
 
-  QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
+  QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), MARGIN, SPACING);
 
-  QFrame* aMainFrame = createMainFrame  (this);
-  QFrame* aBtnFrame  = createButtonFrame(this);
+  QFrame* aMainFrame = createMainFrame  (mainFrame());
 
   aDlgLay->addWidget(aMainFrame);
-  aDlgLay->addWidget(aBtnFrame);
 
   aDlgLay->setStretchFactor(aMainFrame, 1);
-
-  myViewWindow = SMESH::GetViewWindow( mySMESHGUI );
-
-  Init();
 }
 
 //=======================================================================
@@ -124,7 +115,10 @@ QFrame* SMESHGUI_ShapeByMeshDlg::createMainFrame (QWidget* theParent)
   QLabel* anIdLabel = new QLabel( aMainGrp, "element id label");
   anIdLabel->setText( tr("ELEMENT_ID") );
   myElementId = new QLineEdit( aMainGrp, "element id");
-  myElementId->setValidator( new SMESHGUI_IdValidator( theParent, "id validator", 1 ));
+  if (!myIsMultipleAllowed)
+    myElementId->setValidator( new SMESHGUI_IdValidator( theParent, "id validator", 1 ));
+  else
+    myElementId->setValidator( new SMESHGUI_IdValidator( theParent, "id validator" ));
 
   // shape name
   QLabel* aNameLabel = new QLabel( aMainGrp, "geom name label");
@@ -137,38 +131,9 @@ QFrame* SMESHGUI_ShapeByMeshDlg::createMainFrame (QWidget* theParent)
   aLayout->addWidget(aNameLabel,  2, 0);
   aLayout->addWidget(myGeomName,  2, 1);
 
-  connect(myElemTypeGroup, SIGNAL(clicked(int)), SLOT(onTypeChanged(int)));
-  connect(myElementId, SIGNAL(textChanged(const QString&)), SLOT(onElemIdChanged(const QString&)));
-
   return aMainGrp;
 }
 
-//=======================================================================
-// function : createButtonFrame()
-// purpose  : Create frame containing buttons
-//=======================================================================
-QFrame* SMESHGUI_ShapeByMeshDlg::createButtonFrame (QWidget* theParent)
-{
-  QFrame* aFrame = new QFrame(theParent);
-  aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
-
-  myOkBtn    = new QPushButton(tr("SMESH_BUT_OK"   ), aFrame);
-  myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
-
-  QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
-
-  QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING);
-
-  aLay->addWidget(myOkBtn);
-  aLay->addItem(aSpacer);
-  aLay->addWidget(myCloseBtn);
-
-  connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
-  connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
-
-  return aFrame;
-}
-
 //=======================================================================
 // function : ~SMESHGUI_ShapeByMeshDlg()
 // purpose  : Destructor
@@ -178,33 +143,71 @@ SMESHGUI_ShapeByMeshDlg::~SMESHGUI_ShapeByMeshDlg()
   // no need to delete child widgets, Qt does it all for us
 }
 
+//================================================================================
+/*!
+ * \brief Constructor
+*/
+//================================================================================
+SMESHGUI_ShapeByMeshOp::SMESHGUI_ShapeByMeshOp(bool isMultipleAllowed):
+  myIsMultipleAllowed(isMultipleAllowed)
+{
+  if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
+    GeometryGUI::InitGeomGen();
+
+  myDlg = new SMESHGUI_ShapeByMeshDlg;
+  myDlg->setMultipleAllowed(myIsMultipleAllowed);
+
+  connect(myDlg->myElemTypeGroup, SIGNAL(clicked(int)), SLOT(onTypeChanged(int)));
+  connect(myDlg->myElementId, SIGNAL(textChanged(const QString&)), SLOT(onElemIdChanged(const QString&)));
+}
+
+
 //=======================================================================
-// function : Init()
+// function : startOperation()
 // purpose  : Init dialog fields, connect signals and slots, show dialog
 //=======================================================================
-void SMESHGUI_ShapeByMeshDlg::Init()
+void SMESHGUI_ShapeByMeshOp::startOperation()
 {
-  SetMesh( SMESH::SMESH_Mesh::_nil() );
+  //SetMesh( SMESH::SMESH_Mesh::_nil() );
   myIsManualIdEnter = false;
 
-  //erasePreview();
+  SMESHGUI_SelectionOp::startOperation();
 
-  mySMESHGUI->SetActiveDialogBox((QDialog*)this);
+  //activateSelection(); // set filters
+  onSelectionDone(); // desable/enable [ OK ]
 
-  // selection and SMESHGUI
-  connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
-  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
+  myDlg->show();
+}
 
-  setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
-  qApp->processEvents();
-  updateGeometry();
-  adjustSize();
-  resize(minimumSize());
+//================================================================================
+/*!
+ * \brief Destructor
+*/
+//================================================================================
+SMESHGUI_ShapeByMeshOp::~SMESHGUI_ShapeByMeshOp()
+{
+  if ( myDlg )
+    delete myDlg;
+}
 
-  activateSelection();
-  onSelectionDone();
-  
-  this->show();
+//================================================================================
+/*!
+ * \brief Gets dialog of this operation
+  * \retval LightApp_Dialog* - pointer to dialog of this operation
+*/
+//================================================================================
+LightApp_Dialog* SMESHGUI_ShapeByMeshOp::dlg() const
+{
+  return myDlg;
+}
+
+//=======================================================================
+// function : GetShape()
+// purpose  : Get published sub-shape
+//=======================================================================
+GEOM::GEOM_Object_ptr SMESHGUI_ShapeByMeshOp::GetShape()
+{
+  return myGeomObj.in();
 }
 
 //=======================================================================
@@ -212,28 +215,26 @@ void SMESHGUI_ShapeByMeshDlg::Init()
 // purpose  : Set mesh to dialog
 //=======================================================================
 
-void SMESHGUI_ShapeByMeshDlg::SetMesh (SMESH::SMESH_Mesh_ptr thePtr)
+void SMESHGUI_ShapeByMeshOp::SetMesh (SMESH::SMESH_Mesh_ptr thePtr)
 {
   myMesh    = SMESH::SMESH_Mesh::_duplicate(thePtr);
   myGeomObj = GEOM::GEOM_Object::_nil();
   myHasSolids = false;
 
-  vector< bool > hasElement (myElemTypeGroup->count(), false);
-  if (!myMesh->_is_nil() && myViewWindow )
+  vector< bool > hasElement (myDlg->myElemTypeGroup->count(), false);
+  if (!myMesh->_is_nil() )
   {
-    _PTR(SObject) aSobj = SMESH::FindSObject(myMesh.in());
-    SUIT_DataOwnerPtr anIObj (new LightApp_DataOwner(aSobj->GetID().c_str()));
+//     _PTR(SObject) aSobj = SMESH::FindSObject(myMesh.in());
+//     SUIT_DataOwnerPtr anIObj (new LightApp_DataOwner(aSobj->GetID().c_str()));
 
     vector< int > nbShapes( TopAbs_SHAPE, 0 );
     int shapeDim = 0; // max dim with several shapes
-    if ( mySelectionMgr->isOk(anIObj) ) // check that the mesh has a valid shape
+    //if ( /*mySelectionMgr*/ selectionMgr()->isOk(anIObj) ) // check that the mesh has a valid shape
     {
       _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in());
       GEOM::GEOM_Object_var mainShape = SMESH::GetGeom(aSO);
       if ( !mainShape->_is_nil() ) 
       {
-        if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
-          GeometryGUI::InitGeomGen();
         TopoDS_Shape aShape;
         if ( GEOMBase::GetShape(mainShape, aShape))
         {
@@ -259,87 +260,132 @@ void SMESHGUI_ShapeByMeshDlg::SetMesh (SMESH::SMESH_Mesh_ptr thePtr)
       hasElement[ EDGE ]   = shapeDim > 0 && myMesh->NbEdges()  ;
       hasElement[ FACE ]   = shapeDim > 1 && myMesh->NbFaces()  ;
       hasElement[ VOLUME ] = shapeDim > 2 && myMesh->NbVolumes();
-
-      if ( hasElement[ EDGE ] && myViewWindow->GetSelector() )
-      {
-        connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
-      }
     }
     myHasSolids = nbShapes[ TopAbs_SOLID ];
   }
 
   // disable inexistant elem types
-  for ( int i = 0; i < myElemTypeGroup->count(); ++i ) {
-    if ( QButton* button = myElemTypeGroup->find( i ) )
+  for ( int i = 0; i < myDlg->myElemTypeGroup->count(); ++i ) {
+    if ( QButton* button = myDlg->myElemTypeGroup->find( i ) )
       button->setEnabled( hasElement[ i ] );
   }
-  myElementId->setEnabled( hasElement[ EDGE ] );
-  myGeomName-> setEnabled( hasElement[ EDGE ] );
+  myDlg->myElementId->setEnabled( hasElement[ EDGE ] );
+  myDlg->myGeomName-> setEnabled( hasElement[ EDGE ] );
 
   setElementID("");
 }
 
 //=======================================================================
-// function : GetShape()
-// purpose  : Get published sub-shape
+// function : commitOperation()
+// purpose  : called when "Ok" button pressed.
 //=======================================================================
-GEOM::GEOM_Object_ptr SMESHGUI_ShapeByMeshDlg::GetShape()
-{
-  return myGeomObj.in();
-}
 
-//=======================================================================
-// function : onOk()
-// purpose  : SLOT called when "Ok" button pressed.
-//=======================================================================
-void SMESHGUI_ShapeByMeshDlg::onOk()
+void SMESHGUI_ShapeByMeshOp::commitOperation()
 {
+  SMESHGUI_SelectionOp::commitOperation();
   try {
-    int elemID = myElementId->text().toInt();
-    myGeomObj = SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement
-      ( myMesh.in(), elemID, myGeomName->text().latin1());
-
-    accept();
-    emit PublishShape();
+    QStringList aListId = QStringList::split( " ", myDlg->myElementId->text(), false);
+    if (aListId.count() == 1)
+      {
+       int elemID = (aListId.first()).toInt();
+       myGeomObj = GEOM::GEOM_Object::_duplicate(
+           SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement
+         ( myMesh.in(), elemID, myDlg->myGeomName->text().latin1()) );
+      }
+    else
+      {
+       GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
+       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+       
+       if (geomGen->_is_nil() || !aStudy)
+         return;
+       
+       GEOM::GEOM_IShapesOperations_var aShapesOp =
+         geomGen->GetIShapesOperations(aStudy->StudyId());
+       if (aShapesOp->_is_nil() )
+         return;
+       
+       TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
+       
+       std::map<double, GEOM::GEOM_Object_var> aGeomObjectsMap;
+       GEOM::GEOM_Object_var aGeomObject;
+
+       GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
+       
+       for ( int i = 0; i < aListId.count(); i++ )
+         {
+           aGeomObject =
+             SMESHGUI::GetSMESHGen()->FindGeometryByMeshElement(myMesh.in(), aListId[i].toInt());
+
+           if (aGeomObject->_is_nil()) continue;
+           
+           double anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject);
+           if (aShapesOp->IsDone() && aGeomObjectsMap.find(anId) == aGeomObjectsMap.end())
+             {
+               aGeomObjectsMap[anId] = aGeomObject;
+
+               TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aGeomObject->GetShapeType();
+               if (i == 0)
+                 aGroupType = aSubShapeType;
+               else if (aSubShapeType != aGroupType)
+                 aGroupType = TopAbs_SHAPE;
+             }
+         }
+       
+       int aNumberOfGO = aGeomObjectsMap.size();
+       if (aNumberOfGO == 1)
+         myGeomObj = (*aGeomObjectsMap.begin()).second;
+       else if (aNumberOfGO > 1)
+         {
+           GEOM::GEOM_IGroupOperations_var aGroupOp =
+             geomGen->GetIGroupOperations(aStudy->StudyId());
+           if(aGroupOp->_is_nil())
+             return;
+           
+           GEOM::ListOfGO_var aGeomObjects = new GEOM::ListOfGO();
+           aGeomObjects->length( aNumberOfGO );
+
+           int i = 0;
+           std::map<double, GEOM::GEOM_Object_var>::iterator anIter;
+           for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++)
+             aGeomObjects[i++] = (*anIter).second;
+         
+           //create geometry group
+           myGeomObj = aGroupOp->CreateGroup(aMeshShape, aGroupType);
+           aGroupOp->UnionList(myGeomObj, aGeomObjects);
+
+           if (!aGroupOp->IsDone())
+             return;
+         }
+       
+       // publish the GEOM object in study
+       QString aNewGeomGroupName ( myDlg->myGeomName->text().latin1() );
+         
+       SALOMEDS::SObject_var aNewGroupSO =
+       geomGen->AddInStudy(SMESHGUI::GetSMESHGen()->GetCurrentStudy(), myGeomObj, aNewGeomGroupName, aMeshShape);
+      }
   }
   catch (const SALOME::SALOME_Exception& S_ex) {
     SalomeApp_Tools::QtCatchCorbaException(S_ex);
   }
   catch (...) {
   }
-  myViewWindow->SetSelectionMode( ActorSelection );
-  disconnect(mySelectionMgr, 0, this, 0);
-  disconnect(mySMESHGUI, 0, this, 0);
-  mySMESHGUI->ResetState();
-}
 
-//=======================================================================
-// function : onClose()
-// purpose  : SLOT called when "Close" button pressed. Close dialog
-//=======================================================================
-void SMESHGUI_ShapeByMeshDlg::onClose()
-{
-  myViewWindow->SetSelectionMode( ActorSelection );
-  disconnect(mySelectionMgr, 0, this, 0);
-  disconnect(mySMESHGUI, 0, this, 0);
-  mySMESHGUI->ResetState();
-  reject();
-  emit Close();
 }
 
 //=======================================================================
 // function : onSelectionDone()
-// purpose  : SLOT called when selection changed
+// purpose  : SLOT called when selection changed. Enable/desable [ OK ]
 //=======================================================================
-void SMESHGUI_ShapeByMeshDlg::onSelectionDone()
+void SMESHGUI_ShapeByMeshOp::onSelectionDone()
 {
-  myOkBtn->setEnabled( false );
+  myDlg->setButtonEnabled( false, QtxDialog::OK );
   setElementID("");
 
   try {
     SALOME_ListIO aList;
-    mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type());
-    if (aList.Extent() != 1)
+    selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
+    if (!myIsMultipleAllowed && aList.Extent() != 1)
       return;
 
     SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
@@ -347,82 +393,44 @@ void SMESHGUI_ShapeByMeshDlg::onSelectionDone()
       return;
 
     QString aString;
-    int nbElems = SMESH::GetNameOfSelectedElements(myViewWindow->GetSelector(),
+    int nbElems = SMESH::GetNameOfSelectedElements(selector(),//myViewWindow->GetSelector(),
                                                    aList.First(), aString);
-    if ( nbElems == 1 ) {
+    if (nbElems > 0) {
+      if (!myIsMultipleAllowed && nbElems != 1 )
+       return;
       setElementID( aString );
-      myOkBtn->setEnabled( true );
+      myDlg->setButtonEnabled( true, QtxDialog::OK );
     }
   } catch (...) {
   }
 }
 
-//=======================================================================
-// function : onDeactivate()
-// purpose  : SLOT called when dialog must be deativated
-//=======================================================================
-void SMESHGUI_ShapeByMeshDlg::onDeactivate()
-{
-  if ( isEnabled() ) {
-    //disconnect(mySelectionMgr, 0, this, 0);
-    myViewWindow->SetSelectionMode( ActorSelection );
-    setEnabled(false);
-  }
-}
-
-//=======================================================================
-// function : enterEvent()
-// purpose  : Event filter
-//=======================================================================
-void SMESHGUI_ShapeByMeshDlg::enterEvent (QEvent*)
-{
-  // there is a stange problem that enterEvent() comes after onSave()
-  if ( isVisible () && !isEnabled() ) {
-    mySMESHGUI->EmitSignalDeactivateDialog();
-    setEnabled(true);
-    activateSelection();
-    //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
-  }
-}
-
-//=================================================================================
-// function : closeEvent()
-// purpose  : Close dialog box
-//=================================================================================
-void SMESHGUI_ShapeByMeshDlg::closeEvent (QCloseEvent*)
-{
-  onClose();
-}
-
 //=======================================================================
 // function : activateSelection()
 // purpose  : Activate selection in accordance with current pattern type
 //=======================================================================
-void SMESHGUI_ShapeByMeshDlg::activateSelection()
+void SMESHGUI_ShapeByMeshOp::activateSelection()
 {
-  mySelectionMgr->clearFilters();
-  SMESH::SetPointRepresentation(false);
-
-  myGeomName->setText("");
-
-  if ( myViewWindow )
-  {
-    QString geomName;
-    Selection_Mode mode = EdgeSelection;
-    switch ( myElemTypeGroup->id( myElemTypeGroup->selected() )) {
-    case EDGE  :
-      mode = EdgeSelection;   geomName = tr("GEOM_EDGE"); break;
-    case FACE  :
-      mode = FaceSelection;   geomName = tr("GEOM_FACE"); break;
-    case VOLUME:
-      mode = VolumeSelection; geomName = tr(myHasSolids ? "GEOM_SOLID" : "GEOM_SHELL"); break;
-    default: return;
-    }
-    if ( myViewWindow->SelectionMode() != mode )
-      myViewWindow->SetSelectionMode( mode );
-
-    myGeomName->setText( GEOMBase::GetDefaultName( geomName ));
+  selectionMgr()->clearFilters();
+  //SMESH::SetPointRepresentation(false);
+
+  myDlg->myGeomName->setText("");
+
+  QString geomName;
+  Selection_Mode mode = EdgeSelection;
+  switch ( myDlg->myElemTypeGroup->id( myDlg->myElemTypeGroup->selected() )) {
+  case EDGE  :
+    mode = EdgeSelection;   geomName = tr("GEOM_EDGE"); break;
+  case FACE  :
+    mode = FaceSelection;   geomName = tr("GEOM_FACE"); break;
+  case VOLUME:
+    mode = VolumeSelection; geomName = tr(myHasSolids ? "GEOM_SOLID" : "GEOM_SHELL"); break;
+  default: return;
   }
+  if ( selectionMode() != mode )
+    setSelectionMode( mode );
+
+  myDlg->myGeomName->setText( GEOMBase::GetDefaultName( geomName ));
 }
 
 //=======================================================================
@@ -430,7 +438,7 @@ void SMESHGUI_ShapeByMeshDlg::activateSelection()
 //purpose  : SLOT. Called when element type changed.
 //=======================================================================
 
-void SMESHGUI_ShapeByMeshDlg::onTypeChanged (int theType)
+void SMESHGUI_ShapeByMeshOp::onTypeChanged (int theType)
 {
   setElementID("");
   activateSelection();
@@ -442,16 +450,16 @@ void SMESHGUI_ShapeByMeshDlg::onTypeChanged (int theType)
 //           Highlight the element whose Ids the user entered manually
 //=======================================================================
 
-void SMESHGUI_ShapeByMeshDlg::onElemIdChanged(const QString& theNewText)
+void SMESHGUI_ShapeByMeshOp::onElemIdChanged(const QString& theNewText)
 {
-  myOkBtn->setEnabled( false );
+  myDlg->setButtonEnabled( false, QtxDialog::OK );
 
-  if ( myIsManualIdEnter && !myMesh->_is_nil() && myViewWindow )
+  if ( myIsManualIdEnter && !myMesh->_is_nil() )
     if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) )
       if ( SMDS_Mesh* aMesh = actor->GetObject()->GetMesh() )
       {
         SMDSAbs_ElementType type = SMDSAbs_Edge;
-        switch ( myElemTypeGroup->id( myElemTypeGroup->selected() )) {
+        switch ( myDlg->myElemTypeGroup->id( myDlg->myElemTypeGroup->selected() )) {
         case EDGE  : type = SMDSAbs_Edge;   break;
         case FACE  : type = SMDSAbs_Face;   break;
         case VOLUME: type = SMDSAbs_Volume; break;
@@ -465,12 +473,16 @@ void SMESHGUI_ShapeByMeshDlg::onElemIdChanged(const QString& theNewText)
               newIndices.Add( e->GetID() );
         }
 
-        if ( !newIndices.IsEmpty() && newIndices.Extent() == 1 )
-          if ( SVTK_Selector* s = myViewWindow->GetSelector() ) {
-            s->AddOrRemoveIndex( actor->getIO(), newIndices, false );
-            myViewWindow->highlight( actor->getIO(), true, true );
-            myOkBtn->setEnabled( true );
-          }
+       if ( !newIndices.IsEmpty() )
+         {
+           if (!myIsMultipleAllowed && newIndices.Extent() != 1)
+             return;
+           if ( SVTK_Selector* s = selector() ) {
+             s->AddOrRemoveIndex( actor->getIO(), newIndices, false );
+             viewWindow()->highlight( actor->getIO(), true, true );
+             myDlg->setButtonEnabled( true, QtxDialog::OK );
+           }
+         }
       }
 }
 
@@ -479,9 +491,9 @@ void SMESHGUI_ShapeByMeshDlg::onElemIdChanged(const QString& theNewText)
 //purpose  : programmatically set element id
 //=======================================================================
 
-void SMESHGUI_ShapeByMeshDlg::setElementID(const QString& theText)
+void SMESHGUI_ShapeByMeshOp::setElementID(const QString& theText)
 {
   myIsManualIdEnter = false;
-  myElementId->setText(theText);
+  myDlg->myElementId->setText(theText);
   myIsManualIdEnter = true;
 }