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 5 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released

### Added
- Added the possibility to configure a rotation for a dataset, which can be toggled off and on when viewing and annotating data. [#8159](https://github.com/scalableminds/webknossos/pull/8159)
- Measurement tools are now accesible when viewing datasets outside of an annotation. [#8334](https://github.com/scalableminds/webknossos/pull/8334)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions frontend/javascripts/oxalis/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export const MeasurementTools: Array<keyof typeof AnnotationToolEnum> = [
AnnotationToolEnum.AREA_MEASUREMENT,
];

export const AvailableToolsInViewMode = [...MeasurementTools, AnnotationToolEnum.MOVE];

export type AnnotationTool = keyof typeof AnnotationToolEnum;
export enum ContourModeEnum {
DRAW = "DRAW",
Expand Down
6 changes: 6 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, AvailableToolsInViewMode, ControlModeEnum } from "oxalis/constants";
import type { Action } from "oxalis/model/actions/actions";
import { updateKey, updateKey2 } from "oxalis/model/helpers/deep_update";
import {
Expand Down Expand Up @@ -54,6 +55,11 @@ function UiReducer(state: OxalisState, action: Action): OxalisState {
}

case "SET_TOOL": {
if (state.temporaryConfiguration.controlMode === ControlModeEnum.VIEW) {
if (AvailableToolsInViewMode.includes(AnnotationToolEnum[action.tool])) {
return setToolReducer(state, action.tool);
}
}
if (!state.tracing.restrictions.allowUpdate) {
return state;
}
Expand Down
44 changes: 26 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 @@ -847,8 +848,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 @@ -1104,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,8 +298,8 @@ class ActionBarView extends React.PureComponent<Props, State> {
{getIsAIAnalysisEnabled() && isAdminOrDatasetManager
? this.renderStartAIJobButton(shouldDisableAIJobButton, tooltip)
: null}
{!isReadOnly && constants.MODES_PLANE.indexOf(viewMode) > -1 ? <ToolbarView /> : null}
{isViewMode ? this.renderStartTracingButton() : null}
{constants.MODES_PLANE.indexOf(viewMode) > -1 ? <ToolbarView /> : null}
</div>
<AddNewLayoutModal
addLayout={this.addNewLayout}
Expand Down