2017-02-01 15:06:43 +05:00
|
|
|
import os
|
2017-05-30 00:19:34 +05:00
|
|
|
import sys
|
2024-06-14 13:50:42 +05:00
|
|
|
from pathlib import Path
|
2017-02-01 15:06:43 +05:00
|
|
|
|
2021-10-28 16:57:24 +05:00
|
|
|
from . import config
|
|
|
|
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH_BIN))
|
|
|
|
_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH))
|
2017-05-10 22:34:42 +05:00
|
|
|
|
2024-06-14 13:50:42 +05:00
|
|
|
def load_occ_libs():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
import importlib.metadata as metadata
|
|
|
|
except ImportError:
|
|
|
|
import importlib_metadata as metadata
|
|
|
|
import ctypes
|
|
|
|
metadata.metadata('netgen-occt')
|
|
|
|
lib_names = [
|
|
|
|
"TKOffset",
|
|
|
|
"TKFillet",
|
|
|
|
"TKDEIGES",
|
|
|
|
"TKBool",
|
|
|
|
"TKDESTEP",
|
|
|
|
"TKXSBase",
|
|
|
|
"TKDESTL",
|
|
|
|
"TKXCAF",
|
|
|
|
"TKVCAF",
|
|
|
|
"TKCAF",
|
|
|
|
"TKBO",
|
|
|
|
"TKPrim",
|
|
|
|
"TKLCAF",
|
|
|
|
"TKCDF",
|
|
|
|
"TKV3d",
|
|
|
|
"TKHLR",
|
|
|
|
"TKMesh",
|
|
|
|
"TKService",
|
|
|
|
"TKShHealing",
|
|
|
|
"TKTopAlgo",
|
|
|
|
"TKGeomAlgo",
|
|
|
|
"TKBRep",
|
|
|
|
"TKGeomBase",
|
|
|
|
"TKG3d",
|
|
|
|
"TKG2d",
|
|
|
|
"TKMath",
|
|
|
|
"TKDE",
|
|
|
|
"TKernel",
|
|
|
|
]
|
|
|
|
lib_names.reverse()
|
|
|
|
lib_paths = {}
|
|
|
|
for f in metadata.files('netgen-occt'):
|
|
|
|
if f.match('*libTK*') or f.match("*.dll"):
|
|
|
|
p = f.locate()
|
|
|
|
name = p.name.split('.')[0].lower().replace("lib","")
|
|
|
|
lib_paths[name] = str(p)
|
|
|
|
for lib_name in lib_names:
|
|
|
|
p = lib_paths[lib_name.lower()]
|
|
|
|
ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL)
|
|
|
|
|
|
|
|
except metadata.PackageNotFoundError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
load_occ_libs()
|
|
|
|
|
2023-04-28 13:21:51 +05:00
|
|
|
__diagnostics_template = """
|
|
|
|
Netgen diagnostics:
|
|
|
|
sys.platform: {sys.platform}
|
|
|
|
sys.executable: {sys.executable}
|
|
|
|
sys.version: {sys.version}
|
|
|
|
Netgen python version: {config.PYTHON_VERSION}
|
|
|
|
Netgen path {__file__}
|
|
|
|
Netgen config {config.__file__}
|
|
|
|
Netgen version {config.NETGEN_VERSION}
|
|
|
|
sys.path: {sys.path}
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _get_diagnostics():
|
|
|
|
return __diagnostics_template.format(sys=sys, config=config, __file__=__file__)
|
|
|
|
|
|
|
|
# compare compile-time and run-time python version
|
|
|
|
def _check_python_version():
|
|
|
|
sys_version = f"{sys.version_info.major}.{sys.version_info.minor}"
|
|
|
|
compile_version = f"{config.PYTHON_VERSION_MAJOR}.{config.PYTHON_VERSION_MINOR}"
|
|
|
|
|
|
|
|
if sys_version != compile_version:
|
2023-05-23 11:59:05 +05:00
|
|
|
print(_get_diagnostics(), file=sys.stderr)
|
2023-04-28 13:21:51 +05:00
|
|
|
raise RuntimeError(f"Python version mismatch: compile-time version is {compile_version}, run-time version is {sys_version}")
|
|
|
|
|
|
|
|
_check_python_version()
|
|
|
|
|
2017-05-30 00:19:34 +05:00
|
|
|
if sys.platform.startswith('win'):
|
2022-06-22 12:36:03 +05:00
|
|
|
v = sys.version_info
|
|
|
|
if v.major == 3 and v.minor >= 8:
|
2020-10-20 20:17:01 +05:00
|
|
|
os.add_dll_directory(_netgen_bin_dir)
|
2024-05-13 16:43:53 +05:00
|
|
|
os.environ['PATH'] += ';'+_netgen_bin_dir
|
2014-10-01 16:31:22 +06:00
|
|
|
|
2017-05-30 00:19:34 +05:00
|
|
|
del sys
|
|
|
|
del os
|
|
|
|
|
2024-02-05 14:02:39 +05:00
|
|
|
from pyngcore import Timer
|
2017-05-30 00:19:34 +05:00
|
|
|
from . import libngpy
|
2019-12-10 15:59:16 +05:00
|
|
|
|
2022-05-06 13:29:02 +05:00
|
|
|
from netgen.libngpy._meshing import _Redraw
|
2021-11-04 17:02:35 +05:00
|
|
|
|
2022-05-06 13:29:02 +05:00
|
|
|
def Redraw(*args, **kwargs):
|
|
|
|
return _Redraw(*args, **kwargs)
|
2023-12-20 16:04:44 +05:00
|
|
|
|
|
|
|
def TimeFunction(func, name=None):
|
|
|
|
name = name or func.__qualname__
|
|
|
|
timer = Timer(name)
|
|
|
|
def retfunc(*args,**kwargs):
|
|
|
|
with timer:
|
|
|
|
ret = func(*args, **kwargs)
|
|
|
|
return ret
|
|
|
|
return retfunc
|
|
|
|
|