From b686a58a9003de2e770675ec567a492ec5ba6b68 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 27 May 2014 10:51:08 +0000
Subject: [PATCH] hooks for Maxime's development of onelab, V2 !

---
 CMakeLists.txt         | 5 +++++
 Common/GmshConfig.h.in | 1 +
 Fltk/FlGui.cpp         | 5 +++--
 Fltk/graphicWindow.cpp | 7 ++++++-
 Fltk/onelabGroup.cpp   | 2 ++
 5 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2be4ca0e04..4c6bb65e9f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,6 +65,7 @@ opt(NETGEN "Enable Netgen 3D frontal mesh generator" ${DEFAULT})
 opt(NUMPY "Enable conversion between fullMatrix and numpy array (requires SWIG)" OFF)
 opt(OCC "Enable Open CASCADE geometrical models" ${DEFAULT})
 opt(ONELAB "Enable ONELAB solver interface" ${DEFAULT})
+opt(ONELAB2 "Enable experimental ONELAB-Cloud solver interface" OFF)
 opt(ONELAB_METAMODEL "Enable ONELAB metamodels (experimental)" ${DEFAULT})
 opt(OPENMP "Enable OpenMP (experimental)" OFF)
 opt(OPTHOM "Enable high-order mesh optimization tools" ${DEFAULT})
@@ -500,6 +501,10 @@ if(ENABLE_ONELAB)
             DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
 endif(ENABLE_ONELAB)
 
+if(ENABLE_ONELAB2)
+  set_config_option(HAVE_ONELAB2 "ONELAB2")
+endif(ENABLE_ONELAB2)
+
 if(ENABLE_BUILD_IOS)
   find_file(CMAKE_TOOLCHAIN_FILE "ios.cmake")
   if(NOT CMAKE_TOOLCHAIN_FILE)
diff --git a/Common/GmshConfig.h.in b/Common/GmshConfig.h.in
index 7c4949eaab..b6e2c4b183 100644
--- a/Common/GmshConfig.h.in
+++ b/Common/GmshConfig.h.in
@@ -47,6 +47,7 @@
 #cmakedefine HAVE_NO_VSNPRINTF
 #cmakedefine HAVE_OCC
 #cmakedefine HAVE_ONELAB
+#cmakedefine HAVE_ONELAB2
 #cmakedefine HAVE_ONELAB_METAMODEL
 #cmakedefine HAVE_OPENGL
 #cmakedefine HAVE_OPTHOM
diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp
index 7b7cdab727..465734911f 100644
--- a/Fltk/FlGui.cpp
+++ b/Fltk/FlGui.cpp
@@ -761,7 +761,7 @@ void FlGui::updateViews(bool numberOfViewsHasChanged, bool deleteWidgets)
   for(unsigned int i = 0; i < graph.size(); i++)
     graph[i]->checkAnimButtons();
   if(numberOfViewsHasChanged){
-    onelab->rebuildTree(deleteWidgets);
+    if(onelab) onelab->rebuildTree(deleteWidgets);
     options->resetBrowser();
     options->resetExternalViewList();
     fields->loadFieldViewList();
@@ -1105,11 +1105,12 @@ void FlGui::saveMessages(const char *fileName)
 
 void FlGui::rebuildTree(bool deleteWidgets)
 {
-  onelab->rebuildTree(deleteWidgets);
+  if(onelab) onelab->rebuildTree(deleteWidgets);
 }
 
 void FlGui::openModule(const std::string &name)
 {
+  if(!onelab) return;
   if(!onelab->isManuallyClosed("0Modules/" + name))
     onelab->openTreeItem("0Modules/" + name);
 }
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 5d4a7454ec..9ec0a45462 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -3004,8 +3004,12 @@ graphicWindow::graphicWindow(bool main, int numTiles, bool detachedMenu)
   }
 
   if(main && !detachedMenu){
+#if defined(HAVE_ONELAB2)
+    // Hey Maxime, this is for you!
+#else
     _onelab = new onelabGroup(0, mh, twidth, height - mh - sh);
     _onelab->enableTreeWidgetResize(false);
+#endif
   }
   else{
     _onelab = 0;
@@ -3289,12 +3293,13 @@ void graphicWindow::checkAnimButtons()
 
 void graphicWindow::setMenuWidth(int w)
 {
+  if(!_onelab) return;
   if(_menuwin){
     _menuwin->size(std::max(w, _onelab->getMinWindowWidth()), _menuwin->h());
     _menuwin->redraw();
     return;
   }
-  if(!_onelab || !_browser) return;
+  if(!_browser) return;
   double dw = w - _onelab->w();
   if(!dw) return;
   for(unsigned int i = 0; i < gl.size(); i++){
diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp
index 5e72cb116a..2e5e4c1ba6 100644
--- a/Fltk/onelabGroup.cpp
+++ b/Fltk/onelabGroup.cpp
@@ -2063,6 +2063,8 @@ void onelabGroup::addSolver(const std::string &name, const std::string &executab
 
 void solver_cb(Fl_Widget *w, void *data)
 {
+  if(!FlGui::instance()->onelab) return;
+
   int num = (intptr_t)data;
   if(num >= 0){
     std::string name = opt_solver_name(num, GMSH_GET, "");
-- 
GitLab