From 025f8750be630ab3bae4a0024b7497220922843b Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Wed, 10 May 2017 19:34:42 +0200 Subject: [PATCH] GUI support from Python and some cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashed commit of the following: commit 5058ceb9351548937487aa94073e7f59236ae9fe Merge: d37f0af 2da1465 Author: Matthias Hochsteger Date: Wed May 10 19:33:55 2017 +0200 Merge remote-tracking branch 'origin/master' into native_tcl_macos commit d37f0afcc1389c0c3ec0899da9c1af158c926ca5 Author: Matthias Date: Wed May 10 19:27:12 2017 +0200 link gui to netgen, some fixes commit 297141455cd4fab81709c13d6253ad8114beee4a Author: Matthias Date: Wed May 10 19:02:47 2017 +0200 windows fixes commit 9bf290a60835f29762b15ee3b722da132678f90c Author: Matthias Hochsteger 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 Date: Wed May 10 14:03:53 2017 +0200 fix typos commit b3d301ff4e321189aef469bff77f7cffa7b69e98 Author: Matthias Hochsteger Date: Wed May 10 13:32:57 2017 +0200 also link tk to togl on windows... commit c3519abee7b041e45c913a45999ed2d29d4ff325 Author: Matthias Hochsteger Date: Wed May 10 13:30:16 2017 +0200 link TCL to togl on windows commit 80b607436b45f38f4bac2708a78ef03561ad44e5 Author: Matthias Hochsteger Date: Wed May 10 13:26:45 2017 +0200 linkt TCL only to netgen executable commit 080139a431e949e14cb9f05194e19c5129aca3d3 Author: Matthias Hochsteger Date: Wed May 10 13:20:36 2017 +0200 fix dll ex/import commit dd68efacb01fbbbe3f136168f12fed41fa3c3c8a Author: Matthias Hochsteger Date: Wed May 10 13:15:39 2017 +0200 fix dll export commit 9023b9ca49b4c2b99f228f64564990e2d0246b8c Author: Matthias Hochsteger 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 Date: Wed May 10 12:01:36 2017 +0200 more cleanup commit 6df5b82a7d9a1177a755446d563d6c4b98ff6329 Merge: af23786 2b0d3f0 Author: Matthias Hochsteger Date: Wed May 10 11:45:42 2017 +0200 Merge remote-tracking branch 'origin/master' into native_tcl_macos commit af2378637a6513de3b50841ed6314cd7e12f7205 Author: Matthias Hochsteger Date: Wed May 10 11:45:40 2017 +0200 some cleanup commit 81bbe117efe25df53c71f9ae603c50ee4557703a Author: Joachim Schöberl Date: Tue May 9 20:14:46 2017 +0200 tk-gui commit 387e6da678661dd3b9d75d696733f46fe43d789a Merge: e658b5b e653d8e Author: Joachim Schöberl 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 Date: Tue May 9 18:30:35 2017 +0200 use native tcl on macos commit e653d8e6789d20e24b16a68bf760415940e881f8 Author: Matthias Hochsteger Date: Mon May 8 16:37:23 2017 +0200 next fix commit f663c80b00754d141a02fa6abde2077c841bbafb Author: Matthias Hochsteger Date: Mon May 8 16:23:21 2017 +0200 Fix symbol export on windows commit 70d99782423d33d3fa6f80e758a7377d0cb52840 Author: Matthias Hochsteger 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 --- cmake/external_projects/tcltk.cmake | 106 ++++++------- libsrc/visualization/CMakeLists.txt | 2 +- ng/CMakeLists.txt | 26 +++- ng/Togl2.1/CMakeLists.txt | 5 +- ng/Togl2.1/togl.c | 11 +- ng/gui.cpp | 231 +++------------------------- ng/ng.tcl | 3 + ng/ngappinit.cpp | 53 +------ nglib/CMakeLists.txt | 2 +- python/CMakeLists.txt | 2 +- python/__init__.py | 12 +- python/gui.py | 11 ++ 12 files changed, 135 insertions(+), 329 deletions(-) create mode 100644 python/gui.py diff --git a/cmake/external_projects/tcltk.cmake b/cmake/external_projects/tcltk.cmake index ad8c5e4a..65d06df0 100644 --- a/cmake/external_projects/tcltk.cmake +++ b/cmake/external_projects/tcltk.cmake @@ -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 diff --git a/libsrc/visualization/CMakeLists.txt b/libsrc/visualization/CMakeLists.txt index 5031cbab..ceedbc7b 100644 --- a/libsrc/visualization/CMakeLists.txt +++ b/libsrc/visualization/CMakeLists.txt @@ -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) diff --git a/ng/CMakeLists.txt b/ng/CMakeLists.txt index 10db4536..6749dd2f 100644 --- a/ng/CMakeLists.txt +++ b/ng/CMakeLists.txt @@ -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) diff --git a/ng/Togl2.1/CMakeLists.txt b/ng/Togl2.1/CMakeLists.txt index 442a2de4..98ae1310 100644 --- a/ng/Togl2.1/CMakeLists.txt +++ b/ng/Togl2.1/CMakeLists.txt @@ -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 ) diff --git a/ng/Togl2.1/togl.c b/ng/Togl2.1/togl.c index 1a3ed598..67f13392 100644 --- a/ng/Togl2.1/togl.c +++ b/ng/Togl2.1/togl.c @@ -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 diff --git a/ng/gui.cpp b/ng/gui.cpp index ab7bcfab..680a3417 100644 --- a/ng/gui.cpp +++ b/ng/gui.cpp @@ -2,221 +2,40 @@ #include #include -#include "../libsrc/interface/writeuser.hpp" -#include +#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 userformats; - Array 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; } diff --git a/ng/ng.tcl b/ng/ng.tcl index 21f11195..18a870db 100644 --- a/ng/ng.tcl +++ b/ng/ng.tcl @@ -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"} { diff --git a/ng/ngappinit.cpp b/ng/ngappinit.cpp index 69623bc4..21589aaf 100644 --- a/ng/ngappinit.cpp +++ b/ng/ngappinit.cpp @@ -7,17 +7,6 @@ #include #include -#ifdef NGPYTHON -#include -#endif - -/* -namespace netgen -{ - int id = 0, ntasks = 1; -} -*/ - #ifdef PARALLEL #include @@ -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 diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index eb18a638..e56feec0 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -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) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index da3db3aa..d35278f3 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -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 ) diff --git a/python/__init__.py b/python/__init__.py index 1c1346cf..ca1e91bd 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -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 diff --git a/python/gui.py b/python/gui.py new file mode 100644 index 00000000..dad53584 --- /dev/null +++ b/python/gui.py @@ -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