Merge branch 'dev' of https://git.hanasys.jp/qcast3/qcast-front into feature/ysCha

This commit is contained in:
ysCha 2025-06-09 17:08:10 +09:00
commit 351df68762
4 changed files with 74 additions and 27 deletions

View File

@ -26,6 +26,7 @@
"framer-motion": "^11.2.13", "framer-motion": "^11.2.13",
"fs": "^0.0.1-security", "fs": "^0.0.1-security",
"iron-session": "^8.0.2", "iron-session": "^8.0.2",
"jimp": "^1.6.0",
"js-cookie": "^3.0.5", "js-cookie": "^3.0.5",
"mathjs": "^13.0.2", "mathjs": "^13.0.2",
"mssql": "^11.0.1", "mssql": "^11.0.1",

View File

@ -1,7 +1,8 @@
import { NextResponse } from 'next/server' import { NextResponse } from 'next/server'
import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3' import { DeleteObjectCommand, GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3'
import sharp from 'sharp'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import { Jimp } from 'jimp'
const Bucket = process.env.AMPLIFY_BUCKET const Bucket = process.env.AMPLIFY_BUCKET
const s3 = new S3Client({ const s3 = new S3Client({
region: process.env.AWS_REGION, region: process.env.AWS_REGION,
@ -23,8 +24,6 @@ const checkArea = (obj) => {
const cropImage = async (Key, width, height, left, top) => { const cropImage = async (Key, width, height, left, top) => {
try { try {
const checkResult = checkArea({ width, height, left, top })
// Get the image from S3 // Get the image from S3
const { Body } = await s3.send( const { Body } = await s3.send(
new GetObjectCommand({ new GetObjectCommand({
@ -33,28 +32,45 @@ const cropImage = async (Key, width, height, left, top) => {
}), }),
) )
// Convert stream to buffer
const chunks = [] const chunks = []
for await (const chunk of Body) { for await (const chunk of Body) {
chunks.push(chunk) chunks.push(chunk)
} }
const imageBuffer = Buffer.concat(chunks) const buffer = Buffer.concat(chunks)
let processedImage const image = await Jimp.read(buffer)
if (!checkResult) {
processedImage = await sharp(imageBuffer).toBuffer() image.autocrop({ tolerance: 0.0002, leaveBorder: 10 })
} else { return await image.getBuffer('image/png')
processedImage = await sharp(imageBuffer)
.extract({ // Convert stream to buffer
width: parseInt(width), // const chunks = []
height: parseInt(height), // for await (const chunk of Body) {
left: parseInt(left), // chunks.push(chunk)
top: parseInt(top), // }
}) // const imageBuffer = Buffer.concat(chunks)
.png()
.toBuffer() // const image = await Jimp.read(Body)
}
return processedImage // if (!checkResult) {
// processedImage = await image.toBuffer()
// }
//let processedImage
// if (!checkResult) {
// processedImage = await sharp(imageBuffer).toBuffer()
// } else {
// processedImage = await sharp(imageBuffer)
// .extract({
// width: parseInt(width),
// height: parseInt(height),
// left: parseInt(left),
// top: parseInt(top),
// })
// .png()
// .toBuffer()
// }
// return processedImage
} catch (error) { } catch (error) {
console.error('Error processing image:', error) console.error('Error processing image:', error)
throw error throw error

View File

@ -25,6 +25,8 @@ import { useCanvasPopupStatusController } from '@/hooks/common/useCanvasPopupSta
import { useImgLoader } from '@/hooks/floorPlan/useImgLoader' 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 { fontSelector } from '@/store/fontAtom'
const ALLOCATION_TYPE = { const ALLOCATION_TYPE = {
AUTO: 'auto', AUTO: 'auto',
@ -44,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({})
@ -102,10 +107,26 @@ export default function CircuitTrestleSetting({ id }) {
} }
}, []) }, [])
const handleZoomClear = () => { //
const beforeCapture = () => {
// setCanvasZoom(100)
const x = canvas.width / 2
const y = canvas.height / 2
canvas.zoomToPoint(new fabric.Point(x, y), 0.5)
changeFontSize('lengthText', '28')
changeFontSize('circuitNumber', '28')
changeFontSize('flowText', '28')
canvas.renderAll()
}
//
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()
} }
@ -350,7 +371,7 @@ export default function CircuitTrestleSetting({ id }) {
// () // ()
const onApply = async () => { const onApply = async () => {
handleZoomClear() beforeCapture()
setAllModuleSurfaceIsComplete(false) setAllModuleSurfaceIsComplete(false)
setIsGlobalLoading(true) setIsGlobalLoading(true)
@ -361,12 +382,9 @@ export default function CircuitTrestleSetting({ id }) {
obj.pcses = getStepUpListData() obj.pcses = getStepUpListData()
}) })
setViewCircuitNumberTexts(false)
handleCanvasToPng(1) handleCanvasToPng(1)
// result=null // result=null
setViewCircuitNumberTexts(true)
// //
// //
@ -382,6 +400,7 @@ export default function CircuitTrestleSetting({ id }) {
if (result) { if (result) {
handleCanvasToPng(2) handleCanvasToPng(2)
afterCapture()
// //
await saveEstimate(result) await saveEstimate(result)
} else { } else {
@ -391,6 +410,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)

View File

@ -314,7 +314,8 @@ export function useRoofAllocationSetting(id) {
setSurfaceShapePattern(currentObject, roofDisplay.column, false, selectedRoofMaterial, true) setSurfaceShapePattern(currentObject, roofDisplay.column, false, selectedRoofMaterial, true)
drawDirectionArrow(currentObject) drawDirectionArrow(currentObject)
modifyModuleSelectionData() modifyModuleSelectionData()
closeAll() // closeAll()
closePopup(id)
basicSettingSave() basicSettingSave()
setModuleSelectionData({ ...moduleSelectionData, roofConstructions: newRoofList }) setModuleSelectionData({ ...moduleSelectionData, roofConstructions: newRoofList })
} }