void DialogRepositionSurface::OnApply()
{
  LayerSurface* surf = (LayerSurface*)MainWindow::GetMainWindow()->GetActiveLayer("Surface");
  LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindow()->GetActiveLayer("MRI");
  QString msg;
  if ( !surf )
    msg = "No active surface found.";
  else if ( !mri && ui->tabWidget->currentIndex() == 0)
    msg = "No active volume found.";

  if (!msg.isEmpty())
  {
    QMessageBox::warning(this, "Error", msg);
    return;
  }

  if (ValidateAll())
  {
    ui->pushButtonApply->setDisabled(true);
    if (ui->tabWidget->currentIndex() == 0)
    {
      if (ui->comboBoxTarget->currentIndex() == 0)
      {
        surf->RepositionSurface(mri, GetVertex(),
                                GetIntensity(),
                                GetNeighborSize(),
                                GetSigma(),
                                GetFlags());
      }
      else
      {
        double pos[3];
        GetCoordinate(pos);
        surf->RepositionSurface( mri, GetVertex(),
                                       pos,
                                       GetNeighborSize(),
                                       GetSigma(),
                                       GetFlags());
      }
    }
    else if (ui->tabWidget->currentIndex() == 1)
    {
      double pos[3];
      GetCoordinate(pos);
      surf->RepositionVertex(GetVertex(), pos);
    }
    else
    {
      surf->RepositionSmoothSurface(GetVertex(), GetNeighborSize(), GetSmoothingSteps());
    }
    UpdateUI();
    ui->pushButtonApply->setDisabled(false);
    QTimer::singleShot(0, MainWindow::GetMainWindow(), SIGNAL(SlicePositionChanged()));
  }
}
void DialogRepositionSurface::OnApply( wxCommandEvent& event )
{
  LayerSurface* surf = (LayerSurface*)MainWindow::GetMainWindowPointer()->GetActiveLayer( "Surface" );
  LayerMRI* mri = (LayerMRI*)MainWindow::GetMainWindowPointer()->GetActiveLayer( "MRI" );
  wxString msg;
  if ( !surf )
    msg = _("No active surface found.");
  else if ( !mri )
    msg = _("No active volume found." );
  
  if ( !msg.IsEmpty() )
  {
    wxMessageDialog dlg( this, msg, _("Error"), wxOK );
    dlg.ShowModal();
    return;
  }
  if ( ValidateAll() )
  {
    if ( m_choiceTarget->GetCurrentSelection() == 0 )
    {
      surf->RepositionSurface( mri, GetVertex(), 
                           GetIntensity(),
                           GetNeighborSize(),
                           GetSigma() );
    }
    else
    {
      double pos[3];
      GetCoordinate( pos );
      surf->RepositionSurface( mri, GetVertex(), 
                               pos,
                               GetNeighborSize(),
                               GetSigma() );
    }
    UpdateUI();
  }
}