Skip to content

Commit

Permalink
Require cartesian distance to be positive
Browse files Browse the repository at this point in the history
It is expected to always be positive now, so enforce this in the GUI,
and handle old settings where it may have been negative.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Dec 18, 2024
1 parent 5d1ef9c commit 38f7d64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
21 changes: 17 additions & 4 deletions hexrdgui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ def load_from_state(self, state):
pinhole_settings.pop('pinhole_radius') * 2
)

if self.cartesian_virtual_plane_distance < 0:
# We used to allow this to be negative, but now must be positive.
# Taking the absolute value should correct this adequately.
self.cartesian_virtual_plane_distance = abs(
self.cartesian_virtual_plane_distance)

# All QSettings come back as strings. So check that we are dealing with
# a boolean and convert if necessary
if not isinstance(self.live_update, bool):
Expand Down Expand Up @@ -2511,7 +2517,8 @@ def _cartesian_pixel_size(self):
def _set_cartesian_pixel_size(self, v):
if v != self.cartesian_pixel_size:
self.config['image']['cartesian']['pixel_size'] = v
self.rerender_needed.emit()
if self.image_mode == constants.ViewType.cartesian:
self.rerender_needed.emit()

cartesian_pixel_size = property(_cartesian_pixel_size,
_set_cartesian_pixel_size)
Expand All @@ -2520,9 +2527,13 @@ def _cartesian_virtual_plane_distance(self):
return self.config['image']['cartesian']['virtual_plane_distance']

def set_cartesian_virtual_plane_distance(self, v):
if v < 0:
raise RuntimeError(f'Invalid plane distance: {v}')

if v != self.cartesian_virtual_plane_distance:
self.config['image']['cartesian']['virtual_plane_distance'] = v
self.rerender_needed.emit()
if self.image_mode == constants.ViewType.cartesian:
self.rerender_needed.emit()

cartesian_virtual_plane_distance = property(
_cartesian_virtual_plane_distance,
Expand All @@ -2534,7 +2545,8 @@ def _cartesian_plane_normal_rotate_x(self):
def set_cartesian_plane_normal_rotate_x(self, v):
if v != self.cartesian_plane_normal_rotate_x:
self.config['image']['cartesian']['plane_normal_rotate_x'] = v
self.rerender_needed.emit()
if self.image_mode == constants.ViewType.cartesian:
self.rerender_needed.emit()

cartesian_plane_normal_rotate_x = property(
_cartesian_plane_normal_rotate_x,
Expand All @@ -2546,7 +2558,8 @@ def _cartesian_plane_normal_rotate_y(self):
def set_cartesian_plane_normal_rotate_y(self, v):
if v != self.cartesian_plane_normal_rotate_y:
self.config['image']['cartesian']['plane_normal_rotate_y'] = v
self.rerender_needed.emit()
if self.image_mode == constants.ViewType.cartesian:
self.rerender_needed.emit()

cartesian_plane_normal_rotate_y = property(
_cartesian_plane_normal_rotate_y,
Expand Down
3 changes: 3 additions & 0 deletions hexrdgui/image_mode_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self, parent=None):
# Always start with raw tab
self.ui.tab_widget.setCurrentIndex(0)

# Don't allow negative distances
self.ui.cartesian_virtual_plane_distance.setMinimum(1e-8)

# Hide stereo_project_from_polar for now, as projecting from polar
# appears to give a better image (lines up better with overlays)
# than projecting from raw.
Expand Down
5 changes: 4 additions & 1 deletion hexrdgui/resources/ui/image_mode_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>1</number>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -167,6 +167,9 @@
<property name="decimals">
<number>8</number>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
Expand Down

0 comments on commit 38f7d64

Please sign in to comment.