From 281f6c65506bc1ac91ddf48f5028c77219e2c6d1 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Thu, 25 Aug 2016 07:43:23 +0000 Subject: [PATCH] allow to change solver name and executable location interactively in the Solver module --- Fltk/solverButton.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/Fltk/solverButton.cpp b/Fltk/solverButton.cpp index 718d59d3f4..f645039817 100644 --- a/Fltk/solverButton.cpp +++ b/Fltk/solverButton.cpp @@ -9,11 +9,74 @@ #elif defined(HAVE_NO_INTPTR_T) typedef unsigned long intptr_t; #endif +#include <FL/fl_ask.H> #include "GmshMessage.h" #include "FlGui.h" #include "Options.h" #include "onelabGroup.h" #include "solverButton.h" +#include "fileDialogs.h" + +static void solver_rename_cb(Fl_Widget *w, void *data) +{ + if(FlGui::instance()->onelab->isBusy()){ + Msg::Warning("Cannot rename client while solver is running"); + return; + } + + int num = (intptr_t)data; + + std::string name = opt_solver_name(num, GMSH_GET, ""); + onelab::server::citer it = onelab::server::instance()->findClient(name); + if(it != onelab::server::instance()->lastClient()){ + delete *it; + } + + const char *n = fl_input("Solver name:", ""); + if(n){ + opt_solver_name(num, GMSH_SET, name); + std::string exe = opt_solver_executable(num, GMSH_GET, ""); + std::string host = opt_solver_remote_login(num, GMSH_GET, ""); + FlGui::instance()->onelab->addSolver(n, exe, host, num); + } + FlGui::instance()->onelab->rebuildSolverList(); +} + + +static void solver_change_exe_cb(Fl_Widget *w, void *data) +{ + if(FlGui::instance()->onelab->isBusy()){ + Msg::Warning("Cannot change executable name while solver is running"); + return; + } + + int num = (intptr_t)data; + + std::string name = opt_solver_name(num, GMSH_GET, ""); + onelab::server::citer it = onelab::server::instance()->findClient(name); + if(it != onelab::server::instance()->lastClient()){ + delete *it; + } + + std::string exe = opt_solver_executable(num, GMSH_GET, ""); + std::string host = opt_solver_remote_login(num, GMSH_GET, ""); + + const char *old = 0; + if(exe.size()) old = exe.c_str(); + std::string title = "Choose location of " + name + " executable"; + std::string pattern = "*"; +#if defined(WIN32) + pattern += ".exe"; +#endif + if(fileChooser(FILE_CHOOSER_SINGLE, title.c_str(), pattern.c_str(), old)) + exe = fileChooserGetName(1); + + if(exe.size()){ + opt_solver_executable(num, GMSH_SET, exe); + FlGui::instance()->onelab->addSolver(name, exe, host, num); + } + FlGui::instance()->onelab->rebuildSolverList(); +} static void solver_remove_cb(Fl_Widget *w, void *data) { @@ -62,6 +125,9 @@ solverButton::solverButton(int x, int y, int w, int h, int num, Fl_Color col) _butt[1]->selection_color(col); _popup = new Fl_Menu_Button(x + w - popw, y, popw, h); _popup->type(Fl_Menu_Button::POPUP123); + _popup->add("Rename...", 0, (Fl_Callback *)solver_rename_cb, (void *)(intptr_t)num, 0); + _popup->add("Change Executable Location...", 0, (Fl_Callback *)solver_change_exe_cb, (void *)(intptr_t)num, + FL_MENU_DIVIDER); _popup->add("Remove", 0, (Fl_Callback *)solver_remove_cb, (void *)(intptr_t)num, 0); end(); // close the group -- GitLab