Commit b0fb4375 by Christophe Geuzaine

first go at gmsh::graphics API

parent ace0bb67
......@@ -45,9 +45,15 @@
#include "PluginManager.h"
#endif
#if defined(HAVE_FLTK)
#include "FlGui.h"
#endif
#include "gmsh.h" // automatically generated, in gmsh/api
static int _initialized = 0;
static int _argc = 0;
static char **_argv = 0;
static bool _isInitialized()
{
......@@ -70,6 +76,9 @@ void gmsh::initialize(int argc, char **argv)
}
if(GmshInitialize(argc, argv)){
_initialized = 1;
_argc = argc;
_argv = new char*[_argc + 1];
for(int i = 0; i < argc; i++) _argv[i] = argv[i];
return;
}
throw -1;
......@@ -79,6 +88,9 @@ void gmsh::finalize()
{
if(!_isInitialized()){ throw -1; }
if(GmshFinalize()){
_argc = 0;
if(_argv) delete [] _argv;
_argv = 0;
_initialized = 0;
return;
}
......@@ -2153,6 +2165,7 @@ void gmsh::view::write(const int tag, const std::string &fileName,
void gmsh::plugin::setNumber(const std::string &name, const std::string &option,
const double value)
{
if(!_isInitialized()){ throw -1; }
#if defined(HAVE_PLUGINS)
try {
PluginManager::instance()->setPluginOption(name, option, value);
......@@ -2170,6 +2183,7 @@ void gmsh::plugin::setNumber(const std::string &name, const std::string &option,
void gmsh::plugin::setString(const std::string &name, const std::string &option,
const std::string &value)
{
if(!_isInitialized()){ throw -1; }
#if defined(HAVE_PLUGINS)
try {
PluginManager::instance()->setPluginOption(name, option, value);
......@@ -2186,6 +2200,7 @@ void gmsh::plugin::setString(const std::string &name, const std::string &option,
void gmsh::plugin::run(const std::string &name)
{
if(!_isInitialized()){ throw -1; }
#if defined(HAVE_PLUGINS)
try {
PluginManager::instance()->action(name, "Run", 0);
......@@ -2199,3 +2214,21 @@ void gmsh::plugin::run(const std::string &name)
throw -1;
#endif
}
// gmsh::graphics
void gmsh::graphics::runFltkGui()
{
if(!_isInitialized()){ throw -1; }
#if defined(HAVE_FLTK)
FlGui::instance(_argc, _argv);
if(GModel::current()->getFileName().empty())
GModel::current()->setFileName("untitled.geo");
if(!FlGui::instance()->run()){
throw 1;
}
#else
Msg::Error("Fltk GUI not available");
throw -1;
#endif
}
......@@ -457,6 +457,13 @@ plugin.add('run',doc,None,istring('name'))
################################################################################
graphics = gmsh.add_module('graphics','Graphics functions')
doc = '''Launch the FLTK graphical user interface.'''
graphics.add('runFltkGui',doc,None)
################################################################################
api.write_cpp()
api.write_c()
api.write_python()
......@@ -1182,6 +1182,13 @@ namespace gmsh { // Top-level functions
} // namespace plugin
namespace graphics { // Graphics functions
// Launch the FLTK graphical user interface.
GMSH_API void runFltkGui();
} // namespace graphics
} // namespace gmsh
#undef GMSH_API
......
......@@ -3086,3 +3086,22 @@ class plugin:
raise ValueError(
"gmshPluginRun returned non-zero error code : ",
ierr.value)
class graphics:
"""
Graphics functions
"""
@staticmethod
def runFltkGui():
"""
Launch the FLTK graphical user interface.
"""
ierr = c_int()
lib.gmshGraphicsRunFltkGui(
byref(ierr))
if ierr.value != 0 :
raise ValueError(
"gmshGraphicsRunFltkGui returned non-zero error code : ",
ierr.value)
......@@ -1161,3 +1161,10 @@ void gmshPluginRun(const char * name,int * ierr){
} catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}
}
void gmshGraphicsRunFltkGui(int * ierr){
if(ierr) *ierr = 0;
try {
gmsh::graphics::runFltkGui();
} catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}
}
......@@ -1256,6 +1256,9 @@ GMSH_API void gmshPluginSetString(const char * name,
/* Runs the plugin `name'. */
GMSH_API void gmshPluginRun(const char * name,
int * ierr);
/* Launch the FLTK graphical user interface. */
GMSH_API void gmshGraphicsRunFltkGui(int * ierr);
#undef GMSH_API
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment