Search in sources :

Example 1 with GcodeStats

use of com.willwinder.universalgcodesender.gcode.GcodeStats in project Universal-G-Code-Sender by winder.

the class GUIBackend method initializeProcessedLines.

private void initializeProcessedLines(boolean forceReprocess, File startFile, GcodeParser gcodeParser) throws Exception {
    if (startFile != null) {
        try (FileReader fr = new FileReader(startFile)) {
            Charset.forName(fr.getEncoding());
        }
        logger.info("Start preprocessing");
        long start = System.currentTimeMillis();
        if (this.processedGcodeFile == null || forceReprocess) {
            gcp.reset();
            String name = startFile.getName();
            // If this is being re-processed, strip the ugs postfix and try again.
            Pattern word = Pattern.compile("(.*)_ugs_[\\d]+$");
            Matcher match = word.matcher(name);
            if (match.matches()) {
                name = match.group(1);
            }
            this.processedGcodeFile = new File(this.getTempDir(), name + "_ugs_" + System.currentTimeMillis());
            this.preprocessAndExportToFile(gcodeParser, startFile, this.processedGcodeFile);
            // Store gcode file stats.
            GcodeStats gs = gcp.getCurrentStats();
            this.settings.setFileStats(new FileStats(gs.getMin(), gs.getMax(), gs.getCommandCount()));
        }
        long end = System.currentTimeMillis();
        logger.info("Took " + (end - start) + "ms to preprocess");
        if (this.isConnected()) {
            this.estimatedSendDuration = -1L;
            Thread estimateThread = new Thread(() -> estimatedSendDuration = controller.getJobLengthEstimate(processedGcodeFile));
            estimateThread.start();
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) GcodeStats(com.willwinder.universalgcodesender.gcode.GcodeStats) Matcher(java.util.regex.Matcher) FileStats(com.willwinder.universalgcodesender.utils.Settings.FileStats) FileReader(java.io.FileReader) File(java.io.File)

Aggregations

GcodeStats (com.willwinder.universalgcodesender.gcode.GcodeStats)1 FileStats (com.willwinder.universalgcodesender.utils.Settings.FileStats)1 File (java.io.File)1 FileReader (java.io.FileReader)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1