From: jkauttio Date: Thu, 17 Apr 2014 11:55:12 +0000 (+0000) Subject: Merge changes from trunk X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b9d42db02ee4126eb302518a05ff42f471b14954;p=simantics%2Fsysdyn.git Merge changes from trunk refs #2924 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches/dev-jkauttio@29301 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF b/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF index 7f8fe97d..3256e513 100644 --- a/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF +++ b/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF @@ -7,7 +7,8 @@ Bundle-Activator: fi.semantum.sysdyn.solver.Activator Bundle-Vendor: Semantum Oy Require-Bundle: org.eclipse.core.runtime, org.simantics.utils;bundle-version="1.1.0", - org.simantics.databoard;bundle-version="0.6.5" + org.simantics.databoard;bundle-version="0.6.5", + org.simantics.utils.datastructures;bundle-version="1.1.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: fi.semantum.sysdyn.solver diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java index 27ee6841..a407ca4e 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java @@ -61,4 +61,11 @@ public class Addition implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + exp1.accept(visitor); + exp2.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/And.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/And.java index d77a191c..dc3ab53d 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/And.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/And.java @@ -13,6 +13,8 @@ package fi.semantum.sysdyn.solver; import java.util.ArrayList; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class And implements IExpression { public IExpression[] exps; @@ -59,4 +61,10 @@ public class And implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + for(IExpression exp : exps) exp.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Application.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Application.java index c9c2282c..a59ece28 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Application.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Application.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class Application implements IExpression { public String name; @@ -48,4 +50,11 @@ public class Application implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + for(Argument a : args.args) + a.modification.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Argument.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Argument.java index 3a7013f4..2712ab90 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Argument.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Argument.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class Argument implements IExpression { public String name; @@ -47,4 +49,10 @@ public class Argument implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + modification.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java index 72fcd405..45449362 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; import fi.semantum.sysdyn.solver.SolverUtils.Slice; public class Array implements IExpression { @@ -227,4 +228,15 @@ public class Array implements IExpression { return result; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + for(int i=0;i elements = new ArrayList(); @@ -110,4 +112,15 @@ public class ForArray implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + for(int i=0;i copies); + public void accept(ExpressionVisitor visitor); } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/IfThenElse.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/IfThenElse.java index 2176faf4..a95c99e1 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/IfThenElse.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/IfThenElse.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class IfThenElse implements IExpression { public IExpression exp; @@ -56,4 +58,12 @@ public class IfThenElse implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + exp.accept(visitor); + t.accept(visitor); + e.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessOrEqualThan.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessOrEqualThan.java index 7c2f2870..b9ab757e 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessOrEqualThan.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessOrEqualThan.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class LessOrEqualThan implements IExpression { public IExpression exp1; @@ -51,4 +53,11 @@ public class LessOrEqualThan implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + exp1.accept(visitor); + exp2.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessThan.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessThan.java index 9a808538..db798083 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessThan.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/LessThan.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class LessThan implements IExpression { public IExpression exp1; @@ -51,4 +53,11 @@ public class LessThan implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + exp1.accept(visitor); + exp2.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Multiplication.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Multiplication.java index 00397a37..cc4724ab 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Multiplication.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Multiplication.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class Multiplication implements IExpression { public IExpression exp1; @@ -62,4 +64,11 @@ public class Multiplication implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + exp1.accept(visitor); + exp2.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Negation.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Negation.java index cdf125ba..15e9e2df 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Negation.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Negation.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class Negation implements IExpression { public IExpression exp; @@ -46,4 +48,10 @@ public class Negation implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + exp.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NotEquals.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NotEquals.java index 41ca66a5..5c5499ce 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NotEquals.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NotEquals.java @@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class NotEquals implements IExpression { public IExpression exp1; @@ -49,4 +51,11 @@ public class NotEquals implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + exp1.accept(visitor); + exp2.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NullModification.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NullModification.java index 287d6180..cbafd0d9 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NullModification.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/NullModification.java @@ -23,5 +23,10 @@ public class NullModification implements IExpression { public IExpression rewrite(IFrame frame, Map copies) { return this; } + + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + } } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Or.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Or.java index e08c3282..375c9240 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Or.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Or.java @@ -13,6 +13,8 @@ package fi.semantum.sysdyn.solver; import java.util.ArrayList; import java.util.Map; +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; + public class Or implements IExpression { public IExpression[] exps; @@ -59,4 +61,10 @@ public class Or implements IExpression { return this; } + @Override + public void accept(ExpressionVisitor visitor) { + visitor.visit(this); + for(IExpression exp : exps) exp.accept(visitor); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ParameterDeclaration.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ParameterDeclaration.java index 1aa811f7..72cbab5e 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ParameterDeclaration.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/ParameterDeclaration.java @@ -49,4 +49,9 @@ public class ParameterDeclaration implements IExpression { throw new UnsupportedOperationException(); } + @Override + public void accept(ExpressionVisitor visitor) { + throw new UnsupportedOperationException(); + } + } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java index bcd050d4..1a4aed8c 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Solver.java @@ -13,7 +13,15 @@ package fi.semantum.sysdyn.solver; import java.io.StringReader; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.simantics.utils.datastructures.MapList; + +import fi.semantum.sysdyn.solver.IExpression.ExpressionVisitor; import fi.semantum.sysdyn.solver.Model.Globals; import fi.semantum.sysdyn.solver.parser.ModelParser; import fi.semantum.sysdyn.solver.parser.SimpleNode; @@ -27,6 +35,7 @@ public class Solver { private Environment env; private Object[] newValues; + private Object[] derivatives; private double step; private double start; @@ -51,6 +60,52 @@ public class Solver { ready = false; } + private void sortAssignments() { + + final MapList asses = new MapList(); + for(Assignment ass : model.assignments) asses.add(ass.target.base.name, ass); + + final List found = new ArrayList(); + final Set visited = new HashSet(); + + ExpressionVisitor sortVisitor = new ExpressionVisitor() { + @Override + public void visit(IExpression expression) { + if(expression instanceof Variable) { + Variable var = (Variable)expression; + if(visited.add(var.base.name)) { + for(Assignment ass : asses.getValues(var.base.name)) { + ass.expression.accept(this); + if(ass.subscripts != null) + for(IExpression e : ass.subscripts) e.accept(this); + } + found.add(var.base); + } + } + } + }; + + // Sort assignments + for(Assignment ass : model.assignments) { + ass.target.accept(sortVisitor); + } + + Collections.sort(model.assignments, new Comparator() { + + @Override + public int compare(Assignment o1, Assignment o2) { + int i1 = found.indexOf(o1.target.base); + int i2 = found.indexOf(o2.target.base); + if(i1 < i2) return -1; + else if (i1 > i2) return 1; + return 0; + } + + + }); + + } + public void prepare(String input) throws Exception { long startNanos = System.nanoTime(); @@ -79,11 +134,14 @@ public class Solver { env.valueTable = new Object[size+STACK_SIZE]; + sortAssignments(); + model.assignmentArray = model.assignments.toArray(new Assignment[model.assignments.size()]); model.derivativeArray = model.derivatives.toArray(new Assignment[model.derivatives.size()]); model.parameterArray = model.parameters.toArray(new ParameterDeclaration[model.parameters.size()]); newValues = new Object[Math.max(model.assignments.size(),model.derivatives.size())]; + derivatives = new Object[model.derivatives.size()]; int condition = 1; int loops = 0; @@ -185,6 +243,8 @@ public class Solver { return env.getValueArray(); } + + public void step() { // TODO: do something more sensible if the solver is not ready if (!ready) return; @@ -192,24 +252,24 @@ public class Solver { Assignment[] assignments = model.assignmentArray; Assignment[] derivatives = model.derivativeArray; - // should probably be wrapped inside a method or something - env.time += env.step; - - // Solve algebraic equations - for(int i=0;i= 0) { la1tokens[jj_kind] = true; jj_kind = -1; @@ -5954,10 +5959,13 @@ public class ModelParser/*@bgen(jjtree)*/implements ModelParserTreeConstants, Mo if ((jj_la1_2[i] & (1<", "", + "", "", "", "\"operator function\"", diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java index 754f36e8..5aa460e2 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelParserTokenManager.java @@ -15,20 +15,25 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) switch (pos) { case 0: - if ((active0 & 0x3ffffffffffffff0L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active1 & 0x80000L) != 0L) + return 20; + if ((active0 & 0x377bdef7bdef7bf0L) != 0L || (active1 & 0x180000000L) != 0L) { jjmatchedKind = 90; return 2; } - if ((active1 & 0x80000L) != 0L) - return 13; if ((active1 & 0xb30010L) != 0L) - return 9; + return 13; + if ((active0 & 0x884210842108400L) != 0L) + { + jjmatchedKind = 90; + return 44; + } return -1; case 1: if ((active0 & 0x108420080400000L) != 0L) return 2; - if ((active0 & 0x3ef7bdff7fbffff0L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active0 & 0x3ef7bdff7fbffff0L) != 0L || (active1 & 0x180000000L) != 0L) { if (jjmatchedPos != 1) { @@ -41,7 +46,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) case 2: if ((active0 & 0x400000800201200L) != 0L) return 2; - if ((active0 & 0x3bfffdf77f9fedf0L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active0 & 0x3bfffdf77f9fedf0L) != 0L || (active1 & 0x180000000L) != 0L) { jjmatchedKind = 90; jjmatchedPos = 2; @@ -51,7 +56,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) case 3: if ((active0 & 0x1000084212118400L) != 0L) return 2; - if ((active0 & 0x2bfff5b56d8e69f0L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active0 & 0x2bfff5b56d8e69f0L) != 0L || (active1 & 0x180000000L) != 0L) { if (jjmatchedPos != 3) { @@ -64,7 +69,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) case 4: if ((active0 & 0x1090004290008c0L) != 0L) return 2; - if ((active0 & 0x2af6f5b1469e6130L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active0 & 0x2af6f5b1469e6130L) != 0L || (active1 & 0x180000000L) != 0L) { jjmatchedKind = 90; jjmatchedPos = 4; @@ -74,7 +79,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) case 5: if ((active0 & 0x22200011009c0000L) != 0L) return 2; - if ((active0 & 0x8d6f5a046026130L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active0 & 0x8d6f5a046026130L) != 0L || (active1 & 0x180000000L) != 0L) { jjmatchedKind = 90; jjmatchedPos = 5; @@ -84,7 +89,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) case 6: if ((active0 & 0x80d0a000000000L) != 0L) return 2; - if ((active0 & 0x856250046026130L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active0 & 0x856250046026130L) != 0L || (active1 & 0x180000000L) != 0L) { if (jjmatchedPos != 6) { @@ -104,7 +109,7 @@ private final int jjStopStringLiteralDfa_0(int pos, long active0, long active1) } return 2; } - if ((active0 & 0x802200006020020L) != 0L || (active1 & 0xc0000000L) != 0L) + if ((active0 & 0x802200006020020L) != 0L || (active1 & 0x180000000L) != 0L) return 2; return -1; case 8: @@ -185,7 +190,7 @@ private int jjMoveStringLiteralDfa0_0() jjmatchedKind = 68; return jjMoveStringLiteralDfa1_0(0x0L, 0xb30000L); case 47: - return jjStartNfaWithStates_0(0, 83, 13); + return jjStartNfaWithStates_0(0, 83, 20); case 58: jjmatchedKind = 69; return jjMoveStringLiteralDfa1_0(0x0L, 0x2000000L); @@ -227,7 +232,7 @@ private int jjMoveStringLiteralDfa0_0() case 110: return jjMoveStringLiteralDfa1_0(0x1000L, 0x0L); case 111: - return jjMoveStringLiteralDfa1_0(0x108420000L, 0xc0000000L); + return jjMoveStringLiteralDfa1_0(0x108420000L, 0x180000000L); case 112: return jjMoveStringLiteralDfa1_0(0x210842000000000L, 0x0L); case 114: @@ -315,7 +320,7 @@ private int jjMoveStringLiteralDfa1_0(long active0, long active1) case 111: return jjMoveStringLiteralDfa2_0(active0, 0x1042108000201080L, active1, 0L); case 112: - return jjMoveStringLiteralDfa2_0(active0, 0x20000L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa2_0(active0, 0x20000L, active1, 0x180000000L); case 113: return jjMoveStringLiteralDfa2_0(active0, 0x200000000000L, active1, 0L); case 114: @@ -361,7 +366,7 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long a return jjStartNfaWithStates_0(2, 35, 2); return jjMoveStringLiteralDfa3_0(active0, 0x180L, active1, 0L); case 101: - return jjMoveStringLiteralDfa3_0(active0, 0x80030020000L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa3_0(active0, 0x80030020000L, active1, 0x180000000L); case 103: return jjMoveStringLiteralDfa3_0(active0, 0x10L, active1, 0L); case 105: @@ -442,7 +447,7 @@ private int jjMoveStringLiteralDfa3_0(long old0, long active0, long old1, long a return jjStartNfaWithStates_0(3, 60, 2); return jjMoveStringLiteralDfa4_0(active0, 0x100000000L, active1, 0L); case 114: - return jjMoveStringLiteralDfa4_0(active0, 0x20000L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa4_0(active0, 0x20000L, active1, 0x180000000L); case 115: return jjMoveStringLiteralDfa4_0(active0, 0x42000400000040L, active1, 0L); case 116: @@ -470,7 +475,7 @@ private int jjMoveStringLiteralDfa4_0(long old0, long active0, long old1, long a switch(curChar) { case 97: - return jjMoveStringLiteralDfa5_0(active0, 0x2000822000L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa5_0(active0, 0x2000822000L, active1, 0x180000000L); case 99: return jjMoveStringLiteralDfa5_0(active0, 0x100L, active1, 0L); case 101: @@ -578,7 +583,7 @@ private int jjMoveStringLiteralDfa5_0(long old0, long active0, long old1, long a return jjStartNfaWithStates_0(5, 32, 2); else if ((active0 & 0x1000000000L) != 0L) return jjStartNfaWithStates_0(5, 36, 2); - return jjMoveStringLiteralDfa6_0(active0, 0x20000L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa6_0(active0, 0x20000L, active1, 0x180000000L); default : break; } @@ -610,7 +615,7 @@ private int jjMoveStringLiteralDfa6_0(long old0, long active0, long old1, long a case 110: return jjMoveStringLiteralDfa7_0(active0, 0x2000000000000L, active1, 0L); case 111: - return jjMoveStringLiteralDfa7_0(active0, 0x200004020000L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa7_0(active0, 0x200004020000L, active1, 0x180000000L); case 115: if ((active0 & 0x80000000000000L) != 0L) return jjStartNfaWithStates_0(6, 55, 2); @@ -672,7 +677,7 @@ private int jjMoveStringLiteralDfa7_0(long old0, long active0, long old1, long a jjmatchedKind = 17; jjmatchedPos = 7; } - return jjMoveStringLiteralDfa8_0(active0, 0x100L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa8_0(active0, 0x100L, active1, 0x180000000L); case 116: if ((active0 & 0x2000000000000L) != 0L) return jjStartNfaWithStates_0(7, 49, 2); @@ -694,7 +699,7 @@ private int jjMoveStringLiteralDfa8_0(long old0, long active0, long old1, long a switch(curChar) { case 32: - return jjMoveStringLiteralDfa9_0(active0, 0L, active1, 0xc0000000L); + return jjMoveStringLiteralDfa9_0(active0, 0L, active1, 0x180000000L); case 97: return jjMoveStringLiteralDfa9_0(active0, 0x40000000L, active1, 0L); case 98: @@ -746,7 +751,7 @@ private int jjMoveStringLiteralDfa9_0(long old0, long active0, long old1, long a return jjStartNfaWithStates_0(9, 50, 2); return jjMoveStringLiteralDfa10_0(active0, 0x40000000000000L, active1, 0L); case 102: - return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x40000000L); + return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x80000000L); case 108: return jjMoveStringLiteralDfa10_0(active0, 0x2000L, active1, 0L); case 110: @@ -756,7 +761,7 @@ private int jjMoveStringLiteralDfa9_0(long old0, long active0, long old1, long a case 111: return jjMoveStringLiteralDfa10_0(active0, 0x10000000000L, active1, 0L); case 114: - return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x80000000L); + return jjMoveStringLiteralDfa10_0(active0, 0L, active1, 0x100000000L); case 116: return jjMoveStringLiteralDfa10_0(active0, 0x40000000L, active1, 0L); default : @@ -780,13 +785,13 @@ private int jjMoveStringLiteralDfa10_0(long old0, long active0, long old1, long case 101: if ((active0 & 0x2000L) != 0L) return jjStartNfaWithStates_0(10, 13, 2); - return jjMoveStringLiteralDfa11_0(active0, 0x40000000L, active1, 0x80000000L); + return jjMoveStringLiteralDfa11_0(active0, 0x40000000L, active1, 0x100000000L); case 110: if ((active0 & 0x10000000000L) != 0L) return jjStartNfaWithStates_0(10, 40, 2); break; case 117: - return jjMoveStringLiteralDfa11_0(active0, 0L, active1, 0x40000000L); + return jjMoveStringLiteralDfa11_0(active0, 0L, active1, 0x80000000L); default : break; } @@ -806,13 +811,13 @@ private int jjMoveStringLiteralDfa11_0(long old0, long active0, long old1, long case 98: return jjMoveStringLiteralDfa12_0(active0, 0x40000000000000L, active1, 0L); case 99: - return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x80000000L); + return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x100000000L); case 100: if ((active0 & 0x40000000L) != 0L) return jjStartNfaWithStates_0(11, 30, 2); break; case 110: - return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x40000000L); + return jjMoveStringLiteralDfa12_0(active0, 0L, active1, 0x80000000L); default : break; } @@ -830,9 +835,9 @@ private int jjMoveStringLiteralDfa12_0(long old0, long active0, long old1, long switch(curChar) { case 99: - return jjMoveStringLiteralDfa13_0(active0, 0L, active1, 0x40000000L); - case 111: return jjMoveStringLiteralDfa13_0(active0, 0L, active1, 0x80000000L); + case 111: + return jjMoveStringLiteralDfa13_0(active0, 0L, active1, 0x100000000L); case 121: if ((active0 & 0x40000000000000L) != 0L) return jjStartNfaWithStates_0(12, 54, 2); @@ -854,9 +859,9 @@ private int jjMoveStringLiteralDfa13_0(long old0, long active0, long old1, long switch(curChar) { case 114: - return jjMoveStringLiteralDfa14_0(active1, 0x80000000L); + return jjMoveStringLiteralDfa14_0(active1, 0x100000000L); case 116: - return jjMoveStringLiteralDfa14_0(active1, 0x40000000L); + return jjMoveStringLiteralDfa14_0(active1, 0x80000000L); default : break; } @@ -874,11 +879,11 @@ private int jjMoveStringLiteralDfa14_0(long old1, long active1) switch(curChar) { case 100: - if ((active1 & 0x80000000L) != 0L) - return jjStopAtPos(14, 95); + if ((active1 & 0x100000000L) != 0L) + return jjStopAtPos(14, 96); break; case 105: - return jjMoveStringLiteralDfa15_0(active1, 0x40000000L); + return jjMoveStringLiteralDfa15_0(active1, 0x80000000L); default : break; } @@ -896,7 +901,7 @@ private int jjMoveStringLiteralDfa15_0(long old1, long active1) switch(curChar) { case 111: - return jjMoveStringLiteralDfa16_0(active1, 0x40000000L); + return jjMoveStringLiteralDfa16_0(active1, 0x80000000L); default : break; } @@ -914,8 +919,8 @@ private int jjMoveStringLiteralDfa16_0(long old1, long active1) switch(curChar) { case 110: - if ((active1 & 0x40000000L) != 0L) - return jjStopAtPos(16, 94); + if ((active1 & 0x80000000L) != 0L) + return jjStopAtPos(16, 95); break; default : break; @@ -936,7 +941,7 @@ static final long[] jjbitVec0 = { private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 31; + jjnewStateCnt = 44; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -951,22 +956,12 @@ private int jjMoveNfa_0(int startState, int curPos) { switch(jjstateSet[--i]) { - case 13: - if (curChar == 47) - { - if (kind > 3) - kind = 3; - jjCheckNAdd(20); - } - else if (curChar == 42) - jjCheckNAddStates(0, 2); - break; case 0: if ((0x3ff000000000000L & l) != 0L) { - if (kind > 92) - kind = 92; - jjCheckNAddStates(3, 7); + if (kind > 93) + kind = 93; + jjCheckNAddStates(0, 6); } else if ((0x100002600L & l) != 0L) { @@ -974,140 +969,179 @@ private int jjMoveNfa_0(int startState, int curPos) kind = 1; } else if (curChar == 47) - jjAddStates(8, 9); + jjAddStates(7, 8); else if (curChar == 46) - jjCheckNAdd(9); + jjCheckNAdd(13); else if (curChar == 34) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(9, 11); + break; + case 44: + if ((0x3ff400000000000L & l) != 0L) + { + if (kind > 90) + kind = 90; + jjCheckNAdd(2); + } + else if (curChar == 45) + { + if (kind > 92) + kind = 92; + } + break; + case 20: + if (curChar == 47) + { + if (kind > 3) + kind = 3; + jjCheckNAdd(27); + } + else if (curChar == 42) + jjCheckNAddStates(12, 14); break; case 2: if ((0x3ff400000000000L & l) == 0L) break; if (kind > 90) kind = 90; - jjstateSet[jjnewStateCnt++] = 2; + jjCheckNAdd(2); break; case 3: if (curChar == 34) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(9, 11); break; case 4: if ((0xfffffffbfffffbffL & l) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(9, 11); break; case 6: if ((0xfffffffffffffbffL & l) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(9, 11); break; case 7: if (curChar == 34 && kind > 91) kind = 91; break; - case 8: + case 9: + if (curChar == 45 && kind > 92) + kind = 92; + break; + case 12: if (curChar == 46) - jjCheckNAdd(9); + jjCheckNAdd(13); break; - case 9: + case 13: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 93) - kind = 93; - jjCheckNAddTwoStates(9, 10); + if (kind > 94) + kind = 94; + jjCheckNAddStates(15, 18); break; - case 11: + case 15: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 93) - kind = 93; - jjstateSet[jjnewStateCnt++] = 11; + if (kind > 94) + kind = 94; + jjCheckNAdd(15); break; - case 12: + case 16: + if (curChar == 45) + jjCheckNAdd(15); + break; + case 19: if (curChar == 47) - jjAddStates(8, 9); + jjAddStates(7, 8); break; - case 14: + case 21: if ((0xfffffbffffffffffL & l) != 0L) - jjCheckNAddStates(0, 2); + jjCheckNAddStates(12, 14); break; - case 15: + case 22: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 16; + jjstateSet[jjnewStateCnt++] = 23; break; - case 16: + case 23: if ((0xffff7fffffffffffL & l) != 0L) - jjCheckNAddStates(0, 2); + jjCheckNAddStates(12, 14); break; - case 17: + case 24: if (curChar == 47 && kind > 2) kind = 2; break; - case 18: + case 25: if (curChar == 42) - jjstateSet[jjnewStateCnt++] = 17; + jjstateSet[jjnewStateCnt++] = 24; break; - case 19: + case 26: if (curChar != 47) break; if (kind > 3) kind = 3; - jjCheckNAdd(20); + jjCheckNAdd(27); break; - case 20: + case 27: if ((0xfffffffffffffbffL & l) == 0L) break; if (kind > 3) kind = 3; - jjCheckNAdd(20); + jjCheckNAdd(27); break; - case 21: + case 28: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 92) - kind = 92; - jjCheckNAddStates(3, 7); + if (kind > 93) + kind = 93; + jjCheckNAddStates(0, 6); break; - case 22: + case 29: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 92) - kind = 92; - jjCheckNAdd(22); + if (kind > 93) + kind = 93; + jjCheckNAdd(29); break; - case 23: + case 30: if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(23, 24); + jjCheckNAddTwoStates(30, 31); break; - case 24: + case 31: if (curChar != 46) break; - if (kind > 93) - kind = 93; - jjCheckNAddTwoStates(25, 26); + if (kind > 94) + kind = 94; + jjCheckNAddStates(19, 22); break; - case 25: + case 32: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 93) - kind = 93; - jjCheckNAddTwoStates(25, 26); + if (kind > 94) + kind = 94; + jjCheckNAddStates(19, 22); break; - case 27: + case 34: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 93) - kind = 93; - jjstateSet[jjnewStateCnt++] = 27; + if (kind > 94) + kind = 94; + jjCheckNAdd(34); break; - case 28: + case 35: + if (curChar == 45) + jjCheckNAdd(34); + break; + case 38: if ((0x3ff000000000000L & l) != 0L) - jjCheckNAddTwoStates(28, 29); + jjCheckNAddStates(23, 26); break; - case 30: + case 40: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 93) - kind = 93; - jjstateSet[jjnewStateCnt++] = 30; + if (kind > 94) + kind = 94; + jjCheckNAdd(40); + break; + case 41: + if (curChar == 45) + jjCheckNAdd(40); break; default : break; } @@ -1121,6 +1155,23 @@ private int jjMoveNfa_0(int startState, int curPos) switch(jjstateSet[--i]) { case 0: + if ((0x7fffffe87fffffeL & l) != 0L) + { + if (kind > 90) + kind = 90; + jjCheckNAdd(2); + } + if ((0x2000000020L & l) != 0L) + { + if (kind > 92) + kind = 92; + } + if (curChar == 69) + jjCheckNAdd(9); + else if (curChar == 101) + jjCheckNAdd(9); + break; + case 44: case 2: if ((0x7fffffe87fffffeL & l) == 0L) break; @@ -1128,37 +1179,80 @@ private int jjMoveNfa_0(int startState, int curPos) kind = 90; jjCheckNAdd(2); break; + case 1: + if ((0x7fffffe87fffffeL & l) == 0L) + break; + if (kind > 90) + kind = 90; + jjCheckNAdd(2); + break; case 4: if ((0xffffffffefffffffL & l) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(9, 11); break; case 5: if (curChar == 92) jjstateSet[jjnewStateCnt++] = 6; break; case 6: - jjCheckNAddStates(10, 12); + jjCheckNAddStates(9, 11); + break; + case 8: + if ((0x2000000020L & l) != 0L && kind > 92) + kind = 92; break; case 10: - if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 11; + if (curChar == 101) + jjCheckNAdd(9); + break; + case 11: + if (curChar == 69) + jjCheckNAdd(9); break; case 14: - case 16: - jjCheckNAddStates(0, 2); + if ((0x2000000020L & l) != 0L) + jjstateSet[jjnewStateCnt++] = 15; break; - case 20: + case 17: + if (curChar == 101) + jjCheckNAdd(16); + break; + case 18: + if (curChar == 69) + jjCheckNAdd(16); + break; + case 21: + case 23: + jjCheckNAddStates(12, 14); + break; + case 27: if (kind > 3) kind = 3; - jjstateSet[jjnewStateCnt++] = 20; + jjstateSet[jjnewStateCnt++] = 27; break; - case 26: + case 33: if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 27; + jjstateSet[jjnewStateCnt++] = 34; break; - case 29: + case 36: + if (curChar == 101) + jjCheckNAdd(35); + break; + case 37: + if (curChar == 69) + jjCheckNAdd(35); + break; + case 39: if ((0x2000000020L & l) != 0L) - jjstateSet[jjnewStateCnt++] = 30; + jjstateSet[jjnewStateCnt++] = 40; + break; + case 42: + if (curChar == 101) + jjCheckNAdd(41); + break; + case 43: + if (curChar == 69) + jjCheckNAdd(41); break; default : break; } @@ -1175,19 +1269,19 @@ private int jjMoveNfa_0(int startState, int curPos) case 4: case 6: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddStates(10, 12); + jjCheckNAddStates(9, 11); break; - case 14: - case 16: + case 21: + case 23: if ((jjbitVec0[i2] & l2) != 0L) - jjCheckNAddStates(0, 2); + jjCheckNAddStates(12, 14); break; - case 20: + case 27: if ((jjbitVec0[i2] & l2) == 0L) break; if (kind > 3) kind = 3; - jjstateSet[jjnewStateCnt++] = 20; + jjstateSet[jjnewStateCnt++] = 27; break; default : break; } @@ -1200,14 +1294,15 @@ private int jjMoveNfa_0(int startState, int curPos) kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 31 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 44 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { - 14, 15, 18, 22, 23, 24, 28, 29, 13, 19, 4, 5, 7, + 29, 30, 31, 38, 39, 42, 43, 20, 26, 4, 5, 7, 21, 22, 25, 13, + 14, 17, 18, 32, 33, 36, 37, 38, 39, 42, 43, }; /** Token literal values. */ @@ -1232,7 +1327,7 @@ public static final String[] jjstrLiteralImages = { "\145\170\164\145\162\156\141\154", "\154\157\157\160", "\162\145\143\157\162\144", "\50", "\51", "\173", "\175", "\133", "\135", "\56", "\72", "\73", "\54", "\74", "\74\75", "\76", "\76\75", "\75\75", "\74\76", "\53", "\55", "\56\53", "\56\55", "\52", "\57", "\56\52", "\56\57", -"\136", "\56\136", "\75", "\72\75", null, null, null, null, +"\136", "\56\136", "\75", "\72\75", null, null, null, null, null, "\157\160\145\162\141\164\157\162\40\146\165\156\143\164\151\157\156", "\157\160\145\162\141\164\157\162\40\162\145\143\157\162\144", }; /** Lexer state names. */ @@ -1240,14 +1335,14 @@ public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { - 0xfffffffffffffff1L, 0xffffffffL, + 0xfffffffffffffff1L, 0x1ffffffffL, }; static final long[] jjtoSkip = { 0xeL, 0x0L, }; protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[31]; -private final int[] jjstateSet = new int[62]; +private final int[] jjrounds = new int[44]; +private final int[] jjstateSet = new int[88]; private final StringBuilder jjimage = new StringBuilder(); private StringBuilder image = jjimage; private int jjimageLen; @@ -1278,7 +1373,7 @@ private void ReInitRounds() { int i; jjround = 0x80000001; - for (i = 31; i-- > 0;) + for (i = 44; i-- > 0;) jjrounds[i] = 0x80000000; } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj index a6dceb85..2ba477f3 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jj @@ -78,11 +78,12 @@ TOKEN: | | { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } +| | | "." ()? (["e","E"] )? - | "." (["e","E"] )? - | ["e","E"] + ( "." ()? ( )? + | "." ( )? + | ) > } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt index 422e38fd..0296fd88 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/parser/ModelicaParser.jjt @@ -74,11 +74,12 @@ TOKEN: | | { matchedToken.image = matchedToken.image.substring(1,matchedToken.image.length()-1); } +| | | "." ()? (["e","E"] )? - | "." (["e","E"] )? - | ["e","E"] + ( "." ()? ( )? + | "." ( )? + | ) > } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AdjustableTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AdjustableTab.java index da4bae8c..7fffd394 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AdjustableTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/AdjustableTab.java @@ -30,6 +30,7 @@ public abstract class AdjustableTab extends LabelPropertyTabContributor { private Composite spp; private ControlListener controlListener; private static final int WIDE_SCREEN_WIDTH = 1100; + protected Composite composite; @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) { @@ -47,7 +48,7 @@ public abstract class AdjustableTab extends LabelPropertyTabContributor { @Override public void controlResized(ControlEvent e) { - createLayout(); + createLayout(); } }); @@ -70,6 +71,9 @@ public abstract class AdjustableTab extends LabelPropertyTabContributor { * Create layout for controls. */ protected void createLayout() { + if (composite == null || composite.isDisposed()) + return; + Point size = spp.getSize(); if (size.x > size.y) { createControlLayoutHorizontal((size.x > WIDE_SCREEN_WIDTH)); @@ -98,10 +102,10 @@ public abstract class AdjustableTab extends LabelPropertyTabContributor { */ protected abstract void createControlLayoutHorizontal(boolean wideScreen); - @Override - public void dispose() { - if(controlListener != null && spp != null) - spp.removeControlListener(controlListener); - } +// @Override +// public void dispose() { +// if(controlListener != null && spp != null) +// spp.removeControlListener(controlListener); +// } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/LabelPropertyTabContributor.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/LabelPropertyTabContributor.java index 045b4d31..8c0441c4 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/LabelPropertyTabContributor.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/LabelPropertyTabContributor.java @@ -12,59 +12,33 @@ package org.simantics.jfreechart.chart.properties; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IWorkbenchSite; -import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl; -import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.procedure.AsyncListener; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; import org.simantics.selectionview.PropertyTabContributorImpl; -import org.simantics.ui.SimanticsUI; -import org.simantics.utils.datastructures.Callback; import org.simantics.utils.ui.AdaptionUtils; public abstract class LabelPropertyTabContributor extends PropertyTabContributorImpl { - private boolean isDisposed = false; - - - public void createControl(Composite parent, final IWorkbenchSite site, final ISessionContext context, final WidgetSupportImpl support) { - super.createControl(parent, site, context, support); - - // Add dispose listener to make sure name listening receives the correct isDisposed -value - parent.addDisposeListener(new DisposeListener() { - - @Override - public void widgetDisposed(DisposeEvent e) { - LabelPropertyTabContributor.this.dispose(); - } - }); - } - @Override - public void updatePartName(ISelection forSelection, final Callback updateCallback) { - final Variable variable = AdaptionUtils.adaptToSingle(forSelection, Variable.class); - final Resource resource = AdaptionUtils.adaptToSingle(forSelection, Resource.class); - if(resource == null && variable == null) { - updateCallback.run("Selection properties"); - return; - } + public Read getPartNameReadRequest(final ISelection forSelection) { - SimanticsUI.getSession().asyncRequest(new Read() { + return new Read() { @Override public String perform(ReadGraph graph) throws DatabaseException { Layer0 l0 = Layer0.getInstance(graph); ModelingResources mr = ModelingResources.getInstance(graph); + + final Variable variable = AdaptionUtils.adaptToSingle(forSelection, Variable.class); + final Resource resource = AdaptionUtils.adaptToSingle(forSelection, Resource.class); + if(resource == null && variable == null) { + return "Selection"; + } Resource r; if(variable != null) { @@ -84,27 +58,9 @@ public abstract class LabelPropertyTabContributor extends PropertyTabContributor return label; return "No name for selection"; } - }, new AsyncListener() { - - @Override - public void execute(AsyncReadGraph graph, String result) { - updateCallback.run(result); - } - - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - - } - - @Override - public boolean isDisposed() { - return isDisposed; - } - }); + + }; + } - @Override - protected void dispose() { - this.isDisposed = true; - } } diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarAxisTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarAxisTab.java index d8228492..38f7d21e 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarAxisTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarAxisTab.java @@ -67,7 +67,6 @@ public class BarAxisTab extends AdjustableTab implements Widget { private WidgetSupportImpl rangeAxisSupport = new WidgetSupportImpl(); private TrackedText rangelabel, rangemin, rangemax; private ScrolledComposite sc; - private Composite composite; private Group domainGroup; private Label labelLabel; private AxisHidePropertyComposite axisHide; diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarGeneralPropertiesTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarGeneralPropertiesTab.java index 9d669b6c..fa60a3e5 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarGeneralPropertiesTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarGeneralPropertiesTab.java @@ -64,7 +64,6 @@ import org.simantics.sysdyn.JFreeChartResource; public class BarGeneralPropertiesTab extends AdjustableTab { private ScrolledComposite sc; - private Composite composite; private Button hgrid, htitle, hlegend; private TrackedText name, title, time; private TrackedCombo type; diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab.java index 51eefa75..5a9c55a2 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/bar/BarSeriesTab.java @@ -61,7 +61,6 @@ public class BarSeriesTab extends AdjustableTab implements Widget { private Resource chartResource; private BarSeriesPropertyComposite spc; private int options; - private Composite composite; private Composite buttonComposite; public BarSeriesTab(int options) { diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieGeneralPropertiesTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieGeneralPropertiesTab.java index e32a1c7f..3e2b2d2d 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieGeneralPropertiesTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieGeneralPropertiesTab.java @@ -51,7 +51,6 @@ import org.simantics.sysdyn.JFreeChartResource; public class PieGeneralPropertiesTab extends AdjustableTab { private ScrolledComposite sc; - private Composite composite; private Button htitle, hlegend, hlabels; private TrackedText name, title, time; diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab.java index ad0ca645..d5cf346a 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/pie/PieSeriesTab.java @@ -60,7 +60,6 @@ public class PieSeriesTab extends AdjustableTab implements Widget { private Button add, remove; private Resource chartResource; private int options; - private Composite composite; private Composite buttonComposite; public PieSeriesTab(int options) { diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineAxisAndVariablesTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineAxisAndVariablesTab.java index 92d4f9e0..98d7107e 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineAxisAndVariablesTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineAxisAndVariablesTab.java @@ -63,7 +63,6 @@ public class XYLineAxisAndVariablesTab extends AdjustableTab { private ScrolledComposite propertyContainer; private Button addAxis, addVariable, remove; private WidgetSupportImpl additionalSupport; - private Composite composite; private Composite buttonComposite; public XYLineAxisAndVariablesTab() { diff --git a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineGeneralPropertiesTab.java b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineGeneralPropertiesTab.java index 2ab8ae98..495a36e1 100644 --- a/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineGeneralPropertiesTab.java +++ b/org.simantics.jfreechart/src/org/simantics/jfreechart/chart/properties/xyline/XYLineGeneralPropertiesTab.java @@ -72,7 +72,6 @@ import org.simantics.utils.ui.AdaptionUtils; public class XYLineGeneralPropertiesTab extends AdjustableTab implements Widget { private ScrolledComposite sc; - private Composite composite; private TrackedText name, title, xlabel, xvariable, xmin, xmax; private TrackedCombo type; private Button hgrid, htitle, hlegend; diff --git a/org.simantics.sysdyn.feature/rootfiles/sampleModels/Tourists Environments And Hotel Facilities.sysdyn b/org.simantics.sysdyn.feature/rootfiles/sampleModels/Tourists Environments And Hotel Facilities.sysdyn index 7af5e567..def1fc4c 100644 Binary files a/org.simantics.sysdyn.feature/rootfiles/sampleModels/Tourists Environments And Hotel Facilities.sysdyn and b/org.simantics.sysdyn.feature/rootfiles/sampleModels/Tourists Environments And Hotel Facilities.sysdyn differ diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 37bbc783..7b31d5bc 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Migration.pgraph b/org.simantics.sysdyn.ontology/graph/Migration.pgraph index c52fecbc..cf2c2db9 100644 --- a/org.simantics.sysdyn.ontology/graph/Migration.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Migration.pgraph @@ -34,6 +34,7 @@ FROM16TO17 = MIGRATION."from1.6to1.7" : L0.MigrationSequence FROM16TO17.Spreadsheets FROM16TO17.SysdynChanges FROM16TO17.OrderedSetsToLists + FROM16TO17.Custom : L0.MigrationStep FROM16TO17.Ontologies : L0.NamespaceMigrationStep @L0.list @@ -74,7 +75,50 @@ FROM16TO17.Ontologies : L0.NamespaceMigrationStep _ @move"http://www.simantics.org/User-" "1.0" "1.1" _ - @move"http://www.simantics.org/Documentation-" "1.0" "1.1" + @move"http://" "www.simantics.org/Documentation-1.1/Components" "www.semantum.fi/Simupedia-1.0/Components" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Symbols" "www.semantum.fi/Simupedia-1.0/Symbols" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Properties" "www.semantum.fi/Simupedia-1.0/Properties" + _ + @move"http://" "www.simantics.org/Documentation-1.1/DiagramRelations" "www.simantics.org/Documentation-1.2/DiagramRelations" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Relations" "www.simantics.org/Documentation-1.2/Relations" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Terminals" "www.simantics.org/Documentation-1.2/Terminals" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Role" "www.semantum.fi/Simupedia-1.0/Role" + _ + @move"http://" "www.simantics.org/Documentation-1.1/RelationTypeConstraint" "www.simantics.org/Documentation-1.2/RelationTypeConstraint" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Component" "www.semantum.fi/Simupedia-1.0/Components/Component" + _ + @move"http://" "www.simantics.org/Documentation-1.1/DocumentComponent" "www.simantics.org/Documentation-1.2/DocumentComponent" + _ + @move"http://" "www.simantics.org/Documentation-1.1/roleList" "www.semantum.fi/Simupedia-1.0/roleList" + _ + @move"http://" "www.simantics.org/Documentation-1.1/CommandConnectionType" "www.simantics.org/Documentation-1.2/CommandConnectionType" + _ + @move"http://" "www.simantics.org/Documentation-1.1/DataDefinitionConnectionType" "www.simantics.org/Documentation-1.2/DataDefinitionConnectionType" + _ + @move"http://" "www.simantics.org/Documentation-1.1/DataConnectionType" "www.simantics.org/Documentation-1.2/DataConnectionType" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Functions" "www.semantum.fi/Simupedia-1.0/Functions" + _ + @move"http://" "www.simantics.org/Documentation-1.1/DocumentDiagram" "www.simantics.org/Documentation-1.2/DocumentDiagram" + _ + @move"http://" "www.simantics.org/Documentation-1.1/ConnectionType" "www.simantics.org/Documentation-1.2/ConnectionType" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Document/IsConnectedToChild" "www.simantics.org/Documentation-1.2/Document/IsConnectedToChild" + _ + @move"http://" "www.simantics.org/Documentation-1.1/Document" "www.semantum.fi/Simupedia-1.0/Document" + _ + @move"http://" "www.simantics.org/Documentation-1.1" "www.simantics.org/Documentation-1.2" + _ + @move"http://" "www.simantics.org/DocumentWorkbench-1.0" "www.semantum.fi/SimupediaWorkbench-1.0" + + + _ @move"http://www.simantics.org/Document-" "1.1" "1.2" _ diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 1ad68f5d..e5f34635 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -147,6 +147,12 @@ SYSDYN.Variable -- SYSDYN.Variable.equation - - - - + + @@ -787,7 +785,7 @@ @@ -972,10 +970,10 @@ @@ -989,10 +987,10 @@ @@ -1006,10 +1004,10 @@ @@ -2805,6 +2803,14 @@ type="radio" value="flow"> + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java index 90079b11..805f6e18 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java @@ -57,7 +57,7 @@ public class Model extends ViewpointContributor { result.add(new ModulesNode(model.data)); result.add(new FunctionsFolder(model.data)); result.add(new ChartsFolder(model.data)); -// result.add(new SCLModulesFolder(model.data)); + result.add(new SCLModulesFolder(model.data)); return result; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java index 0b83ef3f..473ee7a1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/LoopFactory.java @@ -282,8 +282,10 @@ public class LoopFactory extends SysdynElementFactory { Alignment alignment = Alignment.CENTER; name.setTransform(at2); - if(alignment != null) + if(alignment != null) { name.setHorizontalAlignment((byte) alignment.ordinal()); + name.setVerticalAlignment((byte) alignment.ordinal()); + } } } } @@ -295,7 +297,7 @@ public class LoopFactory extends SysdynElementFactory { private static double getYCoordShift(IElement e) { //String location = e.getHint(SysdynElementHints.KEY_LOCATION); - return 10.7; + return 9.7; } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java index a94c8a14..bd1c1bfd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayDependencyTab.java @@ -33,7 +33,7 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.management.ISessionContext; -import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor; +import org.simantics.jfreechart.chart.properties.AdjustableTab; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.elements.connections.DependencyEdgeClass; import org.simantics.sysdyn.ui.elements.connections.DependencyNode; @@ -47,95 +47,18 @@ import org.simantics.utils.datastructures.Triple; * @author Tuomas Miettinen * */ -public class ArrayDependencyTab extends LabelPropertyTabContributor { +public class ArrayDependencyTab extends AdjustableTab { Button none, plus, minus, other, inside, outside; TrackedText polarityText, polarityLocationText; private DelayMarkWidget delayMark; private ArrowHeadWidget arrowhead; private Scale lineThicknessScale; - - @Override - public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { - Composite composite = new Composite(body, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); - - /* Add a dummy button at the begin to suck in the nonsense selection events that - * the first radio button in the group of ALL the radio buttons receives when no - * radio is selected and then one is selected in other group than where the first - * radio button lies. - */ - Group hiddenDefaultbuttonGroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().exclude(true).applyTo(hiddenDefaultbuttonGroup); - GridLayoutFactory.fillDefaults().applyTo(hiddenDefaultbuttonGroup); - new Button(hiddenDefaultbuttonGroup, support, SWT.RADIO); - - Group polarityGroup = new Group(composite, SWT.NONE); - polarityGroup.setText("Polarity"); - GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityGroup); - GridLayoutFactory.fillDefaults().numColumns(5).applyTo(polarityGroup); - - none = new Button(polarityGroup, support, SWT.RADIO); - none.setText("None"); - none.setSelectionFactory(new PolarityRadioSelectionFactory("")); - none.addSelectionListener(new PolaritySelectionListener(context, "")); - - plus = new Button(polarityGroup, support, SWT.RADIO); - plus.setText("+"); - plus.setSelectionFactory(new PolarityRadioSelectionFactory("+")); - plus.addSelectionListener(new PolaritySelectionListener(context, "+")); - - minus = new Button(polarityGroup, support, SWT.RADIO); - minus.setText("-"); - minus.setSelectionFactory(new PolarityRadioSelectionFactory("-")); - minus.addSelectionListener(new PolaritySelectionListener(context, "-")); - - other = new Button(polarityGroup, support, SWT.RADIO); - other.setText("other"); - other.setSelectionFactory(new OtherPolaritySelectionFactory(new String[] {null, "+", "-", ""})); - - polarityText = new TrackedText(polarityGroup, support, SWT.BORDER); - polarityText.setTextFactory(new OtherPolarityStringPropertyFactory()); - polarityText.addModifyListener(new OtherPolarityStringPropertyModifier()); - GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityText.getWidget()); - - Group locationGroup = new Group(composite, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(locationGroup); - GridLayoutFactory.fillDefaults().applyTo(locationGroup); - locationGroup.setText("Location"); - - inside = new Button(locationGroup, support, SWT.RADIO); - inside.setText("Inside"); - inside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.INSIDE)); - inside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.INSIDE)); - - outside = new Button(locationGroup, support, SWT.RADIO); - outside.setText("Outside"); - outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE)); - outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE)); - - Composite misc = new Composite(composite, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(misc); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(misc); - - arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL); - GridDataFactory.fillDefaults().applyTo(arrowhead.getWidget()); - delayMark = new DelayMarkWidget(misc, support, SWT.NULL); - GridDataFactory.fillDefaults().applyTo(delayMark.getWidget()); - - Group lineThicknessGroup = new Group(misc, SWT.NONE); - GridDataFactory.fillDefaults().applyTo(lineThicknessGroup); - GridLayoutFactory.fillDefaults().applyTo(lineThicknessGroup); - lineThicknessGroup.setText("Line thickness:"); - lineThicknessScale = new Scale(lineThicknessGroup, support, SWT.HORIZONTAL); - lineThicknessScale.getWidget().setMinimum(1); - lineThicknessScale.getWidget().setMaximum(15); - lineThicknessScale.getWidget().setPageIncrement(1); - lineThicknessScale.getWidget().setIncrement(1); - lineThicknessScale.setSelectionFactory(new LineThicknessRadioSelectionFactory()); - lineThicknessScale.addSelectionListener(new LineThicknessSelectionListener(context, lineThicknessScale)); - } + private Group hiddenDefaultbuttonGroup; + private Group polarityGroup; + private Group locationGroup; + private Composite misc; + private Group lineThicknessGroup; class LineThicknessSelectionListener extends SelectionListenerImpl> { Scale scale; @@ -345,4 +268,124 @@ public class ArrayDependencyTab extends LabelPropertyTabContributor { } } + @Override + protected void createAndAddControls(Composite body, IWorkbenchSite site, + ISessionContext context, WidgetSupport support) { + composite = new Composite(body, SWT.NONE); + + /* Add a dummy button at the begin to suck in the nonsense selection events that + * the first radio button in the group of ALL the radio buttons receives when no + * radio is selected and then one is selected in other group than where the first + * radio button lies. + */ + hiddenDefaultbuttonGroup = new Group(composite, SWT.NONE); + new Button(hiddenDefaultbuttonGroup, support, SWT.RADIO); + + polarityGroup = new Group(composite, SWT.NONE); + polarityGroup.setText("Polarity"); + + none = new Button(polarityGroup, support, SWT.RADIO); + none.setText("None"); + none.setSelectionFactory(new PolarityRadioSelectionFactory("")); + none.addSelectionListener(new PolaritySelectionListener(context, "")); + + plus = new Button(polarityGroup, support, SWT.RADIO); + plus.setText("+"); + plus.setSelectionFactory(new PolarityRadioSelectionFactory("+")); + plus.addSelectionListener(new PolaritySelectionListener(context, "+")); + + minus = new Button(polarityGroup, support, SWT.RADIO); + minus.setText("-"); + minus.setSelectionFactory(new PolarityRadioSelectionFactory("-")); + minus.addSelectionListener(new PolaritySelectionListener(context, "-")); + + other = new Button(polarityGroup, support, SWT.RADIO); + other.setText("other"); + other.setSelectionFactory(new OtherPolaritySelectionFactory(new String[] {null, "+", "-", ""})); + + polarityText = new TrackedText(polarityGroup, support, SWT.BORDER); + polarityText.setTextFactory(new OtherPolarityStringPropertyFactory()); + polarityText.addModifyListener(new OtherPolarityStringPropertyModifier()); + + locationGroup = new Group(composite, SWT.NONE); + locationGroup.setText("Location"); + + inside = new Button(locationGroup, support, SWT.RADIO); + inside.setText("Inside"); + inside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.INSIDE)); + inside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.INSIDE)); + + outside = new Button(locationGroup, support, SWT.RADIO); + outside.setText("Outside"); + outside.setSelectionFactory(new PolarityLocationRadioSelectionFactory(DependencyNode.OUTSIDE)); + outside.addSelectionListener(new PolarityLocationSelectionListener(context, DependencyNode.OUTSIDE)); + + misc = new Composite(composite, SWT.NONE); + + arrowhead = new ArrowHeadWidget(misc, support, SWT.NULL); + delayMark = new DelayMarkWidget(misc, support, SWT.NULL); + + lineThicknessGroup = new Group(misc, SWT.NONE); + lineThicknessGroup.setText("Line thickness:"); + lineThicknessScale = new Scale(lineThicknessGroup, support, SWT.HORIZONTAL); + lineThicknessScale.getWidget().setMinimum(1); + lineThicknessScale.getWidget().setMaximum(15); + lineThicknessScale.getWidget().setPageIncrement(1); + lineThicknessScale.getWidget().setIncrement(1); + lineThicknessScale.setSelectionFactory(new LineThicknessRadioSelectionFactory()); + lineThicknessScale.addSelectionListener(new LineThicknessSelectionListener(context, lineThicknessScale)); + } + + @Override + protected void createControlLayoutVertical() { + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(1).applyTo(composite); + + GridDataFactory.fillDefaults().exclude(true).applyTo(hiddenDefaultbuttonGroup); + GridLayoutFactory.fillDefaults().applyTo(hiddenDefaultbuttonGroup); + + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityGroup); + GridLayoutFactory.fillDefaults().numColumns(5).applyTo(polarityGroup); + + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityText.getWidget()); + + GridDataFactory.fillDefaults().applyTo(locationGroup); + GridLayoutFactory.fillDefaults().applyTo(locationGroup); + + GridDataFactory.fillDefaults().grab(true, true).applyTo(misc); + GridLayoutFactory.fillDefaults().numColumns(2).applyTo(misc); + + GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(arrowhead.getWidget()); + GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(delayMark.getWidget()); + + GridDataFactory.fillDefaults().span(2, 1).applyTo(lineThicknessGroup); + GridLayoutFactory.fillDefaults().applyTo(lineThicknessGroup); + } + + @Override + protected void createControlLayoutHorizontal(boolean wideScreen) { + GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); + GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); + + GridDataFactory.fillDefaults().exclude(true).applyTo(hiddenDefaultbuttonGroup); + GridLayoutFactory.fillDefaults().applyTo(hiddenDefaultbuttonGroup); + + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityGroup); + GridLayoutFactory.fillDefaults().numColumns(5).applyTo(polarityGroup); + + GridDataFactory.fillDefaults().grab(true, false).applyTo(polarityText.getWidget()); + + GridDataFactory.fillDefaults().applyTo(locationGroup); + GridLayoutFactory.fillDefaults().applyTo(locationGroup); + + GridDataFactory.fillDefaults().grab(true, true).applyTo(misc); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(misc); + + GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(arrowhead.getWidget()); + GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).applyTo(delayMark.getWidget()); + + GridDataFactory.fillDefaults().span(1, 1).applyTo(lineThicknessGroup); + GridLayoutFactory.fillDefaults().applyTo(lineThicknessGroup); + } + } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java index 3d7183e6..0b6c00c1 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/CommentTab.java @@ -25,7 +25,6 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport; import org.simantics.db.management.ISessionContext; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.jfreechart.chart.properties.LabelPropertyTabContributor; -import org.simantics.utils.datastructures.Callback; /** * Tab for editing diagram comments @@ -35,10 +34,10 @@ import org.simantics.utils.datastructures.Callback; */ public class CommentTab extends LabelPropertyTabContributor { - @Override - public void updatePartName(ISelection forSelection, final Callback updateCallback) { - updateCallback.run("Comment"); - } + @Override + public String getPartName(ISelection forSelection) { + return "Comment"; + } @Override public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java index afee67e9..33ad0ea6 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java @@ -60,7 +60,6 @@ import org.simantics.sysdyn.ui.properties.widgets.factories.ModelNameInputValida public class ConfigurationTab extends AdjustableTab { private ScrolledComposite sc; - private Composite composite; private Label nameLabel, startTimeLabel, stopTimeLabel, stepLengthLabel, outputIntervalLabel, methodLabel, toleranceLabel, variableFilterLabel; private TrackedText name, startTime, stopTime, stepLength, outputInterval, tolerance, variableFilter; @@ -279,7 +278,9 @@ public class ConfigurationTab extends AdjustableTab { "To include variables Auxiliary1, Auxiliary2 and Auxiliary3: \n" + "Auxiliary[1-3]\n" + "or\n" + - "Auxiliary1|Auxiliary2|Auxiliary3"); + "Auxiliary1|Auxiliary2|Auxiliary3\n" + + "NOTE: whitespace must be replaced with an underscore ('_') character" + + "e.g. 'Growth Rate' -> 'Growth_Rate'"); variableFilter = new TrackedText(composite, support, SWT.BORDER); variableFilter.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SysdynModel_variableFilter, "")); @@ -288,7 +289,9 @@ public class ConfigurationTab extends AdjustableTab { "To include variables Auxiliary1, Auxiliary2 and Auxiliary3: \n" + "Auxiliary[1-3]\n" + "or\n" + - "Auxiliary1|Auxiliary2|Auxiliary3"); + "Auxiliary1|Auxiliary2|Auxiliary3\n" + + "NOTE: whitespace must be replaced with an underscore ('_') character" + + "e.g. 'Growth Rate' -> 'Growth_Rate'"); sc.setExpandHorizontal(true); sc.setExpandVertical(true); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java index 6cb813fa..1acc0212 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/DependencyTab.java @@ -55,7 +55,6 @@ public class DependencyTab extends AdjustableTab { Scale lineThicknessScale; private DelayMarkWidget delayMark; private ArrowHeadWidget arrowhead; - private Composite composite; private Group polarityGroup; private Group locationGroup; private Composite misc; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java index c022808d..633cdfa3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -98,7 +98,6 @@ public class EquationTab extends AdjustableTab implements Widget { private WidgetSupportImpl support; private ExpressionComposite expressionComposite; private final WidgetSupportImpl expressionSupport = new WidgetSupportImpl(); - private Composite composite; private Composite nameComposite; private Composite TypeAndUnit; private Label typeLabel; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java index de7994be..c20ede21 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/FunctionTab.java @@ -33,7 +33,6 @@ import org.simantics.sysdyn.ui.properties.widgets.functions.FunctionCodeWidget; public class FunctionTab extends AdjustableTab { ExpressionField modelicaCode; - private Composite composite; private TrackedText nameText; private Group modelicaGroup; private Label startLabel; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java index cc4bd43d..ee43cbb4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/LoopTab.java @@ -60,7 +60,7 @@ public class LoopTab extends AdjustableTab { private TrackedCombo loopItemsDropdown; Button auto, balancing, reinforcing, other, inside, outside; TrackedText loopComment, polarityLocationText; - Composite composite, loopItems; + Composite loopItems; Group commentGroup, rotationGroup; protected Resource resource; public static final String AUTO = "$$AUTO$$"; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 1fb36162..49407d6b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -32,6 +32,7 @@ import org.simantics.db.layer0.request.PossibleActiveVariableFromVariable; import org.simantics.db.layer0.variable.Variable; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.jfreechart.ChartSelectionTabContributor; +import org.simantics.jfreechart.chart.properties.ChartTab; import org.simantics.jfreechart.chart.properties.xyline.XYLineGeneralPropertiesTab; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; @@ -527,6 +528,11 @@ public class ResourceSelectionProcessor implements SelectionProcessor> contentListener; - private RemoveFocusBeforeExperimentComposite composite; private Composite labelComposite; private Label labelName; private Label labelNumber; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java index c5b18516..2e4fc801 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java @@ -86,7 +86,6 @@ public class VariableInformationTab extends AdjustableTab implements Widget { } private Read> fontAndColorRead; - private Composite composite; private Group informationGroup; private TrackedText information; private Group rangeGroup; diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/CustomFontDialog.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/CustomFontDialog.java index 51bcf324..8bf97ce6 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/CustomFontDialog.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/CustomFontDialog.java @@ -19,6 +19,8 @@ import java.util.Map; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.resource.FontDescriptor; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; @@ -38,6 +40,8 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; +import org.simantics.sysdyn.ui.Activator; +import org.simantics.sysdyn.ui.preferences.SysdynDiagramPreferences; import org.simantics.utils.ui.gfx.ColorImageDescriptor; /** @@ -345,6 +349,20 @@ public class CustomFontDialog extends Dialog { int code; RGB color; Display display = Display.getCurrent(); + + //IWorkbenchPage iwp = SysdynWorkbenchUtils.getActivePageOfEditor(); + //final ICanvasContext context = (ICanvasContext)iwp.getActiveEditor().getAdapter(ICanvasContext.class); + + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + color = PreferenceConverter.getColor(store, SysdynDiagramPreferences.ARROW_COLOR); + image = resourceManager.createImage(new ColorImageDescriptor(color.red, color.green, color.blue, 25, 15, false)); + + ti = new TableItem(table, SWT.NONE); + ti.setImage(0, image); + ti.setText(1, "Default Arrow"); + ti.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); + ti.setData(color); + for(String text : systemColors.keySet()) { code = systemColors.get(text); color = display.getSystemColor(code).getRGB(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java index 2f957146..ab53b0f8 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityChartAxisAndVariablesTab.java @@ -47,7 +47,6 @@ public class SensitivityChartAxisAndVariablesTab extends AdjustableTab { private GraphExplorerComposite explorer; private ScrolledComposite propertyContainer; private WidgetSupportImpl additionalSupport; - private Composite composite; public SensitivityChartAxisAndVariablesTab() { additionalSupport = new WidgetSupportImpl(); @@ -111,8 +110,6 @@ public class SensitivityChartAxisAndVariablesTab extends AdjustableTab { protected void createAndAddControls(Composite body, IWorkbenchSite site, final ISessionContext context, WidgetSupport support) { composite = new Composite(body, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); - GridLayoutFactory.fillDefaults().numColumns(2).margins(3, 3).applyTo(composite); // (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys( @@ -128,12 +125,9 @@ public class SensitivityChartAxisAndVariablesTab extends AdjustableTab { updateSelection(context); } }); - GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer); // Scrolled composite for displaying properties of a selection in explorer propertyContainer = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); - GridDataFactory.fillDefaults().span(1, 2).grab(true, true).applyTo(propertyContainer); - GridLayoutFactory.fillDefaults().applyTo(propertyContainer); propertyContainer.setExpandHorizontal(true); propertyContainer.setExpandVertical(true); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java index d6f024e1..73663c77 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ArrayVariableUtils.java @@ -1,3 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2010, 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 - initial API and implementation + *******************************************************************************/ package org.simantics.sysdyn.ui.utils; import java.util.ArrayList; @@ -59,74 +70,91 @@ public class ArrayVariableUtils { result.put(elements.length > 0 ? elements.length - 1 : 0, error); } - for(int i = 0; i < elements.length && i < enumerations.size(); i++) { - if(elements[i].trim().equals(":")) - continue; - if(elements[i].indexOf(":") != elements[i].lastIndexOf(":")) { + String trimmedElement = elements[i].trim(); + if (trimmedElement.charAt(0) == '{' && trimmedElement.charAt(trimmedElement.length() - 1) == '}') { + // Something like "{a, b, c}" + String[] rangeComponents = trimmedElement.substring(1, trimmedElement.length() - 1).split(","); + // Single range component, equals to the enumeration at that index + if(rangeComponents.length == 1 && rangeComponents[0].trim().equals(enumerations.get(i).getName())) + continue; + // more than one range component, they all equal to individual indexes in the enumeration + result.putAll(areRangeComponentsValid(rangeComponents, enumerations, i)); + } else if(trimmedElement.equals(":")) { + continue; // Just a ":" + } else if(elements[i].indexOf(":") != elements[i].lastIndexOf(":")) { + // Something like "a : b : c" error = new SyntaxError(); error.setMessage( "Too many ':' elements"); error.setType(ExpressionField.SYNTAX_ERROR); result.put(i, error); continue; + } else { + // Something like "a : c" OR "a" + String[] rangeComponents = elements[i].split(":"); + if(rangeComponents.length > 2){ + error = new SyntaxError(); + error.setMessage( "Too many ':' elements"); + error.setType(ExpressionField.SYNTAX_ERROR); + result.put(i, error); + continue; + } + // Single range component, equals to the enumeration at that index + if(rangeComponents.length == 1 && rangeComponents[0].trim().equals(enumerations.get(i).getName())) + continue; + // one or two range components, they all equal to individual indexes in the enumeration + result.putAll(areRangeComponentsValid(rangeComponents, enumerations, i)); } + } + if(result.isEmpty()) + return null; + else + return result; + } - String[] rangeComponents = elements[i].split(":"); - if(rangeComponents.length > 2){ - error = new SyntaxError(); - error.setMessage( "Too many ':' elements"); - error.setType(ExpressionField.SYNTAX_ERROR); - result.put(i, error); - continue; + private static Map areRangeComponentsValid(String[] rangeComponents, ArrayList enumerations, int i) { + SyntaxError error; + Map result = new HashMap(); + for(String r : rangeComponents) { + r = r.trim(); + boolean componentIsValid = false; + Enumeration enumeration = enumerations.get(i); + for(EnumerationIndex ei : enumeration.getEnumerationIndexes()) { + if(ei.getName().equals(r)) { + componentIsValid = true; + break; + } } - // Single range component, equals to the enumeration at that index - if(rangeComponents.length == 1 && rangeComponents[0].trim().equals(enumerations.get(i).getName())) - continue; - // one or two range components, they all equal to individual indexes in the enumeration - for(String r : rangeComponents) { - r = r.trim(); - boolean componentIsValid = false; - Enumeration enumeration = enumerations.get(i); - for(EnumerationIndex ei : enumeration.getEnumerationIndexes()) { - if(ei.getName().equals(r)) { + if(!componentIsValid && r.length() > 0) { + // Check if the range is an integer that is between 0 and enumeration indexes size + try { + int index = Integer.parseInt(r); + int min = 1; + int max = enumeration.getEnumerationIndexes().size(); + if(index >= min && index <= max || enumeration.isReplaceable()) { componentIsValid = true; - break; - } - } - if(!componentIsValid && r.length() > 0) { - // Check if the range is an integer that is between 0 and enumeration indexes size - try { - int index = Integer.parseInt(r); - int min = 1; - int max = enumeration.getEnumerationIndexes().size(); - if(index >= min && index <= max || enumeration.isReplaceable()) { - componentIsValid = true; - error = new SyntaxError(); - error.setMessage("Using numbers as array indexes is not encouraged"); - error.setType(ExpressionField.SYNTAX_WARNING); - result.put(i, error); - } else { - error = new SyntaxError(); - error.setMessage("Invalid array index " + index + ". Numbered index must be between " + min + " and " + max); - error.setType(ExpressionField.SYNTAX_ERROR); - result.put(i, error); - } - } catch (NumberFormatException e) { error = new SyntaxError(); - error.setMessage("Invalid range"); + error.setMessage("Using numbers as array indexes is not encouraged"); + error.setType(ExpressionField.SYNTAX_WARNING); + result.put(i, error); + } else { + error = new SyntaxError(); + error.setMessage("Invalid array index " + index + ". Numbered index must be between " + min + " and " + max); error.setType(ExpressionField.SYNTAX_ERROR); result.put(i, error); } + } catch (NumberFormatException e) { + error = new SyntaxError(); + error.setMessage("Invalid range"); + error.setType(ExpressionField.SYNTAX_ERROR); + result.put(i, error); } } } - if(result.isEmpty()) - return null; - else - return result; - } + return result; + } - /** + /** * Checks if the given range can be applied to the given variable. * * @param graph ReadGraph @@ -139,13 +167,30 @@ public class ArrayVariableUtils { if(variable == null) return true; String[] elements = range.split(","); + // Connect arrays, e.g. {a,b,c} + ArrayList connectedElements = new ArrayList(); + for (int i = 0; i < elements.length; ++i) { + String lastElement = elements[i]; + String fullElement = new String(); + if (lastElement.length() > 0 && lastElement.charAt(0) == '{') { + while (lastElement.charAt(lastElement.length() - 1) != '}' && i < elements.length - 1) { + fullElement += lastElement + ","; + ++i; + lastElement = elements[i]; + } + } + fullElement += lastElement; + connectedElements.add(fullElement); + } + String fullElements[] = connectedElements.toArray(new String[connectedElements.size()]); + SysdynModel model = ModelUtils.getModel(graph, variable); if(model == null) return false; IElement e = model.getElement(variable); if(e != null && e instanceof Variable) { Variable v = (Variable) e; - if(isRangeValid(graph, v, elements) == null) + if(isRangeValid(graph, v, fullElements) == null) return true; else return false; diff --git a/org.simantics.sysdyn/adapters.xml b/org.simantics.sysdyn/adapters.xml index 509cd5ea..c01c1f80 100644 --- a/org.simantics.sysdyn/adapters.xml +++ b/org.simantics.sysdyn/adapters.xml @@ -97,5 +97,13 @@ adapterClass="org.simantics.sysdyn.adapter.RunVariableAdapter"/> --> + + + + + \ No newline at end of file diff --git a/org.simantics.sysdyn/scl/Sysdyn.scl b/org.simantics.sysdyn/scl/Sysdyn.scl index b32a845a..148fe0fb 100644 --- a/org.simantics.sysdyn/scl/Sysdyn.scl +++ b/org.simantics.sysdyn/scl/Sysdyn.scl @@ -91,6 +91,8 @@ importJava "org.simantics.sysdyn.utils.DocumentationUtils" where isParameter :: Variable -> Boolean lastValue :: Resource -> String -> String -> Double + lastValue2 :: Variable -> String -> Variable + equation :: Variable -> String -> Variable importJava "org.simantics.sysdyn.manager.SysdynExperiments" where diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java index 002925aa..04c2b623 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java @@ -1,14 +1,18 @@ package org.simantics.sysdyn; +import java.util.Collection; import java.util.HashMap; import java.util.Map; +import org.simantics.databoard.Bindings; import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.mutable.Variant; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ResourceRead; import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.function.All; import org.simantics.db.layer0.variable.StandardGraphChildVariable; @@ -25,6 +29,7 @@ import org.simantics.sysdyn.adapter.NamesIndexVariable; import org.simantics.sysdyn.adapter.TimeIndexVariable; import org.simantics.sysdyn.adapter.TimesIndexVariable; import org.simantics.sysdyn.adapter.ValueIndexVariable; +import org.simantics.sysdyn.adapter.ValueIndexVariableI; import org.simantics.sysdyn.adapter.ValuesIndexVariable; public class Functions { @@ -68,6 +73,68 @@ public class Functions { } }; + + @SCLValue(type = "ValueAccessor") + public static ValueAccessor equationPropertyValue = new ValueAccessor() { + + @Override + public Object getValue(ReadGraph graph, Variable context) throws DatabaseException { + return getValue(graph, context, Bindings.STRING); + } + + @Override + public Object getValue(ReadGraph graph, Variable context, Binding binding) throws DatabaseException { + + Variable v = context.getParent(graph); + + Resource represents = v.getPossibleRepresents(graph); + if(represents != null) { + SysdynResource SYSDYN = SysdynResource.getInstance(graph); + Collection res = ListUtils.toList(graph, graph.getSingleObject(represents, SYSDYN.Variable_expressionList)); + if(res.size() == 1) { + Resource exp = res.iterator().next(); + String text = graph.getRelatedValue(exp, SYSDYN.Expression_equation, Bindings.STRING); + return text; + } + } + + return null; + + } + + @Override + public void setValue(WriteGraph graph, Variable context, Object value) throws DatabaseException { + + if(value instanceof Variant) value = ((Variant)value).getValue(); + + if(!(value instanceof String)) throw new DatabaseException("Unexpected value " + value + ", expected String"); + + setValue(graph, context, value, Bindings.STRING); + + } + + @Override + public void setValue(WriteGraph graph, Variable context, Object value, Binding binding) throws DatabaseException { + + if(value instanceof Variant) value = ((Variant)value).getValue(); + + if(!(value instanceof String)) throw new DatabaseException("Unexpected value " + value + ", expected String"); + + Variable v = context.getParent(graph); + + Resource represents = v.getPossibleRepresents(graph); + if(represents != null) { + SysdynResource SYSDYN = SysdynResource.getInstance(graph); + Collection res = ListUtils.toList(graph, graph.getSingleObject(represents, SYSDYN.Variable_expressionList)); + if(res.size() == 1) { + Resource exp = res.iterator().next(); + graph.claimLiteral(exp, SYSDYN.Expression_equation, value, Bindings.STRING); + } + } + + } + + }; @SCLValue(type = "VariableMap") @@ -97,7 +164,12 @@ public class Functions { String property = context.getName(graph); if(VALUE.equals(property)) - return new ValueIndexVariable(graph, context, name); + if(name.startsWith("$")) { + Integer index = Integer.parseInt(name.substring(1)); + return new ValueIndexVariableI(graph, context, index); + } else { + return new ValueIndexVariable(graph, context, name); + } else if(VALUES.equals(property)) return new ValuesIndexVariable(graph, context, name); else if(TIMES.equals(property)) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/CustomMigrationStep.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/CustomMigrationStep.java new file mode 100644 index 00000000..dce49fa4 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/CustomMigrationStep.java @@ -0,0 +1,58 @@ +package org.simantics.sysdyn.adapter; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.migration.MigrationState; +import org.simantics.db.layer0.migration.MigrationStateKeys; +import org.simantics.db.layer0.migration.MigrationStep; +import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.layer0.Layer0; +import org.simantics.layer0.utils.direct.GraphUtils; +import org.simantics.simulation.ontology.SimulationResource; +import org.simantics.spreadsheet.resource.SpreadsheetResource; + +public class CustomMigrationStep implements MigrationStep { + + @Override + public void applyTo(IProgressMonitor monitor, Session session, MigrationState state) throws DatabaseException { + + final Resource res = state.getProperty(MigrationStateKeys.CURRENT_RESOURCE); + + session.syncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + + Layer0 l0 = Layer0.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + + for(Resource model : graph.syncRequest(new ObjectsWithType(res, l0.ConsistsOf, SIMU.Model))) { + + Resource sheetExperiment = Layer0Utils.getPossibleChild(graph, model, "SheetExperiment"); + if(sheetExperiment != null) return; + + SpreadsheetResource SHEET = SpreadsheetResource.getInstance(graph); + sheetExperiment = GraphUtils.create2(graph, SHEET.Experiment, + l0.HasName, "SheetExperiment", + l0.HasLabel, "Sheet Experiment", + l0.PartOf, model); + + Resource sheetRun = GraphUtils.create2(graph, SHEET.Run, + l0.HasName, "Default", + l0.PartOf, sheetExperiment); + + + } + + } + + }); + + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java index 71ea423e..3b05dd71 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariable.java @@ -1,111 +1,19 @@ package org.simantics.sysdyn.adapter; -import java.util.ArrayList; -import java.util.Collection; - import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; -import org.simantics.fmu.FMUControlJNI; -import org.simantics.fmu.FMUJNIException; -import org.simantics.simulation.experiment.ExperimentState; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.manager.SysdynDataSet; -import org.simantics.sysdyn.manager.SysdynGameExperiment; -import org.simantics.sysdyn.manager.SysdynResult; -public class ValueIndexVariable extends IndexVariable { +public class ValueIndexVariable extends ValueIndexVariableBase { public ValueIndexVariable(ReadGraph graph, Variable parent, String indexes) throws DatabaseException { super(graph, parent, indexes); } - - public static double[] UNRESOLVED = new double[0]; @Override public double[] getValue() { - if(experiment == null) - return UNRESOLVED; - - Collection results = experiment.getActiveResults(); - ArrayList variableNames = getVariableNamesWithIndexNumbers(); - - double[] result = new double[variableNames.size()]; - for(int i = 0; i < variableNames.size(); i++) { - for(SysdynResult r : results) { - if(experiment instanceof SysdynGameExperiment) { - Double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i)); - result[i] = d != null ? d : 0; - } else { - SysdynDataSet ds = r.getDataSet(variableNames.get(i)); - if(ds != null && ds.values != null && ds.values.length > 0) { - result[i] = ds.values[ds.values.length-1]; - } else { - return UNRESOLVED; - } - } - } - } - return result; + return getValueFull(); } - - @Override - public void setIndexedValue(WriteGraph graph, Object value) - throws DatabaseException { - Variable var = parent.getParent(graph); - Resource resource = var.getRepresents(graph); - - if(!(value instanceof double[]) || resource == null) - return; - - double[] values = (double[]) value; - - FMUControlJNI control = null; - if(experiment instanceof SysdynGameExperiment) { // Support only game experiments for now.. - - SysdynGameExperiment exp = (SysdynGameExperiment)experiment; - ExperimentState state = exp.getSysdynExperimentState(); - // Set value to control only if the simulation is running or stopped, not before initialization - if(!(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state))) - return; - - control = ((SysdynGameExperiment)this.experiment).getFMUControl(); - if(control == null) - return; - - - - ArrayList variableNames = getVariableNamesWithIndexNumbers(); - for(int i = 0; i < variableNames.size() && i < values.length; i++) { - if(values[i] == Double.NaN) - continue; - - try { - String name = variableNames.get(i); - control.setRealValue(name, values[i]); - - // Set value for all referred variables in modules - SysdynResource sr = SysdynResource.getInstance(graph); - for(Resource dependency : graph.getObjects(resource, sr.Variable_isTailOf)) { - Resource head = graph.getPossibleObject(dependency, sr.Variable_HasHead); - Resource ref = graph.getPossibleObject(dependency, sr.Dependency_refersTo); - if(ref != null && head != null) { - String module = ""; - if(name.indexOf(".") > 0) - module = name.substring(0, name.lastIndexOf(".") + 1); - String refName = module + NameUtils.getSafeName(graph, head) + "." + NameUtils.getSafeName(graph, ref); - control.setRealValue(refName, values[i]); - } - } - } catch (FMUJNIException e) { - } - } - exp.updateSubscriptions(); - } - } - + } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java new file mode 100644 index 00000000..83bfbba8 --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableBase.java @@ -0,0 +1,110 @@ +package org.simantics.sysdyn.adapter; + +import java.util.ArrayList; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.fmu.FMUControlJNI; +import org.simantics.fmu.FMUJNIException; +import org.simantics.simulation.experiment.ExperimentState; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.sysdyn.manager.SysdynDataSet; +import org.simantics.sysdyn.manager.SysdynGameExperiment; +import org.simantics.sysdyn.manager.SysdynResult; + +abstract public class ValueIndexVariableBase extends IndexVariable { + + public ValueIndexVariableBase(ReadGraph graph, Variable parent, String indexes) + throws DatabaseException { + super(graph, parent, indexes); + } + + public static double[] UNRESOLVED = new double[0]; + + public double[] getValueFull() { + if(experiment == null) + return UNRESOLVED; + + Collection results = experiment.getActiveResults(); + ArrayList variableNames = getVariableNamesWithIndexNumbers(); + + double[] result = new double[variableNames.size()]; + for(int i = 0; i < variableNames.size(); i++) { + for(SysdynResult r : results) { + if(experiment instanceof SysdynGameExperiment) { + Double d = ((SysdynGameExperiment)experiment).getCurrentValue(variableNames.get(i)); + result[i] = d != null ? d : 0; + } else { + SysdynDataSet ds = r.getDataSet(variableNames.get(i)); + if(ds != null && ds.values != null && ds.values.length > 0) { + result[i] = ds.values[ds.values.length-1]; + } else { + return UNRESOLVED; + } + } + } + } + return result; + } + + @Override + public void setIndexedValue(WriteGraph graph, Object value) + throws DatabaseException { + Variable var = parent.getParent(graph); + Resource resource = var.getRepresents(graph); + + if(!(value instanceof double[]) || resource == null) + return; + + double[] values = (double[]) value; + + FMUControlJNI control = null; + if(experiment instanceof SysdynGameExperiment) { // Support only game experiments for now.. + + SysdynGameExperiment exp = (SysdynGameExperiment)experiment; + ExperimentState state = exp.getSysdynExperimentState(); + // Set value to control only if the simulation is running or stopped, not before initialization + if(!(ExperimentState.RUNNING.equals(state) || ExperimentState.STOPPED.equals(state))) + return; + + control = ((SysdynGameExperiment)this.experiment).getFMUControl(); + if(control == null) + return; + + + + ArrayList variableNames = getVariableNamesWithIndexNumbers(); + for(int i = 0; i < variableNames.size() && i < values.length; i++) { + if(values[i] == Double.NaN) + continue; + + try { + String name = variableNames.get(i); + control.setRealValue(name, values[i]); + + // Set value for all referred variables in modules + SysdynResource sr = SysdynResource.getInstance(graph); + for(Resource dependency : graph.getObjects(resource, sr.Variable_isTailOf)) { + Resource head = graph.getPossibleObject(dependency, sr.Variable_HasHead); + Resource ref = graph.getPossibleObject(dependency, sr.Dependency_refersTo); + if(ref != null && head != null) { + String module = ""; + if(name.indexOf(".") > 0) + module = name.substring(0, name.lastIndexOf(".") + 1); + String refName = module + NameUtils.getSafeName(graph, head) + "." + NameUtils.getSafeName(graph, ref); + control.setRealValue(refName, values[i]); + } + } + } catch (FMUJNIException e) { + } + } + exp.updateSubscriptions(); + } + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableI.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableI.java new file mode 100644 index 00000000..b50195ba --- /dev/null +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/ValueIndexVariableI.java @@ -0,0 +1,23 @@ +package org.simantics.sysdyn.adapter; + +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; + +public class ValueIndexVariableI extends ValueIndexVariableBase { + + final int index; + + public ValueIndexVariableI(ReadGraph graph, Variable parent, int index) throws DatabaseException { + super(graph, parent, ""); + this.index = index; + } + + @Override + public Double getValue() { + double[] array = getValueFull(); + if(array == null || array.length < index+1) return Double.NaN; + return array[0]; + } + +} diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java index 7a87c0b5..7a27fd24 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java @@ -68,8 +68,10 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable { String name = child.getName(g); try { SpreadsheetUtils.decodeCellAbsolute(name); - Variant value = child.getPropertyValue(g, SheetVariables.CONTENT, Bindings.VARIANT); - newCells.put(name, value.getValue()); + Object value = child.getPropertyValue(g, SheetVariables.CONTENT); + if(value instanceof Variant) { + newCells.put(name, ((Variant)value).getValue()); + } } catch (CellParseException e) { } catch (MissingVariableException e) { System.out.println("missing content for: " + name); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java index cc79fda7..360ffe1b 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/IndexUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Copyright (c) 2007, 2011, 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 @@ -45,15 +45,24 @@ public class IndexUtils { if(variable.getArrayIndexes() == null || range == null) return ""; ArrayList enumerations = variable.getArrayIndexes(); - StringTokenizer st = new StringTokenizer(range, "[]:,", true); + StringTokenizer st = new StringTokenizer(range, "{}[]:,", true); int index = 0; + boolean insideCurlyBrackets = false; while(st.hasMoreTokens()) { String rangeToken = st.nextToken().trim(); if(rangeToken.matches("[\\[\\]:]")) { sb.append(rangeToken); + } else if(rangeToken.matches("[\\{]")) { + sb.append(rangeToken); + insideCurlyBrackets = true; + } else if(rangeToken.matches("[\\}]")) { + sb.append(rangeToken); + insideCurlyBrackets = false; } else if (rangeToken.equals(",")) { sb.append(rangeToken); - index++; + if (!insideCurlyBrackets) { + index++; + } } else if(index < enumerations.size()) { if(rangeToken.equals(enumerations.get(index).getName())) { sb.append(":"); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java index b3e39609..725516d3 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java @@ -550,5 +550,33 @@ public class DocumentationUtils { } } + + public static org.simantics.db.layer0.variable.Variable lastValue2(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException { + + if(run == null) return null; + + org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, "/" + path); + if(v == null) return null; + + org.simantics.db.layer0.variable.Variable p = v.browsePossible(graph, "#value#$0"); + if(p == null) return null; + + return p; + + } + + public static org.simantics.db.layer0.variable.Variable equation(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException { + + if(run == null) return null; + + org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, "/" + path); + if(v == null) return null; + + org.simantics.db.layer0.variable.Variable p = v.browsePossible(graph, "#equation"); + if(p == null) return null; + + return p; + + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java index cfb10396..bd3d9095 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/LoopUtils.java @@ -23,6 +23,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.exception.ServiceException; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; @@ -283,8 +284,13 @@ public class LoopUtils { } skipBackwardFlows = true; - Resource dependencyConnection = graph.getSingleObject(dependency, mod.ConnectionToDiagramConnection); - String polarity = (String)graph.getPossibleRelatedValue(dependencyConnection, sr.DependencyConnection_polarity, Bindings.STRING); + Resource dependencyConnection; + try { + dependencyConnection = graph.getSingleObject(dependency, mod.ConnectionToDiagramConnection); + } catch (NoSingleResultException e) { + return LoopType.UNDEFINED; + } + String polarity = (String)graph.getPossibleRelatedValue(dependencyConnection, sr.DependencyConnection_polarity, Bindings.STRING); if ("-".equals(polarity)) { oddNumberOfNegativeCausalities = !oddNumberOfNegativeCausalities; } else if (polarity != null diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java index 6a77c80b..e3212aba 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ModelUtils.java @@ -150,6 +150,15 @@ public class ModelUtils { DOC.HasReportFactory, report, l0.PartOf, model); + Resource sheetExperiment = GraphUtils.create2(g, SHEET.Experiment, + l0.HasName, "SheetExperiment", + l0.HasLabel, "Sheet Experiment", + l0.PartOf, model); + + Resource sheetRun = GraphUtils.create2(g, SHEET.Run, + l0.HasName, "Default", + l0.PartOf, sheetExperiment); + ProjectResource PROJ = ProjectResource.getInstance(g); for(Resource dep : g.getObjects(library, l0.IsLinkedTo)) { if(g.isInstanceOf(dep, PROJ.NamespaceRequirement)) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java index f53920c9..cb18b868 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/ProfileEntries.java @@ -17,6 +17,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.profile.Profiles; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; +import org.simantics.simulation.ontology.SimulationResource; import org.simantics.sysdyn.SysdynResource; public class ProfileEntries { @@ -43,6 +44,12 @@ public class ProfileEntries { // public void perform(WriteGraph graph) throws DatabaseException { // DiagramResource DIA = DiagramResource.getInstance(graph); graph.claim(model, DIA.HasActiveProfile, defaultProfile); + SimulationResource SIMU = SimulationResource.getInstance(graph); + graph.claim(defaultProfile, SIMU.IsActive, null, sr.Profiles_IssueWarnings); + graph.claim(defaultProfile, SIMU.IsActive, null, sr.Profiles_ShadowVisualizations); + graph.claim(model, DIA.HasActiveProfile, simulationPlaybackProfile); + graph.claim(simulationPlaybackProfile, SIMU.IsActive, null, sr.Profiles_SimulationPlaybackColours); + // } // });