diff --git a/changelog.d/20241112_132508_klakhov_fix_remember_object.md b/changelog.d/20241112_132508_klakhov_fix_remember_object.md new file mode 100644 index 000000000000..fd3f7bd37eae --- /dev/null +++ b/changelog.d/20241112_132508_klakhov_fix_remember_object.md @@ -0,0 +1,4 @@ +### Fixed + +- Keybinds in UI allow drawing disabled shape types + () diff --git a/cvat-ui/src/actions/annotation-actions.ts b/cvat-ui/src/actions/annotation-actions.ts index 0cc8f3052bc0..115470429990 100644 --- a/cvat-ui/src/actions/annotation-actions.ts +++ b/cvat-ui/src/actions/annotation-actions.ts @@ -1081,7 +1081,7 @@ export function finishCurrentJobAsync(): ThunkAction { export function rememberObject(createParams: { activeObjectType?: ObjectType; activeLabelID?: number; - activeShapeType?: ShapeType; + activeShapeType?: ShapeType | null; activeNumOfPoints?: number; activeRectDrawingMethod?: RectDrawingMethod; activeCuboidDrawingMethod?: CuboidDrawingMethod; diff --git a/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx b/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx index b7f7d60097af..fb2dae58e154 100644 --- a/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx +++ b/cvat-ui/src/components/annotation-page/single-shape-workspace/single-shape-sidebar/single-shape-sidebar.tsx @@ -21,6 +21,7 @@ import message from 'antd/lib/message'; import { ActiveControl, CombinedState, NavigationType, ObjectType, } from 'reducers'; +import { labelShapeType } from 'reducers/annotation-reducer'; import { Canvas, CanvasMode } from 'cvat-canvas-wrapper'; import { Job, Label, LabelType, ShapeType, @@ -259,6 +260,7 @@ function SingleShapeSidebar(): JSX.Element { appDispatch(rememberObject({ activeObjectType: ObjectType.SHAPE, activeLabelID: state.label.id, + activeShapeType: labelShapeType(state.label), })); canvas.draw({ diff --git a/cvat-ui/src/reducers/annotation-reducer.ts b/cvat-ui/src/reducers/annotation-reducer.ts index 265427cceffa..311f54c0fe96 100644 --- a/cvat-ui/src/reducers/annotation-reducer.ts +++ b/cvat-ui/src/reducers/annotation-reducer.ts @@ -10,7 +10,9 @@ import { AuthActionTypes } from 'actions/auth-actions'; import { BoundariesActionTypes } from 'actions/boundaries-actions'; import { Canvas, CanvasMode } from 'cvat-canvas-wrapper'; import { Canvas3d } from 'cvat-canvas3d-wrapper'; -import { DimensionType, JobStage, LabelType } from 'cvat-core-wrapper'; +import { + DimensionType, JobStage, Label, LabelType, +} from 'cvat-core-wrapper'; import { clamp } from 'utils/math'; import { @@ -29,6 +31,16 @@ function updateActivatedStateID(newStates: any[], prevActivatedStateID: number | null; } +export function labelShapeType(label?: Label): ShapeType | null { + if (label && Object.values(ShapeType).includes(label.type as any)) { + return label.type as unknown as ShapeType; + } + if (label?.type === LabelType.TAG) { + return null; + } + return ShapeType.RECTANGLE; +} + const defaultState: AnnotationState = { activities: { loads: {}, @@ -183,12 +195,11 @@ export default (state = defaultState, action: AnyAction): AnnotationState => { const isReview = job.stage === JobStage.VALIDATION; let workspaceSelected = null; let activeObjectType; - let activeShapeType; + let activeShapeType = null; if (defaultLabel?.type === LabelType.TAG) { activeObjectType = ObjectType.TAG; } else { - activeShapeType = defaultLabel && defaultLabel.type !== 'any' ? - defaultLabel.type : ShapeType.RECTANGLE; + activeShapeType = labelShapeType(defaultLabel); activeObjectType = job.mode === 'interpolation' ? ObjectType.TRACK : ObjectType.SHAPE; } diff --git a/cvat-ui/src/reducers/index.ts b/cvat-ui/src/reducers/index.ts index 14196846a393..337ef29927b2 100644 --- a/cvat-ui/src/reducers/index.ts +++ b/cvat-ui/src/reducers/index.ts @@ -769,7 +769,7 @@ export interface AnnotationState { drawing: { activeInteractor?: MLModel | OpenCVTool; activeInteractorParameters?: MLModel['params']['canvas']; - activeShapeType: ShapeType; + activeShapeType: ShapeType | null; activeRectDrawingMethod?: RectDrawingMethod; activeCuboidDrawingMethod?: CuboidDrawingMethod; activeNumOfPoints?: number;