Debian Codegraph @

ProgramOptions.cpp

raw symbols SCIP
1 /***************************************************************************
2 * This file is part of Robocut. *
3 * Copyright (C) 2010 Markus Schulz <[email protected]> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20
21 #include "ProgramOptions.h"
22 #include <cmath>
23 #include <getopt.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <iostream>
27 using namespace std;
28
29 ProgramOptions::ProgramOptions ( )
30 {
31 initAttributes();
32 }
33 ProgramOptions::~ProgramOptions ( )
34 {
35 }
36 ProgramOptions& ProgramOptions::Instance()
37 {
38 static ProgramOptions instance;
39 return instance;
40 }
41
42
43 void ProgramOptions::setSortPath ( int new_var )
44 {
45 sortPath = new_var;
46 }
47
48 int ProgramOptions::getSortPath ( )
49 {
50 return sortPath;
51 }
52
53 void ProgramOptions::setStartCut ( int new_var )
54 {
55 startCut = new_var;
56 }
57
58 int ProgramOptions::getStartCut ( )
59 {
60 return startCut;
61 }
62
63 void ProgramOptions::setFileName ( QString new_var )
64 {
65 fileName = new_var;
66 }
67
68 QString ProgramOptions::getFileName ( )
69 {
70 return fileName;
71 }
72
73 void ProgramOptions::setTspSortPath ( int new_var )
74 {
75 tspSortPath = new_var;
76 }
77
78 int ProgramOptions::getTspSortPath ( )
79 {
80 return tspSortPath;
81 }
82
83 void ProgramOptions::setMedia ( int new_var )
84 {
85 if (new_var<0) new_var = 0;
86 if (new_var>25) new_var = 25;
87 media = new_var;
88 }
89
90 int ProgramOptions::getMedia ( )
91 {
92 return media;
93 }
94
95 void ProgramOptions::setSpeed ( int new_var )
96 {
97 speed = new_var;
98 }
99
100 int ProgramOptions::getSpeed ( )
101 {
102 return speed;
103 }
104
105 void ProgramOptions::setPressure ( int new_var )
106 {
107 pressure = new_var;
108 }
109
110 int ProgramOptions::getPressure ( )
111 {
112 return pressure;
113 }
114
115 void ProgramOptions::setRegMarkAuto ( int new_var )
116 {
117 regMarkAuto = new_var;
118 }
119
120 int ProgramOptions::getRegMarkAuto ( )
121 {
122 return regMarkAuto;
123 }
124
125 void ProgramOptions::setRegMark ( int new_var )
126 {
127 regMark = new_var;
128 }
129
130 int ProgramOptions::getRegMark ( )
131 {
132 return regMark;
133 }
134
135 void ProgramOptions::setRegDimensionWidth ( int new_var )
136 {
137 regDimensionWidth = new_var;
138 }
139
140 int ProgramOptions::getRegDimensionWidth ( )
141 {
142 return lroundl(regDimensionWidth);
143 }
144
145 void ProgramOptions::setRegDimensionHeight ( int new_var )
146 {
147 regDimensionHeight = new_var;
148 }
149
150 int ProgramOptions::getRegDimensionHeight ( )
151 {
152 return lroundl(regDimensionHeight);
153 }
154
155 void ProgramOptions::setRegOriginWidth ( int new_var )
156 {
157 regOriginWidth = new_var;
158 }
159
160 int ProgramOptions::getRegOriginWidth ( )
161 {
162 return lroundl(regOriginWidth);
163 }
164
165 void ProgramOptions::setRegOriginHeight ( int new_var )
166 {
167 regOriginHeight = new_var;
168 }
169
170 int ProgramOptions::getRegOriginHeight ( )
171 {
172 return lroundl(regOriginHeight);
173 }
174
175 void ProgramOptions::setRegDimensionWidthMM ( double new_var )
176 {
177 regDimensionWidth = new_var*20;
178 }
179
180 double ProgramOptions::getRegDimensionWidthMM ( )
181 {
182 return regDimensionWidth/20;
183 }
184
185 void ProgramOptions::setRegDimensionHeightMM ( double new_var )
186 {
187 regDimensionHeight = new_var*20;
188 }
189
190 double ProgramOptions::getRegDimensionHeightMM ( )
191 {
192 return regDimensionHeight/20;
193 }
194
195 void ProgramOptions::setRegOriginWidthMM ( double new_var )
196 {
197 regOriginWidth = new_var*20;
198 }
199
200 double ProgramOptions::getRegOriginWidthMM ( )
201 {
202 return regOriginWidth/20;
203 }
204
205 void ProgramOptions::setRegOriginHeightMM ( double new_var )
206 {
207 regOriginHeight = new_var*20;
208 }
209
210 double ProgramOptions::getRegOriginHeightMM ( )
211 {
212 return regOriginHeight/20;
213 }
214
215 void ProgramOptions::setVersion ( QString new_var )
216 {
217 version = new_var;
218 }
219
220 QString ProgramOptions::getVersion ( )
221 {
222 return version;
223 }
224
225 void ProgramOptions::setVendorUSB_ID ( int new_var )
226 {
227 vendorUSB_ID = new_var;
228 }
229
230 int ProgramOptions::getVendorUSB_ID ( )
231 {
232 return vendorUSB_ID;
233 }
234
235 void ProgramOptions::setProductUSB_ID ( int new_var )
236 {
237 productUSB_ID = new_var;
238 }
239
240 int ProgramOptions::getProductUSB_ID ( )
241 {
242 return productUSB_ID;
243 }
244
245 void ProgramOptions::setMarginTop ( int new_var )
246 {
247 marginTop = new_var;
248 }
249 int ProgramOptions::getMarginTop ( )
250 {
251 return lroundl(marginTop);
252 }
253 void ProgramOptions::setMarginRight ( int new_var )
254 {
255 marginRight = new_var;
256 }
257 int ProgramOptions::getMarginRight ( )
258 {
259 return lroundl(marginRight);
260 }
261
262 void ProgramOptions::setMarginTopMM ( double new_var )
263 {
264 marginTop = new_var*20;
265 }
266 double ProgramOptions::getMarginTopMM ( )
267 {
268 return marginTop/20;
269 }
270 void ProgramOptions::setMarginRightMM ( double new_var )
271 {
272 marginRight = new_var*20;
273 }
274 double ProgramOptions::getMarginRightMM ( )
275 {
276 return marginRight/20;
277 }
278
279 void ProgramOptions::setTrackEnhancing ( int new_var )
280 {
281 trackEnhancing = new_var;
282 }
283
284 int ProgramOptions::getTrackEnhancing ( )
285 {
286 return trackEnhancing;
287 }
288
289 int ProgramOptions::GetOpt (int argc, char *argv[] )
290 {
291 static int version_flag = 0, help_flag = 0, show_flag = 0;
292 int index, option_index = 0;
293 int c = 0;
294 const char shortopts[] = "stg:p:ra:b:c:d:";
295 static struct option longopts[] =
296 {
297 {"help", no_argument, &help_flag, 1},
298 {"version", no_argument, &version_flag, 1},
299 {"show", no_argument, &show_flag, 1},
300 {"no-sort", no_argument, 0, 's'},
301 {"bb-sort", no_argument, 0, 't'},
302 {"cut", no_argument, 0, 'l'},
303 {"media", required_argument, 0, 'm'},
304 {"speed", required_argument, 0, 'g'},
305 {"pressure", required_argument, 0, 'p'},
306 {"track-enhancing", no_argument, 0, 'n'},
307 {"margin-top", required_argument, 0, 'o'},
308 {"margin-right", required_argument, 0, 'q'},
309 {"reg-mark-auto", no_argument, 0, 'r'},
310 {"reg-mark", no_argument, 0, 'h'},
311 {"reg-dimension-width", required_argument, 0, 'a'},
312 {"reg-dimension-height", required_argument, 0, 'b'},
313 {"reg-origin-width", required_argument, 0, 'c'},
314 {"reg-origin-height", required_argument, 0, 'd'},
315 {"usb-vendor-id", required_argument, 0, 'e'},
316 {"usb-product-id", required_argument, 0, 'f'},
317 {0, 0, 0, 0}
318 };
319
320 opterr = 0;
321 while ((c = getopt_long(argc, argv, shortopts, longopts, &option_index)) != -1)
322 {
323 switch (c)
324 {
325 case 0:
326 /* If this option set a flag, do nothing else now. */
327 if (longopts[option_index].flag != 0) break;
328 //cout << longopts[option_index].name << endl;
329 break;
330 case 's':
331 setSortPath(true);
332 break;
333 case 't':
334 setTspSortPath(true);
335 break;
336 case 'l':
337 setStartCut(true);
338 break;
339 case 'm':
340 setMedia(atoi(optarg));
341 break;
342 case 'g':
343 setSpeed(atoi(optarg));
344 break;
345 case 'p':
346 setPressure(atoi(optarg));
347 break;
348 case 'n':
349 setTrackEnhancing(true);
350 break;
351 case 'o':
352 setMarginTopMM(atof(optarg));
353 break;
354 case 'q':
355 setMarginRightMM(atof(optarg));
356 break;
357 case 'r':
358 setRegMarkAuto(true);
359 break;
360 case 'h':
361 setRegMark(true);
362 break;
363 case 'a':
364 setRegDimensionWidthMM(atof(optarg));
365 break;
366 case 'b':
367 setRegDimensionHeightMM(atof(optarg));
368 break;
369 case 'c':
370 setRegOriginWidthMM(atof(optarg));
371 break;
372 case 'd':
373 setRegOriginHeightMM(atof(optarg));
374 break;
375 case 'e':
376 setVendorUSB_ID(atoi(optarg));
377 break;
378 case 'f':
379 setProductUSB_ID(atoi(optarg));
380 break;
381 case '?':
382 if (optopt == 'f')
383 cerr << "Option -"<< optopt <<" requires an argument." << endl;
384 else if (isprint (optopt))
385 cerr << "Unknown option `-"<< (char)optopt <<"'." << endl;
386 else
387 cerr << "Unknown option character ASCII code "<< optopt <<"." << endl;
388 exit(0);
389 default:
390 abort();
391 }
392 }
393 for (index = optind; index < argc; index++)
394 {
395 //cout << "Non-option argument " << argv[index] <<"'." << endl;
396 fileName = argv[optind]; // take the first non arg as file
397 continue;
398 }
399 if(show_flag)
400 {
401 showShow();
402 exit(0);
403 }
404 if(help_flag)
405 {
406 showHelp();
407 exit(0);
408 }
409 if(version_flag)
410 {
411 showVersion();
412 exit(0);
413 }
414 return 0;
415 }
416
417 void ProgramOptions::showHelp ( )
418 {
419 // "<------------------------------------------------------------------------------>"
420 cout << "The `Robocut' program plots or cuts SVG files on a Craft Robo or Silhouette SD" << endl;
421 cout << "or most likely any other customer grade Graphtec cutting plotter." << endl << endl;
422 cout << "Usage:" << endl;
423 cout << " robocut [OPTIONS...] [File]" << endl << endl;
424 // "<------------------------------------------------------------------------------>"
425 cout << "Help Options:" << endl;
426 cout << " --help Show summary of options." << endl;
427 cout << " --version Show version information and copyright details." << endl;
428 cout << " --show Show all the parameters entered and the defaults." << endl << endl;
429 // "<------------------------------------------------------------------------------>"
430 cout << "Application Options:" << endl;
431 cout << " -s, --no-sort Stop sort the objects from the SVG before plotting." << endl;
432 cout << " -t, --bb-sort Sort the objects by bounding box, good for letters." << endl;
433 cout << " This will cut out the inside first and than the" << endl;
434 cout << " outside." << endl;
435 cout << " --cut Shows the cutting dialogue after start." << endl;
436 cout << " --media INT Select the media. See drop down box." << endl;
437 cout << " -g, --speed INT The speed between 1 and 33." << endl;
438 cout << " -p, --pressure INT The pressure between 1 and 10." << endl;
439 cout << " --track-enhancing Move three times back and forward to create a" << endl;
440 cout << " track." << endl;
441 cout << " --margin-top DOUBLE Define the margin on top in mm." << endl;
442 cout << " --margin-right DOUBLE Define the margin right in mm." << endl << endl;
443 // "<------------------------------------------------------------------------------>"
444 cout << "Registration Mark Options:" << endl;
445 cout << " -r, --reg-mark-auto Use registration marks and find the marks" << endl;
446 cout << " automatically." << endl;
447 cout << " --reg-mark Use registration marks but set the knife manually" << endl;
448 cout << " on top the round mark." << endl;
449 cout << " -a, --reg-dimension-width DOUBLE" << endl;
450 cout << " Specify the length in mm between the the two" << endl;
451 cout << " horizontal marks." << endl;
452 cout << " -b, --reg-dimension-height DOUBLE" << endl;
453 cout << " Specify the length in mm between the the two" << endl;
454 cout << " vertical marks." << endl;
455 cout << " -c, --reg-origin-width DOUBLE" << endl;
456 cout << " Specify the length in mm between the the edge of" << endl;
457 cout << " the paper and the first horizontal mark." << endl;
458 cout << " -d, --reg-origin-height DOUBLE" << endl;
459 cout << " Specify the length in mm between the the edge of" << endl;
460 cout << " the paper and the first vertical mark." << endl << endl;
461 // "<------------------------------------------------------------------------------>"
462 cout << "Device Options:" << endl;
463 cout << " --usb-vendor-id INT Try this program with other usb hardware on" << endl;
464 cout << " your own risk. You need to convert hex to dec." << endl;
465 cout << " --usb-product-id INT May also work with other hardware, try" << endl;
466 cout << " usb-devices program to scan your computer." << endl;
467 cout << "Report bugs to https://bugs.launchpad.net/robocut/+filebug." << endl;
468 // "<------------------------------------------------------------------------------>"
469 }
470
471
472 void ProgramOptions::showVersion ( )
473 {
474 cout << (version.toStdString()); // see main.cpp
475 cout << "\n\nCopyright (C) 2015\n";
476 cout << "This is free software; see the source for copying conditions. There is NO\n";
477 cout << "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n";
478 cout << "Written by Tim Hutt <[email protected]> and Markus Schulz <[email protected]>\n";
479 }
480
481 void ProgramOptions::showShow ( )
482 {
483 cout << "Application Options:\n";
484 cout << " -s, --no-sort "<< getSortPath() << endl;
485 cout << " -t, --bb-sort "<< getTspSortPath() << endl;
486 cout << " --cut "<< getStartCut() << endl;
487 cout << " --media "<< getMedia() << endl;
488 cout << " -g, --speed "<< getSpeed() << endl;
489 cout << " -p, --pressure "<< getPressure() << endl;
490 cout << " --track-enhancing "<< getTrackEnhancing() << endl;
491 cout << " --margin-top "<< getMarginTopMM() << " / " << getMarginTop() << endl;
492 cout << " --margin-right "<< getMarginRightMM() << " / " << getMarginRight() << endl;
493 cout << " -r, --reg-mark-auto "<< getRegMarkAuto() << endl;
494 cout << " --reg-mark "<< getRegMark() << endl;
495 cout << " -a, --reg-dimension-width "<< getRegDimensionWidthMM() << " / " << getRegDimensionWidth() << endl;
496 cout << " -b, --reg-dimension-height "<< getRegDimensionHeightMM() << " / " << getRegDimensionHeight() << endl;
497 cout << " -c, --reg-origin-width "<< getRegOriginWidthMM() << " / " << getRegOriginWidth() << endl;
498 cout << " -d, --reg-origin-height "<< getRegOriginHeightMM() << " / " << getRegOriginHeight() << endl;
499 cout << " --usb-vendor-id "<< getVendorUSB_ID() << endl;
500 cout << " --usb-product-id "<< getProductUSB_ID() << endl;
501 cout << "[File] "<< getFileName().toStdString() << endl;
502 }
503
504 void ProgramOptions::initAttributes ( ) {
505 sortPath = false;
506 tspSortPath = false; // used for BBox
507 startCut = false;
508 fileName = "";
509 media = 2;
510 speed = 10;
511 pressure = 10;
512 regMarkAuto = false;
513 regMark = false;
514 setRegDimensionWidthMM(180.0);
515 setRegDimensionHeightMM(240.0);
516 setRegOriginWidthMM(15.0);
517 setRegOriginHeightMM(10.0);
518 vendorUSB_ID = 0x0b4d;
519 productUSB_ID = 0x111d;
520 setMarginTop(500);
521 setMarginRight(320);
522 trackEnhancing = false;
523 }
524