Welcome to mirror list, hosted at ThFree Co, Russian Federation.

viz.py « gui « printrun - github.com/kliment/Printrun.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb4c4ebaaadbcaf599945e19a3ddae9d5e5ed22b (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# This file is part of the Printrun suite.
#
# Printrun is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Printrun is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Printrun.  If not, see <http://www.gnu.org/licenses/>.

import traceback
import logging

import wx

class BaseViz:
    def clear(self, *a):
        pass

    def addfile_perlayer(self, gcode, showall = False):
        layer_idx = 0
        while layer_idx < len(gcode.all_layers):
            yield layer_idx
            layer_idx += 1
        yield None

    def addfile(self, *a, **kw):
        pass

    def addgcodehighlight(self, *a, **kw):
        pass

    def setlayer(self, *a):
        pass

    def on_settings_change(self, changed_settings):
        pass

class NoViz(BaseViz):
    showall = False
    def Refresh(self, *a):
        pass

class NoVizWindow:

    def __init__(self):
        self.p = NoViz()

    def Destroy(self):
        pass

class VizPane(wx.BoxSizer):

    def __init__(self, root, parentpanel = None):
        super(VizPane, self).__init__(wx.VERTICAL)
        if not parentpanel: parentpanel = root.panel
        if root.settings.mainviz == "None":
            root.gviz = NoViz()
            root.gwindow = NoVizWindow()
            return
        use2dview = root.settings.mainviz == "2D"
        if root.settings.mainviz == "3D":
            try:
                import printrun.gcview
                root.gviz = printrun.gcview.GcodeViewMainWrapper(
                    parentpanel,
                    root.build_dimensions_list,
                    root = root,
                    circular = root.settings.circular_bed,
                    antialias_samples = int(root.settings.antialias3dsamples),
                    grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
                    perspective = root.settings.perspective)
                root.gviz.clickcb = root.show_viz_window
            except:
                use2dview = True
                logging.error("3D view mode requested, but we failed to initialize it.\n"
                              + "Falling back to 2D view, and here is the backtrace:\n"
                              + traceback.format_exc())
        if use2dview:
            from printrun import gviz
            root.gviz = gviz.Gviz(parentpanel, (300, 300),
                                  build_dimensions = root.build_dimensions_list,
                                  grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
                                  extrusion_width = root.settings.preview_extrusion_width,
                                  bgcolor = root.bgcolor)
            root.gviz.SetToolTip(wx.ToolTip(_("Click to examine / edit\n  layers of loaded file")))
            root.gviz.showall = 1
            root.gviz.Bind(wx.EVT_LEFT_DOWN, root.show_viz_window)
        use3dview = root.settings.viz3d
        if use3dview:
            try:
                import printrun.gcview
                objects = None
                if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper):
                    objects = root.gviz.objects
                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),
                    grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
                    perspective=root.settings.perspective)
            except:
                use3dview = False
                logging.error("3D view mode requested, but we failed to initialize it.\n"
                              + "Falling back to 2D view, and here is the backtrace:\n"
                              + traceback.format_exc())
        if not use3dview:
            from printrun import gviz
            root.gwindow = gviz.GvizWindow(build_dimensions = root.build_dimensions_list,
                                           grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
                                           extrusion_width = root.settings.preview_extrusion_width,
                                           bgcolor = root.bgcolor)
        root.gwindow.Bind(wx.EVT_CLOSE, lambda x: root.gwindow.Hide())
        if not isinstance(root.gviz, NoViz):
            self.Add(root.gviz.widget, 1, flag = wx.EXPAND)