이미지 캡쳐 전처리 후처리 추가

This commit is contained in:
hyojun.choi 2025-06-05 18:28:58 +09:00
parent a0c64bdaa8
commit bb7b9c020f

View File

@ -26,6 +26,7 @@ import { useImgLoader } from '@/hooks/floorPlan/useImgLoader'
import { usePlan } from '@/hooks/usePlan' import { usePlan } from '@/hooks/usePlan'
import { QcastContext } from '@/app/QcastProvider' import { QcastContext } from '@/app/QcastProvider'
import { fabric } from 'fabric' import { fabric } from 'fabric'
import { fontSelector } from '@/store/fontAtom'
const ALLOCATION_TYPE = { const ALLOCATION_TYPE = {
AUTO: 'auto', AUTO: 'auto',
@ -45,6 +46,9 @@ export default function CircuitTrestleSetting({ id }) {
const { managementState, setManagementState } = useContext(GlobalDataContext) const { managementState, setManagementState } = useContext(GlobalDataContext)
const selectedModules = useRecoilValue(selectedModuleState) const selectedModules = useRecoilValue(selectedModuleState)
const { getPcsAutoRecommendList, getPcsVoltageChk, getPcsVoltageStepUpList, getPcsManualConfChk } = useMasterController() const { getPcsAutoRecommendList, getPcsVoltageChk, getPcsVoltageStepUpList, getPcsManualConfChk } = useMasterController()
const flowText = useRecoilValue(fontSelector('flowText'))
const lengthText = useRecoilValue(fontSelector('lengthText'))
const circuitNumberText = useRecoilValue(fontSelector('circuitNumberText'))
// () // ()
const [selectedStepUpValues, setSelectedStepUpValues] = useState({}) const [selectedStepUpValues, setSelectedStepUpValues] = useState({})
@ -103,19 +107,26 @@ export default function CircuitTrestleSetting({ id }) {
} }
}, []) }, [])
// 50% //
const handleZoomCompression = () => { const beforeCapture = () => {
// setCanvasZoom(100) // setCanvasZoom(100)
const x = canvas.width / 2 const x = canvas.width / 2
const y = canvas.height / 2 const y = canvas.height / 2
canvas.zoomToPoint(new fabric.Point(x, y), 0.5) canvas.zoomToPoint(new fabric.Point(x, y), 0.5)
changeFontSize('lengthText', '28')
changeFontSize('circuitNumber', '28')
changeFontSize('flowText', '28')
canvas.renderAll() canvas.renderAll()
} }
const handleZoomClear = () => { //
const afterCapture = () => {
setCanvasZoom(100) setCanvasZoom(100)
canvas.set({ zoom: 1 }) canvas.set({ zoom: 1 })
canvas.viewportTransform = [1, 0, 0, 1, 0, 0] canvas.viewportTransform = [1, 0, 0, 1, 0, 0]
changeFontSize('lengthText', lengthText.fontSize.value)
changeFontSize('circuitNumber', circuitNumberText.fontSize.value)
changeFontSize('flowText', flowText.fontSize.value)
canvas.renderAll() canvas.renderAll()
} }
@ -360,7 +371,7 @@ export default function CircuitTrestleSetting({ id }) {
// () // ()
const onApply = async () => { const onApply = async () => {
handleZoomCompression() beforeCapture()
setAllModuleSurfaceIsComplete(false) setAllModuleSurfaceIsComplete(false)
setIsGlobalLoading(true) setIsGlobalLoading(true)
@ -392,7 +403,7 @@ export default function CircuitTrestleSetting({ id }) {
if (result) { if (result) {
handleCanvasToPng(2) handleCanvasToPng(2)
handleZoomClear() afterCapture()
// //
await saveEstimate(result) await saveEstimate(result)
} else { } else {
@ -402,6 +413,16 @@ export default function CircuitTrestleSetting({ id }) {
// removeNotAllocationModules() // removeNotAllocationModules()
} }
const changeFontSize = (name, size) => {
const textObjs = canvas?.getObjects().filter((obj) => obj.name === name)
textObjs.forEach((obj) => {
obj.set({
fontSize: size,
})
})
canvas.renderAll()
}
// //
const onClickPrev = () => { const onClickPrev = () => {
// setAllocationType(ALLOCATION_TYPE.AUTO) // setAllocationType(ALLOCATION_TYPE.AUTO)