Rework the AttachmentFactory and Attachments. Make the Attachment
implementations stand on their own and be able to determine the location of their bytes without needing a reference back to the AttachmentFactory. This required changing the loading semantics so the OpenRocketDocument is created prior to beginning to read the xml file. Added an OpenRocketDocumentFactory to facilitate construction of OpenRocketDocument objects.
This commit is contained in:
parent
c59bdd31cd
commit
48adc0b7bf
@ -4,7 +4,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public interface Attachment {
|
public interface Attachment extends Comparable<Attachment> {
|
||||||
|
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
|
@ -1,135 +0,0 @@
|
|||||||
package net.sf.openrocket.document;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipInputStream;
|
|
||||||
|
|
||||||
import net.sf.openrocket.file.FileInfo;
|
|
||||||
import net.sf.openrocket.util.FileUtils;
|
|
||||||
|
|
||||||
public class BaseAttachmentFactory implements AttachmentFactory<BaseAttachmentFactory.BaseAttachment> {
|
|
||||||
|
|
||||||
private FileInfo fileInfo;
|
|
||||||
private boolean isZipFile = false;
|
|
||||||
|
|
||||||
public void setBaseFile(FileInfo fileInfo) {
|
|
||||||
this.fileInfo = fileInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsZipFile(boolean isZipFile) {
|
|
||||||
this.isZipFile = isZipFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class BaseAttachment implements Attachment, Comparable {
|
|
||||||
|
|
||||||
protected String name;
|
|
||||||
|
|
||||||
BaseAttachment(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream getBytes() throws FileNotFoundException, IOException {
|
|
||||||
return BaseAttachmentFactory.this.getBytes(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Object o) {
|
|
||||||
if (!(o instanceof BaseAttachment)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return this.name.compareTo(((BaseAttachment) o).name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseAttachment getAttachment(String name) {
|
|
||||||
return new BaseAttachment(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function returns an InputStream backed by a byte[] containing the decal pixels.
|
|
||||||
* If it reads in the bytes from an actual file, the underlying file is closed.
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
private InputStream getBytes(BaseAttachment attachment) throws FileNotFoundException, IOException {
|
|
||||||
|
|
||||||
// This is the InputStream to be returned.
|
|
||||||
InputStream rawIs = null;
|
|
||||||
|
|
||||||
|
|
||||||
String name = attachment.getName();
|
|
||||||
|
|
||||||
if (rawIs == null && isZipFile) {
|
|
||||||
rawIs = findInZipContainer(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try relative to the model file directory. This is so we can support unzipped container format.
|
|
||||||
if (rawIs == null) {
|
|
||||||
if (fileInfo != null && fileInfo.getDirectory() != null) {
|
|
||||||
File decalFile = new File(fileInfo.getDirectory(), name);
|
|
||||||
rawIs = new FileInputStream(decalFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rawIs == null) {
|
|
||||||
throw new FileNotFoundException("Unable to locate decal for name " + name);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
byte[] bytes = FileUtils.readBytes(rawIs);
|
|
||||||
return new ByteArrayInputStream(bytes);
|
|
||||||
} finally {
|
|
||||||
rawIs.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private ZipInputStream findInZipContainer(String name) {
|
|
||||||
ZipInputStream zis = null;
|
|
||||||
try {
|
|
||||||
zis = new ZipInputStream(fileInfo.getFileURL().openStream());
|
|
||||||
} catch (IOException ex) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ZipEntry entry = zis.getNextEntry();
|
|
||||||
while (entry != null) {
|
|
||||||
if (entry.getName().equals(name)) {
|
|
||||||
return zis;
|
|
||||||
}
|
|
||||||
entry = zis.getNextEntry();
|
|
||||||
}
|
|
||||||
zis.close();
|
|
||||||
return null;
|
|
||||||
} catch (IOException ioex) {
|
|
||||||
try {
|
|
||||||
zis.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
// why does close throw? it's maddening
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -19,7 +19,6 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import net.sf.openrocket.appearance.DecalImage;
|
import net.sf.openrocket.appearance.DecalImage;
|
||||||
import net.sf.openrocket.document.BaseAttachmentFactory.BaseAttachment;
|
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.BugException;
|
import net.sf.openrocket.util.BugException;
|
||||||
@ -28,9 +27,9 @@ import net.sf.openrocket.util.FileUtils;
|
|||||||
public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
||||||
private static LogHelper log = Application.getLogger();
|
private static LogHelper log = Application.getLogger();
|
||||||
|
|
||||||
private final BaseAttachmentFactory baseFactory;
|
private final AttachmentFactory baseFactory;
|
||||||
|
|
||||||
public DecalRegistry(BaseAttachmentFactory baseFactory) {
|
public DecalRegistry(AttachmentFactory baseFactory) {
|
||||||
this.baseFactory = baseFactory;
|
this.baseFactory = baseFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
|||||||
public DecalImage getAttachment(String decalName) {
|
public DecalImage getAttachment(String decalName) {
|
||||||
DecalImageImpl d = registeredDecals.get(decalName);
|
DecalImageImpl d = registeredDecals.get(decalName);
|
||||||
if (d == null) {
|
if (d == null) {
|
||||||
BaseAttachment attachment = baseFactory.getAttachment(decalName);
|
Attachment attachment = baseFactory.getAttachment(decalName);
|
||||||
d = new DecalImageImpl(attachment);
|
d = new DecalImageImpl(attachment);
|
||||||
registeredDecals.put(decalName, d);
|
registeredDecals.put(decalName, d);
|
||||||
}
|
}
|
||||||
@ -58,7 +57,7 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
|||||||
// It's a new file, generate a name for it.
|
// It's a new file, generate a name for it.
|
||||||
String decalName = makeUniqueName(file.getName());
|
String decalName = makeUniqueName(file.getName());
|
||||||
|
|
||||||
BaseAttachment attachment = baseFactory.getAttachment(decalName);
|
Attachment attachment = baseFactory.getAttachment(decalName);
|
||||||
decal = new DecalImageImpl(attachment);
|
decal = new DecalImageImpl(attachment);
|
||||||
decal.setFileSystemLocation(file);
|
decal.setFileSystemLocation(file);
|
||||||
|
|
||||||
@ -76,13 +75,13 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
|||||||
return decals;
|
return decals;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DecalImageImpl implements DecalImage, Comparable {
|
public class DecalImageImpl implements DecalImage {
|
||||||
|
|
||||||
private final BaseAttachment delegate;
|
private final Attachment delegate;
|
||||||
|
|
||||||
private File fileSystemLocation;
|
private File fileSystemLocation;
|
||||||
|
|
||||||
private DecalImageImpl(BaseAttachment delegate) {
|
private DecalImageImpl(Attachment delegate) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +115,7 @@ public class DecalRegistry implements AttachmentFactory<DecalImage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Attachment o) {
|
||||||
if (!(o instanceof DecalImageImpl)) {
|
if (!(o instanceof DecalImageImpl)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package net.sf.openrocket.document;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.sf.openrocket.document.attachments.BaseAttachment;
|
||||||
|
import net.sf.openrocket.document.attachments.FileSystemAttachment;
|
||||||
|
|
||||||
|
public class FileSystemAttachmentFactory implements AttachmentFactory<BaseAttachment> {
|
||||||
|
|
||||||
|
private final File baseDirectory;
|
||||||
|
|
||||||
|
public FileSystemAttachmentFactory() {
|
||||||
|
super();
|
||||||
|
this.baseDirectory = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileSystemAttachmentFactory(File baseDirectory) {
|
||||||
|
super();
|
||||||
|
if (baseDirectory != null && baseDirectory.isDirectory() == false) {
|
||||||
|
throw new IllegalArgumentException("Base file for FileSystemAttachmentFactory is not a directory");
|
||||||
|
}
|
||||||
|
this.baseDirectory = baseDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseAttachment getAttachment(String name) {
|
||||||
|
|
||||||
|
File file = new File(name);
|
||||||
|
|
||||||
|
if (file.isAbsolute()) {
|
||||||
|
return new FileSystemAttachment(name, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
file = new File(baseDirectory, name);
|
||||||
|
return new FileSystemAttachment(name, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package net.sf.openrocket.document;
|
package net.sf.openrocket.document;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -10,7 +12,6 @@ import java.util.Set;
|
|||||||
import net.sf.openrocket.document.events.DocumentChangeEvent;
|
import net.sf.openrocket.document.events.DocumentChangeEvent;
|
||||||
import net.sf.openrocket.document.events.DocumentChangeListener;
|
import net.sf.openrocket.document.events.DocumentChangeListener;
|
||||||
import net.sf.openrocket.document.events.SimulationChangeEvent;
|
import net.sf.openrocket.document.events.SimulationChangeEvent;
|
||||||
import net.sf.openrocket.file.FileInfo;
|
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.logging.TraceException;
|
import net.sf.openrocket.logging.TraceException;
|
||||||
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||||
@ -59,8 +60,8 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
|||||||
private final ArrayList<Simulation> simulations = new ArrayList<Simulation>();
|
private final ArrayList<Simulation> simulations = new ArrayList<Simulation>();
|
||||||
private ArrayList<CustomExpression> customExpressions = new ArrayList<CustomExpression>();
|
private ArrayList<CustomExpression> customExpressions = new ArrayList<CustomExpression>();
|
||||||
|
|
||||||
private BaseAttachmentFactory attachmentFactory = new BaseAttachmentFactory();
|
private final AttachmentFactory attachmentFactory;
|
||||||
private DecalRegistry decalRegistry = new DecalRegistry(attachmentFactory);
|
private final DecalRegistry decalRegistry;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The undo/redo variables and mechanism are documented in doc/undo-redo-flow.*
|
* The undo/redo variables and mechanism are documented in doc/undo-redo-flow.*
|
||||||
@ -95,34 +96,44 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
|||||||
private final StorageOptions storageOptions = new StorageOptions();
|
private final StorageOptions storageOptions = new StorageOptions();
|
||||||
|
|
||||||
|
|
||||||
private final List<DocumentChangeListener> listeners =
|
private final List<DocumentChangeListener> listeners = new ArrayList<DocumentChangeListener>();
|
||||||
new ArrayList<DocumentChangeListener>();
|
|
||||||
|
|
||||||
public OpenRocketDocument(Rocket rocket) {
|
OpenRocketDocument(Rocket rocket, File fileName, boolean isContainer) {
|
||||||
this(rocket.getDefaultConfiguration());
|
this.configuration = rocket.getDefaultConfiguration();
|
||||||
|
this.rocket = rocket;
|
||||||
|
AttachmentFactory attachments;
|
||||||
|
if (isContainer) {
|
||||||
|
try {
|
||||||
|
attachments = new ZipFileAttachmentFactory(fileName.toURI().toURL());
|
||||||
|
} catch (MalformedURLException mex) {
|
||||||
|
attachments = new FileSystemAttachmentFactory(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fileName == null) {
|
||||||
|
attachments = new FileSystemAttachmentFactory(null);
|
||||||
|
} else {
|
||||||
|
attachments = new FileSystemAttachmentFactory(fileName.getParentFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.attachmentFactory = attachments;
|
||||||
|
this.decalRegistry = new DecalRegistry(this.attachmentFactory);
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpenRocketDocument(Rocket rocket, URL jarURL, boolean isContainer) {
|
||||||
|
this.configuration = rocket.getDefaultConfiguration();
|
||||||
|
this.rocket = rocket;
|
||||||
|
this.attachmentFactory = isContainer ? new ZipFileAttachmentFactory(jarURL) : new FileSystemAttachmentFactory(null);
|
||||||
|
this.decalRegistry = new DecalRegistry(this.attachmentFactory);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
private OpenRocketDocument(Configuration configuration) {
|
private void init() {
|
||||||
this.configuration = configuration;
|
|
||||||
this.rocket = configuration.getRocket();
|
|
||||||
|
|
||||||
clearUndo();
|
clearUndo();
|
||||||
|
|
||||||
rocket.addComponentChangeListener(this);
|
rocket.addComponentChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setBaseFile(FileInfo fileInfo) {
|
|
||||||
attachmentFactory.setBaseFile(fileInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setIsZipFile(boolean isZipFile) {
|
|
||||||
attachmentFactory.setIsZipFile(isZipFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void addCustomExpression(CustomExpression expression) {
|
public void addCustomExpression(CustomExpression expression) {
|
||||||
if (customExpressions.contains(expression)) {
|
if (customExpressions.contains(expression)) {
|
||||||
log.user("Could not add custom expression " + expression.getName() + " to document as document alerady has a matching expression.");
|
log.user("Could not add custom expression " + expression.getName() + " to document as document alerady has a matching expression.");
|
||||||
@ -553,11 +564,14 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
|||||||
* motor configuration ID is maintained and the simulations are copied to the new rocket.
|
* motor configuration ID is maintained and the simulations are copied to the new rocket.
|
||||||
* No undo/redo information or file storage information is maintained.
|
* No undo/redo information or file storage information is maintained.
|
||||||
*
|
*
|
||||||
|
* This function is used from the Optimization routine to store alternatives of the same rocket.
|
||||||
|
* For now we can assume that the copy returned does not have any of the attachment factories in place.
|
||||||
|
*
|
||||||
* @return a copy of this document.
|
* @return a copy of this document.
|
||||||
*/
|
*/
|
||||||
public OpenRocketDocument copy() {
|
public OpenRocketDocument copy() {
|
||||||
Rocket rocketCopy = rocket.copyWithOriginalID();
|
Rocket rocketCopy = rocket.copyWithOriginalID();
|
||||||
OpenRocketDocument documentCopy = new OpenRocketDocument(rocketCopy);
|
OpenRocketDocument documentCopy = OpenRocketDocumentFactory.createDocumentFromRocket(rocketCopy);
|
||||||
documentCopy.getDefaultConfiguration().setFlightConfigurationID(configuration.getFlightConfigurationID());
|
documentCopy.getDefaultConfiguration().setFlightConfigurationID(configuration.getFlightConfigurationID());
|
||||||
for (Simulation s : simulations) {
|
for (Simulation s : simulations) {
|
||||||
documentCopy.addSimulation(s.duplicateSimulation(rocketCopy));
|
documentCopy.addSimulation(s.duplicateSimulation(rocketCopy));
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package net.sf.openrocket.document;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import net.sf.openrocket.l10n.Translator;
|
||||||
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
|
import net.sf.openrocket.rocketcomponent.Stage;
|
||||||
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
|
public class OpenRocketDocumentFactory {
|
||||||
|
|
||||||
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
|
public static OpenRocketDocument createNewRocket() {
|
||||||
|
Rocket rocket = new Rocket();
|
||||||
|
Stage stage = new Stage();
|
||||||
|
//// Sustainer
|
||||||
|
stage.setName(trans.get("BasicFrame.StageName.Sustainer"));
|
||||||
|
rocket.addChild(stage);
|
||||||
|
OpenRocketDocument doc = new OpenRocketDocument(rocket, (File) null, false);
|
||||||
|
doc.setSaved(true);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OpenRocketDocument createDocumentFromRocket(Rocket r) {
|
||||||
|
OpenRocketDocument doc = new OpenRocketDocument(r, (File) null, false);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OpenRocketDocument createDocumentForFile(File filename, boolean isContainer) {
|
||||||
|
Rocket rocket = new Rocket();
|
||||||
|
OpenRocketDocument doc = new OpenRocketDocument(rocket, filename, isContainer);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OpenRocketDocument createDocumentForUrl(URL filename, boolean isContainer) {
|
||||||
|
Rocket rocket = new Rocket();
|
||||||
|
OpenRocketDocument doc = new OpenRocketDocument(rocket, filename, isContainer);
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.sf.openrocket.document;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import net.sf.openrocket.document.attachments.ZipFileAttachment;
|
||||||
|
|
||||||
|
public class ZipFileAttachmentFactory implements AttachmentFactory<Attachment> {
|
||||||
|
|
||||||
|
private final URL zipFile;
|
||||||
|
|
||||||
|
public ZipFileAttachmentFactory(URL zipFile) {
|
||||||
|
super();
|
||||||
|
this.zipFile = zipFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Attachment getAttachment(String name) {
|
||||||
|
return new ZipFileAttachment(name, zipFile);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package net.sf.openrocket.document.attachments;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import net.sf.openrocket.document.Attachment;
|
||||||
|
|
||||||
|
public abstract class BaseAttachment implements Attachment {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public BaseAttachment(String name) {
|
||||||
|
super();
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract InputStream getBytes() throws FileNotFoundException, IOException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Attachment o) {
|
||||||
|
if (!(o instanceof BaseAttachment)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return this.name.compareTo(((BaseAttachment) o).name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package net.sf.openrocket.document.attachments;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import net.sf.openrocket.document.Attachment;
|
||||||
|
|
||||||
|
public class FileSystemAttachment extends BaseAttachment implements Attachment {
|
||||||
|
|
||||||
|
private final File location;
|
||||||
|
|
||||||
|
public FileSystemAttachment(String name, File location) {
|
||||||
|
super(name);
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getBytes() throws FileNotFoundException, IOException {
|
||||||
|
return new FileInputStream(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package net.sf.openrocket.document.attachments;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
import net.sf.openrocket.document.Attachment;
|
||||||
|
import net.sf.openrocket.util.FileUtils;
|
||||||
|
|
||||||
|
public class ZipFileAttachment extends BaseAttachment implements Attachment {
|
||||||
|
|
||||||
|
private final URL zipFileLocation;
|
||||||
|
|
||||||
|
public ZipFileAttachment(String name, URL zipFileLocation) {
|
||||||
|
super(name);
|
||||||
|
this.zipFileLocation = zipFileLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getBytes() throws FileNotFoundException, IOException {
|
||||||
|
String name = getName();
|
||||||
|
|
||||||
|
ZipInputStream zis = new ZipInputStream(zipFileLocation.openStream());
|
||||||
|
|
||||||
|
try {
|
||||||
|
ZipEntry entry = zis.getNextEntry();
|
||||||
|
while (entry != null) {
|
||||||
|
if (entry.getName().equals(name)) {
|
||||||
|
byte[] bytes = FileUtils.readBytes(zis);
|
||||||
|
return new ByteArrayInputStream(bytes);
|
||||||
|
}
|
||||||
|
entry = zis.getNextEntry();
|
||||||
|
}
|
||||||
|
throw new FileNotFoundException("Unable to locate decal for name " + name);
|
||||||
|
} finally {
|
||||||
|
zis.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,5 @@
|
|||||||
package net.sf.openrocket.file;
|
package net.sf.openrocket.file;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@ -19,11 +15,11 @@ public abstract class AbstractRocketLoader implements RocketLoader {
|
|||||||
* Loads a rocket from the specified InputStream.
|
* Loads a rocket from the specified InputStream.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final OpenRocketDocument load(InputStream source, MotorFinder motorFinder) throws RocketLoadException {
|
public final void load(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws RocketLoadException {
|
||||||
warnings.clear();
|
warnings.clear();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return loadFromStream(source, motorFinder);
|
loadFromStream(doc, source, motorFinder);
|
||||||
} catch (RocketLoadException e) {
|
} catch (RocketLoadException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -39,7 +35,7 @@ public abstract class AbstractRocketLoader implements RocketLoader {
|
|||||||
*
|
*
|
||||||
* @throws RocketLoadException if an error occurs during loading.
|
* @throws RocketLoadException if an error occurs during loading.
|
||||||
*/
|
*/
|
||||||
protected abstract OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws IOException,
|
protected abstract void loadFromStream(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws IOException,
|
||||||
RocketLoadException;
|
RocketLoadException;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
package net.sf.openrocket.file;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class FileInfo {
|
|
||||||
|
|
||||||
public final URL fileURL;
|
|
||||||
public final File directory;
|
|
||||||
|
|
||||||
public FileInfo(File sourceFile) {
|
|
||||||
URL theURL = null;
|
|
||||||
try {
|
|
||||||
theURL = sourceFile.toURI().toURL();
|
|
||||||
} catch (MalformedURLException mex) {
|
|
||||||
}
|
|
||||||
this.fileURL = theURL;
|
|
||||||
this.directory = sourceFile.getParentFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileInfo(URL sourceURL) {
|
|
||||||
this.fileURL = sourceURL;
|
|
||||||
this.directory = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URL getFileURL() {
|
|
||||||
return fileURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getDirectory() {
|
|
||||||
return directory;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -13,6 +13,7 @@ import java.util.zip.ZipInputStream;
|
|||||||
|
|
||||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||||
import net.sf.openrocket.file.openrocket.importt.OpenRocketLoader;
|
import net.sf.openrocket.file.openrocket.importt.OpenRocketLoader;
|
||||||
import net.sf.openrocket.file.rocksim.importt.RocksimLoader;
|
import net.sf.openrocket.file.rocksim.importt.RocksimLoader;
|
||||||
import net.sf.openrocket.util.ArrayUtils;
|
import net.sf.openrocket.util.ArrayUtils;
|
||||||
@ -38,33 +39,41 @@ public class GeneralRocketLoader {
|
|||||||
private static final byte[] ROCKSIM_SIGNATURE = TextUtil.asciiBytes("<RockSimDoc");
|
private static final byte[] ROCKSIM_SIGNATURE = TextUtil.asciiBytes("<RockSimDoc");
|
||||||
|
|
||||||
private final OpenRocketLoader openRocketLoader = new OpenRocketLoader();
|
private final OpenRocketLoader openRocketLoader = new OpenRocketLoader();
|
||||||
private final FileInfo fileInfo;
|
|
||||||
|
|
||||||
private final RocksimLoader rocksimLoader = new RocksimLoader();
|
private final RocksimLoader rocksimLoader = new RocksimLoader();
|
||||||
|
|
||||||
|
private File baseFile;
|
||||||
|
private URL jarURL;
|
||||||
|
|
||||||
|
private final MotorFinder motorFinder;
|
||||||
|
|
||||||
public GeneralRocketLoader(File file) {
|
public GeneralRocketLoader(File file) {
|
||||||
this.fileInfo = new FileInfo(file);
|
this.baseFile = file;
|
||||||
|
this.jarURL = null;
|
||||||
|
this.motorFinder = new DatabaseMotorFinder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeneralRocketLoader(URL jarURL) {
|
public GeneralRocketLoader(URL jarURL) {
|
||||||
this.fileInfo = new FileInfo(jarURL);
|
this.baseFile = null;
|
||||||
|
this.jarURL = jarURL;
|
||||||
|
this.motorFinder = new DatabaseMotorFinder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a rocket from the specified File object.
|
* Loads a rocket from the File object used in the constructor
|
||||||
*/
|
*/
|
||||||
public final OpenRocketDocument load(File source, MotorFinder motorFinder) throws RocketLoadException {
|
public final OpenRocketDocument load() throws RocketLoadException {
|
||||||
warnings.clear();
|
warnings.clear();
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
stream = new BufferedInputStream(new FileInputStream(source));
|
stream = new BufferedInputStream(new FileInputStream(baseFile));
|
||||||
OpenRocketDocument doc = load(stream, motorFinder);
|
OpenRocketDocument doc = load(stream);
|
||||||
return doc;
|
return doc;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RocketLoadException("Exception loading file: " + source, e);
|
throw new RocketLoadException("Exception loading file: " + baseFile, e);
|
||||||
} finally {
|
} finally {
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
try {
|
try {
|
||||||
@ -76,10 +85,9 @@ public class GeneralRocketLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final OpenRocketDocument load(InputStream source, MotorFinder motorFinder) throws RocketLoadException {
|
public final OpenRocketDocument load(InputStream source) throws RocketLoadException {
|
||||||
try {
|
try {
|
||||||
OpenRocketDocument doc = loadFromStream(source, motorFinder);
|
OpenRocketDocument doc = loadFromStream(source);
|
||||||
doc.setBaseFile(fileInfo);
|
|
||||||
return doc;
|
return doc;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RocketLoadException("Exception loading stream", e);
|
throw new RocketLoadException("Exception loading stream", e);
|
||||||
@ -90,7 +98,7 @@ public class GeneralRocketLoader {
|
|||||||
return warnings;
|
return warnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws IOException,
|
private OpenRocketDocument loadFromStream(InputStream source) throws IOException,
|
||||||
RocketLoadException {
|
RocketLoadException {
|
||||||
|
|
||||||
// Check for mark() support
|
// Check for mark() support
|
||||||
@ -114,13 +122,19 @@ public class GeneralRocketLoader {
|
|||||||
|
|
||||||
// Check for GZIP
|
// Check for GZIP
|
||||||
if (buffer[0] == GZIP_SIGNATURE[0] && buffer[1] == GZIP_SIGNATURE[1]) {
|
if (buffer[0] == GZIP_SIGNATURE[0] && buffer[1] == GZIP_SIGNATURE[1]) {
|
||||||
OpenRocketDocument doc = loadFromStream(new GZIPInputStream(source), motorFinder);
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(baseFile, false);
|
||||||
doc.setIsZipFile(false);
|
loadFromStream(doc, new GZIPInputStream(source));
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for ZIP (for future compatibility)
|
// Check for ZIP (for future compatibility)
|
||||||
if (buffer[0] == ZIP_SIGNATURE[0] && buffer[1] == ZIP_SIGNATURE[1]) {
|
if (buffer[0] == ZIP_SIGNATURE[0] && buffer[1] == ZIP_SIGNATURE[1]) {
|
||||||
|
OpenRocketDocument doc;
|
||||||
|
if (baseFile != null) {
|
||||||
|
doc = OpenRocketDocumentFactory.createDocumentForFile(baseFile, true);
|
||||||
|
} else {
|
||||||
|
doc = OpenRocketDocumentFactory.createDocumentForUrl(jarURL, true);
|
||||||
|
}
|
||||||
// Search for entry with name *.ork
|
// Search for entry with name *.ork
|
||||||
ZipInputStream in = new ZipInputStream(source);
|
ZipInputStream in = new ZipInputStream(source);
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -129,25 +143,52 @@ public class GeneralRocketLoader {
|
|||||||
throw new RocketLoadException("Unsupported or corrupt file.");
|
throw new RocketLoadException("Unsupported or corrupt file.");
|
||||||
}
|
}
|
||||||
if (entry.getName().matches(".*\\.[oO][rR][kK]$")) {
|
if (entry.getName().matches(".*\\.[oO][rR][kK]$")) {
|
||||||
OpenRocketDocument doc = loadFromStream(in, motorFinder);
|
loadFromStream(doc, in);
|
||||||
doc.setIsZipFile(true);
|
|
||||||
return doc;
|
return doc;
|
||||||
} else if (entry.getName().matches(".*\\.[rR][kK][tT]$")) {
|
} else if (entry.getName().matches(".*\\.[rR][kK][tT]$")) {
|
||||||
OpenRocketDocument doc = loadFromStream(in, motorFinder);
|
loadFromStream(doc, in);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OpenRocketDocument doc = null;
|
||||||
|
if (baseFile != null) {
|
||||||
|
doc = OpenRocketDocumentFactory.createDocumentForFile(baseFile, false);
|
||||||
|
} else {
|
||||||
|
doc = OpenRocketDocumentFactory.createDocumentForUrl(jarURL, false);
|
||||||
|
}
|
||||||
|
loadFromStream(doc, source);
|
||||||
|
return doc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadFromStream(OpenRocketDocument doc, InputStream source) throws IOException, RocketLoadException {
|
||||||
|
|
||||||
|
// Check for mark() support
|
||||||
|
if (!source.markSupported()) {
|
||||||
|
source = new BufferedInputStream(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read using mark()
|
||||||
|
byte[] buffer = new byte[READ_BYTES];
|
||||||
|
int count;
|
||||||
|
source.mark(READ_BYTES + 10);
|
||||||
|
count = source.read(buffer);
|
||||||
|
source.reset();
|
||||||
|
|
||||||
|
if (count < 10) {
|
||||||
|
throw new RocketLoadException("Unsupported or corrupt file.");
|
||||||
|
}
|
||||||
|
|
||||||
// Check for OpenRocket
|
// Check for OpenRocket
|
||||||
int match = 0;
|
int match = 0;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (buffer[i] == OPENROCKET_SIGNATURE[match]) {
|
if (buffer[i] == OPENROCKET_SIGNATURE[match]) {
|
||||||
match++;
|
match++;
|
||||||
if (match == OPENROCKET_SIGNATURE.length) {
|
if (match == OPENROCKET_SIGNATURE.length) {
|
||||||
OpenRocketDocument doc = loadUsing(openRocketLoader, source, motorFinder);
|
loadUsing(doc, openRocketLoader, source);
|
||||||
doc.setIsZipFile(false);
|
return;
|
||||||
return doc;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match = 0;
|
match = 0;
|
||||||
@ -156,18 +197,16 @@ public class GeneralRocketLoader {
|
|||||||
|
|
||||||
byte[] typeIdentifier = ArrayUtils.copyOf(buffer, ROCKSIM_SIGNATURE.length);
|
byte[] typeIdentifier = ArrayUtils.copyOf(buffer, ROCKSIM_SIGNATURE.length);
|
||||||
if (Arrays.equals(ROCKSIM_SIGNATURE, typeIdentifier)) {
|
if (Arrays.equals(ROCKSIM_SIGNATURE, typeIdentifier)) {
|
||||||
OpenRocketDocument doc = loadUsing(rocksimLoader, source, motorFinder);
|
loadUsing(doc, rocksimLoader, source);
|
||||||
doc.setIsZipFile(false);
|
return;
|
||||||
return doc;
|
|
||||||
}
|
}
|
||||||
throw new RocketLoadException("Unsupported or corrupt file.");
|
throw new RocketLoadException("Unsupported or corrupt file.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OpenRocketDocument loadUsing(RocketLoader loader, InputStream source, MotorFinder motorFinder)
|
private void loadUsing(OpenRocketDocument doc, RocketLoader loader, InputStream source) throws RocketLoadException {
|
||||||
throws RocketLoadException {
|
|
||||||
warnings.clear();
|
warnings.clear();
|
||||||
OpenRocketDocument doc = loader.load(source, motorFinder);
|
loader.load(doc, source, motorFinder);
|
||||||
warnings.addAll(loader.getWarnings());
|
warnings.addAll(loader.getWarnings());
|
||||||
return doc;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import net.sf.openrocket.document.OpenRocketDocument;
|
|||||||
|
|
||||||
public interface RocketLoader {
|
public interface RocketLoader {
|
||||||
|
|
||||||
public OpenRocketDocument load(InputStream source, MotorFinder motorFinder) throws RocketLoadException;
|
public void load(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws RocketLoadException;
|
||||||
|
|
||||||
public WarningSet getWarnings();
|
public WarningSet getWarnings();
|
||||||
|
|
||||||
|
@ -7,15 +7,12 @@ import net.sf.openrocket.aerodynamics.WarningSet;
|
|||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
import net.sf.openrocket.file.simplesax.AbstractElementHandler;
|
||||||
import net.sf.openrocket.file.simplesax.ElementHandler;
|
import net.sf.openrocket.file.simplesax.ElementHandler;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the content of the <openrocket> tag.
|
* Handles the content of the <openrocket> tag.
|
||||||
*/
|
*/
|
||||||
class OpenRocketContentHandler extends AbstractElementHandler {
|
class OpenRocketContentHandler extends AbstractElementHandler {
|
||||||
private final DocumentLoadingContext context;
|
private final DocumentLoadingContext context;
|
||||||
private final OpenRocketDocument doc;
|
|
||||||
private final Rocket rocket;
|
|
||||||
|
|
||||||
private boolean rocketDefined = false;
|
private boolean rocketDefined = false;
|
||||||
private boolean simulationsDefined = false;
|
private boolean simulationsDefined = false;
|
||||||
@ -23,15 +20,12 @@ class OpenRocketContentHandler extends AbstractElementHandler {
|
|||||||
|
|
||||||
public OpenRocketContentHandler(DocumentLoadingContext context) {
|
public OpenRocketContentHandler(DocumentLoadingContext context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.rocket = new Rocket();
|
|
||||||
this.doc = new OpenRocketDocument(rocket);
|
|
||||||
context.setOpenRocketDocument(doc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenRocketDocument getDocument() {
|
public OpenRocketDocument getDocument() {
|
||||||
if (!rocketDefined)
|
if (!rocketDefined)
|
||||||
return null;
|
return null;
|
||||||
return doc;
|
return context.getOpenRocketDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,7 +40,7 @@ class OpenRocketContentHandler extends AbstractElementHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
rocketDefined = true;
|
rocketDefined = true;
|
||||||
return new ComponentParameterHandler(rocket, context);
|
return new ComponentParameterHandler(getDocument().getRocket(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.equals("datatypes")) {
|
if (element.equals("datatypes")) {
|
||||||
@ -66,7 +60,7 @@ class OpenRocketContentHandler extends AbstractElementHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
simulationsDefined = true;
|
simulationsDefined = true;
|
||||||
return new SimulationsHandler(doc, context);
|
return new SimulationsHandler(getDocument(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
|
warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
|
||||||
|
@ -35,11 +35,12 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws RocketLoadException,
|
public void loadFromStream(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws RocketLoadException,
|
||||||
IOException {
|
IOException {
|
||||||
log.info("Loading .ork file");
|
log.info("Loading .ork file");
|
||||||
DocumentLoadingContext context = new DocumentLoadingContext();
|
DocumentLoadingContext context = new DocumentLoadingContext();
|
||||||
context.setMotorFinder(motorFinder);
|
context.setMotorFinder(motorFinder);
|
||||||
|
context.setOpenRocketDocument(doc);
|
||||||
|
|
||||||
InputSource xmlSource = new InputSource(source);
|
InputSource xmlSource = new InputSource(source);
|
||||||
OpenRocketHandler handler = new OpenRocketHandler(context);
|
OpenRocketHandler handler = new OpenRocketHandler(context);
|
||||||
@ -52,8 +53,6 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
|||||||
throw new RocketLoadException("Malformed XML in input.", e);
|
throw new RocketLoadException("Malformed XML in input.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OpenRocketDocument doc = handler.getDocument();
|
|
||||||
doc.getDefaultConfiguration().setAllStages();
|
doc.getDefaultConfiguration().setAllStages();
|
||||||
|
|
||||||
// Deduce suitable time skip
|
// Deduce suitable time skip
|
||||||
@ -88,7 +87,6 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
|||||||
|
|
||||||
doc.clearUndo();
|
doc.clearUndo();
|
||||||
log.info("Loading done");
|
log.info("Loading done");
|
||||||
return doc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,118 +27,123 @@ import org.xml.sax.SAXException;
|
|||||||
* Limitations: Rocksim flight simulations are not imported; tube fins are not supported; Rocksim 'pods' are not supported.
|
* Limitations: Rocksim flight simulations are not imported; tube fins are not supported; Rocksim 'pods' are not supported.
|
||||||
*/
|
*/
|
||||||
public class RocksimHandler extends AbstractElementHandler {
|
public class RocksimHandler extends AbstractElementHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main content handler.
|
* The main content handler.
|
||||||
*/
|
*/
|
||||||
private RocksimContentHandler handler = null;
|
private RocksimContentHandler handler = null;
|
||||||
|
|
||||||
/**
|
private final OpenRocketDocument document;
|
||||||
* Return the OpenRocketDocument read from the file, or <code>null</code> if a document
|
|
||||||
* has not been read yet.
|
public RocksimHandler(OpenRocketDocument document) {
|
||||||
*
|
super();
|
||||||
* @return the document read, or null.
|
this.document = document;
|
||||||
*/
|
}
|
||||||
public OpenRocketDocument getDocument() {
|
|
||||||
return handler.getDocument();
|
/**
|
||||||
}
|
* Return the OpenRocketDocument read from the file, or <code>null</code> if a document
|
||||||
|
* has not been read yet.
|
||||||
@Override
|
*
|
||||||
public ElementHandler openElement(String element, HashMap<String, String> attributes,
|
* @return the document read, or null.
|
||||||
WarningSet warnings) {
|
*/
|
||||||
|
public OpenRocketDocument getDocument() {
|
||||||
// Check for unknown elements
|
return document;
|
||||||
if (!element.equals("RockSimDocument")) {
|
}
|
||||||
warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
|
|
||||||
return null;
|
@Override
|
||||||
}
|
public ElementHandler openElement(String element, HashMap<String, String> attributes,
|
||||||
|
WarningSet warnings) {
|
||||||
// Check for first call
|
|
||||||
if (handler != null) {
|
// Check for unknown elements
|
||||||
warnings.add(Warning.fromString("Multiple document elements found, ignoring later "
|
if (!element.equals("RockSimDocument")) {
|
||||||
+ "ones."));
|
warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
handler = new RocksimContentHandler();
|
// Check for first call
|
||||||
return handler;
|
if (handler != null) {
|
||||||
}
|
warnings.add(Warning.fromString("Multiple document elements found, ignoring later "
|
||||||
|
+ "ones."));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
handler = new RocksimContentHandler(document);
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the content of the <DesignInformation> tag.
|
* Handles the content of the <DesignInformation> tag.
|
||||||
*/
|
*/
|
||||||
class RocksimContentHandler extends AbstractElementHandler {
|
class RocksimContentHandler extends AbstractElementHandler {
|
||||||
/**
|
/**
|
||||||
* The OpenRocketDocument that is the container for the rocket.
|
* The OpenRocketDocument that is the container for the rocket.
|
||||||
*/
|
*/
|
||||||
private final OpenRocketDocument doc;
|
private final OpenRocketDocument doc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The top-level component, from which all child components are added.
|
* The top-level component, from which all child components are added.
|
||||||
*/
|
*/
|
||||||
private final Rocket rocket;
|
private final Rocket rocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rocksim file version.
|
* The rocksim file version.
|
||||||
*/
|
*/
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
/**
|
public RocksimContentHandler(OpenRocketDocument doc) {
|
||||||
* Constructor.
|
super();
|
||||||
*/
|
this.doc = doc;
|
||||||
public RocksimContentHandler() {
|
this.rocket = doc.getRocket();
|
||||||
this.rocket = new Rocket();
|
}
|
||||||
this.doc = new OpenRocketDocument(rocket);
|
|
||||||
}
|
/**
|
||||||
|
* Get the OpenRocket document that has been created from parsing the Rocksim design file.
|
||||||
/**
|
*
|
||||||
* Get the OpenRocket document that has been created from parsing the Rocksim design file.
|
* @return the instantiated OpenRocketDocument
|
||||||
*
|
*/
|
||||||
* @return the instantiated OpenRocketDocument
|
public OpenRocketDocument getDocument() {
|
||||||
*/
|
return doc;
|
||||||
public OpenRocketDocument getDocument() {
|
}
|
||||||
return doc;
|
|
||||||
}
|
@Override
|
||||||
|
public ElementHandler openElement(String element, HashMap<String, String> attributes,
|
||||||
@Override
|
WarningSet warnings) {
|
||||||
public ElementHandler openElement(String element, HashMap<String, String> attributes,
|
if (RocksimCommonConstants.DESIGN_INFORMATION.equals(element)) {
|
||||||
WarningSet warnings) {
|
//The next sub-element is "RocketDesign", which is really the only thing that matters. Rather than
|
||||||
if (RocksimCommonConstants.DESIGN_INFORMATION.equals(element)) {
|
//create another handler just for that element, handle it here.
|
||||||
//The next sub-element is "RocketDesign", which is really the only thing that matters. Rather than
|
return this;
|
||||||
//create another handler just for that element, handle it here.
|
}
|
||||||
return this;
|
if (RocksimCommonConstants.FILE_VERSION.equals(element)) {
|
||||||
}
|
return PlainTextHandler.INSTANCE;
|
||||||
if (RocksimCommonConstants.FILE_VERSION.equals(element)) {
|
}
|
||||||
return PlainTextHandler.INSTANCE;
|
if (RocksimCommonConstants.ROCKET_DESIGN.equals(element)) {
|
||||||
}
|
return new RocketDesignHandler(doc, rocket);
|
||||||
if (RocksimCommonConstants.ROCKET_DESIGN.equals(element)) {
|
}
|
||||||
return new RocketDesignHandler(doc, rocket);
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
@Override
|
||||||
|
public void closeElement(String element, HashMap<String, String> attributes,
|
||||||
@Override
|
String content, WarningSet warnings) throws SAXException {
|
||||||
public void closeElement(String element, HashMap<String, String> attributes,
|
/**
|
||||||
String content, WarningSet warnings) throws SAXException {
|
* SAX handler for Rocksim file version number. The value is not used currently, but could be used in the future
|
||||||
/**
|
* for backward/forward compatibility reasons (different lower level handlers could be called via a strategy pattern).
|
||||||
* SAX handler for Rocksim file version number. The value is not used currently, but could be used in the future
|
*/
|
||||||
* for backward/forward compatibility reasons (different lower level handlers could be called via a strategy pattern).
|
if (RocksimCommonConstants.FILE_VERSION.equals(element)) {
|
||||||
*/
|
version = content;
|
||||||
if (RocksimCommonConstants.FILE_VERSION.equals(element)) {
|
}
|
||||||
version = content;
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* Answer the file version.
|
||||||
/**
|
*
|
||||||
* Answer the file version.
|
* @return the version of the Rocksim design file
|
||||||
*
|
*/
|
||||||
* @return the version of the Rocksim design file
|
public String getVersion() {
|
||||||
*/
|
return version;
|
||||||
public String getVersion() {
|
}
|
||||||
return version;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -149,165 +154,164 @@ class RocksimContentHandler extends AbstractElementHandler {
|
|||||||
*/
|
*/
|
||||||
class RocketDesignHandler extends AbstractElementHandler {
|
class RocketDesignHandler extends AbstractElementHandler {
|
||||||
private final OpenRocketDocument document;
|
private final OpenRocketDocument document;
|
||||||
/**
|
/**
|
||||||
* The parent component.
|
* The parent component.
|
||||||
*/
|
*/
|
||||||
private final RocketComponent component;
|
private final RocketComponent component;
|
||||||
/**
|
/**
|
||||||
* The parsed stage count. Defaults to 1.
|
* The parsed stage count. Defaults to 1.
|
||||||
*/
|
*/
|
||||||
private int stageCount = 1;
|
private int stageCount = 1;
|
||||||
/**
|
/**
|
||||||
* The overridden stage 1 mass.
|
* The overridden stage 1 mass.
|
||||||
*/
|
*/
|
||||||
private double stage1Mass = 0d;
|
private double stage1Mass = 0d;
|
||||||
/**
|
/**
|
||||||
* The overridden stage 2 mass.
|
* The overridden stage 2 mass.
|
||||||
*/
|
*/
|
||||||
private double stage2Mass = 0d;
|
private double stage2Mass = 0d;
|
||||||
/**
|
/**
|
||||||
* The overridden stage 3 mass.
|
* The overridden stage 3 mass.
|
||||||
*/
|
*/
|
||||||
private double stage3Mass = 0d;
|
private double stage3Mass = 0d;
|
||||||
/**
|
/**
|
||||||
* The overridden stage 1 Cg.
|
* The overridden stage 1 Cg.
|
||||||
*/
|
*/
|
||||||
private double stage1CG = 0d;
|
private double stage1CG = 0d;
|
||||||
/**
|
/**
|
||||||
* The overridden stage 2 Cg.
|
* The overridden stage 2 Cg.
|
||||||
*/
|
*/
|
||||||
private double stage2CG = 0d;
|
private double stage2CG = 0d;
|
||||||
/**
|
/**
|
||||||
* The overridden stage 3 Cg.
|
* The overridden stage 3 Cg.
|
||||||
*/
|
*/
|
||||||
private double stage3CG = 0d;
|
private double stage3CG = 0d;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param c the parent component
|
* @param c the parent component
|
||||||
*/
|
*/
|
||||||
public RocketDesignHandler(OpenRocketDocument document, RocketComponent c) {
|
public RocketDesignHandler(OpenRocketDocument document, RocketComponent c) {
|
||||||
this.document = document;
|
this.document = document;
|
||||||
component = c;
|
component = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||||
/**
|
/**
|
||||||
* In Rocksim stages are from the top down, so a single stage rocket is actually stage '3'. A 2-stage
|
* In Rocksim stages are from the top down, so a single stage rocket is actually stage '3'. A 2-stage
|
||||||
* rocket defines stage '2' as the initial booster with stage '3' sitting atop it. And so on.
|
* rocket defines stage '2' as the initial booster with stage '3' sitting atop it. And so on.
|
||||||
*/
|
*/
|
||||||
if ("Stage3Parts".equals(element)) {
|
if ("Stage3Parts".equals(element)) {
|
||||||
final Stage stage = new Stage();
|
final Stage stage = new Stage();
|
||||||
if (stage3Mass > 0.0d) {
|
if (stage3Mass > 0.0d) {
|
||||||
stage.setMassOverridden(true);
|
stage.setMassOverridden(true);
|
||||||
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
||||||
stage.setOverrideMass(stage3Mass);
|
stage.setOverrideMass(stage3Mass);
|
||||||
}
|
}
|
||||||
if (stage3CG > 0.0d) {
|
if (stage3CG > 0.0d) {
|
||||||
stage.setCGOverridden(true);
|
stage.setCGOverridden(true);
|
||||||
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
||||||
stage.setOverrideCGX(stage3CG);
|
stage.setOverrideCGX(stage3CG);
|
||||||
}
|
}
|
||||||
component.addChild(stage);
|
component.addChild(stage);
|
||||||
return new StageHandler(document, stage);
|
return new StageHandler(document, stage);
|
||||||
}
|
}
|
||||||
if ("Stage2Parts".equals(element)) {
|
if ("Stage2Parts".equals(element)) {
|
||||||
if (stageCount >= 2) {
|
if (stageCount >= 2) {
|
||||||
final Stage stage = new Stage();
|
final Stage stage = new Stage();
|
||||||
if (stage2Mass > 0.0d) {
|
if (stage2Mass > 0.0d) {
|
||||||
stage.setMassOverridden(true);
|
stage.setMassOverridden(true);
|
||||||
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
||||||
stage.setOverrideMass(stage2Mass);
|
stage.setOverrideMass(stage2Mass);
|
||||||
}
|
}
|
||||||
if (stage2CG > 0.0d) {
|
if (stage2CG > 0.0d) {
|
||||||
stage.setCGOverridden(true);
|
stage.setCGOverridden(true);
|
||||||
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
||||||
stage.setOverrideCGX(stage2CG);
|
stage.setOverrideCGX(stage2CG);
|
||||||
}
|
}
|
||||||
component.addChild(stage);
|
component.addChild(stage);
|
||||||
return new StageHandler(document, stage);
|
return new StageHandler(document, stage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ("Stage1Parts".equals(element)) {
|
if ("Stage1Parts".equals(element)) {
|
||||||
if (stageCount == 3) {
|
if (stageCount == 3) {
|
||||||
final Stage stage = new Stage();
|
final Stage stage = new Stage();
|
||||||
if (stage1Mass > 0.0d) {
|
if (stage1Mass > 0.0d) {
|
||||||
stage.setMassOverridden(true);
|
stage.setMassOverridden(true);
|
||||||
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
||||||
stage.setOverrideMass(stage1Mass);
|
stage.setOverrideMass(stage1Mass);
|
||||||
}
|
}
|
||||||
if (stage1CG > 0.0d) {
|
if (stage1CG > 0.0d) {
|
||||||
stage.setCGOverridden(true);
|
stage.setCGOverridden(true);
|
||||||
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
stage.setOverrideSubcomponents(true); //Rocksim does not support this type of override
|
||||||
stage.setOverrideCGX(stage1CG);
|
stage.setOverrideCGX(stage1CG);
|
||||||
}
|
}
|
||||||
component.addChild(stage);
|
component.addChild(stage);
|
||||||
return new StageHandler(document, stage);
|
return new StageHandler(document, stage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (RocksimCommonConstants.NAME.equals(element)) {
|
if (RocksimCommonConstants.NAME.equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
if ("StageCount".equals(element)) {
|
if ("StageCount".equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
if ("Stage3Mass".equals(element)) {
|
if ("Stage3Mass".equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
if ("Stage2Mass".equals(element)) {
|
if ("Stage2Mass".equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
if ("Stage1Mass".equals(element)) {
|
if ("Stage1Mass".equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
if ("Stage3CG".equals(element)) {
|
if ("Stage3CG".equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
if ("Stage2CGAlone".equals(element)) {
|
if ("Stage2CGAlone".equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
if ("Stage1CGAlone".equals(element)) {
|
if ("Stage1CGAlone".equals(element)) {
|
||||||
return PlainTextHandler.INSTANCE;
|
return PlainTextHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeElement(String element, HashMap<String, String> attributes,
|
public void closeElement(String element, HashMap<String, String> attributes,
|
||||||
String content, WarningSet warnings) throws SAXException {
|
String content, WarningSet warnings) throws SAXException {
|
||||||
try {
|
try {
|
||||||
if (RocksimCommonConstants.NAME.equals(element)) {
|
if (RocksimCommonConstants.NAME.equals(element)) {
|
||||||
component.setName(content);
|
component.setName(content);
|
||||||
}
|
}
|
||||||
if ("StageCount".equals(element)) {
|
if ("StageCount".equals(element)) {
|
||||||
stageCount = Integer.parseInt(content);
|
stageCount = Integer.parseInt(content);
|
||||||
}
|
}
|
||||||
if ("Stage3Mass".equals(element)) {
|
if ("Stage3Mass".equals(element)) {
|
||||||
stage3Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
|
stage3Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
|
||||||
}
|
}
|
||||||
if ("Stage2Mass".equals(element)) {
|
if ("Stage2Mass".equals(element)) {
|
||||||
stage2Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
|
stage2Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
|
||||||
}
|
}
|
||||||
if ("Stage1Mass".equals(element)) {
|
if ("Stage1Mass".equals(element)) {
|
||||||
stage1Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
|
stage1Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
|
||||||
}
|
}
|
||||||
if ("Stage3CG".equals(element)) {
|
if ("Stage3CG".equals(element)) {
|
||||||
stage3CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
stage3CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
||||||
}
|
}
|
||||||
if ("Stage2CGAlone".equals(element)) {
|
if ("Stage2CGAlone".equals(element)) {
|
||||||
stage2CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
stage2CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
||||||
}
|
}
|
||||||
if ("Stage1CGAlone".equals(element)) {
|
if ("Stage1CGAlone".equals(element)) {
|
||||||
stage1CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
stage1CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
|
||||||
}
|
}
|
||||||
}
|
} catch (NumberFormatException nfe) {
|
||||||
catch (NumberFormatException nfe) {
|
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
||||||
warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -315,36 +319,36 @@ class RocketDesignHandler extends AbstractElementHandler {
|
|||||||
*/
|
*/
|
||||||
class StageHandler extends AbstractElementHandler {
|
class StageHandler extends AbstractElementHandler {
|
||||||
private final OpenRocketDocument document;
|
private final OpenRocketDocument document;
|
||||||
/**
|
/**
|
||||||
* The parent OpenRocket component.
|
* The parent OpenRocket component.
|
||||||
*/
|
*/
|
||||||
private final RocketComponent component;
|
private final RocketComponent component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param c the parent component
|
* @param c the parent component
|
||||||
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
* @throws IllegalArgumentException thrown if <code>c</code> is null
|
||||||
*/
|
*/
|
||||||
public StageHandler(OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
|
public StageHandler(OpenRocketDocument document, RocketComponent c) throws IllegalArgumentException {
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
throw new IllegalArgumentException("The stage component may not be null.");
|
throw new IllegalArgumentException("The stage component may not be null.");
|
||||||
}
|
}
|
||||||
this.document = document;
|
this.document = document;
|
||||||
component = c;
|
component = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
|
||||||
if (RocksimCommonConstants.NOSE_CONE.equals(element)) {
|
if (RocksimCommonConstants.NOSE_CONE.equals(element)) {
|
||||||
return new NoseConeHandler(document, component, warnings);
|
return new NoseConeHandler(document, component, warnings);
|
||||||
}
|
}
|
||||||
if (RocksimCommonConstants.BODY_TUBE.equals(element)) {
|
if (RocksimCommonConstants.BODY_TUBE.equals(element)) {
|
||||||
return new BodyTubeHandler(document, component, warnings);
|
return new BodyTubeHandler(document, component, warnings);
|
||||||
}
|
}
|
||||||
if (RocksimCommonConstants.TRANSITION.equals(element)) {
|
if (RocksimCommonConstants.TRANSITION.equals(element)) {
|
||||||
return new TransitionHandler(document, component, warnings);
|
return new TransitionHandler(document, component, warnings);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,11 @@ public class RocksimLoader extends AbstractRocketLoader {
|
|||||||
* if an error occurs during loading.
|
* if an error occurs during loading.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws IOException, RocketLoadException {
|
protected void loadFromStream(OpenRocketDocument doc, InputStream source, MotorFinder motorFinder) throws IOException, RocketLoadException {
|
||||||
|
|
||||||
InputSource xmlSource = new InputSource(source);
|
InputSource xmlSource = new InputSource(source);
|
||||||
|
|
||||||
RocksimHandler handler = new RocksimHandler();
|
RocksimHandler handler = new RocksimHandler(doc);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SimpleSAX.readXML(xmlSource, handler, warnings);
|
SimpleSAX.readXML(xmlSource, handler, warnings);
|
||||||
@ -51,9 +51,7 @@ public class RocksimLoader extends AbstractRocketLoader {
|
|||||||
throw new RocketLoadException("Malformed XML in input.", e);
|
throw new RocketLoadException("Malformed XML in input.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final OpenRocketDocument document = handler.getDocument();
|
doc.setFile(null);
|
||||||
document.setFile(null);
|
doc.clearUndo();
|
||||||
document.clearUndo();
|
|
||||||
return document;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import javax.swing.filechooser.FileNameExtensionFilter;
|
|||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.file.DatabaseMotorFinder;
|
|
||||||
import net.sf.openrocket.file.GeneralRocketLoader;
|
import net.sf.openrocket.file.GeneralRocketLoader;
|
||||||
import net.sf.openrocket.file.RocketLoadException;
|
import net.sf.openrocket.file.RocketLoadException;
|
||||||
import net.sf.openrocket.gui.components.UnitSelector;
|
import net.sf.openrocket.gui.components.UnitSelector;
|
||||||
@ -98,7 +97,7 @@ public class CustomExpressionPanel extends JPanel {
|
|||||||
// Load expressions from selected document
|
// Load expressions from selected document
|
||||||
GeneralRocketLoader loader = new GeneralRocketLoader(importFile);
|
GeneralRocketLoader loader = new GeneralRocketLoader(importFile);
|
||||||
try {
|
try {
|
||||||
OpenRocketDocument importedDocument = loader.load(importFile, new DatabaseMotorFinder());
|
OpenRocketDocument importedDocument = loader.load();
|
||||||
for (CustomExpression exp : importedDocument.getCustomExpressions()) {
|
for (CustomExpression exp : importedDocument.getCustomExpressions()) {
|
||||||
doc.addCustomExpression(exp);
|
doc.addCustomExpression(exp);
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ import javax.swing.tree.TreeSelectionModel;
|
|||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||||
import net.sf.openrocket.document.StorageOptions;
|
import net.sf.openrocket.document.StorageOptions;
|
||||||
import net.sf.openrocket.file.GeneralRocketSaver;
|
import net.sf.openrocket.file.GeneralRocketSaver;
|
||||||
import net.sf.openrocket.file.RocketLoadException;
|
import net.sf.openrocket.file.RocketLoadException;
|
||||||
@ -96,7 +97,6 @@ import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
|||||||
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.Stage;
|
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.BugException;
|
import net.sf.openrocket.util.BugException;
|
||||||
import net.sf.openrocket.util.MemoryManagement;
|
import net.sf.openrocket.util.MemoryManagement;
|
||||||
@ -839,7 +839,7 @@ public class BasicFrame extends JFrame {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenRocketDocument doc = new OpenRocketDocument(r);
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentFromRocket(r);
|
||||||
doc.setSaved(true);
|
doc.setSaved(true);
|
||||||
BasicFrame frame = new BasicFrame(doc);
|
BasicFrame frame = new BasicFrame(doc);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@ -855,7 +855,7 @@ public class BasicFrame extends JFrame {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
log.user("Create Iso-Haisu selected");
|
log.user("Create Iso-Haisu selected");
|
||||||
Rocket r = TestRockets.makeIsoHaisu();
|
Rocket r = TestRockets.makeIsoHaisu();
|
||||||
OpenRocketDocument doc = new OpenRocketDocument(r);
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentFromRocket(r);
|
||||||
doc.setSaved(true);
|
doc.setSaved(true);
|
||||||
BasicFrame frame = new BasicFrame(doc);
|
BasicFrame frame = new BasicFrame(doc);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@ -870,7 +870,7 @@ public class BasicFrame extends JFrame {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
log.user("Create Big Blue selected");
|
log.user("Create Big Blue selected");
|
||||||
Rocket r = TestRockets.makeBigBlue();
|
Rocket r = TestRockets.makeBigBlue();
|
||||||
OpenRocketDocument doc = new OpenRocketDocument(r);
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentFromRocket(r);
|
||||||
doc.setSaved(true);
|
doc.setSaved(true);
|
||||||
BasicFrame frame = new BasicFrame(doc);
|
BasicFrame frame = new BasicFrame(doc);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
@ -1465,19 +1465,11 @@ public class BasicFrame extends JFrame {
|
|||||||
public static void newAction() {
|
public static void newAction() {
|
||||||
log.info("New action initiated");
|
log.info("New action initiated");
|
||||||
|
|
||||||
Rocket rocket = new Rocket();
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createNewRocket();
|
||||||
Stage stage = new Stage();
|
|
||||||
//// Sustainer
|
|
||||||
stage.setName(trans.get("BasicFrame.StageName.Sustainer"));
|
|
||||||
rocket.addChild(stage);
|
|
||||||
OpenRocketDocument doc = new OpenRocketDocument(rocket);
|
|
||||||
doc.setSaved(true);
|
|
||||||
|
|
||||||
BasicFrame frame = new BasicFrame(doc);
|
BasicFrame frame = new BasicFrame(doc);
|
||||||
frame.replaceable = true;
|
frame.replaceable = true;
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
// kruland commented this out - I don't like it.
|
|
||||||
//ComponentConfigDialog.showDialog(frame, doc, rocket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +12,6 @@ import java.net.URL;
|
|||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
|
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.file.DatabaseMotorFinder;
|
|
||||||
import net.sf.openrocket.file.GeneralRocketLoader;
|
import net.sf.openrocket.file.GeneralRocketLoader;
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
@ -68,7 +67,7 @@ public class OpenFileWorker extends SwingWorker<OpenRocketDocument, Void> {
|
|||||||
is = new ProgressInputStream(is);
|
is = new ProgressInputStream(is);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OpenRocketDocument document = loader.load(is, new DatabaseMotorFinder());
|
OpenRocketDocument document = loader.load(is);
|
||||||
|
|
||||||
// Set document state
|
// Set document state
|
||||||
document.setFile(file);
|
document.setFile(file);
|
||||||
|
@ -6,7 +6,6 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.document.StorageOptions;
|
import net.sf.openrocket.document.StorageOptions;
|
||||||
import net.sf.openrocket.file.DatabaseMotorFinder;
|
|
||||||
import net.sf.openrocket.file.GeneralRocketLoader;
|
import net.sf.openrocket.file.GeneralRocketLoader;
|
||||||
import net.sf.openrocket.file.GeneralRocketSaver;
|
import net.sf.openrocket.file.GeneralRocketSaver;
|
||||||
import net.sf.openrocket.file.RocketLoadException;
|
import net.sf.openrocket.file.RocketLoadException;
|
||||||
@ -62,7 +61,7 @@ public class RocksimConverter {
|
|||||||
opts.setExplicitlySet(true);
|
opts.setExplicitlySet(true);
|
||||||
|
|
||||||
GeneralRocketLoader loader = new GeneralRocketLoader(input);
|
GeneralRocketLoader loader = new GeneralRocketLoader(input);
|
||||||
OpenRocketDocument document = loader.load(input, new DatabaseMotorFinder());
|
OpenRocketDocument document = loader.load();
|
||||||
saver.save(output, document, opts);
|
saver.save(output, document, opts);
|
||||||
|
|
||||||
} catch (RocketLoadException e) {
|
} catch (RocketLoadException e) {
|
||||||
|
@ -20,8 +20,6 @@ import net.sf.openrocket.database.motor.MotorDatabase;
|
|||||||
import net.sf.openrocket.database.motor.ThrustCurveMotorSetDatabase;
|
import net.sf.openrocket.database.motor.ThrustCurveMotorSetDatabase;
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import net.sf.openrocket.file.DatabaseMotorFinder;
|
|
||||||
import net.sf.openrocket.file.FileInfo;
|
|
||||||
import net.sf.openrocket.file.GeneralRocketLoader;
|
import net.sf.openrocket.file.GeneralRocketLoader;
|
||||||
import net.sf.openrocket.file.RocketLoadException;
|
import net.sf.openrocket.file.RocketLoadException;
|
||||||
import net.sf.openrocket.file.motor.GeneralMotorLoader;
|
import net.sf.openrocket.file.motor.GeneralMotorLoader;
|
||||||
@ -117,10 +115,10 @@ public class IntegrationTest extends BaseTestCase {
|
|||||||
System.setProperty("openrocket.unittest", "true");
|
System.setProperty("openrocket.unittest", "true");
|
||||||
|
|
||||||
// Load the rocket
|
// Load the rocket
|
||||||
GeneralRocketLoader loader = new GeneralRocketLoader();
|
GeneralRocketLoader loader = new GeneralRocketLoader(new File("simplerocket.ork"));
|
||||||
InputStream is = this.getClass().getResourceAsStream("simplerocket.ork");
|
InputStream is = this.getClass().getResourceAsStream("simplerocket.ork");
|
||||||
assertNotNull("Problem in unit test, cannot find simplerocket.ork", is);
|
assertNotNull("Problem in unit test, cannot find simplerocket.ork", is);
|
||||||
document = loader.load(is, new FileInfo(new File("simplerocket.ork")), new DatabaseMotorFinder());
|
document = loader.load(is);
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
undoAction = UndoRedoAction.newUndoAction(document);
|
undoAction = UndoRedoAction.newUndoAction(document);
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* RocksimContentHandlerTest.java
|
|
||||||
*/
|
|
||||||
package net.sf.openrocket.file.rocksim.importt;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RocksimContentHandler Tester.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class RocksimContentHandlerTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Method: getDocument()
|
|
||||||
*
|
|
||||||
* @throws Exception thrown if something goes awry
|
|
||||||
*/
|
|
||||||
@org.junit.Test
|
|
||||||
public void testGetDocument() throws Exception {
|
|
||||||
RocksimContentHandler handler = new RocksimContentHandler();
|
|
||||||
Assert.assertNotNull(handler.getDocument());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||||
import net.sf.openrocket.file.DatabaseMotorFinder;
|
import net.sf.openrocket.file.DatabaseMotorFinder;
|
||||||
import net.sf.openrocket.file.RocketLoadException;
|
import net.sf.openrocket.file.RocketLoadException;
|
||||||
import net.sf.openrocket.rocketcomponent.BodyTube;
|
import net.sf.openrocket.rocketcomponent.BodyTube;
|
||||||
@ -34,7 +35,8 @@ public class RocksimLoaderTest {
|
|||||||
InputStream stream = this.getClass().getResourceAsStream("PodFins.rkt");
|
InputStream stream = this.getClass().getResourceAsStream("PodFins.rkt");
|
||||||
Assert.assertNotNull("Could not open PodFins.rkt", stream);
|
Assert.assertNotNull("Could not open PodFins.rkt", stream);
|
||||||
try {
|
try {
|
||||||
OpenRocketDocument doc = loader.loadFromStream(new BufferedInputStream(stream), new DatabaseMotorFinder());
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||||
|
loader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||||
Assert.assertNotNull(doc);
|
Assert.assertNotNull(doc);
|
||||||
Rocket rocket = doc.getRocket();
|
Rocket rocket = doc.getRocket();
|
||||||
Assert.assertNotNull(rocket);
|
Assert.assertNotNull(rocket);
|
||||||
@ -64,7 +66,9 @@ public class RocksimLoaderTest {
|
|||||||
|
|
||||||
stream = this.getClass().getResourceAsStream("rocksimTestRocket2.rkt");
|
stream = this.getClass().getResourceAsStream("rocksimTestRocket2.rkt");
|
||||||
Assert.assertNotNull("Could not open rocksimTestRocket2.rkt", stream);
|
Assert.assertNotNull("Could not open rocksimTestRocket2.rkt", stream);
|
||||||
doc = loader.loadFromStream(new BufferedInputStream(stream), new DatabaseMotorFinder());
|
|
||||||
|
doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||||
|
loader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||||
|
|
||||||
Assert.assertNotNull(doc);
|
Assert.assertNotNull(doc);
|
||||||
rocket = doc.getRocket();
|
rocket = doc.getRocket();
|
||||||
@ -87,7 +91,9 @@ public class RocksimLoaderTest {
|
|||||||
|
|
||||||
stream = this.getClass().getResourceAsStream("rocksimTestRocket3.rkt");
|
stream = this.getClass().getResourceAsStream("rocksimTestRocket3.rkt");
|
||||||
Assert.assertNotNull("Could not open rocksimTestRocket3.rkt", stream);
|
Assert.assertNotNull("Could not open rocksimTestRocket3.rkt", stream);
|
||||||
doc = loader.loadFromStream(new BufferedInputStream(stream), new DatabaseMotorFinder());
|
|
||||||
|
doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||||
|
loader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||||
|
|
||||||
Assert.assertNotNull(doc);
|
Assert.assertNotNull(doc);
|
||||||
rocket = doc.getRocket();
|
rocket = doc.getRocket();
|
||||||
@ -133,7 +139,9 @@ public class RocksimLoaderTest {
|
|||||||
InputStream stream = RocksimLoaderTest.class.getResourceAsStream("rocksimTestRocket1.rkt");
|
InputStream stream = RocksimLoaderTest.class.getResourceAsStream("rocksimTestRocket1.rkt");
|
||||||
try {
|
try {
|
||||||
Assert.assertNotNull("Could not open rocksimTestRocket1.rkt", stream);
|
Assert.assertNotNull("Could not open rocksimTestRocket1.rkt", stream);
|
||||||
return theLoader.loadFromStream(new BufferedInputStream(stream), new DatabaseMotorFinder());
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||||
|
theLoader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||||
|
return doc;
|
||||||
} finally {
|
} finally {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
@ -143,7 +151,9 @@ public class RocksimLoaderTest {
|
|||||||
InputStream stream = RocksimLoaderTest.class.getResourceAsStream("rocksimTestRocket3.rkt");
|
InputStream stream = RocksimLoaderTest.class.getResourceAsStream("rocksimTestRocket3.rkt");
|
||||||
try {
|
try {
|
||||||
Assert.assertNotNull("Could not open rocksimTestRocket3.rkt", stream);
|
Assert.assertNotNull("Could not open rocksimTestRocket3.rkt", stream);
|
||||||
return theLoader.loadFromStream(new BufferedInputStream(stream), new DatabaseMotorFinder());
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createDocumentForFile(null, false);
|
||||||
|
theLoader.loadFromStream(doc, new BufferedInputStream(stream), new DatabaseMotorFinder());
|
||||||
|
return doc;
|
||||||
} finally {
|
} finally {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -15,10 +18,10 @@ public class ComponentCompare {
|
|||||||
private static final String[] IGNORED_METHODS = {
|
private static final String[] IGNORED_METHODS = {
|
||||||
"getClass", "getChildCount", "getChildren", "getNextComponent", "getID",
|
"getClass", "getChildCount", "getChildren", "getNextComponent", "getID",
|
||||||
"getPreviousComponent", "getParent", "getRocket", "getRoot", "getStage",
|
"getPreviousComponent", "getParent", "getRocket", "getRoot", "getStage",
|
||||||
"getStageNumber", "getComponentName",
|
"getStageNumber", "getComponentName", "getDefaultFlightConfiguration",
|
||||||
// Rocket specific methods:
|
// Rocket specific methods:
|
||||||
"getModID", "getMassModID", "getAerodynamicModID", "getTreeModID", "getFunctionalModID",
|
"getModID", "getMassModID", "getAerodynamicModID", "getTreeModID", "getFunctionalModID",
|
||||||
"getMotorConfigurationIDs", "getDefaultConfiguration", "getMotorMounts"
|
"getFlightConfigurationIDs", "getDefaultConfiguration", "getMotorMounts"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -38,7 +41,7 @@ public class ComponentCompare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void assertDeepEquality(RocketComponent c1, RocketComponent c2) {
|
public static void assertDeepEquality(RocketComponent c1, RocketComponent c2) {
|
||||||
assertEquality(c1, c2);
|
assertEquality(c1, c2);
|
||||||
|
|
||||||
@ -54,7 +57,7 @@ public class ComponentCompare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void assertDeepSimilarity(RocketComponent c1, RocketComponent c2,
|
public static void assertDeepSimilarity(RocketComponent c1, RocketComponent c2,
|
||||||
boolean allowNameDifference) {
|
boolean allowNameDifference) {
|
||||||
assertSimilarity(c1, c2, allowNameDifference);
|
assertSimilarity(c1, c2, allowNameDifference);
|
||||||
@ -71,7 +74,7 @@ public class ComponentCompare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the two components are <em>similar</em>. Two components are similar
|
* Check whether the two components are <em>similar</em>. Two components are similar
|
||||||
* if each of the getXXX and isXXX methods that both object types have return
|
* if each of the getXXX and isXXX methods that both object types have return
|
||||||
@ -114,7 +117,7 @@ public class ComponentCompare {
|
|||||||
if (allowNameDifference && name.equals("getName"))
|
if (allowNameDifference && name.equals("getName"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
// Check for method in other class
|
// Check for method in other class
|
||||||
Method m2;
|
Method m2;
|
||||||
try {
|
try {
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
package net.sf.openrocket.simulation.customexpression;
|
package net.sf.openrocket.simulation.customexpression;
|
||||||
|
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.sf.openrocket.document.OpenRocketDocument;
|
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
|
||||||
|
|
||||||
public class TestExpressions {
|
public class TestExpressions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExpressions() {
|
public void testExpressions() {
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
OpenRocketDocument doc = new OpenRocketDocument(new Rocket());
|
OpenRocketDocument doc = OpenRocketDocumentFactory.createNewRocket();
|
||||||
|
|
||||||
//CustomExpression exp = new CustomExpression(doc, "Kinetic energy", "Ek", "J", ".5*m*Vt^2");
|
//CustomExpression exp = new CustomExpression(doc, "Kinetic energy", "Ek", "J", ".5*m*Vt^2");
|
||||||
|
|
||||||
CustomExpression exp = new CustomExpression(doc, "Average mass", "Mavg", "kg", "mean(m[0:t])");
|
CustomExpression exp = new CustomExpression(doc, "Average mass", "Mavg", "kg", "mean(m[0:t])");
|
||||||
System.out.println( exp.getExpressionString() );
|
System.out.println(exp.getExpressionString());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user