]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/save/SvgExporter.java
Version 18.6, December 2016
[GpsPrune.git] / tim / prune / save / SvgExporter.java
index c27b2f359ae680fc560db1922a869b08000c30a8..d623b4af3d2721196b5910ac73562d70fba4d1c1 100644 (file)
@@ -31,6 +31,7 @@ import tim.prune.UpdateMessageBroker;
 import tim.prune.config.Config;
 import tim.prune.data.Track;
 import tim.prune.function.Export3dFunction;
+import tim.prune.gui.DialogCloser;
 import tim.prune.load.GenericFileFilter;
 import tim.prune.threedee.ThreeDModel;
 
@@ -46,7 +47,7 @@ public class SvgExporter extends Export3dFunction
        private JTextField _phiField = null, _thetaField = null;
        private JTextField _altitudeFactorField = null;
        private JCheckBox _gradientsCheckbox = null;
-       private static double _scaleFactor = 1.0;
+       private static final double _scaleFactor = 200.0;
 
 
        /**
@@ -85,13 +86,18 @@ public class SvgExporter extends Export3dFunction
         */
        public void begin()
        {
-               // Make dialog window to select angles, colours etc
+               // Make dialog window to select input parameters
                if (_dialog == null)
                {
                        _dialog = new JDialog(_parentFrame, I18nManager.getText(getNameKey()), true);
                        _dialog.setLocationRelativeTo(_parentFrame);
                        _dialog.getContentPane().add(makeDialogComponents());
                }
+               // Get exaggeration factor from config
+               final int exaggFactor = Config.getConfigInt(Config.KEY_HEIGHT_EXAGGERATION);
+               if (exaggFactor > 0) {
+                       _altFactor = exaggFactor / 100.0;
+               }
 
                // Set angles
                NumberFormat threeDP = NumberFormat.getNumberInstance();
@@ -131,8 +137,7 @@ public class SvgExporter extends Export3dFunction
                buttonPanel.add(okButton);
                JButton cancelButton = new JButton(I18nManager.getText("button.cancel"));
                cancelButton.addActionListener(new ActionListener() {
-                       public void actionPerformed(ActionEvent e)
-                       {
+                       public void actionPerformed(ActionEvent e) {
                                _dialog.dispose();
                        }
                });
@@ -148,6 +153,7 @@ public class SvgExporter extends Export3dFunction
                phiLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                centralPanel.add(phiLabel);
                _phiField = new JTextField("" + _phi);
+               _phiField.addKeyListener(new DialogCloser(_dialog));
                centralPanel.add(_phiField);
                JLabel thetaLabel = new JLabel(I18nManager.getText("dialog.exportsvg.theta"));
                thetaLabel.setHorizontalAlignment(SwingConstants.TRAILING);
@@ -227,6 +233,8 @@ public class SvgExporter extends Export3dFunction
                                        {
                                                // file saved - store directory in config for later
                                                Config.setConfigString(Config.KEY_TRACK_DIR, file.getParentFile().getAbsolutePath());
+                                               // also store exaggeration
+                                               Config.setConfigInt(Config.KEY_HEIGHT_EXAGGERATION, (int) (_altFactor * 100));
                                        }
                                        else {
                                                // export failed so need to choose again
@@ -264,16 +272,15 @@ public class SvgExporter extends Export3dFunction
                        }
                        catch (NumberFormatException nfe) {}
                        model.scale();
-                       _scaleFactor = 200 / model.getModelSize();
 
                        boolean useGradients = _gradientsCheckbox.isSelected();
 
                        // Create file and write basics
                        writer = new FileWriter(inFile);
                        writeStartOfFile(writer, useGradients, lineSeparator);
-                       writeBasePlane(writer, model.getModelSize(), lineSeparator);
+                       writeBasePlane(writer, lineSeparator);
                        // write out cardinal letters NESW
-                       writeCardinals(writer, model.getModelSize(), lineSeparator);
+                       writeCardinals(writer, lineSeparator);
 
                        // write out points
                        writeDataPoints(writer, model, useGradients, lineSeparator);
@@ -315,7 +322,7 @@ public class SvgExporter extends Export3dFunction
        {
                inWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
                inWriter.write(inLineSeparator);
-               inWriter.write("<!-- Svg file produced by Prune - see http://activityworkshop.net/ -->");
+               inWriter.write("<!-- Svg file produced by GpsPrune - see http://activityworkshop.net/ -->");
                inWriter.write(inLineSeparator);
                inWriter.write("<svg width=\"800\" height=\"700\">");
                inWriter.write(inLineSeparator);
@@ -331,7 +338,7 @@ public class SvgExporter extends Export3dFunction
                                "<stop offset=\"100%\" stop-color=\"#008000\"/>" +
                                "</radialGradient>" +
                                "</defs>";
-                   inWriter.write(defs);
+                       inWriter.write(defs);
                        inWriter.write(inLineSeparator);
                }
                inWriter.write("<g inkscape:label=\"Layer 1\" inkscape:groupmode=\"layer\" id=\"layer1\">");
@@ -341,18 +348,17 @@ public class SvgExporter extends Export3dFunction
        /**
         * Write the base plane
         * @param inWriter Writer to use for writing file
-        * @param inModelSize model size
         * @param inLineSeparator line separator to use
         * @throws IOException on file writing error
         */
-       private void writeBasePlane(FileWriter inWriter, double inModelSize, String inLineSeparator)
+       private void writeBasePlane(FileWriter inWriter, String inLineSeparator)
        throws IOException
        {
                // Use model size and camera angles to draw path for base rectangle (using 3d transform)
-               int[] coords1 = convertCoordinates(-inModelSize, -inModelSize, 0);
-               int[] coords2 = convertCoordinates(inModelSize, -inModelSize, 0);
-               int[] coords3 = convertCoordinates(inModelSize, inModelSize, 0);
-               int[] coords4 = convertCoordinates(-inModelSize, inModelSize, 0);
+               int[] coords1 = convertCoordinates(-1.0, -1.0, 0);
+               int[] coords2 = convertCoordinates(1.0, -1.0, 0);
+               int[] coords3 = convertCoordinates(1.0, 1.0, 0);
+               int[] coords4 = convertCoordinates(-1.0, 1.0, 0);
                final String corners = "M " + coords1[0] + "," + coords1[1]
                        + " L " + coords2[0] + "," + coords2[1]
                        + " L " + coords3[0] + "," + coords3[1]
@@ -364,21 +370,20 @@ public class SvgExporter extends Export3dFunction
        /**
         * Write the cardinal letters NESW
         * @param inWriter Writer to use for writing file
-        * @param inModelSize model size
         * @param inLineSeparator line separator to use
         * @throws IOException on file writing error
         */
-       private void writeCardinals(FileWriter inWriter, double inModelSize, String inLineSeparator)
+       private void writeCardinals(FileWriter inWriter, String inLineSeparator)
        throws IOException
        {
                // Use model size and camera angles to calculate positions
-               int[] coordsN = convertCoordinates(0, inModelSize, 0);
+               int[] coordsN = convertCoordinates(0, 1.0, 0);
                writeCardinal(inWriter, coordsN[0], coordsN[1], "cardinal.n", inLineSeparator);
-               int[] coordsE = convertCoordinates(inModelSize, 0, 0);
+               int[] coordsE = convertCoordinates(1.0, 0, 0);
                writeCardinal(inWriter, coordsE[0], coordsE[1], "cardinal.e", inLineSeparator);
-               int[] coordsS = convertCoordinates(0, -inModelSize, 0);
+               int[] coordsS = convertCoordinates(0, -1.0, 0);
                writeCardinal(inWriter, coordsS[0], coordsS[1], "cardinal.s", inLineSeparator);
-               int[] coordsW = convertCoordinates(-inModelSize, 0, 0);
+               int[] coordsW = convertCoordinates(-1.0, 0, 0);
                writeCardinal(inWriter, coordsW[0], coordsW[1], "cardinal.w", inLineSeparator);
        }