Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React UI: batch of fixes #1227

Merged
merged 6 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cvat-canvas/src/typescript/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

import {
Mode,
DrawData,
MergeData,
SplitData,
Expand Down Expand Up @@ -51,6 +52,7 @@ interface Canvas {
dragCanvas(enable: boolean): void;
zoomCanvas(enable: boolean): void;

mode(): void;
cancel(): void;
}

Expand Down Expand Up @@ -132,6 +134,10 @@ class CanvasImpl implements Canvas {
this.model.select(objectState);
}

public mode(): Mode {
return this.model.mode;
}

public cancel(): void {
this.model.cancel();
}
Expand All @@ -141,4 +147,5 @@ export {
CanvasImpl as Canvas,
CanvasVersion,
RectDrawingMethod,
Mode as CanvasMode,
};
15 changes: 10 additions & 5 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,21 +469,21 @@ export class CanvasViewImpl implements CanvasView, Listener {
'stroke-width': consts.POINTS_STROKE_WIDTH / self.geometry.scale,
});

circle.node.addEventListener('mouseenter', (): void => {
circle.on('mouseenter', (): void => {
circle.attr({
'stroke-width': consts.POINTS_SELECTED_STROKE_WIDTH / self.geometry.scale,
});

circle.node.addEventListener('dblclick', dblClickHandler);
circle.on('dblclick', dblClickHandler);
circle.addClass('cvat_canvas_selected_point');
});

circle.node.addEventListener('mouseleave', (): void => {
circle.on('mouseleave', (): void => {
circle.attr({
'stroke-width': consts.POINTS_STROKE_WIDTH / self.geometry.scale,
});

circle.node.removeEventListener('dblclick', dblClickHandler);
circle.off('dblclick', dblClickHandler);
circle.removeClass('cvat_canvas_selected_point');
});

Expand Down Expand Up @@ -1330,13 +1330,18 @@ export class CanvasViewImpl implements CanvasView, Listener {
private setupPoints(basicPolyline: SVG.PolyLine, state: any): any {
this.selectize(true, basicPolyline);

const group = basicPolyline.remember('_selectHandler').nested
const group: SVG.G = basicPolyline.remember('_selectHandler').nested
.addClass('cvat_canvas_shape').attr({
clientID: state.clientID,
id: `cvat_canvas_shape_${state.clientID}`,
'data-z-order': state.zOrder,
});

group.on('click.canvas', (event: MouseEvent): void => {
// Need to redispatch the event on another element
basicPolyline.fire(new MouseEvent('click', event));
});

group.bbox = basicPolyline.bbox.bind(basicPolyline);
group.clone = basicPolyline.clone.bind(basicPolyline);

Expand Down
14 changes: 10 additions & 4 deletions cvat-canvas/src/typescript/editHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class EditHandlerImpl implements EditHandler {
}).draw(dummyEvent, { snapToGrid: 0.1 });

if (this.editData.state.shapeType === 'points') {
this.editLine.style('stroke-width', 0);
this.editLine.attr('stroke-width', 0);
(this.editLine as any).draw('undo');
}

Expand Down Expand Up @@ -168,7 +168,7 @@ export class EditHandlerImpl implements EditHandler {
for (const points of [firstPart, secondPart]) {
this.clones.push(this.canvas.polygon(points.join(' '))
.attr('fill', this.editedShape.attr('fill'))
.style('fill-opacity', '0.5')
.attr('fill-opacity', '0.5')
.addClass('cvat_canvas_shape'));
}

Expand Down Expand Up @@ -340,18 +340,24 @@ export class EditHandlerImpl implements EditHandler {
public transform(geometry: Geometry): void {
this.geometry = geometry;

if (this.editedShape) {
this.editedShape.attr({
'stroke-width': consts.BASE_STROKE_WIDTH / geometry.scale,
});
}

if (this.editLine) {
(this.editLine as any).draw('transform');
if (this.editData.state.shapeType !== 'points') {
this.editLine.style({
this.editLine.attr({
'stroke-width': consts.BASE_STROKE_WIDTH / geometry.scale,
});
}

const paintHandler = this.editLine.remember('_paintHandler');

for (const point of (paintHandler as any).set.members) {
point.style(
point.attr(
'stroke-width',
`${consts.POINTS_STROKE_WIDTH / geometry.scale}`,
);
Expand Down
10 changes: 8 additions & 2 deletions cvat-core/src/annotations-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@

if (updated.keyframe) {
checkObjectType('keyframe', data.keyframe, 'boolean', null);
if (!this.shapes || (Object.keys(this.shapes).length === 1 && !data.keyframe)) {
throw new ArgumentError(
'Can not remove the latest keyframe of an object. Consider removing the object instead',
);
}
}

return fittedPoints;
Expand Down Expand Up @@ -964,7 +969,8 @@
const current = this.get(frame);
const wasKeyframe = frame in this.shapes;

if ((keyframe && wasKeyframe) || (!keyframe && !wasKeyframe)) {
if ((keyframe && wasKeyframe)
|| (!keyframe && !wasKeyframe)) {
return;
}

Expand Down Expand Up @@ -1088,7 +1094,7 @@

throw new DataError(
'No one left position or right position was found. '
+ `Interpolation impossible. Client ID: ${this.id}`,
+ `Interpolation impossible. Client ID: ${this.clientID}`,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cvat-core/src/object-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
color: null,
hidden: null,
pinned: null,
keyframes: null,
keyframes: serialized.keyframes,
group: serialized.group,
updated: serialized.updated,

Expand Down
2 changes: 2 additions & 0 deletions cvat-ui/src/cvat-canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

import {
Canvas,
CanvasMode,
CanvasVersion,
RectDrawingMethod,
} from '../../cvat-canvas/src/typescript/canvas';

export {
Canvas,
CanvasMode,
CanvasVersion,
RectDrawingMethod,
};
14 changes: 11 additions & 3 deletions cvat-ui/src/reducers/annotation-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { AnyAction } from 'redux';

import { Canvas } from 'cvat-canvas';
import { Canvas, CanvasMode } from 'cvat-canvas';
import { AnnotationActionTypes } from 'actions/annotation-actions';
import { AuthActionTypes } from 'actions/auth-actions';
import {
Expand Down Expand Up @@ -609,9 +609,17 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
};
}
case AnnotationActionTypes.ACTIVATE_OBJECT: {
const { activatedStateID } = action.payload;
const {
activatedStateID,
} = action.payload;
canvas: {
activeControl,
instance,
},
} = state;

if (activeControl !== ActiveControl.CURSOR || instance.mode() !== CanvasMode.IDLE) {
return state;
}

return {
...state,
Expand Down