Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Multiple regions selection interactions #240

Merged
merged 38 commits into from
Sep 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
90d82f5
[ext] Add multiple regions selection
Gondragos Aug 18, 2021
4d26cb2
Merge remote-tracking branch 'origin/master' into feature/multiselection
Gondragos Aug 18, 2021
39f2b78
Commit missed files
Gondragos Aug 18, 2021
647ec78
Fix setting layer ref
Gondragos Aug 19, 2021
b3ff11e
Hide selection borders while one region chosen
Gondragos Aug 19, 2021
f9f36c2
Fix selecting labels on region selecting and make selection tool opti…
Gondragos Aug 19, 2021
28df090
Fix cyclic calculations in brush drawing
Gondragos Aug 23, 2021
73ae855
[ext] Add transform interactions of multiple regions
Gondragos Aug 27, 2021
ea7a0d6
Fix regions drawing
Gondragos Aug 27, 2021
95054d4
[ext] Add copy, paste and cut regions hotkey interactions
Gondragos Aug 27, 2021
93b7c68
Fix pasting with no focus element
Gondragos Aug 27, 2021
e61cd96
[ext] Addduplicate selected regions hotkey interactions
Gondragos Aug 27, 2021
61af809
Fix test. Visible shapes counting
Gondragos Aug 27, 2021
76ab9dd
Fix rle2region label hiding
Gondragos Aug 27, 2021
48ebfd7
Fix code in tests
Gondragos Aug 27, 2021
9279f05
Fix counting visible image regions
Gondragos Aug 27, 2021
c8f8989
Merge branch 'master' into feature/multiselection
Gondragos Aug 27, 2021
4462f98
Allow select regions by selection tool with ctrl+click
Gondragos Aug 27, 2021
f4c1f8f
Update backspace hotkey action
Gondragos Aug 31, 2021
f7612ec
Add highlighting for selected shapes
Gondragos Aug 31, 2021
74d6b00
[ext] make transformer working for polygons and keypoints
Gondragos Sep 3, 2021
a67cf83
Add calculating bboxes inside mst models for image regions
Gondragos Sep 6, 2021
ea83a0f
Subscribe labelOnRegion to bboxCoords field
Gondragos Sep 6, 2021
82e38da
Improve brush regions caching and fix drawing
Gondragos Sep 7, 2021
6bdc810
Merge branch 'fix/brushes' into feature/multiselection
Gondragos Sep 7, 2021
d528954
Merge branch 'master' into feature/multiselection
Gondragos Sep 7, 2021
4d917c5
fix Region2RLE function
Gondragos Sep 7, 2021
b257e17
allow ctrl+click selection for polygons and inside selection
Gondragos Sep 7, 2021
56488d8
fix brush highlight toggle off
Gondragos Sep 7, 2021
60b5e80
fix Region2RLE function
Gondragos Sep 7, 2021
9446db7
fix brush highlight toggle off
Gondragos Sep 7, 2021
93166a7
Merge branch 'master' into fix/brushes
Gondragos Sep 8, 2021
39ba9cb
fix page crashing on switching tasks with polygons
Gondragos Sep 8, 2021
8ce4235
fix brush drawing glitch v2
Gondragos Sep 8, 2021
f5aaf13
Merge branch 'fix/brushes' into feature/multiselection
Gondragos Sep 8, 2021
c0ace7f
fix bboxCoords for rotated shapes
Gondragos Sep 9, 2021
c20ce89
fix creating relation to brush region
Gondragos Sep 9, 2021
6bbcaf4
Fix multiselection moving by dragging polygon region
Gondragos Sep 9, 2021
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
Prev Previous commit
Next Next commit
[ext] Add copy, paste and cut regions hotkey interactions
Gondragos committed Aug 27, 2021
commit 95054d47ac3edcc800becb1737e799d31df5c333
60 changes: 59 additions & 1 deletion src/components/CurrentEntity/CurrentEntity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, observer } from "mobx-react";
import React from "react";
import React, { useEffect } from "react";
import { LsSettings, LsTrash } from "../../assets/icons";
import { Button } from "../../common/Button/Button";
import { confirm } from "../../common/Modal/Modal";
@@ -26,6 +26,64 @@ export const CurrentEntity = injector(observer(({
const isPrediction = entity?.type === 'prediction';
const saved = !entity.userGenerate || entity.sentUserGenerate;

useEffect(()=>{
const copyToClipboard = (ev) => {
const { clipboardData } = ev;
const results = entity.serializedSelection;

clipboardData.setData('application/json', JSON.stringify(results));
ev.preventDefault();

};
const pasteFromClipboard = (ev) => {
const { clipboardData } = ev;
const data = clipboardData.getData('application/json');

try {
const results = JSON.parse(data);

entity.appendResults(results);
ev.preventDefault();
} catch (e) {
return;
}
};

const copyHandler = (ev) =>{
const selection = window.getSelection();

if (!selection.isCollapsed) return;

copyToClipboard(ev);
};
const pasteHandler = (ev) =>{
const selection = window.getSelection();

if (Node.ELEMENT_NODE === selection.focusNode.nodeType && selection.focusNode.focus) return;

pasteFromClipboard(ev);
};
const cutHandler = (ev) =>{
const selection = window.getSelection();

if (!selection.isCollapsed) return;

copyToClipboard(ev);
entity.deleteSelectedRegions();

console.log("Window event: cutHandler", ev);
};

window.addEventListener("copy", copyHandler);
window.addEventListener("paste", pasteHandler);
window.addEventListener("cut", cutHandler);
return () => {
window.removeEventListener("copy", copyHandler);
window.removeEventListener("paste", pasteHandler);
window.removeEventListener("cut", cutHandler);
};
}, [entity.pk ?? entity.id]);

return entity ? (
<Block name="annotation" onClick={e => e.stopPropagation()}>
<Elem name="info" tag={Space} spread>
35 changes: 35 additions & 0 deletions src/stores/AnnotationStore.js
Original file line number Diff line number Diff line change
@@ -133,6 +133,24 @@ const Annotation = types
.concat(self.relationStore.serializeAnnotation());
},

get serializedSelection() {
// Dirty hack to force MST track changes
self.areas.toJSON();

const selectedResults = [];

self.areas.forEach(a => {
if (!a.inSelection) return;
a.results.forEach(r => {
selectedResults.push(r);
});
});

return selectedResults
.map(r => r.serialize())
.filter(Boolean);
},

get highlightedNode() {
return self.regionStore.selection.highlighted;
},
@@ -640,6 +658,23 @@ const Annotation = types
return area;
},

appendResults(results) {
const regionIdMap = {};

// Generate new ids to prevent collisions
results.forEach((result)=>{
const regionId = result.id;

if (!regionIdMap[regionId]) {
regionIdMap[regionId] = guidGenerator();
}
result.id = regionIdMap[regionId];
});

self.deserializeAnnotation(results);
self.updateObjects();
},

serializeAnnotation() {
return self.serialized;
},