diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp index e1b3993ee5650b6ae89f3af1f2717a11a6f102e8..be40fc28017ca6d68056f0d6be73d2b1474edc1a 100644 --- a/Common/Gmsh.cpp +++ b/Common/Gmsh.cpp @@ -16,6 +16,7 @@ #include "CommandLine.h" #include "OS.h" #include "Context.h" +#include "ConnectionManager.h" #include "robustPredicates.h" #if defined(HAVE_MESH) @@ -28,6 +29,12 @@ #include "PluginManager.h" #endif +#if defined(HAVE_FLTK) +#include "FlGui.h" +#include "menuWindow.h" +#include "drawContext.h" +#endif + #if defined(HAVE_LUA) #include "LuaBindings.h" #endif @@ -190,3 +197,66 @@ int GmshBatch() return 1; } + +int GmshFLTK(int argc, char **argv) +{ +#if defined(HAVE_FLTK) && defined(HAVE_POST) + // create the GUI + FlGui::instance(argc, argv); + + // display GUI immediately for quick launch time + FlGui::instance()->check(); + + // open project file and merge all other input files + OpenProject(GModel::current()->getFileName()); + for(unsigned int i = 1; i < CTX::instance()->files.size(); i++){ + if(CTX::instance()->files[i] == "-new"){ + GModel::current()->setVisibility(0); + new GModel(); + } + else + MergeFile(CTX::instance()->files[i]); + } + + if(CTX::instance()->post.combineTime){ + PView::combine(true, 2, CTX::instance()->post.combineRemoveOrig); + FlGui::instance()->updateViews(); + } + + // init first context + switch (CTX::instance()->initialContext) { + case 1: FlGui::instance()->menu->setContext(menu_geometry, 0); break; + case 2: FlGui::instance()->menu->setContext(menu_mesh, 0); break; + case 3: FlGui::instance()->menu->setContext(menu_solver, 0); break; + case 4: FlGui::instance()->menu->setContext(menu_post, 0); break; + default: // automatic + if(PView::list.size()) + FlGui::instance()->menu->setContext(menu_post, 0); + else + FlGui::instance()->menu->setContext(menu_geometry, 0); + break; + } + + // read background mesh if any + if(!CTX::instance()->bgmFileName.empty()) { + MergeFile(CTX::instance()->bgmFileName); + if(PView::list.size()) + GModel::current()->getFields()->setBackgroundMesh(PView::list.size() - 1); + else + Msg::Error("Invalid background mesh (no view)"); + } + + // draw the scene + drawContext::global()->draw(); + + // listen to external solvers + if(CTX::instance()->solver.listen) + ConnectionManager::get(-1)->run(""); + + // loop + return FlGui::instance()->run(); +#else + Msg::Error("GmshFLTK unavailable: please recompile with FLTK support"); + return 0; +#endif +} diff --git a/Common/Gmsh.h b/Common/Gmsh.h index 95922da33bad92c577e21a9362a0eb287c4ec42d..798dcdbaf976a7d2fc3a54254e7011cf4dcfa160 100644 --- a/Common/Gmsh.h +++ b/Common/Gmsh.h @@ -24,5 +24,6 @@ int GmshMergeFile(std::string fileName); int GmshWriteFile(std::string fileName); int GmshFinalize(); int GmshBatch(); +int GmshFLTK(int argc, char **argv); #endif diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index a350644cc362266cd18d8b0024becda5c282320d..a361218f8ba651f8dc26e7a94314514f03ba60d1 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -38,6 +38,7 @@ #include "OpenFile.h" #include "Win32Icon.h" #include "Options.h" +#include "CommandLine.h" #include "Context.h" #include "StringUtils.h" #include "gl2ps.h" @@ -279,7 +280,26 @@ FlGui *FlGui::_instance = 0; FlGui *FlGui::instance(int argc, char **argv) { - if(!_instance) _instance = new FlGui(argc, argv); + if(!_instance){ + _instance = new FlGui(argc, argv); + // set all options in the new GUI + InitOptionsGUI(0); + // say welcome! + Msg::StatusBar(1, false, "Geometry"); + Msg::StatusBar(2, false, "Gmsh %s", GetGmshVersion()); + // log the following for bug reports + Msg::Info("-------------------------------------------------------"); + Msg::Info("Gmsh version : %s", GetGmshVersion()); + Msg::Info("Build OS : %s", GetGmshBuildOS()); + Msg::Info("Build options :%s", GetGmshBuildOptions()); + Msg::Info("Build date : %s", GetGmshBuildDate()); + Msg::Info("Build host : %s", GetGmshBuildHost()); + Msg::Info("Packager : %s", GetGmshPackager()); + Msg::Info("Home directory : %s", CTX::instance()->homeDir.c_str()); + Msg::Info("Launch date : %s", Msg::GetLaunchDate().c_str()); + Msg::Info("Command line : %s", Msg::GetCommandLineArgs().c_str()); + Msg::Info("-------------------------------------------------------"); + } return _instance; } diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp index 6b32ded4567cc34743c5571f021f51f52e651494..898d614df08aa236d554cc5f596599c85306d274 100644 --- a/Fltk/Main.cpp +++ b/Fltk/Main.cpp @@ -6,20 +6,10 @@ #include <string> #include "Gmsh.h" #include "GmshMessage.h" -#include "ConnectionManager.h" -#include "FlGui.h" -#include "menuWindow.h" -#include "drawContext.h" #include "Context.h" #include "Options.h" -#include "Parser.h" -#include "OpenFile.h" -#include "CommandLine.h" #include "PluginManager.h" #include "GModel.h" -#include "Field.h" -#include "BackgroundMesh.h" -#include "PView.h" int main(int argc, char *argv[]) { @@ -46,78 +36,6 @@ int main(int argc, char *argv[]) Msg::Exit(0); } - // Create the GUI - FlGui::instance(argc, argv); - - // Set all previously defined options in the GUI - InitOptionsGUI(0); - - // Say welcome! - Msg::StatusBar(1, false, "Geometry"); - Msg::StatusBar(2, false, "Gmsh %s", GetGmshVersion()); - - // Log the following for bug reports - Msg::Info("-------------------------------------------------------"); - Msg::Info("Gmsh version : %s", GetGmshVersion()); - Msg::Info("Build OS : %s", GetGmshBuildOS()); - Msg::Info("Build options :%s", GetGmshBuildOptions()); - Msg::Info("Build date : %s", GetGmshBuildDate()); - Msg::Info("Build host : %s", GetGmshBuildHost()); - Msg::Info("Packager : %s", GetGmshPackager()); - Msg::Info("Home directory : %s", CTX::instance()->homeDir.c_str()); - Msg::Info("Launch date : %s", Msg::GetLaunchDate().c_str()); - Msg::Info("Command line : %s", Msg::GetCommandLineArgs().c_str()); - Msg::Info("-------------------------------------------------------"); - - // Display the GUI immediately to have a quick "a la Windows" launch time - FlGui::instance()->check(); - - // Open project file and merge all other input files - OpenProject(GModel::current()->getFileName()); - for(unsigned int i = 1; i < CTX::instance()->files.size(); i++){ - if(CTX::instance()->files[i] == "-new"){ - GModel::current()->setVisibility(0); - new GModel(); - } - else - MergeFile(CTX::instance()->files[i]); - } - - if(CTX::instance()->post.combineTime){ - PView::combine(true, 2, CTX::instance()->post.combineRemoveOrig); - FlGui::instance()->updateViews(); - } - - // Init first context - switch (CTX::instance()->initialContext) { - case 1: FlGui::instance()->menu->setContext(menu_geometry, 0); break; - case 2: FlGui::instance()->menu->setContext(menu_mesh, 0); break; - case 3: FlGui::instance()->menu->setContext(menu_solver, 0); break; - case 4: FlGui::instance()->menu->setContext(menu_post, 0); break; - default: // automatic - if(PView::list.size()) - FlGui::instance()->menu->setContext(menu_post, 0); - else - FlGui::instance()->menu->setContext(menu_geometry, 0); - break; - } - - // Read background mesh if any - if(!CTX::instance()->bgmFileName.empty()) { - MergeFile(CTX::instance()->bgmFileName); - if(PView::list.size()) - GModel::current()->getFields()->setBackgroundMesh(PView::list.size() - 1); - else - Msg::Error("Invalid background mesh (no view)"); - } - - // Draw the scene - drawContext::global()->draw(); - - // Listen to external solvers - if(CTX::instance()->solver.listen) - ConnectionManager::get(-1)->run(""); - - // loop - return FlGui::instance()->run(); + // Interactive Gmsh with FLTK GUI + return GmshFLTK(argc, argv); }