X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fsimulation%2FCustomExpression.java;h=1ca9bd08f19dce103472ca774b4067d7710ff8fb;hb=dc2aa2b0bd1e22f097fc38038baedf345e834e2e;hp=1903079a2fb66be9b3437be639931e230532846d;hpb=65eedea8e0080d564e5bfd84b35ae70bdfd4f65b;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/simulation/CustomExpression.java b/core/src/net/sf/openrocket/simulation/CustomExpression.java index 1903079a..1ca9bd08 100644 --- a/core/src/net/sf/openrocket/simulation/CustomExpression.java +++ b/core/src/net/sf/openrocket/simulation/CustomExpression.java @@ -24,7 +24,7 @@ public class CustomExpression implements Cloneable{ 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 AVAILABLE_OPERATORS = new TreeMap() {{ @@ -78,11 +78,11 @@ public class CustomExpression implements Cloneable{ * 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; } /* @@ -90,10 +90,11 @@ public class CustomExpression implements Cloneable{ * 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); } } @@ -145,7 +146,7 @@ public class CustomExpression implements Cloneable{ return false; // No bad characters - for (char c : "0123456789.()[]{}".toCharArray()) + for (char c : "0123456789.,()[]{}<> ".toCharArray()) if (symbol.indexOf(c) != -1 ) return false; @@ -170,6 +171,11 @@ public class CustomExpression implements Cloneable{ 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 names = getAllNames().clone(); if (names.contains(name.trim())){ int index = names.indexOf(name.trim()); @@ -217,6 +223,7 @@ public class CustomExpression implements Cloneable{ // Define the available variables as 0 for (FlightDataType type : getBranch().getTypes()){ + System.out.println( " " + type.getSymbol() ); 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 */ 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; } /*