Merge pull request #24 from rdgraham/openrocket-rdg

Openrocket rdg
This commit is contained in:
plaa 2012-12-19 21:16:34 -08:00
commit 0ef470b02e
3 changed files with 13 additions and 6 deletions

View File

@ -86,6 +86,7 @@ public class CustomExpression implements Cloneable{
this.expression = expression;
// Replace any indexed variables
subExpressions.clear();
expression = subTimeIndexes(expression);
expression = subTimeRanges(expression);
@ -450,13 +451,13 @@ public class CustomExpression implements Cloneable{
if ( !expressions.isEmpty() ) {
// check if expression already exists
if ( expressions.contains(this) ){
log.user("Expression already in document. This unit : "+this.getUnit()+", existing unit : "+expressions.get(0).getUnit());
log.debug("Expression already in document");
return;
}
}
if (this.checkAll()){
log.user("Custom expression added to rocket document");
log.user("New custom expression added to rocket document");
doc.addCustomExpression( this );
}
}
@ -470,6 +471,7 @@ public class CustomExpression implements Cloneable{
else {
int index = doc.getCustomExpressions().indexOf(this);
doc.getCustomExpressions().set(index, newExpression);
log.debug("Overwriting custom expression already in document");
}
}

View File

@ -28,8 +28,6 @@ public class CustomExpressionSimulationListener extends AbstractSimulationListen
//log.debug("Setting value of custom expression "+expression.toString()+" = "+value);
data.setValue(expression.getType(), value);
}
}
@Override

View File

@ -3,6 +3,7 @@ package net.sf.openrocket.simulation.customexpression;
import java.util.List;
import de.congrace.exp4j.Calculable;
import de.congrace.exp4j.ExpressionBuilder;
import de.congrace.exp4j.Variable;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.logging.LogHelper;
@ -27,7 +28,6 @@ public class IndexExpression extends CustomExpression {
@Override
public Variable evaluate(SimulationStatus status){
Calculable calc = buildExpression();
if (calc == null){
return new Variable("Unknown");
@ -42,15 +42,22 @@ public class IndexExpression extends CustomExpression {
List<Double> time = status.getFlightData().get(FlightDataType.TYPE_TIME);
LinearInterpolator interp = new LinearInterpolator(time, data);
// Set the variables in the expression to evaluate
for (FlightDataType etype : status.getFlightData().getTypes()){
double value = status.getFlightData().getLast(etype);
calc.setVariable( new Variable(etype.getSymbol(), value ) );
}
// Evaluate this expression to get the t value
//System.out.println("Evaluating expression to get t value "+this.getExpressionString());
try{
double tvalue = calc.calculate().getDoubleValue();
//System.out.println("t = "+tvalue);
return new Variable(hash(), interp.getValue( tvalue ) );
}
catch (java.util.EmptyStackException e){
log.user("Unable to calculate time index for indexed expression "+getExpressionString()+" due to empty stack exception");
return new Variable("Unknown");
}
}
}