Bug has been fixed: label UIs don't update after changelabel (#109)

main
Boris Sekachev 7 years ago committed by Nikita Manovich
parent b8e0683448
commit f3c406a8eb

@ -1223,9 +1223,15 @@ class ShapeCollectionView {
}); });
} }
onCollectionUpdate(collection) { _updateLabelUIs() {
this._labelsContent.find('.labelContentElement').addClass('hidden'); this._labelsContent.find('.labelContentElement').addClass('hidden');
let labels = new Set(this._currentModels.map((el) => el.label));
for (let label of labels) {
this._labelsContent.find(`.labelContentElement[label_id="${label}"]`).removeClass('hidden');
}
}
onCollectionUpdate(collection) {
// Save parents and detach elements from DOM // Save parents and detach elements from DOM
// in order to increase performance in the buildShapeView function // in order to increase performance in the buildShapeView function
let parents = { let parents = {
@ -1268,7 +1274,6 @@ class ShapeCollectionView {
else { else {
this._currentViews.push(oldViews[oldIdx]); this._currentViews.push(oldViews[oldIdx]);
this._currentModels.push(oldModels[oldIdx]); this._currentModels.push(oldModels[oldIdx]);
this._labelsContent.find(`.labelContentElement[label_id="${oldModels[oldIdx].label}"]`).removeClass('hidden');
} }
} }
@ -1284,10 +1289,9 @@ class ShapeCollectionView {
parents.uis.prepend(this._UIContent); parents.uis.prepend(this._UIContent);
} }
ShapeCollectionView.sortByZOrder(); ShapeCollectionView.sortByZOrder();
this._frameMarker = window.cvat.player.frames.current; this._frameMarker = window.cvat.player.frames.current;
this._updateLabelUIs();
function drawView(shape, model) { function drawView(shape, model) {
let view = buildShapeView(model, buildShapeController(model), this._frameContent, this._UIContent); let view = buildShapeView(model, buildShapeController(model), this._frameContent, this._UIContent);
@ -1297,7 +1301,6 @@ class ShapeCollectionView {
view.subscribe(this); view.subscribe(this);
this._currentViews.push(view); this._currentViews.push(view);
this._currentModels.push(model); this._currentModels.push(model);
this._labelsContent.find(`.labelContentElement[label_id="${model.label}"]`).removeClass('hidden');
} }
} }
@ -1327,18 +1330,37 @@ class ShapeCollectionView {
} }
onShapeViewUpdate(view) { onShapeViewUpdate(view) {
if (view.dragging) { switch (view.updateReason) {
window.cvat.mode = 'drag'; case 'drag':
} if (view.dragging) {
else if (window.cvat.mode === 'drag') { window.cvat.mode = 'drag';
window.cvat.mode = null; }
else if (window.cvat.mode === 'drag') {
window.cvat.mode = null;
}
break;
case 'resize':
if (view.resize) {
window.cvat.mode = 'resize';
}
else if (window.cvat.mode === 'resize') {
window.cvat.mode = null;
}
break;
case 'remove': {
let idx = this._currentViews.indexOf(view);
view.unsubscribe(this);
view.controller().model().unsubscribe(view);
view.erase();
this._currentViews.splice(idx, 1);
this._currentModels.splice(idx, 1);
this._updateLabelUIs();
break;
} }
case 'changelabel': {
if (view.resize) { this._updateLabelUIs();
window.cvat.mode = 'resize'; break;
} }
else if (window.cvat.mode === 'resize') {
window.cvat.mode = null;
} }
} }

@ -272,7 +272,7 @@ class ShapeModel extends Listener {
this._label = +labelId; this._label = +labelId;
this._importAttributes([], []); this._importAttributes([], []);
this._setupKeyFrames(); this._setupKeyFrames();
this.notify('attributes'); this.notify('changelabel');
} }
else { else {
throw Error(`Unknown label id value found: ${labelId}`); throw Error(`Unknown label id value found: ${labelId}`);
@ -1403,6 +1403,7 @@ class ShapeView extends Listener {
}; };
this._controller = shapeController; this._controller = shapeController;
this._updateReason = null;
this._shapeContextMenu = $('#shapeContextMenu'); this._shapeContextMenu = $('#shapeContextMenu');
this._pointContextMenu = $('#pointContextMenu'); this._pointContextMenu = $('#pointContextMenu');
@ -1426,7 +1427,7 @@ class ShapeView extends Listener {
this._flags.dragging = true; this._flags.dragging = true;
blurAllElements(); blurAllElements();
this._hideShapeText(); this._hideShapeText();
this.notify(); this.notify('drag');
}).on('dragend', (e) => { }).on('dragend', (e) => {
let p1 = e.detail.handler.startPoints.point; let p1 = e.detail.handler.startPoints.point;
let p2 = e.detail.p; let p2 = e.detail.p;
@ -1438,7 +1439,7 @@ class ShapeView extends Listener {
events.drag = null; events.drag = null;
this._flags.dragging = false; this._flags.dragging = false;
this._showShapeText(); this._showShapeText();
this.notify(); this.notify('drag');
}); });
// Setup resize events // Setup resize events
@ -1456,7 +1457,7 @@ class ShapeView extends Listener {
events.resize = Logger.addContinuedEvent(Logger.EventType.resizeObject); events.resize = Logger.addContinuedEvent(Logger.EventType.resizeObject);
blurAllElements(); blurAllElements();
this._hideShapeText(); this._hideShapeText();
this.notify(); this.notify('resize');
}).on('resizing', () => { }).on('resizing', () => {
objWasResized = true; objWasResized = true;
}).on('resizedone', () => { }).on('resizedone', () => {
@ -1469,7 +1470,7 @@ class ShapeView extends Listener {
events.resize = null; events.resize = null;
this._flags.resizing = false; this._flags.resizing = false;
this._showShapeText(); this._showShapeText();
this.notify(); this.notify('resize');
}); });
@ -2353,6 +2354,18 @@ class ShapeView extends Listener {
} }
notify(newReason) {
let oldReason = this._updateReason;
this._updateReason = newReason;
try {
Listener.prototype.notify.call(this);
}
finally {
this._updateReason = oldReason;
}
}
// Inteface methods // Inteface methods
draw(interpolation) { draw(interpolation) {
let outside = interpolation.position.outside; let outside = interpolation.position.outside;
@ -2473,6 +2486,7 @@ class ShapeView extends Listener {
case 'remove': case 'remove':
if (model.removed) { if (model.removed) {
this.erase(); this.erase();
this.notify('remove');
} }
break; break;
case 'position': case 'position':
@ -2494,6 +2508,7 @@ class ShapeView extends Listener {
if (colorByLabel.prop('checked')) { if (colorByLabel.prop('checked')) {
colorByLabel.trigger('change'); colorByLabel.trigger('change');
} }
this.notify('changelabel');
break; break;
} }
case 'attributeFocus': { case 'attributeFocus': {
@ -2663,6 +2678,10 @@ class ShapeView extends Listener {
return this._flags.resizing; return this._flags.resizing;
} }
get updateReason() {
return this._updateReason;
}
// Used in shapeGrouper in order to get model via controller and set group id // Used in shapeGrouper in order to get model via controller and set group id
controller() { controller() {
return this._controller; return this._controller;

Loading…
Cancel
Save