Attaches another MJCF model at this site. An empty will be created as an attachment frame. All children of `attachment`'s will be treated as children of this frame. Furthermore, all other elements in `attachment` are merged into the root of the MJCF model to which
(self, attachment)
| 991 | __slots__ = [] |
| 992 | |
| 993 | def attach(self, attachment): |
| 994 | """Attaches another MJCF model at this site. |
| 995 | |
| 996 | An empty <body> will be created as an attachment frame. All children of |
| 997 | `attachment`'s <worldbody> will be treated as children of this frame. |
| 998 | Furthermore, all other elements in `attachment` are merged into the root |
| 999 | of the MJCF model to which this element belongs. |
| 1000 | |
| 1001 | Args: |
| 1002 | attachment: An MJCF `RootElement` |
| 1003 | |
| 1004 | Returns: |
| 1005 | An `mjcf.Element` corresponding to the attachment frame. A joint can be |
| 1006 | added directly to this frame to give degrees of freedom to the attachment. |
| 1007 | |
| 1008 | Raises: |
| 1009 | ValueError: If `other` is not a valid attachment to this element. |
| 1010 | """ |
| 1011 | if not isinstance(attachment, RootElement): |
| 1012 | raise ValueError('Expected a mjcf.RootElement: got {}' |
| 1013 | .format(attachment)) |
| 1014 | if attachment.namescope.parent is not None: |
| 1015 | raise ValueError('The model specified is already attached elsewhere') |
| 1016 | if attachment.namescope == self.namescope: |
| 1017 | raise ValueError('Cannot merge a model to itself') |
| 1018 | self.root._attach(attachment, exclude_worldbody=True, dry_run=True) # pylint: disable=protected-access |
| 1019 | |
| 1020 | if self.namescope.has_identifier('namescope', attachment.model): |
| 1021 | id_number = 1 |
| 1022 | while self.namescope.has_identifier( |
| 1023 | 'namescope', '{}_{}'.format(attachment.model, id_number)): |
| 1024 | id_number += 1 |
| 1025 | attachment.model = '{}_{}'.format(attachment.model, id_number) |
| 1026 | attachment.namescope.parent = self.namescope |
| 1027 | |
| 1028 | if self.tag == constants.WORLDBODY: |
| 1029 | frame_parent = self |
| 1030 | frame_siblings = self._children |
| 1031 | index = len(frame_siblings) |
| 1032 | else: |
| 1033 | frame_parent = self._parent |
| 1034 | frame_siblings = self._parent._children # pylint: disable=protected-access |
| 1035 | index = frame_siblings.index(self) + 1 |
| 1036 | while (index < len(frame_siblings) |
| 1037 | and isinstance(frame_siblings[index], _AttachmentFrame)): |
| 1038 | index += 1 |
| 1039 | frame = _AttachmentFrame(frame_parent, self, attachment) |
| 1040 | frame_siblings.insert(index, frame) |
| 1041 | self.root._attach(attachment, exclude_worldbody=True) # pylint: disable=protected-access |
| 1042 | return frame |
| 1043 | |
| 1044 | |
| 1045 | class _AttachmentFrame(_ElementImpl): |
nothing calls this directly
no test coverage detected