From 1ed8694dbeef9cfea369be144c39cb51bd1a82a2 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Fri, 2 Feb 2024 12:33:50 -0800 Subject: [PATCH] Replace `xmlpos` with `info` string for mjCError. PiperOrigin-RevId: 603759456 Change-Id: I0d86d8e61e31a70da77169107268728d6c052778 --- src/user/user_objects.cc | 28 ++++++++++++---------------- src/user/user_objects.h | 10 +++++----- src/xml/xml_native_reader.cc | 11 +++++------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index bd539ec7..1f399e2b 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -114,9 +114,9 @@ mjCError::mjCError(const mjCBase* obj, const char* msg, const char* str, int pos // append info from mjCBase object if (obj) { // with or without xml position - if (obj->xmlpos[0]>= 0) { - mju::sprintf_arr(temp, "Object name = %s, id = %d, line = %d, column = %d", - obj->name.c_str(), obj->id, obj->xmlpos[0], obj->xmlpos[1]); + if (!obj->info.empty()) { + mju::sprintf_arr(temp, "Object name = %s, id = %d, %s", + obj->name.c_str(), obj->id, obj->info.c_str()); } else { mju::sprintf_arr(temp, "Object name = %s, id = %d", obj->name.c_str(), obj->id); } @@ -512,7 +512,7 @@ mjCBase::mjCBase() { name.clear(); classname.clear(); id = -1; - xmlpos[0] = xmlpos[1] = -1; + info = ""; model = 0; def = 0; frame = nullptr; @@ -3548,11 +3548,10 @@ mjCTendon::~mjCTendon() { // add site as wrap object -void mjCTendon::WrapSite(string name, int row, int col) { +void mjCTendon::WrapSite(string name, std::string_view info) { // create wrap object mjCWrap* wrap = new mjCWrap(model, this); - wrap->xmlpos[0] = row; - wrap->xmlpos[1] = col; + wrap->info = info; // set parameters, add to path wrap->type = mjWRAP_SITE; @@ -3564,11 +3563,10 @@ void mjCTendon::WrapSite(string name, int row, int col) { // add geom (with side site) as wrap object -void mjCTendon::WrapGeom(string name, string sidesite, int row, int col) { +void mjCTendon::WrapGeom(string name, string sidesite, std::string_view info) { // create wrap object mjCWrap* wrap = new mjCWrap(model, this); - wrap->xmlpos[0] = row; - wrap->xmlpos[1] = col; + wrap->info = info; // set parameters, add to path wrap->type = mjWRAP_SPHERE; // replace with cylinder later if needed @@ -3581,11 +3579,10 @@ void mjCTendon::WrapGeom(string name, string sidesite, int row, int col) { // add joint as wrap object -void mjCTendon::WrapJoint(string name, double coef, int row, int col) { +void mjCTendon::WrapJoint(string name, double coef, std::string_view info) { // create wrap object mjCWrap* wrap = new mjCWrap(model, this); - wrap->xmlpos[0] = row; - wrap->xmlpos[1] = col; + wrap->info = info; // set parameters, add to path wrap->type = mjWRAP_JOINT; @@ -3598,11 +3595,10 @@ void mjCTendon::WrapJoint(string name, double coef, int row, int col) { // add pulley -void mjCTendon::WrapPulley(double divisor, int row, int col) { +void mjCTendon::WrapPulley(double divisor, std::string_view info) { // create wrap object mjCWrap* wrap = new mjCWrap(model, this); - wrap->xmlpos[0] = row; - wrap->xmlpos[1] = col; + wrap->info = info; // set parameters, add to path wrap->type = mjWRAP_PULLEY; diff --git a/src/user/user_objects.h b/src/user/user_objects.h index 5fac7b3a..b64c073e 100644 --- a/src/user/user_objects.h +++ b/src/user/user_objects.h @@ -198,7 +198,7 @@ class mjCBase { std::string name; // object name std::string classname; // defaults class name int id; // object id - int xmlpos[2]; // row and column in xml file + std::string info; // error message info set by the user mjCDef* def; // defaults class used to init this object mjCModel* model; // pointer to model that created object mjCFrame* frame; // pointer to frame transformation @@ -1089,10 +1089,10 @@ class mjCTendon : public mjCBase { std::string& get_material() { return material_; } // API for adding wrapping objects - void WrapSite(std::string name, int row=-1, int col=-1); // site - void WrapGeom(std::string name, std::string side, int row=-1, int col=-1); // geom - void WrapJoint(std::string name, double coef, int row=-1, int col=-1); // joint - void WrapPulley(double divisor, int row=-1, int col=-1); // pulley + void WrapSite(std::string name, std::string_view info = ""); // site + void WrapGeom(std::string name, std::string side, std::string_view info = ""); // geom + void WrapJoint(std::string name, double coef, std::string_view info = ""); // joint + void WrapPulley(double divisor, std::string_view info = ""); // pulley // API for access to wrapping objects int NumWraps(void); // number of wraps diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index 9e9ba1d5..94f792ed 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -3293,7 +3293,7 @@ void mjXReader::Tendon(XMLElement* section) { // read attributes depending on type if (wrap=="site") { ReadAttrTxt(sub, "site", text, true); - pten->WrapSite(text, sub->GetLineNum()); + pten->WrapSite(text, "line = " + std::to_string(sub->GetLineNum())); } else if (wrap=="geom") { @@ -3301,18 +3301,18 @@ void mjXReader::Tendon(XMLElement* section) { if (!ReadAttrTxt(sub, "sidesite", text1)) { text1.clear(); } - pten->WrapGeom(text, text1, sub->GetLineNum()); + pten->WrapGeom(text, text1, "line = " + std::to_string(sub->GetLineNum())); } else if (wrap=="pulley") { ReadAttr(sub, "divisor", 1, &data, text, true); - pten->WrapPulley(data, sub->GetLineNum()); + pten->WrapPulley(data, "line = " + std::to_string(sub->GetLineNum())); } else if (wrap=="joint") { ReadAttrTxt(sub, "joint", text, true); ReadAttr(sub, "coef", 1, &data, text1, true); - pten->WrapJoint(text, data, sub->GetLineNum()); + pten->WrapJoint(text, data, "line = " + std::to_string(sub->GetLineNum())); } else { @@ -3743,6 +3743,5 @@ mjCDef* mjXReader::GetClass(XMLElement* section) { // get xml position void mjXReader::GetXMLPos(XMLElement* elem, mjCBase* obj) { - obj->xmlpos[0] = elem->GetLineNum(); - obj->xmlpos[1] = -1; + obj->info = "line = " + std::to_string(elem->GetLineNum()); }