From: miettinen Date: Mon, 27 Jan 2014 10:07:38 +0000 (+0000) Subject: Unit validation for functions in Sysdyn: unit definitions for built-in functions... X-Git-Tag: 1.8.1~152 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=faad26c7b7866fe5dee4add690e08898873a8215;p=simantics%2Fsysdyn.git Unit validation for functions in Sysdyn: unit definitions for built-in functions and propagation of available functions (also user-defined) information within the unit parser (refs #4320). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28714 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index afa595a6..130eceff 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/ModelicaArrayFunctions.pgraph b/org.simantics.sysdyn.ontology/graph/ModelicaArrayFunctions.pgraph index aefaea03..847db26c 100644 --- a/org.simantics.sysdyn.ontology/graph/ModelicaArrayFunctions.pgraph +++ b/org.simantics.sysdyn.ontology/graph/ModelicaArrayFunctions.pgraph @@ -16,10 +16,12 @@ Returns the single element of array A. size(A,i) = 1 is required for 1 <= i <= n MAF.scalar.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.scalar.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -38,10 +40,12 @@ Real v[2] = vector(A); // = {3,4}""" MAF.vector.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.vector.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -61,10 +65,12 @@ C[i_1, ..., i_nA, 1, ..., 1] = A[i_1, ..., i_nA].""" MAF.matrix.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.matrix.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -79,10 +85,12 @@ Returns the number of dimensions k of array expression A, with k >= 0.""" MAF.ndims.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.ndims.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Integer" + SYSDYN.SysdynModelicaFunction.unit "1" @@ -105,13 +113,16 @@ Integer n[:] = size(A); // = {8,4,5}""" MAF.size.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" MAF.size.i : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional true + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.size.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" @@ -131,6 +142,7 @@ The constructor function array(A,B,C,...) constructs an array from its arguments MAF.array.A : SYSDYN.SysdynModelicaFunction.VariableLengthInput SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.VariableLengthInput.shownLabels _ : L0.List @L0.list MAF.array.A.A : L0.String @@ -140,6 +152,7 @@ The constructor function array(A,B,C,...) constructs an array from its arguments @L0.list MAF.array.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -162,9 +175,11 @@ Real[2,6] r2 = cat(2, r1, 2*r1);""" MAF.cat.k : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" MAF.cat.A : SYSDYN.SysdynModelicaFunction.VariableLengthInput SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.VariableLengthInput.shownLabels _ : L0.List @L0.list MAF.cat.A.A : L0.String @@ -174,6 +189,7 @@ Real[2,6] r2 = cat(2, r1, 2*r1);""" @L0.list MAF.cat.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -188,6 +204,7 @@ Returns the n1 x n2 x n3 x ... Integer array with all elements equal to zero (ni MAF.zeros.n : SYSDYN.SysdynModelicaFunction.VariableLengthInput SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.VariableLengthInput.shownLabels _ : L0.List @L0.list MAF.zeros.n.n1 : L0.String @@ -197,6 +214,7 @@ Returns the n1 x n2 x n3 x ... Integer array with all elements equal to zero (ni @L0.list MAF.zeros.o : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Integer" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Integer n annotation(__OpenModelica_varArgs = true); output Integer o[:];""" @@ -213,6 +231,7 @@ Return the n1 x n2 x n3 x ... Integer array with all elements equal to one (ni > MAF.ones.n : SYSDYN.SysdynModelicaFunction.VariableLengthInput SYSDYN.Variable.type "Integer" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.VariableLengthInput.shownLabels _ : L0.List @L0.list MAF.ones.n.n1 : L0.String @@ -222,6 +241,7 @@ Return the n1 x n2 x n3 x ... Integer array with all elements equal to one (ni > @L0.list MAF.ones.o : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Integer" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Integer n annotation(__OpenModelica_varArgs = true); output Integer o[:];""" @@ -244,9 +264,11 @@ Boolean vb[3] = fill(true,3); // = {true, true, true}""" MAF.fill.s : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MAF.fill.n : SYSDYN.SysdynModelicaFunction.VariableLengthInput SYSDYN.Variable.type "Integer" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.VariableLengthInput.shownLabels _ : L0.List @L0.list MAF.fill.n.n1 : L0.String @@ -256,6 +278,7 @@ Boolean vb[3] = fill(true,3); // = {true, true, true}""" @L0.list MAF.fill.o : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input OpenModelica.Internal.BuiltinType s; input Integer n annotation(__OpenModelica_varArgs = true); output OpenModelica.Internal.BuiltinType o[:];""" @@ -273,10 +296,12 @@ Returns the n x n Integer identity matrix, with ones on the diagonal and zeros a MAF.identity.n : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Integer " SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.identity.outArray : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Integer " + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Integer n; output Integer[n,n] outArray;""" @@ -293,10 +318,12 @@ Returns a square matrix with the elements of vector v on the diagonal and all ot MAF.diagonal.v : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.diagonal.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -316,16 +343,20 @@ Real v[:] = linspace(1,7,4); // = {1, 3, 5, 7}""" MAF.linspace.x1 : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MAF.linspace.x2 : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MAF.linspace.n : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Integer" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.linspace.v : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real x1 "start"; input Real x2 "end"; input Integer n "number"; @@ -344,10 +375,12 @@ Returns the smallest element of array expression A.""" MAF.min.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.min.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -362,10 +395,12 @@ Returns the largest element of array expression A.""" MAF.max.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.max.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -391,10 +426,12 @@ sum(i for i in 1:10) // Gives 1+2+...+10=55 MAF.sum.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.sum.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -419,10 +456,12 @@ Example: MAF.product.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.product.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "ANY" @@ -437,10 +476,12 @@ Permutes the first two dimensions of array A. It is an error, if array A does no MAF.transpose.A : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.transpose.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -458,13 +499,16 @@ cross(x,y) = vector( [ x[2]*y[3]-x[3]*y[2]; MAF.cross.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MAF.cross.y : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'q" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.cross.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p*'q" @@ -483,7 +527,10 @@ skew(x) = [ 0 , -x[3], x[2]; MAF.skew.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MAF.skew.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" + \ No newline at end of file diff --git a/org.simantics.sysdyn.ontology/graph/ModelicaFunctions.pgraph b/org.simantics.sysdyn.ontology/graph/ModelicaFunctions.pgraph index 21e2f7d2..942591ad 100644 --- a/org.simantics.sysdyn.ontology/graph/ModelicaFunctions.pgraph +++ b/org.simantics.sysdyn.ontology/graph/ModelicaFunctions.pgraph @@ -16,10 +16,12 @@ Returns the absolute value of v. Is expanded into "(if v >= 0 then v else -v)" ( MF.abs.v : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.abs.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -34,10 +36,12 @@ Returns the inverse of cos of u, with -1 <= u <= +1. Argument u needs to be an I MF.acos.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.acos.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u; output Real y;""" @@ -54,10 +58,12 @@ Returns the inverse of sin of u, with -1 <= u <= +1. Argument u needs to be an I MF.asin.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.asin.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u; output Real y;""" @@ -74,10 +80,12 @@ Returns the inverse of tan of u, with -INF < u < INF. Argument u needs to be an MF.atan.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.atan.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u; output Real y;""" @@ -94,13 +102,16 @@ Returns y = atan2(u1,u2) such that tan(y) = u1/u2 and y is in the range -pi < y MF.atan2.u1 : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.atan2.u2 : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.atan2.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u1; input Real u2; output Real z;""" @@ -118,10 +129,12 @@ Returns the smallest integer not less than x (i.e. the closest integer above x). MF.ceil.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.ceil.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real x; output Real y;""" @@ -138,10 +151,12 @@ Returns the cosine of u, with -INF < u < INF Argument u needs to be an Integer o MF.ceil.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.ceil.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u; output Real y;""" @@ -158,10 +173,12 @@ Returns the cosh of u, with -INF < u < INF. Argument u needs to be an Integer or MF.cosh.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.cosh.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u; output Real y;""" @@ -179,16 +196,20 @@ Returns "expr(time - delayTime)" for time > time.start + delayTime and "expr(tim MF.delay.expr : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.delay.delayTime : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "TIME" MF.delay.delayMax : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional true + SYSDYN.SysdynModelicaFunction.unit "TIME" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.delay.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -209,10 +230,12 @@ equation MF.der.expr : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.der.dexpr : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p/TIME" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real expr(unit = "'p"); output Real dexpr(unit = "'p/s");""" @@ -229,13 +252,16 @@ Returns the algebraic quotient x/y with any fractional part discarted (also know MF.div.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.div.y : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'q" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.div.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p/'q" @@ -250,10 +276,12 @@ Returns true when the value of the boolean expression b changes. Expanded into ( MF.edge.b : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Boolean" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.edge.edgeEvent : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Boolean" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Boolean b; output Boolean edgeEvent;""" @@ -270,10 +298,12 @@ Returns the base e exponential of u, with -INF < u < INF Argument u needs to be MF.exp.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.exp.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u(unit = "1"); output Real y(unit = "1");""" @@ -290,10 +320,12 @@ Returns the largest integer not greater than x (i.e. the closest integer below x MF.floor.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.floor.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real x; output Real y;""" @@ -311,6 +343,7 @@ Returns true during the initialization phase and false otherwise.""" @L0.list MF.initial.isInitial : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Boolean" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ output Boolean isInitial;""" @@ -326,10 +359,12 @@ Returns the base e logarithm of u, with u > 0. Argument u needs to be an Integer MF.log.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.log.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u(unit = "1"); output Real y(unit = "1");""" @@ -346,10 +381,12 @@ Returns the base 10 logarithm of u, with u > 0. Argument u needs to be an Intege MF.log10.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.log10.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u(unit = "1"); output Real y(unit = "1");""" @@ -372,13 +409,16 @@ max(i^2 for i in {3,7,6}) // = 49""" MF.max.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.max.y : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.max.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -399,13 +439,16 @@ min(i^2 for i in {3,7,6}) // = 9""" MF.min.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.min.y : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.min.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -420,13 +463,16 @@ Returns the integer modulus of x/y: mod(x,y) = x - floor(x/y) * y.""" MF.mod.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.mod.y : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.mod.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -444,10 +490,12 @@ If you want a condition to be checked only on time steps, use noEvent. MF.noEvent.expr : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.noEvent.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" @@ -467,10 +515,14 @@ A new event is triggered if at least for one variable v "pre(v) <> v" after the MF.pre.y : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.pre.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" + + MF.rem : SYSDYN.SysdynModelicaFunction L0.HasDescription """rem(x, y) @@ -483,13 +535,16 @@ Returns the integer remainder of x/y: rem(x,y) = x - div(x,y) * y.""" MF.rem.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.rem.y : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.rem.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -504,13 +559,16 @@ Returns true and triggers time events at times start + i * interval (i=0,1,...). MF.sample.start : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "TIME" MF.sample.interval : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "TIME" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.sample.isSample : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Boolean" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ parameter input Real start(fixed = false); parameter input Real interval(fixed = false); output Boolean isSample;""" @@ -551,16 +609,20 @@ sa = sb;""" MF.semiLinear.x : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" MF.semiLinear.positiveSlope : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'q" MF.semiLinear.negativeSlope : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'q" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.semiLinear.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p*'q" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real x; input Real positiveSlope; input Real negativeSlope; @@ -579,10 +641,12 @@ Returns -1 if v is negative, 1 if v is positive. Expanded into "(if v > 0 then 1 MF.sign.v : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.sign.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Integer" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real v; output Integer result;""" @@ -599,10 +663,12 @@ Returns the sine of u, with -INF < u < INF. Argument u needs to be an Integer or MF.sin.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.sin.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real x; output Real y;""" @@ -619,10 +685,12 @@ Returns the sinh of u, with -INF < u < INF. Argument u needs to be an Integer or MF.sinh.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.sinh.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real x; output Real y;""" @@ -640,13 +708,16 @@ The only allowed types for expr in smooth are: real expressions, arrays of allow MF.smooth.p : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "1" MF.smooth.expr : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "'p" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.smooth.result : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "'p" @@ -661,10 +732,12 @@ Square root of v. The value of v must be greater or equal to 0 or an assertion e MF.sqrt.v : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.sqrt.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real v(unit = "'p"); output Real y(unit = "'p(1/2)");""" @@ -681,10 +754,12 @@ Returns the tangent of u, with -INF < u < INF (if u is a multiple of (2n-1)*pi/2 MF.tan.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.tan.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real u; output Real y;""" @@ -701,10 +776,12 @@ Returns the tanh of u, with -INF < u < INF. Argument u needs to be an Integer or MF.tanh.u : SYSDYN.SysdynModelicaFunction.Input SYSDYN.Variable.type "Real" SYSDYN.SysdynModelicaFunction.optional false + SYSDYN.SysdynModelicaFunction.unit "ANY" SYSDYN.SysdynModelicaFunction.outputs _ : L0.List @L0.list MF.tanh.y : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Real" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ input Real x; output Real y;""" @@ -722,5 +799,6 @@ Returns true at the end of a successful simulation.""" @L0.list MF.terminal.isTerminal : SYSDYN.SysdynModelicaFunction.Output SYSDYN.Variable.type "Boolean" + SYSDYN.SysdynModelicaFunction.unit "1" SYSDYN.SysdynModelicaFunction.modelicaFunctionInterface """ output Boolean isTerminal;""" \ No newline at end of file diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index b14b917b..4fc523d6 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -324,6 +324,7 @@ SYSDYN.SysdynModelicaFunctionLibrary -- SYSDYN.SysdynModelicaFunction.definition --> L0.String -- SYSDYN.SysdynModelicaFunction.unit --> L0.String -- SYSDYN.SysdynModelicaFunction.optional --> L0.Boolean functions = Function.getAllBuiltInFunctions(graph); + result = UnitUtils.matchUnits(left, right, functions, UnitUtils.allowEquivalents(graph, model)); if(result != null) issues.add(new ModuleStandardIssue(SR.Validations_ModuleOutputUnitWarning, module, output, reference)); } @@ -139,7 +141,8 @@ public class UnitFunction { continue; String left = graph.getPossibleRelatedValue(variable, SR.Variable_unit); String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit); - result = UnitUtils.matchUnits(left, right, UnitUtils.allowEquivalents(graph, model)); + ArrayList functions = Function.getAllBuiltInFunctions(graph); + result = UnitUtils.matchUnits(left, right, functions, UnitUtils.allowEquivalents(graph, model)); if(result != null) issues.add(new ModuleStandardIssue(SR.Validations_ModuleInputUnitWarning, module, variable, reference)); } @@ -230,7 +233,8 @@ public class UnitFunction { return "No unit defined for " + NameUtils.getSafeName(graph, rightResource); SysdynModel model = ModelUtils.getModel(graph, leftResource); - String result = UnitUtils.matchUnits(left, right, UnitUtils.allowEquivalents(graph, model)); + ArrayList functions = Function.getAllBuiltInFunctions(graph); + String result = UnitUtils.matchUnits(left, right, functions, UnitUtils.allowEquivalents(graph, model)); if(result != null) result = prefix + result + suffix; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/TestParser.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/TestParser.java index 95393832..86b3245c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/TestParser.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/TestParser.java @@ -20,6 +20,7 @@ import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.UnitParser; import org.simantics.sysdyn.unitParser.nodes.UnitResult; +import org.simantics.sysdyn.utils.Function; public class TestParser { @@ -60,7 +61,7 @@ public class TestParser { UnitCheckingNode node = (UnitCheckingNode) parser.expr(); try { - UnitResult u = node.getUnits(units, allowEquivalents); + UnitResult u = node.getUnits(units, Function.getAllBuiltInFunctions(), allowEquivalents); System.out.println("Result: " + u.getCleanFullUnit()); } catch (UnitCheckingException e) { e.printStackTrace(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java index 4949b478..04369f79 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.representation.utils; import java.io.StringReader; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -38,6 +39,7 @@ import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.UnitParser; import org.simantics.sysdyn.unitParser.nodes.ComponentReferenceFull; import org.simantics.sysdyn.unitParser.nodes.UnitResult; +import org.simantics.sysdyn.utils.Function; public class UnitUtils { @@ -52,7 +54,7 @@ public class UnitUtils { HashMap units = UnitUtils.findUnits(graph, model, configuration, components); try { - node.getUnits(units, allowEquivalents(graph, model)); + node.getUnits(units, Function.getAllBuiltInFunctions(graph), allowEquivalents(graph, model)); } catch (UnitCheckingException e) { return e.getMessage(); } catch (DatabaseException e) { @@ -107,9 +109,10 @@ public class UnitUtils { leftReader.close(); try { + ArrayList functions = Function.getAllBuiltInFunctions(graph); boolean allowEquivalents = allowEquivalents(graph, model); - UnitResult rightUnits = right.getUnits(units, allowEquivalents); - UnitResult leftUnits = left.getUnits(null, allowEquivalents); + UnitResult rightUnits = right.getUnits(units, functions, allowEquivalents); + UnitResult leftUnits = left.getUnits(null, functions, allowEquivalents); if(!rightUnits.equals(leftUnits)) return leftUnits.getCleanFullUnit() + " != " + rightUnits.getCleanFullUnit(); @@ -213,7 +216,7 @@ public class UnitUtils { } - public static String matchUnits(String left, String right, boolean allowEquivalents) throws DatabaseException { + public static String matchUnits(String left, String right, ArrayList functions, boolean allowEquivalents) throws DatabaseException { if(left == null || right == null || left.isEmpty() || right.isEmpty()) return "No unit defined"; @@ -230,8 +233,8 @@ public class UnitUtils { rightReader.close(); try { - UnitResult leftUnits = leftNode.getUnits(null, allowEquivalents); - UnitResult rightUnits = rightNode.getUnits(null, allowEquivalents); + UnitResult leftUnits = leftNode.getUnits(null, functions, allowEquivalents); + UnitResult rightUnits = rightNode.getUnits(null, functions, allowEquivalents); if(!rightUnits.equals(leftUnits)) return leftUnits.getCleanFullUnit() + " != " + rightUnits.getCleanFullUnit(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNode.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNode.java index 2233c88e..5a711256 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNode.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/UnitCheckingNode.java @@ -12,9 +12,11 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.nodes.UnitResult; +import org.simantics.sysdyn.utils.Function; public class UnitCheckingNode extends SimpleNode { @@ -23,7 +25,7 @@ public class UnitCheckingNode extends SimpleNode { super(id); } - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException{ + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException{ UnitResult result = new UnitResult(allowEquivalents); if(jjtGetNumChildren() == 0){ @@ -31,7 +33,7 @@ public class UnitCheckingNode extends SimpleNode { result.append(node); } else { for(int i = 0; i < jjtGetNumChildren(); i++) { - result.appendResult(((UnitCheckingNode)jjtGetChild(i)).getUnits(units, allowEquivalents)); + result.appendResult(((UnitCheckingNode)jjtGetChild(i)).getUnits(units, functions, allowEquivalents)); } } return result; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/AddOp.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/AddOp.java index 026b8a1c..6aafee9c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/AddOp.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/AddOp.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -31,8 +33,8 @@ public class AddOp extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { - UnitResult result = super.getUnits(units, allowEquivalents); + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result = super.getUnits(units, functions, allowEquivalents); result.setUnitType(UnitType.OPERATOR); return result; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Arithmetic.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Arithmetic.java index 396bcb1d..44bb2e21 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Arithmetic.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Arithmetic.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -32,7 +34,7 @@ public class Arithmetic extends UnitCheckingNode { @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { UnitResult result = new UnitResult(allowEquivalents); UnitCheckingNode base = null; @@ -41,12 +43,12 @@ public class Arithmetic extends UnitCheckingNode { for(int i = 0; i < jjtGetNumChildren(); i++) { candidateNode = ((UnitCheckingNode)jjtGetChild(i)); - UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents); + UnitResult candidateUnits = candidateNode.getUnits(units, functions, allowEquivalents); if(candidateUnits.getUnitType() == UnitType.OPERATOR) { continue; } else if(base == null || result.getUnitType() == UnitType.SCALAR || result.getUnitType() == UnitType.ANY) { base = ((UnitCheckingNode)jjtGetChild(i)); - result.appendResult(base.getUnits(units, allowEquivalents)); + result.appendResult(base.getUnits(units, functions, allowEquivalents)); continue; } else if(candidateUnits.getUnitType() == UnitType.SCALAR) { continue; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ArrayDefinition.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ArrayDefinition.java index 7b300b21..9754bd3e 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ArrayDefinition.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ArrayDefinition.java @@ -18,6 +18,7 @@ import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -33,7 +34,7 @@ public class ArrayDefinition extends UnitCheckingNode { @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { UnitResult result = new UnitResult(allowEquivalents); result.setUnitType(UnitType.SCALAR); @@ -43,13 +44,13 @@ public class ArrayDefinition extends UnitCheckingNode { FunctionArguments functionArguments = (FunctionArguments) jjtGetChild(0); for(UnitCheckingNode candidateNode : gatherExpressions(functionArguments, new ArrayList())) { - UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents); + UnitResult candidateUnits = candidateNode.getUnits(units, functions, allowEquivalents); if(candidateUnits.getUnitType() == UnitType.SCALAR) { continue; } else if(base == null) { base = candidateNode; UnitType oldUnitType = result.getUnitType(); - result.appendResult(base.getUnits(units, allowEquivalents)); + result.appendResult(base.getUnits(units, functions, allowEquivalents)); /* * Make sure unit type persist diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ComponentReferenceFull.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ComponentReferenceFull.java index c110fcb2..21b01648 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ComponentReferenceFull.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ComponentReferenceFull.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.unitParser.nodes; import java.io.StringReader; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.ParseException; @@ -20,6 +21,7 @@ import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.UnitParser; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -33,12 +35,12 @@ public class ComponentReferenceFull extends UnitCheckingNode { super(id); } - protected UnitResult parseUnits(String units, boolean allowEquivalents) { + protected UnitResult parseUnits(String units, ArrayList functions, boolean allowEquivalents) { StringReader sr = new StringReader(units); UnitParser parser = new UnitParser(sr); try { UnitCheckingNode node = (UnitCheckingNode) parser.expr(); - return node.getUnits(null, allowEquivalents); + return node.getUnits(null, functions, allowEquivalents); } catch (ParseException e) { e.printStackTrace(); } catch (UnitCheckingException e) { @@ -48,7 +50,7 @@ public class ComponentReferenceFull extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { String node = printNode(); if("dmnl".equals(node)) { @@ -61,7 +63,7 @@ public class ComponentReferenceFull extends UnitCheckingNode { if(!units.containsKey(node) || units.get(node) == null) throw new UnitCheckingException("No units defined for " + node); else { - return parseUnits(units.get(node), allowEquivalents); + return parseUnits(units.get(node), functions, allowEquivalents); } } else { UnitResult result = new UnitResult(allowEquivalents); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Divide.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Divide.java index 2c090ea2..c2061059 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Divide.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Divide.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -31,8 +33,8 @@ public class Divide extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { - UnitResult result = super.getUnits(units, allowEquivalents); + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result = super.getUnits(units, functions, allowEquivalents); result.setUnitType(UnitType.OPERATOR); return result; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Factor.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Factor.java index 369f67b6..fc92f871 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Factor.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Factor.java @@ -12,12 +12,14 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.Token; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -32,7 +34,7 @@ public class Factor extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { UnitResult result = new UnitResult(allowEquivalents); UnitCheckingNode current = null; @@ -41,7 +43,7 @@ public class Factor extends UnitCheckingNode { for(int i = 0; i < jjtGetNumChildren(); i++) { current = ((UnitCheckingNode)jjtGetChild(i)); - UnitResult currentUnits = current.getUnits(units, allowEquivalents); + UnitResult currentUnits = current.getUnits(units, functions, allowEquivalents); if(currentUnits.getUnitType() == UnitType.ANY) { result = new UnitResult(allowEquivalents); @@ -59,7 +61,7 @@ public class Factor extends UnitCheckingNode { UnitType unitType = currentUnits.getUnitType(); if(unitType == UnitType.SCALAR) { int exponent; - UnitResult baseUnits = base.getUnits(units, allowEquivalents); + UnitResult baseUnits = base.getUnits(units, functions, allowEquivalents); try { exponent = Integer.valueOf(currentUnits.getFullUnit()); } catch (NumberFormatException e) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ForIndex.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ForIndex.java index 4a185f7b..40889a10 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ForIndex.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/ForIndex.java @@ -12,10 +12,12 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -30,7 +32,7 @@ public class ForIndex extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { return new UnitResult(allowEquivalents); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/FunctionCall.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/FunctionCall.java index a99be2ec..fb04557a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/FunctionCall.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/FunctionCall.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -31,7 +33,7 @@ public class FunctionCall extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { UnitResult result = new UnitResult(allowEquivalents); result.setUnitType(UnitType.ANY); return result; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/IfThenElse.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/IfThenElse.java index 4234acaa..05c36d9b 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/IfThenElse.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/IfThenElse.java @@ -12,10 +12,12 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -31,14 +33,14 @@ public class IfThenElse extends UnitCheckingNode { @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { UnitResult base = null; UnitCheckingNode baseNode = null; UnitCheckingNode candidateNode = null; for(int i = 0; i < jjtGetNumChildren(); i++) { candidateNode = ((UnitCheckingNode)jjtGetChild(i)); - UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents); + UnitResult candidateUnits = candidateNode.getUnits(units, functions, allowEquivalents); if(!(candidateNode instanceof Condition)) { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Multiplication.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Multiplication.java index 43b13aae..57f28f79 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Multiplication.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Multiplication.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -31,8 +33,8 @@ public class Multiplication extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { - UnitResult result = super.getUnits(units, allowEquivalents); + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result = super.getUnits(units, functions, allowEquivalents); result.setUnitType(UnitType.OPERATOR); return result; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Power.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Power.java index ab1d9adf..8d90de3a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Power.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Power.java @@ -11,11 +11,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -29,8 +31,8 @@ public class Power extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { - UnitResult result = super.getUnits(units, allowEquivalents); + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result = super.getUnits(units, functions, allowEquivalents); result.setUnitType(UnitType.OPERATOR); return result; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/RelOp.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/RelOp.java index d7a62ade..56b4138f 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/RelOp.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/RelOp.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -31,8 +33,8 @@ public class RelOp extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { - UnitResult result = super.getUnits(units, allowEquivalents); + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result = super.getUnits(units, functions, allowEquivalents); result.setUnitType(UnitType.OPERATOR); return result; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java index 2fd22f3b..5831092b 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Relation.java @@ -12,10 +12,12 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -30,7 +32,7 @@ public class Relation extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { UnitResult result = new UnitResult(allowEquivalents); UnitCheckingNode base = null; @@ -42,14 +44,14 @@ public class Relation extends UnitCheckingNode { base = ((UnitCheckingNode)jjtGetChild(1)); if(base instanceof Arithmetic) { - result.appendResult(base.getUnits(units, allowEquivalents)); + result.appendResult(base.getUnits(units, functions, allowEquivalents)); for(int i = 2; i < jjtGetNumChildren(); i = i + 2) { candidateNode = ((UnitCheckingNode)jjtGetChild(i)); if(!(candidateNode instanceof Value)) { operator = ((UnitCheckingNode)jjtGetChild(i-1)); - UnitResult candidateUnits = candidateNode.getUnits(units, allowEquivalents); + UnitResult candidateUnits = candidateNode.getUnits(units, functions, allowEquivalents); if(!result.equals(candidateUnits)) { result.equals(candidateUnits); throw new UnitCheckingException("Not equals exception: " + diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Term.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Term.java index 344cf7eb..dfdcc54e 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Term.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Term.java @@ -12,12 +12,14 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.Token; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -32,7 +34,7 @@ public class Term extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { UnitResult result = new UnitResult(allowEquivalents); UnitCheckingNode current = null; @@ -41,7 +43,7 @@ public class Term extends UnitCheckingNode { for(int i = 0; i < jjtGetNumChildren(); i++) { current = ((UnitCheckingNode)jjtGetChild(i)); - UnitResult currentUnits = current.getUnits(units, allowEquivalents); + UnitResult currentUnits = current.getUnits(units, functions, allowEquivalents); if(currentUnits.getUnitType() == UnitType.ANY) { result = new UnitResult(allowEquivalents); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Value.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Value.java index 7e26c569..e0edb445 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Value.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/unitParser/nodes/Value.java @@ -12,11 +12,13 @@ *******************************************************************************/ package org.simantics.sysdyn.unitParser.nodes; +import java.util.ArrayList; import java.util.HashMap; import org.simantics.sysdyn.unitParser.UnitCheckingException; import org.simantics.sysdyn.unitParser.UnitCheckingNode; import org.simantics.sysdyn.unitParser.nodes.UnitResult.UnitType; +import org.simantics.sysdyn.utils.Function; /** * See UnitCheckingNodeFactory for mapping @@ -31,8 +33,8 @@ public class Value extends UnitCheckingNode { } @Override - public UnitResult getUnits(HashMap units, boolean allowEquivalents) throws UnitCheckingException { - UnitResult result = super.getUnits(units, allowEquivalents); + public UnitResult getUnits(HashMap units, ArrayList functions, boolean allowEquivalents) throws UnitCheckingException { + UnitResult result = super.getUnits(units, functions, allowEquivalents); result.setUnitType(UnitType.SCALAR); return result; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/Function.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/Function.java similarity index 72% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/Function.java rename to org.simantics.sysdyn/src/org/simantics/sysdyn/utils/Function.java index 6ddacd64..b01c62f6 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/Function.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/Function.java @@ -1,12 +1,8 @@ -package org.simantics.sysdyn.ui.properties.widgets.expressions; +package org.simantics.sysdyn.utils; import java.util.ArrayList; import java.util.Collection; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.LocalResourceManager; -import org.eclipse.swt.graphics.Device; -import org.eclipse.swt.graphics.Image; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -17,7 +13,6 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.Activator; import org.simantics.ui.SimanticsUI; @@ -34,6 +29,12 @@ public class Function implements Comparable{ private final String parameterList; private final String description; + public static class Parameter { + public String name; + public String unit = "1"; + public boolean variableLength = false; + } + public enum Type { USER_DEFINED, SHARED, @@ -43,64 +44,14 @@ public class Function implements Comparable{ VENSIM } - /** - * Get the icon image for each type of Modelica function. - * @param rm LocalResourceManager for which the image is created. - * @param function Modelica function - * @return Image to be shown e.g. in assistive text feed and ShortcutTab - */ - public static Image getImage(LocalResourceManager rm, Function function) { - switch (function.getType()) { - case USER_DEFINED: - return rm.createImage(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/function.png"))); - case SHARED: - return rm.createImage(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/functionLink.png"))); - case VENSIM: - return rm.createImage(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/vensimFunction.png"))); - case SYSDYN: - return rm.createImage(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/sysdynFunction.png"))); - case MODELICA: - return rm.createImage(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/modelicaFunction.png"))); - case MODELICA_ARRAY: - return rm.createImage(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/modelicaArrayFunction.png"))); - default: - return null; - } - } - - /** - * Get the icon image for each type of Modelica function. - * @param device Device for which the image is used. - * @param function Modelica function - * @return Image to be shown e.g. in assistive text feed and ShortcutTab - */ - @Deprecated - public static Image getImage(Device device, Function function) { - switch (function.getType()) { - case USER_DEFINED: - return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/function.png")).createImage(device); - case SHARED: - return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/functionLink.png")).createImage(device); - case VENSIM: - return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/vensimFunction.png")).createImage(device); - case SYSDYN: - return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/sysdynFunction.png")).createImage(device); - case MODELICA: - return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/modelicaFunction.png")).createImage(device); - case MODELICA_ARRAY: - return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/modelicaArrayFunction.png")).createImage(device); - default: - return null; - } - } - - public Function(String name, String parameterList, Type type, String description){ + public Function(String name, ArrayList parameterList, Type type, String description){ this.name = new String(name); this.type = type; - if (parameterList != null) - this.parameterList = new String(parameterList); + String parameterListString = parameterListToString(parameterList); + if (parameterListString != null) + this.parameterList = new String(parameterListString); else this.parameterList = new String(""); @@ -109,6 +60,17 @@ public class Function implements Comparable{ else this.description = null; } + + public static String parameterListToString(ArrayList parameterList) { + String inputStr = null; + for (Parameter p : parameterList) { + if (inputStr == null) + inputStr = new String(p.name); + else + inputStr += ", " + p.name; + } + return inputStr; + } public String getParameterList() { return parameterList; @@ -141,34 +103,33 @@ public class Function implements Comparable{ * @return String in which the paramters are ", " delimited * @throws DatabaseException */ - public static String getFunctionInputs(ReadGraph graph, SysdynResource sr, Resource r) throws DatabaseException { + public static ArrayList getFunctionInputs(ReadGraph graph, SysdynResource sr, Resource r) throws DatabaseException { Resource inputs = graph.getPossibleObject(r, sr.SysdynModelicaFunction_inputs); - String inputStr = null; + ArrayList inputParameters = new ArrayList(); if (inputs != null) { for (Resource input : ListUtils.toList(graph, inputs)) { - String inputName = null; + Parameter inputParameter = new Parameter(); if (graph.isInstanceOf(input, sr.SysdynModelicaFunction_VariableLengthInput)) { - inputName = ""; + inputParameter.name = ""; + inputParameter.variableLength = true; Resource shownLabels = graph.getPossibleObject( input, sr.SysdynModelicaFunction_VariableLengthInput_shownLabels); if (shownLabels != null) { for (Resource label : ListUtils.toList(graph, shownLabels)) { - inputName += NameUtils.getSafeName(graph, label); - inputName += ", "; + inputParameter.name += NameUtils.getSafeName(graph, label); + inputParameter.name += ", "; } } - inputName += "..."; + inputParameter.name += "..."; } else { - inputName = NameUtils.getSafeName(graph, input); + inputParameter.name = NameUtils.getSafeName(graph, input); } - if (inputStr == null) - inputStr = new String(inputName); - else - inputStr += ", " + inputName; + + inputParameters.add(inputParameter); } } - return inputStr; + return inputParameters; } public static String getFunctionDescription(ReadGraph graph, Resource r) throws DatabaseException { @@ -191,9 +152,9 @@ public class Function implements Comparable{ Resource functionLibrary = graph.getPossibleResource(functionTypeUri); for(Resource r : graph.syncRequest(new ObjectsWithType(functionLibrary, l0.ConsistsOf, sr.SysdynModelicaFunction))) { String name = NameUtils.getSafeName(graph, r); - String inputStr = getFunctionInputs(graph, sr, r); + ArrayList inputs = getFunctionInputs(graph, sr, r); String description = getFunctionDescription(graph, r); - functions.add(new Function(name, inputStr, functionType, description)); + functions.add(new Function(name, inputs, functionType, description)); } return functions; }