1
1
// Copyright (C) 2021-2022 Intel Corporation
2
- // Copyright (C) 2022 CVAT.ai Corporation
2
+ // Copyright (C) 2022-2023 CVAT.ai Corporation
3
3
//
4
4
// SPDX-License-Identifier: MIT
5
5
@@ -18,7 +18,14 @@ export interface ActiveElement {
18
18
19
19
export interface GroupData {
20
20
enabled : boolean ;
21
- grouped : ObjectState [ ] ;
21
+ }
22
+
23
+ export interface MergeData {
24
+ enabled : boolean ;
25
+ }
26
+
27
+ export interface SplitData {
28
+ enabled : boolean ;
22
29
}
23
30
24
31
export interface Configuration {
@@ -80,6 +87,8 @@ export enum UpdateReasons {
80
87
DRAG_CANVAS = 'drag_canvas' ,
81
88
SHAPE_ACTIVATED = 'shape_activated' ,
82
89
GROUP = 'group' ,
90
+ MERGE = 'merge' ,
91
+ SPLIT = 'split' ,
83
92
FITTED_CANVAS = 'fitted_canvas' ,
84
93
CONFIG_UPDATED = 'config_updated' ,
85
94
SHAPES_CONFIG_UPDATED = 'shapes_config_updated' ,
@@ -91,6 +100,8 @@ export enum Mode {
91
100
EDIT = 'edit' ,
92
101
DRAG_CANVAS = 'drag_canvas' ,
93
102
GROUP = 'group' ,
103
+ MERGE = 'merge' ,
104
+ SPLIT = 'split' ,
94
105
}
95
106
96
107
export interface Canvas3dDataModel {
@@ -106,6 +117,8 @@ export interface Canvas3dDataModel {
106
117
objects : ObjectState [ ] ;
107
118
shapeProperties : ShapeProperties ;
108
119
groupData : GroupData ;
120
+ mergeData : MergeData ;
121
+ splitData : SplitData ;
109
122
configuration : Configuration ;
110
123
isFrameUpdating : boolean ;
111
124
nextSetupRequest : {
@@ -119,6 +132,7 @@ export interface Canvas3dModel {
119
132
data : Canvas3dDataModel ;
120
133
readonly imageIsDeleted : boolean ;
121
134
readonly groupData : GroupData ;
135
+ readonly mergeData : MergeData ;
122
136
readonly configuration : Configuration ;
123
137
readonly objects : ObjectState [ ] ;
124
138
setup ( frameData : any , objectStates : ObjectState [ ] ) : void ;
@@ -131,6 +145,8 @@ export interface Canvas3dModel {
131
145
configure ( configuration : Configuration ) : void ;
132
146
fit ( ) : void ;
133
147
group ( groupData : GroupData ) : void ;
148
+ split ( splitData : SplitData ) : void ;
149
+ merge ( mergeData : MergeData ) : void ;
134
150
destroy ( ) : void ;
135
151
updateCanvasObjects ( ) : void ;
136
152
unlockFrameUpdating ( ) : void ;
@@ -166,7 +182,12 @@ export class Canvas3dModelImpl extends MasterImpl implements Canvas3dModel {
166
182
mode : Mode . IDLE ,
167
183
groupData : {
168
184
enabled : false ,
169
- grouped : [ ] ,
185
+ } ,
186
+ mergeData : {
187
+ enabled : false ,
188
+ } ,
189
+ splitData : {
190
+ enabled : false ,
170
191
} ,
171
192
shapeProperties : {
172
193
opacity : 40 ,
@@ -343,10 +364,30 @@ export class Canvas3dModelImpl extends MasterImpl implements Canvas3dModel {
343
364
return ;
344
365
}
345
366
this . data . mode = groupData . enabled ? Mode . GROUP : Mode . IDLE ;
346
- this . data . groupData = { ...this . data . groupData , ... groupData } ;
367
+ this . data . groupData = { ...groupData } ;
347
368
this . notify ( UpdateReasons . GROUP ) ;
348
369
}
349
370
371
+ public split ( splitData : SplitData ) : void {
372
+ if ( ! [ Mode . IDLE , Mode . SPLIT ] . includes ( this . data . mode ) ) {
373
+ throw Error ( `Canvas is busy. Action: ${ this . data . mode } ` ) ;
374
+ }
375
+
376
+ this . data . mode = splitData . enabled ? Mode . SPLIT : Mode . IDLE ;
377
+ this . data . splitData = { ...splitData } ;
378
+ this . notify ( UpdateReasons . SPLIT ) ;
379
+ }
380
+
381
+ public merge ( mergeData : MergeData ) : void {
382
+ if ( ! [ Mode . IDLE , Mode . MERGE ] . includes ( this . data . mode ) ) {
383
+ throw Error ( `Canvas is busy. Action: ${ this . data . mode } ` ) ;
384
+ }
385
+
386
+ this . data . mode = mergeData . enabled ? Mode . MERGE : Mode . IDLE ;
387
+ this . data . mergeData = { ...mergeData } ;
388
+ this . notify ( UpdateReasons . MERGE ) ;
389
+ }
390
+
350
391
public configure ( configuration : Configuration ) : void {
351
392
if ( typeof configuration . resetZoom === 'boolean' ) {
352
393
this . data . configuration . resetZoom = configuration . resetZoom ;
@@ -391,6 +432,10 @@ export class Canvas3dModelImpl extends MasterImpl implements Canvas3dModel {
391
432
return { ...this . data . groupData } ;
392
433
}
393
434
435
+ public get mergeData ( ) : MergeData {
436
+ return { ...this . data . mergeData } ;
437
+ }
438
+
394
439
public get imageIsDeleted ( ) : boolean {
395
440
return this . data . imageIsDeleted ;
396
441
}
0 commit comments