소스 검색

Update 'src/app/components/middle-point/models/middle-point-model.js'

To read GEO with intersection point
New search method "static findOD (vecIdObj, id)" to find object
Changed "static do (map, list)" to "static do (id, map, vecIdObj, list)" with several changes,
including 2 "list.find(.)" to "MiddlePointModel.findOD(.)"
leo 2 년 전
부모
커밋
b6c3c08553
1개의 변경된 파일43개의 추가작업 그리고 8개의 파일을 삭제
  1. 43 8
      src/app/components/middle-point/models/middle-point-model.js

+ 43 - 8
src/app/components/middle-point/models/middle-point-model.js

@@ -15,13 +15,14 @@ import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
 export class MiddlePointModel extends PointModel {
 
   constructor (pointA, pointB, label, id) {
+  try {
     super(id);
     this.pointA = pointA;
     this.pointB = pointB;
     const middlePoint = this.getMiddlePoint();
     this.selectable = true; // para KonvaOjbect: object.attrs.selectable
     console.log("middle-point-model.js!constructor(.): this.id=" + this.id + ", this.selectable=" + this.selectable); //D
-    this.middlePoint = middlePoint; // used by 'middle-point-drawer.js!drawByStates(konvaObject)
+    //r this.middlePoint = middlePoint; // used by 'middle-point-drawer.js!drawByStates(konvaObject)
     this.posX = middlePoint.posX;
     this.posY = middlePoint.posY;
     this.setLabel(label);
@@ -30,6 +31,10 @@ export class MiddlePointModel extends PointModel {
     //this.definitions.push(this.pointB);
     this.definitions = this.getDefinitions();
     this.color = 16711936; //-16711936 = verde; // "#f54260"
+    } catch (error) {
+      console.log("middle-point-model.js!constructor(.): this.id=" + this.id + ", error " + error);
+      console.log("middle-point-model.js!constructor(.): error A=" + GeometricObject.printMap_go(pointA) + ", B=" + GeometricObject.printMap_go(pointB));
+      }
     }
 
   // To be used in GEO file DEFINITION, see app/core/models/application/actions/action.js
@@ -51,14 +56,44 @@ export class MiddlePointModel extends PointModel {
     return { posX: x, posY: y };
     }
 
+  // Help: search object in more stable structure
+  static findOD (vecIdObj, id) {
+    var tam = vecIdObj.length, ii;
+    for (ii=0; ii<tam; ii++)
+      if (vecIdObj[ii].id === id) return ii;
+    return -1; // Error! Not found!
+    }
 
-  static do (map, list) {
-    const id = map.get("id");
-    const pointAId = map.get("param")[0];
-    const pointBId = map.get("param")[1];
-    const pointA = list.find(x => x.id === pointAId);
-    const pointB = list.find(x => x.id === pointBId);
-    const label = map.get("label")[0];
+  // In reading GEO file, need to transform a Map in GeometricObject
+  // @see app/core/parser/file-parser.js
+  // @see app/core/parser/parser-orchestrator.js
+  static do (map, vecIdObj, list) {
+    // 2023/07/18: "vecIdObj" is element of Array with { id : only_id, obj : parsed_object } (build in app/core/application/header-menu.js!onFileChanged()
+    //             each element is similar to: [id=1] [obj=[object Map]]
+    var id="-1", pointAId="-1", pointBId="-1", pointA="-1", pointB="-1", label="-1", index_pointA, index_pointB;
+    var aux2 = JSON.stringify(Object.values(map)), aux3 = JSON.stringify(Object.values(vecIdObj)); //D GeometricObject.printMap_go(map,"map") GeometricObject.printMap_go(list,"list")
+    var aux = "", aux4 = ""; //D Object.keys
+    console.log("middle-point-model.js!map(.): id=" + id + "\n* map=" + aux2 + "\n* vecIdObj=" + aux3); //D
+    try {
+      id = map.get("id"); aux4 += "1,";
+      pointAId = map.get("param")[0]; aux4 += "2,";
+      pointBId = map.get("param")[1]; aux4 += "3,";
+      // pointA = list.find(x => x.id === pointAId); // find in "list" the pointA
+      // pointB = list.find(x => x.id === pointBId); // find in "list" the pointB
+      index_pointA = MiddlePointModel.findOD(vecIdObj, pointAId); // get the index of vecIdObj[ii].id == pointAId
+      index_pointB = MiddlePointModel.findOD(vecIdObj, pointBId); // get the index of vecIdObj[ii].id == pointBId
+      aux4 += "4,";
+      pointA = list[index_pointA]; // pointA = vecIdObj[index_pointA].obj; aux4 += "5,";
+      pointB = list[index_pointB]; // pointB = vecIdObj[index_pointB].obj; aux4 += "6,";
+      label = map.get("label")[0]; aux4 += "7,";
+    } catch (error) {
+      if (!pointA.id) pointA.id = -1; // security (inscrease error proof)
+      if (!pointB.id) pointB.id = -1; // security (inscrease error proof)
+      aux = "\nError: id=" + id + " : " + aux4;
+      }
+    if (!pointA.id) aux += " - index=" + index_pointA + ", pointA.id=<>="+JSON.stringify(pointA); else aux += " - index=" + index_pointA + ", pointA.id=" + pointA.id;
+    if (!pointB.id) aux += " - index=" + index_pointB + ", pointB.id=<>="+JSON.stringify(pointB); else aux += " - index=" + index_pointB + ", pointB.id=" + pointB.id;
+    console.log("middle-point-model.js!map(.): id=" + id + ", pointA.id=" + pointAId + "=" + pointA.id + ", pointB.id=" + pointBId + "=" + pointB.id + ", label=" + label + aux); //D
     return new MiddlePointModel(pointA, pointB, label, id);
     }