1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2014 Christian Luginbühl (dinkel@pimprecords.com)
6 ** Copyright (C) 2018 Andrey Yaromenok (ayaromenok@gmail.com)
7 **
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License along
20 ** with this program; if not, write to the Free Software Foundation, Inc.,
21 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 **
23 **********************************************************************/
24 
25 #include "qg_dlgoptionsmakercam.h"
26 
27 #include "rs_settings.h"
28 
QG_DlgOptionsMakerCam(QWidget * parent,bool modal,Qt::WindowFlags fl)29 QG_DlgOptionsMakerCam::QG_DlgOptionsMakerCam(QWidget* parent, bool modal, Qt::WindowFlags fl) : QDialog(parent, fl)
30 {
31     setModal(modal);
32     setupUi(this);
33     this->gbLayers->setToolTip(tr("MakerCAM as of November 2014 does not hide SVG content \nthat has been set invisibe (\"display: none\" or \"visibility: hidden\")."));
34     this->gbBlocks->setToolTip(tr("MakerCAM as of November 2014 cannot correctly deal with blocks,\nbecause it does not take into account the reference point in the <use>."));
35     this->gbEllipses->setToolTip(tr("MakerCAM as of March 2015 cannot display ellipses and ellipse arcs correctly, \nwhen they are created using the <ellipse> tag  with a rotation in \nthe <transform> attribute or as <path> using elliptic arc segments."));
36     this->gbImages->setToolTip(tr("Exported images can be useful in SVG editors (Inkscape, etc), \nbut avoided in some CAM's."));
37     this->gbDashLines->setToolTip(tr("Many CAM's(MakerCAM, EleskCAM, LaserWeb) ignore dashed/doted line style, \nwhich can be useful in lasercut of plywood or for papercraft. "));
38     this->dSpinBoxDefaultElementWidth->setToolTip(tr("Default width of elements can affect some CAM's/SVG Editors, \nbut ignored by other"));
39     this->dSpinBoxDashLinePatternLength->setToolTip(tr("Length of line pattern related to zoom, \nso default step value required for baking"));
40 
41     loadSettings();
42 }
43 
languageChange()44 void QG_DlgOptionsMakerCam::languageChange()
45 {
46     retranslateUi(this);
47 }
48 
validate()49 void QG_DlgOptionsMakerCam::validate() {
50 
51     saveSettings();
52 
53     accept();
54 }
55 
cancel()56 void QG_DlgOptionsMakerCam::cancel() {
57     reject();
58 }
59 
loadSettings()60 void QG_DlgOptionsMakerCam::loadSettings() {
61 
62     RS_SETTINGS->beginGroup("/ExportMakerCam");
63 
64     updateCheckbox(checkInvisibleLayers, "ExportInvisibleLayers", 0);
65     updateCheckbox(checkConstructionLayers, "ExportConstructionLayers", 0);
66     updateCheckbox(checkBlocksInline, "WriteBlocksInline", 1);
67     updateCheckbox(checkEllipsesToBeziers, "ConvertEllipsesToBeziers", 1);
68     updateCheckbox(checkImages, "ExportImages", 0);
69     updateCheckbox(checkDashDotLines, "BakeDashDotLines", 0);
70     updateDoubleSpinBox(dSpinBoxDefaultElementWidth, "DefaultElementWidth", 1.0);
71     updateDoubleSpinBox(dSpinBoxDashLinePatternLength, "DefaultDashLinePatternLength", 2.5);
72     RS_SETTINGS->endGroup();
73 }
74 
updateCheckbox(QCheckBox * checkbox,QString name,int defaultValue)75 void QG_DlgOptionsMakerCam::updateCheckbox(QCheckBox* checkbox, QString name, int defaultValue) {
76 
77     checkbox->setChecked(RS_SETTINGS->readNumEntry("/" + name, defaultValue) ? true : false);
78 }
79 
updateDoubleSpinBox(QDoubleSpinBox * dSpinBox,QString name,double defaultValue)80 void QG_DlgOptionsMakerCam::updateDoubleSpinBox(QDoubleSpinBox* dSpinBox, QString name, double defaultValue) {
81 
82     dSpinBox->setValue(RS_SETTINGS->readEntry("/" + name, QString::number(defaultValue)).toDouble());
83 }
84 
saveSettings()85 void QG_DlgOptionsMakerCam::saveSettings() {
86 
87     RS_SETTINGS->beginGroup("/ExportMakerCam");
88 
89     saveBoolean("ExportInvisibleLayers", checkInvisibleLayers);
90     saveBoolean("ExportConstructionLayers", checkConstructionLayers);
91     saveBoolean("WriteBlocksInline", checkBlocksInline);
92     saveBoolean("ConvertEllipsesToBeziers", checkEllipsesToBeziers);
93     saveBoolean("ExportImages", checkImages);
94     saveBoolean("BakeDashDotLines", checkDashDotLines);
95     saveDouble("DefaultElementWidth", dSpinBoxDefaultElementWidth);
96     saveDouble("DefaultDashLinePatternLength", dSpinBoxDashLinePatternLength);
97 
98     RS_SETTINGS->endGroup();
99 }
100 
saveBoolean(QString name,QCheckBox * checkbox)101 void QG_DlgOptionsMakerCam::saveBoolean(QString name, QCheckBox* checkbox) {
102 
103     RS_SETTINGS->writeEntry("/" + name, checkbox->isChecked() ? 1 : 0);
104 }
105 
saveDouble(QString name,QDoubleSpinBox * dSpinBox)106 void QG_DlgOptionsMakerCam::saveDouble(QString name, QDoubleSpinBox* dSpinBox) {
107     RS_SETTINGS->writeEntry("/" + name, dSpinBox->value());
108 }
109