public Variable target;\r
public IExpression[] subscripts;\r
public IExpression expression;\r
- public boolean assigned = false;\r
+ //public boolean assigned = false;\r
public boolean isConstant = false;\r
\r
public Assignment(IFrame model, Variable target, IExpression[] subscripts, IExpression expression) {\r
}\r
}\r
\r
- public void assign(IEnvironment env) {\r
+ public void assign(Environment env) {\r
try {\r
Object value = expression.evaluate(env);\r
if(value != null) {\r
validate(target, value);\r
target.assign(env, subscripts, value);\r
- assigned = true;\r
+ env.setAssigned(this);\r
}\r
} catch (ExecutionException e) {\r
if(model instanceof Model) {\r
--- /dev/null
+package fi.semantum.sysdyn.solver;\r
+\r
+import java.io.StringReader;\r
+import java.util.HashMap;\r
+import java.util.LinkedList;\r
+import java.util.Map;\r
+\r
+import fi.semantum.sysdyn.solver.Model.Globals;\r
+import fi.semantum.sysdyn.solver.parser.ModelParser;\r
+import fi.semantum.sysdyn.solver.parser.ParseException;\r
+import fi.semantum.sysdyn.solver.parser.SimpleNode;\r
+\r
+public class CodeCache {\r
+\r
+ final static int CACHE_SIZE = 5;\r
+ \r
+ private static CodeCache INSTANCE;\r
+ \r
+ final Map<String,Model> models = new HashMap<String,Model>();\r
+ final LinkedList<String> codes = new LinkedList<String>();\r
+ \r
+ public static CodeCache getInstance() {\r
+ if(INSTANCE == null) INSTANCE = new CodeCache();\r
+ return INSTANCE;\r
+ }\r
+ \r
+ private CodeCache() {\r
+ }\r
+ \r
+ public Model getModel(String code) throws ParseException {\r
+ \r
+ Model model = models.get(code);\r
+ if(model == null) {\r
+\r
+ StringReader reader = new StringReader(code);\r
+ ModelParser modelParser = new ModelParser(reader);\r
+ SimpleNode n = (SimpleNode)modelParser.stored_definition();\r
+\r
+ Parser parser = new Parser();\r
+ model = new Model(new Globals(), "", false);\r
+ parser.walk(n, 0, model);\r
+ \r
+ model.prepare();\r
+ model.prepareFunctions();\r
+ model.sortAssignments();\r
+ \r
+ models.put(code, model);\r
+ if(codes.size() == 5) {\r
+ String last = codes.removeLast();\r
+ models.remove(last);\r
+ codes.addFirst(code);\r
+ }\r
+ \r
+ }\r
+ \r
+ return model;\r
+ \r
+ }\r
+ \r
+}\r
put(index, value);\r
}\r
\r
+ public void setAssigned(Object ass) {\r
+ assigned.add(ass);\r
+ }\r
+ \r
+ public boolean isAssigned(Object o) {\r
+ return assigned.contains(o);\r
+ }\r
+ \r
+ private Set<Object> assigned = new HashSet<Object>();\r
+ \r
}\r
\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
import java.util.HashMap;\r
+import java.util.HashSet;\r
import java.util.List;\r
import java.util.Map;\r
+import java.util.Set;\r
import java.util.TreeMap;\r
\r
+import org.simantics.utils.datastructures.MapList;\r
+\r
+import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor;\r
+\r
class Model implements IFrame {\r
\r
static class Globals {\r
public final Globals globals;\r
\r
public int line = -1;\r
- public String name;\r
public boolean isEnumClass;\r
\r
+ private String name;\r
+ private int size;\r
+ \r
public Model(Globals globals, String name, boolean isEnumClass) {\r
this.globals = globals;\r
this.name = name;\r
\r
if(!done) throw new IllegalStateException();\r
\r
- int nextIndex = 0;\r
+ size = 0;\r
for(Map.Entry<String, VariableBase> entry : names.entrySet()) {\r
VariableBase base = entry.getValue();\r
- base.index = nextIndex;\r
+ base.index = size;\r
if(PRINT)\r
System.err.println("Variable: " + entry.getKey() + " " + base.index + " " + Arrays.toString(base.dimensions));\r
int dim = base.dimension();\r
if(dim == -1) dim = 1;\r
- nextIndex += dim;\r
+ size += dim;\r
}\r
\r
if(PRINT)\r
System.err.println("==================");\r
\r
- return nextIndex;\r
+ return size;\r
\r
}\r
\r
+ public int getSize() {\r
+ return size;\r
+ }\r
+ \r
public void prettyPrint() {\r
\r
System.err.println("initials");\r
\r
}\r
\r
+ public void prepareFunctions() {\r
+ \r
+ for(Fn fn : functions.values()) {\r
+ if(fn instanceof Function)\r
+ ((Function)fn).prepare();\r
+ }\r
+\r
+ }\r
+ \r
+ public void sortAssignments() {\r
+\r
+ final MapList<String,Assignment> asses = new MapList<String,Assignment>();\r
+ for(Assignment ass : assignments) asses.add(ass.target.base.name, ass);\r
+ \r
+ final List<VariableBase> found = new ArrayList<VariableBase>();\r
+ final Set<String> visited = new HashSet<String>();\r
+\r
+ ExpressionVisitor sortVisitor = new ExpressionVisitor() {\r
+ @Override\r
+ public void visit(IExpression expression) {\r
+ if(expression instanceof Variable) {\r
+ Variable var = (Variable)expression;\r
+ if(visited.add(var.base.name)) {\r
+ for(Assignment ass : asses.getValues(var.base.name)) {\r
+ ass.expression.accept(this);\r
+ if(ass.subscripts != null)\r
+ for(IExpression e : ass.subscripts) e.accept(this);\r
+ }\r
+ found.add(var.base);\r
+ }\r
+ }\r
+ }\r
+ };\r
+ \r
+ // Sort assignments\r
+ for(Assignment ass : assignments) {\r
+ ass.target.accept(sortVisitor);\r
+ }\r
+\r
+ Collections.sort(assignments, new Comparator<Assignment>() {\r
+\r
+ @Override\r
+ public int compare(Assignment o1, Assignment o2) {\r
+ int i1 = found.indexOf(o1.target.base); \r
+ int i2 = found.indexOf(o2.target.base);\r
+ if(i1 < i2) return -1;\r
+ else if (i1 > i2) return 1;\r
+ return 0;\r
+ }\r
+\r
+ \r
+ });\r
+ \r
+ assignmentArray = assignments.toArray(new Assignment[assignments.size()]);\r
+ derivativeArray = derivatives.toArray(new Assignment[derivatives.size()]);\r
+ parameterArray = parameters.toArray(new ParameterDeclaration[parameters.size()]);\r
+ \r
+ }\r
+ \r
}
\ No newline at end of file
\r
public Variable variable;\r
public IExpression modification;\r
- public boolean assigned = false;\r
+// public boolean assigned = false;\r
\r
public ParameterDeclaration(Variable variable, IExpression modification) {\r
this.variable = variable;\r
SimpleNode child = (SimpleNode)n.jjtGetChild(0);\r
String packagePath = getPackagePath(child);\r
String functionName = packagePath + child.op;\r
- System.err.println("function " + functionName + " at line " + child.line);\r
ArrayList<IStatement> stms2 = new ArrayList<IStatement>();\r
Function function = new Function(functionName, new StatementList(stms2), child.line);\r
ArrayList<Object> composition = (ArrayList<Object>)walk(child, indent+2, function);\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-import java.io.StringReader;\r
import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
\r
-import org.simantics.utils.datastructures.MapList;\r
-\r
-import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor;\r
-import fi.semantum.sysdyn.solver.Model.Globals;\r
-import fi.semantum.sysdyn.solver.parser.ModelParser;\r
import fi.semantum.sysdyn.solver.parser.SimpleNode;\r
\r
public class Solver {\r
ready = false;\r
}\r
\r
- private void sortAssignments() {\r
-\r
- final MapList<String,Assignment> asses = new MapList<String,Assignment>();\r
- for(Assignment ass : model.assignments) asses.add(ass.target.base.name, ass);\r
- \r
- final List<VariableBase> found = new ArrayList<VariableBase>();\r
- final Set<String> visited = new HashSet<String>();\r
-\r
- ExpressionVisitor sortVisitor = new ExpressionVisitor() {\r
- @Override\r
- public void visit(IExpression expression) {\r
- if(expression instanceof Variable) {\r
- Variable var = (Variable)expression;\r
- if(visited.add(var.base.name)) {\r
- for(Assignment ass : asses.getValues(var.base.name)) {\r
- ass.expression.accept(this);\r
- if(ass.subscripts != null)\r
- for(IExpression e : ass.subscripts) e.accept(this);\r
- }\r
- found.add(var.base);\r
- }\r
- }\r
- }\r
- };\r
- \r
- // Sort assignments\r
- for(Assignment ass : model.assignments) {\r
- ass.target.accept(sortVisitor);\r
- }\r
-\r
- Collections.sort(model.assignments, new Comparator<Assignment>() {\r
-\r
- @Override\r
- public int compare(Assignment o1, Assignment o2) {\r
- int i1 = found.indexOf(o1.target.base); \r
- int i2 = found.indexOf(o2.target.base);\r
- if(i1 < i2) return -1;\r
- else if (i1 > i2) return 1;\r
- return 0;\r
- }\r
-\r
- \r
- });\r
- \r
- }\r
-\r
private SimpleNode n;\r
private String codeCache = null;\r
\r
\r
long startNanos = System.nanoTime();\r
\r
- if(!input.equals(codeCache)) {\r
+ model = CodeCache.getInstance().getModel(input);\r
\r
- StringReader reader = new StringReader(input);\r
- ModelParser modelParser = new ModelParser(reader);\r
- n = (SimpleNode)modelParser.stored_definition();\r
+// if(!input.equals(codeCache)) {\r
+// \r
+// StringReader reader = new StringReader(input);\r
+// ModelParser modelParser = new ModelParser(reader);\r
+// n = (SimpleNode)modelParser.stored_definition();\r
+//\r
+// Parser parser = new Parser();\r
+// model = new Model(new Globals(), "", false);\r
+// parser.walk(n, 0, model);\r
+// \r
+// model.prepare();\r
+// model.prepareFunctions();\r
+// model.sortAssignments();\r
+//\r
+// codeCache = input;\r
+//\r
+// }\r
\r
- }\r
-\r
- Parser parser = new Parser();\r
- model = new Model(new Globals(), "", false);\r
- parser.walk(n, 0, model);\r
- codeCache = input;\r
-\r
- env = new Environment(model, defaultStep, start);\r
+ int size = model.getSize();\r
\r
- int size = model.prepare();\r
+ env = new Environment(model, defaultStep, start);\r
env.setSize(size);\r
- \r
- for(Fn fn : model.functions.values()) {\r
- if(fn instanceof Function)\r
- ((Function)fn).prepare();\r
- }\r
- \r
env.valueTable = new Object[size+STACK_SIZE];\r
\r
- sortAssignments();\r
- \r
- model.assignmentArray = model.assignments.toArray(new Assignment[model.assignments.size()]);\r
- model.derivativeArray = model.derivatives.toArray(new Assignment[model.derivatives.size()]);\r
- model.parameterArray = model.parameters.toArray(new ParameterDeclaration[model.parameters.size()]);\r
- \r
newValues = new Object[Math.max(model.assignments.size(),model.derivatives.size())];\r
\r
int condition = 1;\r
\r
StringBuilder errors = null;\r
\r
+ ArrayList<Assignment> assignments = new ArrayList<Assignment>();\r
+ assignments.addAll(model.assignments);\r
+ assignments.addAll(model.initials);\r
+\r
while(condition > 0 && loops++ < MAX_LOOPS) {\r
\r
if(loops == MAX_LOOPS) errors = new StringBuilder();\r
\r
for(ParameterDeclaration pd : model.parameters) {\r
try {\r
- if(!pd.assigned) {\r
+ if(!env.isAssigned(pd)) {\r
Object value = pd.modification.evaluate(env);\r
validate(pd.variable, value);\r
pd.variable.assign(env, null, value);\r
- pd.assigned = true;\r
+ env.setAssigned(pd);\r
}\r
} catch (Exception e) {\r
String error = " -" + pd.variable.toString() + ": " + e.getMessage();\r
}\r
}\r
\r
- ArrayList<Assignment> assignments = new ArrayList<Assignment>();\r
- assignments.addAll(model.assignments);\r
- assignments.addAll(model.initials);\r
-\r
for(VariableDeclaration vd : model.variables) {\r
try {\r
- if(!vd.assigned) {\r
+ if(!env.isAssigned(vd)) {\r
for(Argument arg : vd.modification.args) {\r
if(arg.name.endsWith("start")) {\r
Object value = arg.modification.evaluate(env);\r
// efficient way\r
for (Assignment a : assignments) {\r
if (vd.variable.base.equals(a.target.base)) {\r
- a.assigned = true;\r
+ env.setAssigned(a);\r
}\r
}\r
}\r
\r
for(Assignment ass : assignments) {\r
try {\r
- if(!ass.assigned)\r
+ if(!env.isAssigned(ass))\r
ass.assign(env);\r
} catch (Exception e) {\r
String error = " -" + ass.target.toString() + ": " + e.getMessage();\r
public String direction;\r
public String type;\r
public ArgumentList modification;\r
- public boolean assigned = false;\r
+// public boolean assigned = false;\r
\r
public VariableDeclaration(Variable variable, String direction, String type, ArgumentList modification) {\r
this.variable = variable;\r
\r
public class ChartPropertyOptions {\r
\r
- public static final int SHOW_TIME = 1 << 0;\r
- public static final int SHOW_FILTER = 1 << 1;\r
+ public static final int SHOW_TIME = 1 << 0;\r
+ public static final int SHOW_FILTER = 1 << 1;\r
+ public static final int SHOW_VARIABLES = 1 << 2;\r
+ public static final int SHOW_AXIS = 1 << 3;\r
+ public static final int SHOW_CHART = 1 << 4;\r
\r
}\r
public class ChartSelectionTabContributor {\r
\r
public static boolean contibuteTabs(ReadGraph backend, Resource r, List<ComparableTabContributor> tabs) throws DatabaseException{\r
- return contibuteTabs(backend, r, tabs, ChartPropertyOptions.SHOW_TIME);\r
+ return contibuteTabs(backend, r, tabs, ChartPropertyOptions.SHOW_TIME|ChartPropertyOptions.SHOW_AXIS|ChartPropertyOptions.SHOW_VARIABLES|ChartPropertyOptions.SHOW_CHART);\r
}\r
public static boolean contibuteTabs(ReadGraph backend, Resource r, List<ComparableTabContributor> tabs, int options) throws DatabaseException {\r
JFreeChartResource jfree = JFreeChartResource.getInstance(backend);\r
10,\r
r,\r
"General"));\r
- tabs.add(new ComparableTabContributor(\r
- new XYLineAxisAndVariablesTab(r),\r
- 9,\r
- r,\r
- "Axis and Variables"));\r
+ if ((options&ChartPropertyOptions.SHOW_AXIS )>0 ||(options&ChartPropertyOptions.SHOW_VARIABLES)>0 )\r
+ tabs.add(new ComparableTabContributor(\r
+ new XYLineAxisAndVariablesTab(r),\r
+ 9,\r
+ r,\r
+ "Axis and Variables"));\r
} else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
tabs.add(new ComparableTabContributor(\r
new BarGeneralPropertiesTab(r, options),\r
10,\r
r,\r
"General"));\r
- tabs.add(new ComparableTabContributor(\r
- new BarSeriesTab(r, options),\r
- 9,\r
- r,\r
- "Variables"));\r
- tabs.add(new ComparableTabContributor(\r
- new BarAxisTab(r),\r
- 8,\r
- r,\r
- "Axis")); \r
+ if ((options&ChartPropertyOptions.SHOW_VARIABLES )>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new BarSeriesTab(r, options),\r
+ 9,\r
+ r,\r
+ "Variables"));\r
+ if ((options&ChartPropertyOptions.SHOW_AXIS )>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new BarAxisTab(r),\r
+ 8,\r
+ r,\r
+ "Axis")); \r
} else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
tabs.add(new ComparableTabContributor(\r
new PieGeneralPropertiesTab(r, options),\r
10,\r
r,\r
"General"));\r
- tabs.add(new ComparableTabContributor(\r
- new PieSeriesTab(r, options),\r
- 9,\r
- r,\r
- "Variables"));\r
+ if ((options&ChartPropertyOptions.SHOW_VARIABLES )>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new PieSeriesTab(r, options),\r
+ 9,\r
+ r,\r
+ "Variables"));\r
}\r
-\r
- tabs.add(new ComparableTabContributor(\r
- new ChartTab(r),\r
- 1,\r
- r,\r
- "Chart"));\r
+ if ((options&ChartPropertyOptions.SHOW_CHART )>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new ChartTab(r),\r
+ 1,\r
+ r,\r
+ "Chart"));\r
\r
return true;\r
} \r
}\r
\r
public static boolean contibuteTabs2(ReadGraph backend, Resource r, List<ComparableTabContributor> tabs) throws DatabaseException{\r
- return contibuteTabs2(backend, r, tabs, ChartPropertyOptions.SHOW_TIME);\r
+ return contibuteTabs2(backend, r, tabs, ChartPropertyOptions.SHOW_TIME|ChartPropertyOptions.SHOW_AXIS|ChartPropertyOptions.SHOW_VARIABLES|ChartPropertyOptions.SHOW_CHART);\r
}\r
\r
public static boolean contibuteTabs2(ReadGraph backend, Resource r, List<ComparableTabContributor> tabs, int options) throws DatabaseException {\r
10,\r
r,\r
"General"));\r
- tabs.add(new ComparableTabContributor(\r
- new XYLineAxisAndVariablesTab(r),\r
- 9,\r
- r,\r
- "Axis and Variables"));\r
- } else if(backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
- tabs.add(new ComparableTabContributor(\r
+ if ((options&ChartPropertyOptions.SHOW_AXIS )>0 ||(options&ChartPropertyOptions.SHOW_VARIABLES)>0 )\r
+ tabs.add(new ComparableTabContributor(\r
+ new XYLineAxisAndVariablesTab(r),\r
+ 9,\r
+ r,\r
+ "Axis and Variables"));\r
+ } else if (backend.isInstanceOf(plot, jfree.CategoryPlot)) {\r
+ tabs.add(new ComparableTabContributor(\r
new BarGeneralPropertiesTab(r, options),\r
10,\r
r,\r
"General"));\r
- tabs.add(new ComparableTabContributor(\r
- new BarSeriesTab2(r, options),\r
- 9,\r
- r,\r
- "Variables"));\r
- tabs.add(new ComparableTabContributor(\r
- new BarAxisTab(r),\r
- 8,\r
- r,\r
- "Axis")); \r
+ if ((options&ChartPropertyOptions.SHOW_VARIABLES)>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new BarSeriesTab2(r, options),\r
+ 9,\r
+ r,\r
+ "Variables"));\r
+ if ((options&ChartPropertyOptions.SHOW_AXIS )>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new BarAxisTab(r),\r
+ 8,\r
+ r,\r
+ "Axis")); \r
} else if(backend.isInstanceOf(plot, jfree.PiePlot)) {\r
tabs.add(new ComparableTabContributor(\r
new PieGeneralPropertiesTab(r, options),\r
10,\r
r,\r
"General"));\r
- tabs.add(new ComparableTabContributor(\r
- new PieSeriesTab2(r, options),\r
- 9,\r
- r,\r
- "Variables"));\r
+ if ((options&ChartPropertyOptions.SHOW_VARIABLES)>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new PieSeriesTab2(r, options),\r
+ 9,\r
+ r,\r
+ "Variables"));\r
}\r
-\r
- tabs.add(new ComparableTabContributor(\r
- new ChartTab(r),\r
- 1,\r
- r,\r
- "Chart"));\r
+ if ((options&ChartPropertyOptions.SHOW_CHART )>0)\r
+ tabs.add(new ComparableTabContributor(\r
+ new ChartTab(r),\r
+ 1,\r
+ r,\r
+ "Chart"));\r
\r
return true;\r
} \r
SYSDYN.ResultSet <T L0.Entity
>-- SYSDYN.Experiment.result --> SYSDYN.Result <R L0.IsComposedOf
-SYSDYN.InitialCondition <T SIMU.State
+SYSDYN.InitialCondition <T MOD.InitialCondition
>-- SYSDYN.InitialCondition.HasInitialValues --> MOD.PartialIC <R L0.HasProperty : L0.FunctionalRelation
checkEnabled="true">\r
<with\r
variable="selection">\r
+ <or>\r
<test\r
args="org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
+ <test\r
+ args="http://www.simantics.org/Layer0-0.0/SharedOntology"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
+ <test\r
+ args="http://www.simantics.org/Layer0-0.0/Library"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
+ <test\r
+ args="http://www.simantics.org/Simulation-0.0/Model"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
+ </or>\r
</with>\r
</visibleWhen>\r
</command>\r
args="org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
+ <test\r
+ args="http://www.simantics.org/Layer0-0.0/SharedOntology"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
+ <test\r
+ args="http://www.simantics.org/Layer0-0.0/Library"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
+ <test\r
+ args="http://www.simantics.org/Simulation-0.0/Model"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
</or>\r
</with>\r
</activeWhen>\r
if(variable == null)\r
continue;\r
\r
- Resource represents = (Resource)variable.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource represents = (Resource)variable.getRepresents(graph);\r
if(represents == null || \r
!(graph.isInstanceOf(represents, sr.IndependentVariable) || \r
graph.isInstanceOf(represents, sr.Input)))\r
ArrayList<Variable> variables = new ArrayList<Variable>();\r
\r
for(Variable child : variable.getChildren(graph)) {\r
- Resource represents = (Resource)child.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource represents = child.getRepresents(graph);\r
if(graph.isInstanceOf(represents, sr.IndependentVariable)) {\r
variables.add(child);\r
} else if (graph.isInstanceOf(represents, sr.Input)) {\r
\r
\r
for(Variable child : variable.getChildren(graph)) {\r
- Resource represents = (Resource)child.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource represents = child.getRepresents(graph);\r
if(graph.isInstanceOf(represents, sr.IndependentVariable)) {\r
variables.put(child.getName(graph), child);\r
} else if (graph.isInstanceOf(represents, sr.Input)) {\r
\r
for (String s : variables.keySet()) {\r
Variable v = variables.get(s);\r
- Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource represents = v.getRepresents(graph);\r
result.add(new VariableNode<Variable>(v, represents));\r
}\r
\r
for (String s : inputs.keySet()) {\r
Variable v = inputs.get(s);\r
- Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource represents = v.getRepresents(graph);\r
result.add(new InputNode(v, represents));\r
}\r
\r
for (String s : modules.keySet()) {\r
Variable v = modules.get(s);\r
- Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource represents = v.getRepresents(graph);\r
result.add(new ModuleNode(v, represents));\r
}\r
\r
for (String s : enumerations.keySet()) {\r
Variable v = enumerations.get(s);\r
- Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource represents = v.getRepresents(graph);\r
result.add(new EnumerationNode(v, represents));\r
}\r
\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.Activator;\r
\r
String image = "icons/brick.png";\r
\r
- Resource r = (Resource)var.getPropertyValue(graph, Variables.REPRESENTS);\r
+ Resource r = var.getRepresents(graph);\r
if(r != null) {\r
Layer0 L0 = Layer0.getInstance(graph);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
ISelection sel = HandlerUtil.getCurrentSelection(event);\r
\r
@SuppressWarnings("unchecked")\r
- AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
- if (node == null)\r
- return null;\r
+ Resource res = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+ if(res == null) {\r
+ @SuppressWarnings("unchecked")\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+ res = node.data;\r
+ }\r
\r
- final Resource parent = node.data;\r
+ final Resource parent = res;\r
\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.List;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.WriteGraph;\r
return datasets;\r
\r
Collection<SysdynResult> results = experiment.getActiveResults();\r
- ArrayList<String> variableNamesWithIndexes = getVariableNamesWithIndexNumbers();\r
- ArrayList<String> variableNames = getVariableNames();\r
+ List<String> variableNamesWithIndexes = getVariableNamesWithIndexNumbers();\r
+ List<String> variableNames = getVariableNames();\r
\r
for(int i = 0; i < variableNamesWithIndexes.size(); i++) {\r
for(SysdynResult result : results) {\r
package org.simantics.sysdyn.adapter;\r
\r
import java.util.ArrayList;\r
+import java.util.Collections;\r
import java.util.HashMap;\r
+import java.util.List;\r
\r
import org.simantics.Simantics;\r
import org.simantics.databoard.Bindings;\r
protected HashMap<String, String> rvis;\r
protected String indexes;\r
protected VariableSubscriptionManager subscriptionManager;\r
- protected Pair<ArrayList<String>,ArrayList<String>> variableNameArrays;\r
+ private Pair<List<String>,List<String>> variableNameArrays;\r
\r
public IndexVariable(ReadGraph graph, Variable parent, String indexes) throws DatabaseException {\r
this.parent = parent;\r
\r
}\r
\r
- private Pair<ArrayList<String>,ArrayList<String>> getVariableNameArrays() {\r
+ private Pair<List<String>,List<String>> getVariableNameArrays() {\r
\r
if(variableNameArrays == null) {\r
\r
- Pair<ArrayList<String>,ArrayList<String>> result = new Pair<ArrayList<String>,ArrayList<String>>(new ArrayList<String>(), new ArrayList<String>());\r
if(rvi != null && rvis != null) {\r
\r
if(rvi.indexOf('#') > 0)\r
rvi = rvi.substring(0, rvi.indexOf('#'));\r
\r
+ boolean regexp = false;\r
String test = rvi;\r
if(indexes != null && !indexes.isEmpty()) {\r
- String regexIndexes = indexes.trim().replaceAll(":", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012\r
- test = rvi + "\\[" + regexIndexes + "\\]";\r
+ regexp = indexes.contains(":");\r
+ if(regexp) {\r
+ String regexIndexes = indexes.trim().replaceAll(":", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012\r
+ test = rvi + "\\[" + regexIndexes + "\\]";\r
+ } else {\r
+ test = rvi + "[" + indexes + "]";\r
+ }\r
} else {\r
test = rvi + "(\\[.*\\])?";\r
+ regexp = true;\r
}\r
- for(String k : rvis.keySet()) {\r
- String value = rvis.get(k);\r
- if(k.matches(test) || value.matches(test)) {\r
- result.first.add(k.substring(1).replace("/", ".").replace("%20", "_"));\r
- result.second.add(value.substring(1).replace("/", ".").replace("%20", " "));\r
+ \r
+ Pair<List<String>,List<String>> result = null;\r
+ \r
+ if(regexp) {\r
+ result = new Pair<List<String>,List<String>>(new ArrayList<String>(), new ArrayList<String>());\r
+ for(String k : rvis.keySet()) {\r
+ String value = rvis.get(k);\r
+ if(k.matches(test) || value.matches(test)) {\r
+ result.first.add(transform(k));\r
+ result.second.add(transform(value));\r
+ }\r
+ }\r
+ } else {\r
+ String value = rvis.get(test);\r
+ if(value != null) {\r
+ result = new Pair<List<String>,List<String>>(Collections.singletonList(transform(test)), Collections.singletonList(transform(value)));\r
+ } else {\r
+ for(String k : rvis.keySet()) {\r
+ value = rvis.get(k);\r
+ if(value.equals(test)) {\r
+ result = new Pair<List<String>,List<String>>(Collections.singletonList(transform(k)), Collections.singletonList(transform(test)));\r
+ break;\r
+ }\r
+ }\r
}\r
}\r
\r
\r
}\r
\r
- if(variableNameArrays == null) return new Pair<ArrayList<String>,ArrayList<String>>(new ArrayList<String>(), new ArrayList<String>());\r
+ if(variableNameArrays == null) return new Pair<List<String>,List<String>>(new ArrayList<String>(), new ArrayList<String>());\r
\r
return variableNameArrays;\r
\r
}\r
\r
- protected ArrayList<String> getVariableNames() {\r
+ private String transform(String s) {\r
+ return s.substring(1).replace("/", ".").replace("%20", "_");\r
+ }\r
+ \r
+ protected List<String> getVariableNames() {\r
return getVariableNameArrays().second;\r
}\r
\r
- protected ArrayList<String> getVariableNamesWithIndexNumbers() {\r
+ protected List<String> getVariableNamesWithIndexNumbers() {\r
return getVariableNameArrays().first;\r
}\r
\r
}\r
\r
abstract protected void setIndexedValue(WriteGraph graph, Object value) throws DatabaseException;\r
- \r
-\r
\r
@Override\r
public String getName(ReadGraph graph) throws DatabaseException {\r
return indexes;\r
}\r
\r
- @Override\r
- public Object getSerialized(ReadGraph graph) throws DatabaseException {\r
- return indexes;\r
- }\r
-\r
@Override\r
public Variable getParent(ReadGraph graph) throws DatabaseException {\r
return parent;\r
package org.simantics.sysdyn.adapter;\r
\r
import java.util.ArrayList;\r
+import java.util.List;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.WriteGraph;\r
\r
@Override\r
public String[] getValue() {\r
- ArrayList<String> names = getVariableNames();\r
+ List<String> names = getVariableNames();\r
return names.toArray(new String[names.size()]);\r
}\r
\r
package org.simantics.sysdyn.adapter;\r
\r
-import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.List;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.WriteGraph;\r
return new double[0][0];\r
\r
Collection<SysdynResult> results = experiment.getActiveResults();\r
- ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ List<String> variableNames = getVariableNamesWithIndexNumbers();\r
\r
double[][] result = new double[variableNames.size()][];\r
for(int i = 0; i < variableNames.size(); i++) {\r
package org.simantics.sysdyn.adapter;\r
\r
-import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.List;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
\r
\r
Collection<SysdynResult> results = experiment.getActiveResults();\r
- ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ List<String> variableNames = getVariableNamesWithIndexNumbers();\r
\r
double[] result = new double[variableNames.size()];\r
for(int i = 0; i < variableNames.size(); i++) {\r
\r
try {\r
\r
- ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ List<String> variableNames = getVariableNamesWithIndexNumbers();\r
for(int i = 0; i < variableNames.size() && i < values.length; i++) {\r
\r
if(values[i] == Double.NaN)\r
return "$" + index;\r
}\r
\r
- @Override\r
- public Object getSerialized(ReadGraph graph) throws DatabaseException {\r
- return "$" + index;\r
- }\r
- \r
@Override\r
public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
return Datatypes.DOUBLE;\r
package org.simantics.sysdyn.adapter;\r
\r
-import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.List;\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.WriteGraph;\r
\r
@Override\r
public double[][] getValue() {\r
- ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ List<String> variableNames = getVariableNamesWithIndexNumbers();\r
double[][] result = new double[variableNames.size()][];\r
\r
if (experiment != null) {\r
*******************************************************************************/\r
package org.simantics.sysdyn.adapter;\r
\r
+import gnu.trove.map.hash.THashMap;\r
+\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.LinkedHashMap;\r
import java.util.List;\r
+import java.util.Map;\r
\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.layer0.request.VariableRead;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.db.request.ReadExt;\r
+import org.simantics.db.request.RequestFlags;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
}\r
\r
\r
- /**\r
- * Returns rvis in a map in format /ModuleInstance/Variable[1] = /ModuleInstance/Variable[index1]\r
- * @param graph ReadGraph\r
- * @param variable Variable for the rvis\r
- * @return rvis in a map. Keys are numerical formatted array indexes and values are textual.\r
- * @throws DatabaseException\r
- */\r
- public static HashMap<String, String> getActiveRVIs(ReadGraph graph, Variable variable) throws DatabaseException {\r
- return graph.syncRequest(new GetActiveRVIs(variable));\r
- }\r
+// /**\r
+// * Returns rvis in a map in format /ModuleInstance/Variable[1] = /ModuleInstance/Variable[index1]\r
+// * @param graph ReadGraph\r
+// * @param variable Variable for the rvis\r
+// * @return rvis in a map. Keys are numerical formatted array indexes and values are textual.\r
+// * @throws DatabaseException\r
+// */\r
+// public static HashMap<String, String> getActiveRVIs(ReadGraph graph, Variable variable) throws DatabaseException {\r
+// return graph.syncRequest(new GetActiveRVIs(variable));\r
+// }\r
\r
- public static class GetActiveRVIs extends VariableRead<HashMap<String, String>> {\r
+ public static class GetActiveRVIs extends VariableRead<HashMap<String, String>> implements ReadExt {\r
\r
public GetActiveRVIs(Variable variable) {\r
super(variable);\r
}\r
return rvis;\r
}\r
+\r
+ @Override\r
+ public boolean isImmutable(ReadGraph graph) throws DatabaseException {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public int getType() {\r
+ return RequestFlags.IMMEDIATE_UPDATE;\r
+ }\r
}\r
\r
\r
String currentFilter = filter[i].trim();\r
\r
ArrayList<SysdynDataSet> tempResult = new ArrayList<SysdynDataSet>();\r
- HashMap<String, SysdynDataSet> sums = new HashMap<String, SysdynDataSet>();\r
+ Map<String, SysdynDataSet> sums = new THashMap<String, SysdynDataSet>();\r
for(SysdynDataSet dataset : result) {\r
String tempIndexes = dataset.name.substring(dataset.name.indexOf('[') + 1, dataset.name.indexOf(']'));\r
String[] indexes = tempIndexes.split(",");\r
}\r
\r
}, new DefaultPasteHandler(ic));\r
+ \r
+// String id = input.getName(graph);\r
+// SCLRealm realm = SCLSessionManager.sclRealmById(id);\r
+// if(realm != null) {\r
+// byte[] blob = realm.serialize();\r
+// //graph.addLiteral(ic, SYSDYN.InitialCondition_HasInitialValues, SYSDYN.InitialCondition_HasInitialValues_Inverse, MOD.PartialIC, IC, PartialIC.BINDING);\r
+// }\r
+ \r
}\r
\r
Layer0Utils.addCommentMetadata(graph, "Saved new Initial Condition " + name + " " + ic);\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.exception.MissingVariableException;\r
import org.simantics.db.layer0.util.EvaluatingListener;\r
import org.simantics.db.layer0.util.EvaluatingListener.Criterion;\r
import org.simantics.db.layer0.util.EvaluatingListener.Evaluation;\r
import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.db.request.ReadExt;\r
+import org.simantics.db.request.RequestFlags;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.scl.runtime.function.FunctionImpl1;\r
\r
}\r
\r
- public static class LastValueIndexed extends BinaryRead<Resource, String, org.simantics.db.layer0.variable.Variable> {\r
+ public static class LastValueIndexed extends BinaryRead<org.simantics.db.layer0.variable.Variable, String, org.simantics.db.layer0.variable.Variable> implements ReadExt {\r
\r
- public LastValueIndexed(Resource resource, String path) {\r
- super(resource, path);\r
+ public LastValueIndexed(org.simantics.db.layer0.variable.Variable run, String path) {\r
+ super(run, path);\r
}\r
\r
@Override\r
public org.simantics.db.layer0.variable.Variable perform(ReadGraph graph) throws DatabaseException {\r
\r
- org.simantics.db.layer0.variable.Variable run = Variables.getVariable(graph, parameter);\r
- Pair<String, String> nameAndIndices = splitToNameAndIndices(parameter2);\r
- org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, "/" + nameAndIndices.first + "#value#" + nameAndIndices.second);\r
- if(v == null) throw new MissingVariableException("No variable for SysDyn reference path: " + parameter2);\r
- return v;\r
+ try {\r
+ Pair<String, String> nameAndIndices = splitToNameAndIndices(parameter2);\r
+ org.simantics.db.layer0.variable.Variable v = parameter.browsePossible(graph, "/" + nameAndIndices.first + "#value#" + nameAndIndices.second);\r
+ //if(v == null) throw new MissingVariableException("No variable for SysDyn reference path: " + parameter2);\r
+ if(v == null) return null;\r
+ return v;\r
+ } catch (Throwable e) {\r
+ throw new DatabaseException(e);\r
+ }\r
}\r
+\r
+ @Override\r
+ public boolean isImmutable(ReadGraph graph) throws DatabaseException {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public int getType() {\r
+ return RequestFlags.IMMEDIATE_UPDATE;\r
+ }\r
+ \r
}\r
\r
\r
public static org.simantics.db.layer0.variable.Variable lastValueIndexed(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException {\r
if(run == null) return null;\r
- return graph.syncRequest(new LastValueIndexed(run.getRepresents(graph), path));\r
+ return graph.syncRequest(new LastValueIndexed(run, path));\r
} \r
\r
public static org.simantics.db.layer0.variable.Variable equation(ReadGraph graph, org.simantics.db.layer0.variable.Variable input, String path) throws DatabaseException {\r