Fix copying and creating tags

main
Dmitry Kalinin 6 years ago
parent c85ecb7bf3
commit a99dd38fee

@ -138,6 +138,7 @@ export enum AnnotationActionTypes {
SWITCH_Z_LAYER = 'SWITCH_Z_LAYER', SWITCH_Z_LAYER = 'SWITCH_Z_LAYER',
ADD_Z_LAYER = 'ADD_Z_LAYER', ADD_Z_LAYER = 'ADD_Z_LAYER',
SEARCH_ANNOTATIONS_FAILED = 'SEARCH_ANNOTATIONS_FAILED', SEARCH_ANNOTATIONS_FAILED = 'SEARCH_ANNOTATIONS_FAILED',
ADD_TAG = 'ADD_TAG',
} }
export function addZLayer(): AnyAction { export function addZLayer(): AnyAction {
@ -1151,9 +1152,11 @@ export function searchAnnotationsAsync(
}; };
} }
export function pasteShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAction> { export function addTagAsync(
labelID: number,
frame: number,
): ThunkAction<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => { return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const initialState = getStore().getState().annotation.drawing.activeInitialState;
const { const {
canvas: { canvas: {
instance: canvasInstance, instance: canvasInstance,
@ -1161,6 +1164,35 @@ export function pasteShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAction>
job: { job: {
instance: jobInstance, 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<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const initialState = getStore().getState().annotation.drawing.activeInitialState;
const {
canvas: {
instance: canvasInstance,
},
player: { player: {
frame: { frame: {
number: frameNumber, number: frameNumber,
@ -1189,13 +1221,7 @@ export function pasteShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAction>
canvasInstance.cancel(); canvasInstance.cancel();
if (initialState.objectType === ObjectType.TAG) { if (initialState.objectType === ObjectType.TAG) {
const state = new cvat.classes.ObjectState({ dispatch(addTagAsync(initialState.label.id, frameNumber));
objectType: initialState.objectType,
label: initialState.label,
frame: frameNumber,
});
dispatch(createAnnotationsAsync(jobInstance, frameNumber, [state]));
} else { } else {
canvasInstance.draw({ canvasInstance.draw({
enabled: true, enabled: true,
@ -1209,20 +1235,32 @@ export function pasteShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAction>
export function repeatDrawShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAction> { export function repeatDrawShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => { return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const { const {
activeShapeType, canvas: {
activeNumOfPoints, instance: canvasInstance,
activeRectDrawingMethod, },
} = getStore().getState().annotation.drawing; player: {
frame: {
const { instance: canvasInstance } = getStore().getState().annotation.canvas; number: frameNumber,
},
},
drawing: {
activeObjectType,
activeLabelID,
activeShapeType,
activeNumOfPoints,
activeRectDrawingMethod,
},
} = getStore().getState().annotation;
let activeControl = ActiveControl.DRAW_RECTANGLE; let activeControl = ActiveControl.CURSOR;
if (activeShapeType === ShapeType.POLYGON) { 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; activeControl = ActiveControl.DRAW_POLYGON;
} else if (activeShapeType === ShapeType.POLYLINE) { } else if (activeShapeType === ShapeType.POLYLINE) {
activeControl = ActiveControl.DRAW_POLYLINE; activeControl = ActiveControl.DRAW_POLYLINE;
} else if (activeShapeType === ShapeType.POINTS) {
activeControl = ActiveControl.DRAW_POINTS;
} }
dispatch({ dispatch({
@ -1233,12 +1271,16 @@ export function repeatDrawShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAc
}); });
canvasInstance.cancel(); canvasInstance.cancel();
canvasInstance.draw({ if (activeObjectType === ObjectType.TAG) {
enabled: true, dispatch(addTagAsync(activeLabelID, frameNumber));
rectDrawingMethod: activeRectDrawingMethod, } else {
numberOfPoints: activeNumOfPoints, canvasInstance.draw({
shapeType: activeShapeType, enabled: true,
crosshair: activeShapeType === ShapeType.RECTANGLE, rectDrawingMethod: activeRectDrawingMethod,
}); numberOfPoints: activeNumOfPoints,
shapeType: activeShapeType,
crosshair: activeShapeType === ShapeType.RECTANGLE,
});
}
}; };
} }

@ -7,32 +7,26 @@ import { connect } from 'react-redux';
import { import {
CombinedState, CombinedState,
ObjectType,
} from 'reducers/interfaces'; } from 'reducers/interfaces';
import { import {
createAnnotationsAsync, addTagAsync,
} from 'actions/annotation-actions'; } from 'actions/annotation-actions';
import { Canvas } from 'cvat-canvas';
import SetupTagPopoverComponent from 'components/annotation-page/standard-workspace/controls-side-bar/setup-tag-popover'; import SetupTagPopoverComponent from 'components/annotation-page/standard-workspace/controls-side-bar/setup-tag-popover';
import getCore from 'cvat-core';
const cvat = getCore();
interface DispatchToProps { interface DispatchToProps {
onCreateAnnotations(sessionInstance: any, frame: number, states: any[]): void; onAddTag(labelID: number, frame: number): void;
} }
interface StateToProps { interface StateToProps {
canvasInstance: Canvas;
jobInstance: any;
labels: any[]; labels: any[];
frame: number; frame: number;
} }
function mapDispatchToProps(dispatch: any): DispatchToProps { function mapDispatchToProps(dispatch: any): DispatchToProps {
return { return {
onCreateAnnotations(sessionInstance: any, frame: number, states: any[]): void { onAddTag(labelID: number, frame: number): void {
dispatch(createAnnotationsAsync(sessionInstance, frame, states)); dispatch(addTagAsync(labelID, frame));
}, },
}; };
} }
@ -40,12 +34,8 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
function mapStateToProps(state: CombinedState): StateToProps { function mapStateToProps(state: CombinedState): StateToProps {
const { const {
annotation: { annotation: {
canvas: {
instance: canvasInstance,
},
job: { job: {
labels, labels,
instance: jobInstance,
}, },
player: { player: {
frame: { frame: {
@ -56,8 +46,6 @@ function mapStateToProps(state: CombinedState): StateToProps {
} = state; } = state;
return { return {
canvasInstance,
jobInstance,
labels, labels,
frame, frame,
}; };
@ -87,25 +75,13 @@ class DrawShapePopoverContainer extends React.PureComponent<Props, State> {
private onSetup(): void { private onSetup(): void {
const { const {
canvasInstance,
onCreateAnnotations,
jobInstance,
frame, frame,
onAddTag,
} = this.props; } = this.props;
const { selectedLabelID } = this.state; const { selectedLabelID } = this.state;
canvasInstance.cancel(); onAddTag(selectedLabelID, frame);
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]);
} }
public render(): JSX.Element { public render(): JSX.Element {

@ -462,14 +462,14 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
COPY_SHAPE: (event: KeyboardEvent | undefined) => { COPY_SHAPE: (event: KeyboardEvent | undefined) => {
preventDefault(event); preventDefault(event);
const state = activatedStated(); const state = activatedStated();
if (state && state.objectType !== ObjectType.TAG) { if (state) {
copyShape(state); copyShape(state);
} }
}, },
PROPAGATE_OBJECT: (event: KeyboardEvent | undefined) => { PROPAGATE_OBJECT: (event: KeyboardEvent | undefined) => {
preventDefault(event); preventDefault(event);
const state = activatedStated(); const state = activatedStated();
if (state && state.objectType !== ObjectType.TAG) { if (state) {
propagateObject(state); propagateObject(state);
} }
}, },

@ -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: { case AnnotationActionTypes.MERGE_OBJECTS: {
const { enabled } = action.payload; const { enabled } = action.payload;
const activeControl = enabled const activeControl = enabled

Loading…
Cancel
Save