Browse Source

Update 'src/app/components/circumference-component/drawers/circumference-drawer.js'

Previous debug message was provoking error in crationg of second Circumference c1: c0:=Circumference(A,B); c1:=Circumference(B,A);
Some indentation improvements
Some try/catch added to allow iGeomJS work even in presence of error (and to help debug process)
leo 2 years ago
parent
commit
9e6f74c6a3
1 changed files with 133 additions and 60 deletions
  1. 133 60
      src/app/components/circumference-component/drawers/circumference-drawer.js

+ 133 - 60
src/app/components/circumference-component/drawers/circumference-drawer.js

@@ -1,3 +1,16 @@
+/*
+ * iGeom by LInE
+ * Geometric Object: Circumference
+ * Drawer to Segment
+ * www.matematica.br/igeom
+ *
+ * ./app/components/circumference-component/drawers/circumference-drawer.js
+ *
+ * @version 2023/08/20: fixed debug message that was avoiding to create Circumference(B,A) whanever exists Circumference(A,B)
+ * @version 2023/07/30: indentation and 'getRadius()' changed to better name 'getRadiusValue()'
+ *
+ */
+
 import { CircumferenceModel } from "../models/circumference-model";
 import { PointDrawer } from "../../point-component/drawers/point-drawer";
 import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
