import java.awt.event.ActionEvent;
import java.io.File;
-import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import net.sf.openrocket.document.events.DocumentChangeListener;
import net.sf.openrocket.document.events.SimulationChangeEvent;
import net.sf.openrocket.gui.main.ExceptionHandler;
+import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.logging.TraceException;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.Configuration;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
+import net.sf.openrocket.util.ArrayList;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Icons;
/**
* Class describing an entire OpenRocket document, including a rocket and
- * simulations. This class also handles undo/redo operations for the rocket structure.
+ * simulations. The document contains:
+ * <p>
+ * - the rocket definition
+ * - a default Configuration
+ * - Simulation instances
+ * - the stored file and file save information
+ * - undo/redo information
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
public class OpenRocketDocument implements ComponentChangeListener {
private static final LogHelper log = Application.getLogger();
+ private static final Translator trans = Application.getTranslator();
/**
* The minimum number of undo levels that are stored.
/** Whether an undo error has already been reported to the user */
private static boolean undoErrorReported = false;
+
+
private final Rocket rocket;
private final Configuration configuration;
- @SuppressWarnings("unchecked")
public List<Simulation> getSimulations() {
- return (ArrayList<Simulation>) simulations.clone();
+ return simulations.clone();
}
public int getSimulationCount() {
undoDescription.add(null);
}
+ rocket.checkComponentStructure();
+ undoHistory.get(undoPosition).checkComponentStructure();
+ undoHistory.get(undoPosition).copyWithOriginalID().checkComponentStructure();
rocket.loadFrom(undoHistory.get(undoPosition).copyWithOriginalID());
+ rocket.checkComponentStructure();
}
}
}
+
+
+ /**
+ * Return a copy of this document. The rocket is copied with original ID's, the default
+ * motor configuration ID is maintained and the simulations are copied to the new rocket.
+ * No undo/redo information or file storage information is maintained.
+ *
+ * @return a copy of this document.
+ */
+ public OpenRocketDocument copy() {
+ Rocket rocketCopy = rocket.copyWithOriginalID();
+ OpenRocketDocument documentCopy = new OpenRocketDocument(rocketCopy);
+ documentCopy.getDefaultConfiguration().setMotorConfigurationID(configuration.getMotorConfigurationID());
+ for (Simulation s : simulations) {
+ documentCopy.addSimulation(s.duplicateSimulation(rocketCopy));
+ }
+ return documentCopy;
+ }
+
+
+
/////// Listeners
public void addDocumentChangeListener(DocumentChangeListener listener) {
// Actual action to make
+ @Override
public void actionPerformed(ActionEvent e) {
switch (type) {
case UNDO:
switch (type) {
case UNDO:
- name = "Undo";
+ //// Undo
+ name = trans.get("OpenRocketDocument.Undo");
desc = getUndoDescription();
actionEnabled = isUndoAvailable();
this.putValue(SMALL_ICON, Icons.EDIT_UNDO);
break;
case REDO:
- name = "Redo";
+ ////Redo
+ name = trans.get("OpenRocketDocument.Redo");
desc = getRedoDescription();
actionEnabled = isRedoAvailable();
this.putValue(SMALL_ICON, Icons.EDIT_REDO);