|
@@ -1,3 +1,8 @@
|
|
|
+// iGeom JS
|
|
|
+// LInE: "free software and private data"
|
|
|
+// http://www.matematica.br
|
|
|
+// http://www.usp.br/line
|
|
|
+
|
|
|
import * as ObjectClass from "./../enums/elements-class-enum";
|
|
|
|
|
|
const TYPE = 0; // identifica se Ponto, Texto, Reta...
|
|
@@ -24,19 +29,35 @@ export class FileParser {
|
|
|
this.content = content;
|
|
|
}
|
|
|
|
|
|
+ // @calledby app/core/application/header-menu.js: onFileChanged()
|
|
|
parse () {
|
|
|
- return this.content
|
|
|
- .split("\n")
|
|
|
- .filter(str => !str.match(/^[#\[]/))
|
|
|
+ //D console.trace();
|
|
|
+ console.log("file-parser.js!parse(): start");
|
|
|
+ var parsed_object, parsed_result = this.content.split("\n").filter(str => !str.match(/^[#\[]/))
|
|
|
.map(str => {
|
|
|
+ try {
|
|
|
if (!OBJECT_LINE_REGEX.test(str.trim())) {
|
|
|
- console.error("Malformed object string in igeom file: ", str);
|
|
|
+ console.error("Malformed object string in iGeom file: ", str);
|
|
|
return undefined;
|
|
|
}
|
|
|
- return this.parseObjectLine(str.trim());
|
|
|
+ parsed_object = this.parseObjectLine(str.trim());
|
|
|
+ //D console.log("file-parser.js!parse(): str=" + str + "\nparsed_object=" + JSON.stringify(parsed_object)); //D
|
|
|
+ return parsed_object;
|
|
|
+ } catch (error) {
|
|
|
+ // console.error("file-parser.js!parse(): error " + error + " in: " + str);
|
|
|
+ console.log("file-parser.js!parse(): error " + error + " in: " + str);
|
|
|
+ }
|
|
|
});
|
|
|
+ console.log("file-parser.js!parse(): final"); //D
|
|
|
+ return parsed_result;
|
|
|
}
|
|
|
|
|
|
+ // Function to analyse each line of a GEO file, currently with 8 itens.
|
|
|
+ // A typical GEO line (to free Point) and its 8 itens:
|
|
|
+ // 1:0, 0:0, 2:215.0 -145.0, 3:2, 4:A 4.0 -10.0 0, 6:1, 5:-16711936, 7:0
|
|
|
+ // in this line, following the order in line, the param code are
|
|
|
+ // "1" ("1:0"), "0" ("0:0"), "2" ("2:215.0 -145.0"), "3" ("3:2"), "4" ("4:A 4.0 -10.0 0"),
|
|
|
+ // "6" ("6:1"), "5" ("5:-16711936") and "7" ("7:0")
|
|
|
// @param {string} object_line
|
|
|
parseObjectLine (object_line) {
|
|
|
const map = new Map();
|
|
@@ -46,36 +67,37 @@ export class FileParser {
|
|
|
} else {
|
|
|
object_line = object_line.substring(0, object_line.length - 1);
|
|
|
}
|
|
|
+ //D console.log("file-parser.js: object_line = '" + object_line + "'"); //D
|
|
|
const properties = object_line.split(",");
|
|
|
for (const index in properties) {
|
|
|
const prop = properties[index];
|
|
|
const prop_info = prop.trim().split(":");
|
|
|
const key = parseInt(prop_info[0]);
|
|
|
if (prop_info[1] == undefined) continue;
|
|
|
- if (key == TYPE) {
|
|
|
+ if (key == TYPE) { // TYPE = 0
|
|
|
const type = prop_info[1];
|
|
|
map.set("type", ObjectClass.fromCodeToClass(parseInt(type)));
|
|
|
} else if (key == ID) {
|
|
|
const id = prop_info[1];
|
|
|
map.set("id", parseInt(id));
|
|
|
- } else if (key == DEFINITION) {
|
|
|
-var aux = "";
|
|
|
+ } else if (key == DEFINITION) { // DEFINITION = 2: "2:215.0 -145.0" or "2:0 1"...
|
|
|
+ var aux = ""; //D_
|
|
|
const param_list = [];
|
|
|
const list = prop_info[1].trim().split(" ");
|
|
|
-aux += "#prop_info[1]=" + list.length + ", ";
|
|
|
-var ii=0;
|
|
|
+ aux += "index=" + index + ", #prop_info[1]=" + list.length + ", "; //D_
|
|
|
+ var ii=0; //D_
|
|
|
for (const i in list) {
|
|
|
const param = list[i];
|
|
|
const maybe_number = Number(param);
|
|
|
-aux += "(" + ii + "," + param + ", " + maybe_number + "); ";
|
|
|
-ii++;
|
|
|
+ aux += "(" + ii + "," + param + " == " + maybe_number + "?); "; //D_
|
|
|
+ ii++; //D_
|
|
|
if (Number.isNaN(maybe_number)) {
|
|
|
param_list.push(param);
|
|
|
} else {
|
|
|
param_list.push(maybe_number);
|
|
|
}
|
|
|
- }
|
|
|
-console.log("file-parser.js: DEFINITION: " + aux);
|
|
|
+ } // for (const i in list)
|
|
|
+ //DD console.log("file-parser.js: DEFINITION: " + aux); //D_
|
|
|
map.set("param", param_list);
|
|
|
} else if (key == LIST) {
|
|
|
const id_list = [];
|
|
@@ -134,7 +156,8 @@ console.log("file-parser.js: DEFINITION: " + aux);
|
|
|
const b = number & 0xff;
|
|
|
map.set("label_color", { alpha: alpha, r: r, g: g, b: b });
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
+ } // for (const index in properties)
|
|
|
|
|
|
return map;
|
|
|
}
|