return realizationURI; \r
}\r
\r
-\r
- public static void writeSVG(org.jfree.chart.JFreeChart chart, Rectangle2D bounds, File file) throws IOException {\r
-\r
+ public static void writeSVG(org.jfree.chart.JFreeChart chart, Rectangle2D bounds, Writer out) throws IOException {\r
// Get a DOMImplementation.\r
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();\r
\r
svgGenerator.setSVGCanvasSize(new Dimension((int)bounds.getWidth(), (int)bounds.getHeight()));\r
chart.draw(svgGenerator, bounds);\r
\r
- // Finally, stream out SVG to the standard output using\r
- // UTF-8 encoding.\r
+ // Finally, write to out\r
+ svgGenerator.stream(out, false);\r
+\r
+ }\r
+\r
+ public static void writeSVG(org.jfree.chart.JFreeChart chart, Rectangle2D bounds, File file) throws IOException {\r
OutputStream outputStream = new FileOutputStream(file);\r
Writer out = new OutputStreamWriter(outputStream, "UTF-8");\r
- svgGenerator.stream(out, false);\r
+ writeSVG(chart, bounds, out);\r
outputStream.flush();\r
- outputStream.close();\r
+ outputStream.close();
}\r
}\r
class="org.simantics.sysdyn.ui.browser.contributions.Charts"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SCLModules"\r
+ preference="2">\r
+ </implementation>\r
</binding>\r
<binding\r
browseContext="http://www.simantics.org/Sysdyn-0.0/AvailableVariableIndexes">\r
class="org.simantics.sysdyn.ui.browser.contributions.ChartsLabeler"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SCLModulesLabeler"\r
+ preference="2">\r
+ </implementation>\r
</binding>\r
<binding\r
browseContext="http://www.simantics.org/Sysdyn-0.0/AvailableVariableIndexes">\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.ModulesNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder;\r
import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionLibraryNode;\r
import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
import org.simantics.sysdyn.ui.browser.nodes.SheetNode;\r
node instanceof ModulesNode || \r
node instanceof FunctionsFolder ||\r
node instanceof FunctionLibraryNode ||\r
+ node instanceof SCLModulesFolder ||\r
node instanceof SharedFunctionLibraryNode)\r
image = "icons/folder.png";\r
else if (node instanceof ModuleTypeNode || node instanceof ModuleNode || node instanceof ConfigurationNode)\r
result.add(new ModulesNode(model.data));\r
result.add(new FunctionsFolder(model.data));\r
result.add(new ChartsFolder(model.data));\r
+// result.add(new SCLModulesFolder(model.data));\r
return result;\r
}\r
\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\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.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.ui.browser.nodes.SCLModule;\r
+import org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder;\r
+\r
+public class SCLModules extends ViewpointContributor<SCLModulesFolder> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, SCLModulesFolder model)\r
+ throws DatabaseException {\r
+\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ Layer0 l0 = Layer0.getInstance(graph);\r
+ \r
+ for(Resource r : graph.syncRequest(new ObjectsWithType(model.data, l0.ConsistsOf, L0.SCLModule))) {\r
+ result.add(new SCLModule(r));\r
+ }\r
+ return result;\r
+\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder;\r
+\r
+public class SCLModulesLabeler extends LabelerContributor<SCLModulesFolder>{\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SCLModulesFolder input) throws DatabaseException {\r
+ return "SCL Modules";\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.Resource;\r
+\r
+public class SCLModule extends AbstractNode<Resource> {\r
+\r
+ public SCLModule(Resource resource) {\r
+ super(resource);\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.Resource;\r
+\r
+public class SCLModulesFolder extends AbstractNode<Resource> {\r
+ \r
+ public SCLModulesFolder(Resource resource) {\r
+ super(resource);\r
+ }\r
+\r
+ @SuppressWarnings("rawtypes")\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if(clazz == adapter) // There is no resource for this node..\r
+ return null;\r
+ return super.getAdapter(adapter);\r
+ }\r
+\r
+}\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
+import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.UnitComboWidget;\r
import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
variability = "";\r
\r
if(variability != null) {\r
+ graph.denyValue(input, sr.Variable_variability);\r
graph.claimLiteral(input, sr.Variable_variability, variability);\r
+ \r
+ Resource conf = graph.getPossibleObject(input, Layer0.getInstance(graph).PartOf);\r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ SysdynModel sm = smm.getModel(graph, conf);\r
+ sm.getMapping().domainModified(input);\r
+ sm.update(graph);\r
+ \r
}\r
}\r
\r
</win>\r
</launcher>\r
\r
-\r
<vm>\r
- <windows include="true">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6</windows>\r
+ <windows include="true">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</windows>\r
</vm>\r
\r
<license>\r
org.simantics.fmu;bundle-version="1.0.0",
org.simantics.fmu.me.win32;bundle-version="1.0.0",
org.simantics.issues;bundle-version="1.1.0",
- org.simantics.issues.common;bundle-version="1.1.0"
+ org.simantics.issues.common;bundle-version="1.1.0",
+ org.simantics.jfreechart;bundle-version="1.0.0",
+ org.jfree.jchart;bundle-version="1.0.13",
+ org.jfree.jcommon;bundle-version="1.0.16"
Export-Package: org.simantics.sysdyn,
org.simantics.sysdyn.adapter,
org.simantics.sysdyn.expressionParser,
<class className="org.simantics.sysdyn.Functions"/>\r
</namespace>\r
</extension>\r
+ <extension\r
+ point="org.simantics.scl.runtime.package">\r
+ <package\r
+ URI="http://www.simantics.org"\r
+ directory="scl">\r
+ </package>\r
+ </extension>\r
\r
</plugin>\r
--- /dev/null
+include "http://www.simantics.org/DB"\r
+include "http://www.simantics.org/Variables"\r
+\r
+importJava "org.simantics.sysdyn.utils.DocumentationUtils" where\r
+\r
+ @JavaName getModules\r
+ getModules :: Variable -> <ReadGraph> [Resource]\r
+\r
+ @JavaName getConfiguration\r
+ getConfiguration :: Resource -> <ReadGraph> Resource\r
+ \r
+ @JavaName getConfigurationVariables\r
+ getConfigurationVariables :: Resource -> <ReadGraph> [Resource]\r
+ \r
+ @JavaName getName\r
+ getName :: Resource -> <ReadGraph> String\r
+ \r
+ @JavaName getType\r
+ getType :: Resource -> <ReadGraph> String\r
+\r
+ @JavaName getUnit\r
+ getUnit :: Resource -> <ReadGraph> String\r
+\r
+ @JavaName getVariability\r
+ getVariability :: Resource -> <ReadGraph> String \r
+ \r
+ @JavaName getDescription\r
+ getDescription :: Resource -> <ReadGraph> String\r
+ \r
+ @JavaName getDocumentationDefinition\r
+ getDocumentationDefinition :: Resource -> <ReadGraph> String\r
+
\ No newline at end of file
import org.simantics.objmap.annotations.RelatedElements;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.representation.expressions.IExpression;\r
+import org.simantics.sysdyn.representation.expressions.StockExpression;\r
import org.simantics.sysdyn.representation.utils.FormatUtils;\r
\r
/**\r
public ArrayList<IElement> getIncomingDependencies() {\r
return isHeadOf;\r
}\r
+ \r
+ @Override\r
+ public String getDocumentationDefinition() {\r
+ String declaration = getDeclaration();\r
+ String initialEquation = getInitialEquation();\r
+ \r
+ StringBuilder result = new StringBuilder();\r
+ \r
+ if(declaration != null && declaration.length() > 0 && declaration.contains("=")) {\r
+ result.append("<p>");\r
+ if(getExpressions().size() > 1)\r
+ result.append(formatForHTML(declaration));\r
+ else\r
+ result.append(formatForHTML(declaration.substring(declaration.indexOf("=") + 1)));\r
+ result.append("</p>");\r
+ }\r
+ \r
+ if(initialEquation != null && initialEquation.length() > 0) {\r
+ result.append("<p>");\r
+ if(getExpressions().size() > 1)\r
+ result.append(formatForHTML(initialEquation));\r
+ else\r
+ result.append(formatForHTML(initialEquation.substring(initialEquation.indexOf("=") + 1)));\r
+ result.append("</p>");\r
+ }\r
+ \r
+ result.append("<p>");\r
+ for(IExpression exp : getExpressions()) {\r
+ String expression = exp.getDocumentationExpression();\r
+ if(!(exp instanceof StockExpression))\r
+ expression = expression.substring(expression.indexOf("=") + 1);\r
+ result.append(formatForHTML(expression));\r
+ }\r
+ result.append("</p>");\r
+ \r
+ result.append(super.getDocumentationDefinition());\r
+ \r
+ return result.toString();\r
+ }\r
+ \r
+ private String formatForHTML(String text) {\r
+ text = text.replaceAll("\\r\\n|\\r|\\n", "<br/>");\r
+ return text.trim();\r
+ }\r
}\r
boolean continuous = variability == null || variability.isEmpty();\r
return " " + (continuous ? "" : variability + " ") + getType() + " " + getName() + range + ";\n";\r
}\r
+ \r
+ @Override\r
+ public String getDocumentationDefinition() {\r
+ String expression = getDefaultInputValue() + "// Default value";\r
+\r
+ if(isHeadOf.size() > 0 && isHeadOf.get(0) instanceof Dependency) {\r
+ Dependency dependency = (Dependency) isHeadOf.get(0);\r
+ Module module = (Module)dependency.getTail();\r
+ Variable reference = (Variable)dependency.refersTo();\r
+ // If reference exists, use reference name. Otherwise, use default value.\r
+ if(reference != null && reference.getName() != null)\r
+ expression = module.getName() + "." + reference.getName() + ";\n";\r
+ }\r
+ \r
+ return expression + super.getDocumentationDefinition();\r
+ }\r
}\r
}\r
\r
\r
+ \r
+ public String getDocumentationDefinition() {\r
+ String enumerationRedeclarations = getEnumerationRedeclarations();\r
+ String parameterOverrides = getParameterOverrideString();\r
+ \r
+ StringBuilder result = new StringBuilder();\r
+ \r
+ String[] erecs = enumerationRedeclarations.split(",");\r
+ boolean first = true;\r
+ for(String s : erecs) {\r
+ if(s.length() == 0)\r
+ continue;\r
+ \r
+ if(first) {\r
+ result.append("<br/>");\r
+ result.append("Enumeration redeclarations:");\r
+ result.append("<br/>");\r
+ }\r
+ first = false;\r
+ result.append(s.trim());\r
+ result.append("<br/>");\r
+ }\r
+ \r
+ \r
+ first = true;\r
+ String[] poverrds = parameterOverrides.split(",");\r
+ for(String s : poverrds) {\r
+ if(s.length() == 0)\r
+ continue;\r
+\r
+ if(first) {\r
+ result.append("<br/>");\r
+ result.append("Parameter overrides:");\r
+ result.append("<br/>");\r
+ }\r
+ first = false;\r
+ result.append(s.trim());\r
+ result.append("<br/>");\r
+ }\r
+ first = true;\r
+ \r
+ \r
+ return result.toString();\r
+ }\r
}\r
@RelatedValue(SysdynResource.URIs.Variable_unit)\r
protected String unit;\r
\r
+ @RelatedValue(Layer0.URIs.HasDescription)\r
+ protected String description;\r
+ \r
+ @RelatedElement(SysdynResource.URIs.IsOutput)\r
+ protected IElement isOutput; \r
+ \r
/**\r
* Return the variability of this variable (Used in practice only with Input variables)\r
* @return Variability\r
return this.unit;\r
}\r
\r
+ /**\r
+ * Get description\r
+ * @return description\r
+ */\r
+ public String getDescription() {\r
+ if(description == null)\r
+ return "";\r
+ else \r
+ return description;\r
+ }\r
+ \r
+ public boolean isOutput() {\r
+ return !(isOutput == null);\r
+ }\r
+ \r
+ /**\r
+ * Get definition for documentation.\r
+ * \r
+ * For independent variables this is the equations\r
+ * For enumerations this is the indexes\r
+ * etc.\r
+ * @return\r
+ */\r
+ public String getDocumentationDefinition() {\r
+ if(isOutput())\r
+ return "<br />Is output";\r
+ else\r
+ return "";\r
+ }\r
+ \r
}\r
public IndependentVariable getParent() {\r
return parent;\r
}\r
+ \r
+ @Override\r
+ public String getDocumentationExpression() {\r
+ return getEquation();\r
+ }\r
}\r
* @return owner of this expression\r
*/\r
IndependentVariable getParent();\r
+ \r
+ \r
+ /**\r
+ * Get the representation of this expression to web documentation\r
+ * @return\r
+ */\r
+ String getDocumentationExpression();\r
}\r
*******************************************************************************/\r
package org.simantics.sysdyn.representation.expressions;\r
\r
+import java.awt.geom.Rectangle2D;\r
+import java.io.IOException;\r
+import java.io.StringWriter;\r
+\r
+import org.jfree.chart.ChartFactory;\r
+import org.jfree.chart.JFreeChart;\r
+import org.jfree.chart.plot.PlotOrientation;\r
+import org.jfree.data.xy.DefaultXYDataset;\r
import org.simantics.db.ReadGraph;\r
+import org.simantics.jfreechart.chart.ChartUtils;\r
import org.simantics.objmap.annotations.GraphType;\r
import org.simantics.objmap.annotations.RelatedValue;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
return result;\r
}\r
+ \r
+ @Override\r
+ public String getDocumentationExpression() {\r
+ String expression = super.getDocumentationExpression();\r
+ \r
+ // assume lookup table has format: {{1,2},{3,4}}\r
+ String table = lookupTable;\r
+ table = table.replace("{", "");\r
+ table = table.replace("}", "");\r
+ String[] split = table.split(",");\r
+ double[] x = new double[split.length / 2];\r
+ double[] y = new double[split.length / 2];\r
+ \r
+ try {\r
+ for(int i = 0; i < split.length / 2; i++) {\r
+ x[i] = Double.parseDouble(split[i*2]);\r
+ y[i] = Double.parseDouble(split[i*2+1]);\r
+ }\r
+ \r
+ DefaultXYDataset dataset = new DefaultXYDataset();\r
+ dataset.addSeries("lookup", new double[][] {y, x});\r
+ JFreeChart chart = ChartFactory.createXYLineChart(\r
+ "", // chart title\r
+ "", // domain axis label\r
+ "", // range axis label\r
+ dataset, // data\r
+ PlotOrientation.HORIZONTAL, // Orientation\r
+ false, // include legend\r
+ false, // tooltips\r
+ false // urls\r
+ );\r
+ \r
+ StringWriter writer = new StringWriter();\r
+ ChartUtils.writeSVG(chart, new Rectangle2D.Double(0, 0, 200, 100), writer);\r
+ writer.flush();\r
+ String svg = writer.toString();\r
+ writer.close();\r
+ svg = svg.substring(svg.indexOf("<svg"));\r
+ svg = svg.replaceAll("[\r\n]+", "");\r
+ expression = expression + "<div>" + svg + "</div>";\r
+ } catch (NumberFormatException e) {\r
+ \r
+ } catch (IOException e) {\r
+ }\r
+ \r
+ return expression;\r
+ }\r
}\r
--- /dev/null
+package org.simantics.sysdyn.utils;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithSupertype;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
+import org.simantics.sysdyn.manager.SysdynModelManager;\r
+import org.simantics.sysdyn.representation.Book;\r
+import org.simantics.sysdyn.representation.Enumeration;\r
+import org.simantics.sysdyn.representation.IElement;\r
+import org.simantics.sysdyn.representation.IndependentVariable;\r
+import org.simantics.sysdyn.representation.Module;\r
+import org.simantics.sysdyn.representation.Variability;\r
+import org.simantics.sysdyn.representation.Variable;\r
+\r
+public class DocumentationUtils {\r
+ \r
+ public static List<Resource> getModules(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ Resource modelResource = model.getRepresents(graph);\r
+ \r
+ ArrayList<Resource> result = new ArrayList<Resource>();\r
+ \r
+ if(graph.isInstanceOf(modelResource, SR.SysdynModel)) {\r
+ result.add(modelResource);\r
+ result.addAll(graph.syncRequest(new ObjectsWithSupertype(modelResource, Layer0.getInstance(graph).ConsistsOf, SR.Module))); \r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
+ public static Resource getConfiguration(ReadGraph graph, Resource module) throws DatabaseException {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ \r
+ if(graph.isInstanceOf(module, SR.SysdynModel)) {\r
+ return graph.getSingleObject(module, SimulationResource.getInstance(graph).HasConfiguration);\r
+ } else if(graph.isInheritedFrom(module, SR.Module)) {\r
+ return graph.getSingleObject(module, StructuralResource2.getInstance(graph).IsDefinedBy);\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+ \r
+ public static List<Resource> getConfigurationVariables(ReadGraph graph, Resource configuration) throws DatabaseException {\r
+ \r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ SysdynModel sm = smm.getModel(graph, configuration);\r
+ \r
+ ArrayList<Resource> result = new ArrayList<Resource>();\r
+ for(IElement element : sm.getConfiguration().getElements()) {\r
+ if((element instanceof Variable || element instanceof Module) && !(element instanceof Book)) {\r
+ result.add(sm.getMapping().inverseGet(element));\r
+ }\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
+ public static String getName(ReadGraph graph, Resource variable) throws DatabaseException {\r
+ \r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable));\r
+ SysdynModel sm = smm.getModel(graph,configuration);\r
+ \r
+ IElement element = sm.getElement(variable);\r
+ \r
+ if(element instanceof Variable) {\r
+ Variable v = (Variable) element;\r
+ \r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append(v.getName());\r
+ \r
+ \r
+ if(v.getArrayIndexes() != null && v.getArrayIndexes().size() > 0) {\r
+ sb.append("[");\r
+ boolean first = true;\r
+ for(Enumeration e : v.getArrayIndexes()) {\r
+ if(!first)\r
+ sb.append(", ");\r
+ first = false;\r
+ sb.append(e.getName());\r
+ }\r
+ \r
+ sb.append("]");\r
+ }\r
+ \r
+ return sb.toString();\r
+ } \r
+ \r
+ if(element instanceof Module) {\r
+ Module m = (Module) element;\r
+ return m.getName();\r
+ }\r
+ \r
+ return "";\r
+ }\r
+ \r
+ public static String getType(ReadGraph graph, Resource variable) throws DatabaseException {\r
+ \r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable));\r
+ SysdynModel sm = smm.getModel(graph,configuration);\r
+ \r
+ IElement element = sm.getElement(variable);\r
+ \r
+ if(element instanceof Variable) {\r
+ String result = ((Variable)element).getType();\r
+ if(result == null)\r
+ return "";\r
+ else\r
+ return element.getClass().getSimpleName() + " " + result;\r
+ }\r
+ \r
+ if(element instanceof Module) {\r
+ Module m = (Module) element;\r
+ return m.getType().getName();\r
+ }\r
+ \r
+ return "";\r
+ }\r
+ \r
+ public static String getUnit(ReadGraph graph, Resource variable) throws DatabaseException {\r
+ \r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable));\r
+ SysdynModel sm = smm.getModel(graph,configuration);\r
+ \r
+ IElement element = sm.getElement(variable);\r
+ \r
+ if(element instanceof Variable) {\r
+ String result = ((Variable)element).getUnit();\r
+ if(result == null)\r
+ return "";\r
+ else\r
+ return result;\r
+ }\r
+ \r
+ return "";\r
+ }\r
+ \r
+ \r
+ public static String getVariability(ReadGraph graph, Resource variable) throws DatabaseException {\r
+ \r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable));\r
+ SysdynModel sm = smm.getModel(graph,configuration);\r
+ \r
+ IElement element = sm.getElement(variable);\r
+ \r
+ if(element instanceof IndependentVariable) {\r
+ Variability variability = Variability.getVariability((IndependentVariable)element);\r
+ if(variability == Variability.CONTINUOUS)\r
+ return "";\r
+ return variability.toString().toLowerCase();\r
+ }\r
+ if(element instanceof Variable) {\r
+ String result = ((Variable)element).getVariability();\r
+ if(result == null)\r
+ return "";\r
+ else {\r
+ return result;\r
+ }\r
+ }\r
+ \r
+ return "";\r
+ }\r
+ \r
+ public static String getDescription(ReadGraph graph, Resource variable) throws DatabaseException {\r
+ \r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable));\r
+ SysdynModel sm = smm.getModel(graph,configuration);\r
+ \r
+ IElement element = sm.getElement(variable);\r
+ \r
+ if(element instanceof Variable) {\r
+ String result = ((Variable)element).getDescription();\r
+ if(result == null)\r
+ return "";\r
+ else\r
+ return result;\r
+ }\r
+ \r
+ return "";\r
+ }\r
+ \r
+ \r
+ public static String getDocumentationDefinition(ReadGraph graph, Resource variable) throws DatabaseException {\r
+ \r
+ SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+ Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable));\r
+ SysdynModel sm = smm.getModel(graph,configuration);\r
+ \r
+ IElement element = sm.getElement(variable);\r
+ \r
+ if(element instanceof Variable) {\r
+ Variable v = (Variable) element;\r
+ String result = v.getDocumentationDefinition();\r
+ if(result == null)\r
+ return "";\r
+ else\r
+ return result;\r
+ }\r
+ \r
+ if(element instanceof Module) {\r
+ Module m = (Module) element;\r
+ return m.getDocumentationDefinition();\r
+ // Print interface variables and parameter overrides\r
+ }\r
+ \r
+ return "";\r
+ \r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.utils;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class GetConfigurationRequest implements Read<Resource> {\r
+ \r
+ private Resource resource;\r
+ \r
+ public GetConfigurationRequest(Resource resource) {\r
+ this.resource = resource;\r
+ }\r
+\r
+ @Override\r
+ public Resource perform(ReadGraph graph) throws DatabaseException {\r
+ return getConfiguration(graph, resource);\r
+ }\r
+ \r
+ private Resource getConfiguration(ReadGraph graph, Resource resource) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource parent = graph.getPossibleObject(resource, L0.PartOf);\r
+ if(parent == null)\r
+ return null;\r
+ \r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ if(graph.isInstanceOf(parent, SR.SysdynModel)) {\r
+ parent = graph.getPossibleObject(parent, SimulationResource.getInstance(graph).HasConfiguration);\r
+ }\r
+ \r
+ if(graph.isInstanceOf(parent, SR.Configuration)) {\r
+ return parent;\r
+ }\r
+ \r
+ else\r
+ return getConfiguration(graph, parent);\r
+ }\r
+}\r