line-segment-drawer.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { Drawer } from "../../../core/drawers/drawer";
  2. import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
  3. import { label as Label } from "../../../component-registry/label";
  4. import { app as App } from "../../../app";
  5. import { DrawerAggragator } from "../../../core/drawers/drawer-aggregator";
  6. import { selector as Selector } from "../../../core/application/selector";
  7. export class LineSegmentDrawer extends Drawer {
  8. static FIRST_POINT() {
  9. return "FIRST_POINT";
  10. }
  11. static SECOND_POINT() {
  12. return "SECOND_POINT";
  13. }
  14. constructor() {
  15. super();
  16. this.pointA;
  17. this.pointB;
  18. this.states = [
  19. LineSegmentDrawer.FIRST_POINT,
  20. LineSegmentDrawer.SECOND_POINT
  21. ];
  22. }
  23. setPointA(point) {
  24. this.pointA = point;
  25. }
  26. setPointB(point) {
  27. this.pointB = point;
  28. }
  29. draw() {
  30. // if (this._state == null) {
  31. // this._state = LineSegment.STATE_PRIMEIRO_PONTO;
  32. // this._points.clear();
  33. // App.setStatus("Selecione o primeiro ponto no canvas");
  34. // } else if (this._state === LineSegment.STATE_PRIMEIRO_PONTO) {
  35. // const pos = App.pos();
  36. // this._points.add({ x: pos.x, y: pos.y });
  37. // this._state = LineSegment.STATE_SEGUNDO_PONTO;
  38. // } else if (this._state === LineSegment.STATE_SEGUNDO_PONTO) {
  39. // const pos = App.pos();
  40. // this._points.add({ x: pos.x, y: pos.y });
  41. // this.drawPoint(this._points);
  42. // this._points.clear();
  43. // this._state = LineSegment.STATE_PRIMEIRO_PONTO;
  44. // }
  45. const points = Selector.getPoints();
  46. console.info("points", points);
  47. if (points == undefined || points.length < 1) return;
  48. console.info("pointA", points[0]);
  49. console.info("pointB", points[1]);
  50. }
  51. update() {}
  52. static getKonvaLine(pointA, pointB) {
  53. const points = [pointA.posX, pointA.posY, pointB.posX, pointB.posY];
  54. return new Konva.Line({
  55. points: points,
  56. stroke: "grey",
  57. strokeWidth: 2,
  58. lineJoin: "round",
  59. draggable: false,
  60. strokeScaleEnabled: false,
  61. class: ELEMENTS_CLASS.LINE_SEGMENT,
  62. connections: []
  63. });
  64. }
  65. static drawKonvaLine(pointA, pointB) {
  66. const line = LineSegmentDrawer.getKonvaLine(pointA, pointB);
  67. }
  68. }