printrun-src/printrun/gui/viz.py

changeset 46
cce0af6351f0
parent 15
0bbb006204fc
equal deleted inserted replaced
45:c82943fb205f 46:cce0af6351f0
16 import traceback 16 import traceback
17 import logging 17 import logging
18 18
19 import wx 19 import wx
20 20
21 class NoViz(object): 21 class BaseViz:
22
23 showall = False
24
25 def clear(self, *a): 22 def clear(self, *a):
26 pass 23 pass
27 24
28 def addfile_perlayer(self, gcode, showall = False): 25 def addfile_perlayer(self, gcode, showall = False):
29 layer_idx = 0 26 layer_idx = 0
33 yield None 30 yield None
34 31
35 def addfile(self, *a, **kw): 32 def addfile(self, *a, **kw):
36 pass 33 pass
37 34
38 def addgcode(self, *a, **kw):
39 pass
40
41 def addgcodehighlight(self, *a, **kw): 35 def addgcodehighlight(self, *a, **kw):
42 pass
43
44 def Refresh(self, *a):
45 pass 36 pass
46 37
47 def setlayer(self, *a): 38 def setlayer(self, *a):
48 pass 39 pass
49 40
50 class NoVizWindow(object): 41 def on_settings_change(self, changed_settings):
42 pass
43
44 class NoViz(BaseViz):
45 showall = False
46 def Refresh(self, *a):
47 pass
48
49 class NoVizWindow:
51 50
52 def __init__(self): 51 def __init__(self):
53 self.p = NoViz() 52 self.p = NoViz()
54 53
55 def Destroy(self): 54 def Destroy(self):
66 return 65 return
67 use2dview = root.settings.mainviz == "2D" 66 use2dview = root.settings.mainviz == "2D"
68 if root.settings.mainviz == "3D": 67 if root.settings.mainviz == "3D":
69 try: 68 try:
70 import printrun.gcview 69 import printrun.gcview
71 root.gviz = printrun.gcview.GcodeViewMainWrapper(parentpanel, root.build_dimensions_list, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples)) 70 root.gviz = printrun.gcview.GcodeViewMainWrapper(
71 parentpanel,
72 root.build_dimensions_list,
73 root = root,
74 circular = root.settings.circular_bed,
75 antialias_samples = int(root.settings.antialias3dsamples),
76 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2))
72 root.gviz.clickcb = root.show_viz_window 77 root.gviz.clickcb = root.show_viz_window
73 except: 78 except:
74 use2dview = True 79 use2dview = True
75 logging.error("3D view mode requested, but we failed to initialize it.\n" 80 logging.error("3D view mode requested, but we failed to initialize it.\n"
76 + "Falling back to 2D view, and here is the backtrace:\n" 81 + "Falling back to 2D view, and here is the backtrace:\n"
90 try: 95 try:
91 import printrun.gcview 96 import printrun.gcview
92 objects = None 97 objects = None
93 if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper): 98 if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper):
94 objects = root.gviz.objects 99 objects = root.gviz.objects
95 root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (600, 600), build_dimensions = root.build_dimensions_list, objects = objects, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples)) 100 root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer',
101 size = (600, 600),
102 build_dimensions = root.build_dimensions_list,
103 objects = objects,
104 root = root,
105 circular = root.settings.circular_bed,
106 antialias_samples = int(root.settings.antialias3dsamples),
107 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2))
96 except: 108 except:
97 use3dview = False 109 use3dview = False
98 logging.error("3D view mode requested, but we failed to initialize it.\n" 110 logging.error("3D view mode requested, but we failed to initialize it.\n"
99 + "Falling back to 2D view, and here is the backtrace:\n" 111 + "Falling back to 2D view, and here is the backtrace:\n"
100 + traceback.format_exc()) 112 + traceback.format_exc())
104 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2), 116 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
105 extrusion_width = root.settings.preview_extrusion_width, 117 extrusion_width = root.settings.preview_extrusion_width,
106 bgcolor = root.bgcolor) 118 bgcolor = root.bgcolor)
107 root.gwindow.Bind(wx.EVT_CLOSE, lambda x: root.gwindow.Hide()) 119 root.gwindow.Bind(wx.EVT_CLOSE, lambda x: root.gwindow.Hide())
108 if not isinstance(root.gviz, NoViz): 120 if not isinstance(root.gviz, NoViz):
109 self.Add(root.gviz.widget, 1, flag = wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL) 121 self.Add(root.gviz.widget, 1, flag = wx.EXPAND)

mercurial