Add support for printing to stdout in mj_saveLastXML.
PiperOrigin-RevId: 546849864 Change-Id: I799ea3fcd723cf036f82ef5c1ef8152c314072dc
This commit is contained in:
committed by
Copybara-Service
parent
5cfbb6ac8b
commit
24c1ec9aec
@@ -59,11 +59,15 @@ class mj_XMLPrinter : public tinyxml2::XMLPrinter {
|
||||
|
||||
|
||||
// save XML file using custom 2-space indentation
|
||||
tinyxml2::XMLError SaveFile(XMLDocument& doc, FILE* fp) {
|
||||
static string WriteDoc(XMLDocument& doc, char *error, size_t error_sz) {
|
||||
doc.ClearError();
|
||||
mj_XMLPrinter stream(fp, /*compact=*/false);
|
||||
mj_XMLPrinter stream(nullptr, /*compact=*/false);
|
||||
doc.Print(&stream);
|
||||
return doc.ErrorID();
|
||||
if (doc.ErrorID()) {
|
||||
mjCopyError(error, doc.ErrorStr(), error_sz);
|
||||
return "";
|
||||
}
|
||||
return string(stream.CStr());
|
||||
}
|
||||
|
||||
|
||||
@@ -682,10 +686,11 @@ mjXWriter::mjXWriter(void) {
|
||||
|
||||
|
||||
// save existing model in MJCF canonical format, must be compiled
|
||||
void mjXWriter::Write(FILE* fp) {
|
||||
string mjXWriter::Write(char *error, size_t error_sz) {
|
||||
// check model
|
||||
if (!model || !model->IsCompiled()) {
|
||||
throw mjXError(0, "XML Write error: Only compiled model can be written");
|
||||
mjCopyError(error, "XML Write error: Only compiled model can be written", error_sz);
|
||||
return "";
|
||||
}
|
||||
|
||||
// create document and root
|
||||
@@ -722,8 +727,7 @@ void mjXWriter::Write(FILE* fp) {
|
||||
Sensor(root);
|
||||
Keyframe(root);
|
||||
|
||||
// save file
|
||||
SaveFile(doc, fp);
|
||||
return WriteDoc(doc, error, error_sz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user