def set_frame(self, fast_axis, slow_axis, origin): ''' Set the local frame. Sets its own global plane and then, after updating its local frame, propagates the frame down to its children. :param fast_axis: The fast axis of the virtual detector plane :param slow_axis: The slow axis of the virtual detector plane :param origin: The origin vector to the virtual detector plane ''' VirtualPanel.set_frame(self, fast_axis, slow_axis, origin) for child in self: child.set_parent_frame( self.get_fast_axis(), self.get_slow_axis(), self.get_origin())
def __eq__(self, other): ''' Check that this is equal to another group. ''' if VirtualPanel.__eq__(self, other): if len(self) != len(other): return False return all(a == b for a, b in zip(self, other)) else: return False
def _group_or_panel_from_dict(d, obj): ''' Convert a dictionary to a group or panel and add to model. ''' base = VirtualPanel.from_dict(d) obj.set_type(base.get_type()) obj.set_name(base.get_name()) obj.set_local_frame( base.get_local_fast_axis(), base.get_local_slow_axis(), base.get_local_origin()) for child in d['children']: if 'panel' in child: index = child['panel'] obj.add_panel(obj.root()._container[index]) else: HierarchicalDetector._group_or_panel_from_dict(child, obj.add_group())
def to_dict(self): ''' Convert the panel group to a dictionary. ''' d = VirtualPanel.to_dict(self) children = [] for c in self._children: if isinstance(c, Panel): idx = None for i, p in enumerate(self.root()._container): if c.is_(p): idx = i break assert(idx is not None) children.append({ "panel" : idx }) else: children.append(c.to_dict()) d['children'] = children return d
def __init__(self, parent=None): ''' Initialise the list of children to an empty list. ''' VirtualPanel.__init__(self) self._parent = parent self._children = []