Pressing "Save world as" invokes the MainWindow::Save function, which creates a "world_sdf" request message that is fulfilled by the gazebo server. The following is a paraphrase of the code in MainWindow::Save
that places sdf file as a string in msgData
:
// Get the latest world in SDF.
boost::shared_ptr<msgs::response> response =
transport::request(get_world(), "world_sdf");
msgs::GzString msg;
// Make sure the response is correct
if (response->response() != "error" && response->type() == msg.GetTypeName())
{
// Parse the response message
msg.ParseFromString(response->serialized_data());
}
std::string msgData = msg.data();
I say it's a paraphrase because MainWindow::Save
, as part of the gui, also tries to parse the sdf file and insert a <gui>
element with information about the gui state (primarily camera position).
There is also a World::Save function that I think can be called from the same process as the server (WorldPlugin
's and ModelPlugin
's), but I'm not exactly sure how thread-safe it is.