Remove copy_back from Python bindings and mj_copyBack from the C API.

PiperOrigin-RevId: 687377331
Change-Id: I355493d92857418b08b5aa90ea38cebe5c475314
This commit is contained in:
Alessio Quaglino
2024-10-18 11:54:00 -07:00
committed by Copybara-Service
parent 62c0ef4262
commit dcf2816543
14 changed files with 17 additions and 63 deletions
-8
View File
@@ -75,14 +75,6 @@ mjSpec* mj_copySpec(const mjSpec* s) {
// copy back model
void mj_copyBack(mjSpec* s, const mjModel* m) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
modelC->CopyBack(m);
}
// compile model
mjModel* mj_compile(mjSpec* s, const mjVFS* vfs) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
-3
View File
@@ -54,9 +54,6 @@ MJAPI const char* mjs_getError(mjSpec* s);
// Return 1 if compiler error is a warning.
MJAPI int mjs_isWarning(mjSpec* s);
// Copy model fields back into spec.
MJAPI void mj_copyBack(mjSpec* s, const mjModel* m);
// Delete spec.
MJAPI void mj_deleteSpec(mjSpec* s);
+2 -2
View File
@@ -395,7 +395,7 @@ mjSpec* ParseSpecFromString(std::string_view xml, char* error, int nerror) {
}
// Main writer function - calls mjXWrite
std::string WriteXML(const mjSpec* spec, char* error, int nerror) {
std::string WriteXML(const mjModel* m, const mjSpec* spec, char* error, int nerror) {
LocaleOverride locale_override;
// check for empty model
@@ -405,7 +405,7 @@ std::string WriteXML(const mjSpec* spec, char* error, int nerror) {
}
mjXWriter writer;
writer.SetModel(spec);
writer.SetModel(spec, m);
try {
return writer.Write(error, nerror);
+1 -1
View File
@@ -29,6 +29,6 @@ mjSpec* ParseXML(const char* filename, const mjVFS* vfs, char* error, int nerror
mjSpec* ParseSpecFromString(std::string_view xml, char* error = nullptr, int nerror = 0);
// Main writer function
std::string WriteXML(const mjSpec* spec, char* error, int nerror);
std::string WriteXML(const mjModel* m, const mjSpec* spec, char* error, int nerror);
#endif // MUJOCO_SRC_XML_XML_H_
+3 -4
View File
@@ -62,8 +62,7 @@ std::optional<std::string> GlobalModel::ToXML(const mjModel* m, char* error,
mjCopyError(error, "No XML model loaded", error_sz);
return std::nullopt;
}
mj_copyBack(spec_, m);
std::string result = WriteXML(spec_, error, error_sz);
std::string result = WriteXML(m, spec_, error, error_sz);
if (result.empty()) {
return std::nullopt;
}
@@ -229,7 +228,7 @@ mjSpec* mj_parseXMLString(const char* xml, const mjVFS* vfs, char* error, int er
// save spec to XML file, return 1 on success, 0 otherwise
int mj_saveXML(const mjSpec* s, const char* filename, char* error, int error_sz) {
std::string result = WriteXML(s, error, error_sz);
std::string result = WriteXML(NULL, s, error, error_sz);
if (result.empty()) {
return 0;
}
@@ -245,7 +244,7 @@ int mj_saveXML(const mjSpec* s, const char* filename, char* error, int error_sz)
// save spec to string, return 1 on success, 0 otherwise
int mj_saveXMLString(const mjSpec* s, char* xml, int xml_sz, char* error, int error_sz) {
std::string result = WriteXML(s, error, error_sz);
std::string result = WriteXML(NULL, s, error, error_sz);
if (result.size() >= xml_sz) {
std::string error_msg = "Output string too short, should be at least " +
std::to_string(result.size()+1);
+2 -1
View File
@@ -21,6 +21,7 @@
#include <string>
#include <vector>
#include <mujoco/mjmodel.h>
#include <mujoco/mjspec.h>
#include "xml/xml_util.h"
#include "tinyxml2.h"
@@ -43,7 +44,7 @@ mjXBase::mjXBase() {
// set model field
void mjXBase::SetModel(const mjSpec* _model) {
void mjXBase::SetModel(const mjSpec* _model, const mjModel* m) {
spec = (mjSpec*)_model;
}
+1 -1
View File
@@ -88,7 +88,7 @@ class mjXBase : public mjXUtil {
};
// set the model allocated externally
virtual void SetModel(const mjSpec*);
virtual void SetModel(const mjSpec*, const mjModel* = nullptr);
// read alternative orientation specification
static int ReadAlternative(tinyxml2::XMLElement* elem, mjsOrientation& alt);
+6 -3
View File
@@ -853,9 +853,12 @@ mjXWriter::mjXWriter(void) {
// cast model
void mjXWriter::SetModel(const mjSpec* spec) {
if (spec) {
model = (mjCModel*)spec->element;
void mjXWriter::SetModel(const mjSpec* _spec, const mjModel* m) {
if (_spec) {
model = (mjCModel*)_spec->element;
}
if (m) {
model->CopyBack(m);
}
}
+2 -1
View File
@@ -19,6 +19,7 @@
#include <string>
#include <string_view>
#include <mujoco/mjmodel.h>
#include <mujoco/mjspec.h>
#include "user/user_objects.h"
#include "xml/xml_base.h"
@@ -28,7 +29,7 @@ class mjXWriter : public mjXBase {
public:
mjXWriter(); // constructor
virtual ~mjXWriter() = default; // destructor
void SetModel(const mjSpec* spec);
void SetModel(const mjSpec* _spec, const mjModel* m = nullptr);
// write XML document to string
std::string Write(char *error, std::size_t error_sz);