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',
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<Promise<void>, {}, {}, AnyAction> {
export function addTagAsync(
labelID: number,
frame: number,
): ThunkAction<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const initialState = getStore().getState().annotation.drawing.activeInitialState;
const {
canvas: {
instance: canvasInstance,
@ -1161,6 +1164,35 @@ export function pasteShapeAsync(): ThunkAction<Promise<void>, {}, {}, 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<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const initialState = getStore().getState().annotation.drawing.activeInitialState;
const {
canvas: {
instance: canvasInstance,
},
player: {
frame: {
number: frameNumber,
@ -1189,13 +1221,7 @@ export function pasteShapeAsync(): ThunkAction<Promise<void>, {}, {}, 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<Promise<void>, {}, {}, AnyAction>
export function repeatDrawShapeAsync(): ThunkAction<Promise<void>, {}, {}, AnyAction> {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
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<Promise<void>, {}, {}, 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,
});
}
};
}

@ -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<Props, State> {
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 {

@ -462,14 +462,14 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
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);
}
},

@ -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

Loading…
Cancel
Save