import { app as App } from "../app"; import { menu as Menu } from "../core/application/menu"; export const circumference = (function() { let _tool = {}; let _states = ["center", "radius"]; let _state = undefined; let _coordinates = [0, 0, 0, 0]; let _points = [0, 0, 0]; function _draw() { if (_state == undefined) { _state = _states[0]; App.setStatus("Selecione o centro da CircunferĂȘncia"); } else if (_state == _states[0]) { let pos = App.pos(); _coordinates[0] = pos.x; _coordinates[1] = pos.y; _state = _states[1]; App.setStatus("Selecione o raio da CircunferĂȘncia"); } else if (_state == _states[1]) { let pos = App.pos(); _coordinates[2] = pos.x; _coordinates[3] = pos.y; let legA = _coordinates[2] - _coordinates[0]; let legB = _coordinates[3] - _coordinates[1]; let radius = Math.sqrt(Math.pow(legA, 2) + Math.pow(legB, 2)); _points = [_coordinates[0], _coordinates[1], radius]; let p = _points.slice(); _drawcircumference(p[0], p[1], p[2]); } } function _drawcircumference(x, y, radius) { let layer = App.currentLayer(); let group = new Konva.Group({ draggable: true, resizeEnabled: false }); let circle = new Konva.Circle({ x: x, y: y, radius: radius, fill: "transparent", stroke: "black", strokeWidth: 1, strokeScaleEnabled: false, transformEnabled: true, draggable: false }); let point = new Konva.Circle({ x: x, y: y, radius: 5, fill: "#9bc364", stroke: "#9bc364", strokeWidth: 1, strokeScaleEnabled: false, draggable: false, resizeEnabled: false, transformEnabled: false }); group.add(circle); group.add(point); layer.add(group); App.stage.draw(); _clearState(); App.clearSelectedTool(); App.setStatus(""); } function _bootstrap() { Menu.add(_tool); } function _click(id) { if (_state == _states[0]) { App.clearSelectedTool(); _clearState(); return; } App.setSelectedTool(_tool); _state = _states[0]; App.setStatus("Selecione o primeiro ponto no canvas"); } function _clearState() { _state = undefined; } _tool = { id: "circumference", title: "CircunferĂȘncia", icon: "line", click: _click, draw: _draw, points: _points, coordinates: _coordinates, drawcircumference: _drawcircumference }; _bootstrap(); return { draw: _draw, click: _click }; })();