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 "lc_actionfileexportmakercam.h"
26 
27 #include <fstream>
28 
29 #include <QAction>
30 
31 #include "rs_dialogfactory.h"
32 #include "rs_graphic.h"
33 #include "lc_makercamsvg.h"
34 #include "rs_settings.h"
35 #include "lc_xmlwriterqxmlstreamwriter.h"
36 #include "rs_debug.h"
37 
LC_ActionFileExportMakerCam(RS_EntityContainer & container,RS_GraphicView & graphicView)38 LC_ActionFileExportMakerCam::LC_ActionFileExportMakerCam(RS_EntityContainer& container,
39                                                          RS_GraphicView& graphicView)
40     : RS_ActionInterface("Export as CAM/plain SVG...", container, graphicView) {}
41 
42 
init(int status)43 void LC_ActionFileExportMakerCam::init(int status) {
44 
45     RS_ActionInterface::init(status);
46     trigger();
47 }
48 
trigger()49 void LC_ActionFileExportMakerCam::trigger() {
50 
51 	RS_DEBUG->print("LC_ActionFileExportMakerCam::trigger()");
52 
53     if (graphic != NULL) {
54 
55         bool accepted = RS_DIALOGFACTORY->requestOptionsMakerCamDialog();
56 
57         if (accepted) {
58 
59             QString filename = RS_DIALOGFACTORY->requestFileSaveAsDialog(tr("Export as"),
60                                                                          "",
61                                                                          "Scalable Vector Graphics (*.svg)");
62 
63 			if (!filename.isEmpty()) {
64 
65                 RS_SETTINGS->beginGroup("/ExportMakerCam");
66 
67 				std::unique_ptr<LC_MakerCamSVG> generator(new LC_MakerCamSVG(new LC_XMLWriterQXmlStreamWriter(),
68                                                                (bool)RS_SETTINGS->readNumEntry("/ExportInvisibleLayers"),
69                                                                (bool)RS_SETTINGS->readNumEntry("/ExportConstructionLayers"),
70                                                                (bool)RS_SETTINGS->readNumEntry("/WriteBlocksInline"),
71                                                                (bool)RS_SETTINGS->readNumEntry("/ConvertEllipsesToBeziers"),
72                                                                (bool)RS_SETTINGS->readNumEntry("/ExportImages"),
73                                                                (bool)RS_SETTINGS->readNumEntry("/BakeDashDotLines"),
74                                                                (double)RS_SETTINGS->readEntry("/DefaultElementWidth").toDouble(),
75                                                                (double)RS_SETTINGS->readEntry("/DefaultDashLinePatternLength").toDouble())
76 														  );
77 
78                 RS_SETTINGS->endGroup();
79 
80                 if (generator->generate(graphic)) {
81 
82                     std::ofstream file;
83                     file.open(filename.toStdString());
84                     file << generator->resultAsString();
85                     file.close();
86                 }
87             }
88         }
89     }
90 
91     finish(false);
92 }
93