add mjs_detachDefault to delete a default class from mjSpec
PiperOrigin-RevId: 738452369 Change-Id: I5a53a6dc8f89e1e8136aeefc09d7d9b7b7204e1f
This commit is contained in:
committed by
Copybara-Service
parent
a1b9ffd124
commit
be64747166
@@ -287,6 +287,7 @@ ENUMS: Mapping[str, EnumDecl] = dict([
|
||||
('mjOBJ_PLUGIN', 25),
|
||||
('mjNOBJECT', 26),
|
||||
('mjOBJ_FRAME', 100),
|
||||
('mjOBJ_DEFAULT', 101),
|
||||
]),
|
||||
)),
|
||||
('mjtConstraint',
|
||||
|
||||
@@ -9154,7 +9154,27 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
),
|
||||
),
|
||||
),
|
||||
doc='Detach body from mjSpec, remove all references and delete the body, return 0 on success.', # pylint: disable=line-too-long
|
||||
doc='Delete body and descendants from mjSpec, remove all references, return 0 on success.', # pylint: disable=line-too-long
|
||||
)),
|
||||
('mjs_detachDefault',
|
||||
FunctionDecl(
|
||||
name='mjs_detachDefault',
|
||||
return_type=ValueType(name='int'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='s',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjSpec'),
|
||||
),
|
||||
),
|
||||
FunctionParameterDecl(
|
||||
name='d',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjsDefault'),
|
||||
),
|
||||
),
|
||||
),
|
||||
doc='Delete default class and descendants from mjSpec, remove all references, return 0 on success.', # pylint: disable=line-too-long
|
||||
)),
|
||||
('mjs_addBody',
|
||||
FunctionDecl(
|
||||
@@ -9954,7 +9974,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
FunctionDecl(
|
||||
name='mjs_findDefault',
|
||||
return_type=PointerType(
|
||||
inner_type=ValueType(name='mjsDefault', is_const=True),
|
||||
inner_type=ValueType(name='mjsDefault'),
|
||||
),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
|
||||
@@ -448,7 +448,7 @@ PYBIND11_MODULE(_specs, m) {
|
||||
py::return_value_policy::reference_internal);
|
||||
mjSpec.def(
|
||||
"find_default",
|
||||
[](MjSpec& self, std::string& classname) -> const raw::MjsDefault* {
|
||||
[](MjSpec& self, std::string& classname) -> raw::MjsDefault* {
|
||||
return mjs_findDefault(self.ptr, classname.c_str());
|
||||
},
|
||||
py::return_value_policy::reference_internal);
|
||||
@@ -499,6 +499,11 @@ PYBIND11_MODULE(_specs, m) {
|
||||
return mjs_addDefault(spec->ptr, classname.c_str(), parent);
|
||||
},
|
||||
py::return_value_policy::reference_internal);
|
||||
mjSpec.def("detach_default", [](MjSpec& self, raw::MjsDefault& def) {
|
||||
if (mjs_detachDefault(self.ptr, &def) != 0) {
|
||||
throw pybind11::value_error(mjs_getError(self.ptr));
|
||||
}
|
||||
});
|
||||
mjSpec.def_property_readonly(
|
||||
"default",
|
||||
[](MjSpec& self) -> raw::MjsDefault* {
|
||||
|
||||
@@ -589,6 +589,12 @@ class SpecsTest(absltest.TestCase):
|
||||
spec.compile()
|
||||
self.assertEqual(spec.to_xml(), XML)
|
||||
|
||||
# test delete default
|
||||
def1 = spec.find_default('def1')
|
||||
spec.detach_default(def1)
|
||||
def1 = spec.find_default('def1')
|
||||
self.assertIsNone(def1)
|
||||
|
||||
def test_element_list(self):
|
||||
spec = mujoco.MjSpec()
|
||||
sensor1 = spec.add_sensor()
|
||||
|
||||
Reference in New Issue
Block a user