Move CSV listener example to extension

This commit is contained in:
JoePfeiffer 2022-12-07 15:10:54 -07:00
parent ba630ab37e
commit c3d2d5fc16
2 changed files with 86 additions and 60 deletions

View File

@ -1,4 +1,4 @@
package net.sf.openrocket.simulation.listeners.example; package net.sf.openrocket.simulation.extension.impl;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -9,12 +9,14 @@ import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.simulation.FlightDataType; import net.sf.openrocket.simulation.FlightDataType;
import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.simulation.SimulationConditions;
import net.sf.openrocket.simulation.SimulationStatus; import net.sf.openrocket.simulation.SimulationStatus;
import net.sf.openrocket.simulation.exception.SimulationException; import net.sf.openrocket.simulation.exception.SimulationException;
import net.sf.openrocket.simulation.extension.AbstractSimulationExtension;
import net.sf.openrocket.simulation.listeners.AbstractSimulationListener; import net.sf.openrocket.simulation.listeners.AbstractSimulationListener;
public class CSVSaveListener extends AbstractSimulationListener { public class CSVSave extends AbstractSimulationExtension {
private static enum Types { private static enum Types {
TIME { TIME {
@ -219,6 +221,17 @@ public class CSVSaveListener extends AbstractSimulationListener {
private File file; private File file;
private PrintStream output = null; private PrintStream output = null;
@Override
public String getDescription() {
return "dump a CSV file with a predetermined set of flight variables to a CSV file while running";
}
@Override
public void initialize(SimulationConditions conditions) throws SimulationException {
conditions.getSimulationListenerList().add(new CSVSaveListener());
}
private class CSVSaveListener extends AbstractSimulationListener {
@Override @Override
public boolean handleFlightEvent(SimulationStatus status, FlightEvent event) throws SimulationException { public boolean handleFlightEvent(SimulationStatus status, FlightEvent event) throws SimulationException {
@ -290,6 +303,6 @@ public class CSVSaveListener extends AbstractSimulationListener {
System.err.println("WARNING: stepTaken called with no open file " + System.err.println("WARNING: stepTaken called with no open file " +
"(t=" + status.getSimulationTime() + ")"); "(t=" + status.getSimulationTime() + ")");
} }
}
} }
} }

View File

@ -0,0 +1,13 @@
package net.sf.openrocket.simulation.extension.impl;
import net.sf.openrocket.plugin.Plugin;
import net.sf.openrocket.simulation.extension.AbstractSimulationExtensionProvider;
@Plugin
public class CSVSaveProvider extends AbstractSimulationExtensionProvider {
public CSVSaveProvider() {
super(CSVSave.class, "Reports", "CSV Save");
}
}