Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slicer extension 1344 #1919

Merged
merged 38 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7637e3a
A copy of BoxSlicer, changed the way the box is drawn
kmothander Sep 29, 2021
088c983
Added the changes from BoxSlicer_edit.py to BoxSlicer.py
kmothander Sep 30, 2021
0ef28fb
Removed the file, changes are added to BoxSlicer
kmothander Sep 30, 2021
f2cc820
Box can be placed at arbitrary locations
kmothander Oct 27, 2021
a74ae39
Box placed at center of plot, not just at zero, point cleared
kmothander Oct 28, 2021
3047acc
Edit parameters = working, added x_center, y_center to parameter list
kmothander Nov 11, 2021
64d65f8
Revert "add cases in OMFReader"
Jul 4, 2022
d40458f
change initial slab shape
butlerpd Mar 13, 2023
658ff7b
Add fold option to sector slicer
butlerpd Mar 20, 2023
fc18810
normalize box x and y width nomenclature
butlerpd Apr 9, 2023
49256d9
move new "direction" argument to end of list in case someone uses old…
butlerpd Jan 18, 2024
0add8a8
Fix group ID for sector slicer to avoid triggering updates to circula…
jack-rooks Jan 19, 2024
6691678
Revert change to setting the angle with a center angle of alpha (whic…
jack-rooks Jan 19, 2024
3e79c32
Remove the apparently duplicate plot.group_id and switch to using the…
jack-rooks Jan 19, 2024
ad4b50b
Prevent old slicer plots from reappearing when replotting the 2D data…
jack-rooks Jan 21, 2024
ed46cfd
Update slicer 2D data when 2D data is changed (should only apply to t…
jack-rooks Jan 21, 2024
0af0b09
Fix horizontal double lines not updating when dragged (problem refere…
jack-rooks Jan 21, 2024
e50bd5b
fix doc strings lost in the merge
butlerpd Jan 22, 2024
5f0cc3d
edit ci file to allow testing of installer which needs the sasdata co…
butlerpd Feb 22, 2024
6e237d1
Taking care of spurious file changes
butlerpd Mar 10, 2024
501fd12
Avoid deleting slicers with potentially important children (addresses…
jack-rooks Mar 28, 2024
9871d67
Tweaks based on review
butlerpd Mar 28, 2024
488902c
Merge remote-tracking branch 'origin/SlicerExtension_1344' into Slice…
butlerpd Apr 1, 2024
9f7706e
Fixes problem with binwidth calculation leading to errors.
butlerpd Apr 1, 2024
71d6a64
Fixes issues with empty ROI and duplicate code
butlerpd Apr 1, 2024
162cd56
Remove abs(width) from set params
butlerpd Apr 5, 2024
a464ebb
several doc string and comment fixes
butlerpd Apr 6, 2024
cdfc12b
Clean up the width nomenclature and simplify width calc code.
butlerpd Apr 6, 2024
71dcb1b
make graphical changes to ROI more robust
butlerpd Apr 9, 2024
969d92d
hardern error checking for slicer parameter editor box
butlerpd Apr 9, 2024
701706a
mostly cleanup and some final bug fixes
butlerpd Apr 10, 2024
cde0d2d
missed cleanup
butlerpd Apr 10, 2024
6f74525
Add Final validation on grahpical interaction of BoxSlicer.
butlerpd Apr 10, 2024
861e35a
One Final bon bon for box Slicer
butlerpd Apr 11, 2024
28f2930
Update ci.yml
butlerpd Apr 15, 2024
f438e51
Merge branch 'release_6.0.0' into SlicerExtension_1344
butlerpd Apr 19, 2024
b856ded
limit log.warning to one for each drag error
butlerpd Apr 22, 2024
978fadf
Change behavior of moving ROI box outside of data
butlerpd Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 89 additions & 4 deletions src/sas/qtgui/Plotting/Plotter2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def plot(self, data=None, marker=None, show_colorbar=True, update=False):
update=update)

self.updateCircularAverage()
self.updateSlicer()

def calculateDepth(self):
"""
Expand Down Expand Up @@ -338,8 +339,7 @@ def circularAverage(self):
else:
new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}")

new_plot.group_id = "2daverage" + self.data0.name
new_plot.id = "Circ avg " + self.data0.name
new_plot.id = "2daverage" + self.data0.name
new_plot.is_data = True

return new_plot
Expand Down Expand Up @@ -375,8 +375,8 @@ def updateCircularAverage(self):
# See if current item plots contain 2D average plot
has_plot = False
for plot in plots:
if plot.group_id is None: continue
if ca_caption in plot.group_id: has_plot = True
if plot.id is None: continue
if ca_caption in plot.id: has_plot = True
# return prematurely if no circular average plot found
if not has_plot: return

Expand All @@ -388,6 +388,32 @@ def updateCircularAverage(self):
# Show the new plot, if already visible
self.manager.communicator.plotUpdateSignal.emit([new_plot])

def updateSlicer(self):
"""
Update slicer plot on Data2D change
"""
if not hasattr(self, '_item'): return
item = self._item
if self._item.parent() is not None:
item = self._item.parent()
krzywon marked this conversation as resolved.
Show resolved Hide resolved

# Get all plots for current item
plots = GuiUtils.plotsFromModel("", item)
if plots is None: return
slicer_caption = 'Slicer' + self.data0.name
# See if current item plots contain slicer plot
has_plot = False
for plot in plots:
if not hasattr(plot, 'type_id') or plot.type_id is None: continue
if slicer_caption in plot.type_id: has_plot = True
# return prematurely if no slicer plot found
if not has_plot: return

# Now that we've identified the right plot, update the 2D data the slicer uses
self.slicer.data = self.data0
# Replot now that the 2D data is updated
self.slicer._post_data()

def setSlicer(self, slicer, reset=True):
"""
Clear the previous slicer and create a new one.
Expand All @@ -396,6 +422,65 @@ def setSlicer(self, slicer, reset=True):
# Clear current slicer
if self.slicer is not None:
self.slicer.clear()

# Clear the old slicer plots so they don't reappear later
if hasattr(self, '_item'):
item = self._item
if self._item.parent() is not None:
item = self._item.parent()

# Go through all items and see if they are a plot. The checks done here are not as thorough
# as GuiUtils.deleteRedundantPlots (which this takes a lot from). Will this cause problems?
# Primary concern is the check (plot_data.plot_role == DataRole.ROLE_DELETABLE) as I don't
# know what it does. The other checks seem to be related to keeping the new plots for that function
krzywon marked this conversation as resolved.
Show resolved Hide resolved
# TODO: generalize this and put it in GuiUtils so that we can use it elsewhere
tempPlotsToRemove = []
slicer_type_id = 'Slicer' + self.data0.name
for itemIndex in range(item.rowCount()):
# GuiUtils.plotsFromModel tests if the data is of type Data1D or Data2D to determine
# if it is a plot, so let's try that
if isinstance(item.child(itemIndex).data(), (Data1D, Data2D)):
# First take care of this item, then we'll take care of its children
if hasattr(item.child(itemIndex).data(), 'type_id'):
if slicer_type_id in item.child(itemIndex).data().type_id:
# At the time of writing, this should never be the case, but at some point the slicers may
# have relevant children (e.g. plots). We don't want to delete these slicers.
tempHasImportantChildren = False
for tempChildCheck in range(item.child(itemIndex).rowCount()):
# The data explorer uses the "text" attribute to set the name. If this has text='' then
# it can be deleted.
if item.child(itemIndex).child(tempChildCheck).text():
tempHasImportantChildren = True
if not tempHasImportantChildren:
# Store this plot to be removed later. Removing now
# will cause the next plot to be skipped
tempPlotsToRemove.append(item.child(itemIndex))
# It looks like the slicers are children of items that do not have data of instance Data1D or Data2D.
# Now do the children (1 level deep as is done in GuiUtils.plotsFromModel). Note that the slicers always
# seem to be the first entry (index2 == 0)
for itemIndex2 in range(item.child(itemIndex).rowCount()):
krzywon marked this conversation as resolved.
Show resolved Hide resolved
# Repeat what we did above (these if statements could probably be combined
# into one, but I'm not confident enough with how these work to say it wouldn't
# have issues if combined)
if isinstance(item.child(itemIndex).child(itemIndex2).data(), (Data1D, Data2D)):
if hasattr(item.child(itemIndex).child(itemIndex2).data(), 'type_id'):
if slicer_type_id in item.child(itemIndex).child(itemIndex2).data().type_id:
# Check for children we might want to keep (see the above loop)
tempHasImportantChildren = False
for tempChildCheck in range(item.child(itemIndex).child(itemIndex2).rowCount()):
# The data explorer uses the "text" attribute to set the name. If this has text=''
# then it can be deleted.
if item.child(itemIndex).child(itemIndex2).child(tempChildCheck).text():
tempHasImportantChildren = True
if not tempHasImportantChildren:
# Remove the parent since each slicer seems to generate a new entry in item
tempPlotsToRemove.append(item.child(itemIndex))
# Remove all the parent plots with matching criteria
for plot in tempPlotsToRemove:
item.removeRow(plot.row())
# Delete the temporary list of plots to remove
del tempPlotsToRemove

# Create a new slicer
self.slicer_z += 1
self.slicer = slicer(self, self.ax, item=self._item, zorder=self.slicer_z)
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Plotting/Slicers/AnnulusSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def _post_data(self, nbins=None):
new_plot.ytransform = 'y'
new_plot.yaxis("\\rm{Residuals} ", "/")

new_plot.group_id = "AnnulusPhi" + self.data.name
new_plot.id = "AnnulusPhi" + self.data.name
new_plot.type_id = "Slicer" + self.data.name # Used to remove plots after changing slicer so they don't keep showing up after closed
new_plot.is_data = True
new_plot.xtransform = "x"
new_plot.ytransform = "y"
Expand Down
4 changes: 2 additions & 2 deletions src/sas/qtgui/Plotting/Slicers/BaseInteractor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

interface_color = 'black'
disable_color = 'gray'
active_color = 'red'
Expand Down Expand Up @@ -138,8 +140,6 @@ def onDrag(self, ev):
if inside:
self.clickx, self.clicky = ev.xdata, ev.ydata
self.move(ev.xdata, ev.ydata, ev)
else:
self.restore(ev)
return True

def onKey(self, ev):
Expand Down
Loading
Loading