Skip to content

Commit c4397b8

Browse files
committed
ROI editor: activate ROI selection tool by default, so that the user can select right away the area to be used as a ROI
Fix #154
1 parent 8a7cff6 commit c4397b8

4 files changed

Lines changed: 65 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ See DataLab [roadmap page](https://datalab-platform.com/en/contributing/roadmap.
66

77
💥 New features and enhancements:
88

9+
* Region of Interest (ROI) editor:
10+
* This concerns the "Edit Regions of Interest" feature for both signals and images
11+
* New behavior:
12+
* Signals: the range ROI selection tool is now active by default, and the user can select right away the range of the signal to be used as a ROI
13+
* Images: the rectangular ROI selection tool is now active by default, and the user can select right away the rectangular ROI to be used as a ROI
14+
* This closes [Issue #154](https://github.com/DataLab-Platform/DataLab/issues/154) - ROI editor: activate ROI selection tool by default, so that the user can select right away the area to be used as a ROI
15+
* Added the "Select tool" to editor's toolbar, to allow the user to switch between the "Select" and "Draw" tools easily without having to use the plot toolbar on the top of the window
916
* Signal processing features ("Processing" menu):
1017
* New "X-Y mode" feature: this feature simulates the behavior of the X-Y mode of an oscilloscope, i.e. it allows to plot one signal as a function of another signal (e.g. X as a function of Y)
1118

cdl/core/gui/roieditor.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
XRangeSelection,
4242
)
4343
from plotpy.plot import PlotDialog, PlotManager
44-
from plotpy.tools import CircleTool, HRangeTool, PolygonTool, RectangleTool
44+
from plotpy.tools import CircleTool, HRangeTool, PolygonTool, RectangleTool, SelectTool
4545
from qtpy import QtCore as QC
4646
from qtpy import QtWidgets as QW
4747

@@ -94,11 +94,10 @@ def configure_roi_item_in_tool(shape, obj: dlo.SignalObj | dlo.ImageObj) -> None
9494
configure_roi_item(shape, fmt, lbl=True, editable=True, option=obj.PREFIX)
9595

9696

97-
def tool_activate(tool: InteractiveTool) -> None:
98-
"""Tool activate"""
97+
def tool_deselect_items(tool: InteractiveTool) -> None:
98+
"""Deselect all items in plot associated with the tool"""
9999
plot = tool.get_active_plot()
100100
plot.select_some_items([]) # Deselect all items
101-
tool.activate()
102101

103102

104103
def tool_setup_shape(shape: TypeROIItem, obj: dlo.SignalObj | dlo.ImageObj) -> None:
@@ -114,10 +113,14 @@ class ROISegmentTool(HRangeTool):
114113
ICON = "signal_roi.svg"
115114

116115
def __init__(self, manager: PlotManager, obj: dlo.SignalObj) -> None:
117-
super().__init__(manager, switch_to_default_tool=True, toolbar_id=None)
116+
super().__init__(manager, switch_to_default_tool=False, toolbar_id=None)
118117
self.roi = SegmentROI([0, 1], False)
119118
self.obj = obj
120-
self.activate = tool_activate
119+
120+
def activate(self):
121+
"""Activate tool"""
122+
tool_deselect_items(self)
123+
super().activate()
121124

122125
def create_shape(self) -> XRangeSelection:
123126
"""Create shape"""
@@ -135,13 +138,17 @@ class ROIRectangleTool(RectangleTool):
135138
def __init__(self, manager: PlotManager, obj: dlo.ImageObj) -> None:
136139
super().__init__(
137140
manager,
138-
switch_to_default_tool=True,
141+
switch_to_default_tool=False,
139142
toolbar_id=None,
140143
setup_shape_cb=tool_setup_shape,
141144
)
142145
self.roi = RectangularROI([0, 0, 1, 1], True)
143146
self.obj = obj
144-
self.activate = tool_activate
147+
148+
def activate(self):
149+
"""Activate tool"""
150+
tool_deselect_items(self)
151+
super().activate()
145152

146153
def create_shape(self) -> tuple[AnnotatedRectangle, int, int]:
147154
"""Create shape"""
@@ -162,13 +169,17 @@ class ROICircleTool(CircleTool):
162169
def __init__(self, manager: PlotManager, obj: dlo.ImageObj) -> None:
163170
super().__init__(
164171
manager,
165-
switch_to_default_tool=True,
172+
switch_to_default_tool=False,
166173
toolbar_id=None,
167174
setup_shape_cb=tool_setup_shape,
168175
)
169176
self.roi = CircularROI([0, 0, 1], True)
170177
self.obj = obj
171-
self.activate = tool_activate
178+
179+
def activate(self):
180+
"""Activate tool"""
181+
tool_deselect_items(self)
182+
super().activate()
172183

173184
def create_shape(self) -> tuple[AnnotatedCircle, int, int]:
174185
"""Create shape"""
@@ -189,13 +200,17 @@ class ROIPolygonTool(PolygonTool):
189200
def __init__(self, manager: PlotManager, obj: dlo.ImageObj) -> None:
190201
super().__init__(
191202
manager,
192-
switch_to_default_tool=True,
203+
switch_to_default_tool=False,
193204
toolbar_id=None,
194205
setup_shape_cb=tool_setup_shape,
195206
)
196207
self.roi = PolygonalROI([[0, 0], [1, 0], [1, 1], [0, 1]], True)
197208
self.obj = obj
198-
self.activate = tool_activate
209+
210+
def activate(self):
211+
"""Activate tool"""
212+
tool_deselect_items(self)
213+
super().activate()
199214

200215
def create_shape(self) -> tuple[AnnotatedPolygon, int, int]:
201216
"""Create shape"""
@@ -251,6 +266,9 @@ def __init__(
251266
self.__roi.iterate_roi_items(obj, fmt, True, True)
252267
)
253268

269+
mgr = self.plot_dialog.get_manager()
270+
select_tool = mgr.get_tool(SelectTool)
271+
add_actions(self.toolbar, [select_tool.action])
254272
self.add_tools_to_plot_dialog()
255273
item = obj.make_item() if item is None else item
256274
item.set_selectable(False)
@@ -371,7 +389,7 @@ def setup_widget(self) -> None:
371389
layout.addWidget(self.toolbar)
372390
if self.extract:
373391
self.singleobj_btn = QW.QCheckBox(
374-
_("Extract all ROIs into a single %s object") % self.OBJ_NAME,
392+
_("Extract all ROIs\ninto a single %s") % self.OBJ_NAME,
375393
self,
376394
)
377395
layout.addWidget(self.singleobj_btn)
@@ -456,6 +474,7 @@ def add_tools_to_plot_dialog(self) -> None:
456474
mgr = self.plot_dialog.get_manager()
457475
segm_tool = mgr.add_tool(ROISegmentTool, self.obj)
458476
self._tools.append(segm_tool)
477+
segm_tool.activate()
459478

460479
def manually_add_roi(self) -> None:
461480
"""Manually add segment ROI"""
@@ -517,6 +536,7 @@ def add_tools_to_plot_dialog(self) -> None:
517536
circ_tool = mgr.add_tool(ROICircleTool, self.obj)
518537
poly_tool = mgr.add_tool(ROIPolygonTool, self.obj)
519538
self._tools.extend([rect_tool, circ_tool, poly_tool])
539+
rect_tool.activate()
520540

521541
def manually_add_roi(
522542
self, roi_type: Literal["rectangle", "circle", "polygon"]

cdl/locale/fr/LC_MESSAGES/cdl.po

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
msgid ""
55
msgstr ""
66
"Project-Id-Version: PACKAGE VERSION\n"
7-
"POT-Creation-Date: 2025-04-03 14:36+0200\n"
7+
"POT-Creation-Date: 2025-04-05 11:49+0200\n"
88
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
99
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1010
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2305,8 +2305,8 @@ msgstr "ROI par coordonnées"
23052305
msgid "Remove all"
23062306
msgstr "Supprimer tout"
23072307

2308-
msgid "Extract all ROIs into a single %s object"
2309-
msgstr "Extraire toutes les ROI dans un seul objet %s"
2308+
msgid "Extract all ROIs\ninto a single %s"
2309+
msgstr "Extraire toutes les ROI\ndans un seul objet %s"
23102310

23112311
msgid "Remove all ROIs"
23122312
msgstr "Supprimer toutes les ROI"

doc/locale/fr/LC_MESSAGES/contributing/changelog.po

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: DataLab \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2025-04-05 10:44+0200\n"
10+
"POT-Creation-Date: 2025-04-05 11:54+0200\n"
1111
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1212
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1313
"Language: fr\n"
@@ -30,6 +30,27 @@ msgstr "DataLab Version 0.20.0"
3030
msgid "💥 New features and enhancements:"
3131
msgstr "💥 Nouvelles fonctionnalités et améliorations :"
3232

33+
msgid "Region of Interest (ROI) editor:"
34+
msgstr "Éditeur de région d'intérêt (ROI) :"
35+
36+
msgid "This concerns the \"Edit Regions of Interest\" feature for both signals and images"
37+
msgstr "Cela concerne la fonctionnalité \"Éditer les régions d'intérêt\" pour les signaux et les images"
38+
39+
msgid "New behavior:"
40+
msgstr "Nouveau comportement :"
41+
42+
msgid "Signals: the range ROI selection tool is now active by default, and the user can select right away the range of the signal to be used as a ROI"
43+
msgstr "Signaux : l'outil de sélection de la plage ROI est désormais actif par défaut, et l'utilisateur peut sélectionner immédiatement la plage du signal à utiliser comme ROI"
44+
45+
msgid "Images: the rectangular ROI selection tool is now active by default, and the user can select right away the rectangular ROI to be used as a ROI"
46+
msgstr "Images : l'outil de sélection de la ROI rectangulaire est désormais actif par défaut, et l'utilisateur peut sélectionner immédiatement la ROI rectangulaire à utiliser comme ROI"
47+
48+
msgid "This closes [Issue #154](https://github.com/DataLab-Platform/DataLab/issues/154) - ROI editor: activate ROI selection tool by default, so that the user can select right away the area to be used as a ROI"
49+
msgstr "Ceci clotûre le ticket [Issue #154](https://github.com/DataLab-Platform/DataLab/issues/154) - Éditeur de ROI : activer l'outil de sélection de ROI par défaut, afin que l'utilisateur puisse sélectionner immédiatement la zone à utiliser comme ROI"
50+
51+
msgid "Added the \"Select tool\" to editor's toolbar, to allow the user to switch between the \"Select\" and \"Draw\" tools easily without having to use the plot toolbar on the top of the window"
52+
msgstr "Ajout de l'outil \"Sélectionner\" à la barre d'outils de l'éditeur, pour permettre à l'utilisateur de basculer facilement entre les outils \"Sélectionner\" et \"Dessiner\" sans avoir à utiliser la barre d'outils de tracé en haut de la fenêtre"
53+
3354
msgid "Signal processing features (\"Processing\" menu):"
3455
msgstr "Fonctionnalités de traitement du signal (menu \"Traitement\") :"
3556

0 commit comments

Comments
 (0)