Ver Fonte

Update 'src/app/core/parser/parser-orchestrator.js'

To read GEO with intersection point
New debug help method "static printMap_po (map)"
Several indentation changes
Inserted new comments and "try/catch" to help in debug process
Several changes in "orchestrate (vec_dynamic_obj)" method, new parameter "vec_dynamic_obj":
- in "for (const i in this.mapArr)" new test "if (!this.mapArr[i] || this.mapArr[i]=="") continue;" to avoid error
- from "this.do(this.mapArr[i])" to "result = this.do(id, this.mapArr[i], vec_dynamic_obj)"
Several changes in "do (id, map, vecOD)" method, new parameters "id," and ", vecOD":
- from "object = CircumferenceModel.do(map, this.list)" to: object = CircumferenceModel.do(map, vecOD, this.list)
- from "object = IntersectionModel.do(map, this.list)" to: object = IntersectionModel.do(id, map, vecOD, this.list);
- from "object = PointModel.do(map, this.list)" to: object = PointModel.do(map, vecOD);
- from "object = MiddlePointModel.do(map, this.list)" to: object = MiddlePointModel.do(map, vecOD, this.list);
- from "object = LineSegmentModel.do(map, this.list)" to: object = LineSegmentModel.do(map, vecOD, this.list);
- from "object = LineModel.do(map, this.list)" to: object = LineModel.do(map, vecOD, this.list);
In " draw (object)", added to work even under GEO file error: if (object == undefined) return;
New help method "getStringFromObjects (item)"
In "getDrawer (elementClass)" changed "return this.tools.find(x => x.drawer.elementClass === elementClass).drawer;" to
   var answer = this.tools.find(x => x.drawer.elementClass === elementClass).drawer;...
leo há 2 anos atrás
pai
commit
b1cd7994ca
1 ficheiros alterados com 128 adições e 57 exclusões
  1. 128 57
      src/app/core/parser/parser-orchestrator.js

+ 128 - 57
src/app/core/parser/parser-orchestrator.js

@@ -18,68 +18,104 @@ import { IntersectionModel } from "../../components/intersection-component/model
 import { menu } from "../application/menu";
 import { label as Label } from '../../component-registry/label';
 import { LineModel } from "../../components/line-component/models/line-model";
