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

Fixed default undefined, fixed double change #1935

Merged
merged 2 commits into from
Jul 28, 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
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "3.1.1",
"version": "3.1.2",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "babel.config.js",
"scripts": {
Expand Down
79 changes: 45 additions & 34 deletions cvat-core/src/annotations-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
} = require('./common');
const {
colors,
Source,
ObjectShape,
ObjectType,
AttributeType,
Expand Down Expand Up @@ -296,21 +297,6 @@
}, [this.clientID], frame);
}

_saveSource(source, frame) {
const undoSource = this.source;
const redoSource = source;

this.history.do(HistoryActions.CHANGED_SOURCE, () => {
this.source = undoSource;
this.updated = Date.now();
}, () => {
this.source = redoSource;
this.updated = Date.now();
}, [this.clientID], frame);

this.source = source;
}

_validateStateBeforeSave(frame, data, updated) {
let fittedPoints = [];

Expand Down Expand Up @@ -397,10 +383,6 @@
}
}

if (updated.source) {
checkObjectType('source', data.source, 'string', null);
}

return fittedPoints;
}

Expand All @@ -416,8 +398,7 @@
updateTimestamp(updated) {
const anyChanges = updated.label || updated.attributes || updated.points
|| updated.outside || updated.occluded || updated.keyframe
|| updated.zOrder || updated.hidden || updated.lock || updated.pinned
|| updated.source;
|| updated.zOrder || updated.hidden || updated.lock || updated.pinned;

if (anyChanges) {
this.updated = Date.now();
Expand Down Expand Up @@ -549,45 +530,60 @@
_savePoints(points, frame) {
const undoPoints = this.points;
const redoPoints = points;
const undoSource = this.source;
const redoSource = Source.MANUAL;

this.history.do(HistoryActions.CHANGED_POINTS, () => {
this.points = undoPoints;
this.source = undoSource;
this.updated = Date.now();
}, () => {
this.points = redoPoints;
this.source = redoSource;
this.updated = Date.now();
}, [this.clientID], frame);

this.source = Source.MANUAL;
this.points = points;
}

_saveOccluded(occluded, frame) {
const undoOccluded = this.occluded;
const redoOccluded = occluded;
const undoSource = this.source;
const redoSource = Source.MANUAL;

this.history.do(HistoryActions.CHANGED_OCCLUDED, () => {
this.occluded = undoOccluded;
this.source = undoSource;
this.updated = Date.now();
}, () => {
this.occluded = redoOccluded;
this.source = redoSource;
this.updated = Date.now();
}, [this.clientID], frame);

this.source = Source.MANUAL;
this.occluded = occluded;
}

_saveZOrder(zOrder, frame) {
const undoZOrder = this.zOrder;
const redoZOrder = zOrder;
const undoSource = this.source;
const redoSource = Source.MANUAL;

this.history.do(HistoryActions.CHANGED_ZORDER, () => {
this.zOrder = undoZOrder;
this.source = undoSource;
this.updated = Date.now();
}, () => {
this.zOrder = redoZOrder;
this.source = redoSource;
this.updated = Date.now();
}, [this.clientID], frame);

this.source = Source.MANUAL;
this.zOrder = zOrder;
}

Expand Down Expand Up @@ -642,10 +638,6 @@
this._saveHidden(data.hidden, frame);
}

if (updated.source) {
this._saveSource(data.source, frame);
}

this.updateTimestamp(updated);
updated.reset();

Expand Down Expand Up @@ -940,27 +932,31 @@
}, [this.clientID], frame);
}

