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: Pinned option was added #1202

Merged
merged 5 commits into from
Mar 2, 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
76 changes: 43 additions & 33 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
points: [...state.points],
attributes: { ...state.attributes },
zOrder: state.zOrder,
pinned: state.pinned,
};
}

Expand Down Expand Up @@ -885,6 +886,12 @@ export class CanvasViewImpl implements CanvasView, Listener {
}
}

if (drawnState.pinned !== state.pinned && this.activeElement.clientID !== null) {
const activeElement = { ...this.activeElement };
this.deactivate();
this.activate(activeElement);
}

if (state.points
.some((p: number, id: number): boolean => p !== drawnState.points[id])
) {
Expand Down Expand Up @@ -1016,9 +1023,11 @@ export class CanvasViewImpl implements CanvasView, Listener {

shape.removeClass('cvat_canvas_shape_activated');

(shape as any).off('dragstart');
(shape as any).off('dragend');
(shape as any).draggable(false);
if (!drawnState.pinned) {
(shape as any).off('dragstart');
(shape as any).off('dragend');
(shape as any).draggable(false);
}

if (drawnState.shapeType !== 'points') {
this.selectize(false, shape);
Expand Down Expand Up @@ -1098,37 +1107,38 @@ export class CanvasViewImpl implements CanvasView, Listener {
this.content.append(shape.node);
}

(shape as any).draggable().on('dragstart', (): void => {
this.mode = Mode.DRAG;
if (text) {
text.addClass('cvat_canvas_hidden');
}
}).on('dragend', (e: CustomEvent): void => {
if (text) {
text.removeClass('cvat_canvas_hidden');
this.updateTextPosition(
text,
shape,
);
}

this.mode = Mode.IDLE;

const p1 = e.detail.handler.startPoints.point;
const p2 = e.detail.p;
const delta = 1;
const { offset } = this.controller.geometry;
if (Math.sqrt(((p1.x - p2.x) ** 2) + ((p1.y - p2.y) ** 2)) >= delta) {
const points = pointsToArray(
shape.attr('points') || `${shape.attr('x')},${shape.attr('y')} `
+ `${shape.attr('x') + shape.attr('width')},`
+ `${shape.attr('y') + shape.attr('height')}`,
).map((x: number): number => x - offset);
if (!state.pinned) {
(shape as any).draggable().on('dragstart', (): void => {
this.mode = Mode.DRAG;
if (text) {
text.addClass('cvat_canvas_hidden');
}
}).on('dragend', (e: CustomEvent): void => {
if (text) {
text.removeClass('cvat_canvas_hidden');
this.updateTextPosition(
text,
shape,
);
}

this.drawnStates[state.clientID].points = points;
this.onEditDone(state, points);
}
});
this.mode = Mode.IDLE;
const p1 = e.detail.handler.startPoints.point;
const p2 = e.detail.p;
const delta = 1;
const { offset } = this.controller.geometry;
if (Math.sqrt(((p1.x - p2.x) ** 2) + ((p1.y - p2.y) ** 2)) >= delta) {
const points = pointsToArray(
shape.attr('points') || `${shape.attr('x')},${shape.attr('y')} `
+ `${shape.attr('x') + shape.attr('width')},`
+ `${shape.attr('y') + shape.attr('height')}`,
).map((x: number): number => x - offset);

this.drawnStates[state.clientID].points = points;
this.onEditDone(state, points);
}
});
}

if (state.shapeType !== 'points') {
this.selectize(true, shape);
Expand Down
30 changes: 30 additions & 0 deletions cvat-core/src/annotations-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@
checkObjectType('lock', data.lock, 'boolean', null);
}

if (updated.pinned) {
checkObjectType('pinned', data.pinned, 'boolean', null);
}

if (updated.color) {
checkObjectType('color', data.color, 'string', null);
if (!/^#[0-9A-F]{6}$/i.test(data.color)) {
Expand Down Expand Up @@ -379,9 +383,23 @@
super(data, clientID, color, injection);
this.frameMeta = injection.frameMeta;
this.hidden = false;
this.pinned = true;
this.shapeType = null;
}

_savePinned(pinned) {
const undoPinned = this.pinned;
const redoPinned = pinned;

this.history.do(HistoryActions.CHANGED_PINNED, () => {
this.pinned = undoPinned;
}, () => {
this.pinned = redoPinned;
}, [this.clientID]);

this.pinned = pinned;
}

save() {
throw new ScriptingError(
'Is not implemented',
Expand Down Expand Up @@ -455,6 +473,7 @@
color: this.color,
hidden: this.hidden,
updated: this.updated,
pinned: this.pinned,
frame,
};
}
Expand Down Expand Up @@ -537,6 +556,10 @@
this._saveLock(data.lock);
}

if (updated.pinned) {
this._savePinned(data.pinned);
}

if (updated.color) {
this._saveColor(data.color);
}
Expand Down Expand Up @@ -644,6 +667,7 @@
hidden: this.hidden,
updated: this.updated,
label: this.label,
pinned: this.pinned,
keyframes: {
prev,
next,
Expand Down Expand Up @@ -984,6 +1008,10 @@
this._saveLock(data.lock);
}

if (updated.pinned) {
this._savePinned(data.pinned);
}

if (updated.color) {
this._saveColor(data.color);
}
Expand Down Expand Up @@ -1148,6 +1176,7 @@
constructor(data, clientID, color, injection) {
super(data, clientID, color, injection);
this.shapeType = ObjectShape.RECTANGLE;
this.pinned = false;
checkNumberOfPoints(this.shapeType, this.points);
}

Expand Down Expand Up @@ -1315,6 +1344,7 @@
constructor(data, clientID, color, injection) {
super(data, clientID, color, injection);
this.shapeType = ObjectShape.RECTANGLE;
this.pinned = false;
for (const shape of Object.values(this.shapes)) {
checkNumberOfPoints(this.shapeType, shape.points);
}
Expand Down
1 change: 1 addition & 0 deletions cvat-core/src/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
CHANGED_ZORDER: 'Changed z-order',
CHANGED_KEYFRAME: 'Changed keyframe',
CHANGED_LOCK: 'Changed lock',
CHANGED_PINNED: 'Changed pinned',
CHANGED_COLOR: 'Changed color',
CHANGED_HIDDEN: 'Changed hidden',
MERGED_OBJECTS: 'Merged objects',
Expand Down
72 changes: 54 additions & 18 deletions cvat-core/src/object-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
/**
* @param {Object} serialized - is an dictionary which contains
* initial information about an ObjectState;
* Necessary fields: objectType, shapeType, frame, updated
* Optional fields: points, group, zOrder, outside, occluded, hidden,
* attributes, lock, label, mode, color, keyframe, keyframes, clientID, serverID
* These fields can be set later via setters
* </br> Necessary fields: objectType, shapeType, frame, updated, group
* </br> Optional fields: keyframes, clientID, serverID
* </br> Optional fields which can be set later: points, zOrder, outside,
* occluded, hidden, attributes, lock, label, color, keyframe
*/
constructor(serialized) {
const data = {
Expand All @@ -34,12 +34,13 @@
occluded: null,
keyframe: null,

zOrder: undefined,
zOrder: null,
lock: null,
color: null,
hidden: null,
pinned: null,
keyframes: null,
group: serialized.group,
keyframes: serialized.keyframes,
updated: serialized.updated,

clientID: serialized.clientID,
Expand All @@ -63,6 +64,7 @@
this.keyframe = false;

this.zOrder = false;
this.pinned = false;
this.lock = false;
this.color = false;
this.hidden = false;
Expand Down Expand Up @@ -202,7 +204,7 @@
zOrder: {
/**
* @name zOrder
* @type {integer}
* @type {integer | null}
* @memberof module:API.cvat.classes.ObjectState
* @instance
*/
Expand Down Expand Up @@ -242,15 +244,16 @@
/**
* Object of keyframes { first, prev, next, last }
* @name keyframes
* @type {object}
* @type {object | null}
* @memberof module:API.cvat.classes.ObjectState
* @readonly
* @instance
*/
get: () => {
if (data.keyframes) {
if (typeof (data.keyframes) === 'object') {
return { ...data.keyframes };
}

return null;
},
},
Expand Down Expand Up @@ -280,6 +283,25 @@
data.lock = lock;
},
},
pinned: {
/**
* @name pinned
* @type {boolean | null}
* @memberof module:API.cvat.classes.ObjectState
* @instance
*/
get: () => {
if (typeof (data.pinned) === 'boolean') {
return data.pinned;
}

return null;
},
set: (pinned) => {
data.updateFlags.pinned = true;
data.pinned = pinned;
},
},
updated: {
/**
* Timestamp of the latest updated of the object
Expand Down Expand Up @@ -320,19 +342,33 @@
}));

this.label = serialized.label;
this.zOrder = serialized.zOrder;
this.outside = serialized.outside;
this.keyframe = serialized.keyframe;
this.occluded = serialized.occluded;
this.color = serialized.color;
this.lock = serialized.lock;
this.hidden = serialized.hidden;

// It can be undefined in a constructor and it can be defined later
if (typeof (serialized.points) !== 'undefined') {
if (typeof (serialized.zOrder) === 'number') {
this.zOrder = serialized.zOrder;
}
if (typeof (serialized.occluded) === 'boolean') {
this.occluded = serialized.occluded;
}
if (typeof (serialized.outside) === 'boolean') {
this.outside = serialized.outside;
}
if (typeof (serialized.keyframe) === 'boolean') {
this.keyframe = serialized.keyframe;
}
if (typeof (serialized.pinned) === 'boolean') {
this.pinned = serialized.pinned;
}
if (typeof (serialized.hidden) === 'boolean') {
this.hidden = serialized.hidden;
}
if (typeof (serialized.color) === 'string') {
this.color = serialized.color;
}
if (Array.isArray(serialized.points)) {
this.points = serialized.points;
}
if (typeof (serialized.attributes) !== 'undefined') {
if (typeof (serialized.attributes) === 'object') {
this.attributes = serialized.attributes;
}

Expand Down
Loading