From a99dd38fee470e89237485cd10291a74a228baba Mon Sep 17 00:00:00 2001 From: Dmitry Kalinin Date: Tue, 10 Mar 2020 18:58:22 +0300 Subject: [PATCH] Fix copying and creating tags --- cvat-ui/src/actions/annotation-actions.ts | 94 ++++++++++++++----- .../controls-side-bar/setup-tag-popover.tsx | 36 ++----- .../objects-side-bar/objects-list.tsx | 4 +- cvat-ui/src/reducers/annotation-reducer.ts | 24 +++++ 4 files changed, 100 insertions(+), 58 deletions(-) diff --git a/cvat-ui/src/actions/annotation-actions.ts b/cvat-ui/src/actions/annotation-actions.ts index f0208701..6f901cb7 100644 --- a/cvat-ui/src/actions/annotation-actions.ts +++ b/cvat-ui/src/actions/annotation-actions.ts @@ -138,6 +138,7 @@ export enum AnnotationActionTypes { SWITCH_Z_LAYER = 'SWITCH_Z_LAYER', ADD_Z_LAYER = 'ADD_Z_LAYER', SEARCH_ANNOTATIONS_FAILED = 'SEARCH_ANNOTATIONS_FAILED', + ADD_TAG = 'ADD_TAG', } export function addZLayer(): AnyAction { @@ -1151,9 +1152,11 @@ export function searchAnnotationsAsync( }; } -export function pasteShapeAsync(): ThunkAction, {}, {}, AnyAction> { +export function addTagAsync( + labelID: number, + frame: number, +): ThunkAction, {}, {}, AnyAction> { return async (dispatch: ActionCreator): Promise => { - const initialState = getStore().getState().annotation.drawing.activeInitialState; const { canvas: { instance: canvasInstance, @@ -1161,6 +1164,35 @@ export function pasteShapeAsync(): ThunkAction, {}, {}, AnyAction> job: { instance: jobInstance, }, + } = getStore().getState().annotation; + + dispatch({ + type: AnnotationActionTypes.ADD_TAG, + payload: { + labelID, + objectType: ObjectType.TAG, + activeControl: ActiveControl.CURSOR, + }, + }); + + canvasInstance.cancel(); + const objectState = new cvat.classes.ObjectState({ + objectType: ObjectType.TAG, + label: jobInstance.task.labels + .filter((label: any) => label.id === labelID)[0], + frame, + }); + dispatch(createAnnotationsAsync(jobInstance, frame, [objectState])); + }; +} + +export function pasteShapeAsync(): ThunkAction, {}, {}, AnyAction> { + return async (dispatch: ActionCreator): Promise => { + const initialState = getStore().getState().annotation.drawing.activeInitialState; + const { + canvas: { + instance: canvasInstance, + }, player: { frame: { number: frameNumber, @@ -1189,13 +1221,7 @@ export function pasteShapeAsync(): ThunkAction, {}, {}, AnyAction> canvasInstance.cancel(); if (initialState.objectType === ObjectType.TAG) { - const state = new cvat.classes.ObjectState({ - objectType: initialState.objectType, - label: initialState.label, - frame: frameNumber, - - }); - dispatch(createAnnotationsAsync(jobInstance, frameNumber, [state])); + dispatch(addTagAsync(initialState.label.id, frameNumber)); } else { canvasInstance.draw({ enabled: true, @@ -1209,20 +1235,32 @@ export function pasteShapeAsync(): ThunkAction, {}, {}, AnyAction> export function repeatDrawShapeAsync(): ThunkAction, {}, {}, AnyAction> { return async (dispatch: ActionCreator): Promise => { const { - activeShapeType, - activeNumOfPoints, - activeRectDrawingMethod, - } = getStore().getState().annotation.drawing; - - const { instance: canvasInstance } = getStore().getState().annotation.canvas; + canvas: { + instance: canvasInstance, + }, + player: { + frame: { + number: frameNumber, + }, + }, + drawing: { + activeObjectType, + activeLabelID, + activeShapeType, + activeNumOfPoints, + activeRectDrawingMethod, + }, + } = getStore().getState().annotation; - let activeControl = ActiveControl.DRAW_RECTANGLE; - if (activeShapeType === ShapeType.POLYGON) { + let activeControl = ActiveControl.CURSOR; + if (activeShapeType === ShapeType.RECTANGLE) { + activeControl = ActiveControl.DRAW_RECTANGLE; + } else if (activeShapeType === ShapeType.POINTS) { + activeControl = ActiveControl.DRAW_POINTS; + } else if (activeShapeType === ShapeType.POLYGON) { activeControl = ActiveControl.DRAW_POLYGON; } else if (activeShapeType === ShapeType.POLYLINE) { activeControl = ActiveControl.DRAW_POLYLINE; - } else if (activeShapeType === ShapeType.POINTS) { - activeControl = ActiveControl.DRAW_POINTS; } dispatch({ @@ -1233,12 +1271,16 @@ export function repeatDrawShapeAsync(): ThunkAction, {}, {}, AnyAc }); canvasInstance.cancel(); - canvasInstance.draw({ - enabled: true, - rectDrawingMethod: activeRectDrawingMethod, - numberOfPoints: activeNumOfPoints, - shapeType: activeShapeType, - crosshair: activeShapeType === ShapeType.RECTANGLE, - }); + if (activeObjectType === ObjectType.TAG) { + dispatch(addTagAsync(activeLabelID, frameNumber)); + } else { + canvasInstance.draw({ + enabled: true, + rectDrawingMethod: activeRectDrawingMethod, + numberOfPoints: activeNumOfPoints, + shapeType: activeShapeType, + crosshair: activeShapeType === ShapeType.RECTANGLE, + }); + } }; } diff --git a/cvat-ui/src/containers/annotation-page/standard-workspace/controls-side-bar/setup-tag-popover.tsx b/cvat-ui/src/containers/annotation-page/standard-workspace/controls-side-bar/setup-tag-popover.tsx index 03e9bff5..d31d1e7e 100644 --- a/cvat-ui/src/containers/annotation-page/standard-workspace/controls-side-bar/setup-tag-popover.tsx +++ b/cvat-ui/src/containers/annotation-page/standard-workspace/controls-side-bar/setup-tag-popover.tsx @@ -7,32 +7,26 @@ import { connect } from 'react-redux'; import { CombinedState, - ObjectType, } from 'reducers/interfaces'; import { - createAnnotationsAsync, + addTagAsync, } from 'actions/annotation-actions'; -import { Canvas } from 'cvat-canvas'; import SetupTagPopoverComponent from 'components/annotation-page/standard-workspace/controls-side-bar/setup-tag-popover'; -import getCore from 'cvat-core'; -const cvat = getCore(); interface DispatchToProps { - onCreateAnnotations(sessionInstance: any, frame: number, states: any[]): void; + onAddTag(labelID: number, frame: number): void; } interface StateToProps { - canvasInstance: Canvas; - jobInstance: any; labels: any[]; frame: number; } function mapDispatchToProps(dispatch: any): DispatchToProps { return { - onCreateAnnotations(sessionInstance: any, frame: number, states: any[]): void { - dispatch(createAnnotationsAsync(sessionInstance, frame, states)); + onAddTag(labelID: number, frame: number): void { + dispatch(addTagAsync(labelID, frame)); }, }; } @@ -40,12 +34,8 @@ function mapDispatchToProps(dispatch: any): DispatchToProps { function mapStateToProps(state: CombinedState): StateToProps { const { annotation: { - canvas: { - instance: canvasInstance, - }, job: { labels, - instance: jobInstance, }, player: { frame: { @@ -56,8 +46,6 @@ function mapStateToProps(state: CombinedState): StateToProps { } = state; return { - canvasInstance, - jobInstance, labels, frame, }; @@ -87,25 +75,13 @@ class DrawShapePopoverContainer extends React.PureComponent { private onSetup(): void { const { - canvasInstance, - onCreateAnnotations, - jobInstance, frame, + onAddTag, } = this.props; const { selectedLabelID } = this.state; - canvasInstance.cancel(); - - const state = { - objectType: ObjectType.TAG, - label: jobInstance.task.labels - .filter((label: any) => label.id === selectedLabelID)[0], - frame, - - }; - const objectState = new cvat.classes.ObjectState(state); - onCreateAnnotations(jobInstance, frame, [objectState]); + onAddTag(selectedLabelID, frame); } public render(): JSX.Element { diff --git a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/objects-list.tsx b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/objects-list.tsx index 8bc18e0f..6edc95ca 100644 --- a/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/objects-list.tsx +++ b/cvat-ui/src/containers/annotation-page/standard-workspace/objects-side-bar/objects-list.tsx @@ -462,14 +462,14 @@ class ObjectsListContainer extends React.PureComponent { COPY_SHAPE: (event: KeyboardEvent | undefined) => { preventDefault(event); const state = activatedStated(); - if (state && state.objectType !== ObjectType.TAG) { + if (state) { copyShape(state); } }, PROPAGATE_OBJECT: (event: KeyboardEvent | undefined) => { preventDefault(event); const state = activatedStated(); - if (state && state.objectType !== ObjectType.TAG) { + if (state) { propagateObject(state); } }, diff --git a/cvat-ui/src/reducers/annotation-reducer.ts b/cvat-ui/src/reducers/annotation-reducer.ts index d5de5f60..07298373 100644 --- a/cvat-ui/src/reducers/annotation-reducer.ts +++ b/cvat-ui/src/reducers/annotation-reducer.ts @@ -437,6 +437,30 @@ export default (state = defaultState, action: AnyAction): AnnotationState => { }, }; } + case AnnotationActionTypes.ADD_TAG: { + const { + labelID, + objectType, + activeControl, + } = action.payload; + + return { + ...state, + annotations: { + ...state.annotations, + activatedStateID: null, + }, + canvas: { + ...state.canvas, + activeControl, + }, + drawing: { + ...defaultState.drawing, + activeLabelID: labelID, + activeObjectType: objectType, + }, + }; + } case AnnotationActionTypes.MERGE_OBJECTS: { const { enabled } = action.payload; const activeControl = enabled