import org.simantics.sysdyn.modelImport.model.WriteContext;\r
import org.simantics.sysdyn.ui.Activator;\r
import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
\r
/**\r
* Class for importing Vensim models (.mdl) to Simantics SysDyn using MdlParser \r
model = new MdlParser().parse(file);\r
}\r
catch (Exception e) {\r
- e.printStackTrace();\r
+ ExceptionUtils.logAndShowError(e);\r
return null;\r
}\r
\r
</launcher>\r
\r
<vm>\r
- <windows include="true">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6</windows>\r
+ <windows include="true">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</windows>\r
</vm>\r
\r
<license>\r
\r
<features>\r
<feature id="org.simantics.sysdyn" version="1.8.0.qualifier"/>\r
+ <feature id="fi.semantum.simupedia" version="1.0.0.qualifier"/>\r
</features>\r
\r
\r
org.simantics.sysdyn.modelExport,
org.simantics.sysdyn.modelImport,
org.simantics.sysdyn.modelImport.model,
+ org.simantics.sysdyn.modelImport.model.expression,
org.simantics.sysdyn.modelParser,
org.simantics.sysdyn.modelica,
org.simantics.sysdyn.representation,
// by an open parenthesis or a special name)\r
public static final String VARIABLE_EXPRESSION =\r
"([A-Za-z](?![\\s\\w]*\\()\\w*(?:\\s+\\w+)*|"+SPECIAL_NAME+")";\r
- // matches a vensim subscript variable (basic name with a list of indices)\r
+ // matches a vensim subscript variable (variable with a list of indices)\r
public static final String SUBSCRIPT =\r
- "("+BASIC_NAME+")\\[("+BASIC_NAME+"\\!?(?:,"+BASIC_NAME+"\\!?)*)\\]";\r
+ VARIABLE+"\\[("+BASIC_NAME+"\\!?(?:,"+BASIC_NAME+"\\!?)*)\\]";\r
// matches a vensim function (basic name followed by an open parenthesis)\r
public static final String FUNCTION =\r
"("+BASIC_NAME+")\\s*\\(";\r
// replace double quotes with single quotes in quoted variable\r
// names as per modelica syntax (currently useless and might \r
// actually break something)\r
- result.append('\'');\r
- result.append(variable.substring(1, variable.length() - 1));\r
- result.append('\'');\r
+// result.append('\'');\r
+// result.append(variable.substring(1, variable.length() - 1));\r
+// result.append('\'');\r
+ // try this: replace quoted variable names with normalized versions\r
+ String foobar = variable.replace('"', ' ');\r
+ foobar = foobar.replace('-', ' ');\r
+ result.append(variable);\r
}\r
else {\r
// in all other cases, manipulate variable names slightly to \r
// are replaced with dot-operations (e.g. * with .*) inside\r
// the parameters\r
result.append("sum(");\r
+ // TODO: notice that this does not work correctly, should be replaced with a proper parser\r
int closing = expression.indexOf(')', matcher.end());\r
String parameters = expression.substring(matcher.end(), closing);\r
parameters = parameters.replaceAll("\\*", ".*");\r
parameters = parameters.replaceAll("-", ".-");\r
result.append(parameters);\r
offset = closing;\r
+ offset = matcher.end();\r
}\r
else if (function.equalsIgnoreCase("if then else")) {\r
result.append("IFTHENELSE(");\r
double x1 = (double)points[0];\r
double y1 = (double)points[1];\r
\r
- //System.err.println("("+x0+","+y0+") -> ("+x1+","+y1+") -> ("+x2+","+y2+")");\r
-\r
double dx0 = x1 - x0;\r
double dy0 = y1 - y0;\r
double dx1 = x1 - x2;\r
String expression = MdlUtil.normalize(matcher.group(subscriptExpression));\r
\r
Subscript subscript;\r
- if (equivalent)\r
+ if (equivalent) {\r
subscript = new Subscript(name, mdl, expression);\r
- else\r
+ }\r
+ else {\r
subscript = new Subscript(name, mdl, Arrays.asList(expression.split(",")));\r
+ }\r
subscript.parseSuffix(matcher.group(subscriptSuffix));\r
return subscript;\r
}\r
connections.add(connection);\r
}\r
\r
+ public List<Flow> getInFlows(Variable variable) {\r
+ List<Flow> flows = new ArrayList<Flow>();\r
+ for (Connection connection : connections) {\r
+ if (connection instanceof Flow && connection.getHead().equals(variable)) {\r
+ flows.add((Flow)connection);\r
+ }\r
+ }\r
+ return flows;\r
+ }\r
+ \r
+ public List<Flow> getOutFlows(Variable variable) {\r
+ List<Flow> flows = new ArrayList<Flow>();\r
+ for (Connection connection : connections) {\r
+ if (connection instanceof Flow && connection.getTail().equals(variable)) {\r
+ flows.add((Flow)connection);\r
+ }\r
+ }\r
+ return flows;\r
+ }\r
+ \r
+ public List<Dependency> getInDependencies(Variable variable) {\r
+ List<Dependency> deps = new ArrayList<Dependency>();\r
+ for (Connection connection : connections) {\r
+ if (connection instanceof Dependency && connection.getHead().equals(variable)) {\r
+ deps.add((Dependency)connection);\r
+ }\r
+ }\r
+ return deps;\r
+ }\r
+ \r
+ public List<Dependency> getOutDependencies(Variable variable) {\r
+ List<Dependency> deps = new ArrayList<Dependency>();\r
+ for (Connection connection : connections) {\r
+ if (connection instanceof Dependency && connection.getTail().equals(variable)) {\r
+ deps.add((Dependency)connection);\r
+ }\r
+ }\r
+ return deps;\r
+ }\r
+ \r
public void addEnumeration(Enumeration enumeration) {\r
if (enumerations.get(enumeration.getName()) != null) {\r
System.err.println("enumeration "+enumeration.getName()+" already defined");\r
private TextPosition position;\r
\r
public Valve() {\r
- \r
+ // TODO: should this really be done here?\r
+ this.orientation = Orientation.HORIZONTAL;\r
+ this.position = TextPosition.UNSET;\r
}\r
\r
public Valve(Orientation orientation, TextPosition position) {\r