]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Created methods for getting readable documentation definitions from variables and...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 2 Jul 2013 11:26:11 +0000 (11:26 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 2 Jul 2013 11:26:11 +0000 (11:26 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27672 ac1ea38d-2e2b-0410-8846-a27921b304fc

22 files changed:
org.simantics.jfreechart/src/org/simantics/jfreechart/chart/ChartUtils.java
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/AbstractNodeImager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SCLModules.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SCLModulesLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModulesFolder.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java
org.simantics.sysdyn.ui/sysdyn.product
org.simantics.sysdyn/META-INF/MANIFEST.MF
org.simantics.sysdyn/plugin.xml
org.simantics.sysdyn/scl/Sysdyn.scl [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/utils/GetConfigurationRequest.java [new file with mode: 0644]

index 78b36e6289d0874e833c4c515fd70ce94cadcbf6..94eb56dacc87e342d36a57cbcbc70c8a0e71d17e 100644 (file)
@@ -163,9 +163,7 @@ public class ChartUtils {
         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
@@ -179,12 +177,16 @@ public class ChartUtils {
         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
index 2dea0afb622848bdc522452f205ba2cce4a5a606..32671a806b3e8af1b1bcd1aba14da93298102f15 100644 (file)
                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
index 919b02d1572b54cd16ad0d10bb710cd13de64dc6..89b3c7aa98f255de44c42801b57c990f3eb73707 100644 (file)
@@ -43,6 +43,7 @@ import org.simantics.sysdyn.ui.browser.nodes.ModelNode;
 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
@@ -66,6 +67,7 @@ public class AbstractNodeImager extends ImagerContributor<AbstractNode<Resource>
                 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
index 01c21fb1218468f7e9cc330598fc7842ee87b1e7..1f0a44588133159e736664185c8a0ad140ed192b 100644 (file)
@@ -56,6 +56,7 @@ public class Model  extends ViewpointContributor<ModelNode> {
         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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SCLModules.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SCLModules.java
new file mode 100644 (file)
index 0000000..c08691e
--- /dev/null
@@ -0,0 +1,37 @@
+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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SCLModulesLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SCLModulesLabeler.java
new file mode 100644 (file)
index 0000000..01e1b05
--- /dev/null
@@ -0,0 +1,14 @@
+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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModule.java
new file mode 100644 (file)
index 0000000..689d51f
--- /dev/null
@@ -0,0 +1,12 @@
+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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModulesFolder.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SCLModulesFolder.java
new file mode 100644 (file)
index 0000000..8fd7b35
--- /dev/null
@@ -0,0 +1,20 @@
+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
index 5cccc1915afa338db88be54dd6a4c4d3c9765add..19146ffabece0bd269e8d53fae649b0e06209f79 100644 (file)
@@ -34,6 +34,8 @@ import org.simantics.db.exception.DatabaseException;
 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
@@ -148,7 +150,15 @@ public class InputVariableTab  extends LabelPropertyTabContributor {
                     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
index 2a0177f15ea586b2bb3a7f271f736de2704935fd..0ce6f714ac63d3eb5c259a1bddfec1fc4e3ad8a7 100644 (file)
@@ -31,9 +31,8 @@
       </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
index ce2df41dc83858c80f54c5314da3c8207fb67840..564a20ba854a6078ad72ba32d9c2c78b8a12417c 100644 (file)
@@ -29,7 +29,10 @@ Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
  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,
index 965913cefd117665c61ceed10b5ca0cf646eae46..711fcb7e7fc9ef0184eefa41be42d01c24ea06af 100644 (file)
          <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
diff --git a/org.simantics.sysdyn/scl/Sysdyn.scl b/org.simantics.sysdyn/scl/Sysdyn.scl
new file mode 100644 (file)
index 0000000..31d2dec
--- /dev/null
@@ -0,0 +1,32 @@
+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
index ef85624930deaaad53404ef1a99d7c3e1834cb1f..bf050c72da54268d747f96dd56fce55ea3944242 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Iterator;
 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
@@ -154,4 +155,48 @@ public abstract class IndependentVariable extends Variable {
     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
index 97de3b0f7f9d0b4e397f709cc08c41d0dfeb2dea..05227bc37d88f6aa877b6f7613951970c22a4f84 100644 (file)
@@ -120,4 +120,20 @@ public class Input extends Variable {
        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
index 9d55df020b766710e266880ebd25a293fc9feda2..1ff935eb4bc95135c0d28c3cdc1a821a82f2fd60 100644 (file)
@@ -264,4 +264,48 @@ public class Module implements IElement {
        }\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
index 131246548cfaacf061b459a739610d79aa26b7f5..853ce552ca90c442d2c8889325608aaacee52c2e 100644 (file)
@@ -48,6 +48,12 @@ public abstract class Variable implements IElement {
     @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
@@ -110,4 +116,34 @@ public abstract class Variable implements IElement {
         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
index 7bc07c11dce1d2fda4b3915d01b148a1368a20f0..76d7dd22ec19c5887b0f701746ca3d04535d7ce4 100644 (file)
@@ -76,4 +76,9 @@ public abstract class Expression implements IExpression {
     public IndependentVariable getParent() {\r
         return parent;\r
     }\r
+    \r
+    @Override\r
+    public String getDocumentationExpression() {\r
+        return getEquation();\r
+    }\r
 }\r
index ff168d005c0f9cd1f78e396afdc64b8f7cf0b128..249dc0836091d052988ccbcb0c42e9fdee45203f 100644 (file)
@@ -81,4 +81,11 @@ public interface IExpression {
      * @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
index 78d90d96f158f0c4c04d629ae5c61ccb341956ea..997a316a6585d1d3d87a7bf42f6468f0737e9f4c 100644 (file)
  *******************************************************************************/\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
@@ -61,4 +70,51 @@ public class WithLookupExpression extends Expression {
         \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
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java
new file mode 100644 (file)
index 0000000..0a54dda
--- /dev/null
@@ -0,0 +1,223 @@
+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
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/GetConfigurationRequest.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/GetConfigurationRequest.java
new file mode 100644 (file)
index 0000000..4aa5155
--- /dev/null
@@ -0,0 +1,42 @@
+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