Browse Source

draw by existent point

Victor Luiz Domingues 5 years ago
parent
commit
8dd9c26829

+ 21 - 23
src/app/components/circumference-component/drawers/circumference-drawer.js

@@ -4,6 +4,7 @@ import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
 import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 import { selector as Selector } from "../../../core/application/selector";
 import { SelectableDrawer } from "../../../core/drawers/selectable-drawer";
+import { objects as Objects } from "../../../core/application/objects";
 
 export class CircumferenceDrawer extends SelectableDrawer {
   constructor() {
@@ -19,9 +20,19 @@ export class CircumferenceDrawer extends SelectableDrawer {
   }
 
   draw(e) {
+    if (
+      e != undefined &&
+      e.target != undefined &&
+      e.target.attrs.class != undefined &&
+      (e.target.attrs.class == ELEMENTS_CLASS.POINT ||
+        e.target.attrs.class == ELEMENTS_CLASS.INTERSECTION_POINT)
+    ) {
+      this.drawByStates(e.target);
+      return;
+    }
     const points = Selector.getSelectedPoints();
     if (points == undefined || points.length == 0) {
-      this.drawByStates(e);
+      this.drawByStates();
     } else this.drawByPoints(points, undefined, e);
   }
   drawByPoints(points, aggregators, e) {
@@ -41,17 +52,23 @@ export class CircumferenceDrawer extends SelectableDrawer {
     this.reset();
     this.setStatus("");
   }
-  drawByStates(e) {
+  drawByStates(konvaObject) {
+    let aggregator = undefined;
+    if (konvaObject != undefined) {
+      aggregator = Objects.getByKonvaObject(konvaObject)[0];
+    }
     if (this.state == undefined) {
       this.state = this.states[0];
       this.setStatus("Selecione o centro da Circunferência");
     } else if (this.state == this.states[0]) {
-      this.centerAggregator = this.pointDrawer.drawPoint();
+      this.centerAggregator =
+        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
       this.center = this.centerAggregator.genericObject;
       this.state = this.states[1];
       this.setStatus("Selecione o raio da Circunferência");
     } else if (this.state == this.states[1]) {
-      this.radiusAggregator = this.pointDrawer.drawPoint();
+      this.radiusAggregator =
+        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
       this.radius = this.radiusAggregator.genericObject;
       this.createAndDraw(this.center, this.radius);
       this.reset();
@@ -78,25 +95,6 @@ export class CircumferenceDrawer extends SelectableDrawer {
     return aggregator;
   }
   drawcircumference(circumference) {
-    // const circle = new Konva.Circle({
-    //   x: circumference.center.posX,
-    //   y: circumference.center.posY,
-    //   radius: circumference.getRadius(),
-    //   fill: "transparent",
-    //   stroke: "grey",
-    //   strokeWidth: 2,
-    //   strokeScaleEnabled: false,
-    //   transformEnabled: false,
-    //   draggable: false,
-    //   selectable: false,
-    //   index: 0,
-    //   class: ELEMENTS_CLASS.CIRCUMFERENCE,
-    //   style: { stroke: "grey", fill: "grey" },
-    //   fillEnable: false,
-    //   strokeHitEnabled: true,
-    //   hitStrokeWidth: true,
-    //   strokeEnabled: true
-    // });
     const circle = new Konva.Arc({
       x: circumference.center.posX,
       y: circumference.center.posY,

+ 22 - 5
src/app/components/line-segment-component/drawers/line-segment-drawer.js

@@ -43,22 +43,39 @@ export class LineSegmentDrawer extends SelectableDrawer {
     this.setPointB(aggregator.genericObject);
   }
 
-  draw() {
+  draw(e) {
+    if (
+      e != undefined &&
+      e.target != undefined &&
+      e.target.attrs.class != undefined &&
+      (e.target.attrs.class == ELEMENTS_CLASS.POINT ||
+        e.target.attrs.class == ELEMENTS_CLASS.INTERSECTION_POINT)
+    ) {
+      this.drawByStates(e.target);
+      return;
+    }
     const points = Selector.getSelectedPoints();
     if (points == undefined || points.length == 0) {
-      this.drawByState();
+      this.drawByStates();
+      return;
     }
     this.drawByPoints(points);
   }
-  drawByState() {
+  drawByStates(konvaObject) {
+    let aggregator = undefined;
+    if (konvaObject != undefined) {
+      aggregator = Objects.getByKonvaObject(konvaObject)[0];
+    }
     if (this.state == undefined) {
       super.setState(LineSegmentDrawer.FIRST_POINT_STATE);
     } else if (this.state == LineSegmentDrawer.FIRST_POINT_STATE) {
-      const aggregator = this.pointDrawer.drawPoint();
+      aggregator =
+        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
       this.setAggregatorA(aggregator);
       super.setState(LineSegmentDrawer.SECOND_POINT_STATE);
     } else if (this.state == LineSegmentDrawer.SECOND_POINT_STATE) {
-      const aggregator = this.pointDrawer.drawPoint();
+      aggregator =
+        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
       this.setAggregatorB(aggregator);
       this.drawByPoints(
         [this.pointA, this.pointB],

+ 8 - 3
src/app/core/application/objects.js

@@ -1,7 +1,7 @@
 import { stageManager as StageManager } from "./stage-manager";
 
 class Objects {
-  constructor() { }
+  constructor() {}
   add(aggregator) {
     StageManager.getCurrentLayer().addAggregator(aggregator);
   }
@@ -9,10 +9,15 @@ class Objects {
     return StageManager.getCurrentLayer().getAggregators();
   }
   getByGenericObject(genericObject) {
-    return this.get().filter(e => e.genericObject == genericObject);
+    return this.get().filter(e => e.genericObject.id == genericObject.id);
   }
   getByKonvaObject(konvaObject) {
-    return this.get().filter(e => e.konvaObject == konvaObject);
+    return this.get().filter(
+      e =>
+        e.konvaObject._id == konvaObject._id ||
+        e.konvaObject.children.filter(x => x._id == konvaObject._id)[0] !=
+          undefined
+    );
   }
   getSelectedObjects() {
     return StageManager.getCurrentLayer().getSelectedAggregators();