작업중

This commit is contained in:
hyojun.choi 2024-07-22 11:35:15 +09:00
parent 0449d512f2
commit d97ba2bec7
3 changed files with 66 additions and 30 deletions

View File

@ -131,7 +131,6 @@ export class QLine extends fabric.Group {
async = true async = true
toObject(propertiesToInclude) { toObject(propertiesToInclude) {
console.log('toObject')
return fabric.util.object.extend(this.callSuper('toObject'), { return fabric.util.object.extend(this.callSuper('toObject'), {
length: this.length, length: this.length,
line: this.line, line: this.line,

View File

@ -29,6 +29,9 @@ export default class QPolygon extends fabric.Group {
wall wall
initPoints
initOption
constructor(points, options, canvas) { constructor(points, options, canvas) {
/*if (points.length !== 4 && points.length !== 6) { /*if (points.length !== 4 && points.length !== 6) {
throw new Error('Points must be 4 or 6.') throw new Error('Points must be 4 or 6.')
@ -52,6 +55,10 @@ export default class QPolygon extends fabric.Group {
this.points = sortPoints this.points = sortPoints
this.polygon = polygon this.polygon = polygon
this.name = options.name this.name = options.name
this.initPoints = points
this.initOption = options
this.init() this.init()
this.addEvent() this.addEvent()
this.initLines() this.initLines()
@ -108,7 +115,7 @@ export default class QPolygon extends fabric.Group {
} }
}) })
this.addWithUpdate() this.canvas.add()
} }
addLengthText() { addLengthText() {
@ -137,7 +144,7 @@ export default class QPolygon extends fabric.Group {
}) })
this.texts.push(text) this.texts.push(text)
this.addWithUpdate(text) this.canvas.add(text)
}) })
this.canvas.renderAll() this.canvas.renderAll()
@ -192,7 +199,7 @@ export default class QPolygon extends fabric.Group {
const isInside = rectPoints.every((rectPoint) => this.inPolygon(rectPoint) && this.distanceFromEdge(rectPoint) >= cell.padding) const isInside = rectPoints.every((rectPoint) => this.inPolygon(rectPoint) && this.distanceFromEdge(rectPoint) >= cell.padding)
if (isInside) { if (isInside) {
this.addWithUpdate(rect) this.canvas.add(rect)
} }
} }
} }
@ -516,12 +523,12 @@ export default class QPolygon extends fabric.Group {
strokeWidth: 1, strokeWidth: 1,
}) })
this.addWithUpdate(realLine1) this.canvas.add(realLine1)
this.addWithUpdate(realLine2) this.canvas.add(realLine2)
this.addWithUpdate(realLine3) this.canvas.add(realLine3)
this.addWithUpdate(realLine4) this.canvas.add(realLine4)
this.addWithUpdate(realLine5) this.canvas.add(realLine5)
this.addWithUpdate(realLine6) this.canvas.add(realLine6)
if (smallestLength !== maxLength) { if (smallestLength !== maxLength) {
// 정사각형이 아닌경우에만 용마루를 추가한다. // 정사각형이 아닌경우에만 용마루를 추가한다.
this.canvas.add(ridge) this.canvas.add(ridge)
@ -586,7 +593,7 @@ export default class QPolygon extends fabric.Group {
direction: 'horizontal', direction: 'horizontal',
}) })
// this.addWithUpdate(centerLine) // this.canvas.add(centerLine)
centerLines.push(centerLine) centerLines.push(centerLine)
}) })
@ -611,7 +618,7 @@ export default class QPolygon extends fabric.Group {
strokeWidth: 1, strokeWidth: 1,
direction: 'vertical', direction: 'vertical',
}) })
// this.addWithUpdate(centerLine) // this.canvas.add(centerLine)
centerLines.push(centerLine) centerLines.push(centerLine)
}) })
@ -639,7 +646,7 @@ export default class QPolygon extends fabric.Group {
stroke: 'green', stroke: 'green',
idx: index, idx: index,
}) })
this.addWithUpdate(line) this.canvas.add(line)
helpLines.push(line) helpLines.push(line)
this.canvas.renderAll() this.canvas.renderAll()
}) })
@ -670,10 +677,10 @@ export default class QPolygon extends fabric.Group {
}) })
ridgeStartPoints.push(intersectionPoint) ridgeStartPoints.push(intersectionPoint)
this.addWithUpdate(helpLine1) this.canvas.add(helpLine1)
this.addWithUpdate(helpLine2) this.canvas.add(helpLine2)
this.removeWithUpdate(nextLine) this.canvas.remove(nextLine)
this.removeWithUpdate(line) this.canvas.remove(line)
this.canvas.renderAll() this.canvas.renderAll()
}) })
@ -724,9 +731,9 @@ export default class QPolygon extends fabric.Group {
}) })
ridgeEndPoints.push(arrivalPoint) ridgeEndPoints.push(arrivalPoint)
this.addWithUpdate(ridge) this.canvas.add(ridge)
this.addWithUpdate(helpLine) this.canvas.add(helpLine)
this.removeWithUpdate(line) this.canvas.remove(line)
this.canvas.renderAll() this.canvas.renderAll()
} }
}) })
@ -739,7 +746,7 @@ export default class QPolygon extends fabric.Group {
stroke: 'green', stroke: 'green',
}) })
this.addWithUpdate(ridgeConnectLine) this.canvas.add(ridgeConnectLine)
this.canvas.renderAll() this.canvas.renderAll()
}) })
} }
@ -771,7 +778,7 @@ export default class QPolygon extends fabric.Group {
idx: index, idx: index,
}) })
historyLines.push(line) historyLines.push(line)
this.addWithUpdate(line) this.canvas.add(line)
this.canvas.renderAll() this.canvas.renderAll()
}) })
@ -801,10 +808,10 @@ export default class QPolygon extends fabric.Group {
notInterSectionLines.pop() notInterSectionLines.pop()
helpPoints.push(intersectionPoint) helpPoints.push(intersectionPoint)
this.addWithUpdate(helpLine1) this.canvas.add(helpLine1)
this.addWithUpdate(helpLine2) this.canvas.add(helpLine2)
this.removeWithUpdate(prevLine) this.canvas.remove(prevLine)
this.removeWithUpdate(line) this.canvas.remove(line)
this.canvas.renderAll() this.canvas.renderAll()
}) })
// 용마루 // 용마루
@ -861,11 +868,11 @@ export default class QPolygon extends fabric.Group {
strokeWidth: 5, strokeWidth: 5,
}) })
this.addWithUpdate(ridge) this.canvas.add(ridge)
this.canvas.renderAll() this.canvas.renderAll()
this.addWithUpdate(ridgeHelpLine) this.canvas.add(ridgeHelpLine)
this.removeWithUpdate(closestLine) this.canvas.remove(closestLine)
this.canvas.renderAll() this.canvas.renderAll()
}) })
@ -878,7 +885,7 @@ export default class QPolygon extends fabric.Group {
stroke: 'green', stroke: 'green',
strokeWidth: 5, strokeWidth: 5,
}) })
this.addWithUpdate(ridgeConnectLine) this.canvas.add(ridgeConnectLine)
this.canvas.renderAll() this.canvas.renderAll()
} }
@ -890,4 +897,22 @@ export default class QPolygon extends fabric.Group {
getObject() { getObject() {
return this return this
} }
toObject(propertiesToInclude) {
return fabric.util.object.extend(this.callSuper('toObject'), {
points: this.points,
fontSize: this.fontSize,
name: this.name,
shape: this.shape,
texts: this.texts,
lines: this.lines,
wall: this.wall,
initPoints: this.initPoints,
initOption: this.initOption,
})
}
_set(key, value) {
this.callSuper('_set', key, value)
}
} }

View File

@ -118,6 +118,7 @@ export function useCanvas(id) {
QRect.prototype.canvas = canvas QRect.prototype.canvas = canvas
fabric.QLine = fabric.util.createClass(fabric.Group, {}) fabric.QLine = fabric.util.createClass(fabric.Group, {})
fabric.QPolygon = fabric.util.createClass(fabric.Group, {})
// fromObject 메서드를 QLine 클래스에 직접 추가 // fromObject 메서드를 QLine 클래스에 직접 추가
fabric.QLine.fromObject = function (object, callback) { fabric.QLine.fromObject = function (object, callback) {
@ -126,6 +127,14 @@ export function useCanvas(id) {
return callback(new QLine(initPoints, initOption, initLengthTxt)) return callback(new QLine(initPoints, initOption, initLengthTxt))
}) })
} }
// fromObject 메서드를 QLine 클래스에 직접 추가
fabric.QPolygon.fromObject = function (object, callback) {
const { initOption, initPoints, initLengthTxt } = object
fabric.util.enlivenObjects(object.objects, function (enlivenedObjects) {
return callback(new QPolygon(initPoints, initOption, initLengthTxt))
})
}
} }
/** /**
@ -570,6 +579,9 @@ export function useCanvas(id) {
function (o, object) { function (o, object) {
// 각 객체가 로드될 때마다 호출됩니다. // 각 객체가 로드될 때마다 호출됩니다.
console.log('Object loaded: ', o, object) console.log('Object loaded: ', o, object)
canvas?.add(object)
canvas?.renderAll()
}, },
) )