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

Added a way for Shape to preserve user preferred state #1044

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 21 additions & 5 deletions mxcubecore/HardwareObjects/SampleView.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
from PIL import Image

from mxcubecore import HardwareRepository as HWR
from mxcubecore.HardwareObjects.abstract.AbstractSampleView import AbstractSampleView
from mxcubecore.HardwareObjects.abstract.AbstractSampleView import (
AbstractSampleView,
ShapeState,
)
from mxcubecore.model import queue_model_objects


Expand Down Expand Up @@ -179,7 +182,9 @@ def add_shape(self, shape):
self.shapes[shape.id] = shape
shape.shapes_hw_object = self

def add_shape_from_mpos(self, mpos_list, screen_coord, t):
def add_shape_from_mpos(
self, mpos_list, screen_coord, t, state: ShapeState = "SAVED", user_state: ShapeState = "SAVED"
):
"""
Adds a shape of type <t>, with motor positions from mpos_list and
screen position screen_coord.
Expand All @@ -198,11 +203,15 @@ def add_shape_from_mpos(self, mpos_list, screen_coord, t):

if _cls:
shape = _cls(mpos_list, screen_coord)
# In case the shape is being recreated, we need to restore it's state.
shape.state = state
shape.user_state = user_state

self.add_shape(shape)

return shape

def add_shape_from_refs(self, refs, t):
def add_shape_from_refs(self, refs, t, state: ShapeState = "SAVED", user_state: ShapeState = "SAVED"):
"""
Adds a shape of type <t>, taking motor positions and screen positions
from reference points in refs.
Expand All @@ -217,7 +226,7 @@ def add_shape_from_refs(self, refs, t):
mpos = [self.get_shape(refid).mpos() for refid in refs]
spos_list = [self.get_shape(refid).screen_coord for refid in refs]
spos = reduce((lambda x, y: tuple(x) + tuple(y)), spos_list, ())
shape = self.add_shape_from_mpos(mpos, spos, t)
shape = self.add_shape_from_mpos(mpos, spos, t, state, user_state)
shape.refs = refs

return shape
Expand Down Expand Up @@ -457,7 +466,10 @@ def __init__(self, mpos_list=[], screen_coord=(-1, -1)):
self.id = ""
self.cp_list = []
self.name = ""
self.state = "SAVED"
self.state: ShapeState = "SAVED"
self.user_state: ShapeState = (
"SAVED" # used to persist user preferences in regards wether to show or hide particular shape.
)
self.label = ""
self.screen_coord = screen_coord
self.selected = False
Expand Down Expand Up @@ -619,6 +631,10 @@ def update_position(self, transform):
phi_pos = HWR.beamline.diffractometer.omega.get_value() % 360
_d = abs((self.get_centred_position().phi % 360) - phi_pos)

if self.user_state == "HIDDEN":
self.state = "HIDDEN"
return

if min(_d, 360 - _d) > self.shapes_hw_object.hide_grid_threshold:
self.state = "HIDDEN"
else:
Expand Down
12 changes: 10 additions & 2 deletions mxcubecore/HardwareObjects/abstract/AbstractSampleView.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
__license__ = "LGPLv3+"

import abc
from typing import Union
from typing import (
Literal,
Union,
)

from mxcubecore.BaseHardwareObjects import HardwareObject

ShapeState = Literal["HIDDEN", "SAVED", "TMP"]


class AbstractSampleView(HardwareObject):
"""AbstractSampleView Class"""
Expand Down Expand Up @@ -153,13 +158,16 @@ def add_shape(self, shape):
return

@abc.abstractmethod
def add_shape_from_mpos(self, mpos_list, screen_cord, _type):
def add_shape_from_mpos(
self, mpos_list, screen_cord, _type, state: ShapeState = "SAVED", user_state: ShapeState = "SAVED"
):
"""Add a shape of type <t>, with motor positions from mpos_list and
screen position screen_coord.
Args:
mpos_list (list[mpos_list]): List of motor positions
screen_coord (tuple(x, y): Screen cordinate for shape
_type (str): Type str for shape, P (Point), L (Line), G (Grid)
user_state (ShapeState): State of the shape set by the user
Returns:
(Shape): Shape of type _type
"""
Expand Down
Loading