From 327c00c1154d141c4d59e168fc5bc7913b7e86bf Mon Sep 17 00:00:00 2001 From: fdrgsp Date: Thu, 11 Jul 2024 13:16:27 -0400 Subject: [PATCH] fix: circularWell --- .../points_plans/_points_plan_widget.py | 21 +++++++++------- .../points_plans/_well_graphics_view.py | 24 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/pymmcore_widgets/useq_widgets/points_plans/_points_plan_widget.py b/src/pymmcore_widgets/useq_widgets/points_plans/_points_plan_widget.py index 3300c3ec3..2b7757145 100644 --- a/src/pymmcore_widgets/useq_widgets/points_plans/_points_plan_widget.py +++ b/src/pymmcore_widgets/useq_widgets/points_plans/_points_plan_widget.py @@ -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) @@ -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) diff --git a/src/pymmcore_widgets/useq_widgets/points_plans/_well_graphics_view.py b/src/pymmcore_widgets/useq_widgets/points_plans/_well_graphics_view.py index 44fb937b8..cb760d9f2 100644 --- a/src/pymmcore_widgets/useq_widgets/points_plans/_well_graphics_view.py +++ b/src/pymmcore_widgets/useq_widgets/points_plans/_well_graphics_view.py @@ -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) @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) )