Incremental collection update now works with outside/keyframe (#114)

main
Boris Sekachev 7 years ago committed by Nikita Manovich
parent 221f534fb7
commit 886f5e0d6c

@ -1233,16 +1233,17 @@ class ShapeCollectionView {
// Check which old models are new models // Check which old models are new models
for (let oldIdx = 0; oldIdx < oldModels.length; oldIdx ++) { for (let oldIdx = 0; oldIdx < oldModels.length; oldIdx ++) {
let newIdx = newModels.indexOf(oldModels[oldIdx]); let newIdx = newModels.indexOf(oldModels[oldIdx]);
let significantUpdate = ['remove', 'keyframe', 'outside'].includes(oldModels[oldIdx].updateReason);
// Changed frame means a changed position in common case. We need redraw it. // Changed frame means a changed position in common case. We need redraw it.
// If shape has been restored after removing, it view already removed. We need redraw it. // If shape has been restored after removing, it view already removed. We need redraw it.
if (newIdx === -1 || frameChanged || oldModels[oldIdx].updateReason === 'remove') { if (newIdx === -1 || significantUpdate || frameChanged) {
let view = oldViews[oldIdx]; let view = oldViews[oldIdx];
view.unsubscribe(this); view.unsubscribe(this);
view.controller().model().unsubscribe(view); view.controller().model().unsubscribe(view);
view.erase(); view.erase();
if (newIdx != -1 && (frameChanged || oldModels[oldIdx].updateReason === 'remove')) { if (newIdx != -1 && (frameChanged || significantUpdate)) {
drawView.call(this, newShapes[newIdx], newModels[newIdx]) drawView.call(this, newShapes[newIdx], newModels[newIdx])
} }
} }
@ -1255,7 +1256,7 @@ class ShapeCollectionView {
// Now we need draw new models which aren't on previous collection // Now we need draw new models which aren't on previous collection
for (let newIdx = 0; newIdx < newModels.length; newIdx ++) { for (let newIdx = 0; newIdx < newModels.length; newIdx ++) {
if (!oldModels.includes(newModels[newIdx])) { if (!this._currentModels.includes(newModels[newIdx])) {
drawView.call(this, newShapes[newIdx], newModels[newIdx]) drawView.call(this, newShapes[newIdx], newModels[newIdx])
} }
} }

@ -195,6 +195,17 @@ class ShapeModel extends Listener {
return counter; return counter;
} }
notify(updateReason) {
let oldReason = this._updateReason;
this._updateReason = updateReason;
try {
Listener.prototype.notify.call(this);
}
finally {
this._updateReason = oldReason;
}
}
collectStatistic() { collectStatistic() {
let collectObj = {}; let collectObj = {};
collectObj.type = this._type.split('_')[1]; collectObj.type = this._type.split('_')[1];
@ -229,8 +240,7 @@ class ShapeModel extends Listener {
window.cvat.addAction('Change Attribute', () => { window.cvat.addAction('Change Attribute', () => {
if (typeof(oldAttr) === 'undefined') { if (typeof(oldAttr) === 'undefined') {
delete this._attributes.mutable[frame][attrId]; delete this._attributes.mutable[frame][attrId];
this._updateReason = 'attributes'; this.notify('attributes');
this.notify();
} }
else { else {
this.updateAttribute(frame, attrId, oldAttr); this.updateAttribute(frame, attrId, oldAttr);
@ -249,8 +259,7 @@ class ShapeModel extends Listener {
this._attributes.immutable[attrId] = labelsInfo.strToValues(attrInfo.type, value)[0]; this._attributes.immutable[attrId] = labelsInfo.strToValues(attrInfo.type, value)[0];
} }
this._updateReason = 'attributes'; this.notify('attributes');
this.notify();
} }
changeLabel(labelId) { changeLabel(labelId) {
@ -263,8 +272,7 @@ class ShapeModel extends Listener {
this._label = +labelId; this._label = +labelId;
this._importAttributes([], []); this._importAttributes([], []);
this._setupKeyFrames(); this._setupKeyFrames();
this._updateReason = 'changelabel'; this.notify('attributes');
this.notify();
} }
else { else {
throw Error(`Unknown label id value found: ${labelId}`); throw Error(`Unknown label id value found: ${labelId}`);
@ -273,8 +281,7 @@ class ShapeModel extends Listener {
changeColor(color) { changeColor(color) {
this._color = color; this._color = color;
this._updateReason = 'color'; this.notify('color');
this.notify();
} }
interpolate(frame) { interpolate(frame) {
@ -297,14 +304,12 @@ class ShapeModel extends Listener {
// End of undo/redo code // End of undo/redo code
this.updatePosition(frame, position, true); this.updatePosition(frame, position, true);
this._updateReason = 'occluded'; this.notify('occluded');
this.notify();
} }
switchLock() { switchLock() {
this._locked = !this._locked; this._locked = !this._locked;
this._updateReason = 'lock'; this.notify('lock');
this.notify();
} }
switchHide() { switchHide() {
@ -321,8 +326,7 @@ class ShapeModel extends Listener {
this._hiddenText = false; this._hiddenText = false;
} }
this._updateReason = 'hidden'; this.notify('hidden');
this.notify();
} }
switchOutside(frame) { switchOutside(frame) {
@ -346,8 +350,7 @@ class ShapeModel extends Listener {
delete this._attributes.mutable[frame]; delete this._attributes.mutable[frame];
} }
this._updateReason = 'outside'; this.notify('outside');
this.notify();
} }
else { else {
this.switchOutside(frame); this.switchOutside(frame);
@ -370,8 +373,7 @@ class ShapeModel extends Listener {
this._frame = frame; this._frame = frame;
} }
this._updateReason = 'outside'; this.notify('outside');
this.notify();
} }
switchKeyFrame(frame) { switchKeyFrame(frame) {
@ -381,8 +383,12 @@ class ShapeModel extends Listener {
} }
// Undo/redo code // Undo/redo code
let oldPos = Object.assign({}, this._positions[frame]);
window.cvat.addAction('Change Keyframe', () => { window.cvat.addAction('Change Keyframe', () => {
this.switchKeyFrame(frame); this.switchKeyFrame(frame);
if (Object.keys(oldPos).length && oldPos.outside) {
this.switchOutside(frame);
}
}, () => { }, () => {
this.switchKeyFrame(frame); this.switchKeyFrame(frame);
}, frame); }, frame);
@ -411,13 +417,12 @@ class ShapeModel extends Listener {
this._frame = frame; this._frame = frame;
} }
} }
this._updateReason = 'keyframe';
this.notify(); this.notify('keyframe');
} }
click() { click() {
this._updateReason = 'click'; this.notify('click');
this.notify();
} }
prevKeyFrame() { prevKeyFrame() {
@ -437,23 +442,20 @@ class ShapeModel extends Listener {
} }
aamAttributeFocus() { aamAttributeFocus() {
this._updateReason = 'attributeFocus'; this.notify('attributeFocus');
this.notify();
} }
select() { select() {
if (!this._selected) { if (!this._selected) {
this._selected = true; this._selected = true;
this._updateReason = 'selection'; this.notify('selection');
this.notify();
} }
} }
deselect() { deselect() {
if (this._selected) { if (this._selected) {
this._selected = false; this._selected = false;
this._updateReason = 'selection'; this.notify('selection');
this.notify();
} }
} }
@ -480,8 +482,7 @@ class ShapeModel extends Listener {
let position = this._interpolatePosition(frame); let position = this._interpolatePosition(frame);
position.z_order = value; position.z_order = value;
this.updatePosition(frame, position, true); this.updatePosition(frame, position, true);
this._updateReason = 'z_order'; this.notify('z_order');
this.notify();
} }
} }
@ -490,8 +491,7 @@ class ShapeModel extends Listener {
this._active = false; this._active = false;
} }
this._removed = value; this._removed = value;
this._updateReason = 'remove'; this.notify('remove');
this.notify();
} }
get removed() { get removed() {
@ -513,8 +513,7 @@ class ShapeModel extends Listener {
set active(value) { set active(value) {
this._active = value; this._active = value;
if (!this._removed) { if (!this._removed) {
this._updateReason = 'activation'; this.notify('activation');
this.notify();
} }
} }
@ -525,8 +524,7 @@ class ShapeModel extends Listener {
set activeAAM(active) { set activeAAM(active) {
this._activeAAM = active.shape; this._activeAAM = active.shape;
this._activeAAMAttributeId = active.attribute; this._activeAAMAttributeId = active.attribute;
this._updateReason = 'activeAAM'; this.notify('activeAAM');
this.notify();
} }
get activeAAM() { get activeAAM() {
@ -538,8 +536,7 @@ class ShapeModel extends Listener {
set merge(value) { set merge(value) {
this._merge = value; this._merge = value;
this._updateReason = 'merge'; this.notify('merge');
this.notify();
} }
get merge() { get merge() {
@ -548,8 +545,7 @@ class ShapeModel extends Listener {
set groupping(value) { set groupping(value) {
this._groupping = value; this._groupping = value;
this._updateReason = 'groupping'; this.notify('groupping');
this.notify();
} }
get groupping() { get groupping() {
@ -683,8 +679,7 @@ class BoxModel extends ShapeModel {
window.cvat.addAction('Change Position', () => { window.cvat.addAction('Change Position', () => {
if (!Object.keys(oldPos).length) { if (!Object.keys(oldPos).length) {
delete this._positions[frame]; delete this._positions[frame];
this._updateReason = 'position'; this.notify('position');
this.notify();
} }
else { else {
this.updatePosition(frame, oldPos, false); this.updatePosition(frame, oldPos, false);
@ -706,8 +701,7 @@ class BoxModel extends ShapeModel {
} }
if (!silent) { if (!silent) {
this._updateReason = 'position'; this.notify('position');
this.notify();
} }
} }
@ -933,8 +927,7 @@ class PolyShapeModel extends ShapeModel {
} }
if (!silent) { if (!silent) {
this._updateReason = 'position'; this.notify('position');
this.notify();
} }
} }
@ -1209,8 +1202,7 @@ class PolygonModel extends PolyShapeModel {
set draggable(value) { set draggable(value) {
this._draggable = value; this._draggable = value;
this._updateReason = 'draggable'; this.notify('draggable');
this.notify();
} }
get draggable() { get draggable() {

Loading…
Cancel
Save