Salome HOME
imn/auto-reorder_of_nodes_ver2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_AddMeshElementDlg.cxx
index 2febf76f82f06b54077812d8cbefdc472d8ae509..20452fc65c95785afb236029fffeaf436dccbe41 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include <SalomeApp_Application.h>
 #include <SVTK_ViewModel.h>
 #include <SVTK_ViewWindow.h>
+#include <VTKViewer_PolyDataMapper.h>
+#include <SVTK_Renderer.h>
+#include <Qtx.h>
+
 
 // IDL incldues
 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
@@ -65,6 +69,7 @@
 #include <vtkDataSetMapper.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkProperty.h>
+#include <vtkCellData.h>
 
 // Qt includes
 #include <QComboBox>
@@ -95,6 +100,10 @@ namespace SMESH
     SALOME_Actor* myPreviewActor;
     vtkDataSetMapper* myMapper;
     vtkUnstructuredGrid* myGrid;
+    
+    SALOME_Actor* myBallActor;
+    VTKViewer_PolyDataMapper* myBallMapper;
+    vtkPolyData* myBallPolyData; 
 
     SALOME_Actor* myFaceOrientation;
     vtkPolyDataMapper* myFaceOrientationDataMapper;
@@ -113,23 +122,25 @@ namespace SMESH
 
       // Create and display actor
       myMapper = vtkDataSetMapper::New();
-      myMapper->SetInput(myGrid);
+      myMapper->SetInputData(myGrid);
 
       myPreviewActor = SALOME_Actor::New();
       myPreviewActor->PickableOff();
       myPreviewActor->VisibilityOff();
       myPreviewActor->SetMapper(myMapper);
 
-      vtkFloatingPointType anRGB[3];
+      QColor ffc, bfc;
+      int delta;
+
       vtkProperty* aProp = vtkProperty::New();
-      GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) );
-      aProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
+      SMESH::GetColor( "SMESH", "preview_color", ffc, delta, "0, 255, 0|-100" ) ;
+      aProp->SetColor( ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255. );
       myPreviewActor->SetProperty( aProp );
       aProp->Delete();
 
       vtkProperty* aBackProp = vtkProperty::New();
-      GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) );
-      aBackProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
+      bfc = Qtx::mainColorToSecondary(ffc, delta);
+      aBackProp->SetColor( bfc.red() / 255. , bfc.green() / 255. , bfc.blue() / 255. );
       myPreviewActor->SetBackfaceProperty( aBackProp );
       aBackProp->Delete();
 
@@ -137,10 +148,10 @@ namespace SMESH
 
       // Orientation of faces
       myFaceOrientationFilter = SMESH_FaceOrientationFilter::New();
-      myFaceOrientationFilter->SetInput(myGrid);
+      myFaceOrientationFilter->SetInputData(myGrid);
 
       myFaceOrientationDataMapper = vtkPolyDataMapper::New();
-      myFaceOrientationDataMapper->SetInput(myFaceOrientationFilter->GetOutput());
+      myFaceOrientationDataMapper->SetInputConnection(myFaceOrientationFilter->GetOutputPort());
 
       myFaceOrientation = SALOME_Actor::New();
       myFaceOrientation->PickableOff();
@@ -148,12 +159,34 @@ namespace SMESH
       myFaceOrientation->SetMapper(myFaceOrientationDataMapper);
 
       vtkProperty* anOrientationProp = vtkProperty::New();
+      double anRGB[3];
       GetColor( "SMESH", "orientation_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) );
       anOrientationProp->SetColor( anRGB[0], anRGB[1], anRGB[2] );
       myFaceOrientation->SetProperty( anOrientationProp );
       anOrientationProp->Delete();
-
       myVTKViewWindow->AddActor(myFaceOrientation);
+
+      // Preview for the balls
+      vtkProperty* aBallProp = vtkProperty::New();
+      aBallProp->SetColor(ffc.red() / 255. , ffc.green() / 255. , ffc.blue() / 255.);
+      double aBallElemSize = SMESH::GetFloat("SMESH:ball_elem_size",10);
+      aBallProp->SetPointSize(aBallElemSize);
+
+      myBallPolyData = vtkPolyData::New();
+      myBallPolyData->Allocate();
+
+      myBallMapper = VTKViewer_PolyDataMapper::New();
+      myBallMapper->SetInputData(myBallPolyData);
+      myBallMapper->SetBallEnabled(true);
+
+      myBallActor = SALOME_Actor::New();
+      myBallActor->PickableOff();
+      myBallActor->SetVisibility(false);
+      myBallActor->SetProperty(aBallProp);
+      myBallActor->SetMapper(myBallMapper);
+      aBallProp->Delete();
+      
+      myVTKViewWindow->AddActor(myBallActor);
     }
 
     typedef std::vector<vtkIdType> TVTKIds;
