point-drawer.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 { PointModel } from "../models/point-model";
  6. import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
  7. import { stageManager as Stages } from "../../../core/application/stage-manager";
  8. const HOVER_STYLE = {
  9. fill: "#9bc364",
  10. strokeWidth: 2,
  11. stroke: "#FF0000"
  12. };
  13. const STYLE = {
  14. fill: "#9bc364",
  15. strokeWidth: 1,
  16. stroke: "#9bc364"
  17. };
  18. export class PointDrawer extends Drawer {
  19. constructor() {
  20. super();
  21. this.point;
  22. this.label;
  23. this.text;
  24. this.states = ["center"];
  25. }
  26. draw() {
  27. if (this.state == undefined) {
  28. super.setState(this.states[0]);
  29. App.setStatus("Selecione o centro do Ponto");
  30. }
  31. if (this.state == this.states[0]) {
  32. App.setStatus("Selecione o centro do Ponto");
  33. const pos = App.pos();
  34. if (pos == undefined) return;
  35. const drawResult = PointDrawer.drawAndGetPoint(pos.x, pos.y, true);
  36. this.point = drawResult.geometricObject;
  37. super.setKonvaObject(drawResult.konvaObject);
  38. super.addAggregator(
  39. new DrawerAggregator(this, this.point, this.konvaObject)
  40. );
  41. super.setState(this.states[0]);
  42. }
  43. }
  44. update() {}
  45. static drawAndGetPoint(x, y, useLabel) {
  46. return PointDrawer.drawPoint(new PointModel(x, y), useLabel);
  47. }
  48. static drawPoint(point, useLabel) {
  49. const group = Drawer.getKonvaGroup();
  50. const circle = PointDrawer.getKonvaCircle(point);
  51. group.add(circle);
  52. if (useLabel != undefined && useLabel) {
  53. const label = Label.draw();
  54. point.setLabel(label);
  55. const text = PointDrawer.getKonvaText(point, label);
  56. group.add(text);
  57. } else {
  58. if (point.label != undefined) {
  59. const text = PointDrawer.getKonvaText(point, point.label);
  60. group.add(text);
  61. }
  62. }
  63. PointDrawer.configureCircleEvents(circle);
  64. Drawer.drawObject(group);
  65. return { geometricObject: point, konvaObject: group };
  66. }
  67. static getKonvaCircle(point) {
  68. return new Konva.Circle({
  69. x: point.posX,
  70. y: point.posY,
  71. radius: 5,
  72. fill: STYLE.fill,
  73. stroke: STYLE.fill,
  74. strokeWidth: 1,
  75. strokeScaleEnabled: false,
  76. draggable: false,
  77. resizeEnabled: false,
  78. transformEnabled: false,
  79. style: STYLE,
  80. class: ELEMENTS_CLASS.POINT,
  81. connections: [],
  82. listening: true
  83. });
  84. }
  85. static getKonvaText(point, label) {
  86. return new Konva.Text({
  87. x: point.posX + 10,
  88. y: point.posY - 10,
  89. text: label,
  90. fontSize: 12,
  91. fontFamily: "Calibri",
  92. fill: "#434a45",
  93. draggable: false,
  94. resizeEnabled: false,
  95. transformEnabled: false,
  96. selectable: false
  97. });
  98. }
  99. static configureCircleEvents(circle) {
  100. circle.on("mouseover", function() {
  101. this.strokeWidth(HOVER_STYLE.strokeWidth);
  102. this.stroke(HOVER_STYLE.stroke);
  103. Stages.getCurrentKonvaStage().draw();
  104. });
  105. circle.on("mouseout", function() {
  106. this.strokeWidth(STYLE.strokeWidth);
  107. this.stroke(STYLE.stroke);
  108. Stages.getCurrentKonvaStage().draw();
  109. });
  110. }
  111. }