Seamly2D
Code documentation
vcmdexport.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vcmdexport.cpp
4  ** @author Alex Zaharov <alexzkhr@gmail.com>
5  ** @date 25 8, 2015
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2015 Seamly2D project
12  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #include "vcmdexport.h"
30 #include "../dialogs/dialoglayoutsettings.h"
31 #include "../vwidgets/export_format_combobox.h"
32 #include "../ifc/xml/vdomdocument.h"
33 #include "../vformat/vmeasurements.h"
34 #include "../vmisc/commandoptions.h"
35 #include "../vmisc/vsettings.h"
36 #include "../vlayout/vlayoutgenerator.h"
37 #include <QDebug>
38 
40 
41 #define translate(context, source) QCoreApplication::translate((context), (source))
42 
43 //---------------------------------------------------------------------------------------------------------------------
44 VCommandLine::VCommandLine() : parser(), optionsUsed(), optionsIndex(), isGuiEnabled(false)
45 {
46  parser.setApplicationDescription(translate("VCommandLine", "Pattern making program."));
47  parser.addHelpOption();
48  parser.addVersionOption();
49  parser.addPositionalArgument("filename", translate("VCommandLine", "Pattern file."));
50 
52 
53  VCommandLineOptions::const_iterator i = optionsUsed.constBegin();
54  while (i != optionsUsed.constEnd())
55  {
56  parser.addOption(*(*i));
57  ++i;
58  }
59 }
60 
61 //---------------------------------------------------------------------------------------------------------------------
62 qreal VCommandLine::Lo2Px(const QString &src, const DialogLayoutSettings &converter)
63 {
64  return converter.LayoutToPixels(src.toDouble());
65 }
66 
67 //---------------------------------------------------------------------------------------------------------------------
68 qreal VCommandLine::Pg2Px(const QString& src, const DialogLayoutSettings& converter)
69 {
70  return converter.PageToPixels(src.toDouble());
71 }
72 
73 //---------------------------------------------------------------------------------------------------------------------
75 {
76  int index = 0;
77  //keep in mind order here - that is how user will see it, so group-up for usability
78  //=================================================================================================================
79  optionsIndex.insert(LONG_OPTION_BASENAME, index++);
80  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_BASENAME << LONG_OPTION_BASENAME,
81  translate("VCommandLine", "The base filename of exported layout files. Use "
82  "it to enable console export mode."),
83  translate("VCommandLine", "The base filename of layout files")));
84 
85  optionsIndex.insert(LONG_OPTION_DESTINATION, index++);
86  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_DESTINATION << LONG_OPTION_DESTINATION,
87  translate("VCommandLine", "The path to output destination folder. By "
88  "default the directory at which the application was started."),
89  translate("VCommandLine", "The destination folder")));
90 
91  optionsIndex.insert(LONG_OPTION_MEASUREFILE, index++);
92  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_MEASUREFILE,
93  translate("VCommandLine", "Path to custom measure file (export mode)."),
94  translate("VCommandLine", "The measure file")));
95 
96  optionsIndex.insert(LONG_OPTION_EXP2FORMAT, index++);
97  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_EXP2FORMAT << LONG_OPTION_EXP2FORMAT,
98  translate("VCommandLine", "Number corresponding to output format (default = "
99  "0, export mode):") +
101  translate("VCommandLine", "Format number"), "0"));
102 
103  optionsIndex.insert(LONG_OPTION_BINARYDXF, index++);
104  options.append(new QCommandLineOption(QStringList() << LONG_OPTION_BINARYDXF,
105  translate("VCommandLine", "Export dxf in binary form.")));
106 
107  optionsIndex.insert(LONG_OPTION_TEXT2PATHS, index++);
108  options.append(new QCommandLineOption(QStringList() << LONG_OPTION_TEXT2PATHS,
109  translate("VCommandLine", "Export text as paths.")));
110 
112  options.append(new QCommandLineOption(QStringList() << LONG_OPTION_EXPORTONLYDETAILS,
113  translate("VCommandLine", "Export only details. Export details as they "
114  "positioned in the details mode. Any layout related"
115  " options will be ignored.")));
116 
117  optionsIndex.insert(LONG_OPTION_GRADATIONSIZE, index++);
118  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE,
119  translate("VCommandLine", "Set size value a pattern file, that was opened "
120  "with multisize measurements (export mode). Valid "
121  "values: %1cm.")
122  .arg(VMeasurement::WholeListSizes(Unit::Cm).join(", ")),
123  translate("VCommandLine", "The size value")));
124 
125  optionsIndex.insert(LONG_OPTION_GRADATIONHEIGHT, index++);
126  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONHEIGHT << LONG_OPTION_GRADATIONHEIGHT,
127  translate("VCommandLine", "Set height value a pattern file, that was opened "
128  "with multisize measurements (export mode). Valid "
129  "values: %1cm.")
130  .arg(VMeasurement::WholeListHeights(Unit::Cm).join(", ")),
131  translate("VCommandLine", "The height value")));
132 
133  //=================================================================================================================
134  optionsIndex.insert(LONG_OPTION_PAGETEMPLATE, index++);
135  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_PAGETEMPLATE,
136  translate("VCommandLine", "Number corresponding to page template (default = "
137  "0, export mode):") +
139  translate("VCommandLine", "Template number"), "0"));
140 
141  optionsIndex.insert(LONG_OPTION_PAGEW, index++);
142  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEW << LONG_OPTION_PAGEW,
143  translate("VCommandLine", "Page width in current units like 12.0 (cannot be "
144  "used with \"%1\", export mode).")
146  translate("VCommandLine", "The page width")));
147 
148  optionsIndex.insert(LONG_OPTION_PAGEH, index++);
149  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEH << LONG_OPTION_PAGEH,
150  translate("VCommandLine", "Page height in current units like 12.0 (cannot "
151  "be used with \"%1\", export mode).")
153  ("The page height")));
154 
155  optionsIndex.insert(LONG_OPTION_PAGEUNITS, index++);
156  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_PAGEUNITS << LONG_OPTION_PAGEUNITS,
157  translate("VCommandLine", "Page height/width measure units (cannot be used "
158  "with \"%1\", export mode). Valid values: %2.")
160  translate("VCommandLine", "The measure unit")));
161 
162  optionsIndex.insert(LONG_OPTION_IGNORE_MARGINS, index++);
163  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_IGNORE_MARGINS << LONG_OPTION_IGNORE_MARGINS,
164  translate("VCommandLine",
165  "Ignore margins printing (export mode). Disable value keys: "
166  "\"%1\", \"%2\", \"%3\", \"%4\". Set all margins to 0.")
169 
170  optionsIndex.insert(LONG_OPTION_LEFT_MARGIN, index++);
171  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_LEFT_MARGIN << LONG_OPTION_LEFT_MARGIN,
172  translate("VCommandLine",
173  "Page left margin in current units like 3.0 (export mode). If "
174  "not set will be used value from default printer. Or 0 if none "
175  "printers was found. Value will be ignored if key \"%1\" is used.")
177  ("The left margin")));
178 
179  optionsIndex.insert(LONG_OPTION_RIGHT_MARGIN, index++);
180  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_RIGHT_MARGIN << LONG_OPTION_RIGHT_MARGIN,
181  translate("VCommandLine",
182  "Page right margin in current units like 3.0 (export mode). If "
183  "not set will be used value from default printer. Or 0 if none "
184  "printers was found. Value will be ignored if key \"%1\" is used.")
186  ("The right margin")));
187 
188  optionsIndex.insert(LONG_OPTION_TOP_MARGIN, index++);
189  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_TOP_MARGIN << LONG_OPTION_TOP_MARGIN,
190  translate("VCommandLine",
191  "Page top margin in current units like 3.0 (export mode). If "
192  "not set will be used value from default printer. Or 0 if none "
193  "printers was found. Value will be ignored if key \"%1\" is used.")
195  ("The top margin")));
196 
197  optionsIndex.insert(LONG_OPTION_BOTTOM_MARGIN, index++);
198  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_BOTTOM_MARGIN << LONG_OPTION_BOTTOM_MARGIN,
199  translate("VCommandLine",
200  "Page bottom margin in current units like 3.0 (export mode). If "
201  "not set will be used value from default printer. Or 0 if none "
202  "printers was found. Value will be ignored if key \"%1\" is used.")
204  ("The bottom margin")));
205 
206  //=================================================================================================================
207  optionsIndex.insert(LONG_OPTION_ROTATE, index++);
208  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_ROTATE << LONG_OPTION_ROTATE,
209  translate("VCommandLine", "Rotation in degrees (one of predefined, "
210  "export mode). Default value is 180. 0 is no-rotate. Valid values: "
211  "%1. Each value show how many times details will be rotated. For "
212  "example 180 mean two times (360/180=2) by 180 degree.")
213  .arg("0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 18, 20, 24, 30, 36, 40, 45, "
214  "60, 72, 90, 180"),
215  translate("VCommandLine", "Angle")));
216 
217  optionsIndex.insert(LONG_OPTION_CROP, index++);
218  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_CROP << LONG_OPTION_CROP,
219  translate("VCommandLine", "Auto crop unused length (export mode).")));
220 
221  optionsIndex.insert(LONG_OPTION_UNITE, index++);
222  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_UNITE << LONG_OPTION_UNITE,
223  translate("VCommandLine", "Unite pages if possible (export mode). Maximum "
224  "value limited by QImage that supports only a maximum of "
225  "32768x32768 px images.")));
226 
227  //=================================================================================================================
228  optionsIndex.insert(LONG_OPTION_SAVELENGTH, index++);
229  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SAVELENGTH << LONG_OPTION_SAVELENGTH,
230  translate("VCommandLine",
231  "Save length of the sheet if set (export mode). The option tells "
232  "the program to use as much as possible width of sheet. Quality "
233  "of a layout can be worse when this option was used.")));
234 
235  optionsIndex.insert(LONG_OPTION_SHIFTUNITS, index++);
236  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTUNITS << LONG_OPTION_SHIFTUNITS,
237  translate("VCommandLine",
238  "Layout units (as paper's one except px, export mode)."),
239  translate("VCommandLine", "The unit")));
240 
241  optionsIndex.insert(LONG_OPTION_SHIFTLENGTH, index++);
242  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_SHIFTLENGTH << LONG_OPTION_SHIFTLENGTH,
243  translate("VCommandLine", "Shift/Offset layout length measured in layout "
244  "units (export mode). The option show how many points along edge "
245  "will be used in creating a layout."),
246  translate("VCommandLine", "Shift/Offset length")));
247 
248  optionsIndex.insert(LONG_OPTION_GAPWIDTH, index++);
249  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GAPWIDTH << LONG_OPTION_GAPWIDTH,
250  translate("VCommandLine",
251  "The layout gap width x2, measured in layout units (export mode). "
252  "Set distance between details and a detail and a sheet."),
253  translate("VCommandLine", "The gap width")));
254 
255  optionsIndex.insert(LONG_OPTION_GROUPPING, index++);
256  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GROUPPING << LONG_OPTION_GROUPPING,
257  translate("VCommandLine", "Sets layout groupping cases (export mode): %1.")
259  translate("VCommandLine", "Grouping type"), "2"));
260 
261  optionsIndex.insert(LONG_OPTION_TEST, index++);
262  options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_TEST << LONG_OPTION_TEST,
263  translate("VCommandLine", "Run the program in a test mode. The program in "
264  "this mode loads a single pattern file and silently quit without "
265  "showing the main window. The key have priority before key '%1'.")
266  .arg(LONG_OPTION_BASENAME)));
267 
268  optionsIndex.insert(LONG_OPTION_NO_HDPI_SCALING, index++);
269  options.append(new QCommandLineOption(QStringList() << LONG_OPTION_NO_HDPI_SCALING,
270  translate("VCommandLine", "Disable high dpi scaling. Call this option if has "
271  "problem with scaling (by default scaling "
272  "enabled). Alternatively you can use the "
273  "%1 environment variable.")
274  .arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")));
275 }
276 
277 //------------------------------------------------------------------------------------------------------
279 {
280  //this functions covers all options found into layout setup dialog, nothing to add here, unless dialog extended
281 
283  DialogLayoutSettings diag(res.get(), nullptr, true);
284 
285  {
286  //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
287  bool x = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE)));
288 
289  bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH)));
290  bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW)));
291  bool c = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
292 
293  if ((a || b || c) && x)
294  {
295  qCritical() << translate("VCommandLine", "Cannot use pageformat and page explicit size/units together.")
296  << "\n";
297  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
298  }
299 
300  if ((a || b || c) && !(a && b && c))
301  {
302  qCritical() << translate("VCommandLine", "Page height, width, units must be used all 3 at once.") << "\n";
303  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
304  }
305 
306  }
307 
308  {
309  //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
310  bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH)));
311  bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)));
312 
313  if ((a || b) && !(a && b))
314  {
315  qCritical() << translate("VCommandLine", "Shift/Offset length must be used together with shift units.")
316  << "\n";
317  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
318  }
319  }
320 
321  {
322  //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
323  bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH)));
324  bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)));
325 
326  if ((a || b) && !(a && b))
327  {
328  qCritical() << translate("VCommandLine", "Gap width must be used together with shift units.") << "\n";
329  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
330  }
331  }
332 
333  {
334  //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
335  bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_LEFT_MARGIN)));
336  bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
337 
338  if ((a || b) && !(a && b))
339  {
340  qCritical() << translate("VCommandLine", "Left margin must be used together with page units.") << "\n";
341  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
342  }
343  }
344 
345  {
346  //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
347  bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_RIGHT_MARGIN)));
348  bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
349 
350  if ((a || b) && !(a && b))
351  {
352  qCritical() << translate("VCommandLine", "Right margin must be used together with page units.") << "\n";
353  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
354  }
355  }
356 
357  {
358  //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
359  bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TOP_MARGIN)));
360  bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
361 
362  if ((a || b) && !(a && b))
363  {
364  qCritical() << translate("VCommandLine", "Top margin must be used together with page units.") << "\n";
365  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
366  }
367  }
368 
369  {
370  //just anonymous namespace ...don' like to have a,b,c,d everywhere defined
371  bool a = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BOTTOM_MARGIN)));
372  bool b = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)));
373 
374  if ((a || b) && !(a && b))
375  {
376  qCritical() << translate("VCommandLine", "Bottom margin must be used together with page units.") << "\n";
377  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
378  }
379  }
380 
381  const int rotateDegree = OptRotation();
382  diag.SetRotate(rotateDegree != 0 ); // 0 disable rotation
383 
384  if (rotateDegree != VSettings::GetDefLayoutRotationIncrease())//Value by default
385  {
386  if (not diag.SetIncrease(rotateDegree))
387  {
388  qCritical() << translate("VCommandLine", "Invalid rotation value. That must be one of predefined values.")
389  << "\n";
390  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
391  }
392  }
393 
394  // if present units MUST be set before any other to keep conversions correct
395  if (!diag.SelectTemplate(OptPaperSize()))
396  {
397  qCritical() << translate("VCommandLine", "Unknown page templated selected.") << "\n";
398  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
399  }
400 
401  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))))
402  { //at this point we already sure 3 are set or none
403 
404  if (!diag.SelectPaperUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEUNITS)))))
405  {
406  qCritical() << translate("VCommandLine", "Unsupported paper units.") << "\n";
407  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
408  }
409 
410  diag.SetPaperHeight (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEH))), diag));
411  diag.SetPaperWidth (Pg2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGEW))), diag));
412  }
413 
414  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS))))
415  {
416  if (!diag.SelectLayoutUnit(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTUNITS)))))
417  {
418  qCritical() << translate("VCommandLine", "Unsupported layout units.") << "\n";
419  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
420  }
421  }
422 
423  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))))
424  {
425 
426  diag.SetShift(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_SHIFTLENGTH))), diag));
427  }
428 
429  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))))
430  {
431  diag.SetLayoutWidth(Lo2Px(parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GAPWIDTH))), diag));
432  }
433 
434  diag.SetAutoCrop(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_CROP))));
435  diag.SetUnitePages(parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_UNITE))));
437  diag.SetGroup(OptGroup());
438 
439  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_IGNORE_MARGINS))))
440  {
441  diag.SetIgnoreAllFields(true);
442  }
443  else
444  {
445  QMarginsF margins = diag.GetFields();
446 
447  {
448  const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_LEFT_MARGIN));
449  if (parser.isSet(*option))
450  {
451  margins.setLeft(Pg2Px(parser.value(*option), diag));
452  }
453  }
454 
455  {
456  const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_RIGHT_MARGIN));
457  if (parser.isSet(*option))
458  {
459  margins.setRight(Pg2Px(parser.value(*option), diag));
460  }
461  }
462 
463  {
464  const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_TOP_MARGIN));
465  if (parser.isSet(*option))
466  {
467  margins.setTop(Pg2Px(parser.value(*option), diag));
468  }
469  }
470 
471  {
472  const QCommandLineOption *option = optionsUsed.value(optionsIndex.value(LONG_OPTION_BOTTOM_MARGIN));
473  if (parser.isSet(*option))
474  {
475  margins.setBottom(Pg2Px(parser.value(*option), diag));
476  }
477  }
478  diag.SetFields(margins);
479  }
480 
481  diag.DialogAccepted(); // filling VLayoutGenerator
482 
483  return res;
484 }
485 
486 //------------------------------------------------------------------------------------------------------
487 VCommandLinePtr VCommandLine::Get(const QCoreApplication& app)
488 {
489  if (instance == nullptr)
490  {
491  instance.reset(new VCommandLine());
492  }
493  instance->parser.process(app);
494 
495  //fixme: in case of additional options/modes which will need to disable GUI - add it here too
496  instance->isGuiEnabled = not (instance->IsExportEnabled() || instance->IsTestModeEnabled());
497 
498  return instance;
499 }
500 
501 //---------------------------------------------------------------------------------------------------------------------
503 {
504  qDeleteAll(optionsUsed.begin(), optionsUsed.end());
505  optionsUsed.clear();
506 }
507 
508 //------------------------------------------------------------------------------------------------------
510 {
511  instance.reset();
512 }
513 
514 //---------------------------------------------------------------------------------------------------------------------
516 {
517  const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TEST)));
518  if (r && parser.positionalArguments().size() != 1)
519  {
520  qCritical() << translate("VCommandLine", "Test option can be used with single input file only.") << "/n";
521  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
522  }
523  return r;
524 }
525 
526 //---------------------------------------------------------------------------------------------------------------------
528 {
529  return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_NO_HDPI_SCALING)));
530 }
531 
532 //---------------------------------------------------------------------------------------------------------------------
534 {
535  const bool r = parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME)));
536  if (r && parser.positionalArguments().size() != 1)
537  {
538  qCritical() << translate("VCommandLine", "Export options can be used with single input file only.") << "/n";
539  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
540  }
541  return r;
542 }
543 
544 //------------------------------------------------------------------------------------------------------
546 {
547  int ppsize = 0;
548  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))))
549  {
550  ppsize = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_PAGETEMPLATE))).toInt();
551  }
552  return static_cast<DialogLayoutSettings::PaperSizeTemplate>(ppsize);
553 }
554 
555 //------------------------------------------------------------------------------------------------------
557 {
559  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE))))
560  {
561  bool ok = false;
562  rotate = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_ROTATE))).toInt(&ok);
563 
564  if (not ok)
565  {
567  }
568  }
569 
570  return rotate;
571 }
572 
573 //------------------------------------------------------------------------------------------------------
575 {
576  int r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GROUPPING))).toInt();
577  if ( r < 0 || r >= static_cast<int>(Cases::UnknownCase))
578  {
579  r = 0;
580  }
581  return static_cast<Cases>(r);
582 }
583 
584 //------------------------------------------------------------------------------------------------------
586 {
587  QString measure;
588  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE)))
590  //todo: don't want yet to allow user set measure file for general loading,
591  //because need to fix multiply opened windows as well
592  {
593  measure = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_MEASUREFILE)));
594  }
595 
596  return measure;
597 }
598 
599 //---------------------------------------------------------------------------------------------------------------------
601 {
602  QString path;
603  if (IsExportEnabled())
604  {
605  path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BASENAME)));
606  }
607 
608  return path;
609 }
610 
611 //---------------------------------------------------------------------------------------------------------------------
613 {
614  QString path;
615  if (IsExportEnabled())
616  {
617  path = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_DESTINATION)));
618  }
619 
620  return path;
621 }
622 
623 //---------------------------------------------------------------------------------------------------------------------
625 {
626  int r = 0;
627  if (parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT))))
628  {
629  r = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXP2FORMAT))).toInt();
630  }
631  return r;
632 }
633 
634 //---------------------------------------------------------------------------------------------------------------------
636 {
637  return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BINARYDXF)));
638 }
639 
640 //---------------------------------------------------------------------------------------------------------------------
642 {
643  return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TEXT2PATHS)));
644 }
645 
646 //---------------------------------------------------------------------------------------------------------------------
648 {
649  return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_EXPORTONLYDETAILS)));
650 }
651 
652 //---------------------------------------------------------------------------------------------------------------------
654 {
655  return parser.positionalArguments();
656 }
657 
658 //---------------------------------------------------------------------------------------------------------------------
660 {
661  return isGuiEnabled;
662 }
663 
664 //---------------------------------------------------------------------------------------------------------------------
666 {
667  return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE)));
668 }
669 
670 //---------------------------------------------------------------------------------------------------------------------
672 {
673  return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT)));
674 }
675 
676 //---------------------------------------------------------------------------------------------------------------------
678 {
679  const QString size = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONSIZE)));
681  {
682  return size;
683  }
684  else
685  {
686  qCritical() << translate("VCommandLine", "Invalid gradation size value.") << "\n";
687  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
688  }
689 }
690 
691 //---------------------------------------------------------------------------------------------------------------------
693 {
694  const QString height = parser.value(*optionsUsed.value(optionsIndex.value(LONG_OPTION_GRADATIONHEIGHT)));
696  {
697  return height;
698  }
699  else
700  {
701  qCritical() << translate("VCommandLine", "Invalid gradation height value.") << "\n";
702  const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
703  }
704 }
705 
706 #undef translate
qreal PageToPixels(qreal value) const
bool SelectLayoutUnit(const QString &units)
void SetGroup(const Cases &value)
qreal LayoutToPixels(qreal value) const
void SetIgnoreAllFields(bool value)
void SetAutoCrop(bool autoCrop)
static QString MakeHelpTemplateList()
static QString MakeGroupsHelp()
void SetLayoutWidth(qreal value)
bool SelectPaperUnit(const QString &units)
bool SetIncrease(int increase)
void SetPaperHeight(qreal value)
void SetFields(const QMarginsF &value)
bool SelectTemplate(const PaperSizeTemplate &id)
void SetPaperWidth(qreal value)
static QString makeHelpFormatList()
VCommandLineOptions optionsUsed
Definition: vcmdexport.h:118
QString OptDestinationPath() const
Definition: vcmdexport.cpp:612
int OptRotation() const
Definition: vcmdexport.cpp:556
bool IsTestModeEnabled() const
Definition: vcmdexport.cpp:515
static void InitOptions(VCommandLineOptions &options, QMap< QString, int > &optionsIndex)
Definition: vcmdexport.cpp:74
QString OptGradationHeight() const
Definition: vcmdexport.cpp:692
Cases OptGroup() const
Definition: vcmdexport.cpp:574
QStringList OptInputFileNames() const
Definition: vcmdexport.cpp:653
bool isGuiEnabled
Definition: vcmdexport.h:120
static void Reset()
Definition: vcmdexport.cpp:509
static VCommandLinePtr instance
Definition: vcmdexport.h:116
QCommandLineParser parser
Definition: vcmdexport.h:117
int exportOnlyPieces() const
Definition: vcmdexport.cpp:647
QString OptBaseName() const
Definition: vcmdexport.cpp:600
bool IsExportEnabled() const
Definition: vcmdexport.cpp:533
int IsBinaryDXF() const
Definition: vcmdexport.cpp:635
DialogLayoutSettings::PaperSizeTemplate OptPaperSize() const
Definition: vcmdexport.cpp:545
int isTextAsPaths() const
Definition: vcmdexport.cpp:641
QString OptMeasurePath() const
Definition: vcmdexport.cpp:585
bool IsNoScalingEnabled() const
Definition: vcmdexport.cpp:527
static VCommandLinePtr Get(const QCoreApplication &app)
Definition: vcmdexport.cpp:487
VLayoutGeneratorPtr DefaultGenerator() const
Definition: vcmdexport.cpp:278
static qreal Lo2Px(const QString &src, const DialogLayoutSettings &converter)
Definition: vcmdexport.cpp:62
virtual ~VCommandLine()
Definition: vcmdexport.cpp:502
bool IsSetGradationHeight() const
Definition: vcmdexport.cpp:671
bool IsGuiEnabled() const
Definition: vcmdexport.cpp:659
static qreal Pg2Px(const QString &src, const DialogLayoutSettings &converter)
Definition: vcmdexport.cpp:68
QString OptGradationSize() const
Definition: vcmdexport.cpp:677
bool IsSetGradationSize() const
Definition: vcmdexport.cpp:665
QMap< QString, int > optionsIndex
Definition: vcmdexport.h:119
int OptExportType() const
Definition: vcmdexport.cpp:624
static QString UnitsHelpString()
static QStringList WholeListSizes(Unit patternUnit)
static QStringList WholeListHeights(Unit patternUnit)
static bool IsGradationSizeValid(const QString &size)
static bool IsGradationHeightValid(const QString &height)
static int GetDefLayoutRotationIncrease()
Definition: vsettings.cpp:501
const QString SINGLE_OPTION_LEFT_MARGIN
const QString LONG_OPTION_PAGEH
const QString LONG_OPTION_EXP2FORMAT
const QString LONG_OPTION_LEFT_MARGIN
const QString LONG_OPTION_RIGHT_MARGIN
const QString SINGLE_OPTION_ROTATE
const QString SINGLE_OPTION_BASENAME
const QString SINGLE_OPTION_GAPWIDTH
const QString SINGLE_OPTION_RIGHT_MARGIN
const QString LONG_OPTION_GROUPPING
const QString SINGLE_OPTION_EXP2FORMAT
const QString LONG_OPTION_SAVELENGTH
const QString SINGLE_OPTION_CROP
const QString SINGLE_OPTION_SAVELENGTH
const QString LONG_OPTION_TEST
const QString SINGLE_OPTION_PAGEH
const QString SINGLE_OPTION_SHIFTUNITS
const QString LONG_OPTION_BINARYDXF
const QString LONG_OPTION_TOP_MARGIN
const QString SINGLE_OPTION_PAGEW
const QString SINGLE_OPTION_BOTTOM_MARGIN
const QString SINGLE_OPTION_PAGETEMPLATE
const QString LONG_OPTION_BOTTOM_MARGIN
const QString LONG_OPTION_EXPORTONLYDETAILS
const QString LONG_OPTION_BASENAME
const QString LONG_OPTION_PAGETEMPLATE
const QString SINGLE_OPTION_TOP_MARGIN
const QString LONG_OPTION_CROP
const QString LONG_OPTION_PAGEUNITS
const QString LONG_OPTION_ROTATE
const QString LONG_OPTION_SHIFTUNITS
const QString LONG_OPTION_GRADATIONSIZE
const QString LONG_OPTION_GAPWIDTH
const QString LONG_OPTION_SHIFTLENGTH
const QString SINGLE_OPTION_GROUPPING
const QString SINGLE_OPTION_UNITE
const QString LONG_OPTION_UNITE
const QString SINGLE_OPTION_IGNORE_MARGINS
const QString SINGLE_OPTION_TEST
const QString SINGLE_OPTION_PAGEUNITS
const QString LONG_OPTION_GRADATIONHEIGHT
const QString SINGLE_OPTION_GRADATIONHEIGHT
const QString LONG_OPTION_MEASUREFILE
const QString SINGLE_OPTION_DESTINATION
const QString LONG_OPTION_TEXT2PATHS
const QString LONG_OPTION_IGNORE_MARGINS
const QString SINGLE_OPTION_GRADATIONSIZE
const QString LONG_OPTION_DESTINATION
const QString SINGLE_OPTION_MEASUREFILE
const QString LONG_OPTION_PAGEW
const QString SINGLE_OPTION_SHIFTLENGTH
const QString LONG_OPTION_NO_HDPI_SCALING
Definition: def.cpp:535
Cases
Definition: vbank.h:71
@ UnknownCase
#define translate(context, source)
Definition: vcmdexport.cpp:41
std::shared_ptr< VLayoutGenerator > VLayoutGeneratorPtr
Definition: vcmdexport.h:44
std::shared_ptr< VCommandLine > VCommandLinePtr
Definition: vcmdexport.h:41
static const auto V_EX_USAGE
Definition: vsysexits.h:65