An specialized representing a frame holding an external attachment.
| 1043 | |
| 1044 | |
| 1045 | class _AttachmentFrame(_ElementImpl): |
| 1046 | """An specialized <body> representing a frame holding an external attachment. |
| 1047 | """ |
| 1048 | __slots__ = ['_site', '_attachment'] |
| 1049 | |
| 1050 | def __init__(self, parent, site, attachment): |
| 1051 | if parent.tag == constants.WORLDBODY: |
| 1052 | spec = schema.WORLD_ATTACHMENT_FRAME |
| 1053 | else: |
| 1054 | spec = schema.ATTACHMENT_FRAME |
| 1055 | |
| 1056 | spec_is_copied = False |
| 1057 | for child_name, child_spec in spec.children.items(): |
| 1058 | if child_spec.namespace: |
| 1059 | if not spec_is_copied: |
| 1060 | spec = copy.deepcopy(spec) |
| 1061 | spec_is_copied = True |
| 1062 | spec_as_dict = child_spec._asdict() |
| 1063 | spec_as_dict['namespace'] = '{}{}attachment_frame_{}'.format( |
| 1064 | child_spec.namespace, constants.NAMESPACE_SEPARATOR, id(self)) |
| 1065 | spec.children[child_name] = type(child_spec)(**spec_as_dict) |
| 1066 | |
| 1067 | attributes = {} |
| 1068 | with debugging.freeze_current_stack_trace(): |
| 1069 | for attribute_name in spec.attributes.keys(): |
| 1070 | if hasattr(site, attribute_name): |
| 1071 | attributes[attribute_name] = getattr(site, attribute_name) |
| 1072 | super().__init__(spec, parent, attributes) |
| 1073 | self._site = site |
| 1074 | self._attachment = attachment |
| 1075 | self._attachments[attachment.namescope] = attachment.worldbody |
| 1076 | self.namescope.add('attachment_frame', attachment.namescope.name, self) |
| 1077 | self.namescope.add('attached_model', attachment.namescope.name, attachment) |
| 1078 | |
| 1079 | def prefixed_identifier(self, prefix_root=None): |
| 1080 | prefix = self.namescope.full_prefix(prefix_root) |
| 1081 | return prefix + self._attachment.namescope.name + constants.PREFIX_SEPARATOR |
| 1082 | |
| 1083 | def to_xml(self, prefix_root=None, debug_context=None, |
| 1084 | *, |
| 1085 | precision=constants.XML_DEFAULT_PRECISION, |
| 1086 | zero_threshold=0, |
| 1087 | filename_with_hash=True): |
| 1088 | xml_element = (super().to_xml(prefix_root, debug_context, |
| 1089 | precision=precision, |
| 1090 | zero_threshold=zero_threshold, |
| 1091 | filename_with_hash=filename_with_hash)) |
| 1092 | xml_element.set('name', self.prefixed_identifier(prefix_root)) |
| 1093 | return xml_element |
| 1094 | |
| 1095 | @property |
| 1096 | def full_identifier(self): |
| 1097 | return self.prefixed_identifier(self.namescope.root) |
| 1098 | |
| 1099 | def _detach(self, other_namescope): |
| 1100 | super()._detach(other_namescope) |
| 1101 | if other_namescope is self._attachment.namescope: |
| 1102 | self.namescope.remove('attachment_frame', self._attachment.namescope.name) |
no outgoing calls
no test coverage detected
searching dependent graphs…