GCODE Viewer: Fix file position calculation
We were only adding one byte for "\n". That ignored that our regex could also match "\r\n" or "\r\r" or something like that. Our split regex now only matches one "\r" or "\n". Empty lines we'll simply ignore anyhow so no real harm done. Also, we no longer strip the comments in this step - leave that to the worker running in its own thread. Not only should that speed things up a bit, it will also allow us to better debug the worker in the future.
This commit is contained in:
parent
0456896d71
commit
5ce34f774e
2 changed files with 9 additions and 7 deletions
|
|
@ -325,6 +325,11 @@ var doParse = function () {
|
|||
extrude = false;
|
||||
line = line.split(/[\(;]/)[0];
|
||||
|
||||
if (!line || line.trim() === "") {
|
||||
// empty line, skip entirely
|
||||
continue;
|
||||
}
|
||||
|
||||
var addToModel = false;
|
||||
var move = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -44,15 +44,12 @@ GCODE.gCodeReader = (function(){
|
|||
var prepareGCode = function(totalSize){
|
||||
if(!lines)return;
|
||||
gcode = [];
|
||||
var i, tmp, byteCount;
|
||||
var i, byteCount;
|
||||
|
||||
byteCount = 0;
|
||||
for(i=0;i<lines.length;i++){
|
||||
byteCount += lines[i].length + 1; // line length + \n
|
||||
tmp = lines[i].indexOf(";");
|
||||
if(tmp > 1 || tmp === -1) {
|
||||
gcode.push({line: lines[i], percentage: byteCount * 100 / totalSize});
|
||||
}
|
||||
byteCount += lines[i].length + 1; // line length + line ending
|
||||
gcode.push({line: lines[i], percentage: byteCount * 100 / totalSize});
|
||||
}
|
||||
lines = [];
|
||||
};
|
||||
|
|
@ -146,7 +143,7 @@ GCODE.gCodeReader = (function(){
|
|||
this.clear();
|
||||
|
||||
var totalSize = reader.target.result.length;
|
||||
lines = reader.target.result.split(/[\r\n]+/g);
|
||||
lines = reader.target.result.split(/[\r\n]/g);
|
||||
reader.target.result = null;
|
||||
prepareGCode(totalSize);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue