Browse Source

read points

Victor Luiz Domingues 4 years ago
parent
commit
efcc92bf52

+ 14 - 3
src/app/components/point-component/drawers/point-drawer.js

@@ -23,6 +23,10 @@ export class PointDrawer extends SelectableDrawer {
   }
 
   draw(e) {
+    if (e.attrs != undefined && e.attrs.genericObject != undefined) {
+      const aggregator = this.drawPoint(e.attrs.genericObject);
+      return aggregator;
+    }
     if (this.state == undefined) {
       super.setState(this.states[0]);
       App.setStatus("Selecione o centro do Ponto");
@@ -35,10 +39,14 @@ export class PointDrawer extends SelectableDrawer {
     }
   }
 
-  drawPoint() {
+  drawPoint(point) {
     const pos = App.pos();
-    if (pos == undefined) return;
-    const drawResult = PointDrawer.drawAndGetPoint(pos.x, pos.y, true);
+    let drawResult;
+    if (point == undefined) {
+      if (pos == undefined) return;
+      drawResult = PointDrawer.drawAndGetPoint(pos.x, pos.y, true);
+    } else drawResult = PointDrawer.drawPoint(point, true);
+
     this.point = drawResult.geometricObject;
     super.setKonvaObject(drawResult.konvaObject);
     const aggregator = new DrawerAggregator(
@@ -74,6 +82,7 @@ export class PointDrawer extends SelectableDrawer {
   static drawPoint(point, useLabel, draggable, selectable) {
     const group = SelectableDrawer.getKonvaGroup(draggable);
     const circle = PointDrawer.getKonvaCircle(point, draggable, selectable);
+
     if (useLabel != undefined && useLabel) {
       const label = Label.draw();
       point.setLabel(label);
@@ -82,10 +91,12 @@ export class PointDrawer extends SelectableDrawer {
     }
     if (selectable == undefined || selectable)
       SelectableDrawer.setSelectable(circle);
+
     if (useLabel) {
       group.add(circle);
       SelectableDrawer.drawObject(group);
       SelectableDrawer.setMaxIndex(group);
+      console.info("point", point);
       return { geometricObject: point, konvaObject: group };
     } else {
       SelectableDrawer.drawObject(circle);

+ 7 - 0
src/app/components/point-component/models/point-model.js

@@ -15,4 +15,11 @@ export class PointModel extends GeometricObject {
     this.posY = konvaObject.attrs.startPosY + event.target._lastPos.y;
     this.definitions = [{ id: this.posX + 5 }, { id: -this.posY - 5 }];
   }
+  static do(map, list) {
+    const id = map.get("id");
+    const x = map.get("param")[0] - 5;
+    const y = -map.get("param")[1] + 5;
+    const label = map.get("label")[0];
+    return new PointModel(x, y, label, id);
+  }
 }

+ 3 - 1
src/app/core/application/header-menu.js

@@ -1,5 +1,6 @@
 import { stageManager } from "./stage-manager";
 import { FileParser } from "../parser/file-parser";
+import { ParserOrchestrator } from "../parser/parser-orchestrator";
 class HeaderMenu {
   constructor() {}
   bootstrap() {
@@ -32,7 +33,8 @@ class HeaderMenu {
       const result = reader.result;
       const parser = new FileParser(result);
       const map = parser.parse();
-      console.info("map", map);
+      const orchestrator = new ParserOrchestrator(map);
+      orchestrator.orchestrate();
     };
     reader.readAsText(files[0]);
   }

+ 4 - 0
src/app/core/drawers/stage.js

@@ -47,7 +47,11 @@ export class Stage {
     else {
       var layer = this.layer.getKonvaLayer();
       this.layer.getKonvaGroup().add(object);
+      console.info(" this.layer", layer);
+      console.info(" this.konvaStage", this.konvaStage);
+      layer.draw();
       this.konvaStage.draw(layer);
+      this.konvaStage.draw();
     }
   }
   _setState(state) {

+ 2 - 0
src/app/core/enums/elements-class-enum.js

@@ -37,6 +37,8 @@ export function fromCodeToClass(code) {
       return ELEMENTS_CLASS.INTERSECTION_POINT;
     case 6:
       return ELEMENTS_CLASS.LINE_SEGMENT;
+    case 3:
+      return ELEMENTS_CLASS.CIRCUMFERENCE;
     default:
       return ELEMENTS_CLASS.POINT;
   }

+ 8 - 4
src/app/core/parser/file-parser.js

@@ -66,7 +66,8 @@ export class FileParser {
       } else if (key == DEFINITION) {
         const param_list = [];
         const list = prop_info[1].trim().split(" ");
-        for (const param in list) {
+        for (const i in list) {
+          const param = list[i];
           const maybe_number = Number(param);
           if (Number.isNaN(maybe_number)) {
             param_list.push(param);
@@ -78,14 +79,16 @@ export class FileParser {
       } else if (key == LIST) {
         const id_list = [];
         const list = prop_info[1].trim().split(" ");
-        for (const id in list) {
+        for (const i in list) {
+          const id = list[i];
           id_list.push(id);
         }
         map.set("deps", id_list);
       } else if (key == LABEL) {
         const param_list = [];
         const list = prop_info[1].trim().split(" ");
-        for (const param in list) {
+        for (const i in list) {
+          const param = list[i];
           const maybe_number = Number(param);
           if (Number.isNaN(maybe_number)) {
             param_list.push(param);
@@ -112,7 +115,8 @@ export class FileParser {
       } else if (key == PIXEL) {
         const position = [];
         const list = prop_info[1].trim().split(" ");
-        for (const i in list) {
+        for (const index in list) {
+          const i = list[index];
           position.push(parseInt(i));
         }
         map.set("position", position);

+ 49 - 0
src/app/core/parser/parser-orchestrator.js

@@ -0,0 +1,49 @@
+import { ELEMENTS_CLASS } from "../enums/elements-class-enum";
+import { PointModel } from "../../components/point-component/models/point-model";
+import { PointDrawer } from "../../components/point-component/drawers/point-drawer";
+
+export class ParserOrchestrator {
+  constructor(mapArr) {
+    this.mapArr = mapArr;
+    this.list = new Array();
+  }
+  orchestrate() {
+    for (const i in this.mapArr) this.do(this.mapArr[i]);
+    for (const i in this.list) this.draw(this.list[i]);
+  }
+  do(map) {
+    let object;
+    switch (map.get("type")) {
+      case ELEMENTS_CLASS.CIRCUMFERENCE:
+        break;
+      case ELEMENTS_CLASS.INTERSECTION_POINT:
+        break;
+      case ELEMENTS_CLASS.POINT:
+        object = PointModel.do(map, this.list);
+        break;
+      default:
+        break;
+    }
+    this.list.push(object);
+  }
+  draw(object) {
+    let drawer;
+    if (object == undefined) return;
+    switch (object.elementClass) {
+      case ELEMENTS_CLASS.CIRCUMFERENCE:
+        break;
+      case ELEMENTS_CLASS.INTERSECTION_POINT:
+        break;
+      case ELEMENTS_CLASS.POINT:
+        drawer = new PointDrawer();
+        break;
+      default:
+        break;
+    }
+    drawer.draw({
+      attrs: {
+        genericObject: object
+      }
+    });
+  }
+}

+ 6 - 2
src/index.html

@@ -27,8 +27,12 @@
           <div class="d-flex">
             <div class="p-1 flex-fill">
               <ul>
-                <li id="logo">
-                  <img src="assets/images/Logo.png" alt="iGeom.logo" />
+                <li id="logo" style="overflow: inherit !important; ">
+                  <img
+                    src="assets/images/Logo.png"
+                    style="margin-top:-16px;"
+                    alt="iGeom.logo"
+                  />
                 </li>
                 <li>
                   <button>