Merge branch 'kruland-integration' of ssh://github.com/plaa/openrocket into kruland-integration

This commit is contained in:
Sampo Niskanen 2012-12-22 13:29:08 +02:00
commit 1c04713131
11 changed files with 80 additions and 178 deletions

View File

@ -725,6 +725,7 @@ AppearanceCfg.lbl.Usedefault = Use default
AppearanceCfg.but.savedefault = Save as default appearance
AppearanceCfg.lbl.Texture = Texture:
AppearanceCfg.lbl.shine = Shine:
AppearanceCfg.lbl.color.Color = Color:
AppearanceCfg.lbl.color.diffuse = Diffuse Color:
AppearanceCfg.lbl.color.ambient = Ambient Color:
AppearanceCfg.lbl.color.specular = Specular Color:
@ -1061,10 +1062,6 @@ StorageOptChooser.lbl.seconds = seconds
StorageOptChooser.rdbut.Onlyprimfig = Only primary figures
StorageOptChooser.lbl.longC1 = <html>Store only the values shown in the summary table.<br>
StorageOptChooser.lbl.longC2 = This results in the smallest files.
StorageOptChooser.checkbox.IncludeDecals = Include decals
StorageOptChooser.lbl.IncludeDecals = "Including decals will produce a compressed zip file"
StorageOptChooser.checkbox.Compfile = Compress file
StorageOptChooser.lbl.UsingComp = Using compression reduces the file size significantly.
StorageOptChooser.lbl.longD1 = An estimate on how large the resulting file would be with the present options.
StorageOptChooser.ttip.Saveopt = Save options
StorageOptChooser.lbl.Estfilesize = Estimated file size:

View File

