GUI support from Python and some cleanup

Squashed commit of the following:

commit 5058ceb9351548937487aa94073e7f59236ae9fe
Merge: d37f0af 2da1465
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 19:33:55 2017 +0200

    Merge remote-tracking branch 'origin/master' into native_tcl_macos

commit d37f0afcc1389c0c3ec0899da9c1af158c926ca5
Author: Matthias <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 19:27:12 2017 +0200

    link gui to netgen, some fixes

commit 297141455cd4fab81709c13d6253ad8114beee4a
Author: Matthias <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 19:02:47 2017 +0200

    windows fixes

commit 9bf290a60835f29762b15ee3b722da132678f90c
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 18:59:53 2017 +0200

    More cleanup, proper code separation

     ... between netgen exectuable and gui library

commit f46d438d3c9dd32f9f94642b4ec00b85611ef1dd
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 14:03:53 2017 +0200

    fix typos

commit b3d301ff4e321189aef469bff77f7cffa7b69e98
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 13:32:57 2017 +0200

    also link tk to togl on windows...

commit c3519abee7b041e45c913a45999ed2d29d4ff325
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 13:30:16 2017 +0200

    link TCL to togl on windows

commit 80b607436b45f38f4bac2708a78ef03561ad44e5
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 13:26:45 2017 +0200

    linkt TCL only to netgen executable

commit 080139a431e949e14cb9f05194e19c5129aca3d3
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 13:20:36 2017 +0200

    fix dll ex/import

commit dd68efacb01fbbbe3f136168f12fed41fa3c3c8a
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 13:15:39 2017 +0200

    fix dll export

commit 9023b9ca49b4c2b99f228f64564990e2d0246b8c
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 12:06:14 2017 +0200

    use system tcl/tk on MacOS, but download tcl/tk for windows

commit 16eb4c1b01eb5229f93274791187b2c666bb8b8e
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 12:01:36 2017 +0200

    more cleanup

commit 6df5b82a7d9a1177a755446d563d6c4b98ff6329
Merge: af23786 2b0d3f0
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 11:45:42 2017 +0200

    Merge remote-tracking branch 'origin/master' into native_tcl_macos

commit af2378637a6513de3b50841ed6314cd7e12f7205
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Wed May 10 11:45:40 2017 +0200

    some cleanup

commit 81bbe117efe25df53c71f9ae603c50ee4557703a
Author: Joachim Schöberl <joachim.schoeberl@tuwien.ac.at>
Date:   Tue May 9 20:14:46 2017 +0200

    tk-gui

commit 387e6da678661dd3b9d75d696733f46fe43d789a
Merge: e658b5b e653d8e
Author: Joachim Schöberl <joachim.schoeberl@tuwien.ac.at>
Date:   Tue May 9 18:49:20 2017 +0200

    Merge remote-tracking branch 'origin/gui_from_python' into native_tcl_macos

commit e658b5b2c1ac3264f4165b5f6d2b821b3b1b0926
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Tue May 9 18:30:35 2017 +0200

    use native tcl on macos

commit e653d8e6789d20e24b16a68bf760415940e881f8
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 8 16:37:23 2017 +0200

    next fix

commit f663c80b00754d141a02fa6abde2077c841bbafb
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 8 16:23:21 2017 +0200

    Fix symbol export on windows

commit 70d99782423d33d3fa6f80e758a7377d0cb52840
Author: Matthias Hochsteger <matthias.hochsteger@tuwien.ac.at>
Date:   Mon May 8 15:14:56 2017 +0200

    GUI support from Python

    Enables experimental support for starting the Netgen GUI from Python
    directly.
    To use it, just import the gui module:
    > import netgen.gui
This commit is contained in:
Matthias Hochsteger 2017-05-10 19:34:42 +02:00
parent 2da1465d52
commit 025f8750be
12 changed files with 135 additions and 329 deletions

View File