+
 export class ParserOrchestrator {
 
+  //DEBUG: get String from map to check associated geometric object
+  static printMap_po (map) {
+    var str = "";
+    for (let [key, value] of map) { str += "[" + key + "=" + value + "] "; }
+    return str;
+    }
+
   constructor (mapArr) {
     this.mapArr = mapArr;
     this.list = new Array();
     this.drawersMap = new Map();
-    this.tools = menu.tools;
+    this.tools = menu.tools; // ./app/core/application/menu.js
     }
 
-  orchestrate () {
-    var aux = ""; //D
-    var ii=0; //D
+
+  // Process each GEO line to build iGeomJS objects
+  // @param vec_obj_dynamic_obj is Array() with { id : only_id, obj : parsed_object }
+  // @calledby app/core/application/header-menu.js!onFileChanged(): orchestrator.orchestrate();
+  orchestrate (vec_dynamic_obj) {
+    var auxEr = "", auxEr2 = ""; //D
+    var ii=0, result; //D
     try {
-      for (const i in this.mapArr) {
-        this.do(this.mapArr[i]);
-        //D aux += "(" + ii + "," + this.mapArr[i] + "); "; ii++; 
+      console.log("parser-orchestrator.js: orchestrate(): #this.mapArr[]=" + this.mapArr.length);
+      for (const i in this.mapArr) { // [id=1] [type=0] [param=357,-285.48333740234375] [deps=3] [label=A,4,-10,0] [defined=1] [color=[object Object]] [hidden=0] [position=NaN] [font=] [label_color=[object Object]]
+        if (!this.mapArr[i] || this.mapArr[i]=="")
+          continue; // avoid empty entry in "this.mapArr[]" and in "vec_dynamic_obj[]"
+        auxEr += "(" + ii + "," + ParserOrchestrator.printMap_po(this.mapArr[i]) + "); "; ii++; // JSON.stringify(Object.keys(this.mapArr[i]))
+        const id = this.mapArr[i].get("id");
+        console.log("parser-orchestrator.js: orchestrate(): this.mapArr: ii=" + ii + ": this.mapArr[i].id=" + id + ", " + ParserOrchestrator.printMap_po(this.mapArr[i]));
+
+        // This defines elements to be used by "static do (map, list)" of GeometricObject to create the objects
+        result = this.do(id, this.mapArr[i], vec_dynamic_obj); // create the GeometricObject
+
+        if (result==-1) console.log("parser-orchestrator.js: orchestrate(): error 1: i=" + i + ", ii=" + ii + ", this.mapArr["+i+"]=" + ParserOrchestrator.printMap_po(this.mapArr[i]));
+        // this.mapArr[i].entries(). JSON.stringify(Object.keys(this.mapArr[i]))
         }
-      for (const i in this.list) {
-        aux += "(" + ii + "," + this.list[i] + "); "; ii++;
-        this.draw(this.list[i]);
+      console.log("parser-orchestrator.js: orchestrate(): #this.mapArr[]=" + ii); //D + ": " + auxEr); //D
+      ii = 0;
+      for (const i in this.list) { // to each geom. obj. (e.g. Point): ["id","label","labelIgeom","dependentsOnThis","definitions","labelColor","defined","color","visible","draggable","posX","posY","elementClass"]
+        auxEr2 = "id=" + this.list[i].id + ", elementClass=" + this.list[i].elementClass + ", " + JSON.stringify(Object.keys(this.list[i])); // elementClass is int value to DEFINITION, e.g. Point is 0, since its DEFINITION is "2:0"
+        //D console.log("parser-orchestrator.js: orchestrate(): this.list: " + ii + ": " + auxEr2); //D
+        auxEr += "(" + ii + "," + JSON.stringify(Object.keys(this.list[i])) + "); "; ii++; //D
+        result = this.draw(this.list[i]);
+        if (result==-1) console.log("parser-orchestrator.js: orchestrate(): error: ii=" + ii + ", this.list["+i+"]=" + JSON.stringify(Object.keys(this.list[i])));
         }
     } catch (error) {
-      console.log("parser-orchestrator.js!orchestrate(): error " + error + "\n * " + aux);
+      console.log("parser-orchestrator.js!orchestrate(): error " + error + "\n * " + auxEr);
       }
-    console.log("parser-orchestrator.js: orchestrate(): end"); //D
-    }
+    console.log("parser-orchestrator.js: orchestrate(): " + auxEr + "* final"); //D
+    } // orchestrate()
+
 
-  do (map) {
-    var aux = "", int_type = "-1"; //D
+  // Build the Dynamic Objects
+  // @param map is a Map with object (e.g. 'ID=1: 4, TYPE=0: 0, DEFINITION=2: (567.0, -308.0), LIST=3: (5), LABEL=4: (D, 4.0, -10.0, 0), DEFINED=6: 1, COLOR=5:...
+  // @param vecOD is Array with { id : only_id, obj : parsed_object }
+  do (id, map, vecOD) {
+    var auxEr = "", int_type = "-1"; //D
     let object;
     try {
-      aux = "1, "; //D
+      auxEr = "1, "; //D
       int_type = map.get("type");
       switch (int_type) {
         case ELEMENTS_CLASS.CIRCUMFERENCE:
-          aux = "2, "; //D
-          object = CircumferenceModel.do(map, this.list);
+          auxEr = "2, "; //D
+          object = CircumferenceModel.do(map, vecOD, this.list); // CircumferenceModel.do(map, this.list);
           break;
         case ELEMENTS_CLASS.INTERSECTION_POINT:
-          aux = "3, "; //D
-          object = IntersectionModel.do(map, this.list);
+          auxEr = "3, "; //D
+          //D console.log("parser-orchestrator.js!do(.): id=" + id);
+          object = IntersectionModel.do(id, map, vecOD, this.list); // IntersectionModel.do(map, this.list);
           break;
         case ELEMENTS_CLASS.POINT:
-          aux = "4, "; //D
-          object = PointModel.do(map, this.list);
+          auxEr = "4, "; //D
+          object = PointModel.do(map, vecOD); // PointModel.do(map, this.list);
           break;
-        case ELEMENTS_CLASS.MIDDLE_POINT:
-          aux = "5, "; //D
-          object = MiddlePointModel.do(map, this.list);
+        case ELEMENTS_CLASS.MIDDLE_POINT: // 13
+          var auxDef = "";
+          for (var ii=0; ii<vecOD.length; ii++) { const go = vecOD[ii].obj; auxDef += go.id + ","; } // can use "this.list" instead of "vecOD"
+          auxEr = "5 [" + auxDef + "], "; //D
+          // object = MiddlePointModel.do(map, this.list);
+          object = MiddlePointModel.do(map, vecOD, this.list); // 2023/07
           break;
         case ELEMENTS_CLASS.LINE_SEGMENT:
-          aux = "6, "; //D
-          object = LineSegmentModel.do(map, this.list);
+          auxEr = "6, "; //D
+          object = LineSegmentModel.do(map, vecOD, this.list); // LineSegmentModel.do(map, this.list);
           break;
         case ELEMENTS_CLASS.LINE:
-          aux = "7, "; //D
-          object = LineModel.do(map, this.list);
+          auxEr = "7, "; //D
+          object = LineModel.do(map, vecOD, this.list); // LineModel.do(map, this.list);
           break;
         default:
-          aux = "switch type missing! ELEMENTS_CLASS elementClass NOT implemented yet! Look iGeomJS code or try to report this to iGeomJS developers..."; //D
+          auxEr = "switch type missing! ELEMENTS_CLASS elementClass NOT implemented yet! Look iGeomJS code or try to report this to iGeomJS developers..."; //D
           break;
         }
+      auxEr = "8, "; //D
       if (object == undefined) return;
       switch (object.elementClass) {
         case ELEMENTS_CLASS.CIRCUMFERENCE:
@@ -91,53 +127,88 @@ export class ParserOrchestrator {
           Label.pushUpper(object.label);
         }
       this.list.push(object);
-    } catch (error) { console.log("parser-orchestrator.js!do(map): error " + error + "\n * " + aux); }
+    } catch (error) {
+      auxEr += " : int_type=" + int_type;
+      console.log("parser-orchestrator.js!do(map): error " + error + "\n * " + auxEr);
+      console.log(" * map = " + JSON.stringify(Object.keys(map))); // JSON.stringify(map)); // ParserOrchestrator.printMap_po(map));
+      return -1;
+      // console.trace();
+      //  parser-orchestrator.js!orchestrate(): this.do(this.mapArr[i]);
+      //  onFileChanged/obj_file_reader.onload
+      }
+    return 1;
     } // do(map)
 
   draw (object) {
-    var aux = ""; //D
+    var auxEr = ""; //D
     try {
-      console.log("parser-orchestrator.js: draw(object): " + object); //D
-      aux = "1, "; //D
-      if (object == undefined) return;
-      aux += "2, "; //D
-      let drawer;
-      aux += "3, "; //D
+      //D console.log("parser-orchestrator.js: draw(object): " + object); auxEr = "1, "; //D
+      if (object == undefined) return;                            auxEr += "2, "; //D
+      let drawer;                                                 auxEr += "3, "; //D
       switch (object.elementClass) {
-        case ELEMENTS_CLASS.CIRCUMFERENCE:
-          aux += "4, "; //D
+        case ELEMENTS_CLASS.CIRCUMFERENCE:                        auxEr += "4, "; //D
           drawer = this.getDrawer(ELEMENTS_CLASS.CIRCUMFERENCE);
           break;
-        case ELEMENTS_CLASS.INTERSECTION_POINT:
-          aux += "5, "; //D
-          drawer = this.getDrawer(ELEMENTS_CLASS.INTERSECTION_POINT);
+        case ELEMENTS_CLASS.INTERSECTION_POINT:                   auxEr += "5, "; //D
+          drawer = this.getDrawer(ELEMENTS_CLASS.INTERSECTION_POINT); // elementClass = 1
+	  //D //console.log("parser-orchestrator.js!draw(object): elementClass=" + ELEMENTS_CLASS.INTERSECTION_POINT + ", drawer = " + JSON.stringify(Object.keys(drawer)));
           break;
-        case ELEMENTS_CLASS.POINT:
-          aux += "6, "; //D
+        case ELEMENTS_CLASS.POINT:                                auxEr += "6, "; //D
           drawer = this.getDrawer(ELEMENTS_CLASS.POINT);
           break;
-        case ELEMENTS_CLASS.LINE_SEGMENT:
-          aux += "7, "; //D
+        case ELEMENTS_CLASS.LINE_SEGMENT:                         auxEr += "7, "; //D
           drawer = this.getDrawer(ELEMENTS_CLASS.LINE_SEGMENT);
           break;
-        case ELEMENTS_CLASS.LINE:
-          aux += "8, "; //D
-          drawer = this.getDrawer(ELEMENTS_CLASS.LINE);
+        case ELEMENTS_CLASS.LINE:                                 auxEr += "8, "; //D
+          drawer = this.getDrawer(ELEMENTS_CLASS.LINE); // elementClass = 4
+	  //D console.log("parser-orchestrator.js!draw(object): elementClass=" + ELEMENTS_CLASS.LINE + ", drawer = " + JSON.stringify(Object.keys(drawer)));
           break;
-        case ELEMENTS_CLASS.MIDDLE_POINT:
-          aux += "9, "; //D
+        case ELEMENTS_CLASS.MIDDLE_POINT:                         auxEr += "9, "; //D
           drawer = this.getDrawer(ELEMENTS_CLASS.MIDDLE_POINT);
           break;
         default:
-          aux += "10 = object.elementClass NOT implemented yet! Look iGeomJS code or try to report this to iGeomJS developers..."; //D
+          auxEr += "* object.elementClass NOT implemented yet! Look iGeomJS code or try to report this to iGeomJS developers..."; //D
           break;
         }
-      drawer.draw ({ attrs: { genericObject: object } });
-    } catch (error) { console.log("parser-orchestrator.js!draw(object): error " + error + "\n * " + aux); }
+      drawer.draw({ attrs: { genericObject: object } }); // ./app/core/drawers/drawer.js  // ", genericObject=" + JSON.stringify(genericObject)
+    } catch (error) { console.log("parser-orchestrator.js!draw(object): error " + error + "\n * " + auxEr); }
+    } // draw(object)
+
+  //DEBUG: Versao iterativa
+  getStringFromObjects (item) {
+    const listak = Object.keys(item);
+    const listav = Object.values(item);
+    const tam = listak.length;
+    var aux = "", key, value;
+    var ii = -1;
+    try {
+      for (ii=0; ii<tam; ii++) { // >
+        key = listak[ii]; value = listav[ii];
+        aux += "<" + key +":" + JSON.stringify(value.constructor.name) + ">, ";
+        }
+    } catch (error) { aux = "ii=" + ii + ", " + error; }
+    return aux;
     }
 
   getDrawer (elementClass) {
-    return this.tools.find(x => x.drawer.elementClass === elementClass).drawer;
-    }
+    // this.tools = menu.tools; // ./app/core/application/menu.js
+    // For each this.tools[ii] : Object.keys = ["options","drawer","created"] ; Object.values
+    // options=[object Object], drawer=[object Object]; drawer = [ drawerManager , drawing , ... elementClass , ; 
+    //D var aux = "", tam = this.tools.length; for (var ii=0; ii<tam; ii++) aux += JSON.stringify(Object.keys(this.tools[ii])) + ", ";
+    var aux = "", tam = this.tools.length;
+    // return this.tools.find(x => x.drawer.elementClass === elementClass).drawer;
+    var answer = this.tools.find(x => x.drawer.elementClass === elementClass).drawer;
+    const tam3 = this.tools.length;
+    aux +=  ", tam3=" + tam3 +", find=[" + JSON.stringify(Object.keys(answer)) + "]\n";
+    var ii, item;
+    for (ii=0; ii<tam3; ii++) {
+      item = this.tools[ii];
+      // aux += ", " + ii + ": " + JSON.stringify(Object.keys(item)) + "=" + this.getStringFromObjects(Object.keys(item), Object.values(item)); // => TypeError: cyclic object value; JSON.stringify(item) =>  TypeError: cyclic object value
+      aux += ii + ":[" + this.getStringFromObjects(item) + "], ";
+      // aux += ", " + ii + ": " + item.drawer.elementClass;
+      }
+    //D console.log("parser-orchestrator.js!getDrawer(elementClass): elementClass=" + elementClass + ": " + aux);
+    return answer;
+    } // getDrawer(elementClass)
 
   }