From: jsimomaa Date: Thu, 17 Jul 2014 09:21:50 +0000 (+0000) Subject: Merged trunk @29707, 29812, 29904, 29917 to branch 1.8 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=35dfb6f92905596cf5f84b371091b55f2d69ce28;p=simantics%2Fsysdyn.git Merged trunk @29707, 29812, 29904, 29917 to branch 1.8 refs #4987 refs #5067 refs #5093 refs #5113 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches@29923 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java index e03b297d..6ea46d57 100644 --- a/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java +++ b/1.8/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java @@ -249,7 +249,7 @@ public class Solver { long endNanos = System.nanoTime(); - System.err.println("Prepared model in " + 1e-6*(endNanos-startNanos) + "ms."); +// System.err.println("Prepared model in " + 1e-6*(endNanos-startNanos) + "ms."); } diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java index cfd243eb..606b9f33 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/IndexVariable.java @@ -212,7 +212,7 @@ public abstract class IndexVariable extends AbstractPropertyVariable { String test = rvi; if(indexes != null && !indexes.isEmpty()) { - String regexIndexes = indexes.trim().replaceAll("\\b_\\b", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012 + String regexIndexes = indexes.trim().replaceAll(":", "[a-zA-Z0-9_]*"); // Why was there was ".replace('.', ',')" ? - Removed by Teemu 2.9.2012 test = rvi + "\\[" + regexIndexes + "\\]"; } else { test = rvi + "(\\[.*\\])?"; diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java index 3b05dd71..6fb6f77d 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java @@ -4,16 +4,28 @@ import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; -public class ValueIndexVariable extends ValueIndexVariableBase { - +public class ValueIndexVariable extends ValueIndexVariableBase { + + private final boolean scalar; + public ValueIndexVariable(ReadGraph graph, Variable parent, String indexes) throws DatabaseException { super(graph, parent, indexes); + scalar = indexes.indexOf(":") == -1; } @Override - public double[] getValue() { - return getValueFull(); + public Object getValue() { + double[] value = getValueFull(); + if (scalar) { + if (value == UNRESOLVED) { + return Double.NaN; + } else { + return value[0]; + } + } else { + return value; + } } } diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java index 1e7bf51b..0b308f70 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java @@ -58,10 +58,16 @@ abstract public class ValueIndexVariableBase extends IndexVariable { Variable var = parent.getParent(graph); Resource resource = var.getRepresents(graph); - if(!(value instanceof double[]) || resource == null) + if(!(value instanceof Double || value instanceof double[]) || resource == null) return; - double[] values = (double[]) value; + double[] values = null; + if (value instanceof Double) { + values = new double[1]; + values[0] = (Double)value; + } else if (value instanceof double[]) { + values = (double[]) value; + } // FMUControlJNI control = null; if(experiment instanceof SysdynGameExperimentBase) { // Support only game experiments for now.. diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SimulateDurationJob.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SimulateDurationJob.java index 9ff49128..defe0698 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SimulateDurationJob.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SimulateDurationJob.java @@ -94,7 +94,7 @@ class SimulateDurationJob extends Job { } long end = System.nanoTime(); - System.err.println("simulate duration took " + 1e-6*(end-start) + "ms."); +// System.err.println("simulate duration took " + 1e-6*(end-start) + "ms."); return Status.OK_STATUS; diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java index aaa959a5..b48628f2 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiments.java @@ -185,7 +185,7 @@ public class SysdynExperiments { } public static Resource saveIC(WriteGraph graph, Variable input, String name) throws DatabaseException { - + graph.markUndoPoint(); Resource model = Variables.getModel(graph, input); Resource child = Layer0Utils.getPossibleChild(graph, model, name); SysdynResource SYSDYN = SysdynResource.getInstance(graph); @@ -209,12 +209,13 @@ public class SysdynExperiments { graph.addLiteral(ic, SYSDYN.InitialCondition_HasInitialValues, SYSDYN.InitialCondition_HasInitialValues_Inverse, MOD.PartialIC, IC, PartialIC.BINDING); graph.claim(model, L0.ConsistsOf, ic); + Layer0Utils.addCommentMetadata(graph, "Saved new Initial Condition " + name + " " + ic); return ic; } public static void assignIC(WriteGraph graph, Variable experiment, String name) throws DatabaseException { - + graph.markUndoPoint(); System.err.println("assignIC " + experiment.getURI(graph)); Layer0 L0 = Layer0.getInstance(graph); @@ -233,7 +234,7 @@ public class SysdynExperiments { graph.deny(exp, SYSDYN.Experiment_ic); graph.claim(exp, SYSDYN.Experiment_ic, ic); - + Layer0Utils.addCommentMetadata(graph, "Assigned Initial Condition " + graph.getRelatedValue2(ic, L0.HasName, Bindings.STRING) + " to experiment " + graph.getRelatedValue2(exp, L0.HasName, Bindings.STRING)); } public static void deassignIC(WriteGraph graph, Variable experiment) throws DatabaseException { @@ -278,14 +279,14 @@ public class SysdynExperiments { } public static void deleteIC(WriteGraph graph, Variable input, String name) throws DatabaseException { - + graph.markUndoPoint(); Resource model = Variables.getModel(graph, input); Resource child = Layer0Utils.getPossibleChild(graph, model, name); SysdynResource SYSDYN = SysdynResource.getInstance(graph); if((child != null) && graph.isInstanceOf(child, SYSDYN.InitialCondition)) RemoverUtil.remove(graph, child); - + Layer0Utils.addCommentMetadata(graph, "Deleted Initial Condition " + graph.getRelatedValue2(child, Layer0.getInstance(graph).HasName, Bindings.STRING)); } } diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java index 5b630875..8418b14f 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java @@ -94,7 +94,8 @@ public class UnitUtils { public static String matchUnits(ReadGraph graph, SysdynModel model, Configuration configuration, String unit, String expression) { if(unit == null) return "Unit not defined"; - + if (expression == null) + return "Expression not defined"; try { StringReader rightReader = new StringReader(expression); UnitParser rightParser = new UnitParser(rightReader); diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNodeFactory.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNodeFactory.java index 35f22dfb..b24af37a 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNodeFactory.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNodeFactory.java @@ -8,6 +8,7 @@ * * Contributors: * Semantum Oy - initial API and implementation + * VTT Technical Research Centre of Finland *******************************************************************************/ package org.simantics.sysdyn.unitParser; @@ -28,6 +29,9 @@ import org.simantics.sysdyn.unitParser.nodes.ForIndex; import org.simantics.sysdyn.unitParser.nodes.FunctionArguments; import org.simantics.sysdyn.unitParser.nodes.FunctionCall; import org.simantics.sysdyn.unitParser.nodes.IfThenElse; +import org.simantics.sysdyn.unitParser.nodes.LogicalExpression; +import org.simantics.sysdyn.unitParser.nodes.LogicalFactor; +import org.simantics.sysdyn.unitParser.nodes.LogicalTerm; import org.simantics.sysdyn.unitParser.nodes.Multiplication; import org.simantics.sysdyn.unitParser.nodes.NamedArguments; import org.simantics.sysdyn.unitParser.nodes.ParenthesisExpression; @@ -42,8 +46,11 @@ public class UnitCheckingNodeFactory { private static HashMap> constructors = new HashMap>(); static { + constructors.put("logical_expression", LogicalExpression.class); + constructors.put("logical_term", LogicalTerm.class); + constructors.put("logical_factor", LogicalFactor.class); constructors.put("relation", Relation.class); - constructors.put("term", Term.class); + constructors.put("term", Term.class); constructors.put("factor", Factor.class); constructors.put("arithmetic_expression", Arithmetic.class); constructors.put("ifthenelse", IfThenElse.class); diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalExpression.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalExpression.java new file mode 100644 index 00000000..d154ec9d --- /dev/null +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalExpression.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2014 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland + *******************************************************************************/ +package org.simantics.sysdyn.unitParser.nodes; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.simantics.sysdyn.unitParser.UnitCheckingException; +import org.simantics.sysdyn.unitParser.UnitCheckingNode; +import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; + +/** + * See UnitCheckingNodeFactory for mapping + * @author Tuomas Miettinen + * + */ +public class LogicalExpression extends UnitCheckingNode { + + public LogicalExpression(int id) { + super(id); + } + + @Override + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result; + + if (jjtGetNumChildren() == 1) { + result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents); + } else { + // If the logical expression is of type logical_term or logical_term, allow + // all units as input and output unit is scalar + result = new UnitResult(allowEquivalents); + result.setUnitType(UnitType.SCALAR); + } + + return result; + } + +} diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalFactor.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalFactor.java new file mode 100644 index 00000000..ca304bbd --- /dev/null +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalFactor.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2014 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland + *******************************************************************************/ +package org.simantics.sysdyn.unitParser.nodes; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.simantics.sysdyn.unitParser.UnitCheckingException; +import org.simantics.sysdyn.unitParser.UnitCheckingNode; +import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; + +/** + * See UnitCheckingNodeFactory for mapping + * @author Tuomas Miettinen + * + */ +public class LogicalFactor extends UnitCheckingNode { + + public LogicalFactor(int id) { + super(id); + } + + @Override + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result; + + if (jjtGetNumChildren() == 1) { + result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents); + } else { + // If the logical factor is of type not relation, allow + // all units as input and output unit is scalar + result = new UnitResult(allowEquivalents); + result.setUnitType(UnitType.SCALAR); + } + + return result; + } + +} diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalTerm.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalTerm.java new file mode 100644 index 00000000..288a9142 --- /dev/null +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/LogicalTerm.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2014 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland + *******************************************************************************/ +package org.simantics.sysdyn.unitParser.nodes; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.simantics.sysdyn.unitParser.UnitCheckingException; +import org.simantics.sysdyn.unitParser.UnitCheckingNode; +import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; + +/** + * See UnitCheckingNodeFactory for mapping + * @author Tuomas Miettinen + * + */ +public class LogicalTerm extends UnitCheckingNode { + + public LogicalTerm(int id) { + super(id); + } + + @Override + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result; + + if (jjtGetNumChildren() == 1) { + result = ((UnitCheckingNode)jjtGetChild(0)).getUnits(units, functions, allowEquivalents); + } else { + // If the logical term is of type logical_factor and logical_factor, allow + // all units as input and output unit is scalar + result = new UnitResult(allowEquivalents); + result.setUnitType(UnitType.SCALAR); + } + + return result; + } + +} diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java index 5831092b..878b53e1 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java @@ -17,6 +17,7 @@ import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; +import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; import org.simantics.sysdyn.utils.Function; /** @@ -40,8 +41,9 @@ public class Relation extends UnitCheckingNode { UnitCheckingNode candidateNode = null; base = ((UnitCheckingNode)jjtGetChild(0)); - if(!(base instanceof Arithmetic) && jjtGetNumChildren() > 1) + if(!(base instanceof Arithmetic) && jjtGetNumChildren() > 1) { base = ((UnitCheckingNode)jjtGetChild(1)); + } if(base instanceof Arithmetic) { result.appendResult(base.getUnits(units, functions, allowEquivalents)); @@ -53,15 +55,21 @@ public class Relation extends UnitCheckingNode { operator = ((UnitCheckingNode)jjtGetChild(i-1)); UnitResult candidateUnits = candidateNode.getUnits(units, functions, allowEquivalents); if(!result.equals(candidateUnits)) { - result.equals(candidateUnits); throw new UnitCheckingException("Not equals exception: " + base.printNode() + " [" + result.getFullUnit() + "] " + operator.printNode() + " " + candidateNode.printNode() + " [" + candidateUnits.getFullUnit() + "]" ); } } - } + + if (jjtGetNumChildren() > 1) { + // If there is an actual relation (e.g. a > b), the output + // unit is a scalar. + result = new UnitResult(allowEquivalents); + result.setUnitType(UnitType.SCALAR); + } + } return result; diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java index e3212aba..98fb37c0 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java @@ -11,6 +11,7 @@ import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Template; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.document.DocumentResource; import org.simantics.issues.ontology.IssueResource; import org.simantics.layer0.Layer0; @@ -56,6 +57,8 @@ public class ModelUtils { // TODO: remove this public static Resource createModelAt(WriteGraph g, Resource library) { + + g.markUndoPoint(); try { Layer0 l0 = Layer0.getInstance(g); Layer0X L0X = Layer0X.getInstance(g); @@ -178,6 +181,8 @@ public class ModelUtils { ProfileEntries.createStandardProfiles(g, model); + Layer0Utils.addCommentMetadata(g, "Created new Sysdyn Model '" + modelName + "' " + model.toString()); + return model; } catch (DatabaseException e ) { diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java index 9bda6cab..5525cc8d 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/SheetUtils.java @@ -29,7 +29,6 @@ import org.simantics.spreadsheet.resource.SpreadsheetResource; public class SheetUtils { public static Resource createSheet(WriteGraph graph, Resource book, String name, String[] colNames, int[] colWidths) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); SpreadsheetResource sr = SpreadsheetResource.getInstance(graph); @@ -75,7 +74,6 @@ public class SheetUtils { // graph.claim(result, L0.HasChildVariables, L0.HasChildVariables_Inverse, newCell); // // } - return result; } diff --git a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java index 7523baef..ceeff8aa 100644 --- a/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java +++ b/1.8/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/imports/ImportUtils.java @@ -50,6 +50,7 @@ import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor; import org.simantics.db.layer0.migration.MigrationState; import org.simantics.db.layer0.migration.MigrationStateKeys; import org.simantics.db.layer0.migration.MigrationUtils; +import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.util.ModelDependenciesBean; import org.simantics.db.layer0.util.ModelDependency; import org.simantics.db.layer0.util.RemoverUtil; @@ -148,7 +149,7 @@ public class ImportUtils { if(project == null) return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import model: project not found", null); beginTask(monitor, "Import model", 10); - File importFile = new File(path); + final File importFile = new File(path); MigrationState state = MigrationUtils.newState(); state.setProperty(MigrationStateKeys.BASE_URI, SysdynResource.URIs.Migration); state.setProperty(MigrationStateKeys.MODEL_FILE, importFile); @@ -156,6 +157,17 @@ public class ImportUtils { Session session = Simantics.getSession(); + //TODO + // With this empty write it is possible to group change sets nicely in undo view and make good undoable collection + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0Utils.addCommentMetadata(graph, "Imported Sysdyn model from " + importFile.getName()); + } + }); + final ModelDependenciesBean dependenciesBean = getModelDependenciesBean(state); if(dependenciesBean != null) { for(ModelDependency dependency : dependenciesBean.dependencies) {