\r
long endNanos = System.nanoTime();\r
\r
- System.err.println("Prepared model in " + 1e-6*(endNanos-startNanos) + "ms.");\r
+// System.err.println("Prepared model in " + 1e-6*(endNanos-startNanos) + "ms.");\r
\r
}\r
\r
\r
String test = rvi;\r
if(indexes != null && !indexes.isEmpty()) {\r
- String regexIndexes = indexes.trim().replaceAll("\\b_\\b", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012\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 + "(\\[.*\\])?";\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
\r
-public class ValueIndexVariable extends ValueIndexVariableBase<double[]> {\r
-\r
+public class ValueIndexVariable extends ValueIndexVariableBase<Object> {\r
+ \r
+ private final boolean scalar;\r
+ \r
public ValueIndexVariable(ReadGraph graph, Variable parent, String indexes)\r
throws DatabaseException {\r
super(graph, parent, indexes);\r
+ scalar = indexes.indexOf(":") == -1;\r
}\r
\r
@Override\r
- public double[] getValue() {\r
- return getValueFull();\r
+ public Object getValue() {\r
+ double[] value = getValueFull();\r
+ if (scalar) {\r
+ if (value == UNRESOLVED) { \r
+ return Double.NaN;\r
+ } else {\r
+ return value[0];\r
+ }\r
+ } else {\r
+ return value;\r
+ }\r
}\r
\r
}\r
Variable var = parent.getParent(graph);\r
Resource resource = var.getRepresents(graph);\r
\r
- if(!(value instanceof double[]) || resource == null)\r
+ if(!(value instanceof Double || value instanceof double[]) || resource == null)\r
return;\r
\r
- double[] values = (double[]) value;\r
+ double[] values = null;\r
+ if (value instanceof Double) {\r
+ values = new double[1];\r
+ values[0] = (Double)value;\r
+ } else if (value instanceof double[]) {\r
+ values = (double[]) value; \r
+ }\r
\r
// FMUControlJNI control = null;\r
if(experiment instanceof SysdynGameExperimentBase) { // Support only game experiments for now..\r
}\r
\r
long end = System.nanoTime();\r
- System.err.println("simulate duration took " + 1e-6*(end-start) + "ms.");\r
+// System.err.println("simulate duration took " + 1e-6*(end-start) + "ms.");\r
\r
return Status.OK_STATUS;\r
\r
}\r
\r
public static Resource saveIC(WriteGraph graph, Variable input, String name) throws DatabaseException {\r
- \r
+ graph.markUndoPoint();\r
Resource model = Variables.getModel(graph, input);\r
Resource child = Layer0Utils.getPossibleChild(graph, model, name);\r
SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
graph.addLiteral(ic, SYSDYN.InitialCondition_HasInitialValues, SYSDYN.InitialCondition_HasInitialValues_Inverse, MOD.PartialIC, IC, PartialIC.BINDING);\r
graph.claim(model, L0.ConsistsOf, ic);\r
\r
+ Layer0Utils.addCommentMetadata(graph, "Saved new Initial Condition " + name + " " + ic);\r
return ic;\r
\r
}\r
\r
public static void assignIC(WriteGraph graph, Variable experiment, String name) throws DatabaseException {\r
-\r
+ graph.markUndoPoint();\r
System.err.println("assignIC " + experiment.getURI(graph));\r
\r
Layer0 L0 = Layer0.getInstance(graph);\r
\r
graph.deny(exp, SYSDYN.Experiment_ic);\r
graph.claim(exp, SYSDYN.Experiment_ic, ic);\r
- \r
+ Layer0Utils.addCommentMetadata(graph, "Assigned Initial Condition " + graph.getRelatedValue2(ic, L0.HasName, Bindings.STRING) + " to experiment " + graph.getRelatedValue2(exp, L0.HasName, Bindings.STRING));\r
}\r
\r
public static void deassignIC(WriteGraph graph, Variable experiment) throws DatabaseException {\r
}\r
\r
public static void deleteIC(WriteGraph graph, Variable input, String name) throws DatabaseException {\r
-\r
+ graph.markUndoPoint();\r
Resource model = Variables.getModel(graph, input);\r
Resource child = Layer0Utils.getPossibleChild(graph, model, name);\r
SysdynResource SYSDYN = SysdynResource.getInstance(graph);\r
\r
if((child != null) && graph.isInstanceOf(child, SYSDYN.InitialCondition))\r
RemoverUtil.remove(graph, child);\r
- \r
+ Layer0Utils.addCommentMetadata(graph, "Deleted Initial Condition " + graph.getRelatedValue2(child, Layer0.getInstance(graph).HasName, Bindings.STRING));\r
}\r
\r
}\r
public static String matchUnits(ReadGraph graph, SysdynModel model, Configuration configuration, String unit, String expression) {\r
if(unit == null)\r
return "Unit not defined";\r
- \r
+ if (expression == null)\r
+ return "Expression not defined";\r
try {\r
StringReader rightReader = new StringReader(expression);\r
UnitParser rightParser = new UnitParser(rightReader);\r
*\r
* Contributors:\r
* Semantum Oy - initial API and implementation\r
+ * VTT Technical Research Centre of Finland\r
*******************************************************************************/\r
package org.simantics.sysdyn.unitParser;\r
\r
import org.simantics.sysdyn.unitParser.nodes.FunctionArguments;\r
import org.simantics.sysdyn.unitParser.nodes.FunctionCall;\r
import org.simantics.sysdyn.unitParser.nodes.IfThenElse;\r
+import org.simantics.sysdyn.unitParser.nodes.LogicalExpression;\r
+import org.simantics.sysdyn.unitParser.nodes.LogicalFactor;\r
+import org.simantics.sysdyn.unitParser.nodes.LogicalTerm;\r
import org.simantics.sysdyn.unitParser.nodes.Multiplication;\r
import org.simantics.sysdyn.unitParser.nodes.NamedArguments;\r
import org.simantics.sysdyn.unitParser.nodes.ParenthesisExpression;\r
private static HashMap<String, Class<?>> constructors = new HashMap<String, Class<?>>();\r
\r
static {\r
+ constructors.put("logical_expression", LogicalExpression.class);\r
+ constructors.put("logical_term", LogicalTerm.class);\r
+ constructors.put("logical_factor", LogicalFactor.class);\r
constructors.put("relation", Relation.class);\r
- constructors.put("term", Term.class);\r
+ constructors.put("term", Term.class);\r
constructors.put("factor", Factor.class);\r
constructors.put("arithmetic_expression", Arithmetic.class);\r
constructors.put("ifthenelse", IfThenElse.class);\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.unitParser.nodes;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
+import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
+import org.simantics.sysdyn.utils.Function;\r
+\r
+/**\r
+ * See UnitCheckingNodeFactory for mapping\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class LogicalExpression extends UnitCheckingNode {\r
+\r
+ public LogicalExpression(int id) {\r
+ super(id);\r
+ }\r
+\r
+ @Override\r
+ public UnitResult getUnits(HashMap<String, String> units, ArrayList<Function> functions, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result;\r
+ \r
+ if (jjtGetNumChildren() == 1) {\r
+ result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents);\r
+ } else {\r
+ // If the logical expression is of type logical_term or logical_term, allow\r
+ // all units as input and output unit is scalar\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.unitParser.nodes;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
+import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
+import org.simantics.sysdyn.utils.Function;\r
+\r
+/**\r
+ * See UnitCheckingNodeFactory for mapping\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class LogicalFactor extends UnitCheckingNode {\r
+\r
+ public LogicalFactor(int id) {\r
+ super(id);\r
+ }\r
+\r
+ @Override\r
+ public UnitResult getUnits(HashMap<String, String> units, ArrayList<Function> functions, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result;\r
+ \r
+ if (jjtGetNumChildren() == 1) {\r
+ result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents);\r
+ } else {\r
+ // If the logical factor is of type not relation, allow\r
+ // all units as input and output unit is scalar\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.unitParser.nodes;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
+import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
+import org.simantics.sysdyn.utils.Function;\r
+\r
+/**\r
+ * See UnitCheckingNodeFactory for mapping\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class LogicalTerm extends UnitCheckingNode {\r
+\r
+ public LogicalTerm(int id) {\r
+ super(id);\r
+ }\r
+\r
+ @Override\r
+ public UnitResult getUnits(HashMap<String, String> units, ArrayList<Function> functions, boolean allowEquivalents) throws UnitCheckingException {\r
+ UnitResult result;\r
+ \r
+ if (jjtGetNumChildren() == 1) {\r
+ result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents);\r
+ } else {\r
+ // If the logical term is of type logical_factor and logical_factor, allow\r
+ // all units as input and output unit is scalar\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+\r
+}\r
\r
import org.simantics.sysdyn.unitParser.UnitCheckingException;\r
import org.simantics.sysdyn.unitParser.UnitCheckingNode;\r
+import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType;\r
import org.simantics.sysdyn.utils.Function;\r
\r
/**\r
UnitCheckingNode candidateNode = null;\r
\r
base = ((UnitCheckingNode)jjtGetChild(0));\r
- if(!(base instanceof Arithmetic) && jjtGetNumChildren() > 1)\r
+ if(!(base instanceof Arithmetic) && jjtGetNumChildren() > 1) {\r
base = ((UnitCheckingNode)jjtGetChild(1));\r
+ }\r
\r
if(base instanceof Arithmetic) {\r
result.appendResult(base.getUnits(units, functions, allowEquivalents));\r
operator = ((UnitCheckingNode)jjtGetChild(i-1));\r
UnitResult candidateUnits = candidateNode.getUnits(units, functions, allowEquivalents);\r
if(!result.equals(candidateUnits)) {\r
- result.equals(candidateUnits);\r
throw new UnitCheckingException("Not equals exception: " +\r
base.printNode() + " [" + result.getFullUnit() + "] " + operator.printNode() + " " +\r
candidateNode.printNode() + " [" + candidateUnits.getFullUnit() + "]"\r
);\r
}\r
}\r
-\r
}\r
+ \r
+ if (jjtGetNumChildren() > 1) {\r
+ // If there is an actual relation (e.g. a > b), the output\r
+ // unit is a scalar.\r
+ result = new UnitResult(allowEquivalents);\r
+ result.setUnitType(UnitType.SCALAR);\r
+ }\r
+\r
}\r
\r
return result;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.adapter.Template;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
import org.simantics.document.DocumentResource;\r
import org.simantics.issues.ontology.IssueResource;\r
import org.simantics.layer0.Layer0;\r
\r
// TODO: remove this\r
public static Resource createModelAt(WriteGraph g, Resource library) {\r
+ \r
+ g.markUndoPoint();\r
try {\r
Layer0 l0 = Layer0.getInstance(g);\r
Layer0X L0X = Layer0X.getInstance(g);\r
\r
ProfileEntries.createStandardProfiles(g, model);\r
\r
+ Layer0Utils.addCommentMetadata(g, "Created new Sysdyn Model '" + modelName + "' " + model.toString());\r
+ \r
return model;\r
\r
} catch (DatabaseException e ) {\r
public class SheetUtils {\r
\r
public static Resource createSheet(WriteGraph graph, Resource book, String name, String[] colNames, int[] colWidths) throws DatabaseException {\r
-\r
Layer0 L0 = Layer0.getInstance(graph);\r
SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);\r
\r
// graph.claim(result, L0.HasChildVariables, L0.HasChildVariables_Inverse, newCell);\r
// \r
// }\r
-\r
return result;\r
\r
}\r
import org.simantics.db.layer0.migration.MigrationState;\r
import org.simantics.db.layer0.migration.MigrationStateKeys;\r
import org.simantics.db.layer0.migration.MigrationUtils;\r
+import org.simantics.db.layer0.util.Layer0Utils;\r
import org.simantics.db.layer0.util.ModelDependenciesBean;\r
import org.simantics.db.layer0.util.ModelDependency;\r
import org.simantics.db.layer0.util.RemoverUtil;\r
if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null);\r
\r
beginTask(monitor, "Import model", 10);\r
- File importFile = new File(path);\r
+ final File importFile = new File(path);\r
MigrationState state = MigrationUtils.newState();\r
state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration);\r
state.setProperty(MigrationStateKeys.MODEL_FILE, importFile);\r
\r
Session session = Simantics.getSession();\r
\r
+ //TODO\r
+ // With this empty write it is possible to group change sets nicely in undo view and make good undoable collection\r
+ session.syncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ graph.markUndoPoint();\r
+ Layer0Utils.addCommentMetadata(graph, "Imported Sysdyn model from " + importFile.getName());\r
+ }\r
+ });\r
+ \r
final ModelDependenciesBean dependenciesBean = getModelDependenciesBean(state);\r
if(dependenciesBean != null) {\r
for(ModelDependency dependency : dependenciesBean.dependencies) {\r