-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
160 lines (143 loc) · 5.32 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright (c) 2022-2024 plc-user
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//
// QET_ElementScaler is a commandline-tool to scale
// QElectroTech-Graphics and/or converts them to
// Scalable Vector-Graphics.
//
// usage:
// QET_ElementScaler [options] <file>
//
// compiles with C++17 enabled on
// - Debian/GNU Linux (unstable)
// - ReactOS (0.4.15-dev-6811)
// - win
// - ???
// (see compile.sh and/or compile.cmd)
//
// Change(s) for 0.5.0beta1
// - most of the source code has been rewritten
// - added ability to export SVG-data
// - adjusted order of commandline-parameters: see --help
//
// +----------------------------------------------------------+
// | This software uses pugixml library (https://pugixml.org) |
// | pugixml is Copyright (C) 2006-2023 Arseny Kapoulkine. |
// +----------------------------------------------------------+
//
// own headers:
#include "inc/pugixml/pugixml.hpp"
#include "inc/helpers.h"
#include "inc/elements.h"
#include "main.h"
// ============================================================================
// implementation
// ============================================================================
int main(int argc, char **argv)
{
// read and check the Commandline-Parameters
int iRetVal = parseCommandline(argc, argv);
if (_DEBUG_) std::cerr << "iRetVal: " << iRetVal << std::endl;
if (xPrintHelp == true) {
PrintHelp(argv[0], sVersion);
return 0;
}
if (xStopWithError == true) {
std::cerr << "check options and try again!" << std::endl;
return -1;
}
// load Element from stdin or XML-File
pugi::xml_document doc;
pugi::xml_parse_result result;
if (xReadFromStdIn){
result = doc.load(std::cin);
} else {
if ((ElementFile != "") && (std::filesystem::exists(ElementFile))) {
//ElementFile = argv[1];
result = doc.load_file(ElementFile.c_str());
} else
if ((argc>1)&&(std::filesystem::exists(argv[argc-1]))) {
ElementFile = argv[argc-1];
result = doc.load_file(ElementFile.c_str());
} else
{
PrintHelp(argv[0], sVersion);
return -1;
}
}
// check the result of "doc.load"-Function
if (!result){
std::cerr << "file \"" << ElementFile << "\" could not be loaded: " << result.description() << std::endl;
return -1;
} else {
if (_DEBUG_) std::cerr << "Element-File loaded successfully.\n";
}
// build the filename for the scaled element:
ElementFileScaled = ElementFile;
if (xOverwriteOriginal == true){
std::cerr << "will overwrite original file!" << std::endl;
} else {
ElementFileScaled.insert(ElementFileScaled.length()-5, ".SCALED");
}
if (_DEBUG_) std::cerr << ElementFileScaled << std::endl;
// Process the Element-file: scale, flip, etc...
ProcessElement(doc);
if (xCreateSVG == true) {
// SVG-Daten erstellen
std::string s = ToSVG(doc);
if (xPrintToStdOut == true) {
// zur Standard-Ausgabe:
std::cout << s << "\n\n";
}
else {
// Dateinamen erstellen und SVG speichern
SVGFile = ElementFile+".svg";
std::ofstream out;
out.open(SVGFile, std::ios::out);
out << s << "\n";
out.close();
}
return 0;
}
if (xCreateELMT == true) {
if (xPrintToStdOut==true){
if (_DEBUG_) std::cerr << "XML auf stdout ------------------------------------------------------" << std::endl;
doc.save(std::cout, " ", pugi::format_default | pugi::format_no_declaration);
// no result from "doc.save" when sending XML to cout ...
if (_DEBUG_) std::cerr << "XML auf stdout ------------------------------------------------------" << std::endl;
return 0;
} else {
// we try to save the new XML:
if (doc.save_file(ElementFileScaled.c_str(), " ", pugi::format_default | pugi::format_no_declaration) == true){
if (_DEBUG_) std::cerr << "file \"" << ElementFileScaled << "\" saved successfully!" << std::endl;
return 0;
} else {
std::cerr << "file \"" << ElementFileScaled << "\" could not be saved!" << std::endl;
return -1;
}
}
}
return 0;
}