private String name, symbol, unit, expression;
private ExpressionBuilder builder;
- private static Simulation sim = null;
+ private Simulation sim = null;
// A map of available operator strings (keys) and description of function (value)
public static final SortedMap<String, String> AVAILABLE_OPERATORS = new TreeMap<String, String>() {{
* Use this to update the simulation this is associated with
*/
public void setSimulation(Simulation sim){
- CustomExpression.sim = sim;
+ this.sim = sim;
}
public Simulation getSimulation() {
- return CustomExpression.sim;
+ return this.sim;
}
/*
* if no simulated data exists
*/
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();
}
else {
+ System.out.println("Using existing branch");
return sim.getSimulatedData().getBranch(0);
}
}
return false;
// No bad characters
- for (char c : "0123456789.()[]{}".toCharArray())
+ for (char c : "0123456789.,()[]{}<> ".toCharArray())
if (symbol.indexOf(c) != -1 )
return false;
if (name.trim().isEmpty())
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();
if (names.contains(name.trim())){
int index = names.indexOf(name.trim());
// Define the available variables as 0
for (FlightDataType type : getBranch().getTypes()){
+ System.out.println( " " + type.getSymbol() );
builder.withVariable(type.getSymbol(), 0.0);
}
* Returns the new flight data type corresponding to this calculated data
*/
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);
- return FlightDataType.getType(name, symbol, ug);
+ FlightDataType type = FlightDataType.getType(name, symbol, ug);
+ type.setPriority(p);
+ return type;
}
/*