From 5a3f5bea19bbc0177dfd8cb965bf26320a9a76f2 Mon Sep 17 00:00:00 2001
From: Marcel Schwittlick <lzrm@mrzl.net>
Date: Fri, 27 Nov 2015 22:36:31 +0100
Subject: [PATCH] exportgcode: fixing some quirks, refactoring

---
 src/com/t_oster/liblasercut/LaserCutter.java          |  7 ++++++-
 .../liblasercut/drivers/GenericGcodeDriver.java       | 11 +++++------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/com/t_oster/liblasercut/LaserCutter.java b/src/com/t_oster/liblasercut/LaserCutter.java
index 6fc7654..64cc8b2 100644
--- a/src/com/t_oster/liblasercut/LaserCutter.java
+++ b/src/com/t_oster/liblasercut/LaserCutter.java
@@ -24,6 +24,8 @@ package com.t_oster.liblasercut;
 
 import com.t_oster.liblasercut.platform.Point;
 import com.t_oster.liblasercut.platform.Util;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
 import java.util.LinkedList;
 import java.util.List;
 
@@ -80,7 +82,10 @@ public abstract class LaserCutter implements Cloneable, Customizable {
      */
     public abstract void sendJob(LaserJob job, ProgressListener pl, List<String> warnings) throws IllegalJobException, Exception;
 
-	public abstract void saveJob(LaserJob job) throws IllegalJobException, Exception;
+	public void saveJob(java.io.PrintStream fileOutputStream, LaserJob job) throws NotImplementedException, IllegalJobException, Exception {
+		System.err.println("Your driver does not implement saveJob(LaserJob job)");
+		throw new NotImplementedException();
+	}
 
     /**
      * If you lasercutter supports autofocus, override this method,
diff --git a/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java b/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
index 3d2db21..cc0f29d 100644
--- a/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
+++ b/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
@@ -27,6 +27,7 @@ import java.io.File;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
+import java.lang.Exception;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.URI;
@@ -661,14 +662,12 @@ public class GenericGcodeDriver extends LaserCutter {
   }
 
 @Override
-public void saveJob(LaserJob job) throws IllegalJobException, Exception {
+public void saveJob(java.io.PrintStream fileOutputStream, LaserJob job) throws IllegalJobException, Exception {
 	checkJob(job);
 
-	String timestamp = new SimpleDateFormat( "yyyyMMddhhmmssSSS" ).format( new Date( ) );
-	String filename = "output_" + timestamp + ".gcode";
-	System.out.println("Creating file " + filename);
-	this.out = new PrintStream(new File(filename));
+	this.out = fileOutputStream;
 
+	boolean wasSetWaitingForOk = isWaitForOKafterEachLine();
 	setWaitForOKafterEachLine( false );
 
 	writeInitializationCode();
@@ -695,7 +694,7 @@ public void saveJob(LaserJob job) throws IllegalJobException, Exception {
 	writeShutdownCode();
 	this.out.flush();
 
-	setWaitForOKafterEachLine(true);
+	setWaitForOKafterEachLine(wasSetWaitingForOk);
 }
 
   private List<Double> resolutions;
-- 
GitLab