-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathinternal.py
89 lines (68 loc) · 4.99 KB
/
internal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#######################################################
# Visualization settings
import ngsolve.solve
import os
# list of possible attributes -- necessary to provide autocompletion
visoptions_variables = ['usetexture', 'invcolor', 'imaginary', 'lineartexture', 'numtexturecols', 'showclipsolution', 'showsurfacesolution', 'drawfieldlines', 'drawpointcurves', 'numfieldlines', 'fieldlinesrandomstart', 'fieldlinesstartarea', 'fieldlinesstartareap1x', 'fieldlinesstartareap1y', 'fieldlinesstartareap1z', 'fieldlinesstartareap2x', 'fieldlinesstartareap2y', 'fieldlinesstartareap2z', 'fieldlinesstartface', 'fieldlinesfilename', 'fieldlinestolerance', 'fieldlinesrktype', 'fieldlineslength', 'fieldlinesmaxpoints', 'fieldlinesthickness', 'fieldlinesvecfunction', 'fieldlinesphase', 'fieldlinesonlyonephase', 'lineplotfile', 'lineplotsource', 'lineplotusingx', 'lineplotusingy', 'lineplotautoscale', 'lineplotxmin', 'lineplotxmax', 'lineplotymin', 'lineplotymax', 'lineplotcurrentnum', 'lineplotinfos', 'lineplotselected', 'lineplotselector', 'lineplotcolor', 'lineplotsizex', 'lineplotsizey', 'lineplotselectedeval', 'lineplotdatadescr', 'lineplotxcoordselector', 'lineplotycoordselector', 'evaluatefilenames', 'evaluatefiledescriptions', 'clipsolution', 'scalfunction', 'vecfunction', 'evaluate', 'gridsize', 'xoffset', 'yoffset', 'autoscale', 'redrawperiodic', 'logscale', 'mminval', 'mmaxval', 'isolines', 'isosurf', 'subdivisions', 'numiso', 'autoredraw', 'autoredrawtime', 'simulationtime', 'multidimcomponent', 'deformation', 'scaledeform1', 'scaledeform2']
viewoptions_variables = ['specpointvlen', 'colormeshsize', 'whitebackground', 'drawcoordinatecross', 'drawcolorbar', 'drawnetgenlogo', 'stereo', 'shrink', 'drawfilledtrigs', 'drawedges', 'drawbadels', 'centerpoint', 'drawelement', 'drawoutline', 'drawtets', 'drawtetsdomain', 'drawprisms', 'drawpyramids', 'drawhexes', 'drawidentified', 'drawpointnumbers', 'drawedgenumbers', 'drawfacenumbers', 'drawelementnumbers', 'drawdomainsurf', 'drawededges', 'drawedpoints', 'drawedpointnrs', 'drawedtangents', 'drawededgenrs', 'drawmetispartition', 'drawcurveproj', 'drawcurveprojedge', 'usecentercoords', 'centerx', 'centery', 'centerz', 'drawspecpoint', 'specpointx', 'specpointy', 'specpointz']
clipping_variables = ['nx', 'ny', 'nz', 'dist', 'dist2', 'enable', 'onlydomain', 'notdomain']
class TclVariables:
def __init__(self, name, update_cmd, attributes = []):
object.__setattr__(self, '_name', name)
object.__setattr__(self, '_update_cmd', update_cmd)
object.__setattr__(self, '_attributes', attributes)
# set corresponding variable in tcl and call update_cmd
def __setattr__(self, attribute_name, value):
if not attribute_name in self._attributes:
raise KeyError()
tcl_string = 'set '+self._name+'.'+attribute_name+' '+str(value)+'; '+self._update_cmd+';\n'
ngsolve.solve.Tcl_Eval(tcl_string)
ngsolve.Redraw()
# return list of possible attributes - for autocompletion
def __dir__(self):
return list(self.__dict__.keys()) + self._attributes
# rlcomplete checks existence of attribute with this function
def __getattr__(self, name):
if name in self.__dict__:
return self.__dict__[name]
if name in self._attributes:
return True
raise Exception()
def add_group( self, name, attributes=[] ):
self.__dict__[name] = TclVariables(self._name +'.'+name, self._update_cmd, attributes)
visoptions = TclVariables('::visoptions', 'Ng_Vis_Set parameters', visoptions_variables)
viewoptions = TclVariables('::viewoptions', 'Ng_SetVisParameters', viewoptions_variables)
# add subgroups to viewoptions
viewoptions.add_group( 'clipping', clipping_variables )
viewoptions.add_group( 'light', ['amb', 'diff', 'spec', 'locviewer'] )
viewoptions.add_group( 'mat', ['shininess', 'transp'] )
def VideoStart(filename):
ngsolve.solve.Tcl_Eval("Ng_VideoClip .ndraw init " + filename+';\n')
def VideoAddFrame():
ngsolve.solve.Tcl_Eval("Ng_VideoClip .ndraw addframe;\n")
def VideoFinalize():
ngsolve.solve.Tcl_Eval("Ng_VideoClip .ndraw finalize;\n")
def SnapShot(filename):
tmp_filename = filename.lower()
needs_conversion = not tmp_filename.endswith(".ppm")
if needs_conversion:
tmp_filename += ".ppm"
ngsolve.solve.Tcl_Eval("Ng_SnapShot .ndraw {};\n".format(tmp_filename))
ngsolve.Redraw(True)
if needs_conversion:
import time
from PIL import Image
t0 = time.time()
while not os.path.exists(tmp_filename) and time.time()-t0 < 5:
time.sleep(0.1)
im = Image.open(tmp_filename)
im.save(filename)
os.remove(tmp_filename)
def Move(dx, dy):
ngsolve.solve.Tcl_Eval("Ng_MouseMove 0 0 {} {} move; redraw;\n".format(dx, -dy))
def Rotate(dx, dy):
ngsolve.solve.Tcl_Eval("Ng_MouseMove 0 0 {} {} rotate; redraw;\n".format(dx, -dy))
def Zoom(z):
ngsolve.solve.Tcl_Eval("Ng_MouseMove 0 0 0 {} zoom; redraw;\n".format(-z))
def Center():
ngsolve.solve.Tcl_Eval("Ng_Center; redraw;\n")