-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.cpp
More file actions
211 lines (194 loc) · 9.03 KB
/
main.cpp
File metadata and controls
211 lines (194 loc) · 9.03 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/***************************************************************************
main.cpp
------------------
begin : Thu Oct 25 2018
copyright : (C) 2018 by Thomas Lepoix
email : thomas.lepoix@protonmail.ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QApplication>
#include <iostream>
#include "data.hpp"
#include "converter.hpp"
#include "logger.hpp"
#include "mainwindow.hpp"
#include "version.hpp"
using namespace std;
#ifdef QRFL_UNITTEST
#define main not_main
#endif // QRFL_UNITTEST
//******************************************************************************
int main(int argc, char* argv[]) {
//variables
bool verbose=false;
bool gui=false;
Data data;
//argument parser
if(argc==1) {
gui=true;
} else {
for(int i=1;i<argc;i++) {
if(string(argv[i])=="-h" || string(argv[i])=="--help") {
cout << "Usage: " << argv[0] << " -i FILENAME.sch\n"
" " << argv[0] << " -i FILENAME.sch -f [.kicad_pcb|.kicad_mod|.lht|.svg]\n"
" " << argv[0] << " -i FILENAME.sch -f [.kicad_pcb|.kicad_mod|.lht|.svg] -o DIRNAME\n"
" " << argv[0] << " -G\n"
"\n"
" -h, --help Display this help and exit.\n"
" --version Display version information and exit.\n"
" -v, --verbose Verbose mode.\n"
" -G GUI mode (no arguments equals to -G).\n"
" -i FILENAME Use file as input schematic.\n"
" -o DIRNAME Use directory as output.\n"
" -f FORMAT Use format as output layout format.\n"
" FORMAT can be:\n"
" - .kicad_pcb : KiCad layout (default format)\n"
" - .kicad_mod : KiCad module\n"
" - .lht : pcb-rnd layout\n"
" - .m : OpenEMS Octave script\n"
" - .svg : SVG file\n"
" -n NETLIST Specify a netlist to use instead of calling Qucs to create it from the schematic.\n"
" Useful when Qucs is not installed, if you use QucsStudio for example.\n"
" -q, --qucs PATH Specify Qucs executable to call for netlist creation, otherwise qucs, then qucs-s will\n"
" be tried regarding system PATH variable. PATH can be either a relative or absolute path.\n"
" -s Export each substrate in a different file.\n"
" -b Export each block in a different file.\n"
" -k, --keep Keep temporary files.\n"
"\n"
" -e, --exclude STRING Exclude a component. Must be a component label.\n"
" -u, --use STRING Exclude all components except the used ones. Must be a component label.\n"
" --margin-factor INTEGER The distance between circuits and substrate edges.\n"
" is defined as a substrate height multiple. Default is 10.\n"
" --port-shift N X Y Translate a port. X grows to the right, Y grows to the bottom.\n"
" --port-size N L W Set a port size. L is in x axis, W in y axis.\n"
" Can be used with '--port-shift' to create designs such as\n"
" center fed patch antenna.\n"
" --oems-highres-div INTEGER OpenEMS high resolution mesh lambda divisor. Default is 200.\n"
" --oems-metalres-div INTEGER OpenEMS metal resolution mesh lambda divisor. Default is 60.\n"
" --oems-substres-div INTEGER OpenEMS substrate resolution mesh lambda divisor. Default is 30.\n"
" --oems-timeres INTEGER Number of timesteps before OpenEMS stops simulation. Default is 300000.\n"
" --oems-end-criteria STRING OpenEMS stops simulation when energy decayed to this value.\n"
" Should stay between 1e-3 (speed) and 1e-5 (precision). Default is 1e-4.\n"
" --oems-nf2ff-center STRING Set the OpenEMS far field center. Must be a component label.\n"
" --oems-sort-metalresmesh Order metal resolution mesh lines by edge coordinate.\n"
" Default is grouped by component label.\n"
" --oems-pkg Look for 'openems' and 'csxcad' Octave packages (from Debian 10 repository).\n";
return(0);
} else if(string(argv[i])=="--version") {
cout << "Qucs-RFlayout " << VERSION << endl;
return(0);
} else if(string(argv[i])=="-i" && argv[i+1]) {
i++;
data.n_sch=string(argv[i]);
} else if(string(argv[i])=="-o" && argv[i+1]) {
i++;
data.out_dir=string(argv[i]);
} else if(string(argv[i])=="-f" && argv[i+1]) {
i++;
if(string(argv[i])==".kicad_pcb"
|| string(argv[i])==".kicad_mod"
|| string(argv[i])==".svg"
|| string(argv[i])==".lht"
|| string(argv[i])==".m") {
data.out_format=string(argv[i]);
} else {
log_err << "ERROR : Invalid output format : " << argv[i] << "\n";
return(1);
}
} else if(string(argv[i])=="-n" && argv[i+1]) {
i++;
data.n_net=string(argv[i]);
} else if((string(argv[i])=="-q" || string(argv[i])=="--qucs") && argv[i+1]) {
i++;
data.qucs_binary=string(argv[i]);
} else if(string(argv[i])=="-s") {
data.export_each_subst=true;
} else if(string(argv[i])=="-b") {
data.export_each_block=true;
} else if(string(argv[i])=="-k" || string(argv[i])=="--keep") {
data.keep_tmp_files=true;
} else if((string(argv[i])=="-e" || string(argv[i])=="--exclude") && argv[i+1]) {
i++;
data.excluded_elements.push_back(string(argv[i]));
} else if((string(argv[i])=="-u" || string(argv[i])=="--use") && argv[i+1]) {
i++;
data.used_elements.push_back(string(argv[i]));
} else if(string(argv[i])=="--margin-factor" && argv[i+1]) {
i++;
data.subst_margin_factor=atoi(argv[i]);
} else if(string(argv[i])=="--port-shift" && argv[i+1] && argv[i+2] && argv[i+3]) {
i++;
data.port_shift_args.push_back(make_tuple(stoul(string(argv[i])), string(argv[i+1]), string(argv[i+2])));
i+=2;
} else if(string(argv[i])=="--port-size" && argv[i+1] && argv[i+2] && argv[i+3]) {
i++;
data.port_size_args.push_back(make_tuple(stoul(string(argv[i])), string(argv[i+1]), string(argv[i+2])));
i+=2;
} else if(string(argv[i])=="--oems-highres-div" && argv[i+1]) {
i++;
data.oems_highres_div=atoi(argv[i]);
} else if(string(argv[i])=="--oems-metalres-div" && argv[i+1]) {
i++;
data.oems_metalres_div=atoi(argv[i]);
} else if(string(argv[i])=="--oems-substres-div" && argv[i+1]) {
i++;
data.oems_substres_div=atoi(argv[i]);
} else if(string(argv[i])=="--oems-timeres" && argv[i+1]) {
i++;
data.oems_timeres=atoi(argv[i]);
} else if(string(argv[i])=="--oems-end-criteria" && argv[i+1]) {
i++;
data.oems_end_criteria=string(argv[i]);
} else if(string(argv[i])=="--oems-nf2ff-center" && argv[i+1]) {
i++;
data.oems_nf2ff_center=string(argv[i]);
} else if(string(argv[i])=="--oems-sort-metalresmesh") {
data.oems_sort_metalresmesh=true;
} else if(string(argv[i])=="--oems-pkg") {
data.oems_pkg=true;
} else if(string(argv[i])=="-v" || string(argv[i])=="--verbose") {
verbose=true;
} else if(string(argv[i])=="-G") {
gui=true;
} else {
log_err << "ERROR : Unknown argument : " << argv[i] << "\n";
return(1);
}
}
}
if(!verbose) {
cout.rdbuf(nullptr);
}
if(gui) {
cout << "GUI mode\n";
QApplication a(argc, argv);
// Avoid a stold() bug introduced by QApplication() performing setlocale(LC_ALL, "")
setlocale(LC_NUMERIC, "C");
MainWindow w(data);
log_err.obj=&w;
log_err.set_mode(gui);
// log_err << "WARNING : GUI and circuit preview are not up to date yet, take a look at the command line. ;)\n";
w.show();
return(a.exec());
} else {
if(data.n_sch=="") {
log_err << "ERROR : Need an input file\n";
return(1);
}
Converter converter(data);
int ret=converter.run();
if(ret) return(ret);
cout << endl;
}
return(0);
}
#ifdef QRFL_UNITTEST
#undef main
#endif // QRFL_UNITTEST