printrun-src/printrun/gui/viz.py

Fri, 03 Jun 2016 21:14:09 +0200

author
mbayer
date
Fri, 03 Jun 2016 21:14:09 +0200
changeset 19
234037fbca4b
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

Bugfixing, Added M400 magic

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 import traceback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17 import logging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 class NoViz(object):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 showall = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 def clear(self, *a):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 def addfile_perlayer(self, gcode, showall = False):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 layer_idx = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 while layer_idx < len(gcode.all_layers):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 yield layer_idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 layer_idx += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 yield None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 def addfile(self, *a, **kw):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38 def addgcode(self, *a, **kw):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 def addgcodehighlight(self, *a, **kw):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 def Refresh(self, *a):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47 def setlayer(self, *a):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 class NoVizWindow(object):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 def __init__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 self.p = NoViz()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 def Destroy(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 class VizPane(wx.BoxSizer):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 def __init__(self, root, parentpanel = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 super(VizPane, self).__init__(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 if not parentpanel: parentpanel = root.panel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 if root.settings.mainviz == "None":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 root.gviz = NoViz()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 root.gwindow = NoVizWindow()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 use2dview = root.settings.mainviz == "2D"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 if root.settings.mainviz == "3D":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 import printrun.gcview
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 root.gviz = printrun.gcview.GcodeViewMainWrapper(parentpanel, root.build_dimensions_list, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 root.gviz.clickcb = root.show_viz_window
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 use2dview = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75 logging.error("3D view mode requested, but we failed to initialize it.\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 + "Falling back to 2D view, and here is the backtrace:\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 if use2dview:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 from printrun import gviz
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 root.gviz = gviz.Gviz(parentpanel, (300, 300),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 build_dimensions = root.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 extrusion_width = root.settings.preview_extrusion_width,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 bgcolor = root.bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 root.gviz.SetToolTip(wx.ToolTip(_("Click to examine / edit\n layers of loaded file")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 root.gviz.showall = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 root.gviz.Bind(wx.EVT_LEFT_DOWN, root.show_viz_window)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 use3dview = root.settings.viz3d
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 if use3dview:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 import printrun.gcview
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 objects = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 objects = root.gviz.objects
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
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))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 use3dview = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 logging.error("3D view mode requested, but we failed to initialize it.\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 + "Falling back to 2D view, and here is the backtrace:\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 if not use3dview:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 from printrun import gviz
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 root.gwindow = gviz.GvizWindow(build_dimensions = root.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 extrusion_width = root.settings.preview_extrusion_width,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 bgcolor = root.bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 root.gwindow.Bind(wx.EVT_CLOSE, lambda x: root.gwindow.Hide())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 if not isinstance(root.gviz, NoViz):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 self.Add(root.gviz.widget, 1, flag = wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL)

mercurial