@ -1,56 +1,58 @@
if(APPLE)
set(HOME $ENV{HOME})
set(tcl_prefix ${CMAKE_INSTALL_PREFIX}/../../)
ExternalProject_Add(project_tcl
URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tcl8.6.4-src.tar.gz"
URL_MD5 d7cbb91f1ded1919370a30edd1534304
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
UPDATE_COMMAND "" # Disable update
CONFIGURE_COMMAND ../project_tcl/macosx/configure --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin
BUILD_COMMAND make -j4 binaries libraries
INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers
LOG_DOWNLOAD 1
LOG_BUILD 1
LOG_CONFIGURE 1
LOG_INSTALL 1
)
ExternalProject_Add(project_tk
DEPENDS project_tcl
URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tk8.6.4-src.tar.gz"
URL_MD5 261754d7dc2a582f00e35547777e1fea
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
UPDATE_COMMAND "" # Disable update
CONFIGURE_COMMAND ../project_tk/macosx/configure --enable-aqua=yes --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin --with-tcl=${tcl_prefix}/Contents/Frameworks/Tcl.framework
BUILD_COMMAND make -j4 binaries libraries
INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers
LOG_DOWNLOAD 1
LOG_BUILD 1
LOG_CONFIGURE 1
LOG_INSTALL 1
)
ExternalProject_Add(project_tkdnd
URL "https://sourceforge.net/projects/tkdnd/files/OS%20X%20Binaries/TkDND%202.8/tkdnd2.8-OSX-MountainLion.tar.gz"
URL_MD5 2dbb471b1d66c5f391f3c3c5b71548fb
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}/../MacOS
LOG_DOWNLOAD 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
)
list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk project_tkdnd)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}../Frameworks)
set(TCL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework/Headers)
set(TCL_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework)
set(TK_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework)
set(TK_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework/Headers)
# use system tcl/tk
find_package(TCL 8.5 REQUIRED)
# set(HOME $ENV{HOME})
# set(tcl_prefix ${CMAKE_INSTALL_PREFIX}/../../)
# ExternalProject_Add(project_tcl
# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tcl8.6.4-src.tar.gz"
# URL_MD5 d7cbb91f1ded1919370a30edd1534304
# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
# UPDATE_COMMAND "" # Disable update
# CONFIGURE_COMMAND ../project_tcl/macosx/configure --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin
# BUILD_COMMAND make -j4 binaries libraries
# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers
# LOG_DOWNLOAD 1
# LOG_BUILD 1
# LOG_CONFIGURE 1
# LOG_INSTALL 1
# )
#
# ExternalProject_Add(project_tk
# DEPENDS project_tcl
# URL "http://sourceforge.net/projects/tcl/files/Tcl/8.6.4/tk8.6.4-src.tar.gz"
# URL_MD5 261754d7dc2a582f00e35547777e1fea
# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
# UPDATE_COMMAND "" # Disable update
# CONFIGURE_COMMAND ../project_tk/macosx/configure --enable-aqua=yes --enable-threads --enable-framework --prefix=${tcl_prefix} --libdir=${tcl_prefix}/Contents/Frameworks --bindir=${tcl_prefix}/Contents/Frameworks/Tcl.framework/bin --with-tcl=${tcl_prefix}/Contents/Frameworks/Tcl.framework
# BUILD_COMMAND make -j4 binaries libraries
# INSTALL_COMMAND make install-binaries install-headers install-libraries install-private-headers
# LOG_DOWNLOAD 1
# LOG_BUILD 1
# LOG_CONFIGURE 1
# LOG_INSTALL 1
# )
#
# ExternalProject_Add(project_tkdnd
# URL "https://sourceforge.net/projects/tkdnd/files/OS%20X%20Binaries/TkDND%202.8/tkdnd2.8-OSX-MountainLion.tar.gz"
# URL_MD5 2dbb471b1d66c5f391f3c3c5b71548fb
# DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies
# BUILD_IN_SOURCE 1
# CONFIGURE_COMMAND ""
# BUILD_COMMAND ""
# INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory . ${CMAKE_INSTALL_PREFIX}/../MacOS
# LOG_DOWNLOAD 1
# LOG_CONFIGURE 1
# LOG_BUILD 1
# LOG_INSTALL 1
# )
#
# list(APPEND NETGEN_DEPENDENCIES project_tcl project_tk project_tkdnd)
# list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}../Frameworks)
# set(TCL_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework/Headers)
# set(TCL_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tcl.framework)
# set(TK_LIBRARY ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework)
# set(TK_INCLUDE_PATH ${CMAKE_INSTALL_PREFIX}/../Frameworks/Tk.framework/Headers)
#
elseif(WIN32)
ExternalProject_Add(project_win_extlibs

View File

@ -12,7 +12,7 @@ endif(USE_GUI)
add_library(visual ${NG_LIB_TYPE} ${LIB_VISUAL_SOURCES})
if(NOT WIN32)
target_link_libraries( visual ${PYTHON_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TCL_LIBRARY} )
target_link_libraries( visual ${PYTHON_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} )
install( TARGETS visual ${ng_install_dir})
endif(NOT WIN32)

View File

@ -1,4 +1,11 @@
set(netgen_sources demoview.cpp ngappinit.cpp onetcl.cpp parallelfunc.cpp ngpkg.cpp ../libsrc/stlgeom/stlpkg.cpp ../libsrc/visualization/visualpkg.cpp ../libsrc/csg/csgpkg.cpp ../libsrc/geom2d/geom2dpkg.cpp ../libsrc/occ/occpkg.cpp ../libsrc/occ/vsocc.cpp)
set(gui_sources
gui.cpp ngpkg.cpp demoview.cpp parallelfunc.cpp
../libsrc/stlgeom/stlpkg.cpp ../libsrc/visualization/visualpkg.cpp
../libsrc/csg/csgpkg.cpp ../libsrc/geom2d/geom2dpkg.cpp
../libsrc/occ/occpkg.cpp ../libsrc/occ/vsocc.cpp
)
set(netgen_sources ngappinit.cpp onetcl.cpp )
if(USE_GUI)
if(WIN32)
@ -10,21 +17,26 @@ if(USE_GUI)
endif(WIN32)
add_executable(netgen ${netgen_sources})
target_link_libraries( netgen nglib ${ZLIB_LIBRARIES} ${LIBTOGL} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES})
add_library(gui SHARED ${netgen_sources} gui.cpp)
target_link_libraries( gui nglib ${ZLIB_LIBRARIES} ${LIBTOGL} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES})
add_library(gui SHARED ${gui_sources})
target_link_libraries( netgen nglib gui ${ZLIB_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES})
target_link_libraries( gui PUBLIC nglib ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${FFMPEG_LIBRARIES} ${X11_X11_LIB} ${OCC_LIBRARIES} )
target_link_libraries( gui PRIVATE ${LIBTOGL})
if(NOT WIN32)
target_link_libraries( netgen mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis )
target_link_libraries( gui mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis )
target_link_libraries( gui PUBLIC mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis )
endif(NOT WIN32)
install(TARGETS netgen ${ng_install_dir})
install(TARGETS gui DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen)
set_target_properties( gui PROPERTIES PREFIX "") # name output file gui.so instead of libgui.so
install(TARGETS gui ${ng_install_dir})
if(APPLE)
set_target_properties(netgen PROPERTIES OUTPUT_NAME netgen)
endif(APPLE)
if(WIN32)
set_target_properties( gui PROPERTIES OUTPUT_NAME libgui )
endif(WIN32)
endif(USE_GUI)

