Skip to content

Commit

Permalink
fix: circularWell
Browse files Browse the repository at this point in the history
  • Loading branch information
fdrgsp committed Jul 11, 2024
1 parent a0e2541 commit 327c00c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ def __init__(
self,
plan: useq.RelativeMultiPointPlan | None = None,
well_size: tuple[float, float] | float | None = None,
is_well_circular: bool = True,
parent: QWidget | None = None,
) -> None:
super().__init__(parent=parent)

# well size
wdt: float | None
hgt: float | None
if isinstance(well_size, tuple):
wdt, hgt = well_size
elif isinstance(well_size, (int, float)):
elif isinstance(well_size, (int, float)) or well_size is None:
wdt = hgt = well_size
else:
wdt = hgt = None
self._well_width_µm: float | None = wdt * 1000 if wdt is not None else None
self._well_height_µm: float | None = hgt * 1000 if hgt is not None else None

self._is_well_circular = is_well_circular

self._selector = RelativePointPlanSelector()
# graphics scene to draw the well and the fovs
self._well_view = WellView()
self._well_view = WellView(self._is_well_circular)

# main
layout = QHBoxLayout(self)
Expand Down Expand Up @@ -123,9 +123,14 @@ def setWellSize(
if self._selector.active_plan_type is useq.RandomPoints:
self._on_selector_value_changed(self.value())

print(width)
print(w)
print(self._selector.random_points_wdg.max_width.maximum())
def circularWell(self) -> bool:
"""Return True if the well is circular, False otherwise."""
return self._is_well_circular

def setCircularWell(self, circular: bool) -> None:
"""Set the shape of the well."""
self._well_view.setCircularWell(circular)
self._on_selector_value_changed(self.value())

def _on_selector_value_changed(self, value: useq.RelativeMultiPointPlan) -> None:
self._well_view.setPointsPlan(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WellView(ResizingGraphicsView):
# emitted when a position is clicked, the value is a useq.RelativePosition
positionClicked = Signal(object)

def __init__(self, parent: QWidget | None = None):
def __init__(self, is_well_circular: bool, parent: QWidget | None = None):
self._scene = QGraphicsScene()

super().__init__(self._scene, parent)
Expand All @@ -46,7 +46,7 @@ def __init__(self, parent: QWidget | None = None):
self._well_height_um: float | None = 6000
self._fov_width_um: float | None = 400
self._fov_height_um: float | None = 340
self._is_circular: bool = False
self._is_well_circular: bool = True

# the item that draws the outline of the entire well area
self._well_outline_item: QGraphicsItem | None = None
Expand All @@ -65,16 +65,18 @@ def setWellSize(self, width_mm: float | None, height_mm: float | None) -> None:
self._well_width_um = (width_mm * 1000) if width_mm else None
self._well_height_um = (height_mm * 1000) if height_mm else None

def setCircularWell(self, circular: bool) -> None:
"""Set the shape of the well."""
self._is_well_circular = circular

def setPointsPlan(self, plan: useq.RelativeMultiPointPlan) -> None:
"""Set the plan to use to draw the FOVs."""
self._fov_width_um = plan.fov_width
self._fov_height_um = plan.fov_height
if hasattr(plan, "shape") and isinstance(plan.shape, Shape):
self._is_circular = plan.shape == Shape.ELLIPSE

# FOV POINTS BOUNDING AREA
if isinstance(plan, useq.RandomPoints):
self._draw_points_bounding_area(plan.max_width, plan.max_height)
self._draw_points_bounding_area(plan.max_width, plan.max_height, plan.shape)
elif self._points_bounding_area_item:
self._scene.removeItem(self._points_bounding_area_item)

Expand All @@ -94,13 +96,15 @@ def _draw_well_outline(self) -> None:

pen = QPen(QColor(Qt.GlobalColor.green))
pen.setWidth(self._scaled_pen_size())
if self._is_circular:
if self._is_well_circular:
self._well_outline_item = self._scene.addEllipse(rect, pen=pen)
else:
self._well_outline_item = self._scene.addRect(rect, pen=pen)
self._resize_to_fit()

def _draw_points_bounding_area(self, width: float, height: float) -> None:
def _draw_points_bounding_area(
self, width: float, height: float, shape: Shape
) -> None:
"""Draw the bounding area to constrain the FOVs."""
if self._points_bounding_area_item:
self._scene.removeItem(self._points_bounding_area_item)
Expand All @@ -112,7 +116,9 @@ def _draw_points_bounding_area(self, width: float, height: float) -> None:
pen.setWidth(self._scaled_pen_size())
pen.setStyle(Qt.PenStyle.DotLine)

if self._is_circular:
circular = shape == Shape.ELLIPSE

if circular:
self._points_bounding_area_item = self._scene.addEllipse(rect, pen=pen)
else:
self._points_bounding_area_item = self._scene.addRect(rect, pen=pen)
Expand Down Expand Up @@ -215,7 +221,7 @@ def _points_bounding_area_rect(self, width: float, height: float) -> QRectF:
return QRectF()
return (
QRectF(-width / 2, -height / 2, width, height)
if self._is_circular
if self._is_well_circular
else QRectF(-(width - (width / 2)), -(height - (height / 2)), width, height)
)

Expand Down

0 comments on commit 327c00c

Please sign in to comment.