diff --git a/glue/plugins/tools/pv_slicer/pv_sliced_data.py b/glue/plugins/tools/pv_slicer/pv_sliced_data.py index 7b3cbad2b..b237ceae5 100644 --- a/glue/plugins/tools/pv_slicer/pv_sliced_data.py +++ b/glue/plugins/tools/pv_slicer/pv_sliced_data.py @@ -205,7 +205,8 @@ def compute_fixed_resolution_buffer(self, bounds, target_data=None, target_cid=N result = compute_fixed_resolution_buffer(self.original_data, new_bounds, target_data=target_data.original_data, target_cid=target_cid, - subset_state=subset_state) + subset_state=subset_state, + cache_id=cache_id) result = result[tuple(slices)] diff --git a/glue/plugins/tools/pv_slicer/qt/pv_slicer.py b/glue/plugins/tools/pv_slicer/qt/pv_slicer.py index 004a29a6b..e3a7c51ca 100644 --- a/glue/plugins/tools/pv_slicer/qt/pv_slicer.py +++ b/glue/plugins/tools/pv_slicer/qt/pv_slicer.py @@ -29,6 +29,7 @@ def __init__(self, viewer, **kwargs): self._roi_callback = self._extract_callback self._slice_widget = None self.viewer.state.add_callback('reference_data', self._on_reference_data_change) + self.open_viewer = True self._on_reference_data_change() def _on_reference_data_change(self, *args): @@ -46,48 +47,67 @@ def _extract_callback(self, mode): vx, vy = mode.roi().to_polygon() - selected = self.viewer.session.application.selected_layers() + if self.open_viewer: + viewer = self.viewer.session.application.new_data_viewer(ImageViewer) + self.open_viewer = False + else: + viewer = None - open_viewer = False + for layer_state in self.viewer.state.layers: - all_pvdata = [] + data = layer_state.layer - for data in self.viewer.state.layers_data: if isinstance(data, Data): + # TODO: need to generalize this for non-xy cuts + for pvdata in self.viewer.session.data_collection: if isinstance(pvdata, PVSlicedData): if pvdata.original_data is data: + pvdata.original_data = self.viewer.state.reference_data + pvdata.x_att = self.viewer.state.x_att + pvdata.y_att = self.viewer.state.y_att + pvdata.set_xy(vx, vy) break else: - pvdata = None - - if pvdata is None: - pvdata = PVSlicedData(data, - self.viewer.state.x_att, vx, - self.viewer.state.y_att, vy, - label=data.label + " [slice]") - pvdata.parent_viewer = self.viewer - self.viewer.session.data_collection.append(pvdata) - open_viewer = True + pvdata = PVSlicedData(data, + self.viewer.state.x_att, vx, + self.viewer.state.y_att, vy, + label=data.label + " [slice]") + pvdata.parent_viewer = self.viewer + self.viewer.session.data_collection.append(pvdata) + else: - data = pvdata - data.original_data = self.viewer.state.reference_data - data.x_att = self.viewer.state.x_att - data.y_att = self.viewer.state.y_att - data.set_xy(vx, vy) - all_pvdata.append(pvdata) + # For now don't do anything with the subsets, adding the data + # will automatically add all subsets. In future we could try + # and only add subsets that were shown in the original viewer. + continue + + if viewer is not None: - if open_viewer: - viewer = self.viewer.session.application.new_data_viewer(ImageViewer) - for pvdata in all_pvdata: viewer.add_data(pvdata) + # Copy over visual state from original layer, such as color, + # attribute and so on. + pvstate = layer_state.as_dict() + pvstate.pop('layer') + + # Find layer state to update in new viewer - this might not be + # the last layer if subsets are present + for new_layer_state in viewer.state.layers[::-1]: + if new_layer_state.layer is pvdata: + new_layer_state.update_from_dict(pvstate) + break + + if viewer is not None: + viewer.state.aspect = 'auto' + viewer.state.color_mode = self.viewer.state.color_mode viewer.state.reset_limits() + @viewer_tool class PVLinkCursorMode(ToolbarModeBase): """