1 /**
2  * Mandelbulber v2, a 3D fractal generator       ,=#MKNmMMKmmßMNWy,
3  *                                             ,B" ]L,,p%%%,,,§;, "K
4  * Copyright (C) 2015-20 Mandelbulber Team     §R-==%w["'~5]m%=L.=~5N
5  *                                        ,=mm=§M ]=4 yJKA"/-Nsaj  "Bw,==,,
6  * This file is part of Mandelbulber.    §R.r= jw",M  Km .mM  FW ",§=ß., ,TN
7  *                                     ,4R =%["w[N=7]J '"5=],""]]M,w,-; T=]M
8  * Mandelbulber is free software:     §R.ß~-Q/M=,=5"v"]=Qf,'§"M= =,M.§ Rz]M"Kw
9  * you can redistribute it and/or     §w "xDY.J ' -"m=====WeC=\ ""%""y=%"]"" §
10  * modify it under the terms of the    "§M=M =D=4"N #"%==A%p M§ M6  R' #"=~.4M
11  * GNU General Public License as        §W =, ][T"]C  §  § '§ e===~ U  !§[Z ]N
12  * published by the                    4M",,Jm=,"=e~  §  §  j]]""N  BmM"py=ßM
13  * Free Software Foundation,          ]§ T,M=& 'YmMMpM9MMM%=w=,,=MT]M m§;'§,
14  * either version 3 of the License,    TWw [.j"5=~N[=§%=%W,T ]R,"=="Y[LFT ]N
15  * or (at your option)                   TW=,-#"%=;[  =Q:["V""  ],,M.m == ]N
16  * any later version.                      J§"mr"] ,=,," =="""J]= M"M"]==ß"
17  *                                          §= "=C=4 §"eM "=B:m|4"]#F,§~
18  * Mandelbulber is distributed in            "9w=,,]w em%wJ '"~" ,=,,ß"
19  * the hope that it will be useful,                 . "K=  ,=RMMMßM"""
20  * but WITHOUT ANY WARRANTY;                            .'''
21  * without even the implied warranty
22  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * See the GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with Mandelbulber. If not, see <http://www.gnu.org/licenses/>.
27  *
28  * ###########################################################################
29  *
30  * Authors: Krzysztof Marczak (buddhi1980@gmail.com), Sebastian Jennen (jenzebas@gmail.com)
31  *
32  * cCommandLineInterface - CLI Input handler
33  */
34 
35 #ifndef MANDELBULBER2_SRC_COMMAND_LINE_INTERFACE_HPP_
36 #define MANDELBULBER2_SRC_COMMAND_LINE_INTERFACE_HPP_
37 
38 #include <QCommandLineParser>
39 #include <QString>
40 
41 class QCoreApplication;
42 
43 class cCommandLineInterface
44 {
45 public:
46 	cCommandLineInterface(QCoreApplication *qApplication);
47 	~cCommandLineInterface();
48 
49 	enum cliOperationalMode
50 	{
51 		modeBootOnly,
52 		modeNetrender,
53 		modeKeyframe,
54 		modeFlight,
55 		modeStill,
56 		modeQueue,
57 		modeVoxel
58 	};
59 	enum cliErrors
60 	{
61 		cliErrorServerInvalidPort = -10,
62 		cliErrorClientInvalidPort = -11,
63 		cliErrorQueueInit = -12,
64 		cliErrorLoadSettingsFile = -13,
65 		cliErrorResolutionInvalid = -14,
66 		cliErrorFPKInvalid = -15,
67 		cliErrorImageFileFormatInvalid = -16,
68 		cliErrorSettingsFileNotSpecified = -17,
69 
70 		cliErrorFlightNoFrames = -30,
71 		cliErrorFlightStartFrameOutOfRange = -31,
72 		cliErrorFlightEndFrameSmallerStartFrame = -32,
73 		cliErrorFlightEndFrameOutOfRange = -33,
74 
75 		cliErrorKeyframeNoFrames = -40,
76 		cliErrorKeyframeStartFrameOutOfRange = -41,
77 		cliErrorKeyframeEndFrameSmallerStartFrame = -42,
78 		cliErrorKeyframeEndFrameOutOfRange = -43,
79 
80 		cliErrorVoxelOutputFolderDoesNotExists = -50,
81 		cliErrorVoxelOutputFormatInvalid = -51,
82 
83 		cliErrorBenchmarkOutputFolderInvalid = -60,
84 
85 		cliErrorOpenClNotCompiled = -70,
86 		cliErrorOpenClNoPlatform = -71,
87 		cliErrorOpenClNoDevice = -72
88 	};
89 
90 	void ReadCLI();
91 	void ProcessCLI() const;
isNoGUI() const92 	bool isNoGUI() const { return cliData.nogui; }
93 
94 private:
95 	// ## helper methods for ReadCLI
96 	// arguments to cause print and exit
97 	[[noreturn]] static void printExampleHelpAndExit();
98 	[[noreturn]] static void printInputHelpAndExit();
99 	[[noreturn]] void printOpenCLHelpAndExit();
100 	[[noreturn]] static void printParametersAndExit();
101 	[[noreturn]] static void runTestCasesAndExit();
102 	[[noreturn]] void runBenchmarksAndExit();
103 
104 	// argument handling methods
105 	void handleServer();
106 	void handleClient();
107 	void handleQueue();
108 	void handleArgs();
109 	void handleOverrideParameters() const;
110 	void handleResolution();
111 	void handleFpk();
112 	void handleImageFileFormat();
113 	void handleFlight();
114 	void handleKeyframe();
115 	void handleStartFrame();
116 	void handleEndFrame();
117 	void handleVoxel();
118 	void handleGpu();
119 	void handleGpuAll();
120 
121 	struct sCliData
122 	{
123 		bool nogui;
124 		bool server;
125 		bool listParameters;
126 		bool showInputHelp;
127 		bool showExampleHelp;
128 		bool showOpenCLHelp;
129 		bool keyframe;
130 		bool flight;
131 		bool silent;
132 		bool queue;
133 		bool voxel;
134 		bool test;
135 		bool benchmark;
136 		bool touch;
137 		bool gpu;
138 		bool gpuAll;
139 		QString startFrameText;
140 		QString endFrameText;
141 		QString overrideParametersText;
142 		QString imageFileFormat;
143 		QString resolution;
144 		QString fpkText;
145 		QString host;
146 		QString portText;
147 		QString outputText;
148 		QString voxelFormat;
149 		QString logFilepathText;
150 	} cliData;
151 
152 	QCommandLineParser parser;
153 	QStringList args;
154 	cliOperationalMode cliOperationalMode;
155 	bool settingsSpecified;
156 	QCoreApplication *qApplication;
157 };
158 
159 #endif /* MANDELBULBER2_SRC_COMMAND_LINE_INTERFACE_HPP_ */
160