import { Drawer } from "../../../core/drawers/drawer"; import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum"; import { label as Label } from "../../../component-registry/label"; import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator"; import { selector as Selector } from "../../../core/application/selector"; import { LineSegmentModel } from "../models/line-segment-model"; export class LineSegmentDrawer extends Drawer { static FIRST_POINT() { return "FIRST_POINT"; } static SECOND_POINT() { return "SECOND_POINT"; } constructor() { super(); this.pointA; this.pointB; this.label; this.states = [ LineSegmentDrawer.FIRST_POINT, LineSegmentDrawer.SECOND_POINT ]; this.lineSegment; } setPointA(point) { this.pointA = point; } setPointB(point) { this.pointB = point; } draw() { const points = Selector.getSelectedPoints(); const aggregators = Selector.getSelectedPointsAggregators(); if (points == undefined || points.length < 1) return; this.setPointA(points[0]); this.setPointB(points[1]); this.label = Label.draw(); this.lineSegment = new LineSegmentModel( this.pointA, this.pointB, this.label ); const konvaObject = LineSegmentDrawer.getKonvaLine( this.pointA, this.pointB ); super.setKonvaObject(konvaObject); const aggregator = new DrawerAggregator( this, this.lineSegment, this.konvaObject, ELEMENTS_CLASS.LINE_SEGMENT ); super.addAggregator(aggregator); aggregators[1].addAggregator(aggregator); aggregators[0].addAggregator(aggregator); Drawer.drawObject(this.konvaObject); this.konvaObject.zIndex(0); super.batchDraw(); } update(aggregator) { const pointA = aggregator.genericObject.pointA; const pointB = aggregator.genericObject.pointB; aggregator.konvaObject.points([ pointA.posX, pointA.posY, pointB.posX, pointB.posY ]); super.batchDraw(); } static getKonvaLine(pointA, pointB, useLabel) { const points = [pointA.posX, pointA.posY, pointB.posX, pointB.posY]; const line = new Konva.Line({ points: points, stroke: "grey", strokeWidth: 2, lineJoin: "round", draggable: false, strokeScaleEnabled: false, class: ELEMENTS_CLASS.LINE_SEGMENT, connections: [], index: 0 }); return line; } static drawKonvaLine(pointA, pointB) { const line = LineSegmentDrawer.getKonvaLine(pointA, pointB); } }