GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/gepetto/gui/settings.hh Lines: 0 1 0.0 %
Date: 2020-05-14 11:23:33 Branches: 0 0 - %

Line Branch Exec Source
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
      bool verbose;
44
      bool noPlugin;
45
      bool autoWriteSettings;
46
      bool useNameService;
47
48
      int refreshRate;
49
50
      /// Path to avconv binary (maybe ffmpeg on some distributions).
51
      std::string captureDirectory, captureFilename, captureExtension;
52
53
      /// \group record_parameter Video generation parameters
54
      /// \{
55
      QString avconv;
56
      QStringList avConvInputOptions;
57
      QStringList avConvOutputOptions;
58
      /// \}
59
60
      QString installDirectory;
61
62
      QString appStyle;
63
64
      /// Set up default values
65
      Settings (const char* installDirectory);
66
67
      /// Setup paths to find setting files and plugins.
68
      /// \note The environment variable
69
      /// GEPETTO_GUI_PLUGIN_DIRS, LD_LIBRARY_PATH
70
      /// and GEPETTO_GUI_SETTINGS_DIR are read.
71
      void setupPaths () const;
72
73
      /// Get the filename of a configuration file.
74
      QString getQSettingsFileName (const std::string& settingsName) const;
75
76
      /// Initialize the settings.
77
      /// It uses the following elements, in this order:
78
      /// \li read config file names from command line.
79
      /// \li read config files.
80
      /// \li read other command line arguments.
81
      /// \return \li 0 if no error,
82
      ///         \li 1 if no error and the user requested to generate config
83
      ///             files or to print the help,
84
      ///         \li 2 in case of error.
85
      int initSettings (int argc, char * argv[]);
86
87
      /// Update settings from setting files
88
      void fromFiles ();
89
90
      /// Write the settings to configuration files
91
      void writeSettings ();
92
93
      /// Get a setting
94
      QVariant getSetting (const QString & key,
95
          const QVariant & defaultValue = QVariant());
96
97
      PluginManager pluginManager_;
98
      QStringList pluginsToInit_;
99
      QStringList pyplugins_;
100
      QStringList pyscripts_;
101
102
      void setMainWindow (MainWindow* main);
103
104
      void initPlugins ();
105
106
      std::ostream& print (std::ostream& os);
107
108
      /// \note Prefer using Settings::fromFiles()
109
      void readRobotFile ();
110
      /// \note Prefer using Settings::fromFiles()
111
      void readEnvFile ();
112
      /// Read the settings file.
113
      ///
114
      /// Here is the syntax:
115
      /// \code
116
      /// ; Comments starts with a ; You may uncomment to see the effect.
117
      ///
118
      /// [plugins]
119
      /// ; Put a list of C++ plugins followed by '=true'. For instance, HPP users may have
120
      /// ; hppwidgetsplugin.so=true
121
      /// ; hppcorbaserverplugin.so=true
122
      ///
123
      /// [pyplugins]
124
      /// ; Put a list of Python plugins followed by '=true'. For instance, the example plugin can be loaded with
125
      /// ; gepetto.plugin=true
126
      ///
127
      /// ; WARNING: Any comment in this file may be removed by the GUI if you regenerate a configuration file.
128
      /// \endcode
129
      /// \note Details on plugin interface can be found in PluginInterface, resp. PythonWidget, class
130
      /// for C++, resp. Python, plugins.
131
      /// \note Prefer using Settings::fromFiles()
132
      void readSettingFile ();
133
134
      void saveState () const;
135
      void restoreState () const;
136
      void restoreDockWidgetsState () const;
137
138
      void writeRobotFile ();
139
      void writeEnvFile ();
140
      void writeSettingFile ();
141
142
      const char** makeOmniORBargs (int &argc);
143
144
    private:
145
      void addRobotFromString (const std::string& rbtStr);
146
      void addEnvFromString (const std::string& envStr);
147
      void addPlugin (const QString& plg, bool init);
148
      void addPyPlugin (const QString& plg, bool init);
149
      void addPyScript (const QString& fileName);
150
      void addOmniORB (const QString& arg, const QString& value);
151
152
      inline void log (const QString& t);
153
      inline void logError (const QString& t);
154
155
      MainWindow* mw;
156
      QStringList omniORBargv_;
157
    };
158
  } // namespace gui
159
} // namespace gepetto
160
161
#endif // GEPETTO_GUI_SETTINGS_HH