Coverage for tatlin/lib/ui/gcode.py: 100%
86 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 05:56 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-20 05:56 +0000
1# -*- coding: utf-8 -*-
2# Copyright (C) 2011 Denis Kobozev
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software Foundation,
16# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19import wx
21from tatlin.lib.gl.scene import Scene
22from tatlin.lib.ui.panel import Panel
23from tatlin.lib.util import format_float
25from .view import ViewButtons
28class GcodePanel(Panel):
29 def __init__(self, parent, scene: Scene):
30 super(GcodePanel, self).__init__(parent, scene)
32 # ----------------------------------------------------------------------
33 # DIMENSIONS
34 # ----------------------------------------------------------------------
36 static_box_dimensions = wx.StaticBox(self, label="Dimensions")
37 sizer_dimensions = wx.StaticBoxSizer(static_box_dimensions, wx.VERTICAL)
39 label_width = wx.StaticText(self, label="X:")
40 self.label_width_value = wx.StaticText(self)
42 label_depth = wx.StaticText(self, label="Y:")
43 self.label_depth_value = wx.StaticText(self)
45 label_height = wx.StaticText(self, label="Z:")
46 self.label_height_value = wx.StaticText(self)
48 grid_dimensions = wx.GridSizer(3, 2, 5, 5)
49 grid_dimensions.Add(label_width, 0, wx.ALIGN_CENTER)
50 grid_dimensions.Add(self.label_width_value, 0, wx.ALIGN_CENTER)
51 grid_dimensions.Add(label_depth, 0, wx.ALIGN_CENTER)
52 grid_dimensions.Add(self.label_depth_value, 0, wx.ALIGN_CENTER)
53 grid_dimensions.Add(label_height, 0, wx.ALIGN_CENTER)
54 grid_dimensions.Add(self.label_height_value, 0, wx.ALIGN_CENTER)
56 sizer_dimensions.Add(grid_dimensions, 0, wx.EXPAND | wx.ALL, border=5)
58 # ----------------------------------------------------------------------
59 # DISPLAY
60 # ----------------------------------------------------------------------
62 static_box_display = wx.StaticBox(self, label="Display")
63 sizer_display = wx.StaticBoxSizer(static_box_display, wx.VERTICAL)
65 label_layers = wx.StaticText(self, label="Layers")
66 self.slider_layers = wx.Slider(self, style=wx.SL_HORIZONTAL | wx.SL_LABELS)
67 self.check_arrows = wx.CheckBox(self, label="Show arrows")
68 self.check_3d = wx.CheckBox(self, label="3D view")
69 view_buttons = ViewButtons(self, scene)
70 self.check_ortho = wx.CheckBox(self, label="Orthographic projection")
71 self.btn_reset_view = wx.Button(self, label="Reset view")
73 box_display = wx.BoxSizer(wx.VERTICAL)
74 box_display.Add(label_layers, 0, wx.ALIGN_LEFT)
75 box_display.Add(self.slider_layers, 0, wx.EXPAND | wx.TOP, border=5)
76 box_display.Add(self.check_arrows, 0, wx.EXPAND | wx.TOP, border=5)
77 box_display.Add(self.check_3d, 0, wx.EXPAND | wx.TOP, border=5)
78 box_display.Add(view_buttons, 0, wx.ALIGN_CENTER | wx.TOP, border=5)
79 box_display.Add(self.check_ortho, 0, wx.EXPAND | wx.TOP, border=5)
80 box_display.Add(self.btn_reset_view, 0, wx.EXPAND | wx.TOP, border=5)
82 sizer_display.Add(box_display, 0, wx.EXPAND | wx.ALL, border=5)
84 box = wx.BoxSizer(wx.VERTICAL)
85 box.Add(sizer_dimensions, 0, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border=5)
86 box.Add(sizer_display, 0, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border=5)
88 self.SetSizer(box)
90 def connect_handlers(self):
91 if self._handlers_connected:
92 return
94 self.slider_layers.Bind(wx.EVT_SCROLL, self.on_slider_moved)
95 self.check_arrows.Bind(wx.EVT_CHECKBOX, self.on_arrows_toggled)
96 self.btn_reset_view.Bind(wx.EVT_BUTTON, self.on_reset_clicked)
97 self.check_3d.Bind(wx.EVT_CHECKBOX, self.on_set_mode)
98 self.check_ortho.Bind(wx.EVT_CHECKBOX, self.on_set_ortho)
100 self._handlers_connected = True
102 def on_slider_moved(self, event):
103 self.scene.change_num_layers(event.GetEventObject().GetValue())
104 self.scene.invalidate()
106 def on_arrows_toggled(self, event):
107 """
108 Show/hide arrows on the Gcode model.
109 """
110 self.scene.show_arrows(event.GetEventObject().GetValue())
111 self.scene.invalidate()
113 def on_reset_clicked(self, event):
114 """
115 Restore the view of the model shown on startup.
116 """
117 self.scene.reset_view()
118 self.scene.invalidate()
120 def on_set_mode(self, event):
121 val = event.GetEventObject().GetValue()
122 self.check_ortho.Enable(val)
124 self.scene.mode_2d = not val
125 if self.scene.initialized:
126 self.scene.invalidate()
128 def on_set_ortho(self, event):
129 self.scene.mode_ortho = event.GetEventObject().GetValue()
130 self.scene.invalidate()
132 def set_initial_values(self, layers_range_max, layers_value, width, height, depth):
133 if layers_range_max > 1:
134 self.slider_layers.SetRange(1, layers_range_max)
135 self.slider_layers.SetValue(layers_value)
136 self.slider_layers.Show()
137 else:
138 self.slider_layers.Hide()
140 self.check_arrows.SetValue(True) # check the box
141 self.check_3d.SetValue(True)
143 self.label_width_value.SetLabel(format_float(width))
144 self.label_height_value.SetLabel(format_float(height))
145 self.label_depth_value.SetLabel(format_float(depth))
147 def set_3d_view(self, value):
148 self.check_3d.SetValue(value)