View File

@ -8,12 +8,13 @@ if(WIN32)
add_definitions("-DBUILD_togl -DUNICODE -D_UNICODE -DTOGL_USE_FONTS=0 -DSTDC_HEADERS -DSTDC_HEADER")
add_library(togl SHARED togl.c toglProcAddr.c toglStubInit.c)
install(TARGETS togl DESTINATION ${ng_install_dir} COMPONENT netgen)
target_link_libraries(togl ${TCL_LIBRARY} ${TK_LIBRARY})
else(WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -Wno-implicit-int")
add_definitions("-DPACKAGE_NAME=\"Togl\" -DPACKAGE_TARNAME=\"togl\" -DPACKAGE_VERSION=\"2.1\" -DPACKAGE_STRING=\"Togl\ 2.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=0 -DHAVE_LIMITS_H=1 -DHAVE_SYS_PARAM_H=1 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1 -DTCL_THREADS=1 -DMODULE_SCOPE=extern\ __attribute__\(\(__visibility__\(\"hidden\"\)\)\) -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_IS_LONG=1 -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 -DAUTOSTEREOD=\"\"")
include_directories(BEFORE "${TCL_INCLUDE_PATH}/tcl-private/generic" "${TCL_INCLUDE_PATH}/tcl-private/unix")
include_directories(BEFORE "${TCL_INCLUDE_PATH}/tk-private/generic" "${TCL_INCLUDE_PATH}/tk-private/unix")
include_directories(BEFORE "${TK_INCLUDE_PATH}/tk-private/generic" "${TK_INCLUDE_PATH}/tk-private/unix" "${TK_INCLUDE_PATH}/tk-private")
include_directories(BEFORE "${TCL_INCLUDE_PATH}/tk-private/generic/ttk")
include_directories(BEFORE "${TK_INCLUDE_PATH}/../PrivateHeaders")
include_directories(BEFORE "${TCL_INCLUDE_PATH}")
@ -23,5 +24,5 @@ else(WIN32)
target_link_libraries(togl -ldl)
endif(WIN32)
target_link_libraries(togl ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} )
target_link_libraries(togl ${OPENGL_LIBRARIES})
set_target_properties(togl PROPERTIES POSITION_INDEPENDENT_CODE ON )

