Skip to content
Snippets Groups Projects
Commit 30c743fa authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

encapsule most of the FLTK main into GmshFLTK so that it can be used as-is

by external codes
parent 5ff41ee9
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "CommandLine.h" #include "CommandLine.h"
#include "OS.h" #include "OS.h"
#include "Context.h" #include "Context.h"
#include "ConnectionManager.h"
#include "robustPredicates.h" #include "robustPredicates.h"
#if defined(HAVE_MESH) #if defined(HAVE_MESH)
...@@ -28,6 +29,12 @@ ...@@ -28,6 +29,12 @@
#include "PluginManager.h" #include "PluginManager.h"
#endif #endif
#if defined(HAVE_FLTK)
#include "FlGui.h"
#include "menuWindow.h"
#include "drawContext.h"
#endif
#if defined(HAVE_LUA) #if defined(HAVE_LUA)
#include "LuaBindings.h" #include "LuaBindings.h"
#endif #endif
...@@ -190,3 +197,66 @@ int GmshBatch() ...@@ -190,3 +197,66 @@ int GmshBatch()
return 1; 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
}
...@@ -24,5 +24,6 @@ int GmshMergeFile(std::string fileName); ...@@ -24,5 +24,6 @@ int GmshMergeFile(std::string fileName);
int GmshWriteFile(std::string fileName); int GmshWriteFile(std::string fileName);
int GmshFinalize(); int GmshFinalize();
int GmshBatch(); int GmshBatch();
int GmshFLTK(int argc, char **argv);
#endif #endif
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "OpenFile.h" #include "OpenFile.h"
#include "Win32Icon.h" #include "Win32Icon.h"
#include "Options.h" #include "Options.h"
#include "CommandLine.h"
#include "Context.h" #include "Context.h"
#include "StringUtils.h" #include "StringUtils.h"
#include "gl2ps.h" #include "gl2ps.h"
...@@ -279,7 +280,26 @@ FlGui *FlGui::_instance = 0; ...@@ -279,7 +280,26 @@ FlGui *FlGui::_instance = 0;
FlGui *FlGui::instance(int argc, char **argv) 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; return _instance;
} }
......
...@@ -6,20 +6,10 @@ ...@@ -6,20 +6,10 @@
#include <string> #include <string>
#include "Gmsh.h" #include "Gmsh.h"
#include "GmshMessage.h" #include "GmshMessage.h"
#include "ConnectionManager.h"
#include "FlGui.h"
#include "menuWindow.h"
#include "drawContext.h"
#include "Context.h" #include "Context.h"
#include "Options.h" #include "Options.h"
#include "Parser.h"
#include "OpenFile.h"
#include "CommandLine.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "GModel.h" #include "GModel.h"
#include "Field.h"
#include "BackgroundMesh.h"
#include "PView.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -46,78 +36,6 @@ int main(int argc, char *argv[]) ...@@ -46,78 +36,6 @@ int main(int argc, char *argv[])
Msg::Exit(0); Msg::Exit(0);
} }
// Create the GUI // Interactive Gmsh with FLTK GUI
FlGui::instance(argc, argv); return GmshFLTK(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();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment