Display error when SVG export failed

This commit is contained in:
SiboVG 2024-01-30 20:57:22 +01:00
parent 74cfa4dde5
commit 4cf77bcdc4
2 changed files with 26 additions and 12 deletions

View File

@ -968,6 +968,8 @@ FinSetConfig.but.Splitfins = Split fins
FinSetConfig.but.Splitfins.ttip = Split the fin set into separate fins. FinSetConfig.but.Splitfins.ttip = Split the fin set into separate fins.
FinSetConfig.lbl.exportSVG = Export to SVG FinSetConfig.lbl.exportSVG = Export to SVG
FinSetConfig.lbl.exportSVG.ttip = Export the fin profile to an SVG file. FinSetConfig.lbl.exportSVG.ttip = Export the fin profile to an SVG file.
FinSetConfig.errorSVG.title = SVG Export Error
FinSetConfig.errorSVG.msg = An error occurred while exporting the SVG file: %s.
FinSetConfig.but.AutoCalc = Calculate automatically FinSetConfig.but.AutoCalc = Calculate automatically
FinSetConfig.but.AutoCalc.ttip = <html>Calculates the height and length of the fin tabs, based on<br>inner tube and centering ring components of the fin's parent component.</html> FinSetConfig.but.AutoCalc.ttip = <html>Calculates the height and length of the fin tabs, based on<br>inner tube and centering ring components of the fin's parent component.</html>
FinSetConfig.lbl.Through-the-wall = Through-the-wall fin tabs: FinSetConfig.lbl.Through-the-wall = Through-the-wall fin tabs:

View File

@ -14,9 +14,12 @@ import javax.swing.JComboBox;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JSpinner; import javax.swing.JSpinner;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocument;
@ -155,12 +158,18 @@ public abstract class FinSetConfig extends RocketComponentConfig {
return; return;
} }
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory());
SVGOptionPanel svgOptions = (SVGOptionPanel) chooser.getAccessory(); SVGOptionPanel svgOptions = (SVGOptionPanel) chooser.getAccessory();
prefs.setSVGStrokeColor(svgOptions.getStrokeColor()); prefs.setSVGStrokeColor(svgOptions.getStrokeColor());
prefs.setSVGStrokeWidth(svgOptions.getStrokeWidth()); prefs.setSVGStrokeWidth(svgOptions.getStrokeWidth());
FinSetConfig.writeSVGFile((FinSet) component, selectedFile, svgOptions); try {
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(chooser.getCurrentDirectory()); FinSetConfig.writeSVGFile((FinSet) component, selectedFile, svgOptions);
} catch (Exception svgErr) {
JOptionPane.showMessageDialog(FinSetConfig.this,
String.format(trans.get("FinSetConfig.errorSVG.msg"), svgErr.getMessage()),
trans.get("FinSetConfig.errorSVG.title"), JOptionPane.ERROR_MESSAGE);
}
} }
} }
}); });
@ -620,16 +629,19 @@ public abstract class FinSetConfig extends RocketComponentConfig {
return filletPanel; return filletPanel;
} }
private static boolean writeSVGFile(FinSet finSet, File file, SVGOptionPanel svgOptions) { /**
* Writes the FinSet object to an SVG file.
*
* @param finSet the FinSet object to write to the SVG file
* @param file the File object representing the SVG file to be written
* @param svgOptions the SVGOptionPanel object containing the options for writing the SVG file
* @throws Exception if there is an error writing the SVG file
*/
private static void writeSVGFile(FinSet finSet, File file, SVGOptionPanel svgOptions) throws ParserConfigurationException, TransformerException {
Coordinate[] points = finSet.getFinPointsWithRoot(); Coordinate[] points = finSet.getFinPointsWithRoot();
try {
SVGBuilder builder = new SVGBuilder(); SVGBuilder builder = new SVGBuilder();
builder.addPath(points, null, svgOptions.getStrokeColor(), svgOptions.getStrokeWidth()); builder.addPath(points, null, svgOptions.getStrokeColor(), svgOptions.getStrokeWidth());
builder.writeToFile(file); builder.writeToFile(file);
return true;
} catch (Exception e) {
log.error("Error writing SVG file", e);
return false;
}
} }
} }