2017-05-15 21:56:47 +05:00
|
|
|
import netgen
|
2017-05-10 22:34:42 +05:00
|
|
|
|
2022-05-06 13:29:02 +05:00
|
|
|
from . import libngguipy
|
|
|
|
from . import libngpy
|
|
|
|
|
2017-05-15 21:56:47 +05:00
|
|
|
def StartGUI():
|
|
|
|
from tkinter import Tk
|
2022-02-24 22:12:24 +05:00
|
|
|
from netgen import config
|
|
|
|
import sys, os
|
|
|
|
|
2022-02-16 13:22:21 +05:00
|
|
|
try:
|
|
|
|
# the GUI tries to load ngsolve.tcl (which loads ngsolve shared libraries)
|
|
|
|
# BUT might fail to load dependencies (like mkl), these are handled by the
|
|
|
|
# ngsolve __init__.py script, so import ngsolve from python already here
|
|
|
|
import ngsolve
|
|
|
|
except:
|
|
|
|
pass
|
2017-05-10 22:34:42 +05:00
|
|
|
|
2017-05-15 21:56:47 +05:00
|
|
|
global win
|
|
|
|
win = Tk()
|
2017-05-30 00:19:34 +05:00
|
|
|
win.tk.eval('lappend ::auto_path ' + netgen._netgen_lib_dir)
|
|
|
|
win.tk.eval('lappend ::auto_path ' + netgen._netgen_bin_dir)
|
|
|
|
# load with absolute path to avoid issues on MacOS
|
2022-05-06 13:29:02 +05:00
|
|
|
win.tk.eval('load "'+netgen._netgen_lib_dir.replace('\\','/')+'/libnggui[info sharedlibextension]" gui')
|
2022-02-24 22:12:24 +05:00
|
|
|
|
|
|
|
if config.is_python_package and 'darwin' in sys.platform:
|
|
|
|
# libngsolve and other libraries are installed into netgen python dir to keep relative installation paths, but tcl won't find them there automatically
|
|
|
|
netgen_dir = os.path.abspath(os.path.dirname(netgen.__file__))
|
|
|
|
win.tk.eval(f'set netgen_library_dir {netgen_dir}')
|
|
|
|
|
2017-05-30 00:19:34 +05:00
|
|
|
win.tk.eval( netgen.libngpy._meshing._ngscript)
|
2017-05-15 21:56:47 +05:00
|
|
|
|
2022-05-06 13:29:02 +05:00
|
|
|
def _Redraw(*args, **kwargs):
|
|
|
|
if libngpy._meshing._Redraw(*args, **kwargs):
|
|
|
|
import netgen
|
|
|
|
import tkinter
|
|
|
|
cnt = 0
|
|
|
|
while(win.tk.dooneevent(tkinter._tkinter.DONT_WAIT) and cnt < 100):
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
netgen._Redraw = _Redraw
|
|
|
|
_Redraw(blocking=True)
|
|
|
|
|
2018-10-02 14:50:26 +05:00
|
|
|
|
2017-05-15 21:56:47 +05:00
|
|
|
if not netgen.libngpy._meshing._netgen_executable_started:
|
2021-06-01 19:44:59 +05:00
|
|
|
import os
|
|
|
|
if not "NETGEN_DOCUMENTATION_RST_FORMAT" in os.environ:
|
2021-10-27 19:50:07 +05:00
|
|
|
StartGUI()
|
2019-12-06 17:48:00 +05:00
|
|
|
|
|
|
|
def Snapshot(w,h, filename=None):
|
2019-12-10 15:59:16 +05:00
|
|
|
netgen.Redraw(blocking=True)
|
2019-12-06 17:48:00 +05:00
|
|
|
import numpy
|
|
|
|
image = netgen.libngpy.Snapshot(w, h)
|
|
|
|
image = numpy.array(image, dtype=numpy.uint8).reshape(h, w, 3)
|
|
|
|
image = image[::-1,:,:]
|
|
|
|
if filename:
|
|
|
|
import PIL.Image
|
|
|
|
im = PIL.Image.fromarray(image)
|
|
|
|
im.save(filename)
|
|
|
|
return image
|