printrun-src/printrun/gui/viz.py

Wed, 20 Jan 2021 11:37:03 +0100

author
mdd
date
Wed, 20 Jan 2021 11:37:03 +0100
changeset 48
3c27b4ee6fec
parent 46
cce0af6351f0
permissions
-rw-r--r--

reimplemented lasercutter changes

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
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
21 class BaseViz:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 def clear(self, *a):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 def addfile_perlayer(self, gcode, showall = False):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 layer_idx = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 while layer_idx < len(gcode.all_layers):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 yield layer_idx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 layer_idx += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 yield None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 def addfile(self, *a, **kw):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 def addgcodehighlight(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 setlayer(self, *a):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
41 def on_settings_change(self, changed_settings):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
42 pass
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
43
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
44 class NoViz(BaseViz):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
45 showall = False
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
46 def Refresh(self, *a):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
47 pass
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
48
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
49 class NoVizWindow:
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 def __init__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 self.p = NoViz()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 def Destroy(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 class VizPane(wx.BoxSizer):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 def __init__(self, root, parentpanel = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 super(VizPane, self).__init__(wx.VERTICAL)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 if not parentpanel: parentpanel = root.panel
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 if root.settings.mainviz == "None":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 root.gviz = NoViz()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 root.gwindow = NoVizWindow()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 use2dview = root.settings.mainviz == "2D"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 if root.settings.mainviz == "3D":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 import printrun.gcview
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
70 root.gviz = printrun.gcview.GcodeViewMainWrapper(
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
71 parentpanel,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
72 root.build_dimensions_list,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
73 root = root,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
74 circular = root.settings.circular_bed,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
75 antialias_samples = int(root.settings.antialias3dsamples),
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
76 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 root.gviz.clickcb = root.show_viz_window
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 use2dview = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 logging.error("3D view mode requested, but we failed to initialize it.\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 + "Falling back to 2D view, and here is the backtrace:\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 if use2dview:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 from printrun import gviz
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 root.gviz = gviz.Gviz(parentpanel, (300, 300),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 build_dimensions = root.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 extrusion_width = root.settings.preview_extrusion_width,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 bgcolor = root.bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 root.gviz.SetToolTip(wx.ToolTip(_("Click to examine / edit\n layers of loaded file")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 root.gviz.showall = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 root.gviz.Bind(wx.EVT_LEFT_DOWN, root.show_viz_window)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 use3dview = root.settings.viz3d
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 if use3dview:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 import printrun.gcview
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 objects = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 objects = root.gviz.objects
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
100 root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer',
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
101 size = (600, 600),
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
102 build_dimensions = root.build_dimensions_list,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
103 objects = objects,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
104 root = root,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
105 circular = root.settings.circular_bed,
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
106 antialias_samples = int(root.settings.antialias3dsamples),
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
107 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2))
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 use3dview = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110 logging.error("3D view mode requested, but we failed to initialize it.\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 + "Falling back to 2D view, and here is the backtrace:\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112 + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 if not use3dview:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114 from printrun import gviz
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 root.gwindow = gviz.GvizWindow(build_dimensions = root.build_dimensions_list,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 extrusion_width = root.settings.preview_extrusion_width,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 bgcolor = root.bgcolor)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119 root.gwindow.Bind(wx.EVT_CLOSE, lambda x: root.gwindow.Hide())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 if not isinstance(root.gviz, NoViz):
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
121 self.Add(root.gviz.widget, 1, flag = wx.EXPAND)

mercurial