View File

@ -165,11 +165,12 @@
# endif
#endif /* TOGL_AGL */
#if defined(TOGL_NSOPENGL)
# if TK_MAJOR_VERSION < 8 || (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION < 6)
# error Sorry Mac Cocoa version requires Tcl/Tk ver 8.6.0 or higher.
# endif
#endif /* TOGL_NSOPENGL */
// Seems to work with Apple Tcl 8.5 too....
// #if defined(TOGL_NSOPENGL)
// # if TK_MAJOR_VERSION < 8 || (TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION < 6)
// # error Sorry Mac Cocoa version requires Tcl/Tk ver 8.6.0 or higher.
// # endif
// #endif /* TOGL_NSOPENGL */
#if defined(TOGL_WGL) && defined(_MSC_VER)
# define snprintf _snprintf

View File

@ -2,221 +2,40 @@
#include <inctcl.hpp>
#include <meshing.hpp>
#include "../libsrc/interface/writeuser.hpp"
#include <pybind11/pybind11.h>
#ifdef WIN32
#define DLL_HEADER_IMPORT __declspec(dllimport)
#define DLL_HEADER_EXPORT __declspec(dllexport)
#else
#define DLL_HEADER_IMPORT
#define DLL_HEADER_EXPORT
#endif
namespace netgen
{
DLL_HEADER extern Flags parameters;
DLL_HEADER extern bool netgen_executable_started;
DLL_HEADER extern int printmessage_importance;
DLL_HEADER_EXPORT Flags parameters;
}
using netgen::parameters;
using netgen::ngdir;
using netgen::verbose;
using netgen::Array;
using netgen::RegisterUserFormats;
extern "C" int Ng_ServerSocketManagerInit (int port);
extern "C" int Ng_ServerSocketManagerRun (void);
int Tcl_AppInit(Tcl_Interp * interp);
extern bool nodisplay;
extern bool shellmode;
void main_gui()
{
if(netgen::netgen_executable_started)
return;
if ( netgen::id == 0 )
{
cout << "NETGEN-" << PACKAGE_VERSION << endl;
cout << "Developed by Joachim Schoeberl at" << endl
<< "2010-xxxx Vienna University of Technology" << endl
<< "2006-2010 RWTH Aachen University" << endl
<< "1996-2006 Johannes Kepler University Linz" << endl;
#ifdef OCCGEOMETRY
cout << "Including OpenCascade geometry kernel" << endl;
#endif
#ifdef ACIS
cout << "Including ACIS geometry kernel" << endl;
#endif
#ifdef DEBUG
cout << "You are running the debug version !" << endl;
#endif
}
// netgen::h_argc = argc;
// netgen::h_argv = argv;
if (getenv ("NETGENDIR") && strlen (getenv ("NETGENDIR")))
ngdir = getenv ("NETGENDIR");
else
ngdir = ".";
verbose = parameters.GetDefineFlag ("V");
if (verbose)
cout << "NETGENDIR = " << ngdir << endl;
if ( netgen::id == 0 )
{
if (parameters.StringFlagDefined ("testout"))
netgen::testout = new ofstream (parameters.GetStringFlag ("testout", "test.out"));
if(parameters.GetDefineFlag("batchmode"))
nodisplay = true;
if(parameters.GetDefineFlag("shellmode"))
{
nodisplay = true;
shellmode = true;
}
Tcl_FindExecutable(NULL);
// initialize application
Tcl_Interp * myinterp = Tcl_CreateInterp ();
if (Tcl_AppInit (myinterp) == TCL_ERROR)
{
cerr << "Exit Netgen due to initialization problem" << endl;
exit (1);
}
// parse tcl-script
int errcode;
bool internaltcl = false;
if (shellmode)
internaltcl = false;
if (verbose)
{
cout << "Tcl header version = " << TCL_PATCH_LEVEL << endl;
Tcl_Eval (myinterp, "puts \"Tcl runtime version = [info patchlevel] \";");
}
if (parameters.GetDefineFlag ("internaltcl"))
internaltcl=true;
if (parameters.GetDefineFlag ("externaltcl"))
internaltcl=false;
if (internaltcl)
{
if (verbose)
cout << "using internal Tcl-script" << endl;
// connect to one string
extern const char * ngscript[];
const char ** hcp = ngscript;
int len = 0;
while (*hcp)
len += strlen (*hcp++);
char * tr1 = new char[len+1];
*tr1 = 0;
hcp = ngscript;
char * tt1 = tr1;
while (*hcp)
{
strcat (tt1, *hcp);
tt1 += strlen (*hcp++);
}
errcode = Tcl_Eval (myinterp, tr1);
delete [] tr1;
}
else
{
string startfile = ngdir + "/ng.tcl";
if (verbose)
cout << "Load Tcl-script from " << startfile << endl;
errcode = Tcl_EvalFile (myinterp, (char*)startfile.c_str());
}
if (errcode)
{
cout << "Error in Tcl-Script:" << endl;
// cout << "result = " << myinterp->result << endl;
cout << "result = " << Tcl_GetStringResult (myinterp) << endl;
// cout << "in line " << myinterp->errorLine << endl;
cout << "\nMake sure to set environment variable NETGENDIR to directory containing ng.tcl" << endl;
exit (1);
}
// lookup user file formats and insert into format list:
Array<const char*> userformats;
Array<const char*> extensions;
RegisterUserFormats (userformats, extensions);
ostringstream fstr;
tcl_const char * exportft = Tcl_GetVar (myinterp, "exportfiletype", 0);
for (int i = 1; i <= userformats.Size(); i++)
{
fstr << ".ngmenu.file.filetype add radio -label \""
<< userformats.Get(i) << "\" -variable exportfiletype\n";
fstr << "lappend meshexportformats { {" << userformats.Get(i) << "} {" << extensions.Get(i) << "} }\n";
}
Tcl_Eval (myinterp, (char*)fstr.str().c_str());
Tcl_SetVar (myinterp, "exportfiletype", exportft, 0);
// start event-loop
Tk_MainLoop();
Tcl_DeleteInterp (myinterp);
// Tcl_Exit(0);
}
}
DLL_HEADER_EXPORT bool nodisplay = false;
extern "C" int Ng_Init (Tcl_Interp * interp);
extern "C" int Ng_Vis_Init (Tcl_Interp * interp);
extern "C" void Ng_TclCmd(string);
struct GuiThread {
std::thread t;
~GuiThread() {
Ng_TclCmd(".ngmenu.file invoke \"Quit\";");
if(netgen::printmessage_importance>2)
cout << "waiting for GUI to finish..." << endl;
t.join();
}
};
// tcl package dynamic load
extern "C" int DLL_HEADER_EXPORT Gui_Init (Tcl_Interp * interp)
{
if (Ng_Init(interp) == TCL_ERROR) {
cerr << "Problem in Ng_Init: " << endl;
cout << "result = " << Tcl_GetStringResult (interp) << endl;
return TCL_ERROR;
}
if (!nodisplay && Ng_Vis_Init(interp) == TCL_ERROR) {
cerr << "Problem in Ng_Vis_Init: " << endl;
cout << "result = " << Tcl_GetStringResult (interp) << endl;
return TCL_ERROR;
}
static GuiThread gui_thread;
PYBIND11_PLUGIN(gui) {
pybind11::module m("gui", "pybind gui");
gui_thread.t = std::thread([]()
{
main_gui();
});
return m.ptr();
return TCL_OK;
}

View File

@ -1,4 +1,7 @@
catch {lappend auto_path $env(NETGENDIR) }
catch {lappend auto_path $env(NETGENDIR)/../lib }
load libgui[info sharedlibextension] gui
set batchmode [Ng_GetCommandLineParameter batchmode]
if {$batchmode=="undefined"} {

View File

@ -7,17 +7,6 @@
#include <inctcl.hpp>
#include <meshing.hpp>
#ifdef NGPYTHON
#include <boost/python.hpp>
#endif
/*
namespace netgen
{
int id = 0, ntasks = 1;
}
*/
#ifdef PARALLEL
#include <mpi.h>
@ -33,10 +22,11 @@ namespace netgen
namespace netgen
{
Flags parameters;
DLL_HEADER extern Flags parameters;
DLL_HEADER extern bool netgen_executable_started;
}
DLL_HEADER extern bool nodisplay;
using netgen::parameters;
@ -59,7 +49,6 @@ using netgen::RegisterUserFormats;
extern "C" int Ng_ServerSocketManagerInit (int port);
extern "C" int Ng_ServerSocketManagerRun (void);
bool nodisplay = false;
bool shellmode = false;
@ -350,26 +339,6 @@ int Tcl_AppInit(Tcl_Interp * interp)
// return TCL_ERROR;
}
if (Ng_Init(interp) == TCL_ERROR) {
cerr << "Problem in Ng_Init: " << endl;
cout << "result = " << Tcl_GetStringResult (interp) << endl;
// cerr << interp->result << endl;
// return TCL_ERROR;
}
if (!nodisplay && Ng_Vis_Init(interp) == TCL_ERROR) {
cerr << "Problem in Ng_Vis_Init: " << endl;
cout << "result = " << Tcl_GetStringResult (interp) << endl;
// cerr << interp->result << endl;
// return TCL_ERROR;
}
#ifdef TRAFO
// extern int Trafo_Init (Tcl_Interp * interp);
// if (Trafo_Init(interp) == TCL_ERROR)
@ -429,21 +398,3 @@ int Tcl_AppInit(Tcl_Interp * interp)
return TCL_OK;
}
// link MKL with netgen
// necessary for MKL 11.x, since MKL complains if started
// from the ngsolve shared library
#ifdef LINKMKL
extern "C" double ddot_(int *n, double *dx, int *incx, double *dy,
int *incy);
void mkldummy()
{
int n = 1, one = 1;
double a = 1, b = 1;
ddot_(&n, &a, &one, &b, &one);
}
#endif