@@ -163,7 +196,7 @@ namespace SMESH
     {
       vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
       myGrid->SetPoints(aGrid->GetPoints());
-      myGrid->Reset();
+      myGrid->Reset();      
 
       const std::vector<int>& interlace = SMDS_MeshCell::toVtkOrder( VTKCellType( theType ));
       SMDS_MeshCell::applyInterlace( interlace, theIds );
@@ -177,36 +210,68 @@ namespace SMESH
 
       myGrid->Modified();
 
-      SetVisibility(true, theActor->GetFacesOriented());
+      SetVisibility(true, theActor->GetFacesOriented(), false);
     }
 
+    void SetBallPosition(SMESH_Actor* theActor,TVTKIds& theIds, double theDiameter) {
+      vtkUnstructuredGrid *aGrid = theActor->GetUnstructuredGrid();
+      myBallPolyData->Reset();
+      myBallPolyData->DeleteCells();
+      myBallPolyData->SetPoints(aGrid->GetPoints());
+      
+      vtkDataArray* aScalars = vtkDataArray::CreateDataArray(VTK_DOUBLE);
+      aScalars->SetNumberOfComponents(1);
+      aScalars->SetNumberOfTuples(theIds.size());
+      myBallPolyData->GetCellData()->SetScalars(aScalars);
+      aScalars->Delete();
+
+      vtkIdList *anIds = vtkIdList::New();
+      anIds->SetNumberOfIds(1);
+      for (int i = 0, iEnd = theIds.size(); i < iEnd; i++){
+        anIds->InsertId(0,theIds[i]);
+        vtkIdType anId = myBallPolyData->InsertNextCell(VTK_POLY_VERTEX,anIds);
+        double d = theDiameter * theActor->GetBallScale();
+        aScalars->SetTuple(anId,&d);
+        anIds->Reset();
+      }
+      
+      anIds->Delete();
+      myBallPolyData->Modified();
+      SetVisibility (false, false, true);
+    }
 
-    void SetVisibility (bool theVisibility, bool theShowOrientation = false)
+    void SetVisibility (bool theVisibility, bool theShowOrientation = false, bool theShowBalls = false)
     {
       myPreviewActor->SetVisibility(theVisibility);
       myFaceOrientation->SetVisibility(theShowOrientation);
+      myBallActor->SetVisibility(theShowBalls);
       RepaintCurrentView();
     }
 
 
     ~TElementSimulation()
     {
+      myMapper->RemoveAllInputs();
+      myFaceOrientationDataMapper->RemoveAllInputs();
+      myBallMapper->RemoveAllInputs();
+
       if (FindVtkViewWindow(myApplication->activeViewManager(), myViewWindow)) {
-        myVTKViewWindow->RemoveActor(myPreviewActor);
-        myVTKViewWindow->RemoveActor(myFaceOrientation);
+        myVTKViewWindow->RemoveActor(myPreviewActor,false,false);
+        myVTKViewWindow->RemoveActor(myFaceOrientation,false,false);
+        myVTKViewWindow->RemoveActor(myBallActor,false,false);
       }
-      myPreviewActor->Delete();
-      myFaceOrientation->Delete();
 
-      myMapper->RemoveAllInputs();
       myMapper->Delete();
-
-      myFaceOrientationFilter->Delete();
-
-      myFaceOrientationDataMapper->RemoveAllInputs();
+      myGrid->Delete();
+      myPreviewActor->Delete();
+            
+      myFaceOrientationFilter->Delete();      
       myFaceOrientationDataMapper->Delete();
+      myFaceOrientation->Delete();
 
-      myGrid->Delete();
+      myBallMapper->Delete();
+      myBallPolyData->Delete();
+      myBallActor->Delete();
     }
   };
 }
