\r
FL = <http://www.simantics.org/Sysdyn-1.1/Built-in Functions> : SYSDYN.SysdynModelicaFunctionLibrary\r
\r
+FL.minmax : SYSDYN.SysdynModelicaFunction\r
+ L0.HasDescription "Limits the result of an equation to between the given minimum and maximum values."\r
+ SYSDYN.SysdynModelicaFunction.modelicaFunctionCode """ input Real expression;\r
+ input Real minimum;\r
+ input Real maximum;\r
+ output Real result;\r
+algorithm\r
+ result := min(maximum, max(minimum, expression));"""\r
+\r
\r
FL.xidz : SYSDYN.SysdynModelicaFunction\r
L0.HasDescription "X if divided by zero"\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_minmax;\r
public final Resource Built$in_Functions_xidz;\r
public final Resource Built$in_Functions_zidz;\r
public final Resource Center;\r
public static final String Built$in_Functions_Vensim_Functions_ZIDZ = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/ZIDZ";\r
public static final String Built$in_Functions_interpolate = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/interpolate";\r
public static final String Built$in_Functions_interpolateFull = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/interpolateFull";\r
+ public static final String Built$in_Functions_minmax = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/minmax";\r
public static final String Built$in_Functions_xidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/xidz";\r
public static final String Built$in_Functions_zidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/zidz";\r
public static final String Center = "http://www.simantics.org/Sysdyn-1.1/Center";\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_minmax = getResourceOrNull(graph, URIs.Built$in_Functions_minmax);\r
Built$in_Functions_xidz = getResourceOrNull(graph, URIs.Built$in_Functions_xidz);\r
Built$in_Functions_zidz = getResourceOrNull(graph, URIs.Built$in_Functions_zidz);\r
Center = getResourceOrNull(graph, URIs.Center);\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.TreeMap;\r
\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ui.modelBrowser2.model.SheetsNode;\r
import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
\r
public class Configuration extends ViewpointContributor<ConfigurationNode<Resource>> {\r
\r
}\r
\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
- ArrayList<Variable> variables = new ArrayList<Variable>();\r
- ArrayList<Variable> inputs = new ArrayList<Variable>();\r
- ArrayList<Variable> modules = new ArrayList<Variable>();\r
- ArrayList<Variable> enumerations = new ArrayList<Variable>();\r
+ TreeMap<String, Variable> variables = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+ TreeMap<String, Variable> inputs = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+ TreeMap<String, Variable> modules = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+ TreeMap<String, Variable> enumerations = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+\r
\r
for(Variable child : variable.browseChildren(graph)) {\r
Resource represents = (Resource)child.getPropertyValue(graph, Variables.REPRESENTS);\r
if(graph.isInstanceOf(represents, sr.IndependentVariable)) {\r
- variables.add(child);\r
+ variables.put(child.getName(graph), child);\r
} else if (graph.isInstanceOf(represents, sr.Input)) {\r
- inputs.add(child);\r
+ inputs.put(child.getName(graph), child);\r
} else if (graph.isInstanceOf(represents, sr.Module)) {\r
- modules.add(child);\r
+ modules.put(child.getName(graph), child);\r
} else if (graph.isInstanceOf(represents, sr.Enumeration)) {\r
- enumerations.add(child);\r
+ enumerations.put(child.getName(graph), child);\r
}\r
}\r
\r
- for (Variable v : variables) {\r
+ for (String s : variables.keySet()) {\r
+ Variable v = variables.get(s);\r
Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
result.add(new VariableNode<Variable>(v, represents));\r
}\r
- for (Variable v : inputs) {\r
+ \r
+ for (String s : inputs.keySet()) {\r
+ Variable v = inputs.get(s);\r
Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
result.add(new InputNode(v, represents));\r
}\r
- for (Variable v : modules) { \r
+ \r
+ for (String s : modules.keySet()) {\r
+ Variable v = modules.get(s);\r
Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
result.add(new ModuleNode(v, represents));\r
}\r
- for (Variable v : enumerations) {\r
+ \r
+ for (String s : enumerations.keySet()) {\r
+ Variable v = enumerations.get(s);\r
Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
result.add(new EnumerationNode(v, represents));\r
}\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.TreeMap;\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.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionNode;\r
import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
\r
public class FunctionLibraries extends ViewpointContributor<FunctionsFolder> {\r
\r
\r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
\r
- // Find model functions\r
+ TreeMap<String, Resource> sortResult = new TreeMap<String, Resource>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+ // Find and sort model functions\r
for(Resource function : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunction))) {\r
- result.add(new FunctionNode(function));\r
+ sortResult.put(NameUtils.getSafeName(graph, function), function);\r
}\r
+ for(Resource function : sortResult.values())\r
+ result.add(new FunctionNode(function));\r
\r
- // Find model function libraries\r
+ // Find and sort model function libraries\r
+ sortResult.clear();\r
for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
- result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
- } \r
- \r
+ sortResult.put(NameUtils.getSafeName(graph, functionLibrary), functionLibrary);\r
+ }\r
+ for(Resource functionLibrary : sortResult.values())\r
+ result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
+ \r
+ // Find built-in functions\r
Resource sysdyn = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.1");\r
if(sysdyn != null) {\r
for(Resource library : graph.syncRequest(new ObjectsWithType(sysdyn, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.TreeMap;\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.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\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
+import org.simantics.utils.strings.AlphanumComparator;\r
\r
public class LibraryFunctions extends ViewpointContributor<FunctionLibraryNode<Resource>> {\r
\r
FunctionLibraryNode<Resource> library) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(graph);\r
ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ \r
+ TreeMap<String, Resource> sortResult = new TreeMap<String, Resource>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+\r
+ // Find and sort functions in library\r
for(Resource function : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunction))) {\r
- result.add(new FunctionNode(function));\r
+ sortResult.put(NameUtils.getSafeName(graph, function), function);\r
}\r
+ for(Resource function : sortResult.values())\r
+ result.add(new FunctionNode(function));\r
+\r
+ // Find and sort libraries in library\r
+ sortResult.clear();\r
for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary))) {\r
- result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
+ sortResult.put(NameUtils.getSafeName(graph, functionLibrary), functionLibrary);\r
}\r
+ for(Resource functionLibrary : sortResult.values())\r
+ result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
+ \r
return result;\r
\r
}\r
-\r
+ \r
@Override\r
public String getViewpointId() {\r
return "Standard";\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.TreeMap;\r
\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
\r
public class ModuleType extends ViewpointContributor<ModuleTypeNode> {\r
\r
\r
if(instance == null) return result;\r
Resource conf = graph.getSingleObject(instance, str.IsDefinedBy);\r
+ \r
+ // Independent variables\r
+ TreeMap<String, Resource> variables = new TreeMap<String, Resource>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.IndependentVariable))) {\r
- result.add(new VariableNode<Resource>(r));\r
+ variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
}\r
+ for(String key : variables.keySet())\r
+ result.add(new VariableNode<Resource>(variables.get(key)));\r
+ \r
+ // Inputs\r
+ variables.clear();\r
for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Input))) {\r
- result.add(new InputNode(r));\r
+ variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
}\r
+ for(String key : variables.keySet())\r
+ result.add(new InputNode(variables.get(key)));\r
+ \r
+ // Modules\r
+ variables.clear();\r
for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Module))) {\r
- result.add(new ModuleNode(r));\r
+ variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
}\r
+ for(String key : variables.keySet())\r
+ result.add(new ModuleNode(variables.get(key)));\r
+ \r
+ // Enumerations\r
+ variables.clear();\r
for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Enumeration))) {\r
- result.add(new EnumerationNode(r));\r
+ variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
}\r
+ for(String key : variables.keySet())\r
+ result.add(new EnumerationNode(variables.get(key)));\r
+ \r
return result;\r
}\r
\r
import org.simantics.graphviz.Graph;\r
import org.simantics.graphviz.Node;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
/**\r
// Model root was not found, return empty graph\r
if(model == null)\r
return g;\r
+ \r
+ // Find the parent module/model of the selected resource\r
+ Resource parentResource = graph.getPossibleObject(resource, l0.PartOf);\r
+ if(graph.isInstanceOf(parentResource, sr.ConfigurationDiagram)) {\r
+ parentResource = graph.getPossibleObject(parentResource, ModelingResources.getInstance(graph).DiagramToComposite);\r
+ } else if(graph.isInstanceOf(parentResource, sr.SysdynModel)) {\r
+ parentResource = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
+ }\r
\r
// Set root node\r
Node rootNode = new Node(g, NameUtils.getSafeLabel(graph, model));\r
rootNode.setShape("rectangle");\r
HashSet<Resource> visited = new HashSet<Resource>();\r
visited.add(model);\r
- findChildModules(g, rootNode, graph, model, visited);\r
+ findChildModules(g, rootNode, graph, model, parentResource, visited);\r
\r
\r
return g;\r
* @param parent Parent module or model\r
* @param graph ReadGraph\r
* @param resource Module type or model\r
+ * @param parent2 \r
* @param visited All visited modules. Needed to check for loops in the structure. Loops are not allowed.\r
* @throws DatabaseException\r
*/\r
- private void findChildModules(Graph g, Node parent, ReadGraph graph, Resource resource, HashSet<Resource> visited) throws DatabaseException {\r
+ private void findChildModules(Graph g, Node parent, ReadGraph graph, Resource resource, Resource parentResource, HashSet<Resource> visited) throws DatabaseException {\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 l0 = Layer0.getInstance(graph);\r
\r
+ Resource configuration = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, sr.Configuration));\r
+\r
+ // Set the parent color different, if it is the parent of the selected resource\r
+ if(configuration.equals(parentResource))\r
+ parent.setColor("#ff8c00");\r
+ \r
HashMap<Resource, Integer> modules = new HashMap<Resource, Integer>();\r
\r
// Find all module children\r
- Resource configuration = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, sr.Configuration));\r
for(Resource m : graph.getObjects(configuration, l0.ConsistsOf)) {\r
Resource type = graph.getPossibleObject(m, l0.InstanceOf);\r
if(graph.isInheritedFrom(type, sr.Module)) {\r
node.setFontColor("#FF0000");\r
continue;\r
} else {\r
- visited.add(type);\r
- findChildModules(g, node, graph, type, visited);\r
+ HashSet<Resource> copy = new HashSet<Resource>(visited);\r
+ copy.add(type);\r
+ findChildModules(g, node, graph, type, parentResource, copy);\r
}\r
\r
}\r
protected static SimulationLocation createSimulationFiles(SysdynModel sysdynModel, String modelText, HashMap<String, String> inits, String additionalScript, boolean fmu) throws IOException {\r
return ModelicaManager.createSimulationFiles(\r
sysdynModel.getSimulationDir(),\r
- sysdynModel.getConfiguration().getName(),\r
+ sysdynModel.getConfiguration().getLabel(),\r
modelText,\r
inits,\r
additionalScript,\r
for(int k = 0; k < subscription.length; k++) {\r
SysdynGameExperiment.this.results.get(subscription[k]).add(results[k]);\r
}\r
+ } else {\r
+ monitor.worked(1);\r
}\r
stepNumber++;\r
monitor.worked(1);\r
e.printStackTrace();\r
}\r
\r
- // Add the current result if there is one\r
- if(getSysdynResult() != null)\r
- activeResults.add(0, getSysdynResult() );\r
-\r
return activeResults;\r
}\r
\r
\r
@Override\r
public void execute(ArrayList<SysdynResult> result) {\r
+ // Add the current result if there is one\r
+ if(result != null && getSysdynResult() != null)\r
+ result.add(0, getSysdynResult() );\r
+ \r
activeResults = result;\r
resultChanged();\r
}\r
public File getSimulationDir() {\r
if(simulationDir == null) {\r
File modelsDir = Activator.getBundleContext().getDataFile("models");\r
- String configName = configuration.getName();\r
+ String configName = configuration.getLabel();\r
List<String> files = Arrays.asList(modelsDir.list());\r
if (files.contains(configName)) {\r
int i = 2;\r
\r
// If the configuration is model configuration, use model name. Otherwise, use configuration name.\r
ModuleType mt = configuration.getModuleType();\r
- String className = mt != null ? (mt.getName().replace(" ", "")) : (configuration.getName().replace(" ", ""));\r
+ String className = mt != null ? (mt.getName().replace(" ", "")) : (configuration.getLabel().replace(" ", ""));\r
\r
b.append("class ").append(className);\r
\r
}\r
\r
public String getLabel() {\r
- return label;\r
+ return label != null ? label : name;\r
}\r
\r
public ModuleType getModuleType() {\r
import org.simantics.sysdyn.representation.IndependentVariable;\r
import org.simantics.sysdyn.representation.utils.FormatUtils;\r
import org.simantics.sysdyn.representation.utils.IndexUtils;\r
+import org.simantics.sysdyn.representation.utils.SheetFormatUtils;\r
\r
/**\r
* Representation of a withlookup expression\r
String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange());\r
\r
return \r
- " " + variable.getName() + (range.equals("[:]") ? "" : range) + " = interpolate(" + equation + ", " + lookupTable + ");\n";\r
+ " " + variable.getName() + (range.equals("[:]") ? "" : range) + " = interpolate(" + equation + ", " + SheetFormatUtils.reformatSheetReferences(variable, lookupTable) + ");\n";\r
}\r
\r
@Override\r
IModelicaMonitor monitor;\r
\r
public SimulationJob(SysdynModel model, Experiment experiment) {\r
- super("Simulate " + model.getConfiguration().getName());\r
+ super("Simulate " + model.getConfiguration().getLabel());\r
this.model = model;\r
this.experiment = experiment;\r
if(PlatformUI.isWorkbenchRunning()) {\r
\r
@Override\r
protected IStatus run(IProgressMonitor monitor) {\r
- monitor.beginTask("Simulate " + model.getConfiguration().getName(), 5); \r
- this.monitor.message("Simulate " + model.getConfiguration().getName());\r
+ monitor.beginTask("Simulate " + model.getConfiguration().getLabel(), 5); \r
+ this.monitor.message("Simulate " + model.getConfiguration().getLabel());\r
try {\r
model.update();\r
if(experiment instanceof SysdynExperiment)\r