1 |
|
|
// Copyright (c) 2015-2018, LAAS-CNRS |
2 |
|
|
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) |
3 |
|
|
// |
4 |
|
|
// This file is part of gepetto-viewer. |
5 |
|
|
// gepetto-viewer is free software: you can redistribute it |
6 |
|
|
// and/or modify it under the terms of the GNU Lesser General Public |
7 |
|
|
// License as published by the Free Software Foundation, either version |
8 |
|
|
// 3 of the License, or (at your option) any later version. |
9 |
|
|
// |
10 |
|
|
// gepetto-viewer is distributed in the hope that it will be |
11 |
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
12 |
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 |
|
|
// General Lesser Public License for more details. You should have |
14 |
|
|
// received a copy of the GNU Lesser General Public License along with |
15 |
|
|
// gepetto-viewer. If not, see <http://www.gnu.org/licenses/>. |
16 |
|
|
|
17 |
|
|
#ifndef GEPETTO_GUI_SETTINGS_HH |
18 |
|
|
#define GEPETTO_GUI_SETTINGS_HH |
19 |
|
|
|
20 |
|
|
#include <ostream> |
21 |
|
|
#include <string> |
22 |
|
|
#include <QString> |
23 |
|
|
#include <QStringList> |
24 |
|
|
|
25 |
|
|
#include <gepetto/gui/dialog/pluginmanagerdialog.hh> |
26 |
|
|
|
27 |
|
|
namespace gepetto { |
28 |
|
|
namespace gui { |
29 |
|
|
class MainWindow; |
30 |
|
|
|
31 |
|
|
/// Settings manager for the interface. |
32 |
|
|
/// |
33 |
|
|
/// This struct is responsible for parsing configuration files as follow: |
34 |
|
|
/// - Robots file: Settings::readRobotFile() |
35 |
|
|
/// - Environments file: Settings::readEnvFile() |
36 |
|
|
/// - Configuration file: Settings::readSettingFile() |
37 |
|
|
struct Settings { |
38 |
|
|
std::string configurationFile; |
39 |
|
|
std::string predifinedRobotConf; |
40 |
|
|
std::string predifinedEnvConf; |
41 |
|
|
std::string stateConf; |
42 |
|
|
|
43 |
|
|
std::string logFile; |
44 |
|
|
|
45 |
|
|
bool verbose; |
46 |
|
|
bool noPlugin; |
47 |
|
|
bool autoWriteSettings; |
48 |
|
|
bool useNameService; |
49 |
|
|
|
50 |
|
|
int refreshRate; |
51 |
|
|
|
52 |
|
|
/// Path to avconv binary (maybe ffmpeg on some distributions). |
53 |
|
|
std::string captureDirectory, captureFilename, captureExtension; |
54 |
|
|
|
55 |
|
|
/// \group record_parameter Video generation parameters |
56 |
|
|
/// \{ |
57 |
|
|
QString avconv; |
58 |
|
|
QStringList avConvInputOptions; |
59 |
|
|
QStringList avConvOutputOptions; |
60 |
|
|
/// \} |
61 |
|
|
|
62 |
|
|
QString installDirectory; |
63 |
|
|
|
64 |
|
|
QString appStyle; |
65 |
|
|
|
66 |
|
|
/// Set up default values |
67 |
|
|
Settings (const char* installDirectory); |
68 |
|
|
|
69 |
|
|
/// Setup paths to find setting files and plugins. |
70 |
|
|
/// \note The environment variable |
71 |
|
|
/// GEPETTO_GUI_PLUGIN_DIRS, LD_LIBRARY_PATH |
72 |
|
|
/// and GEPETTO_GUI_SETTINGS_DIR are read. |
73 |
|
|
void setupPaths () const; |
74 |
|
|
|
75 |
|
|
/// Get the filename of a configuration file. |
76 |
|
|
QString getQSettingsFileName (const std::string& settingsName) const; |
77 |
|
|
|
78 |
|
|
/// Initialize the settings. |
79 |
|
|
/// It uses the following elements, in this order: |
80 |
|
|
/// \li read config file names from command line. |
81 |
|
|
/// \li read config files. |
82 |
|
|
/// \li read other command line arguments. |
83 |
|
|
/// \return \li 0 if no error, |
84 |
|
|
/// \li 1 if no error and the user requested to generate config |
85 |
|
|
/// files or to print the help, |
86 |
|
|
/// \li 2 in case of error. |
87 |
|
|
int initSettings (int argc, char * argv[]); |
88 |
|
|
|
89 |
|
|
/// Update settings from setting files |
90 |
|
|
void fromFiles (); |
91 |
|
|
|
92 |
|
|
/// Write the settings to configuration files |
93 |
|
|
void writeSettings (); |
94 |
|
|
|
95 |
|
|
/// Get a setting |
96 |
|
|
QVariant getSetting (const QString & key, |
97 |
|
|
const QVariant & defaultValue = QVariant()); |
98 |
|
|
|
99 |
|
|
PluginManager pluginManager_; |
100 |
|
|
QStringList pluginsToInit_; |
101 |
|
|
QStringList pyplugins_; |
102 |
|
|
QStringList pyscripts_; |
103 |
|
|
|
104 |
|
|
void setMainWindow (MainWindow* main); |
105 |
|
|
|
106 |
|
|
void initPlugins (); |
107 |
|
|
|
108 |
|
|
std::ostream& print (std::ostream& os); |
109 |
|
|
|
110 |
|
|
/// \note Prefer using Settings::fromFiles() |
111 |
|
|
void readRobotFile (); |
112 |
|
|
/// \note Prefer using Settings::fromFiles() |
113 |
|
|
void readEnvFile (); |
114 |
|
|
/// Read the settings file. |
115 |
|
|
/// |
116 |
|
|
/// Here is the syntax: |
117 |
|
|
/// \code |
118 |
|
|
/// ; Comments starts with a ; You may uncomment to see the effect. |
119 |
|
|
/// |
120 |
|
|
/// [plugins] |
121 |
|
|
/// ; Put a list of C++ plugins followed by '=true'. For instance, HPP users may have |
122 |
|
|
/// ; hppwidgetsplugin.so=true |
123 |
|
|
/// ; hppcorbaserverplugin.so=true |
124 |
|
|
/// |
125 |
|
|
/// [pyplugins] |
126 |
|
|
/// ; Put a list of Python plugins followed by '=true'. For instance, the example plugin can be loaded with |
127 |
|
|
/// ; gepetto.plugin=true |
128 |
|
|
/// |
129 |
|
|
/// ; WARNING: Any comment in this file may be removed by the GUI if you regenerate a configuration file. |
130 |
|
|
/// \endcode |
131 |
|
|
/// \note Details on plugin interface can be found in PluginInterface, resp. PythonWidget, class |
132 |
|
|
/// for C++, resp. Python, plugins. |
133 |
|
|
/// \note Prefer using Settings::fromFiles() |
134 |
|
|
void readSettingFile (); |
135 |
|
|
|
136 |
|
|
void saveState () const; |
137 |
|
|
void restoreState () const; |
138 |
|
|
void restoreDockWidgetsState () const; |
139 |
|
|
|
140 |
|
|
void writeRobotFile (); |
141 |
|
|
void writeEnvFile (); |
142 |
|
|
void writeSettingFile (); |
143 |
|
|
|
144 |
|
|
const char** makeOmniORBargs (int &argc); |
145 |
|
|
|
146 |
|
|
private: |
147 |
|
|
void addRobotFromString (const std::string& rbtStr); |
148 |
|
|
void addEnvFromString (const std::string& envStr); |
149 |
|
|
void addPlugin (const QString& plg, bool init); |
150 |
|
|
void addPyPlugin (const QString& plg, bool init); |
151 |
|
|
void addPyScript (const QString& fileName); |
152 |
|
|
void addOmniORB (const QString& arg, const QString& value); |
153 |
|
|
|
154 |
|
|
inline void log (const QString& t); |
155 |
|
|
inline void logError (const QString& t); |
156 |
|
|
|
157 |
|
|
MainWindow* mw; |
158 |
|
|
QStringList omniORBargv_; |
159 |
|
|
}; |
160 |
|
|
} // namespace gui |
161 |
|
|
} // namespace gepetto |
162 |
|
|
|
163 |
|
|
#endif // GEPETTO_GUI_SETTINGS_HH |