@@ -343,18 +408,31 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI*          theMo
   SelectButtonC1A1 = new QPushButton(GroupC1);
   SelectButtonC1A1->setIcon(image1);
   LineEditC1A1 = new QLineEdit(GroupC1);
-  LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, myIsPoly ? 1000 : myNbNodes));
+  LineEditC1A1->setValidator
+    (new SMESHGUI_IdValidator(this, ( myIsPoly || myNbNodes == 1 ) ? 1000 : myNbNodes));
 
   Reverse = (myElementType == SMDSAbs_Face || myElementType == SMDSAbs_Volume ) ? new QCheckBox(tr("SMESH_REVERSE"), GroupC1) : 0;
 
+  AutomaticPresentation = (myGeomType == SMDSEntity_Quadrangle || myGeomType == SMDSEntity_Polygon ||
+                           myGeomType == SMDSEntity_Pyramid    || myGeomType == SMDSEntity_Hexa    ||
+                           myGeomType == SMDSEntity_Penta      || myGeomType == SMDSEntity_Hexagonal_Prism ) ? new QCheckBox(tr("SMESH_AUTOMATIC_PRESENTATION"), GroupC1) : 0;
+  if ( AutomaticPresentation ) {
+    GetNextPresentationButton = new QPushButton(tr("SMESH_BUT_GET_NEXT_SHAPE"), GroupC1);
+    GetNextPresentationButton->setAutoDefault(false);
+  }
   DiameterSpinBox = ( myGeomType == SMDSEntity_Ball ) ? new SMESHGUI_SpinBox(GroupC1) : 0;
   QLabel* diameterLabel = DiameterSpinBox ? new QLabel( tr("BALL_DIAMETER"),GroupC1) : 0;
 
   GroupC1Layout->addWidget(TextLabelC1A1,    0, 0);
   GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
   GroupC1Layout->addWidget(LineEditC1A1,     0, 2);
+  if ( AutomaticPresentation ) {
+    AutomaticPresentation->setChecked(true);
+    GroupC1Layout->addWidget(AutomaticPresentation, 1, 0, 1, 2);
+    GroupC1Layout->addWidget(GetNextPresentationButton, 1, 2, 1, 1);
+  }
   if ( Reverse ) {
-    GroupC1Layout->addWidget(Reverse, 1, 0, 1, 3);
+    GroupC1Layout->addWidget(Reverse, 2, 0, 1, 3);
   }
   if ( DiameterSpinBox ) {
     GroupC1Layout->addWidget(diameterLabel,   1, 0);
@@ -362,6 +440,7 @@ SMESHGUI_AddMeshElementDlg::SMESHGUI_AddMeshElementDlg( SMESHGUI*          theMo
 
     DiameterSpinBox->RangeStepAndValidator( 1e-7, 1e+9, 0.1 );
     DiameterSpinBox->SetValue( 1. );
+    connect( DiameterSpinBox, SIGNAL( valueChanged ( double ) ), this, SLOT( onDiameterChanged( ) ) );
   }
   /* Add to group ************************************************/
   GroupGroups = new QGroupBox( tr( "SMESH_ADD_TO_GROUP" ), this );
@@ -439,22 +518,25 @@ void SMESHGUI_AddMeshElementDlg::Init()
   myActor = 0;
 
   /* signals and slots connections */
-  connect(buttonOk, SIGNAL(clicked()),     SLOT(ClickOnOk()));
-  connect(buttonCancel, SIGNAL(clicked()), SLOT(ClickOnCancel()));
-  connect(buttonApply, SIGNAL(clicked()),  SLOT(ClickOnApply()));
-  connect(buttonHelp, SIGNAL(clicked()),   SLOT(ClickOnHelp()));
-
-  connect(SelectButtonC1A1, SIGNAL(clicked()), SLOT(SetEditCurrentArgument()));
-  connect(LineEditC1A1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
-  connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), SLOT(DeactivateActiveDialog()));
-  connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(SelectionIntoArgument()));
+  connect(buttonOk,                SIGNAL(clicked()),                     SLOT(ClickOnOk()));
+  connect(buttonCancel,            SIGNAL(clicked()),                     SLOT(reject()));
+  connect(buttonApply,             SIGNAL(clicked()),                     SLOT(ClickOnApply()));
+  connect(buttonHelp,              SIGNAL(clicked()),                     SLOT(ClickOnHelp()));
+
+  connect(SelectButtonC1A1,        SIGNAL(clicked()),                     SLOT(SetEditCurrentArgument()));
+  connect(LineEditC1A1,            SIGNAL(textChanged(const QString&)),   SLOT(onTextChange(const QString&)));
+  connect(mySMESHGUI,              SIGNAL(SignalDeactivateActiveDialog()),SLOT(DeactivateActiveDialog()));
+  connect(mySelectionMgr,          SIGNAL(currentSelectionChanged()),     SLOT(SelectionIntoArgument()));
   /* to close dialog if study frame change */