@@ -8,7 +21,8 @@ import { objects as Objects } from "../../../core/application/objects";
 import { label as Label } from "../../../component-registry/label";
 
 export class CircumferenceDrawer extends SelectableDrawer {
-  constructor() {
+
+  constructor () {
     super();
     this.states = ["center", "radius"];
     this.state = undefined;
@@ -19,32 +33,48 @@ export class CircumferenceDrawer extends SelectableDrawer {
     this.centerAggregator;
     this.konvaObject;
     this.setElementClass(ELEMENTS_CLASS.CIRCUMFERENCE);
-  }
-
-  draw(e) {
-    if (e != undefined) {
-
-      if (
-        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;
-      } else if (e.attrs != undefined && e.attrs.genericObject != undefined) {
+    }
 
-        this.resolveAggregators([e.attrs.genericObject.center, e.attrs.genericObject.radius], undefined, false);
-        this.createByCircumference(e.attrs.genericObject);
-        return;
+  // @calledby app/core/models/components/component.js: draw(e): this.drawer.draw(e);
+  draw (e) {
+    var auxE = ""; //D
+    console.log("circumference-drawer.js!draw(e)"); //D
+    try { // allow working in presence of error, besides to help debug process
+      if (e != undefined) {
+        if (e.target != undefined && e.target.attrs.class != undefined &&
+            (e.target.attrs.class == ELEMENTS_CLASS.POINT || e.target.attrs.class == ELEMENTS_CLASS.INTERSECTION_POINT) ) {
+          console.log("circumference-drawer.js!draw(e): (1) e.target.attrs.class=" + (e.target.attrs.class != undefined ? e.target.attrs.class : "<>")); //D
+          this.drawByStates(e.target);
+          return;
+          }
+        else
+        if (e.attrs != undefined && e.attrs.genericObject != undefined) {
+          console.log("circumference-drawer.js!draw(e): (2) e.target.attrs.genericObject=" + (e.target.attrs.genericObject != undefined ? e.target.attrs.genericObject : "<>")); //D
+          this.resolveAggregators([e.attrs.genericObject.center, e.attrs.genericObject.radius], undefined, false);
+          this.createByCircumference(e.attrs.genericObject);
+          return;
+          }
+        }
+      auxE += "1, "; //D
+      const points = Selector.getSelectedPoints();
+      auxE += "2 (#points=" + (points!=undefined && points.length!=undefined ? points.length : "0") + "), "; //D
+      console.log("circumference-drawer.js!draw(e): (3) antes de this.drawByStates()");
+      if (points == undefined || points.length == 0) {
+        auxE += "3, "; //D
+        this.drawByStates();
+        auxE += "4, "; //D
+        } 
+      else {
+        auxE += "5, "; //D
+        this.drawByPoints(points, undefined, e);
+        auxE += "6, "; //D
+        }
+    } catch (error) {
+      console.log("circumference-drawer.js!draw(e): Error '" + error + "', with " + auxE);
       }
     }
-    const points = Selector.getSelectedPoints();
-    if (points == undefined || points.length == 0) {
-      this.drawByStates();
-    } else this.drawByPoints(points, undefined, e);
-  }
-  drawByPoints(points, aggregators, e) {
+
+  drawByPoints (points, aggregators, e) {
     aggregators = this.resolveAggregators(points, aggregators, true);
     this.centerAggregator = aggregators[0];
     this.radiusAggregator = aggregators[1];
@@ -53,55 +83,99 @@ export class CircumferenceDrawer extends SelectableDrawer {
     this.createAndDraw(this.center, this.radius);
     this.reset();
     this.setStatus("");
-  }
-  drawByStates(konvaObject) {
+    }
+
+  drawByStates (konvaObject) {
+    var auxE = ""; //D
     let aggregator = undefined;
+    auxE += "1, "; //D
+    try {
     if (konvaObject != undefined) {
+      auxE += "2, "; //D
       aggregator = Objects.getByKonvaObject(konvaObject)[0];
-    }
+      auxE += "3, "; //D
+      }
     if (this.state == undefined) {
+      auxE += "4, "; //D
       this.state = this.states[0];
-      this.setStatus("Selecione o centro da Circunferência");
-    } else if (this.state == this.states[0]) {
-      this.centerAggregator =
-        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
+      this.setStatus("Select the first point A, will be the center of the circumference");
+      auxE += "5, "; //D
+      }
+    else
+    if (this.state == this.states[0]) { // first point A from Circunference(A,B)
+      auxE += "6, "; //D
+      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 =
-        aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
+      this.setStatus("Select the second point B such that ||A-B|| define the circumference radius");
+      auxE += "7, "; //D
+      }
+    else
+    if (this.state == this.states[1]) { // second point B from Circunference(A,B)
+      auxE += "8, "; //D
+      this.radiusAggregator = aggregator != undefined ? aggregator : this.pointDrawer.drawPoint();
+      auxE += "9, "; //D
       this.radius = this.radiusAggregator.genericObject;
+      auxE += "10, "; //D
       this.createAndDraw(this.center, this.radius);
+      auxE += "11, "; //D
       this.reset();
       this.state = this.states[0];
+      auxE += "12, "; //D
+      }
+    auxE += "13, "; //D
+    } catch (error) {
+      console.log("circumference-drawer.js!drawByStates(konvaObject): Error '" + error + "', with " + auxE);
+      }
     }
-  }
-  createAndDraw(center, radius) {
+
+  createAndDraw (center, radius) {
+    var auxE = "";
+    try {
     this.center = center;
     this.radius = radius;
+    auxE += "1, "; //D
     this.circumference = new CircumferenceModel(this.center, this.radius);
+    auxE += "2, "; //D
     const label = Label.draw(true);
+    auxE += "3, "; //D
     this.circumference.setLabel(label);
+    auxE += "4 (this.circumference.id=" + (this.circumference!=undefined ? this.circumference.id : "<>") + "), "; //D
     this.createByCircumference(this.circumference);
-  }
-  createByCircumference(circumference) {
+    auxE += "5, "; //D
+    } catch (error) {
+      console.log("circumference-drawer.js!createAndDraw(center, radius): Error '" + error + "', with " + auxE);
+      }
+    }
+
+  createByCircumference (circumference) {
+    var auxE = "";
+    var aggregator = "";
+    try {
     this.circumference = circumference;
+    auxE += "1, "; //D
     this.konvaObject = this.drawCircumference(this.circumference);
-    const aggregator = new DrawerAggregator(
-      this,
-      this.circumference,
-      this.konvaObject,
-      ELEMENTS_CLASS.CIRCUMFERENCE
-    );
-    super.addAggregator(aggregator);
+    auxE += "2, "; //D
+    aggregator = new DrawerAggregator(this, this.circumference, this.konvaObject, ELEMENTS_CLASS.CIRCUMFERENCE);
+    auxE += "3, "; //D
+    super.addAggregator(aggregator); // SelectableDrawer extends Drawer: app/core/drawers/drawer.js: addAggregator(aggregator)
+    auxE += "4, "; //D
     this.centerAggregator.addAggregator(aggregator);
+    auxE += "5, "; //D
     this.radiusAggregator.addAggregator(aggregator);
+    auxE += "6, "; //D
     SelectableDrawer.drawObject(this.konvaObject);
+    auxE += "7, "; //D
     this.konvaObject.zIndex(0);
+    auxE += "8, "; //D
     super.batchDraw();
+    auxE += "9, "; //D
+    } catch (error) {
+      console.log("circumference-drawer.js!createByCircumference(circumference): Error '" + error + "', with " + auxE);
+      }
     return aggregator;
-  }
+    }
+
   drawCircumference (circumference) {
     const circle = new Konva.Arc({
       x: circumference.center.posX,
@@ -119,29 +193,27 @@ export class CircumferenceDrawer extends SelectableDrawer {
       index: 0,
       class: ELEMENTS_CLASS.CIRCUMFERENCE,
       style: { stroke: "grey", fill: "grey" }
-    });
+      });
     SelectableDrawer.setSelectableIfIntersectionChanged(circle);
     return circle;
-  }
-  resolveAggregators(points, aggregators, selected) {
+    }
+
+  resolveAggregators (points, aggregators, selected) {
     if (this.center == undefined) {
       this.center = points[0];
-    }
+      }
     if (this.radius == undefined) {
       this.radius = points[1];
-    }
+      }
     if (aggregators == undefined && selected == true)
       aggregators = Selector.getSelectedPointsAggregators();
     else {
-      aggregators = [
-        Objects.getByGenericObject(points[0])[0],
-        Objects.getByGenericObject(points[1])[0]
-      ];
-    }
+      aggregators = [ Objects.getByGenericObject(points[0])[0], Objects.getByGenericObject(points[1])[0] ];
+      }
     this.centerAggregator = aggregators[0];
     this.radiusAggregator = aggregators[1];
     return aggregators;
-  }
+    }
 
   update (aggregator, e) {
     if (!aggregator.visible) return;
@@ -151,5 +223,6 @@ export class CircumferenceDrawer extends SelectableDrawer {
     aggregator.konvaObject.x(center.posX);
     aggregator.konvaObject.y(center.posY);
     super.batchDraw();
-  }
-}
+    }
+
+  }