printrun-src/printrun/objectplater.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 from .utils import install_locale, iconfile
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17 install_locale('plater')
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 import logging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20 import os
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 import types
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 def patch_method(obj, method, replacement):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 orig_handler = getattr(obj, method)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 def wrapped(*a, **kwargs):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 kwargs['orig_handler'] = orig_handler
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 return replacement(*a, **kwargs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 setattr(obj, method, types.MethodType(wrapped, obj))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 class PlaterPanel(wx.Panel):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 def __init__(self, **kwargs):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 self.destroy_on_done = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 parent = kwargs.get("parent", None)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
36 super().__init__(parent = parent)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 self.prepare_ui(**kwargs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 def prepare_ui(self, filenames = [], callback = None, parent = None, build_dimensions = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 self.filenames = filenames
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
41 panel = self.menupanel = wx.Panel(self)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 sizer = self.menusizer = wx.GridBagSizer()
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
43 # Load button
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
44 loadbutton = wx.Button(panel, label = _("Load"))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
45 loadbutton.Bind(wx.EVT_BUTTON, self.load)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
46 sizer.Add(loadbutton, pos = (0, 0), span = (1, 1), flag = wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
47 # Export button
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
48 exportbutton = wx.Button(panel, label = _("Export"))
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
49 exportbutton.Bind(wx.EVT_BUTTON, self.export)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
50 sizer.Add(exportbutton, pos = (0, 1), span = (1, 1), flag = wx.EXPAND)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
51
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 self.l = wx.ListBox(panel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 sizer.Add(self.l, pos = (1, 0), span = (1, 2), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 sizer.AddGrowableRow(1, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 # Clear button
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 clearbutton = wx.Button(panel, label = _("Clear"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 clearbutton.Bind(wx.EVT_BUTTON, self.clear)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 sizer.Add(clearbutton, pos = (2, 0), span = (1, 2), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 # Snap to Z = 0 button
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 snapbutton = wx.Button(panel, label = _("Snap to Z = 0"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 snapbutton.Bind(wx.EVT_BUTTON, self.snap)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62 sizer.Add(snapbutton, pos = (3, 0), span = (1, 1), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 # Put at center button
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 centerbutton = wx.Button(panel, label = _("Put at center"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 centerbutton.Bind(wx.EVT_BUTTON, self.center)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 sizer.Add(centerbutton, pos = (3, 1), span = (1, 1), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 # Delete button
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 deletebutton = wx.Button(panel, label = _("Delete"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 deletebutton.Bind(wx.EVT_BUTTON, self.delete)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 sizer.Add(deletebutton, pos = (4, 0), span = (1, 1), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 # Auto arrange button
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 autobutton = wx.Button(panel, label = _("Auto arrange"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73 autobutton.Bind(wx.EVT_BUTTON, self.autoplate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 sizer.Add(autobutton, pos = (5, 0), span = (1, 2), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75 if callback is not None:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 donebutton = wx.Button(panel, label = _("Done"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 donebutton.Bind(wx.EVT_BUTTON, lambda e: self.done(e, callback))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 sizer.Add(donebutton, pos = (6, 0), span = (1, 1), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 cancelbutton = wx.Button(panel, label = _("Cancel"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 cancelbutton.Bind(wx.EVT_BUTTON, lambda e: self.Destroy())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 sizer.Add(cancelbutton, pos = (6, 1), span = (1, 1), flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 self.basedir = "."
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 self.models = {}
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
84 panel.SetSizer(sizer)
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
85 self.mainsizer = wx.BoxSizer(wx.HORIZONTAL)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 self.mainsizer.Add(panel, flag = wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 self.SetSizer(self.mainsizer)
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
88 self.build_dimensions = build_dimensions or [200, 200, 100, 0, 0, 0]
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 def set_viewer(self, viewer):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 # Patch handle_rotation on the fly
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 if hasattr(viewer, "handle_rotation"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 def handle_rotation(self, event, orig_handler):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 if self.initpos is None:
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
95 self.initpos = event.GetPosition()
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 if event.ShiftDown():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 p1 = self.initpos
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
99 p2 = event.GetPosition()
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 x1, y1, _ = self.mouse_to_3d(p1[0], p1[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 x2, y2, _ = self.mouse_to_3d(p2[0], p2[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 self.parent.move_shape((x2 - x1, y2 - y1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 self.initpos = p2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 orig_handler(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 patch_method(viewer, "handle_rotation", handle_rotation)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 # Patch handle_wheel on the fly
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 if hasattr(viewer, "handle_wheel"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 def handle_wheel(self, event, orig_handler):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110 if event.ShiftDown():
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 angle = 10
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
112 if event.GetWheelRotation() < 0:
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
113 angle = -angle
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
114 self.parent.rotate_shape(angle / 2)
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 orig_handler(event)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 patch_method(viewer, "handle_wheel", handle_wheel)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 self.s = viewer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119 self.mainsizer.Add(self.s, 1, wx.EXPAND)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121 def move_shape(self, delta):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 """moves shape (selected in l, which is list ListBox of shapes)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 by an offset specified in tuple delta.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124 Positive numbers move to (rigt, down)"""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 name = self.l.GetSelection()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126 if name == wx.NOT_FOUND:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 name = self.l.GetString(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 model = self.models[name]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132 model.offsets = [model.offsets[0] + delta[0],
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 model.offsets[1] + delta[1],
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 model.offsets[2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 ]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 return True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 def rotate_shape(self, angle):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139 """rotates acive shape
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 positive angle is clockwise
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 """
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 name = self.l.GetSelection()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 if name == wx.NOT_FOUND:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 return False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 name = self.l.GetString(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 model = self.models[name]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147 model.rot += angle
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 def autoplate(self, event = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 logging.info(_("Autoplating"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 separation = 2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153 from printrun import packer
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 p = packer.Packer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 for i in self.models:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 width = abs(self.models[i].dims[0] - self.models[i].dims[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 height = abs(self.models[i].dims[2] - self.models[i].dims[3])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 p.add_rect(width, height, data = i)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159 centerx = self.build_dimensions[0] / 2 + self.build_dimensions[3]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160 centery = self.build_dimensions[1] / 2 + self.build_dimensions[4]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 rects = p.pack(padding = separation,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 center = packer.Vector2(centerx, centery))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 for rect in rects:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 i = rect.data
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 position = rect.center()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 self.models[i].offsets[0] = position.x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 self.models[i].offsets[1] = position.y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 except ImportError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 bedsize = self.build_dimensions[0:3]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170 cursor = [0, 0, 0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 newrow = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 max = [0, 0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173 for i in self.models:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 self.models[i].offsets[2] = -1.0 * self.models[i].dims[4]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 x = abs(self.models[i].dims[0] - self.models[i].dims[1])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 y = abs(self.models[i].dims[2] - self.models[i].dims[3])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 centre = [x / 2, y / 2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178 centreoffset = [self.models[i].dims[0] + centre[0],
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 self.models[i].dims[2] + centre[1]]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180 if (cursor[0] + x + separation) >= bedsize[0]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 cursor[0] = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 cursor[1] += newrow + separation
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
183 newrow = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184 if (newrow == 0) or (newrow < y):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 newrow = y
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 # To the person who works out why the offsets are applied
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187 # differently here:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 # Good job, it confused the hell out of me.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 self.models[i].offsets[0] = cursor[0] + centre[0] - centreoffset[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190 self.models[i].offsets[1] = cursor[1] + centre[1] - centreoffset[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 if (max[0] == 0) or (max[0] < (cursor[0] + x)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 max[0] = cursor[0] + x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193 if (max[1] == 0) or (max[1] < (cursor[1] + x)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194 max[1] = cursor[1] + x
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 cursor[0] += x + separation
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196 if (cursor[1] + y) >= bedsize[1]:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 logging.info(_("Bed full, sorry sir :("))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200 centerx = self.build_dimensions[0] / 2 + self.build_dimensions[3]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 centery = self.build_dimensions[1] / 2 + self.build_dimensions[4]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202 centreoffset = [centerx - max[0] / 2, centery - max[1] / 2]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203 for i in self.models:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 self.models[i].offsets[0] += centreoffset[0]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 self.models[i].offsets[1] += centreoffset[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208 def clear(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 result = wx.MessageBox(_('Are you sure you want to clear the grid? All unsaved changes will be lost.'),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 _('Clear the grid?'),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 wx.YES_NO | wx.ICON_QUESTION)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 if result == 2:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213 self.models = {}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 self.l.Clear()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 def center(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 i = self.l.GetSelection()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 if i != -1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 m = self.models[self.l.GetString(i)]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221 centerx = self.build_dimensions[0] / 2 + self.build_dimensions[3]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222 centery = self.build_dimensions[1] / 2 + self.build_dimensions[4]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 m.offsets = [centerx, centery, m.offsets[2]]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 def snap(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227 i = self.l.GetSelection()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 if i != -1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 m = self.models[self.l.GetString(i)]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230 m.offsets[2] = -m.dims[4]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233 def delete(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 i = self.l.GetSelection()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 if i != -1:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 del self.models[self.l.GetString(i)]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 self.l.Delete(i)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 self.l.Select(self.l.GetCount() - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239 self.Refresh()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 def add_model(self, name, model):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 newname = os.path.split(name.lower())[1]
46
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
243 if not isinstance(newname, str):
cce0af6351f0 updated and added new files for printrun
mdd
parents: 15
diff changeset
244 newname = str(newname, "utf-8")
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245 c = 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 while newname in self.models:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247 newname = os.path.split(name.lower())[1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 newname = newname + "(%d)" % c
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 c += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 self.models[newname] = model
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 self.l.Append(newname)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253 i = self.l.GetSelection()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 if i == wx.NOT_FOUND:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255 self.l.Select(0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 self.l.Select(self.l.GetCount() - 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259 def load(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260 dlg = wx.FileDialog(self, _("Pick file to load"), self.basedir, style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 dlg.SetWildcard(self.load_wildcard)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262 if dlg.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263 name = dlg.GetPath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 self.load_file(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267 def load_file(self, filename):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268 raise NotImplementedError
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270 def export(self, event):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271 dlg = wx.FileDialog(self, _("Pick file to save to"), self.basedir, style = wx.FD_SAVE)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 dlg.SetWildcard(self.save_wildcard)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273 if dlg.ShowModal() == wx.ID_OK:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 name = dlg.GetPath()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275 self.export_to(name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276 dlg.Destroy()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278 def export_to(self, name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279 raise NotImplementedError
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
280
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
281 class Plater(wx.Frame):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
282 def __init__(self, **kwargs):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283 self.destroy_on_done = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284 parent = kwargs.get("parent", None)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285 size = kwargs.get("size", (800, 580))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
286 if "size" in kwargs:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 del kwargs["size"]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288 wx.Frame.__init__(self, parent, title = _("Plate building tool"), size = size)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289 self.SetIcon(wx.Icon(iconfile("plater.png"), wx.BITMAP_TYPE_PNG))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290 self.prepare_ui(**kwargs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
292 def make_plater(panel_class):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293 name = panel_class.__name__.replace("Panel", "")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294 return type(name, (Plater, panel_class), {})

mercurial