Parcourir la source

Update 'src/app/core/models/application/actions/action.js'

To read GEO with intersection point
Several indentation changes
Inserted new comments and "try/catch" to help in debug process
leo il y a 2 ans
Parent
commit
1c853101d4
1 fichiers modifiés avec 69 ajouts et 43 suppressions
  1. 69 43
      src/app/core/models/application/actions/action.js

+ 69 - 43
src/app/core/models/application/actions/action.js

@@ -1,16 +1,27 @@
+/*
+ * iGeom by LInE
+ * Free software to student private data
+ *
+ * http://www.matematica.br/igeom
+ * http://www.usp.br/line
+ *
+ * Prepare string describing (in GEO format) each objects in iGeomJS
+ * 
+ * ./app/core/models/application/actions/action.js
+ * @version 2023/07/14: Fixed reading GEO file with midpoint
+ */
+
 import { GenericObject } from "../../objects/generic-object";
 import { GEO_FILE } from "../../../enums/geo-file-enum";
 
 export class Action {
-  constructor(genericObject) {
+
+  constructor (genericObject) {
+    console.log("action.js!constructor(): "); //D
     this.id = genericObject.id;
     this.type = genericObject.elementClass;
-    this.definition = this.r(
-      genericObject.definitions.map(x => x.id).toString()
-    );
-    this.list = this.r(
-      genericObject.dependentsOnThis.map(x => x.id).toString()
-    );
+    this.definition = this.r(genericObject.definitions.map(x => x.id).toString());
+    this.list = this.r(genericObject.dependentsOnThis.map(x => x.id).toString());
     this.label = genericObject.labelIgeom;
     this.defined = genericObject.defined;
     this.color = genericObject.color;
@@ -19,8 +30,10 @@ export class Action {
     this.font = "";
     this.labelColor = genericObject.labelColor;
     this.genericObject = genericObject;
-  }
-  do() {
+    }
+
+  do () {
+    //D console.log("action.js!do(): ");
     const genericObject = new GenericObject(this.id);
     genericObject.color = this.color;
     genericObject.elementClass = this.type;
@@ -28,47 +41,58 @@ export class Action {
     genericObject.list = this.list;
     genericObject.label = this.label;
     genericObject.visible = this.hidden == 0;
-  }
-  toMap() {
+    }
+
+  toMap () {
     const map = new Map();
     map.set("key", "value");
     return map;
-  }
+    }
 
-  fromMapList(map) { }
+  fromMapList (map) { }
 
-  toString() {
-    return (
-      "{" +
-      `${this.d(GEO_FILE.ID, this.id)}, ` +
-      `${this.d(GEO_FILE.TYPE, this.type)}, ` +
-      `${this.d(GEO_FILE.DEFINITION, this.definition)}, ` +
-      `${this.d(GEO_FILE.LIST, this.list)}, ` +
-      `${this.d(GEO_FILE.LABEL, this.label)}, ` +
-      `${this.d(GEO_FILE.DEFINED, this.defined)}, ` +
-      `${this.d(GEO_FILE.COLOR, this.color)}, ` +
-      `${this.d(GEO_FILE.HIDDEN, this.hidden)}, ` +
-      `${this.d(GEO_FILE.PIXEL, this.pixel)}, ` +
-      `${this.d(GEO_FILE.FONT, this.font)}, ` +
-      `${this.d(GEO_FILE.LABEL_COLOR, this.labelColor)}` +
-      `}!\n`
-    );
-  }
-  d(key, value) {
+  toString () {
+    //  Items of GEO line: Id, Type, Definition, List, Label, Defined, Color, Hidden, Pixel, Font, LabelColor;
+    //  Correspon. values: 1   0     2           3     4      5        6      7       8      9     10
+    var strC = "", tam;
+    try {
+    if (this.id)         strC += `${this.d(GEO_FILE.ID, this.id)}, `;
+    strC += `${this.d(GEO_FILE.TYPE, this.type)}, `;                                  // TYPE is 0 and JavaScript interpret it as false (do not use "if")
+    if (this.definition) strC += `${this.d(GEO_FILE.DEFINITION, this.definition)}, `;
+    if (this.list)       strC += `${this.d(GEO_FILE.LIST, this.list)}, `;
+    if (this.label)      strC += `${this.d(GEO_FILE.LABEL, this.label)}, `;
+    if (this.defined)    strC += `${this.d(GEO_FILE.DEFINED, this.defined)}, `;
+    if (this.color)      strC += `${this.d(GEO_FILE.COLOR, this.color)}, `;
+    if (this.hidden)     strC += `${this.d(GEO_FILE.HIDDEN, this.hidden)}, `;
+    else                 strC += `${this.d(GEO_FILE.HIDDEN, 0)}, `;                   // Must set "7:0" otherwise the object will be hidden
+    if (this.pixel)      strC += `${this.d(GEO_FILE.PIXEL, this.pixel)}, `;
+    if (this.font)       strC += `${this.d(GEO_FILE.FONT, this.font)}, `;
+    if (this.labelColor) strC += `${this.d(GEO_FILE.LABEL_COLOR, this.labelColor)}`;
+    strC = strC.trim();
+    tam = strC.length;
+    if (strC[tam-1] == ",") 
+      strC = strC.substring(0, tam-1).trim();
+    } catch (error) { console.log("action.js!toString(): error " + error); }
+    strC = "{" + strC + "}!\n";
+    console.log("action.js!toString(): \n" + strC);
+    //D console.trace();
+    return strC;
+    } // toString()
+
+  d (key, value) {
     return `${key}:${value}`;
-  }
-  r(str) {
+    }
+
+  r (str) {
     return str.replace(/,/g, " ");
-  }
-  rehydrate() {
+    }
+
+  rehydrate () {
+    console.log("action.js!rehydrate(): inicial"); //D
     this.id = this.genericObject.id;
     this.type = this.genericObject.elementClass;
-    this.definition = this.r(
-      this.genericObject.definitions.map(x => x.id).toString()
-    );
-    this.list = this.r(
-      this.genericObject.dependentsOnThis.map(x => x.id).toString()
-    );
+    this.definition = this.r(this.genericObject.definitions.map(x => x.id).toString());
+    this.list = this.r(this.genericObject.dependentsOnThis.map(x => x.id).toString());
     this.label = this.genericObject.labelIgeom;
     this.defined = this.genericObject.defined;
     this.color = this.genericObject.color;
@@ -76,5 +100,7 @@ export class Action {
     this.pixel = "";
     this.font = "";
     this.labelColor = "";
-  }
-}
+    console.log("action.js!rehydrate(): final"); //D
+    }
+
+  } // export class Action