Rework Decal byte handling code and DecalRegistry. Added interface

DecalImage which is used by the Decal object to retrieve the bytes for
the image.  The DecalRegistry now operates as a factory and registry for
DecalImage objects.  The decal handling code in the saver is now greatly
simplified because the logical decal names are updated when constructed
by the DecalRegistry.
This commit is contained in:
kruland2607 2013-01-06 16:58:18 -06:00
parent e4f713196c
commit acba62ce59
42 changed files with 722 additions and 644 deletions

View File

@ -17,29 +17,29 @@ import net.sf.openrocket.util.Coordinate;
*
*/
public class AppearanceBuilder extends AbstractChangeSource {
private Color paint;
private double shine;
private double offsetU, offsetV;
private double centerU, centerV;
private double scaleU, scaleV;
private double rotation;
private String image;
private DecalImage image;
private Decal.EdgeMode edgeMode;
private boolean batch;
public AppearanceBuilder() {
resetToDefaults();
}
public AppearanceBuilder(Appearance a) {
resetToDefaults();
if ( a != null ){
if (a != null) {
setPaint(a.getPaint());
setShine(a.getShine());
Decal d = a.getTexture();
if ( d != null ){
if (d != null) {
setOffset(d.getOffset().x, d.getOffset().y);
setCenter(d.getCenter().x, d.getCenter().y);
setScaleUV(d.getScale().x, d.getScale().y);
@ -49,7 +49,7 @@ public class AppearanceBuilder extends AbstractChangeSource {
}
}
}
public void resetToDefaults() {
paint = new Color(0, 0, 0);
shine = 0;
@ -60,11 +60,11 @@ public class AppearanceBuilder extends AbstractChangeSource {
image = null;
edgeMode = EdgeMode.REPEAT;
}
public Appearance getAppearance() {
Decal t = null;
if (image != null) {
t = new Decal( //
new Coordinate(offsetU, offsetV), //
@ -74,94 +74,94 @@ public class AppearanceBuilder extends AbstractChangeSource {
image, //
edgeMode);
}
return new Appearance( paint, shine, t);
return new Appearance(paint, shine, t);
}
public Color getPaint() {
return paint;
}
public void setPaint(Color paint) {
this.paint = paint;
fireChangeEvent();
}
public double getShine() {
return shine;
}
public void setShine(double shine) {
this.shine = shine;
fireChangeEvent();
}
public double getOffsetU() {
return offsetU;
}
public void setOffsetU(double offsetU) {
this.offsetU = offsetU;
fireChangeEvent();
}
public double getOffsetV() {
return offsetV;
}
public void setOffsetV(double offsetV) {
this.offsetV = offsetV;
fireChangeEvent();
}
public void setOffset(double u, double v) {
setOffsetU(u);
setOffsetV(v);
}
public double getCenterU() {
return centerU;
}
public void setCenterU(double centerU) {
this.centerU = centerU;
fireChangeEvent();
}
public double getCenterV() {
return centerV;
}
public void setCenterV(double centerV) {
this.centerV = centerV;
fireChangeEvent();
}
public void setCenter(double u, double v) {
setCenterU(u);
setCenterV(v);
}
public double getScaleU() {
return scaleU;
}
public void setScaleU(double scaleU) {
this.scaleU = scaleU;
fireChangeEvent();
}
public double getScaleV() {
return scaleV;
}
public void setScaleV(double scaleV) {
this.scaleV = scaleV;
fireChangeEvent();
}
public void setScaleUV(double u, double v) {
setScaleU(u);
setScaleV(v);
@ -170,57 +170,57 @@ public class AppearanceBuilder extends AbstractChangeSource {
public double getScaleX() {
return 1.0 / getScaleU();
}
public void setScaleX(double scaleU) {
setScaleU(1.0 / scaleU);
}
public double getScaleY() {
return 1.0 / getScaleV();
}
public void setScaleY(double scaleV) {
setScaleV(1.0 / scaleV);
}
public double getRotation() {
return rotation;
}
public void setRotation(double rotation) {
this.rotation = rotation;
fireChangeEvent();
}
public String getImage() {
public DecalImage getImage() {
return image;
}
public void setImage(String image) {
public void setImage(DecalImage image) {
this.image = image;
fireChangeEvent();
}
public Decal.EdgeMode getEdgeMode() {
return edgeMode;
}
public void setEdgeMode(Decal.EdgeMode edgeMode) {
this.edgeMode = edgeMode;
fireChangeEvent();
}
@Override
protected void fireChangeEvent() {
if ( !batch )
if (!batch)
super.fireChangeEvent();
}
public void batch(Runnable r){
public void batch(Runnable r) {
batch = true;
r.run();
batch = false;
fireChangeEvent();
}
}

View File

@ -24,11 +24,11 @@ public class Decal {
private final Coordinate offset, center, scale;
private final double rotation;
private final String image;
private final DecalImage image;
private final EdgeMode mode;
Decal(final Coordinate offset, final Coordinate center, final Coordinate scale, final double rotation,
final String image, final EdgeMode mode) {
final DecalImage image, final EdgeMode mode) {
this.offset = offset;
this.center = center;
this.scale = scale;
@ -57,7 +57,7 @@ public class Decal {
return mode;
}
public String getImage() {
public DecalImage getImage() {
return image;
}

View File

@ -0,0 +1,14 @@
package net.sf.openrocket.appearance;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
public interface DecalImage {
public String getName();
public InputStream getBytes() throws FileNotFoundException, IOException;
public void exportImage( File file, boolean watchForChanges ) throws IOException;
}

View File

@ -9,11 +9,18 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.sf.openrocket.appearance.DecalImage;
import net.sf.openrocket.file.FileInfo;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.startup.Application;
@ -26,7 +33,7 @@ public class DecalRegistry {
private FileInfo fileInfo;
private boolean isZipFile = false;
private Map<String,File> exportedDecalMap = new HashMap<String,File>();
private Map<String,DecalImageImpl> registeredDecals = new HashMap<String,DecalImageImpl>();
public void setBaseFile(FileInfo fileInfo) {
this.fileInfo = fileInfo;
@ -36,6 +43,107 @@ public class DecalRegistry {
this.isZipFile = isZipFile;
}
public DecalImage getDecalImage( String decalName ) {
DecalImageImpl d = registeredDecals.get(decalName);
if ( d == null ) {
d = new DecalImageImpl(decalName);
registeredDecals.put(decalName, d);
}
return d;
}
public DecalImage getDecalImage( File file ) {
// See if this file is being used already
DecalImageImpl decal = findDecalForFile( file );
if ( decal != null ) {
return decal;
}
// It's a new file, generate a name for it.
String decalName = makeUniqueName( file.getName() );
decal = new DecalImageImpl( decalName );
decal.setFileSystemLocation( file );
registeredDecals.put(decalName, decal);
return decal;
}
public Set<DecalImage> getDecalList( ) {
Set<DecalImage> decals = new TreeSet<DecalImage>();
decals.addAll(registeredDecals.values());
return decals;
}
public Set<DecalImage> getExportableDecalsList() {
Set<DecalImage> exportableDecals = new HashSet<DecalImage>();
for( DecalImage d : registeredDecals.values() ) {
if ( isExportable(d.getName())) {
exportableDecals.add(d);
}
}
return exportableDecals;
}
public class DecalImageImpl implements DecalImage, Comparable {
private final String name;
private File fileSystemLocation;
private DecalImageImpl( String name ) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public InputStream getBytes() throws FileNotFoundException, IOException {
return DecalRegistry.this.getDecal(this);
}
@Override
public void exportImage(File file, boolean watchForChanges) throws IOException {
this.fileSystemLocation = file;
DecalRegistry.this.exportDecal(this, file);
}
File getFileSystemLocation() {
return fileSystemLocation;
}
void setFileSystemLocation( File fileSystemLocation ) {
this.fileSystemLocation = fileSystemLocation;
}
@Override
public String toString() {
return name;
}
@Override
public int compareTo(Object o) {
if ( ! (o instanceof DecalImageImpl ) ) {
return -1;
}
return this.name.compareTo( ((DecalImageImpl)o).name );
}
}
/**
* Returns true if the named decal is exportable - that is, it is currently stored in
* the zip file.
@ -43,7 +151,7 @@ public class DecalRegistry {
* @param name
* @return
*/
public boolean isExportable( String name ) {
private boolean isExportable( String name ) {
if ( !isZipFile ) {
return false;
}
@ -69,48 +177,29 @@ public class DecalRegistry {
* @throws FileNotFoundException
* @throws IOException
*/
public InputStream getDecal( String name ) throws FileNotFoundException, IOException {
private InputStream getDecal( DecalImageImpl decal ) throws FileNotFoundException, IOException {
// This is the InputStream to be returned.
InputStream rawIs = null;
// First check if the decal had been exported
{
File exportedFile= exportedDecalMap.get(name);
if ( exportedFile != null ) {
try {
rawIs = new FileInputStream(exportedFile);
} catch (FileNotFoundException ex) {
// If we can no longer find the file, we'll try to resort to using a different loading
// strategy.
exportedDecalMap.remove(name);
}
}
// First check if the decal is located on the file system
File exportedFile= decal.getFileSystemLocation();
if ( exportedFile != null ) {
rawIs = new FileInputStream(exportedFile);
}
String name = decal.getName();
if ( rawIs == null && isZipFile ) {
rawIs = findInZipContainer(name);
}
// Check absolute file name:
// Try relative to the model file directory. This is so we can support unzipped container format.
if ( rawIs == null ) {
File decal = new File(name);
if ( decal.isAbsolute() ) {
try {
rawIs = new FileInputStream(decal);
} catch ( FileNotFoundException e ){
name = decal.getName();
log.debug("Unable to find absolute file" + decal + ", falling back to " + name);
}
}
}
// Try relative to the model file directory.
if ( rawIs == null ) {
if( fileInfo.getDirectory() != null ) {
File decal = new File(fileInfo.getDirectory(), name);
rawIs = new FileInputStream(decal);
if( fileInfo != null && fileInfo.getDirectory() != null ) {
File decalFile = new File(fileInfo.getDirectory(), name);
rawIs = new FileInputStream(decalFile);
}
}
@ -128,10 +217,10 @@ public class DecalRegistry {
}
public void exportDecal( String decalName, File selectedFile ) throws IOException {
private void exportDecal( DecalImageImpl decal, File selectedFile ) throws IOException {
try {
InputStream is = getDecal(decalName);
InputStream is = decal.getBytes();
OutputStream os = new BufferedOutputStream( new FileOutputStream(selectedFile));
FileUtils.copy(is, os);
@ -139,15 +228,11 @@ public class DecalRegistry {
is.close();
os.close();
exportedDecalMap.put(decalName, selectedFile );
}
catch (IOException iex) {
throw new BugException(iex);
}
}
@ -178,4 +263,84 @@ public class DecalRegistry {
return null;
}
}
private DecalImageImpl findDecalForFile( File file ) {
for( DecalImageImpl d : registeredDecals.values() ) {
if ( file.equals( d.getFileSystemLocation() ) ) {
return d;
}
}
return null;
}
/**
* Regular expression for parsing file names with numerical identifiers.
* For examples:
*
* decals/an image (3).png
*
* group(0) = "decals/an image (3).png"
* group(1) = "decals/an image"
* group(2) = " (3)"
* group(3) = "3"
* group(4) = "png"
*
* decals/an image.png
*
* group(0) = "decals/an image.png"
* group(1) = "decals/an image"
* group(2) = "null"
* group(3) = "null"
* group(4) = "png"
*/
private static final Pattern fileNamePattern = Pattern.compile("(.*?)( \\((\\d+)\\)\\)?+)?\\.(\\w*)");
private static final int BASE_NAME_INDEX = 1;
private static final int NUMBER_INDEX = 3;
private static final int EXTENSION_INDEX = 4;
private String makeUniqueName( String name ) {
String newName = "decals/" + name;
String basename = "";
String extension = "";
Matcher nameMatcher = fileNamePattern.matcher(newName);
if ( nameMatcher.matches() ) {
basename = nameMatcher.group(BASE_NAME_INDEX);
extension = nameMatcher.group(EXTENSION_INDEX);
}
Set<Integer> counts = new TreeSet<Integer>();
boolean needsRewrite = false;
for ( DecalImageImpl d: registeredDecals.values() ) {
Matcher m = fileNamePattern.matcher( d.getName() );
if ( m.matches() ) {
if ( basename.equals(m.group(BASE_NAME_INDEX)) && extension.equals(m.group(EXTENSION_INDEX))) {
String intString = m.group(NUMBER_INDEX);
if ( intString != null ) {
Integer i = Integer.parseInt(intString);
counts.add(i);
}
needsRewrite = true;
}
} else if ( newName.equals(d.getName() ) ) {
needsRewrite = true;
}
}
if ( !needsRewrite ) {
return newName;
}
// find a missing integer;
Integer newIndex = 1;
while( counts.contains(newIndex) ) {
newIndex++;
}
return MessageFormat.format("{0} ({1}).{2}", basename,newIndex,extension);
}
}

View File

@ -178,38 +178,10 @@ public class OpenRocketDocument implements ComponentChangeListener {
return configuration;
}
public DecalRegistry getDecalRegistry() {
return decalRegistry;
}
public void setDecalRegistry(DecalRegistry decalRegistry) {
this.decalRegistry = decalRegistry;
}
public Set<String> getDecalList( ) {
Set<String> decals = new TreeSet<String>();
// Look for all decals used in the rocket.
for( RocketComponent c : this.getRocket() ) {
if ( c.getAppearance() == null ) {
continue;
}
Appearance ap = c.getAppearance();
if ( ap.getTexture() == null ) {
continue;
}
Decal decal = ap.getTexture();
String decalName = decal.getImage();
decals.add(decalName);
}
return decals;
}
public File getFile() {
return file;
}

View File

@ -7,15 +7,14 @@ import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.AppearanceBuilder;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.appearance.DecalImage;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.StorageOptions;
import net.sf.openrocket.document.StorageOptions.FileType;
@ -156,117 +155,27 @@ public class GeneralRocketSaver {
return;
}
// grab the set of decal images. We do this up front
// so we can fail early if some resource is missing.
// decalNameNormalization maps the current decal file name
// to the name used in the zip file.
Map<String,String> decalNameNormalization = new HashMap<String,String>();
// decals maintains a mapping from decal file name to an input stream.
Map<String,InputStream> decals = new HashMap<String,InputStream>();
// try block to close streams held in decals if something goes wrong.
try {
// Look for all decals used in the rocket.
for( RocketComponent c : document.getRocket() ) {
if ( c.getAppearance() == null ) {
continue;
}
Appearance ap = c.getAppearance();
if ( ap.getTexture() == null ) {
continue;
}
Decal decal = ap.getTexture();
String decalName = decal.getImage();
// If the decal name is already in the decals map, we've already
// seen it attached to another component.
if ( decals.containsKey(decalName) ) {
continue;
}
// Use the DecalRegistry to get the input stream.
InputStream is = document.getDecalRegistry().getDecal(decalName);
// Add it to the decals map.
decals.put(decalName, is);
// Normalize the name:
File fname = new File(decalName);
String newName = "decals/" + fname.getName();
// If the normalized name is already used, it represents a different
// decal name. We need to change the name slightly to find one which works.
if ( decalNameNormalization.values().contains(newName) ) {
// We'll append integers to the names until we get something which works.
// so if newName is "decals/foo.jpg", we will try "decals/foo (1).jpg"
// "decals/foo (2).jpg", etc.
String newNameTemplate = buildFilenameTemplate(newName);
int i=1;
while( true ) {
newName = MessageFormat.format(newNameTemplate, i);
if ( ! decalNameNormalization.values().contains(newName) ) {
break;
}
i++;
}
}
decalNameNormalization.put(decalName, newName);
}
}
catch (IOException ex) {
for ( InputStream is: decals.values() ) {
try {
is.close();
}
catch ( Throwable t ) {
}
}
throw ex;
}
// Now we have to loop through all the components and update their names.
Set<DecalImage> usedDecals = new TreeSet<DecalImage>();
// 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() ) {
// Look for all decals used in the rocket.
for( RocketComponent c : document.getRocket() ) {
if ( c.getAppearance() == null ) {
continue;
}
Appearance ap = c.getAppearance();
if ( ap.getTexture() == null ) {
continue;
}
AppearanceBuilder builder = new AppearanceBuilder(ap);
Decal decal = ap.getTexture();
builder.setImage( decalNameNormalization.get(ap.getTexture().getImage()));
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());
usedDecals.add(decal.getImage());
}
saveAllPartsZipFile(fileName, output, rocketDocCopy, options, decalMap);
saveAllPartsZipFile(fileName, output, document, options, usedDecals);
}
public void saveAllPartsZipFile(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options, Map<String,InputStream> decals) throws IOException {
public void saveAllPartsZipFile(String fileName, OutputStream output, OpenRocketDocument document, StorageOptions options, Set<DecalImage> decals) throws IOException {
// Open a zip stream to write to.
ZipOutputStream zos = new ZipOutputStream(output);
@ -282,13 +191,13 @@ public class GeneralRocketSaver {
// Now we write out all the decal images files.
for( Map.Entry<String, InputStream> image : decals.entrySet() ) {
for( DecalImage image : decals ) {
String name = image.getKey();
String name = image.getName();
ZipEntry decal = new ZipEntry(name);
zos.putNextEntry(decal);
InputStream is = image.getValue();
InputStream is = image.getBytes();
int bytesRead = 0;
byte[] buffer = new byte[2048];
while( (bytesRead = is.read(buffer)) > 0 ) {
@ -306,21 +215,6 @@ public class GeneralRocketSaver {
}
// package scope for testing.
static String buildFilenameTemplate( String fileName ) {
// We're going to use MessageTemplate for this. If we don't have a dot
// just append "(5)"
String nameTemplate = fileName + " ({0})";
// split up the newName. Look for extension.
int lastDot = fileName.lastIndexOf('.');
if ( lastDot > 0 ) {
String firstPart = fileName.substring(0, lastDot );
String lastPart = fileName.substring(lastDot);
nameTemplate = firstPart + " ({0})" + lastPart;
}
return nameTemplate;
}
private void saveInternal(OutputStream output, OpenRocketDocument document, StorageOptions options)
throws IOException {

View File

@ -20,16 +20,18 @@ class AppearanceHandler extends AbstractElementHandler {
private final AppearanceBuilder builder = new AppearanceBuilder();
private boolean isInDecal = false;
public AppearanceHandler( RocketComponent component, DocumentLoadingContext context ) {
public AppearanceHandler(RocketComponent component, DocumentLoadingContext context) {
this.context = context;
this.component = component;
}
@Override
public ElementHandler openElement(String element,HashMap<String, String> attributes, WarningSet warnings)
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
throws SAXException {
if ( "decal".equals(element) ) {
if ("decal".equals(element)) {
String name = attributes.remove("name");
builder.setImage(name);
builder.setImage(context.getOpenRocketDocument().getDecalRegistry().getDecalImage(name));
double rotation = Double.parseDouble(attributes.remove("rotation"));
builder.setRotation(rotation);
String edgeModeName = attributes.remove("edgemode");
@ -40,39 +42,40 @@ class AppearanceHandler extends AbstractElementHandler {
}
return PlainTextHandler.INSTANCE;
}
@Override
public void closeElement(String element,HashMap<String, String> attributes, String content, WarningSet warnings) throws SAXException {
if ( "paint".equals(element) ) {
public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings) throws SAXException {
if ("paint".equals(element)) {
int red = Integer.parseInt(attributes.get("red"));
int green = Integer.parseInt(attributes.get("green"));
int blue = Integer.parseInt(attributes.get("blue"));
builder.setPaint( new Color(red,green,blue));
builder.setPaint(new Color(red, green, blue));
return;
}
if ( "shine".equals(element) ){
if ("shine".equals(element)) {
double shine = Double.parseDouble(content);
builder.setShine(shine);
return;
}
if ( isInDecal && "center".equals(element) ) {
if (isInDecal && "center".equals(element)) {
double x = Double.parseDouble(attributes.get("x"));
double y = Double.parseDouble(attributes.get("y"));
builder.setCenter(x,y);
builder.setCenter(x, y);
return;
}
if ( isInDecal && "offset".equals(element) ) {
if (isInDecal && "offset".equals(element)) {
double x = Double.parseDouble(attributes.get("x"));
double y = Double.parseDouble(attributes.get("y"));
builder.setOffset(x,y);
builder.setOffset(x, y);
return;
}
if ( isInDecal && "scale".equals(element) ) {
if (isInDecal && "scale".equals(element)) {
double x = Double.parseDouble(attributes.get("x"));
double y = Double.parseDouble(attributes.get("y"));
builder.setScaleUV(x,y);
builder.setScaleUV(x, y);
return;
}
if( isInDecal && "decal".equals(element) ) {
if (isInDecal && "decal".equals(element)) {
isInDecal = false;
return;
}
@ -83,7 +86,7 @@ class AppearanceHandler extends AbstractElementHandler {
@Override
public void endHandler(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
if ( "decal".equals(element) ) {
if ("decal".equals(element)) {
isInDecal = false;
return;
}

View File

@ -1,12 +1,13 @@
package net.sf.openrocket.file.openrocket.importt;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.MotorFinder;
public class DocumentLoadingContext {
private int fileVersion;
private MotorFinder motorFinder;
private OpenRocketDocument document;
public int getFileVersion() {
return fileVersion;
@ -23,5 +24,13 @@ public class DocumentLoadingContext {
public void setMotorFinder(MotorFinder motorFinder) {
this.motorFinder = motorFinder;
}
public OpenRocketDocument getOpenRocketDocument() {
return document;
}
public void setOpenRocketDocument(OpenRocketDocument document) {
this.document = document;
}
}

View File

@ -25,6 +25,7 @@ class OpenRocketContentHandler extends AbstractElementHandler {
this.context = context;
this.rocket = new Rocket();
this.doc = new OpenRocketDocument(rocket);
context.setOpenRocketDocument(doc);
}
public OpenRocketDocument getDocument() {

View File

@ -27,65 +27,65 @@ import net.sf.openrocket.util.LineStyle;
public class RocketComponentSaver {
private static final Translator trans = Application.getTranslator();
protected RocketComponentSaver() {
// Prevent instantiation from outside the package
}
protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List<String> elements) {
elements.add("<name>" + RocketSaver.escapeXML(c.getName()) + "</name>");
ComponentPreset preset = c.getPresetComponent();
if (preset != null) {
elements.add("<preset type=\"" + preset.getType() +
"\" manufacturer=\"" + preset.getManufacturer().getSimpleName() +
"\" partno=\"" + preset.getPartNo() + "\" digest=\"" + preset.getDigest() + "\"/>");
}
Appearance ap = c.getAppearance();
if ( ap != null ) {
if (ap != null) {
elements.add("<appearance>");
Color paint = ap.getPaint();
emitColor("paint",elements,paint);
emitColor("paint", elements, paint);
elements.add("<shine>" + ap.getShine() + "</shine>");
Decal decal = ap.getTexture();
if ( decal != null ) {
String name = decal.getImage();
if (decal != null) {
String name = decal.getImage().getName();
double rotation = decal.getRotation();
EdgeMode edgeMode = decal.getEdgeMode();
elements.add("<decal name=\""+name+"\" rotation=\""+rotation+"\" edgemode=\""+ edgeMode.name()+"\">");
elements.add("<decal name=\"" + name + "\" rotation=\"" + rotation + "\" edgemode=\"" + edgeMode.name() + "\">");
Coordinate center = decal.getCenter();
elements.add("<center x=\""+center.x+"\" y=\""+center.y+"\"/>");
elements.add("<center x=\"" + center.x + "\" y=\"" + center.y + "\"/>");
Coordinate offset = decal.getOffset();
elements.add("<offset x=\""+offset.x+"\" y=\""+offset.y+"\"/>");
elements.add("<offset x=\"" + offset.x + "\" y=\"" + offset.y + "\"/>");
Coordinate scale = decal.getScale();
elements.add("<scale x=\""+scale.x+"\" y=\""+scale.y+"\"/>");
elements.add("<scale x=\"" + scale.x + "\" y=\"" + scale.y + "\"/>");
elements.add("</decal>");
}
elements.add("</appearance>");
}
// Save color and line style if significant
if (!(c instanceof Rocket || c instanceof ComponentAssembly)) {
Color color = c.getColor();
emitColor("color", elements, color);
LineStyle style = c.getLineStyle();
if (style != null) {
// Type names currently equivalent to the enum names except for case.
elements.add("<linestyle>" + style.name().toLowerCase(Locale.ENGLISH) + "</linestyle>");
}
}
// Save position unless "AFTER"
if (c.getRelativePosition() != RocketComponent.Position.AFTER) {
// The type names are currently equivalent to the enum names except for case.
String type = c.getRelativePosition().name().toLowerCase(Locale.ENGLISH);
elements.add("<position type=\"" + type + "\">" + c.getPositionValue() + "</position>");
}
// Overrides
boolean overridden = false;
if (c.isMassOverridden()) {
@ -100,26 +100,26 @@ public class RocketComponentSaver {
elements.add("<overridesubcomponents>" + c.getOverrideSubcomponents()
+ "</overridesubcomponents>");
}
// Comment
if (c.getComment().length() > 0) {
elements.add("<comment>" + RocketSaver.escapeXML(c.getComment()) + "</comment>");
}
}
protected final String materialParam(Material mat) {
return materialParam("material", mat);
}
protected final String materialParam(String tag, Material mat) {
String str = "<" + tag;
switch (mat.getType()) {
case LINE:
str += " type=\"line\"";
@ -133,31 +133,31 @@ public class RocketComponentSaver {
default:
throw new BugException("Unknown material type: " + mat.getType());
}
String baseName = trans.getBaseText("material", mat.getName());
return str + " density=\"" + mat.getDensity() + "\">" + RocketSaver.escapeXML(baseName) + "</" + tag + ">";
}
protected final List<String> motorMountParams(MotorMount mount) {
if (!mount.isMotorMount())
return Collections.emptyList();
String[] motorConfigIDs = ((RocketComponent) mount).getRocket().getFlightConfigurationIDs();
List<String> elements = new ArrayList<String>();
elements.add("<motormount>");
for (String id : motorConfigIDs) {
MotorConfiguration motorConfig = mount.getFlightConfiguration(id);
if ( motorConfig == null ) {
if (motorConfig == null) {
continue;
}
Motor motor = motorConfig.getMotor();
// Nothing is stored if no motor loaded
if (motor == null)
continue;
elements.add(" <motor configid=\"" + id + "\">");
if (motor.getMotorType() != Motor.Type.UNKNOWN) {
elements.add(" <type>" + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + "</type>");
@ -171,7 +171,7 @@ public class RocketComponentSaver {
elements.add(" <designation>" + RocketSaver.escapeXML(motor.getDesignation()) + "</designation>");
elements.add(" <diameter>" + motor.getDiameter() + "</diameter>");
elements.add(" <length>" + motor.getLength() + "</length>");
// Motor delay
if (motorConfig.getEjectionDelay() == Motor.PLUGGED) {
elements.add(" <delay>none</delay>");
@ -179,33 +179,33 @@ public class RocketComponentSaver {
elements.add(" <delay>" + motorConfig.getEjectionDelay() + "</delay>");
}
if ( motorConfig.getIgnitionEvent() != null ) {
if (motorConfig.getIgnitionEvent() != null) {
elements.add(" <ignitionevent>" + motorConfig.getIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + "</ignitionevent>");
}
if ( motorConfig.getIgnitionDelay() != null ) {
if (motorConfig.getIgnitionDelay() != null) {
elements.add(" <ignitiondelay>" + motorConfig.getIgnitionDelay() + "</ignitiondelay>");
}
elements.add(" </motor>");
}
elements.add(" <ignitionevent>"
+ mount.getDefaultIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
+ "</ignitionevent>");
elements.add(" <ignitiondelay>" + mount.getDefaultIgnitionDelay() + "</ignitiondelay>");
elements.add(" <overhang>" + mount.getMotorOverhang() + "</overhang>");
elements.add("</motormount>");
return elements;
}
private final static void emitColor( String elementName, List<String> elements, Color color ) {
private final static void emitColor(String elementName, List<String> elements, Color color) {
if (color != null) {
elements.add("<" + elementName+ " red=\"" + color.getRed() + "\" green=\"" + color.getGreen()
elements.add("<" + elementName + " red=\"" + color.getRed() + "\" green=\"" + color.getGreen()
+ "\" blue=\"" + color.getBlue() + "\"/>");
}
}
}

View File

@ -3,18 +3,21 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import java.util.HashMap;
/**
* A SAX handler for the Rocksim AttachedParts XML type.
*/
class AttachedPartsHandler extends AbstractElementHandler {
private final OpenRocketDocument document;
/** The parent component. */
private final RocketComponent component;
@ -25,41 +28,42 @@ class AttachedPartsHandler extends AbstractElementHandler {
*
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public AttachedPartsHandler(RocketComponent c) throws IllegalArgumentException {
public AttachedPartsHandler(OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
if (c == null) {
throw new IllegalArgumentException("The parent component of any attached part may not be null.");
}
this.document = document;
component = c;
}
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
if (RocksimCommonConstants.FIN_SET.equals(element)) {
return new FinSetHandler(component);
return new FinSetHandler(document, component);
}
if (RocksimCommonConstants.CUSTOM_FIN_SET.equals(element)) {
return new FinSetHandler(component);
return new FinSetHandler(document, component);
}
if (RocksimCommonConstants.LAUNCH_LUG.equals(element)) {
return new LaunchLugHandler(component, warnings);
return new LaunchLugHandler(document, component, warnings);
}
if (RocksimCommonConstants.PARACHUTE.equals(element)) {
return new ParachuteHandler(component, warnings);
return new ParachuteHandler(document, component, warnings);
}
if (RocksimCommonConstants.STREAMER.equals(element)) {
return new StreamerHandler(component, warnings);
return new StreamerHandler(document, component, warnings);
}
if (RocksimCommonConstants.MASS_OBJECT.equals(element)) {
return new MassObjectHandler(component, warnings);
return new MassObjectHandler(document, component, warnings);
}
if (RocksimCommonConstants.RING.equals(element)) {
return new RingHandler(component, warnings);
return new RingHandler(document, component, warnings);
}
if (RocksimCommonConstants.BODY_TUBE.equals(element)) {
return new InnerBodyTubeHandler(component, warnings);
return new InnerBodyTubeHandler(document, component, warnings);
}
if (RocksimCommonConstants.TRANSITION.equals(element)) {
return new TransitionHandler(component, warnings);
return new TransitionHandler(document, component, warnings);
}
if (RocksimCommonConstants.TUBE_FIN_SET.equals(element)) {
warnings.add("Tube fins are not currently supported. Ignoring.");

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.database.Databases;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimDensityType;
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
@ -52,8 +53,14 @@ public abstract class BaseHandler<C extends RocketComponent> extends AbstractEle
*/
private String materialName = "";
private RockSimAppearanceBuilder appearanceBuilder = new RockSimAppearanceBuilder();
protected final OpenRocketDocument document;
private final RockSimAppearanceBuilder appearanceBuilder;
public BaseHandler( OpenRocketDocument document ) {
this.document = document;
appearanceBuilder = new RockSimAppearanceBuilder( document );
}
/**
* The SAX method called when the closing element tag is reached.
*
@ -293,7 +300,7 @@ public abstract class BaseHandler<C extends RocketComponent> extends AbstractEle
*
* @return the Method instance, or null
*/
private static Method getMethod(RocketComponent component, String name, Class<?>[] args) {
private static Method getMethod(RocketComponent component, String name, Class[] args) {
Method method = null;
try {
method = component.getClass().getMethod(name, args);

View File

@ -3,7 +3,10 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
import net.sf.openrocket.file.simplesax.ElementHandler;
@ -11,9 +14,8 @@ import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* A SAX handler for Rocksim Body Tubes.
@ -31,7 +33,8 @@ class BodyTubeHandler extends BaseHandler<BodyTube> {
* @param warnings the warning set
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public BodyTubeHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
public BodyTubeHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent component of a body tube may not be null.");
}
@ -44,7 +47,7 @@ class BodyTubeHandler extends BaseHandler<BodyTube> {
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
return new AttachedPartsHandler(bodyTube);
return new AttachedPartsHandler(document, bodyTube);
}
return PlainTextHandler.INSTANCE;
}
@ -98,7 +101,6 @@ class BodyTubeHandler extends BaseHandler<BodyTube> {
*
* @return BULK
*/
@Override
public Material.Type getMaterialType() {
return Material.Type.BULK;
}

View File

@ -3,7 +3,13 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
import net.sf.openrocket.file.rocksim.RocksimLocationMode;
@ -19,12 +25,8 @@ import net.sf.openrocket.rocketcomponent.IllegalFinPointException;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
import net.sf.openrocket.util.Coordinate;
import org.xml.sax.SAXException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.xml.sax.SAXException;
/**
* A SAX handler for Rocksim fin sets. Because the type of fin may not be known first (in Rocksim file format, the fin
@ -69,8 +71,7 @@ class FinSetHandler extends AbstractElementHandler {
/**
* The length of the mid-chord (aka height).
*/
@SuppressWarnings("unused")
private double midChordLen = 0.0d;
private double midChordLen = 0.0d;
/**
* The distance of the leading edge from root to top.
*/
@ -140,9 +141,8 @@ class FinSetHandler extends AbstractElementHandler {
*/
private Double calcCg = 0d;
private RockSimAppearanceBuilder appearanceBuilder = new RockSimAppearanceBuilder();
private final RockSimAppearanceBuilder appearanceBuilder;
/**
* Constructor.
*
@ -150,10 +150,11 @@ class FinSetHandler extends AbstractElementHandler {
*
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public FinSetHandler (RocketComponent c) throws IllegalArgumentException {
public FinSetHandler (OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
if (c == null) {
throw new IllegalArgumentException("The parent component of a fin set may not be null.");
}
appearanceBuilder = new RockSimAppearanceBuilder( document );
component = c;
}
@ -330,16 +331,16 @@ class FinSetHandler extends AbstractElementHandler {
/**
* Convert a Rocksim string that represents fin plan points into an array of OpenRocket coordinates.
*
* @param myPointList a comma and pipe delimited string of X,Y coordinates from Rocksim. This is of the format:
* @param pointList a comma and pipe delimited string of X,Y coordinates from Rocksim. This is of the format:
* <pre>x0,y0|x1,y1|x2,y2|... </pre>
* @param warnings the warning set to convey incompatibilities to the user
*
* @return an array of OpenRocket Coordinates
*/
private Coordinate[] toCoordinates (String myPointList, WarningSet warnings) {
private Coordinate[] toCoordinates (String pointList, WarningSet warnings) {
List<Coordinate> result = new ArrayList<Coordinate>();
if (myPointList != null && myPointList.length() > 0) {
String[] points = myPointList.split("\\Q|\\E");
if (pointList != null && pointList.length() > 0) {
String[] points = pointList.split("\\Q|\\E");
for (String point : points) {
String[] aPoint = point.split(",");
try {

View File

@ -3,16 +3,18 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* A SAX handler for Rocksim inside tubes.
@ -31,8 +33,9 @@ class InnerBodyTubeHandler extends PositionDependentHandler<InnerTube> {
* @param warnings the warning set
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public InnerBodyTubeHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
if (c == null) {
public InnerBodyTubeHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent component of an inner tube may not be null.");
}
bodyTube = new InnerTube();
@ -44,7 +47,7 @@ class InnerBodyTubeHandler extends PositionDependentHandler<InnerTube> {
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
return new AttachedPartsHandler(bodyTube);
return new AttachedPartsHandler(document, bodyTube);
}
return PlainTextHandler.INSTANCE;
}

View File

@ -3,7 +3,10 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
import net.sf.openrocket.file.simplesax.ElementHandler;
@ -11,9 +14,8 @@ import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* The SAX handler for Rocksim Launch Lugs.
@ -33,7 +35,8 @@ class LaunchLugHandler extends PositionDependentHandler<LaunchLug> {
*
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public LaunchLugHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
public LaunchLugHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent component of a launch lug may not be null.");
}

View File

@ -3,7 +3,10 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimDensityType;
import net.sf.openrocket.file.simplesax.ElementHandler;
@ -14,9 +17,8 @@ import net.sf.openrocket.rocketcomponent.MassComponent;
import net.sf.openrocket.rocketcomponent.MassObject;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.ShockCord;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* A SAX handler for Rocksim's MassObject XML type.
@ -60,7 +62,8 @@ class MassObjectHandler extends PositionDependentHandler<MassObject> {
*
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public MassObjectHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
public MassObjectHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent component of a mass component may not be null.");
}
@ -187,7 +190,6 @@ class MassObjectHandler extends PositionDependentHandler<MassObject> {
*
* @param position the OpenRocket position
*/
@Override
public void setRelativePosition(RocketComponent.Position position) {
current.setRelativePosition(position);
}

View File

@ -3,7 +3,10 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
import net.sf.openrocket.file.rocksim.RocksimNoseConeCode;
@ -13,9 +16,8 @@ import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.NoseCone;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Transition;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* The SAX nose cone handler for Rocksim NoseCones.
@ -40,7 +42,8 @@ class NoseConeHandler extends BaseHandler<NoseCone> {
*
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public NoseConeHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
public NoseConeHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent component of a nose cone may not be null.");
}
@ -54,7 +57,7 @@ class NoseConeHandler extends BaseHandler<NoseCone> {
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
//Nose cones in Rocksim may have attached parts - namely Mass Objects - as children.
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
return new AttachedPartsHandler(noseCone);
return new AttachedPartsHandler(document, noseCone);
}
return PlainTextHandler.INSTANCE;
}
@ -147,7 +150,6 @@ class NoseConeHandler extends BaseHandler<NoseCone> {
*
* @return BULK
*/
@Override
public Material.Type getMaterialType() {
return Material.Type.BULK;
}

View File

@ -3,7 +3,10 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.file.simplesax.PlainTextHandler;
@ -12,9 +15,8 @@ import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.Parachute;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* A SAX handler for Rocksim's Parachute XML type.
@ -37,7 +39,8 @@ class ParachuteHandler extends RecoveryDeviceHandler<Parachute> {
*
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public ParachuteHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
public ParachuteHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent of a parachute may not be null.");
}
@ -87,8 +90,7 @@ class ParachuteHandler extends RecoveryDeviceHandler<Parachute> {
}
if (RocksimCommonConstants.SPILL_HOLE_DIA.equals(element)) {
//Not supported in OpenRocket
@SuppressWarnings("unused")
double spillHoleRadius = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS;
double spillHoleRadius = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS;
warnings.add("Parachute spill holes are not supported. Ignoring.");
}
if (RocksimCommonConstants.SHROUD_LINE_MASS_PER_MM.equals(element)) {
@ -114,7 +116,6 @@ class ParachuteHandler extends RecoveryDeviceHandler<Parachute> {
*
* @return a component
*/
@Override
public Parachute getComponent() {
return chute;
}

View File

@ -3,13 +3,15 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimLocationMode;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* An abstract base class that handles position dependencies for all lower level components that
@ -25,6 +27,9 @@ public abstract class PositionDependentHandler<C extends RocketComponent> extend
/** Temporary position. */
private RocketComponent.Position position = RocketComponent.Position.TOP;
public PositionDependentHandler( OpenRocketDocument document ) {
super(document);
}
/**
* {@inheritDoc}
*/

View File

@ -3,15 +3,17 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimDensityType;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* A handler specific to streamers and parachutes. This is done because Rocksim allows any type of material to be
@ -31,6 +33,10 @@ public abstract class RecoveryDeviceHandler<C extends RecoveryDevice> extends Po
*/
private Double calcMass = 0d;
public RecoveryDeviceHandler( OpenRocketDocument document ) {
super(document);
}
/**
* {@inheritDoc}
*/
@ -61,7 +67,6 @@ public abstract class RecoveryDeviceHandler<C extends RecoveryDevice> extends Po
* @param rawDensity the density as specified in the Rocksim design file
* @return a value in OpenRocket SURFACE density units
*/
@Override
protected double computeDensity(RocksimDensityType type, double rawDensity) {
double result;

View File

@ -3,7 +3,10 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.file.simplesax.PlainTextHandler;
@ -14,9 +17,8 @@ import net.sf.openrocket.rocketcomponent.EngineBlock;
import net.sf.openrocket.rocketcomponent.RingComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.TubeCoupler;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* A SAX handler for centering rings, tube couplers, and bulkheads.
@ -45,7 +47,8 @@ class RingHandler extends PositionDependentHandler<CenteringRing> {
* @param warnings the warning set
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public RingHandler(RocketComponent theParent, WarningSet warnings) throws IllegalArgumentException {
public RingHandler(OpenRocketDocument document, RocketComponent theParent, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (theParent == null) {
throw new IllegalArgumentException("The parent of a ring may not be null.");
}

View File

@ -7,15 +7,21 @@ import java.net.MalformedURLException;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.appearance.AppearanceBuilder;
import net.sf.openrocket.appearance.Decal.EdgeMode;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.util.Color;
public class RockSimAppearanceBuilder extends AppearanceBuilder {
boolean preventSeam = false;
boolean repeat = false;
private final OpenRocketDocument document;
public RockSimAppearanceBuilder(OpenRocketDocument document) {
this.document = document;
}
public void processElement(String element, String content, WarningSet warnings) {
try {
if (RocksimCommonConstants.TEXTURE.equals(element)) {
@ -32,37 +38,37 @@ public class RockSimAppearanceBuilder extends AppearanceBuilder {
//ignored
} else if ("SpecularColor".equals(element)) {
//Ignored
} else if ("UseSingleColor".equals(element) || "SimpleColorModel".equals(element) ) {
} else if ("UseSingleColor".equals(element) || "SimpleColorModel".equals(element)) {
//Ignored
}
} catch (Exception e) {
warnings.add("Could not convert " + element + " value of " + content + ": " + e.getMessage());
}
}
private void parseTexture(String s) throws FileNotFoundException, MalformedURLException {
final String[] parts = s.trim().split("\\|");
boolean interpolate = false;
boolean flipr = false;
boolean flips = false;
boolean flipt = false;
for (String part : parts) {
// Sometimes it is name=(value) and sometimes name(value)
final String name = part.substring(0, part.indexOf("(")).replace("=", "");
final String value = part.substring(part.indexOf("(") + 1, part.length() - 1);
if ("file".equals(name)) {
if (value.length() > 0){
if (value.length() > 0) {
final File f = new File(value);
if (!f.exists()) {
//Find out how to get path of current rocksim file
//so I can look in it's directory
}
setImage(value);
setImage(document.getDecalRegistry().getDecalImage(value));
}
} else if ("repeat".equals(name)) {
repeat = "1".equals(value);
@ -87,72 +93,73 @@ public class RockSimAppearanceBuilder extends AppearanceBuilder {
setScaleUV(Double.parseDouble(c[0]), Double.parseDouble(c[1]));
}
}
if ( repeat ){
if (repeat) {
setEdgeMode(EdgeMode.REPEAT);
}
if ( preventSeam ){
if (preventSeam) {
setEdgeMode(EdgeMode.MIRROR);
}
if ( !flips ){
if (!flips) {
setScaleUV(getScaleU(), getScaleV() * -1);
setOffset(getOffsetU(), -1 - getOffsetV());
}
if ( !flipr ){
if (!flipr) {
setScaleUV(getScaleU() * -1, getScaleV());
setOffset(-1 - getOffsetU(), getOffsetV());
}
//TODO Make use of these values
System.out.println("Interpolate: " + interpolate);
System.out.println("FlipT: " + flipt);;
System.out.println("FlipT: " + flipt);
;
}
static Color weight(Color c, double w) {
return new Color((int) (c.getRed() * w), (int) (c.getGreen() * w), (int) (c.getBlue() * w), c.getAlpha());
}
static Color parseColor(String s) {
// blue and white came from a real file.
if ( "blue".equals(s) ) {
return new Color(0,0,255);
if ("blue".equals(s)) {
return new Color(0, 0, 255);
}
if ( "white".equals(s) ) {
return new Color(255,255,255);
if ("white".equals(s)) {
return new Color(255, 255, 255);
}
// I guessed these are valid color names in Rksim.
if ( "red".equals(s) ) {
return new Color(255,0,0);
if ("red".equals(s)) {
return new Color(255, 0, 0);
}
if( "green".equals(s) ) {
return new Color(0,255,0);
if ("green".equals(s)) {
return new Color(0, 255, 0);
}
if ( "black".equals(s) ) {
return new Color(0,0,0);
if ("black".equals(s)) {
return new Color(0, 0, 0);
}
s = s.replace("rgb(", "");
s = s.replace(")", "");
String ss[] = s.split(",");
return new Color(Integer.parseInt(ss[0]), Integer.parseInt(ss[1]), Integer.parseInt(ss[2]));
}
public boolean isPreventSeam() {
return preventSeam;
}
public void setPreventSeam(boolean preventSeam) {
this.preventSeam = preventSeam;
}
public boolean isRepeat() {
return repeat;
}
public void setRepeat(boolean repeat) {
this.repeat = repeat;
}
}

View File

@ -4,6 +4,8 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.Warning;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
@ -14,9 +16,8 @@ import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Stage;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* This class is a Sax element handler for Rocksim version 9 design files. It parses the Rocksim file (typically
@ -113,7 +114,7 @@ class RocksimContentHandler extends AbstractElementHandler {
return PlainTextHandler.INSTANCE;
}
if (RocksimCommonConstants.ROCKET_DESIGN.equals(element)) {
return new RocketDesignHandler(rocket);
return new RocketDesignHandler(doc, rocket);
}
return null;
}
@ -147,6 +148,7 @@ class RocksimContentHandler extends AbstractElementHandler {
* structures. If that invariant is not true, then behavior will be unpredictable.
*/
class RocketDesignHandler extends AbstractElementHandler {
private final OpenRocketDocument document;
/**
* The parent component.
*/
@ -185,7 +187,8 @@ class RocketDesignHandler extends AbstractElementHandler {
*
* @param c the parent component
*/
public RocketDesignHandler(RocketComponent c) {
public RocketDesignHandler(OpenRocketDocument document, RocketComponent c) {
this.document = document;
component = c;
}
@ -208,7 +211,7 @@ class RocketDesignHandler extends AbstractElementHandler {
stage.setOverrideCGX(stage3CG);
}
component.addChild(stage);
return new StageHandler(stage);
return new StageHandler(document, stage);
}
if ("Stage2Parts".equals(element)) {
if (stageCount >= 2) {
@ -224,7 +227,7 @@ class RocketDesignHandler extends AbstractElementHandler {
stage.setOverrideCGX(stage2CG);
}
component.addChild(stage);
return new StageHandler(stage);
return new StageHandler(document, stage);
}
}
if ("Stage1Parts".equals(element)) {
@ -241,7 +244,7 @@ class RocketDesignHandler extends AbstractElementHandler {
stage.setOverrideCGX(stage1CG);
}
component.addChild(stage);
return new StageHandler(stage);
return new StageHandler(document, stage);
}
}
if (RocksimCommonConstants.NAME.equals(element)) {
@ -311,6 +314,7 @@ class RocketDesignHandler extends AbstractElementHandler {
* A SAX handler for a Rocksim stage.
*/
class StageHandler extends AbstractElementHandler {
private final OpenRocketDocument document;
/**
* The parent OpenRocket component.
*/
@ -322,23 +326,24 @@ class StageHandler extends AbstractElementHandler {
* @param c the parent component
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public StageHandler(RocketComponent c) throws IllegalArgumentException {
public StageHandler(OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
if (c == null) {
throw new IllegalArgumentException("The stage component may not be null.");
}
this.document = document;
component = c;
}
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
if (RocksimCommonConstants.NOSE_CONE.equals(element)) {
return new NoseConeHandler(component, warnings);
return new NoseConeHandler(document, component, warnings);
}
if (RocksimCommonConstants.BODY_TUBE.equals(element)) {
return new BodyTubeHandler(component, warnings);
return new BodyTubeHandler(document, component, warnings);
}
if (RocksimCommonConstants.TRANSITION.equals(element)) {
return new TransitionHandler(component, warnings);
return new TransitionHandler(document, component, warnings);
}
return null;
}

View File

@ -3,15 +3,17 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Streamer;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* A SAX handler for Streamer components.
@ -31,7 +33,8 @@ class StreamerHandler extends RecoveryDeviceHandler<Streamer> {
*
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public StreamerHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
public StreamerHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent of a streamer may not be null.");
}

View File

@ -3,7 +3,10 @@
*/
package net.sf.openrocket.file.rocksim.importt;
import java.util.HashMap;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
import net.sf.openrocket.file.rocksim.RocksimFinishCode;
import net.sf.openrocket.file.rocksim.RocksimNoseConeCode;
@ -12,9 +15,8 @@ import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Transition;
import org.xml.sax.SAXException;
import java.util.HashMap;
import org.xml.sax.SAXException;
/**
* The SAX handler for Transition components.
@ -37,7 +39,8 @@ class TransitionHandler extends BaseHandler<Transition> {
* @param warnings the warning set
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public TransitionHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
public TransitionHandler(OpenRocketDocument document, RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
super(document);
if (c == null) {
throw new IllegalArgumentException("The parent of a transition may not be null.");
}
@ -49,7 +52,7 @@ class TransitionHandler extends BaseHandler<Transition> {
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
if (RocksimCommonConstants.ATTACHED_PARTS.equals(element)) {
return new AttachedPartsHandler(transition);
return new AttachedPartsHandler(document, transition);
}
return PlainTextHandler.INSTANCE;
}
@ -151,7 +154,6 @@ class TransitionHandler extends BaseHandler<Transition> {
*
* @return BULK
*/
@Override
public Material.Type getMaterialType() {
return Material.Type.BULK;
}

View File

@ -5,8 +5,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.swing.JComboBox;
@ -16,6 +14,7 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.appearance.DecalImage;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
@ -41,15 +40,9 @@ public class ExportDecalDialog extends JDialog {
JLabel label = new JLabel(trans.get("ExportDecalDialog.decalList.lbl"));
panel.add(label);
Set<String> allDecals = document.getDecalList();
List<String> exportableDecals = new ArrayList<String>();
for ( String decal : allDecals ) {
if ( document.getDecalRegistry().isExportable(decal) ) {
exportableDecals.add(decal);
}
}
Set<DecalImage> exportableDecals = document.getDecalRegistry().getExportableDecalsList();
decalComboBox = new JComboBox( exportableDecals.toArray( new String[0] ) );
decalComboBox = new JComboBox( exportableDecals.toArray( new DecalImage[0] ) );
decalComboBox.setEditable(false);
panel.add(decalComboBox, "growx, wrap");
@ -68,7 +61,7 @@ public class ExportDecalDialog extends JDialog {
// Here we copy the bits out.
// FIXME - confirm overwrite?
String selectedDecal = (String) decalComboBox.getSelectedItem();
DecalImage selectedDecal = (DecalImage) decalComboBox.getSelectedItem();
File selectedFile = chooser.getSelectedFile();
export(selectedDecal,selectedFile);
@ -82,10 +75,10 @@ public class ExportDecalDialog extends JDialog {
this.pack();
}
private void export( String decalName, File selectedFile ) {
private void export( DecalImage decal, File selectedFile ) {
try {
document.getDecalRegistry().exportDecal(decalName,selectedFile);
decal.exportImage(selectedFile, false);
}
catch (IOException iex) {
throw new BugException(iex);

View File

@ -9,7 +9,9 @@ import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;
import net.sf.openrocket.appearance.AppearanceBuilder;
import net.sf.openrocket.appearance.DecalImage;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.startup.Application;
@ -20,17 +22,19 @@ public class DecalModel extends AbstractListModel implements ComboBoxModel {
private static final String NONE_SELECTED = trans.get("lbl.select");
private static final String SELECT_FILE = trans.get("lbl.choose");
private final OpenRocketDocument document;
private final Component parent;
private final AppearanceBuilder ab;
private static File lastImageDir = null;
private String[] decals;
private DecalImage[] decals;
public DecalModel(Component parent, OpenRocketDocument document, AppearanceBuilder ab) {
this.document = document;
this.parent = parent;
this.ab = ab;
decals = document.getDecalList().toArray( new String[0] );
decals = document.getDecalRegistry().getDecalList().toArray(new DecalImage[0]);
}
@Override
@ -46,7 +50,7 @@ public class DecalModel extends AbstractListModel implements ComboBoxModel {
if (index == getSize() - 1) {
return SELECT_FILE;
}
return decals[index-1];
return decals[index - 1];
}
@Override
@ -60,26 +64,29 @@ public class DecalModel extends AbstractListModel implements ComboBoxModel {
public void run() {
File current = lastImageDir;
lastImageDir = current;
JFileChooser fc = new JFileChooser(current);
fc.setCurrentDirectory(((SwingPreferences) Application.getPreferences()).getDefaultDirectory());
int action = fc.showOpenDialog(SwingUtilities.getWindowAncestor(parent));
if ( action == JFileChooser.APPROVE_OPTION) {
setSelectedItem(fc.getSelectedFile().getAbsolutePath());
if (action == JFileChooser.APPROVE_OPTION) {
((SwingPreferences) Application.getPreferences()).setDefaultDirectory(fc.getCurrentDirectory());
File file = fc.getSelectedFile();
setSelectedItem(document.getDecalRegistry().getDecalImage(file));
}
}
});
} else {
ab.setImage( (String) item);
ab.setImage((DecalImage) item);
}
}
@Override
public Object getSelectedItem() {
String name = ab.getImage();
if (name == null) {
DecalImage decal = ab.getImage();
if (decal == null) {
return NONE_SELECTED;
} else {
return name;
return decal;
}
}

View File

@ -49,7 +49,7 @@ import net.sf.openrocket.util.StateChangeListener;
public class AppearancePanel extends JPanel {
private static final Translator trans = Application.getTranslator();
private AppearanceBuilder ab;
/**
@ -58,32 +58,32 @@ public class AppearancePanel extends JPanel {
*/
private final static UnitGroup TEXTURE_UNIT = new UnitGroup();
static {
Unit no_unit = new GeneralUnit(1,"",2) {
Unit no_unit = new GeneralUnit(1, "", 2) {
@Override
public double getNextValue(double value) {
return value+.1;
return value + .1;
}
@Override
public double getPreviousValue(double value) {
return value-.1;
return value - .1;
}
};
TEXTURE_UNIT.addUnit(no_unit);
}
private static final JColorChooser colorChooser = new JColorChooser();
private class ColorActionListener implements ActionListener {
private final String valueName;
private final Object o;
ColorActionListener(final Object o, final String valueName) {
this.valueName = valueName;
this.o = o;
}
@Override
public void actionPerformed(ActionEvent colorClickEvent) {
try {
@ -112,12 +112,12 @@ public class AppearancePanel extends JPanel {
}
}
}
public AppearancePanel(final OpenRocketDocument document, final RocketComponent c) {
super(new MigLayout("fill", "[150][grow][150][grow]"));
ab = new AppearanceBuilder(c.getAppearance());
net.sf.openrocket.util.Color figureColor = c.getColor();
if (figureColor == null) {
figureColor = Application.getPreferences().getDefaultColor(c.getClass());
@ -125,9 +125,9 @@ public class AppearancePanel extends JPanel {
final JButton figureColorButton = new JButton(new ColorIcon(figureColor));
final JButton colorButton = new JButton(new ColorIcon(ab.getPaint()));
final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));;
final JComboBox textureDropDown = new JComboBox(new DecalModel(this, document, ab));
ab.addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
@ -136,7 +136,7 @@ public class AppearancePanel extends JPanel {
c.setAppearance(ab.getAppearance());
}
});
c.addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
@ -147,13 +147,13 @@ public class AppearancePanel extends JPanel {
figureColorButton.setIcon(new ColorIcon(col));
}
});
figureColorButton.addActionListener(new ColorActionListener(c, "Color"));
colorButton.addActionListener(new ColorActionListener(ab, "Paint"));
BooleanModel fDefault = new BooleanModel(c.getColor() == null);
{// Style Header Row
final JCheckBox colorDefault = new JCheckBox(fDefault);
colorDefault.addActionListener(new ActionListener() {
@ -189,15 +189,15 @@ public class AppearancePanel extends JPanel {
fDefault.addEnableComponent(button, false);
add(button, "span 2, align right, wrap");
}
{// Figure Color
add(new JLabel(trans.get("RocketCompCfg.lbl.Componentcolor")));
fDefault.addEnableComponent(figureColorButton, false);
add(figureColorButton);
}
{// Line Style
add(new JLabel(trans.get("RocketCompCfg.lbl.Complinestyle")));
LineStyle[] list = new LineStyle[LineStyle.values().length + 1];
@ -211,32 +211,32 @@ public class AppearancePanel extends JPanel {
add(combo, "wrap");
}
add(new JSeparator(SwingConstants.HORIZONTAL), "span, wrap, growx");
{// Texture Header Row
add(new StyledLabel(trans.get("AppearanceCfg.lbl.Appearance"), Style.BOLD), "wrap");
}
{// Texture File
add(new JLabel(trans.get("AppearanceCfg.lbl.Texture")));
JPanel p = new JPanel(new MigLayout("fill, ins 0", "[grow][]"));
p.add(textureDropDown, "grow");
add(p, "span 3, growx, wrap");
final JButton editBtn = new JButton(trans.get("AppearanceCfg.but.edit"));
editBtn.setEnabled( ab.getImage() != null );
editBtn.setEnabled(ab.getImage() != null);
ab.addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
editBtn.setEnabled(ab.getImage() == null);
}
});
editBtn.addActionListener( new ActionListener() {
editBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
EditDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), document, ab.getImage());
EditDecalHelper.editDecal(SwingUtilities.getWindowAncestor(AppearancePanel.this), ab.getImage());
} catch (IOException ex) {
throw new BugException(ex);
}
@ -258,15 +258,15 @@ public class AppearancePanel extends JPanel {
}
});
}
{ // Scale
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.scale")));
add(new JLabel("x:"), "split 4");
JSpinner scaleU = new JSpinner(new DoubleModel(ab, "ScaleX", TEXTURE_UNIT).getSpinnerModel());
scaleU.setEditor(new SpinnerEditor(scaleU));
add(scaleU, "w 40");
add(new JLabel("y:"));
JSpinner scaleV = new JSpinner(new DoubleModel(ab, "ScaleY", TEXTURE_UNIT).getSpinnerModel());
scaleV.setEditor(new SpinnerEditor(scaleV));
@ -285,16 +285,16 @@ public class AppearancePanel extends JPanel {
add(unit, "growx");
add(slide, "w 50");
}
{ // Offset
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.offset")));
add(new JLabel("x:"), "split 4");
JSpinner offsetU = new JSpinner(new DoubleModel(ab, "OffsetU", TEXTURE_UNIT).getSpinnerModel());
offsetU.setEditor(new SpinnerEditor(offsetU));
add(offsetU, "w 40");
add(new JLabel("y:"));
JSpinner offsetV = new JSpinner(new DoubleModel(ab, "OffsetV", TEXTURE_UNIT).getSpinnerModel());
offsetV.setEditor(new SpinnerEditor(offsetV));
@ -308,8 +308,8 @@ public class AppearancePanel extends JPanel {
JComboBox combo = new JComboBox(new EnumModel<EdgeMode>(ab, "EdgeMode", list));
add(combo);
}
{ // Rotation
add(new JLabel(trans.get("AppearanceCfg.lbl.texture.rotation")));
DoubleModel rotationModel = new DoubleModel(ab, "Rotation", UnitGroup.UNITS_ANGLE);
@ -320,8 +320,8 @@ public class AppearancePanel extends JPanel {
BasicSlider bs = new BasicSlider(rotationModel.getSliderModel(-Math.PI, Math.PI));
add(bs, "w 50, wrap");
}
}
}

View File

@ -14,7 +14,6 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.document.DecalRegistry;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -26,37 +25,35 @@ import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.TextureIO;
public class RealisticRenderStrategy extends RenderStrategy {
private final float[] colorBlack = { 0, 0, 0, 1 };
private final float[] color = new float[4];
private static final LogHelper log = Application.getLogger();
private final DecalRegistry decalLoader;
private boolean needClearCache = false;
private Map<String, Texture> oldTexCache = new HashMap<String, Texture>();
private Map<String, Texture> texCache = new HashMap<String, Texture>();
private float anisotrophy = 0;
public RealisticRenderStrategy(OpenRocketDocument document) {
super(document);
this.decalLoader = document.getDecalRegistry();
}
@Override
public void updateFigure() {
needClearCache = true;
}
@Override
public void init(GLAutoDrawable drawable) {
oldTexCache = new HashMap<String,Texture>();
texCache = new HashMap<String,Texture>();
oldTexCache = new HashMap<String, Texture>();
texCache = new HashMap<String, Texture>();
GL2 gl = drawable.getGL().getGL2();
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
new float[] { 0,0,0 }, 0);
gl.glLightModelfv(GL2ES1.GL_LIGHT_MODEL_AMBIENT,
new float[] { 0, 0, 0 }, 0);
float amb = 0.3f;
float dif = 1.0f - amb;
float spc = 1.0f;
@ -66,50 +63,50 @@ public class RealisticRenderStrategy extends RenderStrategy {
new float[] { dif, dif, dif, 1 }, 0);
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_SPECULAR,
new float[] { spc, spc, spc, 1 }, 0);
gl.glEnable(GLLightingFunc.GL_LIGHT1);
gl.glEnable(GLLightingFunc.GL_LIGHTING);
gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
gl.glEnable(GLLightingFunc.GL_NORMALIZE);
if (gl.isExtensionAvailable("GL_EXT_texture_filter_anisotropic")) {
float a[] = new float[1];
gl.glGetFloatv(GL.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, a, 0);
anisotrophy = a[0];
}
}
@Override
public void dispose(GLAutoDrawable drawable) {
oldTexCache = null;
texCache = null;
}
@Override
public boolean isDrawn(RocketComponent c) {
return true;
}
@Override
public boolean isDrawnTransparent(RocketComponent c) {
return false;
}
@Override
public void preGeometry(GL2 gl, RocketComponent c, float alpha) {
if (needClearCache) {
clearCaches(gl);
needClearCache = false;
}
Appearance a = getAppearance(c);
gl.glLightModeli(GL2ES1.GL_LIGHT_MODEL_TWO_SIDE, 1);
gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL,GL2.GL_SEPARATE_SPECULAR_COLOR);
if ( a.getTexture() != null ){
color[0] = color[1] = color[2] = 1;
gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);
if (a.getTexture() != null) {
color[0] = color[1] = color[2] = 1;
} else {
convertColor(a.getPaint(), color);
color[3] = alpha;
@ -118,15 +115,15 @@ public class RealisticRenderStrategy extends RenderStrategy {
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0);
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0);
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0);
color[0] = color[1] = color[2] = (float)a.getShine();
color[0] = color[1] = color[2] = (float) a.getShine();
color[3] = alpha;
gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, color, 0);
gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, (int)(100 * a.getShine()));
gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, (int) (100 * a.getShine()));
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
gl.glMateriali(GL.GL_BACK, GLLightingFunc.GL_SHININESS, 0);
Decal t = a.getTexture();
Texture tex = null;
if (t != null) {
@ -135,30 +132,30 @@ public class RealisticRenderStrategy extends RenderStrategy {
if (t != null && tex != null) {
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
tex.enable(gl);
tex.bind(gl);
gl.glMatrixMode(GL.GL_TEXTURE);
gl.glPushMatrix();
gl.glTranslated(-t.getCenter().x, -t.getCenter().y, 0);
gl.glRotated(57.2957795 * t.getRotation(), 0, 0, 1);
gl.glTranslated(t.getCenter().x, t.getCenter().y, 0);
gl.glScaled(t.getScale().x, t.getScale().y, 0);
gl.glTranslated(t.getOffset().x, t.getOffset().y, 0);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, toEdgeMode(t.getEdgeMode()));
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, toEdgeMode(t.getEdgeMode()));
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
if ( anisotrophy > 0){
if (anisotrophy > 0) {
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotrophy);
}
}
}
@Override
public void postGeometry(GL2 gl, RocketComponent c, float alpha) {
Appearance a = getAppearance(c);
@ -174,7 +171,7 @@ public class RealisticRenderStrategy extends RenderStrategy {
tex.disable(gl);
}
}
private void clearCaches(GL2 gl) {
log.debug("ClearCaches");
for (Map.Entry<String, Texture> e : oldTexCache.entrySet()) {
@ -185,37 +182,37 @@ public class RealisticRenderStrategy extends RenderStrategy {
oldTexCache = texCache;
texCache = new HashMap<String, Texture>();
}
private Texture getTexture(Decal t) {
String imageName = t.getImage();
String imageName = t.getImage().getName();
// Return the Cached value if available
if (texCache.containsKey(imageName))
return texCache.get(imageName);
// If the texture is in the Old Cache, save it.
if (oldTexCache.containsKey(imageName)) {
texCache.put(imageName, oldTexCache.get(imageName));
oldTexCache.remove(imageName);
return texCache.get(imageName);
}
// Otherwise load it.
Texture tex = null;
try {
log.debug("Loading texture " + t);
InputStream is = decalLoader.getDecal(imageName);
InputStream is = t.getImage().getBytes();
TextureData data = TextureIO.newTextureData(GLProfile.getDefault(), is, true, null);
tex = TextureIO.newTexture(data);
} catch (Throwable e) {
log.error("Error loading Texture", e);
}
texCache.put(imageName, tex);
return tex;
}
private Appearance getAppearance(RocketComponent c) {
Appearance ret = c.getAppearance();
if (ret == null) {
@ -223,7 +220,7 @@ public class RealisticRenderStrategy extends RenderStrategy {
}
return ret;
}
private int toEdgeMode(Decal.EdgeMode m) {
switch (m) {
case REPEAT:
@ -236,7 +233,7 @@ public class RealisticRenderStrategy extends RenderStrategy {
return GL.GL_CLAMP_TO_EDGE;
}
}
protected static void convertColor(Color color, float[] out) {
if (color == null) {
out[0] = 1;

View File

@ -5,7 +5,7 @@ import java.awt.Window;
import java.io.File;
import java.io.IOException;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.appearance.DecalImage;
import net.sf.openrocket.gui.dialogs.EditDecalDialog;
import net.sf.openrocket.startup.Application;
@ -18,8 +18,9 @@ public class EditDecalHelper {
private static final SwingPreferences prefs = ((SwingPreferences)Application.getPreferences());
public static void editDecal( Window parent, OpenRocketDocument document, String decalId ) throws IOException {
public static void editDecal( Window parent, DecalImage decal ) throws IOException {
String decalId = decal.getName();
// Create Temp File.
int dotlocation = decalId.lastIndexOf('.');
String extension = "tmp";
@ -28,7 +29,7 @@ public class EditDecalHelper {
}
File tmpFile = File.createTempFile("OR_graphics", extension);
document.getDecalRegistry().exportDecal(decalId, tmpFile);
decal.exportImage(tmpFile, true);
//First Check preferences
if ( prefs.isDecalEditorPreferenceSet() ) {

View File

@ -1,31 +0,0 @@
package net.sf.openrocket.file;
import java.text.MessageFormat;
import org.junit.Test;
import static org.junit.Assert.*;
public class GeneralRocketSaverTest {
@Test
public void testBuildFilenameTemplate() {
assertEquals("abc ({0}).jpg", GeneralRocketSaver.buildFilenameTemplate("abc.jpg"));
assertEquals("a ({0}).jpg", GeneralRocketSaver.buildFilenameTemplate("a.jpg"));
assertEquals("abc ({0})", GeneralRocketSaver.buildFilenameTemplate("abc"));
assertEquals("abc ({0}).", GeneralRocketSaver.buildFilenameTemplate("abc."));
assertEquals(".abc ({0})", GeneralRocketSaver.buildFilenameTemplate(".abc"));
// This one is hideous, but hey so was the original name.
// If anybody wants to change the algorithm when there are multiple leading dots
// go ahead and change these test cases too.
assertEquals(". ({0}).abc", GeneralRocketSaver.buildFilenameTemplate("..abc"));
assertEquals( "abc (15).jpg", MessageFormat.format(GeneralRocketSaver.buildFilenameTemplate("abc.jpg"), 15));
}
}

View File

@ -30,7 +30,7 @@ public class BodyTubeHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new BodyTubeHandler(null, new WarningSet());
new BodyTubeHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -38,7 +38,7 @@ public class BodyTubeHandlerTest extends RocksimTestBase {
}
Stage stage = new Stage();
BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
BodyTubeHandler handler = new BodyTubeHandler(null, stage, new WarningSet());
BodyTube component = (BodyTube) getField(handler, "bodyTube");
assertContains(component, stage.getChildren());
}
@ -50,8 +50,8 @@ public class BodyTubeHandlerTest extends RocksimTestBase {
*/
@Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new BodyTubeHandler(new Stage(), new WarningSet()).openElement(null, null, null));
Assert.assertNotNull(new BodyTubeHandler(new Stage(), new WarningSet()).openElement("AttachedParts", null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new BodyTubeHandler(null, new Stage(), new WarningSet()).openElement(null, null, null));
Assert.assertNotNull(new BodyTubeHandler(null, new Stage(), new WarningSet()).openElement("AttachedParts", null, null));
}
/**
@ -63,7 +63,7 @@ public class BodyTubeHandlerTest extends RocksimTestBase {
@Test
public void testCloseElement() throws Exception {
Stage stage = new Stage();
BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
BodyTubeHandler handler = new BodyTubeHandler(null, stage, new WarningSet());
BodyTube component = (BodyTube) getField(handler, "bodyTube");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -134,7 +134,7 @@ public class BodyTubeHandlerTest extends RocksimTestBase {
*/
@Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new BodyTubeHandler(new Stage(), new WarningSet()).getComponent() instanceof BodyTube);
Assert.assertTrue(new BodyTubeHandler(null, new Stage(), new WarningSet()).getComponent() instanceof BodyTube);
}
/**
@ -144,7 +144,7 @@ public class BodyTubeHandlerTest extends RocksimTestBase {
*/
@Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.BULK, new BodyTubeHandler(new Stage(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.BULK, new BodyTubeHandler(null, new Stage(), new WarningSet()).getMaterialType());
}
}

View File

@ -28,7 +28,7 @@ public class FinSetHandlerTest extends TestCase {
@org.junit.Test
public void testAsOpenRocket() throws Exception {
FinSetHandler dto = new FinSetHandler(new BodyTube());
FinSetHandler dto = new FinSetHandler(null, new BodyTube());
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -93,7 +93,7 @@ public class FinSetHandlerTest extends TestCase {
*/
@org.junit.Test
public void testToCoordinates() throws Exception {
FinSetHandler holder = new FinSetHandler(new BodyTube());
FinSetHandler holder = new FinSetHandler(null, new BodyTube());
Method method = FinSetHandler.class.getDeclaredMethod("toCoordinates", String.class, WarningSet.class);
method.setAccessible(true);

View File

@ -29,7 +29,7 @@ public class InnerBodyTubeHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new InnerBodyTubeHandler(null, new WarningSet());
new InnerBodyTubeHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -37,7 +37,7 @@ public class InnerBodyTubeHandlerTest extends RocksimTestBase {
}
BodyTube tube = new BodyTube();
InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
InnerBodyTubeHandler handler = new InnerBodyTubeHandler(null, tube, new WarningSet());
InnerTube component = (InnerTube) getField(handler, "bodyTube");
assertContains(component, tube.getChildren());
}
@ -49,8 +49,8 @@ public class InnerBodyTubeHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
Assert.assertNotNull(new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).openElement("AttachedParts", null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new InnerBodyTubeHandler(null, new BodyTube(), new WarningSet()).openElement(null, null, null));
Assert.assertNotNull(new InnerBodyTubeHandler(null, new BodyTube(), new WarningSet()).openElement("AttachedParts", null, null));
}
/**
@ -62,7 +62,7 @@ public class InnerBodyTubeHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testCloseElement() throws Exception {
BodyTube tube = new BodyTube();
InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
InnerBodyTubeHandler handler = new InnerBodyTubeHandler(null, tube, new WarningSet());
InnerTube component = (InnerTube) getField(handler, "bodyTube");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -126,7 +126,7 @@ public class InnerBodyTubeHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testSetRelativePosition() throws Exception {
BodyTube tube = new BodyTube();
InnerBodyTubeHandler handler = new InnerBodyTubeHandler(tube, new WarningSet());
InnerBodyTubeHandler handler = new InnerBodyTubeHandler(null, tube, new WarningSet());
InnerTube component = (InnerTube) getField(handler, "bodyTube");
handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
@ -139,7 +139,7 @@ public class InnerBodyTubeHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).getComponent() instanceof InnerTube);
Assert.assertTrue(new InnerBodyTubeHandler(null, new BodyTube(), new WarningSet()).getComponent() instanceof InnerTube);
}
/**
@ -149,7 +149,7 @@ public class InnerBodyTubeHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.BULK, new InnerBodyTubeHandler(new BodyTube(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.BULK, new InnerBodyTubeHandler(null, new BodyTube(), new WarningSet()).getMaterialType());
}
}

View File

@ -30,7 +30,7 @@ public class LaunchLugHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new LaunchLugHandler(null, new WarningSet());
new LaunchLugHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -38,7 +38,7 @@ public class LaunchLugHandlerTest extends RocksimTestBase {
}
BodyTube tube = new BodyTube();
LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
LaunchLugHandler handler = new LaunchLugHandler(null, tube, new WarningSet());
LaunchLug component = (LaunchLug) getField(handler, "lug");
assertContains(component, tube.getChildren());
}
@ -50,7 +50,7 @@ public class LaunchLugHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new LaunchLugHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new LaunchLugHandler(null, new BodyTube(), new WarningSet()).openElement(null, null, null));
}
/**
@ -62,7 +62,7 @@ public class LaunchLugHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testCloseElement() throws Exception {
BodyTube tube = new BodyTube();
LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
LaunchLugHandler handler = new LaunchLugHandler(null, tube, new WarningSet());
LaunchLug component = (LaunchLug) getField(handler, "lug");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -117,7 +117,7 @@ public class LaunchLugHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testSetRelativePosition() throws Exception {
BodyTube tube = new BodyTube();
LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
LaunchLugHandler handler = new LaunchLugHandler(null, tube, new WarningSet());
LaunchLug component = (LaunchLug) getField(handler, "lug");
handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
@ -130,7 +130,7 @@ public class LaunchLugHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new LaunchLugHandler(new BodyTube(), new WarningSet()).getComponent() instanceof LaunchLug);
Assert.assertTrue(new LaunchLugHandler(null, new BodyTube(), new WarningSet()).getComponent() instanceof LaunchLug);
}
/**
@ -140,7 +140,7 @@ public class LaunchLugHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.BULK, new LaunchLugHandler(new BodyTube(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.BULK, new LaunchLugHandler(null, new BodyTube(), new WarningSet()).getMaterialType());
}

View File

@ -29,7 +29,7 @@ public class MassObjectHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new MassObjectHandler(null, new WarningSet());
new MassObjectHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -37,7 +37,7 @@ public class MassObjectHandlerTest extends RocksimTestBase {
}
BodyTube tube = new BodyTube();
MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
MassObjectHandler handler = new MassObjectHandler(null, tube, new WarningSet());
MassComponent mass = (MassComponent) getField(handler, "mass");
MassComponent current = (MassComponent) getField(handler, "current");
Assert.assertEquals(mass, current);
@ -50,7 +50,7 @@ public class MassObjectHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new MassObjectHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new MassObjectHandler(null, new BodyTube(), new WarningSet()).openElement(null, null, null));
}
/**
@ -65,7 +65,7 @@ public class MassObjectHandlerTest extends RocksimTestBase {
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
MassObjectHandler handler = new MassObjectHandler(null, tube, new WarningSet());
MassComponent component = (MassComponent) getField(handler, "mass");
handler.closeElement("Len", attributes, "-1", warnings);
@ -98,7 +98,7 @@ public class MassObjectHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testSetRelativePosition() throws Exception {
BodyTube tube = new BodyTube();
MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
MassObjectHandler handler = new MassObjectHandler(null, tube, new WarningSet());
MassComponent component = (MassComponent) getField(handler, "mass");
handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
@ -111,7 +111,7 @@ public class MassObjectHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new MassObjectHandler(new BodyTube(), new WarningSet()).getComponent() instanceof MassComponent);
Assert.assertTrue(new MassObjectHandler(null, new BodyTube(), new WarningSet()).getComponent() instanceof MassComponent);
}
/**
@ -121,6 +121,6 @@ public class MassObjectHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.LINE, new MassObjectHandler(new BodyTube(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.LINE, new MassObjectHandler(null, new BodyTube(), new WarningSet()).getMaterialType());
}
}

View File

@ -32,7 +32,7 @@ public class NoseConeHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new NoseConeHandler(null, new WarningSet());
new NoseConeHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -40,7 +40,7 @@ public class NoseConeHandlerTest extends RocksimTestBase {
}
Stage stage = new Stage();
NoseConeHandler handler = new NoseConeHandler(stage, new WarningSet());
NoseConeHandler handler = new NoseConeHandler(null, stage, new WarningSet());
NoseCone component = (NoseCone) getField(handler, "noseCone");
assertContains(component, stage.getChildren());
}
@ -52,8 +52,8 @@ public class NoseConeHandlerTest extends RocksimTestBase {
*/
@Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new NoseConeHandler(new Stage(), new WarningSet()).openElement(null, null, null));
Assert.assertNotNull(new NoseConeHandler(new Stage(), new WarningSet()).openElement("AttachedParts", null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new NoseConeHandler(null, new Stage(), new WarningSet()).openElement(null, null, null));
Assert.assertNotNull(new NoseConeHandler(null, new Stage(), new WarningSet()).openElement("AttachedParts", null, null));
}
/**
@ -69,7 +69,7 @@ public class NoseConeHandlerTest extends RocksimTestBase {
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
NoseConeHandler handler = new NoseConeHandler(stage, warnings);
NoseConeHandler handler = new NoseConeHandler(null, stage, warnings);
NoseCone component = (NoseCone) getField(handler, "noseCone");
handler.closeElement("ShapeCode", attributes, "0", warnings);
@ -188,7 +188,7 @@ public class NoseConeHandlerTest extends RocksimTestBase {
*/
@Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new NoseConeHandler(new Stage(), new WarningSet()).getComponent() instanceof NoseCone);
Assert.assertTrue(new NoseConeHandler(null, new Stage(), new WarningSet()).getComponent() instanceof NoseCone);
}
/**
@ -198,6 +198,6 @@ public class NoseConeHandlerTest extends RocksimTestBase {
*/
@Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.BULK, new NoseConeHandler(new Stage(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.BULK, new NoseConeHandler(null, new Stage(), new WarningSet()).getMaterialType());
}
}

View File

@ -26,7 +26,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new ParachuteHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new ParachuteHandler(null, new BodyTube(), new WarningSet()).openElement(null, null, null));
}
/**
@ -38,7 +38,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
public void testCloseElement() throws Exception {
BodyTube tube = new BodyTube();
ParachuteHandler handler = new ParachuteHandler(tube, new WarningSet());
ParachuteHandler handler = new ParachuteHandler(null, tube, new WarningSet());
Parachute component = (Parachute) getField(handler, "chute");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -89,7 +89,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new ParachuteHandler(null, new WarningSet());
new ParachuteHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -97,7 +97,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
}
BodyTube tube = new BodyTube();
ParachuteHandler handler = new ParachuteHandler(tube, new WarningSet());
ParachuteHandler handler = new ParachuteHandler(null, tube, new WarningSet());
Parachute component = (Parachute) getField(handler, "chute");
assertContains(component, tube.getChildren());
}
@ -110,7 +110,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testSetRelativePosition() throws Exception {
BodyTube tube = new BodyTube();
ParachuteHandler handler = new ParachuteHandler(tube, new WarningSet());
ParachuteHandler handler = new ParachuteHandler(null, tube, new WarningSet());
Parachute component = (Parachute) getField(handler, "chute");
handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
@ -123,7 +123,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new ParachuteHandler(new BodyTube(), new WarningSet()).getComponent() instanceof Parachute);
Assert.assertTrue(new ParachuteHandler(null, new BodyTube(), new WarningSet()).getComponent() instanceof Parachute);
}
/**
@ -133,7 +133,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.SURFACE, new ParachuteHandler(new BodyTube(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.SURFACE, new ParachuteHandler(null, new BodyTube(), new WarningSet()).getMaterialType());
}
/**
@ -144,7 +144,7 @@ public class ParachuteHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testEndHandler() throws Exception {
BodyTube tube = new BodyTube();
ParachuteHandler handler = new ParachuteHandler(tube, new WarningSet());
ParachuteHandler handler = new ParachuteHandler(null, tube, new WarningSet());
Parachute component = (Parachute) getField(handler, "chute");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();

View File

@ -31,7 +31,7 @@ public class RingHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new RingHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new RingHandler(null, new BodyTube(), new WarningSet()).openElement(null, null, null));
}
/**
@ -43,7 +43,7 @@ public class RingHandlerTest extends RocksimTestBase {
public void testCloseElement() throws Exception {
BodyTube tube = new BodyTube();
RingHandler handler = new RingHandler(tube, new WarningSet());
RingHandler handler = new RingHandler(null, tube, new WarningSet());
CenteringRing component = (CenteringRing) getField(handler, "ring");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -86,9 +86,8 @@ public class RingHandlerTest extends RocksimTestBase {
@Test
public void testBulkhead() throws Exception {
BodyTube tube = new BodyTube();
RingHandler handler = new RingHandler(tube, new WarningSet());
@SuppressWarnings("unused")
CenteringRing component = (CenteringRing) getField(handler, "ring");
RingHandler handler = new RingHandler(null, tube, new WarningSet());
CenteringRing component = (CenteringRing) getField(handler, "ring");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -123,7 +122,7 @@ public class RingHandlerTest extends RocksimTestBase {
@Test
public void testTubeCoupler() throws Exception {
BodyTube tube = new BodyTube();
RingHandler handler = new RingHandler(tube, new WarningSet());
RingHandler handler = new RingHandler(null, tube, new WarningSet());
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -157,7 +156,7 @@ public class RingHandlerTest extends RocksimTestBase {
@Test
public void testEngineBlock() throws Exception {
BodyTube tube = new BodyTube();
RingHandler handler = new RingHandler(tube, new WarningSet());
RingHandler handler = new RingHandler(null, tube, new WarningSet());
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -194,7 +193,7 @@ public class RingHandlerTest extends RocksimTestBase {
@Test
public void testRing() throws Exception {
BodyTube tube = new BodyTube();
RingHandler handler = new RingHandler(tube, new WarningSet());
RingHandler handler = new RingHandler(null, tube, new WarningSet());
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -229,7 +228,7 @@ public class RingHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new RingHandler(null, new WarningSet());
new RingHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -237,9 +236,8 @@ public class RingHandlerTest extends RocksimTestBase {
}
BodyTube tube = new BodyTube();
RingHandler handler = new RingHandler(tube, new WarningSet());
@SuppressWarnings("unused")
CenteringRing component = (CenteringRing) getField(handler, "ring");
RingHandler handler = new RingHandler(null, tube, new WarningSet());
CenteringRing component = (CenteringRing) getField(handler, "ring");
}
/**
@ -250,7 +248,7 @@ public class RingHandlerTest extends RocksimTestBase {
@org.junit.Test
public void testSetRelativePosition() throws Exception {
BodyTube tube = new BodyTube();
RingHandler handler = new RingHandler(tube, new WarningSet());
RingHandler handler = new RingHandler(null, tube, new WarningSet());
CenteringRing component = (CenteringRing) getField(handler, "ring");
handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
@ -264,7 +262,7 @@ public class RingHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new RingHandler(new BodyTube(), new WarningSet()).getComponent() instanceof CenteringRing);
Assert.assertTrue(new RingHandler(null, new BodyTube(), new WarningSet()).getComponent() instanceof CenteringRing);
}
/**
@ -274,7 +272,7 @@ public class RingHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.BULK, new RingHandler(new BodyTube(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.BULK, new RingHandler(null, new BodyTube(), new WarningSet()).getMaterialType());
}

View File

@ -28,7 +28,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
*/
@Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new StreamerHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new StreamerHandler(null, new BodyTube(), new WarningSet()).openElement(null, null, null));
}
/**
@ -40,7 +40,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
public void testCloseElement() throws Exception {
BodyTube tube = new BodyTube();
StreamerHandler handler = new StreamerHandler(tube, new WarningSet());
StreamerHandler handler = new StreamerHandler(null, tube, new WarningSet());
Streamer component = (Streamer) getField(handler, "streamer");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
@ -85,7 +85,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new StreamerHandler(null, new WarningSet());
new StreamerHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -93,7 +93,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
}
BodyTube tube = new BodyTube();
StreamerHandler handler = new StreamerHandler(tube, new WarningSet());
StreamerHandler handler = new StreamerHandler(null, tube, new WarningSet());
Streamer component = (Streamer) getField(handler, "streamer");
assertContains(component, tube.getChildren());
}
@ -106,7 +106,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
@Test
public void testSetRelativePosition() throws Exception {
BodyTube tube = new BodyTube();
StreamerHandler handler = new StreamerHandler(tube, new WarningSet());
StreamerHandler handler = new StreamerHandler(null, tube, new WarningSet());
Streamer component = (Streamer) getField(handler, "streamer");
handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
@ -119,7 +119,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
*/
@Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new StreamerHandler(new BodyTube(), new WarningSet()).getComponent() instanceof Streamer);
Assert.assertTrue(new StreamerHandler(null, new BodyTube(), new WarningSet()).getComponent() instanceof Streamer);
}
/**
@ -129,7 +129,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
*/
@Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.SURFACE, new StreamerHandler(new BodyTube(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.SURFACE, new StreamerHandler(null, new BodyTube(), new WarningSet()).getMaterialType());
}
/**
@ -140,7 +140,7 @@ public class StreamerHandlerTest extends RocksimTestBase {
@Test
public void testEndHandler() throws Exception {
BodyTube tube = new BodyTube();
StreamerHandler handler = new StreamerHandler(tube, new WarningSet());
StreamerHandler handler = new StreamerHandler(null, tube, new WarningSet());
Streamer component = (Streamer) getField(handler, "streamer");
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();

View File

@ -29,7 +29,7 @@ public class TransitionHandlerTest extends RocksimTestBase {
public void testConstructor() throws Exception {
try {
new TransitionHandler(null, new WarningSet());
new TransitionHandler(null, null, new WarningSet());
Assert.fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
@ -37,7 +37,7 @@ public class TransitionHandlerTest extends RocksimTestBase {
}
Stage stage = new Stage();
TransitionHandler handler = new TransitionHandler(stage, new WarningSet());
TransitionHandler handler = new TransitionHandler(null, stage, new WarningSet());
Transition component = (Transition) getField(handler, "transition");
assertContains(component, stage.getChildren());
}
@ -49,7 +49,7 @@ public class TransitionHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testOpenElement() throws Exception {
Assert.assertEquals(PlainTextHandler.INSTANCE, new TransitionHandler(new Stage(), new WarningSet()).openElement(null, null, null));
Assert.assertEquals(PlainTextHandler.INSTANCE, new TransitionHandler(null, new Stage(), new WarningSet()).openElement(null, null, null));
}
/**
@ -64,7 +64,7 @@ public class TransitionHandlerTest extends RocksimTestBase {
HashMap<String, String> attributes = new HashMap<String, String>();
WarningSet warnings = new WarningSet();
TransitionHandler handler = new TransitionHandler(stage, new WarningSet());
TransitionHandler handler = new TransitionHandler(null, stage, new WarningSet());
Transition component = (Transition) getField(handler, "transition");
handler.closeElement("ShapeCode", attributes, "0", warnings);
@ -214,7 +214,7 @@ public class TransitionHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetComponent() throws Exception {
Assert.assertTrue(new TransitionHandler(new Stage(), new WarningSet()).getComponent() instanceof Transition);
Assert.assertTrue(new TransitionHandler(null, new Stage(), new WarningSet()).getComponent() instanceof Transition);
}
/**
@ -224,7 +224,7 @@ public class TransitionHandlerTest extends RocksimTestBase {
*/
@org.junit.Test
public void testGetMaterialType() throws Exception {
Assert.assertEquals(Material.Type.BULK, new TransitionHandler(new Stage(), new WarningSet()).getMaterialType());
Assert.assertEquals(Material.Type.BULK, new TransitionHandler(null, new Stage(), new WarningSet()).getMaterialType());
}