2023-04-26 19:48:54 +05:00
|
|
|
import importlib.util, threading, sys, os
|
2021-10-27 19:50:07 +05:00
|
|
|
|
2022-04-28 13:46:49 +05:00
|
|
|
def _py_handler(f):
|
2023-04-26 19:48:54 +05:00
|
|
|
spec = importlib.util.spec_from_file_location(os.path.basename(f), os.path.abspath(f))
|
|
|
|
module = importlib.util.module_from_spec(spec)
|
|
|
|
spec.loader.exec_module(module)
|
|
|
|
return module
|
2022-04-28 13:46:49 +05:00
|
|
|
|
|
|
|
def _geo_handler(f):
|
|
|
|
from netgen.csg import CSGeometry
|
|
|
|
print("load", f)
|
|
|
|
geo = CSGeometry(f)
|
|
|
|
geo.Draw()
|
|
|
|
|
|
|
|
def _step_handler(f):
|
|
|
|
from netgen.occ import OCCGeometry
|
|
|
|
print("load", f)
|
|
|
|
geo = OCCGeometry(f)
|
|
|
|
geo.Draw()
|
|
|
|
|
|
|
|
def _stl_handler(f):
|
|
|
|
from netgen.stl import STLGeometry
|
|
|
|
print("load", f)
|
|
|
|
geo = STLGeometry(f)
|
|
|
|
geo.Draw()
|
|
|
|
|
|
|
|
_file_handler = {}
|
|
|
|
_file_handler['.py'] = _py_handler
|
|
|
|
_file_handler['.geo'] = _geo_handler
|
|
|
|
_file_handler['.step'] = _step_handler
|
|
|
|
_file_handler['.stl'] = _stl_handler
|
|
|
|
|
2021-10-27 19:50:07 +05:00
|
|
|
def handle_arguments():
|
2022-02-11 22:39:48 +05:00
|
|
|
import __main__
|
2022-04-28 13:46:49 +05:00
|
|
|
import os.path
|
2021-10-27 19:50:07 +05:00
|
|
|
argv = sys.argv
|
2022-04-28 13:46:49 +05:00
|
|
|
if len(argv)>1:
|
|
|
|
_, ext = os.path.splitext(argv[1])
|
|
|
|
if ext in _file_handler:
|
|
|
|
_file_handler[ext](argv[1])
|
2021-10-27 19:50:07 +05:00
|
|
|
|
|
|
|
def main():
|
2021-11-04 17:02:35 +05:00
|
|
|
import netgen
|
|
|
|
# Use Redraw without event handling
|
|
|
|
netgen.Redraw = netgen._Redraw
|
|
|
|
|
2021-10-27 19:50:07 +05:00
|
|
|
from .gui import win
|
|
|
|
th = threading.Thread(target=handle_arguments)
|
|
|
|
th.start()
|
|
|
|
win.tk.mainloop()
|
2021-11-04 17:02:35 +05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|