-  connect(mySMESHGUI, SIGNAL (SignalStudyFrameChanged()), SLOT(ClickOnCancel()));
-  connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), SLOT(ClickOnCancel()));    
+  connect(mySMESHGUI,              SIGNAL(SignalStudyFrameChanged()),     SLOT(reject()));
+  connect(mySMESHGUI,              SIGNAL(SignalCloseAllDialogs()),       SLOT(reject()));
 
   if (Reverse)
-    connect(Reverse, SIGNAL(stateChanged(int)), SLOT(CheckBox(int)));
-
+    connect(Reverse,               SIGNAL(stateChanged(int)),             SLOT(CheckBox(int)));
+  if (AutomaticPresentation) {
+    connect(AutomaticPresentation, SIGNAL(stateChanged(int)),             SLOT(SelectionIntoArgument()));
+    connect(GetNextPresentationButton, SIGNAL(clicked()),                 SLOT(GetNextShapePresentation()));
+  }
   // set selection mode
   SMESH::SetPointRepresentation(true);
 
@@ -477,9 +559,9 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
 
   if (myNbOkNodes && !mySMESHGUI->isActiveStudyLocked()) {
     myBusy = true;
-    SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
-    anArrayOfIndices->length(myNbNodes);
     QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
+    SMESH::long_array_var anArrayOfIndices = new SMESH::long_array;
+    anArrayOfIndices->length(aListId.count());
     const std::vector<int>& revIndex = SMDS_MeshCell::reverseSmdsOrder( myGeomType );
     if ( Reverse && Reverse->isChecked() && !revIndex.empty() )
       for (int i = 0; i < aListId.count(); i++)
@@ -498,12 +580,12 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
     int idx = 0;
     if( addToGroup ) {
       aGroupName = ComboBox_GroupName->currentText();
-      for ( int i = 1; i < ComboBox_GroupName->count(); i++ ) {
+      for ( int i = 1; i <= ComboBox_GroupName->count(); i++ ) {
         QString aName = ComboBox_GroupName->itemText( i );
         if ( aGroupName == aName && ( i == ComboBox_GroupName->currentIndex() || idx == 0 ) )
           idx = i;
       }
-      if ( idx > 0 && idx < myGroups.count() ) {
+      if ( idx > 0 && idx <= myGroups.count() ) {
         SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( myGroups[idx-1] );
         if ( !aGeomGroup->_is_nil() ) {
           int res = SUIT_MessageBox::question( this, tr( "SMESH_WRN_WARNING" ),
@@ -515,28 +597,38 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
       }
     }
 
-    long anElemId = -1;
     SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
+    SMESH::long_array_var anIdList = new SMESH::long_array;
+    anIdList->length( 1 );
+    anIdList[0] = -1;
+
     switch (myElementType) {
     case SMDSAbs_0DElement:
-      anElemId = aMeshEditor->Add0DElement(anArrayOfIndices[0]); break;
+      anIdList->length( anArrayOfIndices->length() );
+      for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
+        anIdList[i] = aMeshEditor->Add0DElement(anArrayOfIndices[i]);
+      break;
     case SMDSAbs_Ball:
-      if ( myGeomType == SMDSEntity_Ball )
-        anElemId = aMeshEditor->AddBall(anArrayOfIndices[0],
-                                        DiameterSpinBox->GetValue()); break;
+      if ( myGeomType == SMDSEntity_Ball ) {
+        anIdList->length( anArrayOfIndices->length() );
+        for ( size_t i = 0; i < anArrayOfIndices->length(); ++i )
+          anIdList[i] = aMeshEditor->AddBall(anArrayOfIndices[i],
+                                             DiameterSpinBox->GetValue());
+      }
+      break;
     case SMDSAbs_Edge:
-      anElemId = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
+      anIdList[0] = aMeshEditor->AddEdge(anArrayOfIndices.inout()); break;
     case SMDSAbs_Face:
       if ( myIsPoly )
-        anElemId = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
+        anIdList[0] = aMeshEditor->AddPolygonalFace(anArrayOfIndices.inout());
       else
-        anElemId = aMeshEditor->AddFace(anArrayOfIndices.inout());
+        anIdList[0] = aMeshEditor->AddFace(anArrayOfIndices.inout());
       break;
     default:
-      anElemId = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
+      anIdList[0] = aMeshEditor->AddVolume(anArrayOfIndices.inout()); break;
     }
 
-    if ( anElemId != -1 && addToGroup && !aGroupName.isEmpty() ) {
+    if ( anIdList[0] > 0 && addToGroup && !aGroupName.isEmpty() ) {
       SMESH::SMESH_Group_var aGroupUsed;
       if ( aGroup->_is_nil() ) {
         // create new group 
@@ -559,23 +651,21 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
           aGroupUsed = SMESH::SMESH_Group::_narrow( aGroup );
       }
 
-      if ( !aGroupUsed->_is_nil() ) {
-        SMESH::long_array_var anIdList = new SMESH::long_array;
-        anIdList->length( 1 );
-        anIdList[0] = anElemId;
+      if ( !aGroupUsed->_is_nil() )
         aGroupUsed->Add( anIdList.inout() );
-      }
     }
 
     SALOME_ListIO aList; aList.Append( myActor->getIO() );
     mySelector->ClearIndex();
     mySelectionMgr->setSelectedObjects( aList, false );
 
-    SMESH::UpdateView();
     mySimulation->SetVisibility(false);
-
+    SMESH::UpdateView();
+    
     buttonOk->setEnabled(false);
     buttonApply->setEnabled(false);
+    if ( AutomaticPresentation )
+      GetNextPresentationButton->setEnabled(false);
 
     myEditCurrentArgument->setText("");
 
@@ -592,23 +682,22 @@ void SMESHGUI_AddMeshElementDlg::ClickOnApply()
 void SMESHGUI_AddMeshElementDlg::ClickOnOk()
 {
   ClickOnApply();
-  ClickOnCancel();
+  reject();
 }
 
 //=================================================================================
-// function : ClickOnCancel()
+// function : reject()
 // purpose  :
 //=================================================================================
-void SMESHGUI_AddMeshElementDlg::ClickOnCancel()
+void SMESHGUI_AddMeshElementDlg::reject()
 {
-  //mySelectionMgr->clearSelected();
   mySimulation->SetVisibility(false);
   SMESH::SetPointRepresentation(false);
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode( ActorSelection );
   disconnect(mySelectionMgr, 0, this, 0);
   mySMESHGUI->ResetState();
-  reject();
+  QDialog::reject();
 }
 
 //=================================================================================
@@ -649,6 +738,8 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
 
   buttonOk->setEnabled(false);
   buttonApply->setEnabled(false);
+  if ( AutomaticPresentation )
+    GetNextPresentationButton->setEnabled(false);
 
   mySimulation->SetVisibility(false);
 
@@ -676,7 +767,7 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
       aViewWindow->highlight( myActor->getIO(), true, true );
 
-    myNbOkNodes = ( allOk && myNbNodes == aListId.count() );
+    myNbOkNodes = ( allOk && ( myNbNodes == aListId.count() || myNbNodes == 1 ));
 
     if (myIsPoly)
       {
@@ -690,6 +781,8 @@ void SMESHGUI_AddMeshElementDlg::onTextChange (const QString& theNewText)
   if(myNbOkNodes) {
     buttonOk->setEnabled(true);
     buttonApply->setEnabled(true);
+    if ( AutomaticPresentation && AutomaticPresentation->isChecked() )
+      GetNextPresentationButton->setEnabled(true);
     displaySimulation();
   }
 
@@ -709,6 +802,7 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
   myActor = 0;
 
   myBusy = true;
+  QString anOldEditArgument = myEditCurrentArgument->text();
   myEditCurrentArgument->setText("");
   myBusy = false;
 
@@ -717,6 +811,8 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
 
   buttonOk->setEnabled(false);
   buttonApply->setEnabled(false);
+  if ( AutomaticPresentation )
+    GetNextPresentationButton->setEnabled(false);
 
   mySimulation->SetVisibility(false);
   //  SMESH::SetPointRepresentation(true);
@@ -760,14 +856,34 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
 
   // get selected nodes
   QString aString = "";
-  int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,myActor->getIO(),aString);
-  myBusy = true;
-  myEditCurrentArgument->setText(aString);
-  myBusy = false;
-  if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 ) {
-    myNbNodes = nbNodes;
-  } else if (myNbNodes != nbNodes) {
-    return;
+  int nbNodes = 0;
+  while ( aString == "" || anOldEditArgument == aString ) {
+    if ( AutomaticPresentation && AutomaticPresentation->isChecked() ) {
+      nbNodes = SMESH::GetNameOfSelectedSortedNodes( myGeomType , mySelector, myActor, myShift, aString );
+    }
+    else
+      nbNodes = SMESH::GetNameOfSelectedNodes( mySelector, myActor->getIO(), aString );
+    if ( aString!= "" && myNbNodes == nbNodes && anOldEditArgument == aString && AutomaticPresentation && AutomaticPresentation->isChecked()) {
+      myShift++;
+      if ( myShift > nbNodes ) {
+        myEditCurrentArgument->setText(aString);
+        myShift = 0;
+        break;
+      }
+      continue;
+    }
+    myBusy = true;
+    myEditCurrentArgument->setText(aString);
+    myBusy = false;
+    if (myIsPoly && myElementType == SMDSAbs_Face && nbNodes >= 3 )
+      myNbNodes = nbNodes;
+    else if (myNbNodes != nbNodes && myNbNodes != 1) {
+      myShift = 0;
+      return;
+    }
+    if ( !AutomaticPresentation || !AutomaticPresentation->isChecked() ||
+       ( myIsPoly && nbNodes < 3 ) )
+      break;
   }
 
   // OK
@@ -775,6 +891,8 @@ void SMESHGUI_AddMeshElementDlg::SelectionIntoArgument()
 
   buttonOk->setEnabled(true);
   buttonApply->setEnabled(true);
+  if ( AutomaticPresentation && AutomaticPresentation->isChecked() )
+    GetNextPresentationButton->setEnabled(true);
 
   displaySimulation();
 }
@@ -801,7 +919,11 @@ void SMESHGUI_AddMeshElementDlg::displaySimulation()
     }
 
     vtkIdType aType = SMDS_MeshCell::toVtkType( myGeomType );
-    mySimulation->SetPosition(myActor,aType,anIds);
+    if(aType == VTK_POLY_VERTEX) {
+      mySimulation->SetBallPosition(myActor,anIds,DiameterSpinBox->GetValue());
+    } else {
+      mySimulation->SetPosition(myActor,aType,anIds);
+    }
     SMESH::UpdateView();
   }
 }
@@ -820,6 +942,16 @@ void SMESHGUI_AddMeshElementDlg::SetEditCurrentArgument()
   SelectionIntoArgument();
 }
 
+//=================================================================================
+// function : GetNextShapePresentation()
+// purpose  :
+//=================================================================================
+void SMESHGUI_AddMeshElementDlg::GetNextShapePresentation()
+{
+  myShift++;
+  SetEditCurrentArgument();
+}
+
 //=================================================================================
 // function : DeactivateActiveDialog()
 // purpose  :
@@ -867,26 +999,6 @@ void SMESHGUI_AddMeshElementDlg::enterEvent (QEvent*)
   ActivateThisDialog();
 }
 
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void SMESHGUI_AddMeshElementDlg::closeEvent (QCloseEvent*)
-{
-  /* same than click on cancel button */
-  ClickOnCancel();
-}
-
-//=================================================================================
-// function : hideEvent()
-// purpose  : caused by ESC key
-//=================================================================================
-void SMESHGUI_AddMeshElementDlg::hideEvent (QHideEvent*)
-{
-  if (!isMinimized())
-    ClickOnCancel();
-}
-
 //=================================================================================
 // function : CheckBox()
 // purpose  :
@@ -918,6 +1030,14 @@ void SMESHGUI_AddMeshElementDlg::keyPressEvent( QKeyEvent* e )
   }
 }
 
+//=================================================================================
+// function : isValid
+// purpose  :
+//=================================================================================
+void SMESHGUI_AddMeshElementDlg::onDiameterChanged(){
+  displaySimulation();
+}
+
 //=================================================================================
 // function : isValid
 // purpose  :