Skip to content

Commit a44b1c5

Browse files
committed
feat(roi): refactor ROI editing functions and update UI labels for clarity
1 parent def1981 commit a44b1c5

3 files changed

Lines changed: 57 additions & 88 deletions

File tree

‎src/App.tsx‎

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,29 +2546,24 @@ export default function App() {
25462546
[runtime, currentId],
25472547
);
25482548

2549-
const handleEditRoi = useCallback(async () => {
2550-
if (!runtime || !currentId) return;
2551-
const segs = await runtime.getSignalRoi(currentId);
2552-
// "Edit numerically" now opens the docked ROI panel (no modal) with
2553-
// the coordinate form, selecting the first ROI. Drawing stays
2554-
// disarmed so the plot keeps pan/zoom until the user picks a tool.
2549+
const handleToggleRoiEditMode = useCallback(async () => {
2550+
if (roiEditMode) {
2551+
// Leaving the editor: disarm drawing and clear the active selection.
2552+
setRoiEditMode(false);
2553+
setRoiDrawGeometry(null);
2554+
setSelectedRoiIndex(null);
2555+
return;
2556+
}
2557+
// Entering the unified ROI editor: load the current ROI, arm the
2558+
// range-draw tool so a first ROI can be traced immediately, and
2559+
// pre-select the first ROI (if any) so its coordinate form opens at once.
2560+
const segs =
2561+
runtime && currentId ? await runtime.getSignalRoi(currentId) : [];
25552562
setRoi(segs);
2556-
setRoiDrawGeometry(null);
2563+
setRoiDrawGeometry("segment");
25572564
setSelectedRoiIndex(segs.length > 0 ? 0 : null);
25582565
setRoiEditMode(true);
2559-
}, [runtime, currentId]);
2560-
2561-
const handleToggleRoiEditMode = useCallback(() => {
2562-
setRoiEditMode((m) => {
2563-
const next = !m;
2564-
// Entering edit mode arms the range-draw tool so the user can trace
2565-
// a first ROI immediately (even when none exists yet); leaving it
2566-
// disarms drawing and clears the active selection.
2567-
setRoiDrawGeometry(next ? "segment" : null);
2568-
if (!next) setSelectedRoiIndex(null);
2569-
return next;
2570-
});
2571-
}, []);
2566+
}, [roiEditMode, runtime, currentId]);
25722567

