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

Show measurement tool in read-only mode #8334

Merged
merged 14 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions frontend/javascripts/oxalis/model/reducers/ui_reducer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AnnotationToolEnum, ControlModeEnum } from "oxalis/constants";
import type { Action } from "oxalis/model/actions/actions";
import { updateKey, updateKey2 } from "oxalis/model/helpers/deep_update";
import {
Expand All @@ -8,6 +9,12 @@ import {
import { hideBrushReducer } from "oxalis/model/reducers/volumetracing_reducer_helpers";
import type { OxalisState } from "oxalis/store";

const ALLOWED_TOOLS_IN_VIEW_MODE = [
AnnotationToolEnum.MOVE,
AnnotationToolEnum.AREA_MEASUREMENT,
AnnotationToolEnum.LINE_MEASUREMENT,
]; // TODO_c make prettier

function UiReducer(state: OxalisState, action: Action): OxalisState {
switch (action.type) {
case "SET_DROPZONE_MODAL_VISIBILITY": {
Expand Down Expand Up @@ -54,6 +61,11 @@ function UiReducer(state: OxalisState, action: Action): OxalisState {
}

case "SET_TOOL": {
if (state.temporaryConfiguration.controlMode === ControlModeEnum.VIEW) {
if (ALLOWED_TOOLS_IN_VIEW_MODE.includes(AnnotationToolEnum[action.tool])) {
return setToolReducer(state, action.tool);
}
}
if (!state.tracing.restrictions.allowUpdate) {
return state;
}
Expand Down
45 changes: 27 additions & 18 deletions frontend/javascripts/oxalis/view/action-bar/toolbar_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { document } from "libs/window";
import {
type AnnotationTool,
AnnotationToolEnum,
ControlModeEnum,
FillModeEnum,
type InterpolationMode,
InterpolationModeEnum,
Expand Down Expand Up @@ -126,6 +127,7 @@ const handleToggleSelectiveVisibilityInProofreading = (value: boolean) => {
const handleSetTool = (event: RadioChangeEvent) => {
const value = event.target.value as AnnotationTool;
Store.dispatch(setToolAction(value));
console.log("Tool set to", value);
knollengewaechs marked this conversation as resolved.
Show resolved Hide resolved
};

const handleCreateCell = () => {
Expand Down Expand Up @@ -847,8 +849,11 @@ const TOOL_NAMES = {

export default function ToolbarView() {
const dispatch = useDispatch();
const hasVolume = useSelector((state: OxalisState) => state.tracing.volumes.length > 0);
const hasSkeleton = useSelector((state: OxalisState) => state.tracing.skeleton != null);
const hasVolume = useSelector((state: OxalisState) => state.tracing?.volumes.length > 0);
const hasSkeleton = useSelector((state: OxalisState) => state.tracing?.skeleton != null);
const isViewMode = useSelector(
(state: OxalisState) => state.temporaryConfiguration.controlMode === ControlModeEnum.VIEW,
);
const isAgglomerateMappingEnabled = useSelector(hasAgglomerateMapping);

const [lastForcefullyDisabledTool, setLastForcefullyDisabledTool] =
Expand Down Expand Up @@ -1103,22 +1108,26 @@ export default function ToolbarView() {
</ToolRadioButton>
</React.Fragment>
) : null}
<ToolRadioButton
name={TOOL_NAMES.BOUNDING_BOX}
description="Create, resize and modify bounding boxes."
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].isDisabled}
value={AnnotationToolEnum.BOUNDING_BOX}
>
<img
src="/assets/images/bounding-box.svg"
alt="Bounding Box Icon"
style={{
opacity: disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].isDisabled ? 0.5 : 1,
...imgStyleForSpaceyIcons,
}}
/>
</ToolRadioButton>
{!isViewMode && (
<ToolRadioButton
name={TOOL_NAMES.BOUNDING_BOX}
description="Create, resize and modify bounding boxes."
disabledExplanation={disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].explanation}
disabled={disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].isDisabled}
value={AnnotationToolEnum.BOUNDING_BOX}
>
<img
src="/assets/images/bounding-box.svg"
alt="Bounding Box Icon"
style={{
opacity: disabledInfosForTools[AnnotationToolEnum.BOUNDING_BOX].isDisabled
? 0.5
: 1,
...imgStyleForSpaceyIcons,
}}
/>
</ToolRadioButton>
)}

{hasSkeleton && hasVolume ? (
<ToolRadioButton
Expand Down
4 changes: 2 additions & 2 deletions frontend/javascripts/oxalis/view/action_bar_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class ActionBarView extends React.PureComponent<Props, State> {
const {
dataset,
is2d,
isReadOnly,
isReadOnly, // TODO_c are there any cases where this is true, that are not read-only annotations or view mode?
showVersionRestore,
controlMode,
hasSkeleton,
Expand Down Expand Up @@ -298,7 +298,7 @@ class ActionBarView extends React.PureComponent<Props, State> {
{getIsAIAnalysisEnabled() && isAdminOrDatasetManager
? this.renderStartAIJobButton(shouldDisableAIJobButton, tooltip)
: null}
{!isReadOnly && constants.MODES_PLANE.indexOf(viewMode) > -1 ? <ToolbarView /> : null}
{constants.MODES_PLANE.indexOf(viewMode) > -1 ? <ToolbarView /> : null}
{isViewMode ? this.renderStartTracingButton() : null}
</div>
<AddNewLayoutModal
Expand Down