_appendShapeActionToHistory(actionType, frame, undoShape, redoShape) {
_appendShapeActionToHistory(actionType, frame, undoShape, redoShape, undoSource, redoSource) {
this.history.do(actionType, () => {
if (!undoShape) {
delete this.shapes[frame];
} else {
this.shapes[frame] = undoShape;
}
this.source = undoSource;
this.updated = Date.now();
}, () => {
if (!redoShape) {
delete this.shapes[frame];
} else {
this.shapes[frame] = redoShape;
}
this.source = redoSource;
this.updated = Date.now();
}, [this.clientID], frame);
}

_savePoints(points, frame) {
const current = this.get(frame);
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = Source.MANUAL;
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ? { ...this.shapes[frame], points } : {
frame,
Expand All @@ -972,17 +968,22 @@
};

this.shapes[frame] = redoShape;
this.source = Source.MANUAL;
this._appendShapeActionToHistory(
HistoryActions.CHANGED_POINTS,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
);
}

_saveOutside(frame, outside) {
const current = this.get(frame);
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = Source.MANUAL;
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ? { ...this.shapes[frame], outside } : {
frame,
Expand All @@ -994,17 +995,22 @@
};

this.shapes[frame] = redoShape;
this.source = Source.MANUAL;
this._appendShapeActionToHistory(
HistoryActions.CHANGED_OUTSIDE,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
);
}

_saveOccluded(occluded, frame) {
const current = this.get(frame);
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = Source.MANUAL;
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ? { ...this.shapes[frame], occluded } : {
frame,
Expand All @@ -1016,17 +1022,22 @@
};

this.shapes[frame] = redoShape;
this.source = Source.MANUAL;
this._appendShapeActionToHistory(
HistoryActions.CHANGED_OCCLUDED,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
);
}

_saveZOrder(zOrder, frame) {
const current = this.get(frame);
const wasKeyframe = frame in this.shapes;
const undoSource = this.source;
const redoSource = Source.MANUAL;
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = wasKeyframe ? { ...this.shapes[frame], zOrder } : {
frame,
Expand All @@ -1038,11 +1049,14 @@
};

this.shapes[frame] = redoShape;
this.source = Source.MANUAL;
this._appendShapeActionToHistory(
HistoryActions.CHANGED_ZORDER,
frame,
undoShape,
redoShape,
undoSource,
redoSource,
);
}

Expand All @@ -1055,6 +1069,8 @@
return;
}

const undoSource = this.source;
const redoSource = Source.MANUAL;
const undoShape = wasKeyframe ? this.shapes[frame] : undefined;
const redoShape = keyframe ? {
frame,
Expand All @@ -1066,6 +1082,7 @@
source: current.source,
} : undefined;

this.source = Source.MANUAL;
if (redoShape) {
this.shapes[frame] = redoShape;
} else {
Expand All @@ -1077,6 +1094,8 @@
frame,
undoShape,
redoShape,
undoSource,
redoSource,
);
}

Expand Down Expand Up @@ -1128,10 +1147,6 @@
this._saveAttributes(data.attributes, frame);
}

if (updated.source) {
this._saveSource(data.source, frame);
}

if (updated.keyframe) {
this._saveKeyframe(frame, data.keyframe);
}
Expand Down Expand Up @@ -1264,10 +1279,6 @@
this._saveColor(data.color, frame);
}

if (updated.source) {
this._saveSource(data.source, frame);
}

this.updateTimestamp(updated);
updated.reset();

Expand Down
4 changes: 2 additions & 2 deletions cvat-core/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function build() {
LogType,
HistoryActions,
colors,
source,
Source,
} = require('./enums');

const {
Expand Down Expand Up @@ -532,7 +532,7 @@ function build() {
LogType,
HistoryActions,
colors,
source,
Source,
},
/**
* Namespace is used for access to exceptions
Expand Down
12 changes: 6 additions & 6 deletions cvat-core/src/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@
/**
* Annotation type
* @enum {string}
* @name source
* @name Source
* @memberof module:API.cvat.enums
* @property {string} MANUAL 'manual'
* @property {string} AUTO 'auto'
* @readonly
*/
const source = Object.freeze({
MANUAL:'manual',
AUTO:'auto',
});
const Source = Object.freeze({
MANUAL:'manual',
AUTO:'auto',
});

/**
* Logger event types
Expand Down Expand Up @@ -257,6 +257,6 @@
LogType,
HistoryActions,
colors,
source,
Source,
};
})();
15 changes: 7 additions & 8 deletions cvat-core/src/object-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: MIT
*/

const { Source } = require('./enums');

/* global
require:false
*/
Expand Down Expand Up @@ -39,7 +41,7 @@
color: null,
hidden: null,
pinned: null,
source: null,
source: Source.MANUAL,
keyframes: serialized.keyframes,
group: serialized.group,
updated: serialized.updated,
Expand Down Expand Up @@ -69,7 +71,6 @@
this.lock = false;
this.color = false;
this.hidden = false;
this.source = false;

return reset;
},
Expand Down Expand Up @@ -114,16 +115,12 @@
source: {
/**
* @name source
* @type {module:API.cvat.enums.source}
* @type {module:API.cvat.enums.Source}
* @memberof module:API.cvat.classes.ObjectState
* @readonly
* @instance
*/
get: () => data.source,
set: (source) => {
data.updateFlags.source = true;
data.source = source;
},
},
clientID: {
/**
Expand Down Expand Up @@ -359,8 +356,10 @@

this.label = serialized.label;
this.lock = serialized.lock;
this.source = serialized.source;

if ([Source.MANUAL, Source.AUTO].includes(serialized.source)) {
data.source = serialized.source;
}
if (typeof (serialized.zOrder) === 'number') {
this.zOrder = serialized.zOrder;
}
Expand Down
Loading