projects
/
debian
/
openrocket
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
- Workaround for bug with plotting when given INF value.
[debian/openrocket]
/
core
/
src
/
net
/
sf
/
openrocket
/
simulation
/
customexpression
/
CustomExpression.java
diff --git
a/core/src/net/sf/openrocket/simulation/customexpression/CustomExpression.java
b/core/src/net/sf/openrocket/simulation/customexpression/CustomExpression.java
index 2ac41ffc0651bc7a094998089af45607d37c5c28..e233deff992fdfcebb990801bb63289875072664 100644
(file)
--- a/
core/src/net/sf/openrocket/simulation/customexpression/CustomExpression.java
+++ b/
core/src/net/sf/openrocket/simulation/customexpression/CustomExpression.java
@@
-34,11
+34,12
@@
public class CustomExpression implements Cloneable{
private List<CustomExpression> subExpressions = new ArrayList<CustomExpression>();
public CustomExpression(OpenRocketDocument doc){
private List<CustomExpression> subExpressions = new ArrayList<CustomExpression>();
public CustomExpression(OpenRocketDocument doc){
+ this.doc = doc;
+
setName("");
setSymbol("");
setUnit("");
setExpression("");
setName("");
setSymbol("");
setUnit("");
setExpression("");
- this.doc = doc;
}
public CustomExpression(OpenRocketDocument doc,
}
public CustomExpression(OpenRocketDocument doc,
@@
-171,22
+172,33
@@
public class CustomExpression implements Cloneable{
// get a list of all the names of all the available variables
protected ArrayList<String> getAllNames(){
ArrayList<String> names = new ArrayList<String>();
// 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());
if (doc != null){
for (FlightDataType type : FlightDataType.ALL_TYPES)
names.add(type.getName());
if (doc != null){
-
Array
List<CustomExpression> expressions = doc.getCustomExpressions();
+ List<CustomExpression> expressions = doc.getCustomExpressions();
for (CustomExpression exp : expressions ){
if (exp != this)
names.add(exp.getName());
}
}
for (CustomExpression exp : expressions ){
if (exp != this)
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>();
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());
for (FlightDataType type : FlightDataType.ALL_TYPES)
symbols.add(type.getSymbol());
@@
-196,15
+208,23
@@
public class CustomExpression implements Cloneable{
symbols.add(exp.getSymbol());
}
}
symbols.add(exp.getSymbol());
}
}
+ */
+ for (FlightDataType type : doc.getFlightDataTypes()){
+ String symb = type.getSymbol();
+ if (!symb.equals( this.getSymbol() )){
+ symbols.add(symb);
+ }
+ }
+
return symbols;
}
public boolean checkSymbol(){
return symbols;
}
public boolean checkSymbol(){
- if (
symbol.trim().isEmpty(
))
+ if (
"".equals(symbol.trim()
))
return false;
// No bad characters
return false;
// No bad characters
- for (char c : "0123456789.,()[]{}<>:#@%^&* ".toCharArray())
+ for (char c : "0123456789.,()[]{}<>:#@%^&*
$
".toCharArray())
if (symbol.indexOf(c) != -1 )
return false;
if (symbol.indexOf(c) != -1 )
return false;
@@
-226,11
+246,11
@@
public class CustomExpression implements Cloneable{
}
public boolean checkName(){
}
public boolean checkName(){
- if (
name.trim().isEmpty(
))
+ if (
"".equals(name.trim()
))
return false;
// No characters that could mess things up saving etc
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;
if (name.indexOf(c) != -1 )
return false;
@@
-275,7
+295,7
@@
public class CustomExpression implements Cloneable{
* building the expression.
*/
public boolean checkExpression(){
* building the expression.
*/
public boolean checkExpression(){
- if (
expression.trim().isEmpty(
)){
+ if (
"".equals(expression.trim()
)){
return false;
}
return false;
}
@@
-293,6
+313,7
@@
public class CustomExpression implements Cloneable{
}
else break;
case '#' : return false;
}
else break;
case '#' : return false;
+ case '$' : return false;
case '=' : return false;
}
}
case '=' : return false;
}
}
@@
-304,6
+325,7
@@
public class CustomExpression implements Cloneable{
//// Define the available variables as empty
// The built in data types
//// Define the available variables as empty
// The built in data types
+ /*
for (FlightDataType type : FlightDataType.ALL_TYPES){
builder.withVariable(new Variable(type.getSymbol()));
}
for (FlightDataType type : FlightDataType.ALL_TYPES){
builder.withVariable(new Variable(type.getSymbol()));
}
@@
-311,12
+333,16
@@
public class CustomExpression implements Cloneable{
for (String symb : getAllSymbols()){
builder.withVariable(new Variable(symb));
}
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) {
// 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;
}
return false;
}
@@
-326,7
+352,9
@@
public class CustomExpression implements Cloneable{
}
public Double evaluateDouble(SimulationStatus status){
}
public Double evaluateDouble(SimulationStatus status){
- return evaluate(status).getDoubleValue();
+ double result = evaluate(status).getDoubleValue();
+ if (result == Double.NEGATIVE_INFINITY || result == Double.POSITIVE_INFINITY) result = Double.NaN;
+ return result;
}
/*
}
/*
@@
-340,14
+368,14
@@
public class CustomExpression implements Cloneable{
* Builds a specified expression, log any errors and returns null in case of error.
*/
protected Calculable buildExpression(ExpressionBuilder b){
* 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) {
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) {
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;
}
return null;
}
@@
-395,10
+423,13
@@
public class CustomExpression implements Cloneable{
*/
public FlightDataType getType(){
*/
public FlightDataType getType(){
+
UnitGroup ug = UnitGroup.SIUNITS.get(unit);
if ( ug == null ){
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);
}
ug = new FixedUnitGroup(unit);
}
+ //UnitGroup ug = new FixedUnitGroup(unit);
FlightDataType type = FlightDataType.getType(name, symbol, ug);
FlightDataType type = FlightDataType.getType(name, symbol, ug);
@@
-412,7
+443,7
@@
public class CustomExpression implements Cloneable{
*/
public void addToDocument(){
// Abort if exact expression already in
*/
public void addToDocument(){
// Abort if exact expression already in
-
Array
List<CustomExpression> expressions = doc.getCustomExpressions();
+ List<CustomExpression> expressions = doc.getCustomExpressions();
if ( !expressions.isEmpty() ) {
// check if expression already exists
if ( expressions.contains(this) ){
if ( !expressions.isEmpty() ) {
// check if expression already exists
if ( expressions.contains(this) ){
@@
-441,7
+472,7
@@
public class CustomExpression implements Cloneable{
@Override
public String toString(){
@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
}
@Override
@@
-465,13
+496,14
@@
public class CustomExpression implements Cloneable{
}
/*
}
/*
- * 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(){
* Used for temporary substitution when evaluating index and range expressions.
*/
public String hash(){
- Integer hashint = new Integer(this.getExpressionString().hashCode());
- String hash = "
#
";
+ Integer hashint = new Integer(this.getExpressionString().hashCode()
+ symbol.hashCode()
);
+ String hash = "
$
";
for (char c : hashint.toString().toCharArray()){
for (char c : hashint.toString().toCharArray()){
+ if (c == '-') c = '0';
char newc = (char) (c + 17);
hash = hash + newc;
}
char newc = (char) (c + 17);
hash = hash + newc;
}