40 #include <QVBoxLayout> 41 #include <QMessageBox> 42 #include <QPushButton> 46 #include <moveit_msgs/DisplayRobotState.h> 59 QVBoxLayout* layout =
new QVBoxLayout();
60 layout->setAlignment(Qt::AlignTop);
65 new HeaderWidget(
"Simulate With Gazebo",
"The following tool will auto-generate the URDF changes needed " 66 "for Gazebo compatibility with ROSControl and MoveIt!. The " 67 "needed changes are shown in green.",
69 layout->addWidget(header);
72 QSpacerItem* blank_space =
new QSpacerItem(1, 8);
73 layout->addSpacerItem(blank_space);
75 QLabel* instructions =
new QLabel(
this);
76 instructions->setText(
"You can run the following command to quickly find the necessary URDF file to edit:");
77 layout->addWidget(instructions);
79 QTextEdit* instructions_command =
new QTextEdit(
this);
80 instructions_command->setText(std::string(
"roscd " + config_data->urdf_pkg_name_).c_str());
81 instructions_command->setReadOnly(
true);
82 instructions_command->setMaximumHeight(30);
83 layout->addWidget(instructions_command);
86 blank_space =
new QSpacerItem(1, 6);
87 layout->addSpacerItem(blank_space);
90 QPushButton* btn_generate =
new QPushButton(
"&Generate URDF",
this);
91 btn_generate->setMinimumWidth(180);
92 btn_generate->setMinimumHeight(40);
93 layout->addWidget(btn_generate);
94 layout->setAlignment(btn_generate, Qt::AlignLeft);
110 copy_urdf_->setText(
"<a href='contract'>Copy to Clipboard</a>");
111 connect(
copy_urdf_, SIGNAL(linkActivated(
const QString)),
this, SLOT(
copyURDF(
const QString)));
116 this->setLayout(layout);
125 std::string gazebo_compatible_urdf_string =
config_data_->getGazeboCompatibleURDF();
126 std::size_t urdf_length = gazebo_compatible_urdf_string.length();
132 std::smatch start_match;
133 std::smatch end_match;
134 std::regex start_reg_ex(
"<inertial");
135 std::regex end_reg_ex(
"</inertial");
138 std::regex_search(gazebo_compatible_urdf_string, start_match, start_reg_ex);
139 std::regex_search(gazebo_compatible_urdf_string, end_match, end_reg_ex);
142 std::vector<int> inertial_opening_matches;
143 std::vector<int> inertial_closing_matches;
145 inertial_closing_matches.push_back(0);
148 for (
auto it = std::sregex_iterator(gazebo_compatible_urdf_string.begin(), gazebo_compatible_urdf_string.end(),
150 it != std::sregex_iterator(); ++it)
152 inertial_opening_matches.push_back(it->position());
155 inertial_opening_matches.push_back(urdf_length);
158 for (
auto it = std::sregex_iterator(gazebo_compatible_urdf_string.begin(), gazebo_compatible_urdf_string.end(),
160 it != std::sregex_iterator(); ++it)
162 inertial_closing_matches.push_back(it->position());
165 for (std::size_t match_number = 0; match_number < inertial_opening_matches.size() - 1; match_number++)
170 QString(gazebo_compatible_urdf_string
171 .substr(inertial_closing_matches[match_number],
172 inertial_opening_matches[match_number] - inertial_closing_matches[match_number])
179 QString(gazebo_compatible_urdf_string
180 .substr(inertial_opening_matches[match_number],
181 inertial_closing_matches[match_number + 1] - inertial_opening_matches[match_number] + 11)
183 inertial_closing_matches[match_number + 1] += 11;
187 std::size_t first_transmission = gazebo_compatible_urdf_string.find(
"<transmission");
190 std::size_t last_inertial = inertial_closing_matches[inertial_opening_matches.size() - 1];
192 if (first_transmission != std::string::npos)
196 QString(gazebo_compatible_urdf_string.substr(last_inertial, first_transmission - last_inertial).c_str()));
201 gazebo_compatible_urdf_string.substr(first_transmission, urdf_length - first_transmission - 10).c_str()));