--- /dev/null
+\r
+L0 = <http://www.simantics.org/Layer0-1.0>\r
+SYSDYN = <http://www.simantics.org/Sysdyn-1.0>\r
+\r
+VF = <http://www.simantics.org/Sysdyn-1.0/Built-in Functions/Vensim Functions> : SYSDYN.SysdynModelicaFunctionLibrary\r
+\r
+/*\r
+VF.DELAYFIXED : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """DELAY FIXED( inputVar , dtime , init )\r
+ -> delay(inputVar, dtime)\r
+ init -value is ignored."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real inputVar;\r
+ input Real dtime;\r
+ input Real init;\r
+ input Real t = time;\r
+ output Real z;\r
+protected\r
+ parameter Real parameterDTime = dtime; \r
+algorithm\r
+ z := if time < parameterDTime then init else delay(inputVar, parameterDTime);"""\r
+*/\r
+ \r
+VF.IFTHENELSE : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """IF THEN ELSE( cond , ontrue , onfalse )\r
+ -> if cond then ontrue else onfalse"""\r
+ SYSDYN.HasModelicaFunctionCode """ input Boolean cond;\r
+ input Real ontrue;\r
+ input Real onfalse;\r
+ output Real z;\r
+algorithm\r
+ z := if cond then ontrue else onfalse;""" \r
+ \r
+VF.MAX : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """MAX(a, b) \r
+ Returns the larger of a and b."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real a;\r
+ input Real b;\r
+ output Real z;\r
+algorithm\r
+ z := if a > b then a else b;""" \r
+ \r
+VF.MIN : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """MIN(a, b) \r
+ Returns the smaller of a and b."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real a;\r
+ input Real b;\r
+ output Real z;\r
+algorithm\r
+ z := if a < b then a else b;""" \r
+ \r
+VF.XIDZ : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """XIDZ(a, b, x)\r
+ x if divided by zero, a/b otherwise."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real a;\r
+ input Real b;\r
+ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := xidz(a, b, x);""" \r
+ \r
+VF.ZIDZ : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """XIDZ(a, b)\r
+ Zero if divided by zero, a/b otherwise."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real a;\r
+ input Real b;\r
+ output Real z;\r
+algorithm\r
+ z := zidz(a, b);""" \r
+ \r
+VF.ABS : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """ABS(x)\r
+ Returns the absolute value of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := abs(x);""" \r
+ \r
+VF.SQRT : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """SQRT(x)\r
+ Returns the square root of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := sqrt(x);""" \r
+ \r
+VF.MODULO : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """MODULO(a, b)\r
+ Returns the remainder when a is divided by b. """\r
+ SYSDYN.HasModelicaFunctionCode """ input Real a;\r
+ input Real b;\r
+ output Real z;\r
+algorithm\r
+ z := mod(a, b);""" \r
+ \r
+VF.PULSE : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """PULSE(start, width)\r
+ Returns 1.0 starting at time start and lasting for interval width. 0.0 is returned at other times."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real start;\r
+ input Real width;\r
+ input Real t = time;\r
+ output Real z; \r
+algorithm\r
+ z := if t >= start and (t - start) <= width then 1.0 else 0.0;""" \r
+ \r
+VF.RAMP : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """RAMP(slope, startTime, endTime) \r
+ Returns 0 until the start time and then slopes upward until end time and then holds constant."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real slope;\r
+ input Real startTime;\r
+ input Real endTime;\r
+ input Real t = time;\r
+ output Real z; \r
+algorithm\r
+ z := \r
+ if t > startTime then\r
+ if t < endTime then \r
+ slope * (t - startTime) \r
+ else\r
+ slope * (endTime - startTime)\r
+ else\r
+ 0;""" \r
+ \r
+VF.STEP : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """STEP(height, stepTime)\r
+ Returns 0.0 until the step time and then returns height."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real height;\r
+ input Real stepTime;\r
+ input Real t = time;\r
+ output Real z;\r
+algorithm\r
+ z := if t >= stepTime then height else 0.0;""" \r
+ \r
+/* Continuous built-in common mathematical functions */\r
+\r
+VF.EXP : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """\r
+ """\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := exp(x);"""\r
+ \r
+VF.SIN : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """SIN(x)\r
+ Returns the sine of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := sin(x);""" \r
+ \r
+VF.SINH : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """SINH(x)\r
+ Returns the hyperbolic sine of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := sinh(x);""" \r
+\r
+VF.COS : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """COS(x)\r
+ Returns the cosine of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := cos(x);""" \r
+ \r
+VF.COSH : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """COSH(x)\r
+ Returns the hyperbolic cosine of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := cosh(x);""" \r
+ \r
+VF.TAN : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """TAN(x)\r
+ Returns the tangent of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := tan(x);""" \r
+ \r
+VF.TANH : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """TANH(x)\r
+ Returns the hyperbolic tangent of x."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := tanh(x);""" \r
+ \r
+VF.LN : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription """LN(x)\r
+ Returns the natural logarithm of x. \r
+ In modelica log(x) is the natural logarighm and log10(x) is base 10 logarighm."""\r
+ SYSDYN.HasModelicaFunctionCode """ input Real x;\r
+ output Real z;\r
+algorithm\r
+ z := log(x);""" \r
+
\ No newline at end of file
public final Resource AuxiliarySymbol;\r
public final Resource BasicExperiment;\r
public final Resource Built$in_Functions;\r
+ public final Resource Built$in_Functions_Vensim_Functions;\r
+ public final Resource Built$in_Functions_Vensim_Functions_ABS;\r
+ public final Resource Built$in_Functions_Vensim_Functions_COS;\r
+ public final Resource Built$in_Functions_Vensim_Functions_COSH;\r
+ public final Resource Built$in_Functions_Vensim_Functions_EXP;\r
+ public final Resource Built$in_Functions_Vensim_Functions_IFTHENELSE;\r
+ public final Resource Built$in_Functions_Vensim_Functions_LN;\r
+ public final Resource Built$in_Functions_Vensim_Functions_MAX;\r
+ public final Resource Built$in_Functions_Vensim_Functions_MIN;\r
+ public final Resource Built$in_Functions_Vensim_Functions_MODULO;\r
+ public final Resource Built$in_Functions_Vensim_Functions_PULSE;\r
+ public final Resource Built$in_Functions_Vensim_Functions_RAMP;\r
+ public final Resource Built$in_Functions_Vensim_Functions_SIN;\r
+ public final Resource Built$in_Functions_Vensim_Functions_SINH;\r
+ public final Resource Built$in_Functions_Vensim_Functions_SQRT;\r
+ public final Resource Built$in_Functions_Vensim_Functions_STEP;\r
+ public final Resource Built$in_Functions_Vensim_Functions_TAN;\r
+ public final Resource Built$in_Functions_Vensim_Functions_TANH;\r
+ public final Resource Built$in_Functions_Vensim_Functions_XIDZ;\r
+ public final Resource Built$in_Functions_Vensim_Functions_ZIDZ;\r
public final Resource Built$in_Functions_interpolate;\r
public final Resource Built$in_Functions_interpolateFull;\r
public final Resource Built$in_Functions_xidz;\r
public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol";\r
public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment";\r
public static final String Built$in_Functions = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions";\r
+ public static final String Built$in_Functions_Vensim_Functions = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions";\r
+ public static final String Built$in_Functions_Vensim_Functions_ABS = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/ABS";\r
+ public static final String Built$in_Functions_Vensim_Functions_COS = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/COS";\r
+ public static final String Built$in_Functions_Vensim_Functions_COSH = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/COSH";\r
+ public static final String Built$in_Functions_Vensim_Functions_EXP = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/EXP";\r
+ public static final String Built$in_Functions_Vensim_Functions_IFTHENELSE = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/IFTHENELSE";\r
+ public static final String Built$in_Functions_Vensim_Functions_LN = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/LN";\r
+ public static final String Built$in_Functions_Vensim_Functions_MAX = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/MAX";\r
+ public static final String Built$in_Functions_Vensim_Functions_MIN = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/MIN";\r
+ public static final String Built$in_Functions_Vensim_Functions_MODULO = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/MODULO";\r
+ public static final String Built$in_Functions_Vensim_Functions_PULSE = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/PULSE";\r
+ public static final String Built$in_Functions_Vensim_Functions_RAMP = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/RAMP";\r
+ public static final String Built$in_Functions_Vensim_Functions_SIN = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/SIN";\r
+ public static final String Built$in_Functions_Vensim_Functions_SINH = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/SINH";\r
+ public static final String Built$in_Functions_Vensim_Functions_SQRT = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/SQRT";\r
+ public static final String Built$in_Functions_Vensim_Functions_STEP = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/STEP";\r
+ public static final String Built$in_Functions_Vensim_Functions_TAN = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/TAN";\r
+ public static final String Built$in_Functions_Vensim_Functions_TANH = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/TANH";\r
+ public static final String Built$in_Functions_Vensim_Functions_XIDZ = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/XIDZ";\r
+ public static final String Built$in_Functions_Vensim_Functions_ZIDZ = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/Vensim+Functions/ZIDZ";\r
public static final String Built$in_Functions_interpolate = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/interpolate";\r
public static final String Built$in_Functions_interpolateFull = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/interpolateFull";\r
public static final String Built$in_Functions_xidz = "http://www.simantics.org/Sysdyn-1.0/Built-in+Functions/xidz";\r
AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol);\r
BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
Built$in_Functions = getResourceOrNull(graph, URIs.Built$in_Functions);\r
+ Built$in_Functions_Vensim_Functions = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions);\r
+ Built$in_Functions_Vensim_Functions_ABS = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_ABS);\r
+ Built$in_Functions_Vensim_Functions_COS = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_COS);\r
+ Built$in_Functions_Vensim_Functions_COSH = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_COSH);\r
+ Built$in_Functions_Vensim_Functions_EXP = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_EXP);\r
+ Built$in_Functions_Vensim_Functions_IFTHENELSE = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_IFTHENELSE);\r
+ Built$in_Functions_Vensim_Functions_LN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_LN);\r
+ Built$in_Functions_Vensim_Functions_MAX = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_MAX);\r
+ Built$in_Functions_Vensim_Functions_MIN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_MIN);\r
+ Built$in_Functions_Vensim_Functions_MODULO = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_MODULO);\r
+ Built$in_Functions_Vensim_Functions_PULSE = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_PULSE);\r
+ Built$in_Functions_Vensim_Functions_RAMP = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_RAMP);\r
+ Built$in_Functions_Vensim_Functions_SIN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_SIN);\r
+ Built$in_Functions_Vensim_Functions_SINH = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_SINH);\r
+ Built$in_Functions_Vensim_Functions_SQRT = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_SQRT);\r
+ Built$in_Functions_Vensim_Functions_STEP = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_STEP);\r
+ Built$in_Functions_Vensim_Functions_TAN = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_TAN);\r
+ Built$in_Functions_Vensim_Functions_TANH = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_TANH);\r
+ Built$in_Functions_Vensim_Functions_XIDZ = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_XIDZ);\r
+ Built$in_Functions_Vensim_Functions_ZIDZ = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_ZIDZ);\r
Built$in_Functions_interpolate = getResourceOrNull(graph, URIs.Built$in_Functions_interpolate);\r
Built$in_Functions_interpolateFull = getResourceOrNull(graph, URIs.Built$in_Functions_interpolateFull);\r
Built$in_Functions_xidz = getResourceOrNull(graph, URIs.Built$in_Functions_xidz);\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
-import java.util.HashSet;\r
-import java.util.Map;\r
\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.scl.runtime.function.Function;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionNode;\r
\r
public class FunctionLibraries extends ViewpointContributor<FunctionsFolder> {\r
\r
- @SuppressWarnings("unchecked")\r
@Override\r
public Collection<?> getContribution(ReadGraph graph, FunctionsFolder functionsFolder)\r
throws DatabaseException {\r
result.add(new FunctionNode(function));\r
}\r
\r
- // Find function libraries in model and sysdyn ontology\r
- Function index = graph.adapt(L0.Dependencies, Function.class);\r
- Collection<Map<String, Object>> results = (Collection<Map<String, Object>>)index.apply(graph, functionsFolder.data, "Types:SysdynModelicaFunctionLibrary");\r
- HashSet<Resource> modelLibraries = new HashSet<Resource>();\r
- for(Map<String, Object> r : results) {\r
- Resource library = (Resource)r.get("Resource");\r
- if(library == null)\r
- continue;\r
- Resource root = graph.getPossibleObject(library, l0.PartOf);\r
- while(!graph.isInstanceOf(root, sr.SysdynModel) && !graph.isInstanceOf(root, l0.Ontology)) {\r
- library = root;\r
- root = graph.getPossibleObject(library, l0.PartOf);\r
+ // Find model function libraries\r
+ for(Resource modelLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
+ new FunctionLibraryNode<Resource>(modelLibrary);\r
+ } \r
+ \r
+ Resource sysdyn = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.0");\r
+ if(sysdyn != null) {\r
+ for(Resource library : graph.syncRequest(new ObjectsWithType(sysdyn, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
+ result.add(new FunctionLibraryNode<Resource>(library));\r
}\r
- \r
- // If the root is not a shared library (it is the model or sysdyn ontology)\r
- if(graph.isInstanceOf(root, sr.SysdynModel))\r
- modelLibraries.add(library);\r
}\r
\r
\r
- for(Resource modelLibrary : modelLibraries) {\r
- result.add(new FunctionLibraryNode<Resource>(modelLibrary));\r
- }\r
- \r
result.add(new SharedFunctionsFolder(functionsFolder.data));\r
\r
return result;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\r
-import org.simantics.db.VirtualGraph;\r
import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.procedure.single.SingleSetSyncListener;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.request.Queries;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.common.utils.OrderedSetUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.GenericRelationIndex;\r
import org.simantics.db.layer0.adapter.RuntimeValuations;\r
import org.simantics.db.layer0.adapter.TrendVariable;\r
import org.simantics.db.layer0.service.ActivationManager;\r
-import org.simantics.db.layer0.util.Simantics;\r
import org.simantics.db.request.Read;\r
import org.simantics.db.service.GraphChangeListenerSupport;\r
import org.simantics.db.service.LifecycleSupport;\r
if(g.isInstanceOf(dep, PROJ.NamespaceRequirement)) {\r
for(Resource req : g.getObjects(dep, PROJ.RequiresNamespace)) {\r
String uri = g.getPossibleValue(req, Bindings.STRING);\r
- System.err.println("dep uri=" + uri);\r
if(uri != null) {\r
Resource target = g.getResource(uri);\r
if(target != null) {\r
\r
\r
\r
- final Layer0 l0 = Layer0.getInstance(session);\r
ActivationManager activationManager = session.getService(ActivationManager.class);\r
if (activationManager != null) {\r
activationManager.activate(session, projectResource);\r
\r
\r
VirtualGraphSupport support = session.getService(VirtualGraphSupport.class);\r
-// final VirtualGraph graph = session.getService(VirtualGraph.class);\r
-\r
-// SysdynResource SYSDYN = SysdynResource.getInstance(session);\r
-// session.asyncRequest(new ObjectsWithType(projectResource, l0.ConsistsOf, SYSDYN.SysdynModel), new SingleSetSyncListener<Resource>() {\r
-//\r
-// @Override\r
-// public void add(ReadGraph g, final Resource model) throws DatabaseException {\r
-// \r
-// GenericRelationIndex index = g.adapt(l0.DependenciesRelation, GenericRelationIndex.class);\r
-// index.trackAndIndex(g.getSession(), model);\r
-// \r
-// // FIXME:\r
-// Simantics.async(new Runnable() {\r
-//\r
-// @Override\r
-// public void run() {\r
-// try {\r
-// // This creates experiment realizations\r
-// graph.register(new HistoryRealizationVirtualGraph(session, model));\r
-// // This creates the BaseRealization\r
-// graph.register(new DefaultRealizationVirtualGraph(session, model));\r
-// } catch (DatabaseException e) {\r
-// e.printStackTrace();\r
-// }\r
-// }\r
-//\r
-// });\r
-// }\r
-//\r
-// @Override\r
-// public void exception(ReadGraph graph, Throwable t) {\r
-// t.printStackTrace();\r
-// }\r
-//\r
-// @Override\r
-// public boolean isDisposed() {\r
-// return false;\r
-// }\r
-//\r
-// });\r
\r
support.getWorkspacePersistent("experiments");\r
\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
SimulationResource simu = SimulationResource.getInstance(graph);\r
\r
- Set<Resource> parents = getParents(graph, model);\r
+ Set<Resource> parents = getParents(graph, model, true);\r
for(Resource parent : parents) {\r
if(graph.isInstanceOf(parent, sr.SysdynModel)) {\r
Resource configuration = graph.getPossibleObject(parent, simu.HasConfiguration);\r
return paths;\r
}\r
\r
- private static Set<Resource> getParents(ReadGraph graph, SysdynModel model) throws DatabaseException{\r
+ private static Set<Resource> getParents(ReadGraph graph, SysdynModel model, boolean onlyWithContent) throws DatabaseException{\r
HashSet<Resource> parents = new HashSet<Resource>();\r
\r
Layer0 l0 = Layer0.getInstance(graph);\r
\r
parents.add(modelResource);\r
\r
- Collection<Resource> sharedOntologies = graph.syncRequest(new ObjectsWithType(\r
- modelResource, l0.IsLinkedTo, sr.SharedFunctionOntology));\r
- parents.addAll(sharedOntologies);\r
+ for(Resource r : graph.getObjects(modelResource, l0.IsLinkedTo)) {\r
+ if(graph.isInstanceOf(r, sr.SharedFunctionOntology)) {\r
+ parents.add(r);\r
+ } else {\r
+ Collection<Resource> libraries = graph.syncRequest(new ObjectsWithType(\r
+ r, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary));\r
+ if(!libraries.isEmpty())\r
+ parents.add(r);\r
+ }\r
+ }\r
+ \r
+ if(onlyWithContent) {\r
+ HashSet<Resource> contentParents = new HashSet<Resource>();\r
+ for(Resource parent : parents) {\r
+ if(hasContent(graph, parent))\r
+ contentParents.add(parent);\r
+ }\r
+ parents = contentParents;\r
+ }\r
\r
return parents;\r
\r
}\r
\r
+ private static boolean hasContent(ReadGraph graph, Resource library) {\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ try {\r
+ if(!graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunction)).isEmpty())\r
+ return true;\r
+ else {\r
+ for(Resource l : graph.syncRequest(new ObjectsWithType(library, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
+ boolean hasContent = hasContent(graph, l);\r
+ if(hasContent)\r
+ return true;\r
+ }\r
+ }\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return false;\r
+ }\r
+ \r
public static void updateFunctionFilesForModel(ReadGraph graph, SysdynModel model) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
\r
- Set<Resource> parents = getParents(graph, model);\r
+ Set<Resource> parents = getParents(graph, model, false);\r
\r
for(Resource parent : parents) {\r
if(graph.isInstanceOf(parent, sr.SysdynModel)) {\r
import org.simantics.sysdyn.mdlImport.mdlElements.EquivalenceSubscript;\r
import org.simantics.sysdyn.mdlImport.mdlElements.Expression;\r
import org.simantics.sysdyn.mdlImport.mdlElements.Flow;\r
+import org.simantics.sysdyn.mdlImport.mdlElements.Function;\r
import org.simantics.sysdyn.mdlImport.mdlElements.Model;\r
import org.simantics.sysdyn.mdlImport.mdlElements.Stock;\r
import org.simantics.sysdyn.mdlImport.mdlElements.Subscript;\r
name =(nameAndData[0].replace("\"", ""));\r
variable = getVariable(model, name);\r
if(variable == null) {\r
- variable = new Auxiliary();\r
+ variable = new Function();\r
variable.setName(name);\r
model.addElement(variable);\r
}\r
DiagramResource dr = DiagramResource.getInstance(graph);\r
StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
\r
- Resource diagram = graph.getSingleObject(configuration, mr.CompositeToDiagram);\r
- \r
- if(diagram == null)\r
+ Resource diagram = graph.getPossibleObject(configuration, mr.CompositeToDiagram);\r
+ Resource startElement = graph.getPossibleObject(start.getResource(), mr.ComponentToElement);\r
+ Resource endElement = graph.getPossibleObject(end.getResource(), mr.ComponentToElement);\r
+ if(diagram == null || startElement == null || endElement == null)\r
return null;\r
\r
+ \r
if(connectionType == null)\r
connectionType = sr.Dependency;\r
\r
\r
\r
// Build diagram connectors and connection\r
- Resource startElement = graph.getSingleObject(start.getResource(), mr.ComponentToElement);\r
Resource tailConnector = GraphUtils.create2(graph, \r
dr.Connector,\r
sr.HasTailTerminal, startElement);\r
\r
- Resource endElement = graph.getSingleObject(end.getResource(), mr.ComponentToElement);\r
Resource headConnector = GraphUtils.create2(graph,\r
dr.Connector,\r
sr.HasHeadTerminal, endElement,\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.mdlImport.mdlElements;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.mdlImport.ImportUtils;\r
+\r
+public class Function extends Variable {\r
+\r
+ @Override\r
+ public void write(WriteGraph graph, Resource parent, double xOffset,\r
+ double yOffset) {\r
+ if(parent == null || graph == null)\r
+ return;\r
+ \r
+ try {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ if(!graph.isInstanceOf(parent, sr.SysdynModel))\r
+ return;\r
+ Layer0 l0 = Layer0.getInstance(graph); \r
+ \r
+ Resource function = GraphUtils.create2(graph, \r
+ sr.SysdynModelicaFunction,\r
+ l0.HasName, ImportUtils.escapeName(this.getName()));\r
+ \r
+ if(comments != null && comments.length() > 0)\r
+ graph.claimLiteral(function, l0.HasDescription, comments);\r
+ \r
+ if(expressions != null && expressions.get(0) != null) {\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(" input Real a;\n");\r
+ sb.append(" output Real result;\n");\r
+ sb.append("algorithm\n");\r
+ sb.append(" result := interpolate(a, " + expressions.get(0).getExpression() + ");");\r
+ graph.claimLiteral(function, sr.HasModelicaFunctionCode, sb.toString());\r
+ }\r
+\r
+ graph.claim(parent, l0.ConsistsOf, function);\r
+ resource = function;\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ \r
+ }\r
+\r
+\r
+}\r
\r
private HashMap<String, Element> elementMap = new HashMap<String, Element>();\r
private ArrayList<Subscript> subscripts = new ArrayList<Subscript>();\r
+ private ArrayList<Function> functions = new ArrayList<Function>();\r
private ArrayList<Connection> connections = new ArrayList<Connection>();\r
private ArrayList<View> views = new ArrayList<View>();\r
private ArrayList<Element> unlocatedElements = new ArrayList<Element>();\r
public void addElement(Element element) {\r
if(element instanceof Subscript)\r
addSubscript((Subscript)element);\r
+ else if(element instanceof Function)\r
+ addFunction((Function)element);\r
else\r
unlocatedElements.add(element);\r
if(element.getName() != null)\r
subscripts.add(subscript);\r
}\r
\r
+ public void addFunction(Function function) {\r
+ functions.add(function);\r
+ }\r
+ \r
public void addElement(View view, Element element) {\r
if(element instanceof Subscript)\r
addSubscript((Subscript)element);\r
\r
// Diagram creation copied from SysdynProject. \r
// Could the same code be reused? \r
+ \r
+ Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.0");\r
+ Resource layer0 = graph.getResource("http://www.simantics.org/Layer0-1.0");\r
+\r
Resource model = GraphUtils.create2(\r
graph,\r
sr.SysdynModel,\r
l0.HasName, getName(),\r
l0.HasLabel, getName(),\r
sr.HasStartTime, startTime,\r
- sr.HasStopTime, endTime \r
+ sr.HasStopTime, endTime,\r
+ l0.IsLinkedTo, sysdyn,\r
+ l0.IsLinkedTo, layer0\r
);\r
\r
Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram);\r
\r
graph.claim(conf, mr.CompositeToDiagram, diagram);\r
graph.claim(model, simu.HasConfiguration, conf);\r
+ graph.claim(model, l0.HasBaseRealization, conf);\r
\r
Resource mapping = graph.newResource();\r
graph.claim(mapping, l0.InstanceOf, null, sr.DiagramToCompositeMapping);\r
for(Connection c : connections) {\r
c.write(graph, conf);\r
}\r
+ \r
+ for(Function f : functions) {\r
+ f.write(graph, model, 0, 0);\r
+ }\r
\r
\r
} catch (DatabaseException e) {\r
}\r
\r
public void addElement(Element e) {\r
+ if(e instanceof Subscript ||\r
+ e instanceof Function)\r
+ return;\r
+ \r
if(e.getX()<minX)\r
minX = e.getX();\r
if(e.getX()>maxX)\r