@@ -36,6 +36,7 @@ import { useDropzone } from "react-dropzone";
3636import { useDispatch , useSelector } from "react-redux" ;
3737import {
3838 changeCurrentDrawType ,
39+ changeCurrentStatus ,
3940 changeZoom ,
4041 createDrawObject ,
4142 redoDrawObject ,
@@ -44,11 +45,12 @@ import {
4445} from "reduxes/annotation/action" ;
4546import {
4647 selectorAnnotationStatehHistory ,
48+ selectorCurrentDrawState ,
4749 selectorcurrentDrawType ,
4850 selectorDrawObjectById ,
4951 selectorDrawObjectStateIdByAI ,
5052} from "reduxes/annotation/selector" ;
51- import { DrawObject , DrawType } from "reduxes/annotation/type" ;
53+ import { DrawObject , DrawState , DrawType } from "reduxes/annotation/type" ;
5254import {
5355 addImagesToAnnotation ,
5456 addNewClassLabel ,
@@ -64,10 +66,21 @@ import {
6466} from "reduxes/annotationmanager/selecetor" ;
6567import { hashCode , intToRGB } from "../LabelAnnotation" ;
6668import { convertStrokeColorToFillColor } from "../LabelAnnotation/ClassLabel" ;
69+ import NearMeIcon from "@mui/icons-material/NearMe" ;
70+ import {
71+ MAX_HEIGHT_IMAGE_IN_EDITOR ,
72+ MAX_WIDTH_IMAGE_IN_EDITOR ,
73+ } from "components/Annotation/Editor/const" ;
74+ import { getFitScaleEditor } from "components/Annotation/Editor/utils" ;
6775
6876const ControlPanel = ( ) => {
6977 const dispatch = useDispatch ( ) ;
70- const currentDrawType = useSelector ( selectorcurrentDrawType ) ;
78+ const [ drawType , setDrawType ] = React . useState < DrawType | null > (
79+ useSelector ( selectorcurrentDrawType )
80+ ) ;
81+ const [ drawState , setDrawState ] = React . useState < DrawState | null > (
82+ useSelector ( selectorCurrentDrawState )
83+ ) ;
7184 const drawObjectById = useSelector ( selectorDrawObjectById ) ;
7285 const currentPreviewImageName = useSelector ( selectorCurrentPreviewImageName ) ;
7386 const currentAnnotationFile = useSelector ( selectorCurrentAnnotationFile ) ;
@@ -88,14 +101,32 @@ const ControlPanel = () => {
88101 ) ;
89102
90103 const resetScaleHandler = ( ) => {
91- dispatch ( changeZoom ( { zoom : { zoom : 1 , position : { x : 0 , y : 0 } } } ) ) ;
104+ if ( currentAnnotationFile ) {
105+ const { width, height } = currentAnnotationFile ;
106+ const zoom = getFitScaleEditor ( width , height ) ;
107+ dispatch (
108+ changeZoom ( {
109+ zoom : { zoom, position : { x : 0 , y : 0 } } ,
110+ } )
111+ ) ;
112+ }
92113 } ;
93114
94115 const selectModeHandle = (
95116 event : React . MouseEvent < HTMLElement > ,
96- drawType : DrawType
117+ type : DrawType
97118 ) => {
98- dispatch ( changeCurrentDrawType ( { currentDrawType : drawType } ) ) ;
119+ dispatch ( changeCurrentDrawType ( { currentDrawType : type } ) ) ;
120+ setDrawType ( type ) ;
121+ setDrawState ( null ) ;
122+ } ;
123+ const handleSelectDrawState = (
124+ event : React . MouseEvent < HTMLElement > ,
125+ state : DrawState
126+ ) => {
127+ dispatch ( changeCurrentStatus ( { drawState : state } ) ) ;
128+ setDrawState ( state ) ;
129+ setDrawType ( null ) ;
99130 } ;
100131 const handleExportLabelMe = ( ) => {
101132 if ( currentAnnotationFile && drawObjectById ) {
@@ -350,7 +381,7 @@ const ControlPanel = () => {
350381 < >
351382 < Box sx = { { minWidth : 100 } } display = "flex" flexDirection = "column" gap = { 1 } >
352383 < ToggleButtonGroup
353- value = { currentDrawType }
384+ value = { drawType }
354385 exclusive
355386 onChange = { selectModeHandle }
356387 aria-label = "mode"
@@ -387,6 +418,23 @@ const ControlPanel = () => {
387418 < PolylineIcon />
388419 </ ToggleButton >
389420 </ ToggleButtonGroup >
421+ < ToggleButtonGroup
422+ value = { drawState }
423+ exclusive
424+ onChange = { handleSelectDrawState }
425+ aria-label = "mode"
426+ className = "annotationControlPanel"
427+ size = "large"
428+ sx = { { border : "1px dashed grey" } }
429+ >
430+ < ToggleButton
431+ className = "annotationBtn"
432+ value = { DrawState . SELECTING }
433+ aria-label = "selecting"
434+ >
435+ < NearMeIcon />
436+ </ ToggleButton >
437+ </ ToggleButtonGroup >
390438 < Box
391439 display = "flex"
392440 mt = { 3 }
0 commit comments