25732568
// Live-edit callback fed by the plot when the user drags a ROI handle or
25742569
// draws a brand-new rectangle in edit mode. The backend is updated with
@@ -2758,16 +2753,6 @@ export default function App() {
27582753
// Image ROI handlers (Phase 13)
27592754
// ------------------------------------------------------------------
27602755

2761-
const handleImageEditRoi = useCallback(async () => {
2762-
if (!runtime || !currentId) return;
2763-
const segs = await runtime.getImageRoi(currentId);
2764-
// Open the docked ROI panel (no modal) with the coordinate form.
2765-
setImageRoi(segs);
2766-
setRoiDrawGeometry(null);
2767-
setSelectedRoiIndex(segs.length > 0 ? 0 : null);
2768-
setImageRoiEditMode(true);
2769-
}, [runtime, currentId]);
2770-
27712756
const handleImageAddRectangle = useCallback(async () => {
27722757
if (!runtime || !currentId || !imageData) return;
27732758
const sx = (imageData.width * imageData.dx) / 4 || 1;
@@ -2813,22 +2798,26 @@ export default function App() {
28132798
await runtime.setImageRoi(currentId, next);
28142799
}, [runtime, currentId, imageRoi, imageData]);
28152800

2816-
const handleToggleImageRoiEditMode = useCallback(() => {
2817-
setImageRoiEditMode((m) => {
2818-
const next = !m;
2819-
// Entering edit mode arms the rectangle-draw tool so a first ROI can
2820-
// be traced right away; leaving it disarms drawing and clears the
2821-
// active selection. ROI editing and the erase session are mutually
2822-
// exclusive, so entering one leaves the other.
2823-
setRoiDrawGeometry(next ? "rectangle" : null);
2824-
if (next) {
2825-
setImageEraseMode(false);
2826-
setEraseRegions([]);
2827-
}
2828-
if (!next) setSelectedRoiIndex(null);
2829-
return next;
2830-
});
2831-
}, []);
2801+
const handleToggleImageRoiEditMode = useCallback(async () => {
2802+
if (imageRoiEditMode) {
2803+
setImageRoiEditMode(false);
2804+
setRoiDrawGeometry(null);
2805+
setSelectedRoiIndex(null);
2806+
return;
2807+
}
2808+
// Entering the unified ROI editor: load the current ROI, arm the
2809+
// rectangle-draw tool, and pre-select the first ROI (if any) so its
2810+
// coordinate form opens at once. ROI editing and the erase session are
2811+
// mutually exclusive, so entering one leaves the other.
2812+
const segs =
2813+
runtime && currentId ? await runtime.getImageRoi(currentId) : [];
2814+
setImageRoi(segs);
2815+
setImageEraseMode(false);
2816+
setEraseRegions([]);
2817+
setRoiDrawGeometry("rectangle");
2818+
setSelectedRoiIndex(segs.length > 0 ? 0 : null);
2819+
setImageRoiEditMode(true);
2820+
}, [imageRoiEditMode, runtime, currentId]);
28322821

28332822
// Live-edit callback fed by the plot when the user drags a ROI handle
28342823
// or draws a brand-new shape in edit mode. The backend is updated with
@@ -3903,7 +3892,6 @@ export default function App() {
39033892
...(treeKind === "signal"
39043893
? buildRoiActions(roi, roiEditMode, hasRoiClipboard, {
39053894
onToggleEditMode: handleToggleRoiEditMode,
3906-
onEditNumerically: handleEditRoi,
39073895
onExtractEach: handleRoiExtractEach,
39083896
onExtractMerged: handleRoiExtractMerged,
39093897
onCopy: handleRoiCopy,
@@ -3918,7 +3906,6 @@ export default function App() {
39183906
onAddRectangle: handleImageAddRectangle,
39193907
onAddCircle: handleImageAddCircle,
39203908
onCreateGrid: handleCreateRoiGrid,
3921-
onEditNumerically: handleImageEditRoi,
39223909
onExtractEach: handleImageRoiExtractEach,
39233910
onExtractMerged: handleImageRoiExtractMerged,
39243911
onCopy: handleImageRoiCopy,
@@ -3955,7 +3942,6 @@ export default function App() {
39553942
handleDeleteAll,
39563943
handleApplyFeature,
39573944
handleEditProperties,
3958-
handleEditRoi,
39593945
handleToggleRoiEditMode,
39603946
handleRoiExtractEach,
39613947
handleRoiExtractMerged,
@@ -3968,7 +3954,6 @@ export default function App() {
39683954
handleImageAddRectangle,
39693955
handleImageAddCircle,
39703956
handleCreateRoiGrid,
3971-
handleImageEditRoi,
39723957
handleImageRoiExtractEach,
39733958
handleToggleImageRoiEditMode,
39743959
handleImageRoiExtractMerged,

‎src/actions/registry.ts‎

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,8 @@ function buildAnalysisActions(
737737

738738
/** Callbacks for the ``ROI`` top-level menu (mirrors DataLab desktop). */
739739
export interface RoiActionCallbacks {
740-
/** Toggle the interactive (drag/draw) ROI editor on the plot. */
740+
/** Toggle the docked ROI editor (draw + coordinate table) on the plot. */
741741
onToggleEditMode: () => void;
742-
/** Open the numerical ROI dialog. */
743-
onEditNumerically: () => void;
744742
/** Extract one new signal per ROI (1-to-n). */
745743
onExtractEach: () => void;
746744
/** Extract a single new signal containing the concatenation of all ROIs. */
@@ -776,23 +774,17 @@ export function buildRoiActions(
776774
ready(s) && (roi.length > 0 || s.selectionHasRoi);
777775
const out: ActionDescriptor[] = [
778776
{
779-
id: "roi.edit_graphical",
780-
label: roiEditMode ? t("Stop graphical edit") : t("Edit graphically"),
777+
id: "roi.edit",
778+
label: roiEditMode
779+
? t("Stop editing regions of interest")
780+
: t("Edit regions of interest"),
781781
menuPath: roiEditMode
782-
? "ROI/Stop graphical edit"
783-
: "ROI/Edit graphically",
782+
? "ROI/Stop editing regions of interest"
783+
: "ROI/Edit regions of interest",
784784
iconUrl: getRoiIconUrl("roi_graphical"),
785785
enabled: ready,
786786
run: cb.onToggleEditMode,
787787
},
788-
{
789-
id: "roi.edit_numerical",
790-
label: t("Edit numerically…"),
791-
menuPath: "ROI/Edit numerically…",
792-
iconUrl: getRoiIconUrl("roi_coordinate"),
793-
enabled: ready,
794-
run: cb.onEditNumerically,
795-
},
796788
{
797789
id: "roi.copy",
798790
label: t("Copy ROI"),
@@ -884,13 +876,11 @@ export function buildRoiActions(
884876

885877
/** Callbacks for the image ``ROI`` top-level menu. */
886878
export interface ImageRoiActionCallbacks {
887-
/** Toggle the interactive (drag/draw) ROI editor on the plot. */
879+
/** Toggle the docked ROI editor (draw + coordinate table) on the plot. */
888880
onToggleEditMode: () => void;
889-
/** Open the numerical ROI dialog (rectangle/circle/polygon editor). */
890-
onEditNumerically: () => void;
891-
/** Append a new default rectangle ROI then open the numerical dialog. */
881+
/** Append a new default rectangle ROI then open the editor panel. */
892882
onAddRectangle: () => void;
893-
/** Append a new default circle ROI then open the numerical dialog. */
883+
/** Append a new default circle ROI then open the editor panel. */
894884
onAddCircle: () => void;
895885
/** Open the "Create ROI grid" dialog and replace the current image's ROI
896886
* with a generated grid of rectangles. */
@@ -930,11 +920,13 @@ export function buildImageRoiActions(
930920
ready(s) && (roi.length > 0 || s.selectionHasRoi);
931921
const out: ActionDescriptor[] = [
932922
{
933-
id: "image_roi.edit_graphical",
934-
label: roiEditMode ? t("Stop graphical edit") : t("Edit graphically"),
923+
id: "image_roi.edit",
924+
label: roiEditMode
925+
? t("Stop editing regions of interest")
926+
: t("Edit regions of interest"),
935927
menuPath: roiEditMode
936-
? "ROI/Stop graphical edit"
937-
: "ROI/Edit graphically",
928+
? "ROI/Stop editing regions of interest"
929+
: "ROI/Edit regions of interest",
938930
iconUrl: getRoiIconUrl("roi_graphical"),
939931
enabled: ready,
940932
run: cb.onToggleEditMode,
@@ -964,15 +956,6 @@ export function buildImageRoiActions(
964956
enabled: ready,
965957
run: cb.onCreateGrid,
966958
},
967-
{
968-
id: "image_roi.edit_numerical",
969-
label: t("Edit numerically…"),
970-
menuPath: "ROI/Edit numerically…",
971-
iconUrl: getRoiIconUrl("roi_coordinate"),
972-
beginGroup: true,
973-
enabled: ready,
974-
run: cb.onEditNumerically,
975-
},
976959
{
977960
id: "image_roi.copy",
978961
label: t("Copy ROI"),

‎src/locales/fr.json‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,10 @@
329329
"Edit": "Édition",
330330
"Edit array": "Éditer le tableau",
331331
"Edit data…": "Éditer les données…",
332-
"Edit graphically": "Éditer graphiquement",
333332
"Edit metadata": "Modifier les métadonnées",
334-
"Edit numerically…": "Éditer numériquement…",
335333
"Edit parameters of: {label}": "Modifier les paramètres de : {label}",
336334
"Edit pixel values in a spreadsheet": "Éditer les valeurs des pixels dans un tableur",
335+
"Edit regions of interest": "Modifier les régions d'intérêt",
337336
"Edit X / Y values in a spreadsheet": "Éditer les valeurs X / Y dans un tableur",
338337
"Edit…": "Éditer…",
339338
"empty array": "tableau vide",
@@ -343,7 +342,6 @@
343342
"Endpoint preset": "Préréglage de point de terminaison",
344343
"Enhance your security on the web": "Améliorer votre sécurité sur le web",
345344
"Enhanced security mode site preferences": "Préférences de site pour une sécurité renforcée",
346-
"Erase": "Effacer",
347345
"Erase area": "Effacer une zone",
348346
"Erase area…": "Effacer une zone…",
349347
"Erosion (disk)": "Erosion (disque)",
@@ -873,7 +871,7 @@
873871
"Sticks": "Bâtons",
874872
"Stop": "Arrêter",
875873
"Stop current macro": "Arrêter la macro courante",
876-
"Stop graphical edit": "Arrêter l'édition graphique",
874+
"Stop editing regions of interest": "Arrêter la modification des régions d'intérêt",
877875
"Stop the assistant (Esc)": "Arrêter l'assistant (Échap)",
878876
"Store data on disk": "Stocker les données sur disque",
879877
"Subtract constant": "Soustraire une constante",
@@ -985,6 +983,10 @@
985983
"Zero padding": "Complément de zéros",
986984
"Zero padding…": "Complément de zéros…",
987985
"Zoom in / out around the cursor (Plotly default)": "Zoom avant / arrière autour du curseur (par défaut Plotly)",
986+
"Edit graphically": "Éditer graphiquement",
987+
"Edit numerically…": "Éditer numériquement…",
988+
"Erase": "Effacer",
989+
"Stop graphical edit": "Arrêter l'édition graphique",
988990
"Circle center must be a number.": "Le centre du cercle doit être un nombre.",
989991
"Circle radius must be > 0.": "Le rayon du cercle doit être > 0.",
990992
"Edit image regions of interest": "Modifier les régions d'intérêt de l'image",
@@ -997,6 +999,5 @@
997999
"Vertices (space-separated": "Sommets (paires",
9981000
"All bounds must be valid numbers.": "Toutes les bornes doivent être des nombres valides.",
9991001
"Each segment must satisfy xmin < xmax.": "Chaque segment doit respecter xmin < xmax.",
1000-
"Edit regions of interest": "Modifier les régions d'intérêt",
10011002
"No ROI defined. Click Add to create one.": "Aucune ROI définie. Cliquez sur Ajouter pour en créer une."
10021003
}

0 commit comments

Comments
 (0)