X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fsimulation%2FCustomExpression.java;h=6e829bb189ee85dcae0dad71c433ab4cf2d506f3;hb=79fda8aa8a7d682ac6bfd871021a7afd6711c2d6;hp=1ca9bd08f19dce103472ca774b4067d7710ff8fb;hpb=dc2aa2b0bd1e22f097fc38038baedf345e834e2e;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/simulation/CustomExpression.java b/core/src/net/sf/openrocket/simulation/CustomExpression.java index 1ca9bd08..6e829bb1 100644 --- a/core/src/net/sf/openrocket/simulation/CustomExpression.java +++ b/core/src/net/sf/openrocket/simulation/CustomExpression.java @@ -90,7 +90,7 @@ public class CustomExpression implements Cloneable{ * if no simulated data exists */ private FlightDataBranch getBranch() { - if ( sim == null || sim.getSimulatedData().getBranchCount() == 0){//sim.getSimulatedData().getBranch(0) == null) { + if ( sim == null || sim.getSimulatedData() == null || sim.getSimulatedData().getBranchCount() == 0){ return new FlightDataBranch(); } else { @@ -173,7 +173,7 @@ public class CustomExpression implements Cloneable{ // No characters that could mess things up saving etc for (char c : ",()[]{}<>".toCharArray()) - if (symbol.indexOf(c) != -1 ) + if (name.indexOf(c) != -1 ) return false; ArrayList names = getAllNames().clone(); @@ -223,7 +223,6 @@ 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); } @@ -267,13 +266,17 @@ 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); FlightDataType type = FlightDataType.getType(name, symbol, ug); - type.setPriority(p); + + // If in a simulation, figure out priority from order in array so that customs expressions are always at the top + if (sim != null && sim.getCustomExpressions().contains(this)){ + int totalExpressions = sim.getCustomExpressions().size(); + int p = -1*(totalExpressions-sim.getCustomExpressions().indexOf(this)); + type.setPriority(p); + } + return type; }