Developer Documentation
Loading...
Searching...
No Matches
CommandLineParser.cc
1
2#include "CommandLineParser.hh"
3#include <iostream>
5#include <OpenFlipper/BasePlugin/PluginFunctionsCore.hh>
6
7
8// Parse all options
9CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *errorMessage) {
10
11 #ifndef WIN32
12 #ifndef __APPLE__
13 //workaround for bug with stereo mode on Qt5.7.0 and Qt5.7.1 on Linux
14 int QtVersionMajor, QtVersionMinor, QtVersionPatch;
15 if(sscanf(qVersion(),"%1d.%1d.%1d",&QtVersionMajor, &QtVersionMinor, &QtVersionPatch) == 3)
16 {
17 if(QtVersionMajor == 5 && QtVersionMinor >= 7)
18 {
19 if(QtVersionPatch < 2)
20 {
21 std::cerr << "The used Qt Version does not support stereo mode. Disabling stereo mode." << std::endl;
22 OpenFlipper::Options::stereo(false);
23 }
24 else
25 std::cerr << "Stereo Mode has not been tested for the used Qt Version." << std::endl;
26 }
27 }
28 #endif
29 #endif
30
31
32 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
33
34
35 QCommandLineOption debugOption(QStringList() << "d" << "debug",QCoreApplication::translate("main", "Enable debugging mode"));
36 parser.addOption(debugOption);
37
38 QCommandLineOption stereoOption("disable-stereo",QCoreApplication::translate("main", "Disable stereo mode"));
39 parser.addOption(stereoOption);
40
41 QCommandLineOption batchOption(QStringList() << "b" << "batch",QCoreApplication::translate("main", "Batch mode, you have to provide a script for execution"));
42 parser.addOption(batchOption);
43
44 QCommandLineOption logConsoleOption(QStringList() << "c" << "log-to-console",QCoreApplication::translate("main", "Write logger window contents to console"));
45 parser.addOption(logConsoleOption);
46
47 QCommandLineOption remoteControlOption("remote-control",QCoreApplication::translate("main", "Batch mode accepting remote connections"));
48 parser.addOption(remoteControlOption);
49
50 QCommandLineOption fulscreenOption(QStringList() << "f" << "fullscreen",QCoreApplication::translate("main", "Start in fullscreen mode"));
51 parser.addOption(fulscreenOption);
52
53 QCommandLineOption hideLoggerOption(QStringList() << "l" << "hide-logger",QCoreApplication::translate("main", "Start with hidden log window"));
54 parser.addOption(hideLoggerOption);
55
56 QCommandLineOption hideToolboxOption(QStringList() << "t" << "hide-toolbox",QCoreApplication::translate("main", "Start with hidden toolbox"));
57 parser.addOption(hideToolboxOption);
58
59 QCommandLineOption noSplashOption("no-splash",QCoreApplication::translate("main", "Hide splash screen"));
60 parser.addOption(noSplashOption);
61
62 QCommandLineOption polyMeshOption("p",QCoreApplication::translate("main", "Open files as PolyMeshes"));
63 parser.addOption(polyMeshOption);
64
65 QCommandLineOption remotePortOption("remote-port",QCoreApplication::translate("main", "Remote port"),"portnumber");
66 parser.addOption(remotePortOption);
67
68 QCommandLineOption coreProfileOption("core-profile",QCoreApplication::translate("main", "OpenGL Core Profile Mode"));
69 parser.addOption(coreProfileOption);
70
71 QCommandLineOption glVersionOption("glVersion",QCoreApplication::translate("main","Request OpenGL version <major>.<minor> "),QCoreApplication::translate("main","< 1.0 | 1.1 | ... | 4.6 >"));
72 parser.addOption(glVersionOption);
73
74 QCommandLineOption samplesOption("samples",QCoreApplication::translate("main","Overwrite multisampling sample count"),QCoreApplication::translate("main","< 0 | 1 | 2 | ... | 16 >"));
75 parser.addOption(samplesOption);
76
77 QCommandLineOption glStereoOption("glStereo",QCoreApplication::translate("main","Overwrite OpenGL Stereo setting"),QCoreApplication::translate("main","< true | false >"));
78 parser.addOption(glStereoOption);
79
80 QCommandLineOption profileOption("profile",QCoreApplication::translate("main","Request OpenGL context profile <profile> with profile set as compat or core"),QCoreApplication::translate("main","< compat | core >"));
81 parser.addOption(profileOption);
82
83 QCommandLineOption pluginOptionsOption(QStringList() << "o" << "pluginoptions",QCoreApplication::translate("main", "Pass options to plugins"), "key1=value1;key2=value2;...");
84 parser.addOption(pluginOptionsOption);
85
86 const QCommandLineOption helpOption = parser.addHelpOption();
87 const QCommandLineOption versionOption = parser.addVersionOption();
88
89
90 // Now parse the command line
91 if (!parser.parse(QCoreApplication::arguments())) {
92 *errorMessage = parser.errorText();
93 return CommandLineError;
94 }
95
96 if (parser.isSet(helpOption))
97 return CommandLineHelpRequested;
98
99 if (parser.isSet(versionOption))
100 return CommandLineVersionRequested;
101
102 if (parser.isSet(debugOption)) {
103 OpenFlipper::Options::debug(true);
104 }
105
106 if (parser.isSet(stereoOption)) {
107 OpenFlipper::Options::stereo(false);
108 }
109
110 if (parser.isSet(batchOption)) {
111 OpenFlipper::Options::nogui(true);
112 }
113
114 if (parser.isSet(logConsoleOption)) {
115 OpenFlipper::Options::logToConsole(true);
116 }
117
118 if (parser.isSet(remoteControlOption)) {
119 OpenFlipper::Options::remoteControl(true);
120 }
121
122 if (parser.isSet(fulscreenOption)) {
123 OpenFlipperSettings().setValue("Core/Gui/fullscreen",true);
124 }
125
126 if (parser.isSet(hideLoggerOption)) {
127 OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
128 }
129
130 if (parser.isSet(hideToolboxOption)) {
131 OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",true);
132 }
133
134 if (parser.isSet(noSplashOption)) {
135 OpenFlipperSettings().setValue("Core/Gui/splash",false);
136 }
137
138 if (parser.isSet(polyMeshOption)) {
139 openPolyMeshes = true;
140 }
141
142 if (parser.isSet(remotePortOption)) {
143 const QString port = parser.value("remote-port");
144 std::cerr << "Got port option : " << port.toStdString() << std::endl;
145 OpenFlipper::Options::remoteControl(port.toInt());
146 }
147 if(parser.isSet("samples"))
148 OpenFlipper::Options::samples(parser.value("samples").toInt(),true);
149 if(parser.isSet("glVersion"))
150 {
151 QStringList values = parser.value("glVersion").split(".");
152 QPair<int,int> version(
153 values[0].toInt(),
154 values[1].toInt());
155 OpenFlipper::Options::glVersion(version,true);
156 }
157
158 if(parser.isSet("glStereo"))
159 OpenFlipper::Options::glStereo(parser.value("glStereo")=="true");
160
161 if(parser.value(profileOption)=="core")
162 {
163 OpenFlipper::Options::coreProfile(true, true);
164 }
165 else
166 {
167 if(parser.value(profileOption)=="compat")
168 {
169 OpenFlipper::Options::coreProfile(false, true);
170 }
171 }
172 if(parser.isSet(coreProfileOption)) {
173 OpenFlipper::Options::coreProfile(true, true);
174 }
175 if(parser.isSet(pluginOptionsOption))
176 {
177 QStringList poptions = parser.value(pluginOptionsOption).split(";");
178 QVector<QPair<QString, QString>> pcloptions;
179 for(auto s : poptions)
180 {
181 auto kvp = s.split("=");
182
183 // Only consider terms of the kind "key=value"
184 if(kvp.size() != 2u)
185 continue;
186
187 auto key = kvp[0];
188 auto value = kvp[1];
189 pcloptions.push_back({key, value});
190 }
192 }
193
194 return CommandLineOk;
195}
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void setPluginCommandLineOptions(const QVector< QPair< QString, QString > > &_pluginCommandLineOptions)