feat(tool): size/pos store
This commit is contained in:
@@ -38,6 +38,7 @@ import {
|
|||||||
getTrackingAuxiliaryAnnotation,
|
getTrackingAuxiliaryAnnotation,
|
||||||
} from "../api/label"
|
} from "../api/label"
|
||||||
import { Project } from "../api/project/typing"
|
import { Project } from "../api/project/typing"
|
||||||
|
import { labelimagePerformanceConfig } from "../config/performance"
|
||||||
import { LabelState } from "../LabelNossr"
|
import { LabelState } from "../LabelNossr"
|
||||||
import {
|
import {
|
||||||
initialDetail,
|
initialDetail,
|
||||||
@@ -57,7 +58,6 @@ import useRenderTag from "../useRenderTag"
|
|||||||
import { useRightToolsStore } from "../useRightToolsStore"
|
import { useRightToolsStore } from "../useRightToolsStore"
|
||||||
import { useTopToolsStore } from "../useTopToolsStore"
|
import { useTopToolsStore } from "../useTopToolsStore"
|
||||||
import { checkCommentsIsSame } from "../util"
|
import { checkCommentsIsSame } from "../util"
|
||||||
import { labelimagePerformanceConfig } from "../config/performance"
|
|
||||||
import { safeClone } from "../utils/clone"
|
import { safeClone } from "../utils/clone"
|
||||||
import { labelTypeMap } from "../utils/constants"
|
import { labelTypeMap } from "../utils/constants"
|
||||||
import { adjustPoints } from "../utils/paperjs"
|
import { adjustPoints } from "../utils/paperjs"
|
||||||
@@ -126,6 +126,11 @@ type FrameSwitchGhostState = {
|
|||||||
animating: boolean
|
animating: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clonePaperPoint = (point: paper.Point | null | undefined) => {
|
||||||
|
if (!point) return null
|
||||||
|
return new paper.Point(point.x, point.y)
|
||||||
|
}
|
||||||
|
|
||||||
const normalizePoint = (value: any): NormalizedPoint | null => {
|
const normalizePoint = (value: any): NormalizedPoint | null => {
|
||||||
if (value instanceof paper.Point) return [value.x, value.y]
|
if (value instanceof paper.Point) return [value.x, value.y]
|
||||||
if (value instanceof paper.Segment) {
|
if (value instanceof paper.Segment) {
|
||||||
@@ -445,6 +450,7 @@ const PaperContainer = (
|
|||||||
assistToolEnabled,
|
assistToolEnabled,
|
||||||
assistToolSize,
|
assistToolSize,
|
||||||
renderMode,
|
renderMode,
|
||||||
|
saveCurrentScale,
|
||||||
showTags,
|
showTags,
|
||||||
showTagsConfigs,
|
showTagsConfigs,
|
||||||
} = useTopToolsStore()
|
} = useTopToolsStore()
|
||||||
@@ -2583,6 +2589,24 @@ const PaperContainer = (
|
|||||||
}
|
}
|
||||||
}, [renderMode, stopRenderModePan])
|
}, [renderMode, stopRenderModePan])
|
||||||
|
|
||||||
|
const getTargetGroupPosition = useCallback(
|
||||||
|
({
|
||||||
|
defaultPosition,
|
||||||
|
preservedPosition,
|
||||||
|
canPreserve,
|
||||||
|
}: {
|
||||||
|
defaultPosition: paper.Point
|
||||||
|
preservedPosition?: paper.Point | null
|
||||||
|
canPreserve?: boolean
|
||||||
|
}) => {
|
||||||
|
if (saveCurrentScale && canPreserve && preservedPosition) {
|
||||||
|
return clonePaperPoint(preservedPosition) ?? defaultPosition.clone()
|
||||||
|
}
|
||||||
|
return defaultPosition.clone()
|
||||||
|
},
|
||||||
|
[saveCurrentScale]
|
||||||
|
)
|
||||||
|
|
||||||
const preparePendingFrameSwitch = useCallback(
|
const preparePendingFrameSwitch = useCallback(
|
||||||
async (imageName: string, token: number) => {
|
async (imageName: string, token: number) => {
|
||||||
if (
|
if (
|
||||||
@@ -2600,6 +2624,12 @@ const PaperContainer = (
|
|||||||
clearPendingFrameSwitch(token)
|
clearPendingFrameSwitch(token)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const preserveGroupPosition =
|
||||||
|
saveCurrentScale &&
|
||||||
|
currentVisibleGroup.getItems({ data: { name: "pic" } }).length > 0
|
||||||
|
const preservedGroupPosition = preserveGroupPosition
|
||||||
|
? clonePaperPoint(currentVisibleGroup.position)
|
||||||
|
: null
|
||||||
|
|
||||||
const stagingGroup = new paper.Group({
|
const stagingGroup = new paper.Group({
|
||||||
applyMatrix: false,
|
applyMatrix: false,
|
||||||
@@ -2684,10 +2714,15 @@ const PaperContainer = (
|
|||||||
raster.bounds.width / 2,
|
raster.bounds.width / 2,
|
||||||
raster.bounds.height / 2
|
raster.bounds.height / 2
|
||||||
)
|
)
|
||||||
stagingGroup.position = new paper.Point(
|
const centeredGroupPosition = new paper.Point(
|
||||||
raster.bounds.width / 2,
|
raster.bounds.width / 2,
|
||||||
raster.bounds.height / 2
|
raster.bounds.height / 2
|
||||||
)
|
)
|
||||||
|
stagingGroup.position = getTargetGroupPosition({
|
||||||
|
defaultPosition: centeredGroupPosition,
|
||||||
|
preservedPosition: preservedGroupPosition,
|
||||||
|
canPreserve: preserveGroupPosition,
|
||||||
|
})
|
||||||
raster.sendToBack()
|
raster.sendToBack()
|
||||||
|
|
||||||
const imageData = useLabelStore.getState().label.get(imageName)
|
const imageData = useLabelStore.getState().label.get(imageName)
|
||||||
@@ -2732,6 +2767,7 @@ const PaperContainer = (
|
|||||||
[
|
[
|
||||||
clearPendingFrameSwitch,
|
clearPendingFrameSwitch,
|
||||||
commitFrameSwitch,
|
commitFrameSwitch,
|
||||||
|
getTargetGroupPosition,
|
||||||
imgSize?.clientHeight,
|
imgSize?.clientHeight,
|
||||||
imgSize?.clientWidth,
|
imgSize?.clientWidth,
|
||||||
isPendingFrameSwitchStale,
|
isPendingFrameSwitchStale,
|
||||||
@@ -2739,6 +2775,7 @@ const PaperContainer = (
|
|||||||
reconcileRasterScaleForImage,
|
reconcileRasterScaleForImage,
|
||||||
renderImagePolygonsBatchedToGroup,
|
renderImagePolygonsBatchedToGroup,
|
||||||
renderTag,
|
renderTag,
|
||||||
|
saveCurrentScale,
|
||||||
setGroup,
|
setGroup,
|
||||||
setRasterPath,
|
setRasterPath,
|
||||||
setRasterSize,
|
setRasterSize,
|
||||||
@@ -2823,6 +2860,11 @@ const PaperContainer = (
|
|||||||
if (activeImage && projectDetail?.id) {
|
if (activeImage && projectDetail?.id) {
|
||||||
const requestId = ++rasterLoadRequestIdRef.current
|
const requestId = ++rasterLoadRequestIdRef.current
|
||||||
const requestImage = activeImage
|
const requestImage = activeImage
|
||||||
|
const preserveGroupPosition =
|
||||||
|
saveCurrentScale && getPicRasters(paperGroup).length > 0
|
||||||
|
const preservedGroupPosition = preserveGroupPosition
|
||||||
|
? clonePaperPoint(paperGroup.position)
|
||||||
|
: null
|
||||||
rasterLoadingImageRef.current = requestImage
|
rasterLoadingImageRef.current = requestImage
|
||||||
cancelRasterFadeTransition()
|
cancelRasterFadeTransition()
|
||||||
getPicRasters(paperGroup).forEach((item) => {
|
getPicRasters(paperGroup).forEach((item) => {
|
||||||
@@ -2981,6 +3023,10 @@ const PaperContainer = (
|
|||||||
raster.bounds.width / 2,
|
raster.bounds.width / 2,
|
||||||
raster.bounds.height / 2
|
raster.bounds.height / 2
|
||||||
)
|
)
|
||||||
|
const centeredGroupPosition = new paper.Point(
|
||||||
|
raster.bounds.width / 2,
|
||||||
|
raster.bounds.height / 2
|
||||||
|
)
|
||||||
raster.visible = true
|
raster.visible = true
|
||||||
const previousRasters = getPicRasters(paperGroup).filter(
|
const previousRasters = getPicRasters(paperGroup).filter(
|
||||||
(item) => item !== raster
|
(item) => item !== raster
|
||||||
@@ -3034,10 +3080,11 @@ const PaperContainer = (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
usePaperStore.getState().group!.position = new paper.Point(
|
paperGroup.position = getTargetGroupPosition({
|
||||||
raster.bounds.width / 2,
|
defaultPosition: centeredGroupPosition,
|
||||||
raster.bounds.height / 2
|
preservedPosition: preservedGroupPosition,
|
||||||
)
|
canPreserve: preserveGroupPosition,
|
||||||
|
})
|
||||||
setRasterPath(new paper.Path.Rectangle(raster.bounds))
|
setRasterPath(new paper.Path.Rectangle(raster.bounds))
|
||||||
raster.sendToBack()
|
raster.sendToBack()
|
||||||
renderedImageRef.current = requestImage
|
renderedImageRef.current = requestImage
|
||||||
@@ -3059,9 +3106,11 @@ const PaperContainer = (
|
|||||||
cancelRasterFadeTransition,
|
cancelRasterFadeTransition,
|
||||||
decodeFrameImage,
|
decodeFrameImage,
|
||||||
getPicRasters,
|
getPicRasters,
|
||||||
|
getTargetGroupPosition,
|
||||||
imgSize?.clientHeight,
|
imgSize?.clientHeight,
|
||||||
imgSize?.clientWidth,
|
imgSize?.clientWidth,
|
||||||
projectDetail?.id,
|
projectDetail?.id,
|
||||||
|
saveCurrentScale,
|
||||||
setRasterPath,
|
setRasterPath,
|
||||||
setRasterScale,
|
setRasterScale,
|
||||||
setRasterSize,
|
setRasterSize,
|
||||||
@@ -3171,6 +3220,9 @@ const PaperContainer = (
|
|||||||
: undefined) ||
|
: undefined) ||
|
||||||
(rasterItems.length ? rasterItems[rasterItems.length - 1] : undefined)
|
(rasterItems.length ? rasterItems[rasterItems.length - 1] : undefined)
|
||||||
if (!currentRaster) return false
|
if (!currentRaster) return false
|
||||||
|
const preservedGroupPosition = saveCurrentScale
|
||||||
|
? clonePaperPoint(group.position)
|
||||||
|
: null
|
||||||
|
|
||||||
const rasterSizeStore = usePaperStore.getState().rasterSize
|
const rasterSizeStore = usePaperStore.getState().rasterSize
|
||||||
const rawRasterSize = rasterSizeStore[activeImage] ?? [
|
const rawRasterSize = rasterSizeStore[activeImage] ?? [
|
||||||
@@ -3224,10 +3276,15 @@ const PaperContainer = (
|
|||||||
currentRaster.bounds.width / 2,
|
currentRaster.bounds.width / 2,
|
||||||
currentRaster.bounds.height / 2
|
currentRaster.bounds.height / 2
|
||||||
)
|
)
|
||||||
group.position = new paper.Point(
|
const centeredGroupPosition = new paper.Point(
|
||||||
currentRaster.bounds.width / 2,
|
currentRaster.bounds.width / 2,
|
||||||
currentRaster.bounds.height / 2
|
currentRaster.bounds.height / 2
|
||||||
)
|
)
|
||||||
|
group.position = getTargetGroupPosition({
|
||||||
|
defaultPosition: centeredGroupPosition,
|
||||||
|
preservedPosition: preservedGroupPosition,
|
||||||
|
canPreserve: saveCurrentScale,
|
||||||
|
})
|
||||||
|
|
||||||
setRasterPath(new paper.Path.Rectangle(currentRaster.bounds))
|
setRasterPath(new paper.Path.Rectangle(currentRaster.bounds))
|
||||||
setRasterScale(activeImage, nextScale)
|
setRasterScale(activeImage, nextScale)
|
||||||
@@ -3241,9 +3298,11 @@ const PaperContainer = (
|
|||||||
}, [
|
}, [
|
||||||
activeImage,
|
activeImage,
|
||||||
getPicRasters,
|
getPicRasters,
|
||||||
|
getTargetGroupPosition,
|
||||||
imgSize?.clientHeight,
|
imgSize?.clientHeight,
|
||||||
imgSize?.clientWidth,
|
imgSize?.clientWidth,
|
||||||
renderTag,
|
renderTag,
|
||||||
|
saveCurrentScale,
|
||||||
scaleRenderedAnnotationItemsInPlace,
|
scaleRenderedAnnotationItemsInPlace,
|
||||||
setRasterPath,
|
setRasterPath,
|
||||||
setRasterScale,
|
setRasterScale,
|
||||||
|
|||||||
Reference in New Issue
Block a user