@ -27,10 +27,6 @@ public class DecalRegistry {
private boolean isZipFile = false;
private Map<String,File> exportedDecalMap = new HashMap<String,File>();
/* TODO - should we implement caching?
private Map<String,byte[]> cache = new HashMap<String,byte[]>();
*/
public void setBaseFile(FileInfo fileInfo) {
this.fileInfo = fileInfo;
@ -52,7 +48,7 @@ public class DecalRegistry {
return false;
}
try {
InputStream is = forwardToEntry(name);
InputStream is = findInZipContainer(name);
if ( is != null ) {
is.close();
return true;
@ -63,7 +59,7 @@ public class DecalRegistry {
return false;
}
}
/**
* This function returns an InputStream backed by a byte[] containing the decal pixels.
* If it reads in the bytes from an actual file, the underlying file is closed.
@ -74,18 +70,11 @@ public class DecalRegistry {
* @throws IOException
*/
public InputStream getDecal( String name ) throws FileNotFoundException, IOException {
/* TODO
// if the decal has already been cached return it.
byte[] bytes = cache.get(name);
if ( bytes != null ) {
return new ByteArrayInputStream(bytes);
}
*/
// This is the InputStream to be returned.
InputStream rawIs = null;
// First check if the decal had been exported
{
File exportedFile= exportedDecalMap.get(name);
@ -101,7 +90,7 @@ public class DecalRegistry {
}
if ( rawIs == null && isZipFile ) {
rawIs = forwardToEntry(name);
rawIs = findInZipContainer(name);
}
// Check absolute file name:
@ -131,7 +120,6 @@ public class DecalRegistry {
try {
byte[] bytes = FileUtils.readBytes(rawIs);
// TODO - here we would update the cache.
return new ByteArrayInputStream(bytes);
}
finally {
@ -141,7 +129,7 @@ public class DecalRegistry {
}
public void exportDecal( String decalName, File selectedFile ) throws IOException {
try {
InputStream is = getDecal(decalName);
OutputStream os = new BufferedOutputStream( new FileOutputStream(selectedFile));
@ -150,21 +138,26 @@ public class DecalRegistry {
is.close();
os.close();
exportedDecalMap.put(decalName, selectedFile );
}
catch (IOException iex) {
throw new BugException(iex);
}
}
private ZipInputStream forwardToEntry( String name ) throws IOException {
ZipInputStream zis = new ZipInputStream(fileInfo.fileURL.openStream());
private ZipInputStream findInZipContainer( String name ) {
ZipInputStream zis = null;
try {
zis = new ZipInputStream(fileInfo.fileURL.openStream());
} catch( IOException ex ) {
return null;
}
try {
ZipEntry entry = zis.getNextEntry();
while ( entry != null ) {
@ -173,12 +166,16 @@ public class DecalRegistry {
}
entry = zis.getNextEntry();
}
zis.close();
return null;
}
catch ( IOException ioex ) {
zis.close();
throw ioex;
try {
zis.close();
} catch ( IOException ex ) {
// why does close throw? it's maddening
}
return null;
}
zis.close();
return null;
}
}

View File

@ -14,10 +14,6 @@ public class StorageOptions implements Cloneable {
private FileType fileType = FileType.OPENROCKET;
private boolean includeDecals = false;
private boolean compressionEnabled = true;
private double simulationTimeSkip = SIMULATION_DATA_NONE;
private boolean explicitlySet = false;
@ -30,22 +26,6 @@ public class StorageOptions implements Cloneable {
this.fileType = fileType;
}
public boolean isIncludeDecals() {
return includeDecals;
}
public void setIncludeDecals(boolean includeDecals) {
this.includeDecals = includeDecals;
}
public boolean isCompressionEnabled() {
return compressionEnabled;
}
public void setCompressionEnabled(boolean compression) {
this.compressionEnabled = compression;
}
public double getSimulationTimeSkip() {
return simulationTimeSkip;
}

View File

@ -106,7 +106,6 @@ public class GeneralRocketLoader {
// Check for GZIP
if (buffer[0] == GZIP_SIGNATURE[0] && buffer[1] == GZIP_SIGNATURE[1]) {
OpenRocketDocument doc = loadFromStream(new GZIPInputStream(source), motorFinder);
doc.getDefaultStorageOptions().setCompressionEnabled(true);
doc.getDecalRegistry().setIsZipFile(false);
return doc;
}
@ -122,8 +121,6 @@ public class GeneralRocketLoader {
}
if (entry.getName().matches(".*\\.[oO][rR][kK]$")) {
OpenRocketDocument doc = loadFromStream(in, motorFinder);
doc.getDefaultStorageOptions().setCompressionEnabled(true);
doc.getDefaultStorageOptions().setIncludeDecals(true);
doc.getDecalRegistry().setIsZipFile(true);
return doc;
} else if ( entry.getName().matches(".*\\.[rR][kK][tT]$")) {

View File

@ -18,6 +18,7 @@ import net.sf.openrocket.appearance.AppearanceBuilder;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.StorageOptions;
import net.sf.openrocket.document.StorageOptions.FileType;
import net.sf.openrocket.file.openrocket.OpenRocketSaver;
import net.sf.openrocket.file.rocksim.export.RocksimSaver;
import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -146,24 +147,15 @@ public class GeneralRocketSaver {
private void save(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options) throws IOException {
// If we don't include decals, just write the simple file.
if (!options.isIncludeDecals()) {
saveInternal(output,document,options);
// For now, we don't save decal inforamtion in ROCKSIM files, so don't do anything
// which follows.
// TODO - add support for decals in ROCKSIM files?
if ( options.getFileType() == FileType.ROCKSIM ) {
saveInternal(output, document, options);
output.close();
return;
}
// We're saving decals, so the result will be a zip file. There's no
// need to gzip the rocket model file in the archive.
options.setCompressionEnabled(false);
/* if we want a directory ...
String path = fileName;
int dotlocation = fileName.lastIndexOf('.');
if ( dotlocation > 1 ) {
path = fileName.substring(dotlocation);
}
*/
// grab the set of decal images. We do this up front
// so we can fail early if some resource is missing.
@ -239,7 +231,12 @@ public class GeneralRocketSaver {
}
// Now we have to loop through all the components and update their names.
for( RocketComponent c : document.getRocket() ) {
// First we copy the OpenRocketDocument so we can modify the decal file names
// without changing the ui's copy. This is so the ui will continue to
// use the exported decals.
OpenRocketDocument rocketDocCopy = document.copy();
for( RocketComponent c : rocketDocCopy.getRocket() ) {
if ( c.getAppearance() == null ) {
continue;
@ -258,7 +255,19 @@ public class GeneralRocketSaver {
c.setAppearance(builder.getAppearance());
}
Map<String,InputStream> decalMap = new HashMap<String,InputStream>();
for( Map.Entry<String, InputStream> image : decals.entrySet() ) {
String newName = decalNameNormalization.get(image.getKey());
decalMap.put(newName, image.getValue());
}
saveAllPartsZipFile(fileName, output, rocketDocCopy, options, decalMap);
}
public void saveAllPartsZipFile(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options, Map<String,InputStream> decals) throws IOException {
// Open a zip stream to write to.
ZipOutputStream zos = new ZipOutputStream(output);
zos.setLevel(9);
@ -275,8 +284,8 @@ public class GeneralRocketSaver {
for( Map.Entry<String, InputStream> image : decals.entrySet() ) {
String newName = decalNameNormalization.get(image.getKey());
ZipEntry decal = new ZipEntry(newName);
String name = image.getKey();
ZipEntry decal = new ZipEntry(name);
zos.putNextEntry(decal);
InputStream is = image.getValue();

View File

@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.zip.GZIPOutputStream;
import net.sf.openrocket.aerodynamics.Warning;
import net.sf.openrocket.document.OpenRocketDocument;
@ -57,11 +56,8 @@ public class OpenRocketSaver extends RocketSaver {
// Estimated storage used by different portions
// These have been hand-estimated from saved files
private static final int BYTES_PER_COMPONENT_UNCOMPRESSED = 590;
private static final int BYTES_PER_COMPONENT_COMPRESSED = 80;
private static final int BYTES_PER_SIMULATION_UNCOMPRESSED = 1000;
private static final int BYTES_PER_SIMULATION_COMPRESSED = 100;
private static final int BYTES_PER_DATAPOINT_UNCOMPRESSED = 350;
private static final int BYTES_PER_DATAPOINT_COMPRESSED = 100;
@ -73,11 +69,6 @@ public class OpenRocketSaver extends RocketSaver {
log.info("Saving .ork file");
if (options.isCompressionEnabled()) {
log.debug("Enabling compression");
output = new GZIPOutputStream(output);
}
dest = new BufferedWriter(new OutputStreamWriter(output, OPENROCKET_CHARSET));
// Select file version number
@ -121,9 +112,6 @@ public class OpenRocketSaver extends RocketSaver {
log.debug("Writing complete, flushing buffers");
dest.flush();
if (options.isCompressionEnabled()) {
((GZIPOutputStream) output).finish();
}
}
/*
@ -178,17 +166,11 @@ public class OpenRocketSaver extends RocketSaver {
componentCount++;
}
if (options.isCompressionEnabled())
size += componentCount * BYTES_PER_COMPONENT_COMPRESSED;
else
size += componentCount * BYTES_PER_COMPONENT_UNCOMPRESSED;
size += componentCount * BYTES_PER_COMPONENT_COMPRESSED;
// Size per simulation
if (options.isCompressionEnabled())
size += doc.getSimulationCount() * BYTES_PER_SIMULATION_COMPRESSED;
else
size += doc.getSimulationCount() * BYTES_PER_SIMULATION_UNCOMPRESSED;
size += doc.getSimulationCount() * BYTES_PER_SIMULATION_COMPRESSED;
// Size per flight data point
@ -205,10 +187,7 @@ public class OpenRocketSaver extends RocketSaver {
}
}
if (options.isCompressionEnabled())
size += pointCount * BYTES_PER_DATAPOINT_COMPRESSED;
else
size += pointCount * BYTES_PER_DATAPOINT_UNCOMPRESSED;
size += pointCount * BYTES_PER_DATAPOINT_COMPRESSED;
return size;
}

View File

@ -84,7 +84,6 @@ public class OpenRocketLoader extends AbstractRocketLoader {
timeSkip = Math.rint(timeSkip * 100) / 100;
doc.getDefaultStorageOptions().setSimulationTimeSkip(timeSkip);
doc.getDefaultStorageOptions().setCompressionEnabled(false); // Set by caller if compressed
doc.getDefaultStorageOptions().setExplicitlySet(false);
doc.clearUndo();

View File

@ -62,7 +62,6 @@ public class RocksimSaver extends RocketSaver {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(dest, "UTF-8"));
writer.write(marshalToRocksim(doc));
writer.flush();
writer.close();
}
@Override

View File

@ -39,9 +39,6 @@ public class StorageOptionChooser extends JPanel {
private JSpinner timeSpinner;
private JCheckBox compressButton;
private JCheckBox decalButton;
private JLabel estimateLabel;
@ -123,22 +120,6 @@ public class StorageOptionChooser extends JPanel {
noneButton.addActionListener(actionUpdater);
this.add(noneButton, "spanx, wrap 20lp");
//// Save decals
// FIXME - should we hide this if there are no decals?
decalButton = new JCheckBox(trans.get("StorageOptChooser.checkbox.IncludeDecals"));
decalButton.setToolTipText(trans.get("StorageOptChooser.lbl.IncludeDecals"));
decalButton.addActionListener(actionUpdater);
this.add(decalButton, "spanx, wrap para");
//// Compress file
// FIXME - if the user selects save decals, should we automatically select compress file?
compressButton = new JCheckBox(trans.get("StorageOptChooser.checkbox.Compfile"));
//// Using compression reduces the file size significantly.
compressButton.setToolTipText(trans.get("StorageOptChooser.lbl.UsingComp"));
compressButton.addActionListener(actionUpdater);
this.add(compressButton, "spanx, wrap para");
// Estimate is updated in loadOptions(opts)
estimateLabel = new JLabel("");
//// An estimate on how large the resulting file would
@ -176,10 +157,6 @@ public class StorageOptionChooser extends JPanel {
timeSpinner.setValue(t);
artificialEvent = false;
// Compression checkbox
compressButton.setSelected(opts.isCompressionEnabled());
decalButton.setSelected(opts.isIncludeDecals());
updateEstimate();
}
@ -197,9 +174,6 @@ public class StorageOptionChooser extends JPanel {
opts.setSimulationTimeSkip(t);
opts.setIncludeDecals(decalButton.isSelected());
opts.setCompressionEnabled(compressButton.isSelected());
opts.setExplicitlySet(true);
}

View File

@ -49,7 +49,11 @@ public class AppearancePanel extends JPanel {
private SimpleAppearanceBuilder ab;
private final static UnitGroup UNIT_FOR_SCALES = new UnitGroup();
/**
* A non-unit that adjusts by a small amount, suitable for
* values that are on the 0-1 scale
*/
private final static UnitGroup TEXTURE_UNIT = new UnitGroup();
static {
Unit no_unit = new GeneralUnit(1,"",2) {
@Override
@ -63,7 +67,7 @@ public class AppearancePanel extends JPanel {
}
};
UNIT_FOR_SCALES.addUnit(no_unit);
TEXTURE_UNIT.addUnit(no_unit);
}
private static final JColorChooser colorChooser = new JColorChooser();
@ -117,11 +121,7 @@ public class AppearancePanel extends JPanel {
}
final JButton figureColorButton = new JButton(new ColorIcon(figureColor));
/*final JButton diffuseColorButton = new JButton(new ColorIcon(ab.getDiffuse()));
final JButton ambientColorButton = new JButton(new ColorIcon(ab.getAmbient()));
final JButton specularColorButton = new JButton(new ColorIcon(ab.getSpecular()));*/
final JButton colorButton = new JButton(new ColorIcon(ab.getAmbient()));
final JButton colorButton = new JButton(new ColorIcon(ab.getColor()));
final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));;
@ -129,9 +129,6 @@ public class AppearancePanel extends JPanel {
@Override
public void stateChanged(EventObject e) {
figureColorButton.setIcon(new ColorIcon(c.getColor()));
/*diffuseColorButton.setIcon(new ColorIcon(ab.getDiffuse()));
ambientColorButton.setIcon(new ColorIcon(ab.getAmbient()));
specularColorButton.setIcon(new ColorIcon(ab.getSpecular()));*/
colorButton.setIcon(new ColorIcon(ab.getColor()));
c.setAppearance(ab.getAppearance());
}
@ -150,11 +147,7 @@ public class AppearancePanel extends JPanel {
figureColorButton.addActionListener(new ColorActionListener(c, "Color"));
colorButton.addActionListener(new ColorActionListener(ab, "Color"));
/*diffuseColorButton.addActionListener(new ColorActionListener(ab, "Diffuse"));
ambientColorButton.addActionListener(new ColorActionListener(ab, "Ambient"));
specularColorButton.addActionListener(new ColorActionListener(ab, "Specular"));*/
BooleanModel mDefault = new BooleanModel(c.getAppearance() == null);
BooleanModel fDefault = new BooleanModel(c.getColor() == null);
@ -220,66 +213,50 @@ public class AppearancePanel extends JPanel {
{// Texture Header Row
add(new StyledLabel(trans.get("AppearanceCfg.lbl.Appearance"), Style.BOLD), "wrap");
final JCheckBox materialDefault = new JCheckBox(mDefault);
materialDefault.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (materialDefault.isSelected()) {
c.setAppearance(null);
} else {
c.setAppearance(ab.getAppearance());
}
}
});
}
{// Texture File
add(new JLabel(trans.get("AppearanceCfg.lbl.Texture")));
JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]"));
mDefault.addEnableComponent(textureDropDown, false);
p.add(textureDropDown, "grow");
add(p, "span 3, growx, wrap");
}
/*{ // Diffuse
add(new JLabel(trans.get("AppearanceCfg.lbl.color.diffuse")));
mDefault.addEnableComponent(diffuseColorButton, false);
add(diffuseColorButton);
}*/
{ // Color
add(new JLabel("Color"));
mDefault.addEnableComponent(colorButton, false);
add(new JLabel(trans.get("AppearanceCfg.lbl.color.Color")));
//mDefault.addEnableComponent(colorButton, false);
colorButton.setEnabled(ab.getImage() == null);
add(colorButton);
ab.addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
colorButton.setEnabled(ab.getImage() == null);
}
});
}
{ // Scale
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.scale")));
add(new JLabel("x:"), "split 4");
JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX",UNIT_FOR_SCALES).getSpinnerModel());
JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX", TEXTURE_UNIT).getSpinnerModel());
scaleU.setEditor(new SpinnerEditor(scaleU));
mDefault.addEnableComponent(scaleU, false);
add(scaleU, "w 40");
add(new JLabel("y:"));
JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY",UNIT_FOR_SCALES).getSpinnerModel());
JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY", TEXTURE_UNIT).getSpinnerModel());
scaleV.setEditor(new SpinnerEditor(scaleV));
mDefault.addEnableComponent(scaleV, false);
add(scaleV, "wrap, w 40");
}
{// Placeholder
{// Shine
add(new JLabel(trans.get("AppearanceCfg.lbl.shine")));
IntegerModel shineModel = new IntegerModel(ab, "Shine", 0, 100);
JSpinner spin = new JSpinner(shineModel.getSpinnerModel());
JSlider slide = new JSlider(shineModel.getSliderModel());
mDefault.addEnableComponent(slide, false);
mDefault.addEnableComponent(spin, false);
add(spin, "split 2, w 50");
add(slide, "w 100");
add(slide, "w 50");
}
@ -287,15 +264,13 @@ public class AppearancePanel extends JPanel {
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.offset")));
add(new JLabel("x:"), "split 4");
JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU").getSpinnerModel());
JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU", TEXTURE_UNIT).getSpinnerModel());
offsetU.setEditor(new SpinnerEditor(offsetU));
mDefault.addEnableComponent(offsetU, false);
add(offsetU, "w 40");
add(new JLabel("y:"));
JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV").getSpinnerModel());
JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV", TEXTURE_UNIT).getSpinnerModel());
offsetV.setEditor(new SpinnerEditor(offsetV));
mDefault.addEnableComponent(offsetV, false);
add(offsetV, "wrap, w 40");
}
@ -304,7 +279,6 @@ public class AppearancePanel extends JPanel {
EdgeMode[] list = new EdgeMode[EdgeMode.values().length + 1];
System.arraycopy(EdgeMode.values(), 0, list, 1, EdgeMode.values().length);
JComboBox combo = new JComboBox(new EnumModel<EdgeMode>(ab, "EdgeMode", list));
mDefault.addEnableComponent(combo, false);
add(combo);
}
@ -314,12 +288,10 @@ public class AppearancePanel extends JPanel {
DoubleModel rotationModel = new DoubleModel(ab, "Rotation", UnitGroup.UNITS_ANGLE);
JSpinner rotation = new JSpinner(rotationModel.getSpinnerModel());
rotation.setEditor(new SpinnerEditor(rotation));
mDefault.addEnableComponent(rotation, false);
add(rotation, "split 3, w 50");
add(new UnitSelector(rotationModel));
BasicSlider bs = new BasicSlider(rotationModel.getSliderModel(-Math.PI, Math.PI));
mDefault.addEnableComponent(bs, false);
add(bs, "w 100, wrap");
add(bs, "w 50, wrap");
}

View File

@ -59,7 +59,6 @@ public class RocksimConverter {
try {
StorageOptions opts = new StorageOptions();
opts.setFileType(StorageOptions.FileType.OPENROCKET);
opts.setCompressionEnabled(true);
opts.setSimulationTimeSkip(StorageOptions.SIMULATION_DATA_NONE);
opts.setExplicitlySet(true);