Explorar el Código

Update 'src/app/core/application/header-menu.js'

Fixes to read GEO file with midpoint.
Indentation adjusts: inserted space in all function/method declaration (before open parenthesis) to distinguish it from its use
Changed comments.
leo hace 2 años
padre
commit
de09b46289
Se han modificado 1 ficheros con 46 adiciones y 20 borrados
  1. 46 20
      src/app/core/application/header-menu.js

+ 46 - 20
src/app/core/application/header-menu.js

@@ -1,20 +1,37 @@
+/*
+ * iGeom by LInE
+ * Free software to student private data
+ *
+ * http://www.matematica.br/igeom
+ * http://www.usp.br/line
+ *
+ * Treat actions associated to iGeomJS menu (File | Edit)
+ *
+ * ./app/core/application/header-menu.js
+ * @version 2023/07/14: Fixe reading GEO file with midpoint
+ */
+
 import { stageManager } from "./stage-manager";
 import { FileParser } from "../parser/file-parser";
 import { ParserOrchestrator } from "../parser/parser-orchestrator";
+
 class HeaderMenu {
-  constructor() { }
-  bootstrap() {
+
+  constructor () { }
+
+  bootstrap () {
     $("body").on("click", "#save", this.save.bind(this));
     $("body").on("click", "#open", this.open.bind(this));
     $("body").on("change", "#input-file", this.onFileChanged.bind(this));
-  }
-  save() {
+    }
+
+  save () {
     const layer = stageManager.getCurrentLayer();
     const file = layer.actionManager.save();
     const name = prompt("Sallet como", layer.name.replace(/ /g, "_").toLowerCase());
-    if (name == undefined) return;
-    const a = document.createElement("a"),
-      url = URL.createObjectURL(file);
+    if (name == undefined)
+      return;
+    const a = document.createElement("a"), url = URL.createObjectURL(file);
     a.href = url;
     a.download = `${name}.geo`;
     document.body.appendChild(a);
@@ -22,23 +39,32 @@ class HeaderMenu {
     setTimeout(function () {
       document.body.removeChild(a);
       window.URL.revokeObjectURL(url);
-    }, 0);
-  }
-  open() {
+      }, 0);
+    }
+
+  open () {
     $("#input-file").click();
-  }
-  onFileChanged() {
+    }
+
+  onFileChanged () {
     const files = $("#input-file")[0].files;
     if (files == undefined || files.length === 0) return;
     const reader = new FileReader();
     reader.onload = function () {
-      const result = reader.result;
-      const parser = new FileParser(result);
-      const map = parser.parse();
-      const orchestrator = new ParserOrchestrator(map);
-      orchestrator.orchestrate();
-    };
+      var result = "-1", parser = "-1", map = "-1", orchestrator = "-1";
+      try {
+        result = reader.result;
+        parser = new FileParser(result);
+        map = parser.parse();
+        orchestrator = new ParserOrchestrator(map);
+        orchestrator.orchestrate();
+        }
+      catch (error) {
+        console.log("header-menu.js!onFileChanged()!reader.onload: error " + error + "\n * result = " + result + "\n * parser = " + JSON.stringify(parser) + "\n * map = " + JSON.stringify(map));
+        }
+      };
     reader.readAsText(files[0]);
+    }
   }
-}
-export const headerMenu = new HeaderMenu();
+
+export const headerMenu = new HeaderMenu();