Debian Codegraph @

Plotter.cpp

raw symbols SCIP
1 /***************************************************************************
2 * This file is part of Robocut. *
3 * Copyright (C) 2010 Tim Hutt <[email protected]> *
4 * Copyright (C) 2010 Markus Schulz <[email protected]> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
21
22 #include "Plotter.h"cxx . . $ `<file>/Plotter.h`/
23 #include "ProgramOptions.h"cxx . . $ `<file>/ProgramOptions.h`/
24
25 #include <libusb-1.0/libusb.h>
26
27 int VENDOR_IDcxx . . $ VENDOR_ID. = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getVendorUSB_IDcxx . . $ ProgramOptions#getVendorUSB_ID(b126dc7c1de90089).();
28 int PRODUCT_IDcxx . . $ PRODUCT_ID. = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getProductUSB_IDcxx . . $ ProgramOptions#getProductUSB_ID(b126dc7c1de90089).();
29
30 #include <iostream>
31 #include <cmath>
32
33
34 stringcxx . . $ string# UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(int e)
35 {
36 switch (e)
37 {
38 case LIBUSB_SUCCESS:
39 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Success (internal error)"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
40 case LIBUSB_ERROR_IO:
41 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "I/O error"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
42 case LIBUSB_ERROR_INVALID_PARAM:
43 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Invalid parameter"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
44 case LIBUSB_ERROR_ACCESS:
45 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Access denied"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
46 case LIBUSB_ERROR_NO_DEVICE:
47 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "No device"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
48 case LIBUSB_ERROR_NOT_FOUND:
49 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Entity not found"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
50 case LIBUSB_ERROR_BUSY:
51 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Resource busy"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
52 case LIBUSB_ERROR_TIMEOUT:
53 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Timeout"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
54 case LIBUSB_ERROR_OVERFLOW:
55 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Overflow"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
56 case LIBUSB_ERROR_PIPE:
57 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Pipe error"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
58 case LIBUSB_ERROR_INTERRUPTED:
59 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Syscall interrupted"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
60 case LIBUSB_ERROR_NO_MEM:
61 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Insufficient memory"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
62 case LIBUSB_ERROR_NOT_SUPPORTED:
63 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Operation not supported"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
64 case LIBUSB_ERROR_OTHER:
65 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Other error"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
66 }
67 returncxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). "Unknown error"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
68 }
69
70 // Send some data to the USB device.
71 Errorcxx . . $ Error# UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(libusb_device_handle* handle, const stringcxx . . $ string#& s, int timeout = 0)
72 {
73 // Send in 4096 byte chunks. Not sure where I got this from, I'm not sure it is actually necessary.
74 for (unsigned int i = 0; i < s.lengthcxx . . $ std/__cxx11/basic_string#length(48278e53df7b52a5).(); i += 4096)
75 {
76 stringcxx . . $ string# data = scxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f)..substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(i, 4096);
77 int transferred;
78 unsigned char endpoint = '\x01';
79 int ret = libusb_bulk_transfer(handle, endpoint, reinterpret_cast<unsigned char*>(const_cast<char*>(data.c_strcxx . . $ std/__cxx11/basic_string#c_str(1016ee5406d91ab9).())),
80 data.lengthcxx . . $ std/__cxx11/basic_string#length(48278e53df7b52a5).(), &transferred, timeout);
81 if (ret != 0)
82 {
83 cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error writing to device: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(ret) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
84 return Errorcxx . . $ Error#("Error writing to device: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(ret));
85 }
86 if ((unsigned int)transferred != data.lengthcxx . . $ std/__cxx11/basic_string#length(48278e53df7b52a5).())
87 {
88 cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Warning, some data not transferred correctly." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
89 return Errorcxx . . $ Error#("Some data not transferred. Attempted: " +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(data.lengthcxx . . $ std/__cxx11/basic_string#length(48278e53df7b52a5).()) +cxx . . $ std/operator+(900ec9581c410ad9). " Transferred: " +cxx . . $ std/operator+(aa1c00e85b87da6b). ItoScxx . . $ ItoS(7eb93f795f0defb3).(transferred));
90 }
91 }
92 return Successcxx . . $ Success.;
93 }
94
95 // Receive some data up to the maximum packet size of 64. Because we use the packet size
96 // there can never be overflows, and 64 is ok because none of the craft robo responses are
97 // anywhere near that long.
98 Errorcxx . . $ Error# UsbReceivecxx . . $ UsbReceive(f5a276abbf5da7cb).(libusb_device_handle* handle, stringcxx . . $ string#& s, int timeout = 0)
99 {
100 s.clearcxx . . $ std/__cxx11/basic_string#clear(49f6e7a06ebc5aa8).();
101
102 // A buffer that is one packet long.
103 const int PacketSize = 64;
104 unsigned char buffer[PacketSize];
105 int transferred = 0;
106 unsigned char endpoint = '\x82';
107 int ret = libusb_bulk_transfer(handle, endpoint, buffer, PacketSize, &transferred, timeout);
108 if (ret != 0) // But it could be a timout.
109 {
110 cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error reading from device: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(ret) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
111 return Errorcxx . . $ Error#("Error reading from device: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(ret));
112 }
113
114 s =cxx . . $ std/__cxx11/basic_string#`operator=`(706c69e8c742c906). stringcxx . . $ std/__cxx11/basic_string#basic_string(f26a9578972d3fae).(reinterpret_cast<char*>(buffer), transferred);
115 return Successcxx . . $ Success.;
116 }
117
118 // Send a control message
119 //Error UsbControl(libusb_device_handle* handle, ...)
120 //{
121 // libusb_control_transfer(handle,
122 // uint8_t request_type, uint8_t request, uint16_t value, uint16_t index,
123 // unsigned char *data, uint16_t length, unsigned int timeout);
124 //}
125
126 libusb_device_handle *UsbOpencxx . . $ UsbOpen(8430fd59fc59b3e0).(struct cutter_idcxx . . $ cutter_id# *id)
127 {
128 libusb_device** list;
129 ssize_t cnt = libusb_get_device_list(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &list);
130 if (cnt < 1)
131 {
132 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Couldn't get usb device list.");
133 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
134 }
135
136 int err = 0;
137
138 libusb_device* found = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
139 for (ssize_t i = 0; i < cnt; ++i)
140 {
141 libusb_device* device = list[i];
142 libusb_device_descriptor desc;
143 libusb_get_device_descriptor(device, &desc);
144 // I don't want to be more specific than this really.
145 if ((desc.idVendor == VENDOR_IDcxx . . $ VENDOR_ID. || desc.idVendor == VENDOR_ID_GRAPHTECcxx . . $ VENDOR_ID_GRAPHTEC.) &&
146 (desc.idProduct == PRODUCT_IDcxx . . $ PRODUCT_ID. ||
147 desc.idProduct == PRODUCT_ID_CC200_20cxx . . $ PRODUCT_ID_CC200_20. ||
148 desc.idProduct == PRODUCT_ID_CC300_20cxx . . $ PRODUCT_ID_CC300_20. ||
149 desc.idProduct == PRODUCT_ID_SILHOUETTE_SD_1cxx . . $ PRODUCT_ID_SILHOUETTE_SD_1. ||
150 desc.idProduct == PRODUCT_ID_SILHOUETTE_SD_2cxx . . $ PRODUCT_ID_SILHOUETTE_SD_2. ||
151 desc.idProduct == PRODUCT_ID_SILHOUETTE_CAMEOcxx . . $ PRODUCT_ID_SILHOUETTE_CAMEO. ||
152 desc.idProduct == PRODUCT_ID_SILHOUETTE_PORTRAITcxx . . $ PRODUCT_ID_SILHOUETTE_PORTRAIT.
153 )
154 )
155 {
156 // Just use the first one. Who has two?!
157 found = device;
158 id->usb_product_idcxx . . $ cutter_id#usb_product_id. = desc.idProduct;
159 id->usb_vendor_idcxx . . $ cutter_id#usb_vendor_id. = desc.idVendor;
160 break;
161 }
162 }
163
164 if (!found)
165 {
166 libusb_free_device_list(list, 1);
167 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Couldn't find Craft Robo 2 (USB device with Vendor ID with USB VendorID 0b4d and ProductID 110a). Is it connected to the system and powered on?");
168 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
169 }
170
171 libusb_device_handle* handle;
172
173 err = libusb_open(found, &handle);
174 if (err != 0)
175 {
176 libusb_free_device_list(list, 1);
177 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Error accessing Craft Robo 2: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(err) +cxx . . $ std/operator+(900ec9581c410ad9). ". Do you have permission (on Linux make sure you are in the group 'lp').");
178 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
179 }
180
181 libusb_free_device_list(list, 1);
182 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). "Ready";
183 return handle;
184 }
185
186 // caller can use UsbSend() afterwards, and should
187 // finally do libusb_release_interface(handle, 0); libusb_close(handle);
188 libusb_device_handle *UsbInitcxx . . $ UsbInit(8430fd59fc59b3e0).(struct cutter_idcxx . . $ cutter_id# *id)
189 {
190 // Now do stuff with the handle.
191 int r = 0;
192
193 libusb_device_handle* handle = UsbOpencxx . . $ UsbOpen(8430fd59fc59b3e0).(id);
194 if (!handle) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
195
196 if (libusb_kernel_driver_active(handle, 0) == 1)
197 {
198 r = libusb_detach_kernel_driver(handle, 0);
199 if (r != 0)
200 {
201 libusb_close(handle);
202 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Error detaching kernel USB driver: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(r));
203 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
204 }
205 }
206
207 r = libusb_reset_device(handle);
208 if (r != 0)
209 {
210 libusb_close(handle);
211 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Error resetting device: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(r));
212 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
213 }
214
215 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Selecting configuration." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
216 r = libusb_set_configuration(handle, 1);
217 if (r < 0)
218 {
219 libusb_close(handle);
220 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Error setting USB configuration: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(r));
221 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
222 }
223
224
225 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Claiming main control interface." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
226 r = libusb_claim_interface(handle, 0);
227 if (r < 0)
228 {
229 libusb_close(handle);
230 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Error claiming USB interface: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(r));
231 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
232 }
233
234 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Setting alt interface." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
235 r = libusb_set_interface_alt_setting(handle, 0, 0); // Probably not really necessary.
236 if (r < 0)
237 {
238 libusb_close(handle);
239 id->msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Error setting alternate USB interface: " +cxx . . $ std/operator+(39ed2c165380f78e). UsbErrorcxx . . $ UsbError(7eb93f795f0defb3).(r));
240 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
241 }
242
243 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Initialisation successful." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
244 return handle;
245 }
246
247 struct cutter_idcxx . . $ cutter_id# *Identifycxx . . $ Identify(4c0d3da0b6c41992).()
248 {
249 static struct cutter_idcxx . . $ cutter_id# id = { "?", 0, 0 };
250 libusb_device_handle *handle;
251
252 if (1)
253 {
254 handle = UsbOpencxx . . $ UsbOpen(8430fd59fc59b3e0).(&id);
255 if (handle)
256 libusb_close(handle);
257 else
258 id.msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). "no device found";
259 }
260 else
261 {
262 id.msgcxx . . $ cutter_id#msg. =cxx . . $ std/__cxx11/basic_string#`operator=`(63cc1ae870623930). Errorcxx . . $ Error#("Cannot Identify while cut thread is running");
263 }
264 return &id;
265 }
266
267
268 QListcxx . . $ QList#<QPolygonFcxx . . $ QPolygonF#> Transform_Silhouette_Cameocxx . . $ Transform_Silhouette_Cameo(e3d882e1574489e7).(QListcxx . . $ QList#<QPolygonFcxx . . $ QPolygonF#> cuts, double *mediawidth, double *mediaheight)
269 {
270 const double devicewidth = 300; // cameo is 12inch aka 300mm wide
271 double w;
272 double h = *mediaheight;
273
274 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Transform_Silhouette_Cameo " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). *mediawidth <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "," <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). *mediaheight <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
275 if (0)
276 {
277 w = *mediawidth;
278 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Paper right aligned" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
279 }
280 else
281 {
282 w = devicewidth;
283 // adjust the used media area, so that the hardware does not clip.
284 *mediawidth = devicewidth;
285 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Paper left aligned" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
286 }
287
288
289 // flip it around 180 deg, and go backwards through the path list.
290 QListcxx . . $ QList#<QPolygonFcxx . . $ QPolygonF#> pathscxx . . $ QList#QList(49f6e7a06ebc5aa8).;
291 for (int i = cuts.sizecxx . . $ QList#size(455f465bc33b4cdf).()-1; i >= 0; i--)
292 {
293 QPolygonFcxx . . $ QPolygonF# polycxx . . $ QPolygonF#QPolygonF(49f6e7a06ebc5aa8).;
294 for (int j = 0; j < cuts[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i].sizecxx . . $ QVector#size(455f465bc33b4cdf).(); j++)
295 {
296 // QPolygonF is a QList<QPointF>
297 double x = cuts[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i][cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).j].xcxx . . $ QPointF#x(21b6c25e127938e2).();
298 double y = cuts[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i][cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).j].ycxx . . $ QPointF#y(21b6c25e127938e2).();
299 poly <<cxx . . $ QVector#`operator<<`(a67f761fa76cec1d). QPointFcxx . . $ QPointF#QPointF(bc12c9ec15586e6a).(w-x, h-y);
300 }
301 paths <<cxx . . $ QList#`operator<<`(309d1580d8f5dc58). poly;
302 }
303 return pathscxx . . $ QList#QList(b1a5d2b9a710f6d1).;
304 }
305
306 Errorcxx . . $ Error# Cutcxx . . $ Cut(9dcd4b391af4ff6f).(CutParamscxx . . $ CutParams# p)
307 {
308 VENDOR_IDcxx . . $ VENDOR_ID. = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getVendorUSB_IDcxx . . $ ProgramOptions#getVendorUSB_ID(b126dc7c1de90089).();
309 PRODUCT_IDcxx . . $ PRODUCT_ID. = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getProductUSB_IDcxx . . $ ProgramOptions#getProductUSB_ID(b126dc7c1de90089).();
310
311 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Cutting... VENDOR_ID : " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). VENDOR_IDcxx . . $ VENDOR_ID. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " PRODUCT_ID: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). PRODUCT_IDcxx . . $ PRODUCT_ID.
312 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " mediawidth: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). p.mediawidthcxx . . $ CutParams#mediawidth. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " mediaheight: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). p.mediaheightcxx . . $ CutParams#mediaheight.
313 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "media: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). p.mediacxx . . $ CutParams#media. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " speed: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). p.speedcxx . . $ CutParams#speed. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " pressure: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). p.pressurecxx . . $ CutParams#pressure.
314 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " trackenhancing: " <<cxx . . $ std/basic_ostream#`operator<<`(511cbee2d2e28827). p.trackenhancingcxx . . $ CutParams#trackenhancing. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " regmark: " <<cxx . . $ std/basic_ostream#`operator<<`(511cbee2d2e28827). p.regmarkcxx . . $ CutParams#regmark.
315 <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " regsearch:" <<cxx . . $ std/basic_ostream#`operator<<`(511cbee2d2e28827). p.regsearchcxx . . $ CutParams#regsearch. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7)." regwidth:" <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). p.regwidthcxx . . $ CutParams#regwidth. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " reglength: " <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). p.regheightcxx . . $ CutParams#regheight. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
316
317 if (p.mediacxx . . $ CutParams#media. < 100 || p.mediacxx . . $ CutParams#media. > 300)
318 p.mediacxx . . $ CutParams#media. = 300;
319 if (p.speedcxx . . $ CutParams#speed. < 1)
320 p.speedcxx . . $ CutParams#speed. = 1;
321 if (p.speedcxx . . $ CutParams#speed. > 10)
322 p.speedcxx . . $ CutParams#speed. = 10;
323 if (p.pressurecxx . . $ CutParams#pressure. < 1)
324 p.pressurecxx . . $ CutParams#pressure. = 1;
325 if (p.pressurecxx . . $ CutParams#pressure. > 33)
326 p.pressurecxx . . $ CutParams#pressure. = 33;
327
328 // how can VENDOR_ID / PRODUCT_ID report the correct values abve???
329 struct cutter_idcxx . . $ cutter_id# id = { "?", 0, 0 };
330 libusb_device_handle* handle = UsbInitcxx . . $ UsbInit(8430fd59fc59b3e0).(&id);
331 if (id.usb_vendor_idcxx . . $ cutter_id#usb_vendor_id. == VENDOR_ID_GRAPHTECcxx . . $ VENDOR_ID_GRAPHTEC. &&
332 id.usb_product_idcxx . . $ cutter_id#usb_product_id. == PRODUCT_ID_SILHOUETTE_CAMEOcxx . . $ PRODUCT_ID_SILHOUETTE_CAMEO.)
333 {
334 // should this also transform the regwidth regheigth or not?
335 p.cutscxx . . $ CutParams#cuts. =cxx . . $ QList#`operator=`(15ec5f0e45a4f6d6). Transform_Silhouette_Cameocxx . . $ Transform_Silhouette_Cameo(e3d882e1574489e7).(pcxx . . $ QList#QList(3d2301cfd89f773a)..cutscxx . . $ CutParams#cuts., &p.mediawidthcxx . . $ CutParams#mediawidth., &p.mediaheightcxx . . $ CutParams#mediaheight.);
336 }
337
338 // TODO: Use exceptions.
339
340 Errorcxx . . $ Error# e = Successcxx . . $ Success.;
341 stringcxx . . $ string# respcxx . . $ std/__cxx11/basic_string#basic_string(49f6e7a06ebc5aa8).;
342
343 // Initialise plotter.
344 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "\x1b\x04"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
345 if (!e) goto error;
346
347 // Status request.
348 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "\x1b\x05"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
349 if (!e) goto error;
350
351 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbReceivecxx . . $ UsbReceive(f5a276abbf5da7cb).(handle, resp, 5000);
352 if (!e) goto error;
353
354 if (resp !=cxx . . $ std/`operator!=`(4b17aa87c9f300c6). "0\x03") // 0 = Ready. 1 = Moving. 2 = Nothing loaded. " " = ??
355 {
356 if (resp ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "1\x03")
357 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). Errorcxx . . $ Error#("Moving, please try again.");
358 else if (resp ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "2\x03")
359 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). Errorcxx . . $ Error#("Empty tray, please load media."); // Silhouette Cameo
360 else
361 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). Errorcxx . . $ Error#("Invalid response from plotter: " +cxx . . $ std/operator+(42c652dfebe55ad7). resp);
362 goto error;
363 }
364
365 // Home the cutter.
366 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "TT\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
367 if (!e) goto error;
368
369 // Query version.
370 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FG\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
371 if (!e) goto error;
372
373 // Receive the firmware version.
374 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbReceivecxx . . $ UsbReceive(f5a276abbf5da7cb).(handle, resp, 10000); // Large timeout because the plotter moves.
375 if (!e) goto error;
376 // Don't really care about this.
377 // if (resp.length() != 10)
378 // {
379 // e = Error("Version error: " + version);
380 // goto error;
381 // }
382
383 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FW" +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(p.mediacxx . . $ CutParams#media.) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03");
384 if (!e) goto error;
385
386 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "!" +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(p.speedcxx . . $ CutParams#speed.) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03");
387 if (!e) goto error;
388
389 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FX" +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(p.pressurecxx . . $ CutParams#pressure.) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03");
390 if (!e) goto error;
391
392 // I think this sets the distance from the position of the plotter
393 // head to the actual cutting point, maybe in 0.1 mms (todo: Measure blade).
394 // It is 0 for the pen, 18 for cutting.
395 // C possible stands for curvature. Not that any of the other letters make sense...
396 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FC" +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(p.mediacxx . . $ CutParams#media. == 113 ? 0 : 18) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03");
397 if (!e) goto error;
398
399 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FY" +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(p.trackenhancingcxx . . $ CutParams#trackenhancing. ? 0 : 1) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03");
400 if (!e) goto error;
401
402 // Set to portrait. FN1 does landscape but it's easier just to rotate the image.
403 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FN0\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
404 if (!e) goto error;
405
406 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FE0\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); // No idea what this does.
407 if (!e) goto error;
408
409 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "TB71\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); // Again, no idea. Maybe something to do with registration marks?
410 if (!e) goto error;
411
412 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbReceivecxx . . $ UsbReceive(f5a276abbf5da7cb).(handle, resp, 10000); // Allow 10s. Seems reasonable.
413 if (!e) goto error;
414
415 if (resp !=cxx . . $ std/`operator!=`(4b17aa87c9f300c6). " 0, 0\x03")
416 {
417 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). Errorcxx . . $ Error#("Invalid response from plotter.");
418 goto error;
419 }
420
421
422 // Begin page definition.
423 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FA\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
424 if (!e) goto error;
425
426
427 // Block for all the "jump to error crosses initialization" errors. Really need to use exceptions!
428 {
429
430 // Page size: height,width in 20ths of a mm minus a margin. This is for A4. TODO: Find maximum and use that.
431 stringstreamcxx . . $ std/stringstream# pagecxx . . $ std/__cxx11/basic_stringstream#basic_stringstream(49f6e7a06ebc5aa8).;
432
433 int width = lroundl(p.mediawidthcxx . . $ CutParams#mediawidth. * 20.0);
434 int height = lroundl(p.mediaheightcxx . . $ CutParams#mediaheight. * 20.0);
435
436 int margintop = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getMarginTopcxx . . $ ProgramOptions#getMarginTop(b126dc7c1de90089).();
437 int marginright = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getMarginRightcxx . . $ ProgramOptions#getMarginRight(b126dc7c1de90089).();
438
439 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FU" +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(height - margintop) +cxx . . $ std/operator+(900ec9581c410ad9). "," +cxx . . $ std/operator+(aa1c00e85b87da6b). ItoScxx . . $ ItoS(7eb93f795f0defb3).(width - marginright) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03");
440 if (!e) goto error;
441 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FM1\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); // ?
442 if (!e) goto error;
443
444 if (p.regmarkcxx . . $ CutParams#regmark.)
445 {
446 stringstreamcxx . . $ std/stringstream# regmarkstrcxx . . $ std/__cxx11/basic_stringstream#basic_stringstream(49f6e7a06ebc5aa8).;
447 regmarkstr.precisioncxx . . $ std/ios_base#precision(8ce0d1b217db7fd1).(0);
448 stringcxx . . $ string# searchregcharcxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). = "23,"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).;
449 int regw = lroundl(p.regwidthcxx . . $ CutParams#regwidth. * 20.0);
450 int regl = lroundl(p.regheightcxx . . $ CutParams#regheight. * 20.0);
451 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "TB50,381\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); //only with registration (it was TB50,1) ???
452 if (!e) goto error;
453
454 if (p.regsearchcxx . . $ CutParams#regsearch.)
455 searchregchar =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74)."123,";
456
457 regmarkstr <<cxx . . $ std/`operator<<`(88df5bef833f7f83). "TB99\x03TB55,1\x03TB" +cxx . . $ std/operator+(42c652dfebe55ad7). searchregchar +cxx . . $ std/operator+(aa1c00e85b87da6b). ItoScxx . . $ ItoS(7eb93f795f0defb3).(regw) +cxx . . $ std/operator+(900ec9581c410ad9). "," +cxx . . $ std/operator+(aa1c00e85b87da6b). ItoScxx . . $ ItoS(7eb93f795f0defb3).(regl) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03";
458
459 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Registration mark string: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). regmarkstr.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
460
461 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, regmarkstr.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).()); //registration mark test /1-2: 180.0mm / 1-3: 230.0mm (origin 15mmx20mm)
462 if (!e) goto error;
463
464 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FQ5\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); // only with registration ???
465 if (!e) goto error;
466
467 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbReceivecxx . . $ UsbReceive(f5a276abbf5da7cb).(handle, resp, 40000); // Allow 20s for reply...
468 if (!e) goto error;
469 if (resp !=cxx . . $ std/`operator!=`(4b17aa87c9f300c6). " 0, 0\x03")
470 {
471 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). resp <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
472 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). Errorcxx . . $ Error#("Couldn't find registration marks.");
473 goto error;
474 }
475 // Looks like if the reg marks work it gets 3 messages back (if it fails it times out because it only gets the first message)
476 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbReceivecxx . . $ UsbReceive(f5a276abbf5da7cb).(handle, resp, 40000); // Allow 20s for reply...
477 if (!e) goto error;
478 if (resp !=cxx . . $ std/`operator!=`(4b17aa87c9f300c6). " 0\x03")
479 {
480 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). resp <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
481 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). Errorcxx . . $ Error#("Couldn't find registration marks.");
482 goto error;
483 }
484
485 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbReceivecxx . . $ UsbReceive(f5a276abbf5da7cb).(handle, resp, 40000); // Allow 20s for reply...
486 if (!e) goto error;
487 if (resp !=cxx . . $ std/`operator!=`(4b17aa87c9f300c6). " 1\x03")
488 {
489 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). resp <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
490 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). Errorcxx . . $ Error#("Couldn't find registration marks.");
491 goto error;
492 }
493 }
494 else
495 {
496 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "TB50,1\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); // ???
497 if (!e) goto error;
498 }
499
500 if (!e) goto error;
501 // I think this is the feed command. Sometimes it is 5588 - maybe a maximum?
502 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FO" +cxx . . $ std/operator+(39ed2c165380f78e). ItoScxx . . $ ItoS(7eb93f795f0defb3).(height - margintop) +cxx . . $ std/operator+(900ec9581c410ad9). "\x03");
503 if (!e) goto error;
504
505 page.flagscxx . . $ std/ios_base#flags(79f645757f7c3f1c).(ioscxx . . $ std/ios#::fixedcxx . . $ std/ios_base#fixed.);
506 page.precisioncxx . . $ std/ios_base#precision(8ce0d1b217db7fd1).(0);
507 page <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "&100,100,100,\\0,0,Z" <<cxx . . $ std/`operator<<`(88df5bef833f7f83). ItoScxx . . $ ItoS(7eb93f795f0defb3).(width) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "," <<cxx . . $ std/`operator<<`(88df5bef833f7f83). ItoScxx . . $ ItoS(7eb93f795f0defb3).(height) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ",L0";
508 for (int i = 0; i < p.cutscxx . . $ CutParams#cuts..sizecxx . . $ QList#size(455f465bc33b4cdf).(); ++i)
509 {
510 if (p.cutscxx . . $ CutParams#cuts.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i].sizecxx . . $ QVector#size(455f465bc33b4cdf).() < 2)
511 continue;
512
513 double x = p.cutscxx . . $ CutParams#cuts.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i][cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).0].xcxx . . $ QPointF#x(21b6c25e127938e2).()*20.0;
514 double y = p.cutscxx . . $ CutParams#cuts.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i][cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).0].ycxx . . $ QPointF#y(21b6c25e127938e2).()*20.0;
515
516 double xorigin = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getRegOriginWidthMMcxx . . $ ProgramOptions#getRegOriginWidthMM(31fa7155c10fdd13).();
517 double yorigin = ProgramOptionscxx . . $ ProgramOptions#::Instancecxx . . $ ProgramOptions#Instance(63cd40b15f95c435).().getRegOriginHeightMMcxx . . $ ProgramOptions#getRegOriginHeightMM(31fa7155c10fdd13).();
518
519 if (p.regmarkcxx . . $ CutParams#regmark.)
520 {
521 x = x - (xorigin*20.0);
522 y = y + (yorigin*20.0);
523 }
524
525 // TODO: Also do this in the UI and warn the user about it.
526 if (x < 0.0) x = 0.0;
527 if (x > width) x = width;
528
529 if (y < 0.0) y = 0.0;
530 if (y > height) y = height;
531
532 page <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ",M" <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). x <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "," <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). height-y;
533 for (int j = 1; j < p.cutscxx . . $ CutParams#cuts.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i].sizecxx . . $ QVector#size(455f465bc33b4cdf).(); ++j)
534 {
535 x = p.cutscxx . . $ CutParams#cuts.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i][cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).j].xcxx . . $ QPointF#x(21b6c25e127938e2).()*20.0;
536 y = p.cutscxx . . $ CutParams#cuts.[cxx . . $ QList#`operator[]`(7a0ef1c7079e8533).i][cxx . . $ QVector#`operator[]`(7a0ef1c7079e8533).j].ycxx . . $ QPointF#y(21b6c25e127938e2).()*20.0;
537
538 if (p.regmarkcxx . . $ CutParams#regmark.)
539 {
540 x = x - (xorigin*20.0);
541 y = y + (yorigin*20.0);
542 }
543
544 bool draw = true;
545 if (x <= 0.0)
546 {
547 x = 0.0;
548 draw = false;
549 }
550 if (x >= width)
551 {
552 x = width;
553 draw = false;
554 }
555 if (y <= 0.0)
556 {
557 y = 0.0;
558 draw = false;
559 }
560 if (y >= height)
561 {
562 y = height;
563 draw = false;
564 }
565
566 if (draw) page <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ",D" <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). x <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "," <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). height-y;
567 else page <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ",M" <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). x <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "," <<cxx . . $ std/basic_ostream#`operator<<`(968942d578224538). height-y; // if outside the range just move
568 }
569 }
570
571
572 page <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "&1,1,1,TB50,0\x03"; // TB maybe .. ah I dunno. Need to experiment. No idea what &1,1,1 does either.
573
574 // cout << page.str() << endl;
575
576 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, page.strcxx . . $ std/__cxx11/basic_stringstream#str(d33e1a6fd36255f7).());
577 if (!e) goto error;
578 }
579
580 // Feed the page out.
581 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "FO0\x03"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
582 if (!e) goto error;
583
584 // Halt?
585 e =cxx . . $ Error#`operator=`(928620813ca2ddf7). UsbSendcxx . . $ UsbSend(9a3035e5b91f40a3).(handle, "H,"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).);
586 if (!e) goto error;
587
588
589 // Don't really care about the results of these!
590 libusb_release_interface(handle, 0);
591 libusb_close(handle);
592
593 return Successcxx . . $ Success.;
594
595 error: // Hey, this is basically C and I can't be bothered to properly C++-ify it. TODO: Use exceptions.
596 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error: " <<cxx . . $ std/basic_ostream#`operator<<`(511cbee2d2e28827). e <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). endlcxx . . $ std/endl(345bf97a19cc83a9).;
597 libusb_release_interface(handle, 0);
598 libusb_close(handle);
599 return e;
600
601 }
602