private List<CustomExpression> subExpressions = new ArrayList<CustomExpression>();
public CustomExpression(OpenRocketDocument doc){
+ this.doc = doc;
+
setName("");
setSymbol("");
setUnit("");
setExpression("");
- this.doc = doc;
}
public CustomExpression(OpenRocketDocument doc,
// get a list of all the names of all the available variables
protected ArrayList<String> getAllNames(){
ArrayList<String> names = new ArrayList<String>();
+ /*
for (FlightDataType type : FlightDataType.ALL_TYPES)
names.add(type.getName());
names.add(exp.getName());
}
}
+ */
+ for (FlightDataType type : doc.getFlightDataTypes()){
+ String symb = type.getName();
+ if (name == null) continue;
+
+ if (!name.equals( this.getName() )){
+ names.add(symb);
+ }
+ }
return names;
}
// get a list of all the symbols of the available variables ignoring this one
protected ArrayList<String> getAllSymbols(){
ArrayList<String> symbols = new ArrayList<String>();
+ /*
for (FlightDataType type : FlightDataType.ALL_TYPES)
symbols.add(type.getSymbol());
symbols.add(exp.getSymbol());
}
}
+ */
+ for (FlightDataType type : doc.getFlightDataTypes()){
+ String symb = type.getSymbol();
+ if (!symb.equals( this.getSymbol() )){
+ symbols.add(symb);
+ }
+ }
+
return symbols;
}
return false;
// No bad characters
- for (char c : "0123456789.,()[]{}<>:#@%^&* ".toCharArray())
+ for (char c : "0123456789.,()[]{}<>:#@%^&*$ ".toCharArray())
if (symbol.indexOf(c) != -1 )
return false;
return false;
// No characters that could mess things up saving etc
- for (char c : ",()[]{}<>#".toCharArray())
+ for (char c : ",()[]{}<>#$".toCharArray())
if (name.indexOf(c) != -1 )
return false;
}
else break;
case '#' : return false;
+ case '$' : return false;
case '=' : return false;
}
}
//// Define the available variables as empty
// The built in data types
+ /*
for (FlightDataType type : FlightDataType.ALL_TYPES){
builder.withVariable(new Variable(type.getSymbol()));
}
for (String symb : getAllSymbols()){
builder.withVariable(new Variable(symb));
}
+ */
+ for (FlightDataType type : doc.getFlightDataTypes()){
+ builder.withVariable(new Variable(type.getSymbol()));
+ }
// Try to build
try {
builder.build();
} catch (Exception e) {
- log.user("Custom expression invalid : " + e.toString());
+ log.user("Custom expression " + this.toString() + " invalid : " + e.toString());
return false;
}
* Builds a specified expression, log any errors and returns null in case of error.
*/
protected Calculable buildExpression(ExpressionBuilder b){
- Calculable calc;
+ Calculable calc = null;
try {
calc = b.build();
} catch (UnknownFunctionException e1) {
- log.user("Unknown function. Could not build custom expression "+name);
+ log.user("Unknown function. Could not build custom expression "+this.toString());
return null;
} catch (UnparsableExpressionException e1) {
- log.user("Unparsable expression. Could not build custom expression "+name+". "+e1.getMessage());
+ log.user("Unparsable expression. Could not build custom expression "+this.toString()+". "+e1.getMessage());
return null;
}
*/
public FlightDataType getType(){
+
UnitGroup ug = UnitGroup.SIUNITS.get(unit);
if ( ug == null ){
+ log.debug("SI unit not found for "+unit+" in expression "+toString()+". Making a new fixed unit.");
ug = new FixedUnitGroup(unit);
}
+ //UnitGroup ug = new FixedUnitGroup(unit);
FlightDataType type = FlightDataType.getType(name, symbol, ug);
@Override
public String toString(){
- return "Custom expression : "+this.name.toString()+ " " + this.expression.toString();
+ return "[Expression name="+this.name.toString()+ " expression=" + this.expression+" unit="+this.unit+"]";
}
@Override
}
/*
- * Returns a simple all upper case string hash code with a proceeding # mark.
+ * Returns a simple all upper case string hash code with a proceeding $ mark.
* Used for temporary substitution when evaluating index and range expressions.
*/
public String hash(){
Integer hashint = new Integer(this.getExpressionString().hashCode());
- String hash = "#";
+ String hash = "$";
for (char c : hashint.toString().toCharArray()){
char newc = (char) (c + 17);
hash = hash + newc;