@@ -437,6 +437,10 @@ export class CanvasViewImpl implements CanvasView, Listener {
437
437
. filter ( ( _state : any ) : boolean => (
438
438
_state . clientID === self . activeElement . clientID
439
439
) ) ;
440
+ if ( [ 'cuboid' , 'rectangle' ] . includes ( state . shapeType ) ) {
441
+ e . preventDefault ( ) ;
442
+ return ;
443
+ }
440
444
if ( e . ctrlKey ) {
441
445
const { points } = state ;
442
446
self . onEditDone (
@@ -721,7 +725,10 @@ export class CanvasViewImpl implements CanvasView, Listener {
721
725
public notify ( model : CanvasModel & Master , reason : UpdateReasons ) : void {
722
726
this . geometry = this . controller . geometry ;
723
727
if ( reason === UpdateReasons . CONFIG_UPDATED ) {
728
+ const { activeElement } = this ;
729
+ this . deactivate ( ) ;
724
730
this . configuration = model . configuration ;
731
+ this . activate ( activeElement ) ;
725
732
this . editHandler . configurate ( this . configuration ) ;
726
733
this . drawHandler . configurate ( this . configuration ) ;
727
734
@@ -939,26 +946,63 @@ export class CanvasViewImpl implements CanvasView, Listener {
939
946
for ( const state of states ) {
940
947
if ( state . hidden || state . outside ) continue ;
941
948
ctx . fillStyle = 'white' ;
942
- if ( [ 'rectangle' , 'polygon' ] . includes ( state . shapeType ) ) {
943
- const points = state . shapeType === 'rectangle' ? [
944
- state . points [ 0 ] , // xtl
945
- state . points [ 1 ] , // ytl
946
- state . points [ 2 ] , // xbr
947
- state . points [ 1 ] , // ytl
948
- state . points [ 2 ] , // xbr
949
- state . points [ 3 ] , // ybr
950
- state . points [ 0 ] , // xtl
951
- state . points [ 3 ] , // ybr
952
- ] : state . points ;
949
+ if ( [ 'rectangle' , 'polygon' , 'cuboid' ] . includes ( state . shapeType ) ) {
950
+ let points = [ ] ;
951
+ if ( state . shapeType === 'rectangle' ) {
952
+ points = [
953
+ state . points [ 0 ] , // xtl
954
+ state . points [ 1 ] , // ytl
955
+ state . points [ 2 ] , // xbr
956
+ state . points [ 1 ] , // ytl
957
+ state . points [ 2 ] , // xbr
958
+ state . points [ 3 ] , // ybr
959
+ state . points [ 0 ] , // xtl
960
+ state . points [ 3 ] , // ybr
961
+ ] ;
962
+ } else if ( state . shapeType === 'cuboid' ) {
963
+ points = [
964
+ state . points [ 0 ] ,
965
+ state . points [ 1 ] ,
966
+ state . points [ 4 ] ,
967
+ state . points [ 5 ] ,
968
+ state . points [ 8 ] ,
969
+ state . points [ 9 ] ,
970
+ state . points [ 12 ] ,
971
+ state . points [ 13 ] ,
972
+ ] ;
973
+ } else {
974
+ points = [ ...state . points ] ;
975
+ }
953
976
ctx . beginPath ( ) ;
954
977
ctx . moveTo ( points [ 0 ] , points [ 1 ] ) ;
955
978
for ( let i = 0 ; i < points . length ; i += 2 ) {
956
979
ctx . lineTo ( points [ i ] , points [ i + 1 ] ) ;
957
980
}
958
981
ctx . closePath ( ) ;
982
+ ctx . fill ( ) ;
959
983
}
960
984
961
- ctx . fill ( ) ;
985
+ if ( state . shapeType === 'cuboid' ) {
986
+ for ( let i = 0 ; i < 5 ; i ++ ) {
987
+ const points = [
988
+ state . points [ ( 0 + i * 4 ) % 16 ] ,
989
+ state . points [ ( 1 + i * 4 ) % 16 ] ,
990
+ state . points [ ( 2 + i * 4 ) % 16 ] ,
991
+ state . points [ ( 3 + i * 4 ) % 16 ] ,
992
+ state . points [ ( 6 + i * 4 ) % 16 ] ,
993
+ state . points [ ( 7 + i * 4 ) % 16 ] ,
994
+ state . points [ ( 4 + i * 4 ) % 16 ] ,
995
+ state . points [ ( 5 + i * 4 ) % 16 ] ,
996
+ ] ;
997
+ ctx . beginPath ( ) ;
998
+ ctx . moveTo ( points [ 0 ] , points [ 1 ] ) ;
999
+ for ( let j = 0 ; j < points . length ; j += 2 ) {
1000
+ ctx . lineTo ( points [ j ] , points [ j + 1 ] ) ;
1001
+ }
1002
+ ctx . closePath ( ) ;
1003
+ ctx . fill ( ) ;
1004
+ }
1005
+ }
962
1006
}
963
1007
}
964
1008
}
@@ -1055,7 +1099,9 @@ export class CanvasViewImpl implements CanvasView, Listener {
1055
1099
return `${ acc } ${ val } ,` ;
1056
1100
} , '' ,
1057
1101
) ;
1058
- ( shape as any ) . clear ( ) ;
1102
+ if ( state . shapeType !== 'cuboid' ) {
1103
+ ( shape as any ) . clear ( ) ;
1104
+ }
1059
1105
shape . attr ( 'points' , stringified ) ;
1060
1106
1061
1107
if ( state . shapeType === 'points' && ! isInvisible ) {
@@ -1116,6 +1162,9 @@ export class CanvasViewImpl implements CanvasView, Listener {
1116
1162
} else if ( state . shapeType === 'points' ) {
1117
1163
this . svgShapes [ state . clientID ] = this
1118
1164
. addPoints ( stringified , state ) ;
1165
+ } else if ( state . shapeType === 'cuboid' ) {
1166
+ this . svgShapes [ state . clientID ] = this
1167
+ . addCuboid ( stringified , state ) ;
1119
1168
}
1120
1169
}
1121
1170
@@ -1202,6 +1251,10 @@ export class CanvasViewImpl implements CanvasView, Listener {
1202
1251
this . selectize ( false , shape ) ;
1203
1252
}
1204
1253
1254
+ if ( drawnState . shapeType === 'cuboid' ) {
1255
+ ( shape as any ) . attr ( 'projections' , false ) ;
1256
+ }
1257
+
1205
1258
( shape as any ) . off ( 'resizestart' ) ;
1206
1259
( shape as any ) . off ( 'resizing' ) ;
1207
1260
( shape as any ) . off ( 'resizedone' ) ;
@@ -1281,6 +1334,11 @@ export class CanvasViewImpl implements CanvasView, Listener {
1281
1334
this . content . append ( shape . node ) ;
1282
1335
}
1283
1336
1337
+ const { showProjections } = this . configuration ;
1338
+ if ( state . shapeType === 'cuboid' && showProjections ) {
1339
+ ( shape as any ) . attr ( 'projections' , true ) ;
1340
+ }
1341
+
1284
1342
if ( ! state . pinned ) {
1285
1343
shape . addClass ( 'cvat_canvas_shape_draggable' ) ;
1286
1344
( shape as any ) . draggable ( ) . on ( 'dragstart' , ( ) : void => {
@@ -1548,6 +1606,30 @@ export class CanvasViewImpl implements CanvasView, Listener {
1548
1606
return polyline ;
1549
1607
}
1550
1608
1609
+ private addCuboid ( points : string , state : any ) : any {
1610
+ const cube = ( this . adoptedContent as any ) . cube ( points )
1611
+ . fill ( state . color ) . attr ( {
1612
+ clientID : state . clientID ,
1613
+ 'color-rendering' : 'optimizeQuality' ,
1614
+ id : `cvat_canvas_shape_${ state . clientID } ` ,
1615
+ fill : state . color ,
1616
+ 'shape-rendering' : 'geometricprecision' ,
1617
+ stroke : state . color ,
1618
+ 'stroke-width' : consts . BASE_STROKE_WIDTH / this . geometry . scale ,
1619
+ 'data-z-order' : state . zOrder ,
1620
+ } ) . addClass ( 'cvat_canvas_shape' ) ;
1621
+
1622
+ if ( state . occluded ) {
1623
+ cube . addClass ( 'cvat_canvas_shape_occluded' ) ;
1624
+ }
1625
+
1626
+ if ( state . hidden || state . outside ) {
1627
+ cube . style ( 'display' , 'none' ) ;
1628
+ }
1629
+
1630
+ return cube ;
1631
+ }
1632
+
1551
1633
private setupPoints ( basicPolyline : SVG . PolyLine , state : any ) : any {
1552
1634
this . selectize ( true , basicPolyline ) ;
1553
1635
0 commit comments