Replace mjs_detachBody and mjs_detachDefault with mjs_detach.
In a follow-up, mjs_detach will be changed to only remove without deleting an element. PiperOrigin-RevId: 773637351 Change-Id: I9ee4d3584ba88ccc225591337cf036bab806e25c
This commit is contained in:
committed by
Copybara-Service
parent
4ce6293217
commit
0488d9f4eb
+25
-33
@@ -284,35 +284,18 @@ const char* mjs_getError(mjSpec* s) {
|
||||
|
||||
|
||||
// detach body from mjSpec, return 0 on success
|
||||
int mjs_detachBody(mjSpec* s, mjsBody* b) {
|
||||
int mjs_detach(mjSpec* s, mjsElement* element) {
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
mjCBody* body = static_cast<mjCBody*>(b->element);
|
||||
try {
|
||||
*model -= *body;
|
||||
} catch (mjCError& e) {
|
||||
model->SetError(e);
|
||||
if (!element) {
|
||||
model->SetError(mjCError(0, "Element is null."));
|
||||
return -1;
|
||||
}
|
||||
model->Detach(body);
|
||||
return 0;
|
||||
mjCError e(0, "Detach is not implemented yet.");
|
||||
model->SetError(e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// detach default from mjSpec, return 0 on success
|
||||
int mjs_detachDefault(mjSpec* s, mjsDefault* def) {
|
||||
mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
if (!def) {
|
||||
modelC->SetError(mjCError(0, "Cannot detach, default is null"));
|
||||
return -1;
|
||||
}
|
||||
mjCDef* defC = static_cast<mjCDef*>(def->element);
|
||||
try {
|
||||
*modelC -= *defC;
|
||||
} catch (mjCError& e) {
|
||||
modelC->SetError(e);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// check if model has warnings
|
||||
int mjs_isWarning(mjSpec* s) {
|
||||
@@ -372,15 +355,24 @@ int mj_copyBack(mjSpec* s, const mjModel* m) {
|
||||
|
||||
|
||||
// delete object, return 0 on success
|
||||
int mjs_delete(mjsElement* element) {
|
||||
mjCModel* model;
|
||||
if (element->elemtype == mjOBJ_DEFAULT)
|
||||
model = static_cast<mjCDef*>(element)->model;
|
||||
else
|
||||
model = static_cast<mjCBase*>(element)->model;
|
||||
int mjs_delete(mjSpec* s, mjsElement* element) {
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
if (!element) {
|
||||
model->SetError(mjCError(0, "Element is null."));
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
// it will call the appropriate destructor since ~mjCBase is virtual
|
||||
model->DeleteElement(element);
|
||||
if (element->elemtype == mjOBJ_BODY) {
|
||||
mjCBody* body = static_cast<mjCBody*>(element);
|
||||
*model -= *body;
|
||||
model->DeleteElement(body);
|
||||
} else if (element->elemtype == mjOBJ_DEFAULT) {
|
||||
mjCDef* def = static_cast<mjCDef*>(element);
|
||||
*model -= *def;
|
||||
} else {
|
||||
// it will call the appropriate destructor since ~mjCBase is virtual
|
||||
model->DeleteElement(element);
|
||||
}
|
||||
return 0;
|
||||
} catch (mjCError& e) {
|
||||
model->SetError(e);
|
||||
@@ -1035,7 +1027,7 @@ const char* mjs_resolveOrientation(double quat[4], mjtByte degree, const char* s
|
||||
mjsFrame* mjs_bodyToFrame(mjsBody** body) {
|
||||
mjCBody* bodyC = static_cast<mjCBody*>((*body)->element);
|
||||
mjCFrame* frameC = bodyC->ToFrame();
|
||||
bodyC->model->Detach(bodyC);
|
||||
bodyC->model->DeleteElement((*body)->element);
|
||||
*body = nullptr;
|
||||
return &frameC->spec;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user