Ejemplo n.º 1
0
    def set_state_from_snapshot(self, session, data):
        self.name = data['name']
        self.id = data['id']
        p = data['parent']
        if p:
            p.add([self])

        pa = data['positions']
        from numpy import float32, float64
        if pa.dtype == float32:
            # Fix old sessions that saved array as float32
            pa = pa.astype(float64)
        from chimerax.geometry import Places
        self.positions = Places(place_array=pa)
        self.display_positions = data['display_positions']
        for d in self.all_drawings():
            for attr in [
                    'allow_depth_cue', 'accept_shadow', 'accept_multishadow'
            ]:
                if attr in data:
                    setattr(d, attr, data[attr])

        if 'clip_cap' in data:
            self.clip_cap = data['clip_cap']

        if 'drawing state' in data:
            from chimerax.graphics.gsession import DrawingState
            DrawingState.set_state_from_snapshot(self, session,
                                                 data['drawing state'])
            self.SESSION_SAVE_DRAWING = True
Ejemplo n.º 2
0
 def restore_geometry(self, session, data):
     '''
     Restore model and drawing state saved with save_geometry().
     '''
     from chimerax.graphics.gsession import DrawingState
     Model.set_state_from_snapshot(self, session, data['model state'])
     DrawingState.set_state_from_snapshot(self, session,
                                          data['drawing state'])
     return self
Ejemplo n.º 3
0
    def restore_snapshot(cls, session, data):
        from chimerax.graphics.gsession import DrawingState
        d = AtomicShapeDrawing('')
        DrawingState.set_state_from_snapshot(d, session, data['drawing'])
        d._shapes = [_AtomicShape(*args) for args in data['shapes']]
        d._selected_shapes.update([d._shapes[i] for i in data['selected']])
        if any(s.atoms for s in d._shapes):
            # After drawing is added to parent, add back the selection handler
            def post_shape_handler(trigger, trigger_data, drawing=d):
                from chimerax.core.triggerset import DEREGISTER
                drawing._add_handler_if_needed()
                return DEREGISTER

            session.triggers.add_handler("end restore session",
                                         post_shape_handler)
        return d
Ejemplo n.º 4
0
 def take_snapshot(self, session, flags):
     from chimerax.graphics.gsession import DrawingState
     data = {
         'model state': Surface.take_snapshot(self, session, flags),
         'drawing state': DrawingState().take_snapshot(self, session, flags),
         'version': GENERIC3D_STATE_VERSION,
     }
     return data
Ejemplo n.º 5
0
 def save_geometry(self, session, flags):
     '''
     Return state for saving Model and Drawing geometry that can be restored
     with restore_geometry().
     '''
     from chimerax.graphics.gsession import DrawingState
     data = {
         'model state': Model.take_snapshot(self, session, flags),
         'drawing state': DrawingState.take_snapshot(self, session, flags),
         'version': 1
     }
     return data
Ejemplo n.º 6
0
 def take_snapshot(self, session, flags):
     from chimerax.graphics.gsession import DrawingState
     data = {}
     data['version'] = AtomicShapeDrawing.SESSION_VERSION
     data['drawing'] = DrawingState.take_snapshot(self, session, flags)
     data['shapes'] = list(
         (s.triangle_range, s.description, s.atoms) for s in self._shapes)
     data['selected'] = [
         i for i in range(len(self._shapes))
         if self._shapes[i] in self._selected_shapes
     ]
     return data
Ejemplo n.º 7
0
 def take_snapshot(self, session, flags):
     p = self.parent
     if p is session.models.scene_root_model:
         p = None  # Don't include root as a parent since root is not saved.
     data = {
         'name': self.name,
         'id': self.id,
         'parent': p,
         'positions': self.positions.array(),
         'display_positions': self.display_positions,
         'allow_depth_cue': self.allow_depth_cue,
         'accept_shadow': self.accept_shadow,
         'accept_multishadow': self.accept_multishadow,
         'version': MODEL_STATE_VERSION,
     }
     if hasattr(self, 'clip_cap'):
         data['clip_cap'] = self.clip_cap
     if self.SESSION_SAVE_DRAWING:
         from chimerax.graphics.gsession import DrawingState
         data['drawing state'] = DrawingState.take_snapshot(
             self, session, flags, include_children=False)
     return data
Ejemplo n.º 8
0
 def restore_snapshot(cls, session, data):
     m = cls('name', session)
     m.set_state_from_snapshot(session, data['model state'])
     from chimerax.graphics.gsession import DrawingState
     DrawingState().set_state_from_snapshot(m, session, data['drawing state'])
     return m