View File

@ -28,7 +28,7 @@ if(NOT WIN32)
endif(USE_GUI)
endif(NOT WIN32)
target_link_libraries( nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${OCC_LIBRARIES} )
target_link_libraries( nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ${OCC_LIBRARIES} )
if(USE_OCC AND NOT WIN32)
target_link_libraries(nglib occ)

View File

@ -1,4 +1,4 @@
install(FILES __init__.py meshing.py csg.py geom2d.py stl.py
install(FILES __init__.py meshing.py csg.py geom2d.py stl.py gui.py
DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen
COMPONENT netgen
)

View File

@ -3,11 +3,17 @@ from sys import path
from sys import platform as __platform
if __platform.startswith('linux'):
path.append(os.path.dirname(__file__) + '/../../..')
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'../../../../bin'))
_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'../../../../lib'))
if __platform.startswith('win'):
path.append(os.path.dirname(__file__) + '/../../../bin')
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__) + '/../../../bin'))
_netgen_lib_dir=_netgen_bin_dir
if __platform.startswith('darwin'):
path.append(os.path.dirname(__file__) + '/../../../../../MacOS')
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__) + '/../../../../../MacOS'))
_netgen_lib_dir=_netgen_bin_dir
path.append(_netgen_lib_dir)
path.append(_netgen_bin_dir)
import libngpy
del path

11
python/gui.py Normal file
View File

@ -0,0 +1,11 @@
from tkinter import Tk
from . import _netgen_lib_dir
from . import _netgen_bin_dir
win = Tk()
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
win.tk.eval("source "+os.path.realpath(os.path.join(_netgen_bin_dir, 'ng.tcl')).replace('\\','/'))
# %gui tk