import java.util.ArrayList;
import java.util.Iterator;
+import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import tim.prune.App;
-import tim.prune.Config;
-import tim.prune.GenericFunction;
import tim.prune.I18nManager;
import tim.prune.UpdateMessageBroker;
+import tim.prune.config.Config;
+import tim.prune.data.NumberUtils;
import tim.prune.data.Track;
+import tim.prune.function.Export3dFunction;
+import tim.prune.gui.DialogCloser;
import tim.prune.load.GenericFileFilter;
import tim.prune.threedee.LineDialog;
import tim.prune.threedee.ThreeDModel;
/**
- * Class to export track information
- * into a specified Pov file
+ * Class to export a 3d scene of the track to a specified Pov file
*/
-public class PovExporter extends GenericFunction
+public class PovExporter extends Export3dFunction
{
private Track _track = null;
private JDialog _dialog = null;
private JFileChooser _fileChooser = null;
private String _cameraX = null, _cameraY = null, _cameraZ = null;
private JTextField _cameraXField = null, _cameraYField = null, _cameraZField = null;
- private JTextField _fontName = null, _altitudeCapField = null;
- private int _altitudeCap = ThreeDModel.MINIMUM_ALTITUDE_CAP;
+ private JTextField _fontName = null, _altitudeFactorField = null;
private JRadioButton _ballsAndSticksButton = null;
// defaults
/**
- * Constructor giving frame and track
+ * Constructor
* @param inApp App object
*/
public PovExporter(App inApp)
double cameraDist = Math.sqrt(inX*inX + inY*inY + inZ*inZ);
if (cameraDist > 0.0)
{
- _cameraX = "" + (inX / cameraDist * DEFAULT_CAMERA_DISTANCE);
- _cameraY = "" + (inY / cameraDist * DEFAULT_CAMERA_DISTANCE);
+ _cameraX = NumberUtils.formatNumber(inX / cameraDist * DEFAULT_CAMERA_DISTANCE, 5);
+ _cameraY = NumberUtils.formatNumber(inY / cameraDist * DEFAULT_CAMERA_DISTANCE, 5);
// Careful! Need to convert from java3d (right-handed) to povray (left-handed) coordinate system!
- _cameraZ = "" + (-inZ / cameraDist * DEFAULT_CAMERA_DISTANCE);
- }
- }
-
-
- /**
- * @param inAltitudeCap altitude cap to use
- */
- public void setAltitudeCap(int inAltitudeCap)
- {
- _altitudeCap = inAltitudeCap;
- if (_altitudeCap < ThreeDModel.MINIMUM_ALTITUDE_CAP)
- {
- _altitudeCap = ThreeDModel.MINIMUM_ALTITUDE_CAP;
+ _cameraZ = NumberUtils.formatNumber(-inZ / cameraDist * DEFAULT_CAMERA_DISTANCE, 5);
}
}
_cameraXField.setText(_cameraX);
_cameraYField.setText(_cameraY);
_cameraZField.setText(_cameraZ);
- // Set vertical scale
- _altitudeCapField.setText("" + _altitudeCap);
+ _altitudeFactorField.setText("" + _altFactor);
// Show dialog
_dialog.pack();
_dialog.setVisible(true);
{
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
- panel.add(new JLabel(I18nManager.getText("dialog.exportpov.text")), BorderLayout.NORTH);
+ JLabel introLabel = new JLabel(I18nManager.getText("dialog.exportpov.text"));
+ introLabel.setBorder(BorderFactory.createEmptyBorder(4, 4, 6, 4));
+ panel.add(introLabel, BorderLayout.NORTH);
// OK, Cancel buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
JLabel fontLabel = new JLabel(I18nManager.getText("dialog.exportpov.font"));
fontLabel.setHorizontalAlignment(SwingConstants.TRAILING);
centralPanel.add(fontLabel);
- String defaultFont = Config.getPovrayFont();
+ String defaultFont = Config.getConfigString(Config.KEY_POVRAY_FONT);
if (defaultFont == null || defaultFont.equals("")) {
defaultFont = DEFAULT_FONT_FILE;
}
_fontName = new JTextField(defaultFont, 12);
_fontName.setAlignmentX(Component.LEFT_ALIGNMENT);
+ _fontName.addKeyListener(new DialogCloser(_dialog));
centralPanel.add(_fontName);
//coordinates of camera
JLabel cameraXLabel = new JLabel(I18nManager.getText("dialog.exportpov.camerax"));
centralPanel.add(cameraZLabel);
_cameraZField = new JTextField("" + _cameraZ);
centralPanel.add(_cameraZField);
- // Altitude capping
- JLabel altitudeCapLabel = new JLabel(I18nManager.getText("dialog.3d.altitudecap"));
+ // Altitude exaggeration
+ JLabel altitudeCapLabel = new JLabel(I18nManager.getText("dialog.3d.altitudefactor"));
altitudeCapLabel.setHorizontalAlignment(SwingConstants.TRAILING);
centralPanel.add(altitudeCapLabel);
- _altitudeCapField = new JTextField("" + _altitudeCap);
- centralPanel.add(_altitudeCapField);
+ _altitudeFactorField = new JTextField("1.0");
+ centralPanel.add(_altitudeFactorField);
// Radio buttons for style - balls on sticks or tubes
JPanel stylePanel = new JPanel();
_fileChooser.setFileFilter(new GenericFileFilter("filetype.pov", new String[] {"pov"}));
_fileChooser.setAcceptAllFileFilterUsed(false);
// start from directory in config which should be set
- File configDir = Config.getWorkingDirectory();
- if (configDir != null) {_fileChooser.setCurrentDirectory(configDir);}
+ final String configDir = Config.getConfigString(Config.KEY_TRACK_DIR);
+ if (configDir != null) {_fileChooser.setCurrentDirectory(new File(configDir));}
}
// Allow choose again if an existing file is selected
{
// file saved
// Store directory in config for later
- Config.setWorkingDirectory(file.getParentFile());
+ Config.setConfigString(Config.KEY_TRACK_DIR, file.getParentFile().getAbsolutePath());
}
else
{
try
{
// try to use given altitude cap
- _altitudeCap = Integer.parseInt(_altitudeCapField.getText());
- model.setAltitudeCap(_altitudeCap);
+ double altFactor = Double.parseDouble(_altitudeFactorField.getText());
+ model.setAltitudeFactor(altFactor);
+ }
+ catch (NumberFormatException nfe) { // parse failed, reset
+ _altitudeFactorField.setText("1.0");
}
- catch (NumberFormatException nfe) {}
model.scale();
// Create file and write basics
}
catch (IOException ioe)
{
- JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.failed") + ioe.getMessage(),
+ JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("error.save.failed") + " : " + ioe.getMessage(),
I18nManager.getText("error.save.dialogtitle"), JOptionPane.ERROR_MESSAGE);
}
finally
{
fontPath = DEFAULT_FONT_FILE;
}
+ else {
+ Config.setConfigString(Config.KEY_POVRAY_FONT, fontPath);
+ }
// Set up output
String[] outputLines = {
"global_settings { ambient_light rgb <4, 4, 4> }", "",
" open",
" pigment { color rgb <0.5 0.5 0.5> }",
" }", "",
- // TODO: Export rods to POV? How to store in data?
+ // MAYBE: Export rods to POV? How to store in data?
"#declare waypoint_sphere =",
" sphere {",
" <0, 0, 0>, 0.4",
" pigment { color rgb <1 1 1> }",
" translate <-" + (inModelSize * 1.03) + ", 0.2, 0>",
"}", "",
- // TODO: Light positions should relate to model size
+ // MAYBE: Light positions should relate to model size
"// lights",
"light_source { <-1, 9, -4> color rgb <0.5 0.5 0.5>}",
"light_source { <1, 6, -14> color rgb <0.6 0.6 0.6>}",