-
Notifications
You must be signed in to change notification settings - Fork 16
/
GazeboGui.cc
149 lines (130 loc) · 4.52 KB
/
GazeboGui.cc
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
/*
* Copyright (C) 2019 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <fstream>
#include <ignition/common/Console.hh>
#include <ignition/common/Filesystem.hh>
#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/gui/GuiRunner.hh>
#include <ignition/gui/MainWindow.hh>
#include "ignition/gazebo/gui/Gui.hh"
#include "ignition/gazebo/gui/TmpIface.hh"
#include "GazeboGui.hh"
using namespace ignition;
using namespace ignition::launch;
/////////////////////////////////////////////////
GazeboGui::GazeboGui()
: ignition::launch::Plugin()
{
}
/////////////////////////////////////////////////
GazeboGui::~GazeboGui()
{
}
/////////////////////////////////////////////////
bool GazeboGui::Load(const tinyxml2::XMLElement *_elem)
{
int argc;
char **argv = nullptr;
// Set default config file for Launch
std::string defaultConfigPath;
ignition::common::env(IGN_HOMEDIR, defaultConfigPath);
defaultConfigPath = ignition::common::joinPaths(defaultConfigPath,
".ignition", "launch");
auto defaultConfigFile = ignition::common::joinPaths(defaultConfigPath,
"gui.config");
// Check if there's a default config file under
// ~/.ignition/launch and use that. If there isn't, create it
if (!ignition::common::exists(defaultConfigFile))
{
ignition::common::createDirectories(defaultConfigPath);
std::ofstream configFile(defaultConfigFile);
if (configFile.is_open())
{
configFile <<
"<window>\n" <<
" <width>1000</width>\n" <<
" <height>845</height>\n" <<
" <style\n" <<
" material_theme='Light'\n" <<
" material_primary='DeepOrange'\n" <<
" material_accent='LightBlue'\n" <<
" toolbar_color_light='#f3f3f3'\n" <<
" toolbar_text_color_light='#111111'\n" <<
" toolbar_color_dark='#414141'\n" <<
" toolbar_text_color_dark='#f3f3f3'\n" <<
" plugin_toolbar_color_light='#bbdefb'\n" <<
" plugin_toolbar_text_color_light='#111111'\n" <<
" plugin_toolbar_color_dark='#607d8b'\n" <<
" plugin_toolbar_text_color_dark='#eeeeee'\n" <<
" />\n" <<
" <menus>\n" <<
" <drawer default='false'>\n" <<
" </drawer>\n" <<
" </menus>\n" <<
"</window>\n";
configFile.close();
ignmsg << "Saved file [" << defaultConfigFile << "]" << std::endl;
}
else
{
ignerr << "Unable to open file [" << defaultConfigFile << "]"
<< std::endl;
}
}
auto app = gazebo::gui::createGui(argc, argv, defaultConfigFile.c_str(),
defaultConfigFile.c_str(), false);
auto win = app->findChild<ignition::gui::MainWindow *>()->QuickWindow();
// Customize window
std::string windowTitle{"Gazebo"};
auto elem = _elem->FirstChildElement("window_title");
if (elem)
windowTitle = elem->GetText();
win->setProperty("title", QString::fromStdString(windowTitle));
auto iconElem = _elem->FirstChildElement("window_icon");
if (iconElem)
{
win->setIcon(QIcon(iconElem->GetText()));
}
// Process all the plugins.
for (elem = _elem->FirstChildElement("plugin"); elem;
elem = elem->NextSiblingElement("plugin"))
{
// Get the plugin's name
const char *nameStr = elem->Attribute("name");
std::string name = nameStr == nullptr ? "" : nameStr;
if (name.empty())
{
ignerr << "A GazeboGui plugin is missing the name attribute. "
<< "Skipping this plugin.\n";
continue;
}
// Get the plugin's filename
const char *fileStr = elem->Attribute("filename");
std::string file = fileStr == nullptr ? "" : fileStr;
if (file.empty())
{
ignerr << "A GazeboServer plugin with name[" << name << "] is "
<< "missing the filename attribute. Skipping this plugin.\n";
continue;
}
app->LoadPlugin(file, elem);
}
igndbg << "Running the GazeboGui plugin.\n";
// This blocks until the window is closed or we receive a SIGINT
app->exec();
return false;
}