diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml
index c0f49064..4b9f0309 100644
--- a/diylc/diylc-core/src/org/diylc/presenter/update.xml
+++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml
@@ -4438,6 +4438,10 @@
NEW_FEATURE
Guitar wiring analyzer can now detect treble bleed circuit on volume controls
+
+ NEW_FEATURE
+ Added headless mode for direct render to file without the GUI - use 'inputFile --export (--force) outputFile' syntax
+
NEW_FEATURE
Added two types of 4PDT On/On/On Switches, e.g. DiMarzio EP1111 (thank you Lukasz Tekieli)
diff --git a/diylc/diylc-swing/DIYLCStarter.launch b/diylc/diylc-swing/DIYLCStarter.launch
index fc93bd7c..fa569a22 100644
--- a/diylc/diylc-swing/DIYLCStarter.launch
+++ b/diylc/diylc-swing/DIYLCStarter.launch
@@ -13,6 +13,7 @@
+
diff --git a/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java b/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java
index a18ff637..02dbce9b 100644
--- a/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java
+++ b/diylc/diylc-swing/src/org/diylc/DIYLCStarter.java
@@ -20,8 +20,10 @@ package org.diylc;
import java.io.File;
import java.lang.reflect.Field;
import java.net.URL;
+import java.util.Arrays;
import java.util.List;
import java.util.Properties;
+import javax.activity.InvalidActivityException;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
@@ -37,6 +39,8 @@ import org.diylc.presenter.Presenter;
import org.diylc.serialization.ProjectFileManager;
import org.diylc.swing.gui.MainFrame;
import org.diylc.swing.gui.TemplateDialog;
+import org.diylc.swing.plugins.file.ProjectDrawingProvider;
+import org.diylc.swingframework.export.DrawingExporter;
import org.diylc.swingframework.fonts.FontOptimizer;
import com.apple.eawt.AppEvent;
import com.apple.eawt.Application;
@@ -75,12 +79,16 @@ public class DIYLCStarter {
// Initialize splash screen
DIYLCSplash splash = null;
Exception splashException = null;
+
+ boolean exportMode = Arrays.stream(args).anyMatch(a -> a.equalsIgnoreCase("--export"));
- try {
- splash = new DIYLCSplash();
- } catch (Exception e) {
- System.out.println("Splash screen could not be initialized: " + e.getMessage());
- splashException = e;
+ if (!exportMode) {
+ try {
+ splash = new DIYLCSplash();
+ } catch (Exception e) {
+ System.out.println("Splash screen could not be initialized: " + e.getMessage());
+ splashException = e;
+ }
}
URL url = DIYLCStarter.class.getResource("log4j.properties");
@@ -93,6 +101,10 @@ public class DIYLCStarter {
}
initializeConfiguration();
+
+ if (exportMode) {
+ LOG.info("Running in export mode with params: " + String.join(", ", args));
+ }
// disable HIGHLIGHT_CONTINUITY_AREA config, keep it transient
ConfigurationManager.getInstance().writeValue(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false);
@@ -174,16 +186,20 @@ public class DIYLCStarter {
LOG.info("Main frame created.");
// mainFrame.setLocationRelativeTo(null);
- if (splash == null) {
- LOG.warn("Splash screen could not be initialized", splashException);
- } else {
- LOG.info("Hiding splash screen...");
- splash.setVisible(false);
- splash.dispose();
- LOG.info("Done hiding splash screen.");
+ if (!exportMode) {
+ if (splash == null) {
+ LOG.warn("Splash screen could not be initialized", splashException);
+ } else {
+ LOG.info("Hiding splash screen...");
+ splash.setVisible(false);
+ splash.dispose();
+ LOG.info("Done hiding splash screen.");
+ }
}
- mainFrame.setVisible(true);
+ if (!exportMode) {
+ mainFrame.setVisible(true);
+ }
// assign open file handler for Mac
if (Utils.isMac()) {
@@ -227,11 +243,52 @@ public class DIYLCStarter {
LOG.error("Could not read config.properties file", e);
}
- if (ConfigurationManager.getInstance().isFileWithErrors())
+ if (!exportMode && ConfigurationManager.getInstance().isFileWithErrors())
mainFrame.showMessage(""
+ "There was an error reading the configuration file and it was replaced by a default configuration.
"
+ "The backup file is created and placed in user directory under 'diylc' sub-directory with the current timestamp at the end.
"
+ "", "Warning", IView.WARNING_MESSAGE);
+
+ if (exportMode) {
+ String exportFile = args[args.length - 1];
+ if (exportFile == null || exportFile.startsWith("--")) {
+ LOG.error("No output file provided");
+ System.exit(-1);
+ }
+ boolean forceMode = Arrays.stream(args).anyMatch(x -> "--force".equalsIgnoreCase(x));
+ if (new File(exportFile).exists()) {
+ if (forceMode) {
+ LOG.info("Replacing existing file.");
+ } else {
+ LOG.error("File already exists. Use --force flag to overwrite existing files or change export file name.");
+ System.exit(-1);
+ }
+ }
+ if (exportFile.toLowerCase().endsWith(".png")) {
+ try {
+ ProjectDrawingProvider drawingProvider = new ProjectDrawingProvider(presenter, false, false, false);
+ DrawingExporter.getInstance().exportPNG(drawingProvider, new File(exportFile));
+ LOG.info("Done.");
+ System.exit(0);
+ } catch (Exception e) {
+ LOG.error(e.getMessage());
+ System.exit(-1);
+ }
+ }
+ if (exportFile.toLowerCase().endsWith(".pdf")) {
+ try {
+ ProjectDrawingProvider drawingProvider = new ProjectDrawingProvider(presenter, false, false, false);
+ DrawingExporter.getInstance().exportPDF(drawingProvider, new File(exportFile));
+ LOG.info("Done.");
+ System.exit(0);
+ } catch (Exception e) {
+ LOG.error(e.getMessage());
+ System.exit(-1);
+ }
+ }
+ System.err.println("Unsupported output file type. Only PDF and PNG are currently supported");
+ System.exit(-1);
+ }
}
private static void initializeConfiguration() {