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