Skip to content

Commit

Permalink
Fix: Keybinds in UI allow drawing disabled shape types (#8685)
Browse files Browse the repository at this point in the history
<!-- Raise an issue to propose your change
(https://github.com/cvat-ai/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution guide](https://docs.cvat.ai/docs/contributing/).
-->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->
Resolved: #8673

### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [x] I have created a changelog fragment <!-- see top comment in
CHANGELOG.md -->
- ~~[ ] I have updated the documentation accordingly~~
- ~~[ ] I have added tests to cover my changes~~
- [x] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [x] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/cvat-ai/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/cvat-ai/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/cvat-ai/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/cvat-ai/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Resolved an issue preventing users from drawing only enabled shape
types in the user interface.
  
- **New Features**
- Introduced a new function to determine shape types based on labels,
enhancing the annotation process.
- Updated the handling of active shape types to allow for a nullable
state, improving flexibility.

- **Documentation**
- Added descriptive messages for the annotation process to clarify the
shape being annotated.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
klakhov authored Nov 13, 2024
1 parent 506b288 commit 0b528df
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20241112_132508_klakhov_fix_remember_object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Keybinds in UI allow drawing disabled shape types
(<https://github.com/cvat-ai/cvat/pull/8685>)
2 changes: 1 addition & 1 deletion cvat-ui/src/actions/annotation-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -259,6 +260,7 @@ function SingleShapeSidebar(): JSX.Element {
appDispatch(rememberObject({
activeObjectType: ObjectType.SHAPE,
activeLabelID: state.label.id,
activeShapeType: labelShapeType(state.label),
}));

canvas.draw({
Expand Down
19 changes: 15 additions & 4 deletions cvat-ui/src/reducers/annotation-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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: {},
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0b528df

Please sign in to comment.