Commits default values into attributes of the specified element. Args: element: A PyMJCF element. attributes: (optional) A list of strings specifying the attributes to be copied from defaults, or `None` if all attributes should be copied.
(element, attributes=None)
| 52 | |
| 53 | |
| 54 | def commit_defaults(element, attributes=None): |
| 55 | """Commits default values into attributes of the specified element. |
| 56 | |
| 57 | Args: |
| 58 | element: A PyMJCF element. |
| 59 | attributes: (optional) A list of strings specifying the attributes to be |
| 60 | copied from defaults, or `None` if all attributes should be copied. |
| 61 | """ |
| 62 | dclass = element.dclass |
| 63 | parent = element.parent |
| 64 | while dclass is None and parent != element.root: |
| 65 | dclass = getattr(parent, 'childclass', None) |
| 66 | parent = parent.parent |
| 67 | if dclass is None: |
| 68 | dclass = element.root.default |
| 69 | |
| 70 | while dclass != element.root: |
| 71 | if element.tag in _ACTUATOR_TAGS: |
| 72 | tags = _ACTUATOR_TAGS |
| 73 | else: |
| 74 | tags = (element.tag,) |
| 75 | for tag in tags: |
| 76 | default_element = getattr(dclass, tag) |
| 77 | for name, value in default_element.get_attributes().items(): |
| 78 | if attributes is None or name in attributes: |
| 79 | if hasattr(element, name) and getattr(element, name) is None: |
| 80 | setattr(element, name, value) |
| 81 | dclass = dclass.parent |
nothing calls this directly
no test coverage detected
searching dependent graphs…