mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Added headless mode for direct render to file without the GUI
This commit is contained in:
@@ -4438,6 +4438,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Guitar wiring analyzer can now detect treble bleed circuit on volume controls</description>
|
<description>Guitar wiring analyzer can now detect treble bleed circuit on volume controls</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Added headless mode for direct render to file without the GUI - use 'inputFile --export (--force) outputFile' syntax</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added two types of 4PDT On/On/On Switches, e.g. DiMarzio EP1111 (thank you Lukasz Tekieli)</description>
|
<description>Added two types of 4PDT On/On/On Switches, e.g. DiMarzio EP1111 (thank you Lukasz Tekieli)</description>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-16.0.1"/>
|
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-16.0.1"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.diylc.DIYLCStarter"/>
|
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.diylc.DIYLCStarter"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="diylc-swing"/>
|
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="diylc-swing"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value=""c:\Users\bancika\Downloads\CUB V Layout.2024-06-07T15-37-50.diy" --export --force "c:\Users\bancika\Downloads\CUB V Layout.2024-06-07T15-37-50.pdsf""/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="diylc-swing"/>
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="diylc-swing"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms512m -Xmx2048m -javaagent:lib/jar-loader.jar -Dorg.diylc.storeDict=true -Dorg.diylc.enableTests=true -Dorg.diylc.scriptRun=true -Ddorg.diylc.debugContinuityAreas=true -Ddorg.diylc.debugComponentAreas=true -Ddorg.diylc.WriteStaticVariants=true -Ddorg.diylc.WriteStaticBlocks=true --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.geom=ALL-UNNAMED"/>
|
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms512m -Xmx2048m -javaagent:lib/jar-loader.jar -Dorg.diylc.storeDict=true -Dorg.diylc.enableTests=true -Dorg.diylc.scriptRun=true -Ddorg.diylc.debugContinuityAreas=true -Ddorg.diylc.debugComponentAreas=true -Ddorg.diylc.WriteStaticVariants=true -Ddorg.diylc.WriteStaticBlocks=true --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.geom=ALL-UNNAMED"/>
|
||||||
</launchConfiguration>
|
</launchConfiguration>
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ package org.diylc;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import javax.activity.InvalidActivityException;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -37,6 +39,8 @@ import org.diylc.presenter.Presenter;
|
|||||||
import org.diylc.serialization.ProjectFileManager;
|
import org.diylc.serialization.ProjectFileManager;
|
||||||
import org.diylc.swing.gui.MainFrame;
|
import org.diylc.swing.gui.MainFrame;
|
||||||
import org.diylc.swing.gui.TemplateDialog;
|
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 org.diylc.swingframework.fonts.FontOptimizer;
|
||||||
import com.apple.eawt.AppEvent;
|
import com.apple.eawt.AppEvent;
|
||||||
import com.apple.eawt.Application;
|
import com.apple.eawt.Application;
|
||||||
@@ -75,12 +79,16 @@ public class DIYLCStarter {
|
|||||||
// Initialize splash screen
|
// Initialize splash screen
|
||||||
DIYLCSplash splash = null;
|
DIYLCSplash splash = null;
|
||||||
Exception splashException = null;
|
Exception splashException = null;
|
||||||
|
|
||||||
|
boolean exportMode = Arrays.stream(args).anyMatch(a -> a.equalsIgnoreCase("--export"));
|
||||||
|
|
||||||
try {
|
if (!exportMode) {
|
||||||
splash = new DIYLCSplash();
|
try {
|
||||||
} catch (Exception e) {
|
splash = new DIYLCSplash();
|
||||||
System.out.println("Splash screen could not be initialized: " + e.getMessage());
|
} catch (Exception e) {
|
||||||
splashException = e;
|
System.out.println("Splash screen could not be initialized: " + e.getMessage());
|
||||||
|
splashException = e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
URL url = DIYLCStarter.class.getResource("log4j.properties");
|
URL url = DIYLCStarter.class.getResource("log4j.properties");
|
||||||
@@ -93,6 +101,10 @@ public class DIYLCStarter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initializeConfiguration();
|
initializeConfiguration();
|
||||||
|
|
||||||
|
if (exportMode) {
|
||||||
|
LOG.info("Running in export mode with params: " + String.join(", ", args));
|
||||||
|
}
|
||||||
|
|
||||||
// disable HIGHLIGHT_CONTINUITY_AREA config, keep it transient
|
// disable HIGHLIGHT_CONTINUITY_AREA config, keep it transient
|
||||||
ConfigurationManager.getInstance().writeValue(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false);
|
ConfigurationManager.getInstance().writeValue(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false);
|
||||||
@@ -174,16 +186,20 @@ public class DIYLCStarter {
|
|||||||
LOG.info("Main frame created.");
|
LOG.info("Main frame created.");
|
||||||
// mainFrame.setLocationRelativeTo(null);
|
// mainFrame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
if (splash == null) {
|
if (!exportMode) {
|
||||||
LOG.warn("Splash screen could not be initialized", splashException);
|
if (splash == null) {
|
||||||
} else {
|
LOG.warn("Splash screen could not be initialized", splashException);
|
||||||
LOG.info("Hiding splash screen...");
|
} else {
|
||||||
splash.setVisible(false);
|
LOG.info("Hiding splash screen...");
|
||||||
splash.dispose();
|
splash.setVisible(false);
|
||||||
LOG.info("Done hiding splash screen.");
|
splash.dispose();
|
||||||
|
LOG.info("Done hiding splash screen.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mainFrame.setVisible(true);
|
if (!exportMode) {
|
||||||
|
mainFrame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
// assign open file handler for Mac
|
// assign open file handler for Mac
|
||||||
if (Utils.isMac()) {
|
if (Utils.isMac()) {
|
||||||
@@ -227,11 +243,52 @@ public class DIYLCStarter {
|
|||||||
LOG.error("Could not read config.properties file", e);
|
LOG.error("Could not read config.properties file", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigurationManager.getInstance().isFileWithErrors())
|
if (!exportMode && ConfigurationManager.getInstance().isFileWithErrors())
|
||||||
mainFrame.showMessage("<html>"
|
mainFrame.showMessage("<html>"
|
||||||
+ "There was an error reading the configuration file and it was replaced by a default configuration.<br>"
|
+ "There was an error reading the configuration file and it was replaced by a default configuration.<br>"
|
||||||
+ "The backup file is created and placed in user directory under 'diylc' sub-directory with the current timestamp at the end.<br>"
|
+ "The backup file is created and placed in user directory under 'diylc' sub-directory with the current timestamp at the end.<br>"
|
||||||
+ "</html>", "Warning", IView.WARNING_MESSAGE);
|
+ "</html>", "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() {
|
private static void initializeConfiguration() {
|
||||||
|
|||||||
Reference in New Issue
Block a user