Fixed issue where symbols / units for FlightDataTypes would not be defined after loading a .ork file with data defined. Data types now figured out from the name when loading .ork file.
Also changed the priority of the data types so that custom expressions show up first.
This commit is contained in:
parent
50f3fc39a6
commit
d4c4242c7f
@ -1202,7 +1202,6 @@ class SimulationsHandler extends AbstractElementHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SingleSimulationHandler extends AbstractElementHandler {
|
class SingleSimulationHandler extends AbstractElementHandler {
|
||||||
private static final LogHelper log = Application.getLogger();
|
|
||||||
|
|
||||||
private final DocumentLoadingContext context;
|
private final DocumentLoadingContext context;
|
||||||
|
|
||||||
@ -1225,6 +1224,10 @@ class SingleSimulationHandler extends AbstractElementHandler {
|
|||||||
public void setCustomExpressions(ArrayList<CustomExpression> expressions){
|
public void setCustomExpressions(ArrayList<CustomExpression> expressions){
|
||||||
this.customExpressions = expressions;
|
this.customExpressions = expressions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<CustomExpression> getCustomExpressions(){
|
||||||
|
return customExpressions;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElementHandler openElement(String element, HashMap<String, String> attributes,
|
public ElementHandler openElement(String element, HashMap<String, String> attributes,
|
||||||
@ -1240,7 +1243,7 @@ class SingleSimulationHandler extends AbstractElementHandler {
|
|||||||
conditionHandler = new SimulationConditionsHandler(doc.getRocket(), context);
|
conditionHandler = new SimulationConditionsHandler(doc.getRocket(), context);
|
||||||
return conditionHandler;
|
return conditionHandler;
|
||||||
} else if (element.equals("flightdata")) {
|
} else if (element.equals("flightdata")) {
|
||||||
dataHandler = new FlightDataHandler(context);
|
dataHandler = new FlightDataHandler(this, context);
|
||||||
return dataHandler;
|
return dataHandler;
|
||||||
} else {
|
} else {
|
||||||
warnings.add("Unknown element '" + element + "', ignoring.");
|
warnings.add("Unknown element '" + element + "', ignoring.");
|
||||||
@ -1545,12 +1548,14 @@ class FlightDataHandler extends AbstractElementHandler {
|
|||||||
private FlightDataBranchHandler dataHandler;
|
private FlightDataBranchHandler dataHandler;
|
||||||
private WarningSet warningSet = new WarningSet();
|
private WarningSet warningSet = new WarningSet();
|
||||||
private List<FlightDataBranch> branches = new ArrayList<FlightDataBranch>();
|
private List<FlightDataBranch> branches = new ArrayList<FlightDataBranch>();
|
||||||
|
|
||||||
|
private SingleSimulationHandler simHandler;
|
||||||
private FlightData data;
|
private FlightData data;
|
||||||
|
|
||||||
|
|
||||||
public FlightDataHandler(DocumentLoadingContext context) {
|
public FlightDataHandler(SingleSimulationHandler simHandler, DocumentLoadingContext context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.simHandler = simHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlightData getFlightData() {
|
public FlightData getFlightData() {
|
||||||
@ -1569,8 +1574,9 @@ class FlightDataHandler extends AbstractElementHandler {
|
|||||||
warnings.add("Illegal flight data definition, ignoring.");
|
warnings.add("Illegal flight data definition, ignoring.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
dataHandler = new FlightDataBranchHandler(attributes.get("name"),
|
dataHandler = new FlightDataBranchHandler( attributes.get("name"),
|
||||||
attributes.get("types"), context);
|
attributes.get("types"),
|
||||||
|
simHandler, context);
|
||||||
return dataHandler;
|
return dataHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1666,19 +1672,52 @@ class FlightDataBranchHandler extends AbstractElementHandler {
|
|||||||
private final DocumentLoadingContext context;
|
private final DocumentLoadingContext context;
|
||||||
private final FlightDataType[] types;
|
private final FlightDataType[] types;
|
||||||
private final FlightDataBranch branch;
|
private final FlightDataBranch branch;
|
||||||
|
|
||||||
public FlightDataBranchHandler(String name, String typeList, DocumentLoadingContext context) {
|
private static final LogHelper log = Application.getLogger();
|
||||||
|
private final SingleSimulationHandler simHandler;
|
||||||
|
|
||||||
|
public FlightDataBranchHandler(String name, String typeList, SingleSimulationHandler simHandler, DocumentLoadingContext context) {
|
||||||
|
this.simHandler = simHandler;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
String[] split = typeList.split(",");
|
String[] split = typeList.split(",");
|
||||||
types = new FlightDataType[split.length];
|
types = new FlightDataType[split.length];
|
||||||
for (int i = 0; i < split.length; i++) {
|
for (int i = 0; i < split.length; i++) {
|
||||||
types[i] = FlightDataType.getType(split[i], "None ("+split[i]+")", UnitGroup.UNITS_NONE);
|
String typeName = split[i];
|
||||||
// TODO: HIGH: Deal with symbols
|
FlightDataType matching = findFlightDataType(typeName);
|
||||||
|
types[i] = matching;
|
||||||
|
//types[i] = FlightDataType.getType(typeName, matching.getSymbol(), matching.getUnitGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: LOW: May throw an IllegalArgumentException
|
// TODO: LOW: May throw an IllegalArgumentException
|
||||||
branch = new FlightDataBranch(name, types);
|
branch = new FlightDataBranch(name, types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the full flight data type given name only
|
||||||
|
// Note: this way of doing it requires that custom expressions always come before flight data in the file,
|
||||||
|
// not the nicest but this is always the case anyway.
|
||||||
|
private FlightDataType findFlightDataType(String name){
|
||||||
|
|
||||||
|
// Look in built in types
|
||||||
|
for (FlightDataType t : FlightDataType.ALL_TYPES){
|
||||||
|
if (t.getName().equals(name) ){
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look in custom expressions, meanwhile set priority based on order in file
|
||||||
|
int totalExpressions = simHandler.getCustomExpressions().size();
|
||||||
|
for (int i=0; i<totalExpressions; i++){
|
||||||
|
CustomExpression exp = simHandler.getCustomExpressions().get(i);
|
||||||
|
if (exp.getName().equals(name) ){
|
||||||
|
FlightDataType t = exp.getType();
|
||||||
|
t.setPriority(-1*(totalExpressions-i));
|
||||||
|
return exp.getType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("Could not find the flight data type '"+name+"' used in the XML file. Substituted type with unknown symbol and units.");
|
||||||
|
return FlightDataType.getType(name, "Unknown", UnitGroup.UNITS_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
public FlightDataBranch getBranch() {
|
public FlightDataBranch getBranch() {
|
||||||
branch.immute();
|
branch.immute();
|
||||||
|
@ -24,7 +24,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
|
|
||||||
private String name, symbol, unit, expression;
|
private String name, symbol, unit, expression;
|
||||||
private ExpressionBuilder builder;
|
private ExpressionBuilder builder;
|
||||||
private static Simulation sim = null;
|
private Simulation sim = null;
|
||||||
|
|
||||||
// A map of available operator strings (keys) and description of function (value)
|
// A map of available operator strings (keys) and description of function (value)
|
||||||
public static final SortedMap<String, String> AVAILABLE_OPERATORS = new TreeMap<String, String>() {{
|
public static final SortedMap<String, String> AVAILABLE_OPERATORS = new TreeMap<String, String>() {{
|
||||||
@ -78,11 +78,11 @@ public class CustomExpression implements Cloneable{
|
|||||||
* Use this to update the simulation this is associated with
|
* Use this to update the simulation this is associated with
|
||||||
*/
|
*/
|
||||||
public void setSimulation(Simulation sim){
|
public void setSimulation(Simulation sim){
|
||||||
CustomExpression.sim = sim;
|
this.sim = sim;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Simulation getSimulation() {
|
public Simulation getSimulation() {
|
||||||
return CustomExpression.sim;
|
return this.sim;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -90,10 +90,11 @@ public class CustomExpression implements Cloneable{
|
|||||||
* if no simulated data exists
|
* if no simulated data exists
|
||||||
*/
|
*/
|
||||||
private FlightDataBranch getBranch() {
|
private FlightDataBranch getBranch() {
|
||||||
if ( sim == null || sim.getSimulatedData().getBranch(0) == null) {
|
if ( sim == null || sim.getSimulatedData().getBranchCount() == 0){//sim.getSimulatedData().getBranch(0) == null) {
|
||||||
return new FlightDataBranch();
|
return new FlightDataBranch();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
System.out.println("Using existing branch");
|
||||||
return sim.getSimulatedData().getBranch(0);
|
return sim.getSimulatedData().getBranch(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,7 +146,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// No bad characters
|
// No bad characters
|
||||||
for (char c : "0123456789.()[]{}".toCharArray())
|
for (char c : "0123456789.,()[]{}<> ".toCharArray())
|
||||||
if (symbol.indexOf(c) != -1 )
|
if (symbol.indexOf(c) != -1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -170,6 +171,11 @@ public class CustomExpression implements Cloneable{
|
|||||||
if (name.trim().isEmpty())
|
if (name.trim().isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// No characters that could mess things up saving etc
|
||||||
|
for (char c : ",()[]{}<>".toCharArray())
|
||||||
|
if (symbol.indexOf(c) != -1 )
|
||||||
|
return false;
|
||||||
|
|
||||||
ArrayList<String> names = getAllNames().clone();
|
ArrayList<String> names = getAllNames().clone();
|
||||||
if (names.contains(name.trim())){
|
if (names.contains(name.trim())){
|
||||||
int index = names.indexOf(name.trim());
|
int index = names.indexOf(name.trim());
|
||||||
@ -217,6 +223,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
|
|
||||||
// Define the available variables as 0
|
// Define the available variables as 0
|
||||||
for (FlightDataType type : getBranch().getTypes()){
|
for (FlightDataType type : getBranch().getTypes()){
|
||||||
|
System.out.println( " " + type.getSymbol() );
|
||||||
builder.withVariable(type.getSymbol(), 0.0);
|
builder.withVariable(type.getSymbol(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,8 +267,14 @@ public class CustomExpression implements Cloneable{
|
|||||||
* Returns the new flight data type corresponding to this calculated data
|
* Returns the new flight data type corresponding to this calculated data
|
||||||
*/
|
*/
|
||||||
public FlightDataType getType(){
|
public FlightDataType getType(){
|
||||||
|
// Figure out priority from order in array so that customs expressions are always at the top
|
||||||
|
|
||||||
|
int totalExpressions = sim.getCustomExpressions().size();
|
||||||
|
int p = -1*(totalExpressions-sim.getCustomExpressions().indexOf(this));
|
||||||
UnitGroup ug = new FixedUnitGroup(unit);
|
UnitGroup ug = new FixedUnitGroup(unit);
|
||||||
return FlightDataType.getType(name, symbol, ug);
|
FlightDataType type = FlightDataType.getType(name, symbol, ug);
|
||||||
|
type.setPriority(p);
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -106,8 +106,8 @@ public class FlightDataBranch implements Monitorable {
|
|||||||
mutable.check();
|
mutable.check();
|
||||||
|
|
||||||
ArrayList<Double> list = values.get(type);
|
ArrayList<Double> list = values.get(type);
|
||||||
|
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
|
|
||||||
list = new ArrayList<Double>();
|
list = new ArrayList<Double>();
|
||||||
int n = getLength();
|
int n = getLength();
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
@ -115,10 +115,13 @@ public class FlightDataBranch implements Monitorable {
|
|||||||
}
|
}
|
||||||
values.put(type, list);
|
values.put(type, list);
|
||||||
minValues.put(type, value);
|
minValues.put(type, value);
|
||||||
maxValues.put(type, value);
|
maxValues.put(type, value);
|
||||||
|
|
||||||
}
|
}
|
||||||
list.set(list.size() - 1, value);
|
|
||||||
|
if (list.size() > 0){
|
||||||
|
list.set(list.size() - 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
double min = minValues.get(type);
|
double min = minValues.get(type);
|
||||||
double max = maxValues.get(type);
|
double max = maxValues.get(type);
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
|||||||
|
|
||||||
//// Vertical position and motion
|
//// Vertical position and motion
|
||||||
//// Altitude
|
//// Altitude
|
||||||
public static final FlightDataType TYPE_ALTITUDE = newType(trans.get("FlightDataType.TYPE_ALTITUDE"), "a", UnitGroup.UNITS_DISTANCE, 10);
|
public static final FlightDataType TYPE_ALTITUDE = newType(trans.get("FlightDataType.TYPE_ALTITUDE"), "h", UnitGroup.UNITS_DISTANCE, 10);
|
||||||
//// Vertical velocity
|
//// Vertical velocity
|
||||||
public static final FlightDataType TYPE_VELOCITY_Z = newType(trans.get("FlightDataType.TYPE_VELOCITY_Z"), "Vz", UnitGroup.UNITS_VELOCITY, 11);
|
public static final FlightDataType TYPE_VELOCITY_Z = newType(trans.get("FlightDataType.TYPE_VELOCITY_Z"), "Vz", UnitGroup.UNITS_VELOCITY, 11);
|
||||||
//// Vertical acceleration
|
//// Vertical acceleration
|
||||||
@ -180,6 +180,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
|||||||
|
|
||||||
// An array of all the built in types
|
// An array of all the built in types
|
||||||
public static final FlightDataType[] ALL_TYPES = {
|
public static final FlightDataType[] ALL_TYPES = {
|
||||||
|
TYPE_TIME,
|
||||||
TYPE_ALTITUDE ,
|
TYPE_ALTITUDE ,
|
||||||
TYPE_VELOCITY_Z ,
|
TYPE_VELOCITY_Z ,
|
||||||
TYPE_ACCELERATION_Z,
|
TYPE_ACCELERATION_Z,
|
||||||
@ -243,7 +244,15 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
|||||||
* @return a data type.
|
* @return a data type.
|
||||||
*/
|
*/
|
||||||
public static synchronized FlightDataType getType(String s, String symbol, UnitGroup u) {
|
public static synchronized FlightDataType getType(String s, String symbol, UnitGroup u) {
|
||||||
|
// modified to include the unit
|
||||||
FlightDataType type = EXISTING_TYPES.get(s.toLowerCase(Locale.ENGLISH));
|
FlightDataType type = EXISTING_TYPES.get(s.toLowerCase(Locale.ENGLISH));
|
||||||
|
|
||||||
|
// added this for backward compatibility. Will update type if symbol undefined
|
||||||
|
//if (type != null && type.getSymbol() != symbol){
|
||||||
|
// EXISTING_TYPES.remove(type);
|
||||||
|
// type = null;
|
||||||
|
//}
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -264,7 +273,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String symbol;
|
private final String symbol;
|
||||||
private final UnitGroup units;
|
private final UnitGroup units;
|
||||||
private final int priority;
|
private int priority;
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
|
|
||||||
@ -281,7 +290,9 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setPriority(int p){
|
||||||
|
this.priority = p;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -297,7 +308,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name; //+" ("+symbol+") "+units.getDefaultUnit().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user