]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Expression types started
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 22 Dec 2009 15:11:21 +0000 (15:11 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 22 Dec 2009 15:11:21 +0000 (15:11 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13342 ac1ea38d-2e2b-0410-8846-a27921b304fc

21 files changed:
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/EquationView.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionView.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/NormalExpressionView.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionView.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IExpression.java [deleted file]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/NormalExpression.java [deleted file]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java [new file with mode: 0644]
sysdyn_ontologies/generate_sysdyn.bat
sysdyn_ontologies/sysdyn.graph

index 2675900cb6a332e641f5633fe24efd7b9ccf0368..656a3f76dd8df4229f37788ea6c39dd326567a97 100644 (file)
@@ -29,7 +29,6 @@ public class FlowElement extends Element implements IElementListener {
     Connectable tail;\r
     @RelatedElement("http://www.simantics.org/Sysdyn#HasHead")\r
     Connectable head;\r
-    double angle = 0.1;\r
 \r
     // Auxiliary       \r
     double angle0;\r
index e820dad2bd6b64d9f577c25ceeb67f645e07d0aa..474fbd7e1747479f2de1f7669a92a1ce5ce514ae 100644 (file)
@@ -34,6 +34,9 @@ public class TextElement extends RectangularElement implements Movable, Connecta
     // Properties\r
     @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#HasName")\r
     public String label = "Unnamed";\r
+    \r
+    @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#HasType")\r
+    public String type = "Real";\r
        \r
        // Auxiliary fields\r
        double textX;\r
index 713d39ee1a8ec1fea3c0f3b211957384acebd237..095bec4e3a42afa3b74e45401fe8451568c85d01 100644 (file)
@@ -9,17 +9,15 @@ import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.FocusAdapter;\r
 import org.eclipse.swt.events.FocusEvent;\r
 import org.eclipse.swt.events.FocusListener;\r
-import org.eclipse.swt.events.KeyAdapter;\r
-import org.eclipse.swt.events.KeyEvent;\r
 import org.eclipse.swt.events.MouseEvent;\r
 import org.eclipse.swt.events.MouseListener;\r
 import org.eclipse.swt.graphics.Font;\r
 import org.eclipse.swt.layout.RowLayout;\r
 import org.eclipse.swt.widgets.Combo;\r
 import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.TabFolder;\r
 import org.eclipse.swt.widgets.TabItem;\r
@@ -28,16 +26,18 @@ import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swt.widgets.Text;\r
 import org.eclipse.ui.ISelectionListener;\r
 import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.IWorkbenchPartReference;\r
 import org.eclipse.ui.part.ViewPart;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.equation.expressions.ExpressionView;\r
+import org.simantics.sysdyn.ui.equation.expressions.NormalExpressionView;\r
+import org.simantics.sysdyn.ui.equation.expressions.StockExpressionView;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
 \r
@@ -52,8 +52,6 @@ public class EquationView extends ViewPart implements ISelectionListener {
     Text nameText;\r
 \r
     Composite equationComposite;\r
-    Label equationLabel;\r
-    Text text;\r
 \r
     String originalText;\r
     TabFolder tabFolder;\r
@@ -62,14 +60,37 @@ public class EquationView extends ViewPart implements ISelectionListener {
     TabItem functions;\r
     Composite unitsAndRange;\r
     Composite variableType;\r
+    Composite emptyComposite;\r
+    ExpressionView expressionView;\r
 \r
+    org.eclipse.ui.IPartListener2 focusLostListener;\r
 \r
     @Override    \r
     public void createPartControl(Composite parent) {\r
+        // Listeners\r
         getSite().getPage().addPostSelectionListener(this);\r
+        focusLostListener = new org.eclipse.ui.IPartListener2()\r
+        {\r
+            public void partInputChanged(IWorkbenchPartReference partRef) {}\r
+            public void partVisible(IWorkbenchPartReference partRef) {}\r
+            public void partHidden(IWorkbenchPartReference partRef) {}\r
+            public void partOpened(IWorkbenchPartReference partRef) {}\r
+            public void partDeactivated(IWorkbenchPartReference partRef)\r
+            {\r
+                if(partRef.getPart(false) instanceof EquationView) {\r
+                    if(expressionView != null) expressionView.save();\r
+                }\r
+            }\r
+            public void partClosed(IWorkbenchPartReference partRef) {}\r
+            public void partBroughtToTop(IWorkbenchPartReference partRef) {}\r
+            public void partActivated(IWorkbenchPartReference partRef) {}\r
+        };\r
+        getViewSite().getPage().addPartListener(focusLostListener);\r
 \r
         GridLayoutFactory.fillDefaults().numColumns(4).margins(5, 5).applyTo(parent);\r
 \r
+\r
+\r
         // Upper part of the view: Name (and renaming)\r
         nameText = new Text(parent, SWT.SINGLE | SWT.BORDER);\r
         nameText.setFont(FONT);\r
@@ -82,41 +103,30 @@ public class EquationView extends ViewPart implements ISelectionListener {
         variables.setText("Variables");\r
         variableTable = new Table (tabFolder, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);\r
         variableTable.addMouseListener(new MouseListener(){\r
-            \r
+\r
             @Override\r
             public void mouseDoubleClick(MouseEvent e) {\r
                 TableItem[] selection = variableTable.getSelection();\r
-                final String var = selection[0].getText();\r
-                text.getDisplay().asyncExec(new Runnable() {\r
-                    \r
-                    @Override\r
-                    public void run() {\r
-                        int pos = text.getCaretPosition();\r
-                        String middle = var;\r
-                        String start = text.getText(0, pos -1);\r
-                        String end = text.getText(pos, text.getCharCount()-1);\r
-                        if (pos != 0 && !text.getText(pos-1, pos).equals(" "))\r
-                            middle = " " + middle;\r
-                        if (pos != text.getCharCount() && !text.getText(pos, pos+1).equals(" "))\r
-                            middle = middle + " ";\r
-                        text.setText(start + middle + end);\r
-                        text.forceFocus();\r
-                        text.setSelection(pos + middle.length());\r
-                    }\r
-                });\r
-            }\r
-\r
-            @Override\r
-            public void mouseDown(MouseEvent e) {\r
+                if(selection.length > 0) {\r
+                    final String var = selection[0].getText();\r
+                    expressionView.getDisplay().asyncExec(new Runnable() {\r
 \r
+                        @Override\r
+                        public void run() {\r
+                            expressionView.replaceSelection(var);\r
+                        }\r
+                    });\r
+                }\r
             }\r
 \r
             @Override\r
-            public void mouseUp(MouseEvent e) {\r
+            public void mouseDown(MouseEvent e) {}\r
 \r
-            }\r
+            @Override\r
+            public void mouseUp(MouseEvent e) {}\r
 \r
         });\r
+\r
         variableTable.addFocusListener(new FocusListener() {\r
 \r
             @Override\r
@@ -127,7 +137,7 @@ public class EquationView extends ViewPart implements ISelectionListener {
             public void focusLost(FocusEvent e) {\r
                 variableTable.deselectAll();\r
             }\r
-            \r
+\r
         });\r
         variables.setControl(variableTable);\r
 \r
@@ -143,8 +153,10 @@ public class EquationView extends ViewPart implements ISelectionListener {
         functions.setControl(table);\r
 \r
         // Right side of the view: Details, comments\r
-        Composite emptyComposite = new Composite(parent, SWT.NONE);\r
+        emptyComposite = new Composite(parent, SWT.NONE);\r
         GridDataFactory.fillDefaults().span(1,4).grab(true, true).applyTo(emptyComposite);\r
+        GridLayoutFactory.fillDefaults().applyTo(emptyComposite);\r
+\r
 \r
         // Below the variable name: Variable type\r
         variableType = new Composite(parent, SWT.NONE);\r
@@ -172,53 +184,9 @@ public class EquationView extends ViewPart implements ISelectionListener {
         // Below variable type: Equation\r
         equationComposite = new Composite(parent, SWT.NONE);\r
         GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(equationComposite);\r
-        GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(equationComposite);\r
-        equationLabel = new Label(equationComposite, SWT.NONE);\r
-        equationLabel.setFont(FONT);\r
-        equationLabel.setText("=");\r
-        GridDataFactory.fillDefaults().applyTo(equationLabel);\r
-\r
-        text = new Text(equationComposite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
-        text.setFont(FONT);\r
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(text);\r
-        text.addFocusListener(new FocusAdapter() {\r
+        GridLayoutFactory.fillDefaults().applyTo(equationComposite);\r
 \r
-            @Override\r
-            public void focusLost(FocusEvent e) {\r
-                final String currentText = text.getText();\r
-                if(originalText != null && !originalText.equals(currentText)) {\r
-                    SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
-                        @Override\r
-                        public void perform(WriteGraph g)\r
-                        throws DatabaseException {\r
-                            Builtins b = g.getBuiltins();\r
-                            SysdynResource sr = SysdynResource.getInstance(g);\r
-\r
-                            Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
-                            if(expression == null) {\r
-                                expression = g.newResource();\r
-                                g.claim(expression, b.InstanceOf, sr.Expression);\r
-                                g.claim(variable, sr.HasExpression, expression);\r
-                            }\r
-                            g.claimValue(expression, sr.HasText, currentText);\r
-                        }\r
-\r
-                    });\r
-                }\r
-            }            \r
-\r
-        });\r
-        text.addKeyListener(new KeyAdapter() {          \r
-\r
-            @Override\r
-            public void keyPressed(KeyEvent e) {\r
-                if(e.keyCode == SWT.ESC) {\r
-                    text.setText(originalText);\r
-                }                \r
-            }\r
-\r
-        });\r
 \r
         // Lower part of the view: Units and Range\r
         unitsAndRange = new Composite(parent, SWT.NONE); \r
@@ -243,9 +211,10 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
     static class Auxiliary {\r
         ArrayList<String> dependencies;\r
-        String eqLabel, name, value;\r
+        String name;\r
+        String type;\r
     }\r
-    \r
+\r
     class UpdateViewRequest implements Read<Auxiliary> {\r
 \r
         Resource resource;\r
@@ -256,26 +225,19 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
         @Override\r
         public Auxiliary perform(ReadGraph graph) throws DatabaseException {\r
-            SysdynResource sr = SysdynResource.getInstance(graph);\r
             Builtins b = graph.getBuiltins();\r
             Auxiliary a = new Auxiliary();\r
-            if (graph.isInstanceOf(resource, sr.Auxiliary) || graph.isInstanceOf(resource, sr.Valve))\r
-                a.eqLabel = "=";\r
-            else if (graph.isInstanceOf(resource, sr.Stock))\r
-                a.eqLabel = "initial =";\r
-            else \r
-                return null;\r
             variable = resource;\r
             a.name = graph.getRelatedValue(resource, b.HasName);\r
-            Resource expression = graph.getPossibleObject(resource, sr.HasExpression);     \r
-            a.value = expression == null ? null :\r
-                (String)graph.getPossibleRelatedValue(expression, sr.HasText);\r
             a.dependencies = getDependencies(resource);\r
+            SysdynResource sr = SysdynResource.getInstance(graph);\r
+            if (graph.isInstanceOf(variable, sr.Auxiliary) || graph.isInstanceOf(variable, sr.Valve))\r
+                a.type = "NORMAL";\r
+            else if (graph.isInstanceOf(variable, sr.Stock))\r
+                a.type = "STOCK";\r
+            \r
             return a;\r
         }\r
-\r
-\r
-\r
     }\r
 \r
     @Override\r
@@ -293,52 +255,55 @@ public class EquationView extends ViewPart implements ISelectionListener {
                                 @Override\r
                                 public void exception(Throwable t) {\r
                                     // TODO Auto-generated method stub\r
-                                    \r
+\r
                                 }\r
 \r
                                 @Override\r
                                 public void execute(final Auxiliary result) {\r
-                                    text.getDisplay().asyncExec(new Runnable() {\r
+                                    equationComposite.getDisplay().asyncExec(new Runnable() {\r
 \r
                                         @Override\r
                                         public void run(){\r
-                                            \r
+\r
                                             variableTable.removeAll();\r
                                             TableItem item;\r
                                             for(String d : result.dependencies) {\r
                                                 item = new TableItem(variableTable, SWT.NONE);\r
                                                 item.setText(d);\r
                                             }\r
-                                            \r
                                             nameText.setText(result.name);\r
-                                            equationLabel.setText(result.eqLabel);\r
-                                            equationComposite.layout();\r
-                                            if(result.value == null)\r
-                                                originalText = "";\r
-                                            else\r
-                                                originalText = result.value;\r
-                                            text.setText(originalText);\r
-                                            \r
+\r
+                                            for(Control c : equationComposite.getChildren()) {\r
+                                                c.dispose();\r
+                                            }        \r
                                             \r
+                                            ExpressionView ev = null;\r
+                                            if (result.type.equalsIgnoreCase("NORMAL"))\r
+                                                ev = new NormalExpressionView(equationComposite, SWT.NONE, variable);\r
+                                            else if (result.type.equalsIgnoreCase("STOCK"))\r
+                                                ev = new StockExpressionView(equationComposite, SWT.NONE, variable);\r
+                                            expressionView = ev;\r
+                                            equationComposite.layout();\r
+\r
                                         }\r
                                     });      \r
-                                    \r
+\r
                                 }\r
 \r
                                 @Override\r
                                 public boolean isDisposed() {\r
                                     return disposed;\r
                                 }\r
-                                \r
+\r
                             }\r
-                            );\r
+                    );\r
             }\r
         }\r
     }\r
 \r
     @Override\r
     public void setFocus() {\r
-        text.setFocus();\r
+        //text.setFocus();\r
     }\r
 \r
     // Returns the names of the related variables (dependencies)\r
@@ -377,10 +342,11 @@ public class EquationView extends ViewPart implements ISelectionListener {
 \r
         return variables;\r
     }\r
-    \r
+\r
     @Override\r
     public void dispose() {\r
         disposed = true;\r
+        getViewSite().getPage().removePartListener(focusLostListener);\r
         super.dispose();\r
     }\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionView.java
new file mode 100644 (file)
index 0000000..8b55b09
--- /dev/null
@@ -0,0 +1,20 @@
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Font;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.db.Resource;\r
+\r
+abstract public class ExpressionView extends Composite {\r
+\r
+    static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL);\r
+    protected Resource variable;\r
+    \r
+    public ExpressionView(Composite parent, int style, Resource variable) {\r
+        super(parent, style);\r
+        this.variable = variable;\r
+    }\r
\r
+    abstract public void save();\r
+    abstract public void replaceSelection(String text);\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/NormalExpressionView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/NormalExpressionView.java
new file mode 100644 (file)
index 0000000..7fb0bc6
--- /dev/null
@@ -0,0 +1,123 @@
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusAdapter;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.KeyAdapter;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#NormalExpression")\r
+public class NormalExpressionView extends ExpressionView {\r
+\r
+    Label equationLabel;\r
+    Text expression;\r
+    Point lastSelection = new Point(0,0);\r
+\r
+    @RelatedValue("http://www.simantics.org/Sysdyn#HasEquation")\r
+    private String equation;\r
+\r
+    public NormalExpressionView(Composite parent, int style, final Resource variable) {\r
+        super(parent, style, variable);\r
+\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+                @Override\r
+                public String perform(ReadGraph graph) throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
+                    if (expression != null && graph.isInstanceOf(expression, sr.NormalExpression)) {\r
+                        equation = graph.getRelatedValue(expression, sr.HasEquation);\r
+                    } else {\r
+                        equation = "";\r
+                    }\r
+                    return null;\r
+                }\r
+\r
+            });\r
+        } catch (DatabaseException e1) {\r
+            e1.printStackTrace();\r
+        }\r
+\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(this);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(this);\r
+        equationLabel = new Label(this, SWT.NONE);\r
+        equationLabel.setFont(FONT);\r
+        equationLabel.setText("=");\r
+        GridDataFactory.fillDefaults().applyTo(equationLabel);\r
+\r
+\r
+        expression = new Text(this, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        expression.setFont(FONT);\r
+        expression.setText(equation);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
+        \r
+        expression.addFocusListener(new FocusAdapter() {\r
+\r
+            @Override\r
+            public void focusLost(FocusEvent e) {\r
+                lastSelection = expression.getSelection();\r
+            }\r
+        });\r
+\r
+        expression.addKeyListener(new KeyAdapter() {          \r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(e.keyCode == SWT.ESC) {\r
+                    expression.setText(equation);\r
+                }                \r
+            }\r
+\r
+        });\r
+\r
+    }\r
+\r
+    @Override\r
+    public void save() {  \r
+        final String currentText = expression.getText();\r
+        if(equation != null && !equation.equals(currentText)) {\r
+            SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+                @Override\r
+                public void perform(WriteGraph g)\r
+                throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(g);\r
+                    Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
+                    Builtins b = g.getBuiltins();\r
+                    if(expression == null) {\r
+                        expression = g.newResource();\r
+                        g.claim(expression, b.InstanceOf, sr.NormalExpression);\r
+                        g.claim(variable, sr.HasExpression, expression);\r
+                    }\r
+                    g.claimValue(expression, sr.HasEquation, currentText);\r
+                }\r
+\r
+            });\r
+        }\r
+\r
+    }\r
+    \r
+    public void replaceSelection(String text) {\r
+        String oldExpression = expression.getText();\r
+        String newExpression = oldExpression.substring(0, lastSelection.x) + text + oldExpression.substring(lastSelection.y);\r
+        expression.setText(newExpression);\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/StockExpressionView.java
new file mode 100644 (file)
index 0000000..e640eed
--- /dev/null
@@ -0,0 +1,127 @@
+package org.simantics.sysdyn.ui.equation.expressions;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusAdapter;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.KeyAdapter;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#StockExpression")\r
+public class StockExpressionView extends ExpressionView {\r
+\r
+    Label equationLabel;\r
+    Text expression;\r
+    Point lastSelection = new Point(0,0);\r
+\r
+    @RelatedValue("http://www.simantics.org/Sysdyn#HasInitialEquation")\r
+    private String initialEquation;\r
+    \r
+    public StockExpressionView(Composite parent, int style, final Resource variable) {\r
+        super(parent, style, variable);\r
+        \r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+                @Override\r
+                public String perform(ReadGraph graph) throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
+                    if (expression != null && graph.isInstanceOf(expression, sr.StockExpression)) {\r
+                        initialEquation = graph.getRelatedValue(expression, sr.HasInitialEquation);\r
+                    } else {\r
+                        initialEquation = "";\r
+                    }\r
+                    return null;\r
+                }\r
+\r
+            });\r
+        } catch (DatabaseException e1) {\r
+            e1.printStackTrace();\r
+        }\r
+        \r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(this);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).spacing(3, 3).applyTo(this);\r
+        equationLabel = new Label(this, SWT.NONE);\r
+        equationLabel.setFont(FONT);\r
+        equationLabel.setText("Initial\nValue");\r
+        GridDataFactory.fillDefaults().applyTo(equationLabel);\r
+\r
+\r
+        expression = new Text(this, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
+        expression.setFont(FONT);\r
+        expression.setText(initialEquation);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
+        \r
+        expression.addFocusListener(new FocusAdapter() {\r
+\r
+            @Override\r
+            public void focusLost(FocusEvent e) {\r
+                lastSelection = expression.getSelection();\r
+            }\r
+        });\r
+\r
+        expression.addKeyListener(new KeyAdapter() {          \r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(e.keyCode == SWT.ESC) {\r
+                    expression.setText(initialEquation);\r
+                }                \r
+            }\r
+\r
+        });\r
+\r
+    }\r
+\r
+\r
+    @Override\r
+    public void replaceSelection(String text) {\r
+        String oldExpression = expression.getText();\r
+        String newExpression = oldExpression.substring(0, lastSelection.x) + text + oldExpression.substring(lastSelection.y);\r
+        expression.setText(newExpression);        \r
+    }\r
+\r
+    @Override\r
+    public void save() {\r
+        final String currentText = expression.getText();\r
+        if(initialEquation != null && !initialEquation.equals(currentText)) {\r
+            SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+                @Override\r
+                public void perform(WriteGraph g)\r
+                throws DatabaseException {\r
+                    SysdynResource sr = SysdynResource.getInstance(g);\r
+                    Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
+                    Builtins b = g.getBuiltins();\r
+                    if(expression == null) {\r
+                        expression = g.newResource();\r
+                        g.claim(expression, b.InstanceOf, sr.StockExpression);\r
+                        g.claim(variable, sr.HasExpression, expression);\r
+                    }\r
+                    g.claimValue(expression, sr.HasInitialEquation, currentText);\r
+                }\r
+\r
+            });\r
+        }\r
+\r
+        \r
+    }\r
+\r
+}\r
index 542861aecd6b62a70d56f8ed0166d2c0e348742b..76df255efe2ceab98f906fc1c70775d90e868df4 100644 (file)
@@ -46,7 +46,7 @@ public class SysdynModelicaEditor extends TextEditor {
                     throws CoreException {\r
                 try {\r
                     Configuration configuration =\r
-                        LoadRepresentation.load(SimanticsUI.getSession(), ((ResourceEditorInput)element).getResource());\r
+                        LoadRepresentation.loadConfiguration(SimanticsUI.getSession(), ((ResourceEditorInput)element).getResource());\r
                     ModelicaWriter writer = new ModelicaWriter();\r
                     writer.write(configuration);\r
                     \r
index efa65edc45b894f2885ad184378ba7f0f42ba319..3546148fe4f4012ae0cee627f7460b094509573e 100644 (file)
@@ -25,17 +25,21 @@ public class SysdynResource {
     public final Resource Expression;\r
     public final Resource Flow;\r
     public final Resource HasAngle;\r
+    public final Resource HasEquation;\r
     public final Resource HasExpression;\r
     public final Resource HasHead;\r
+    public final Resource HasInitialEquation;\r
     public final Resource HasTail;\r
-    public final Resource HasText;\r
+    public final Resource HasType;\r
     public final Resource HasX;\r
     public final Resource HasY;\r
     public final Resource IndependentVariable;\r
     public final Resource IsHeadOf;\r
     public final Resource IsTailOf;\r
     public final Resource NormalExpression;\r
+    public final Resource ParameterExpression;\r
     public final Resource Stock;\r
+    public final Resource StockExpression;\r
     public final Resource SysdynProject;\r
     public final Resource Valve;\r
     public final Resource Variable;\r
@@ -48,17 +52,21 @@ public class SysdynResource {
         public static final String Expression = "http://www.simantics.org/Sysdyn#Expression";\r
         public static final String Flow = "http://www.simantics.org/Sysdyn#Flow";\r
         public static final String HasAngle = "http://www.simantics.org/Sysdyn#HasAngle";\r
+        public static final String HasEquation = "http://www.simantics.org/Sysdyn#HasEquation";\r
         public static final String HasExpression = "http://www.simantics.org/Sysdyn#HasExpression";\r
         public static final String HasHead = "http://www.simantics.org/Sysdyn#HasHead";\r
+        public static final String HasInitialEquation = "http://www.simantics.org/Sysdyn#HasInitialEquation";\r
         public static final String HasTail = "http://www.simantics.org/Sysdyn#HasTail";\r
-        public static final String HasText = "http://www.simantics.org/Sysdyn#HasText";\r
+        public static final String HasType = "http://www.simantics.org/Sysdyn#HasType";\r
         public static final String HasX = "http://www.simantics.org/Sysdyn#HasX";\r
         public static final String HasY = "http://www.simantics.org/Sysdyn#HasY";\r
         public static final String IndependentVariable = "http://www.simantics.org/Sysdyn#IndependentVariable";\r
         public static final String IsHeadOf = "http://www.simantics.org/Sysdyn#IsHeadOf";\r
         public static final String IsTailOf = "http://www.simantics.org/Sysdyn#IsTailOf";\r
         public static final String NormalExpression = "http://www.simantics.org/Sysdyn#NormalExpression";\r
+        public static final String ParameterExpression = "http://www.simantics.org/Sysdyn#ParameterExpression";\r
         public static final String Stock = "http://www.simantics.org/Sysdyn#Stock";\r
+        public static final String StockExpression = "http://www.simantics.org/Sysdyn#StockExpression";\r
         public static final String SysdynProject = "http://www.simantics.org/Sysdyn#SysdynProject";\r
         public static final String Valve = "http://www.simantics.org/Sysdyn#Valve";\r
         public static final String Variable = "http://www.simantics.org/Sysdyn#Variable";\r
@@ -81,17 +89,21 @@ public class SysdynResource {
         Expression = getResourceOrNull(graph, URIs.Expression);\r
         Flow = getResourceOrNull(graph, URIs.Flow);\r
         HasAngle = getResourceOrNull(graph, URIs.HasAngle);\r
+        HasEquation = getResourceOrNull(graph, URIs.HasEquation);\r
         HasExpression = getResourceOrNull(graph, URIs.HasExpression);\r
         HasHead = getResourceOrNull(graph, URIs.HasHead);\r
+        HasInitialEquation = getResourceOrNull(graph, URIs.HasInitialEquation);\r
         HasTail = getResourceOrNull(graph, URIs.HasTail);\r
-        HasText = getResourceOrNull(graph, URIs.HasText);\r
+        HasType = getResourceOrNull(graph, URIs.HasType);\r
         HasX = getResourceOrNull(graph, URIs.HasX);\r
         HasY = getResourceOrNull(graph, URIs.HasY);\r
         IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
         IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf);\r
         IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
         NormalExpression = getResourceOrNull(graph, URIs.NormalExpression);\r
+        ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
         Stock = getResourceOrNull(graph, URIs.Stock);\r
+        StockExpression = getResourceOrNull(graph, URIs.StockExpression);\r
         SysdynProject = getResourceOrNull(graph, URIs.SysdynProject);\r
         Valve = getResourceOrNull(graph, URIs.Valve);\r
         Variable = getResourceOrNull(graph, URIs.Variable);\r
index 23b1b8c11551ed37ecbe62252cda757e9ffa3f24..f990c4c2acefe8d58bbdffc988a49f699fe5b0ab 100644 (file)
@@ -1,69 +1,42 @@
 package org.simantics.sysdyn.modelica;\r
 \r
-import org.simantics.sysdyn.representation.Auxiliary;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.IElement;\r
 import org.simantics.sysdyn.representation.Stock;\r
-import org.simantics.sysdyn.representation.Valve;\r
 import org.simantics.sysdyn.representation.Variable;\r
-import org.simantics.sysdyn.representation.visitors.ElementVisitorVoidAdapter;\r
-import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
 public class ModelicaWriter {\r
 \r
     StringBuilder b = new StringBuilder();\r
-    \r
-    IElementVisitorVoid componentWriter = new ElementVisitorVoidAdapter() {\r
-        public void visit(Auxiliary auxiliary) {\r
-            b.append("    Real ").append(escape(auxiliary.name)).append(";\n");\r
-        }\r
-        public void visit(Valve valve) {\r
-            b.append("    Real ").append(escape(valve.name)).append(";\n");\r
-        }\r
-        public void visit(Stock stock) {\r
-            b.append("    Real ").append(escape(stock.name)).append(";\n");\r
-        }       \r
-    };\r
-    \r
-    IElementVisitorVoid equationWriter = new ElementVisitorVoidAdapter() {\r
-        public void visit(Auxiliary auxiliary) {\r
-            b.append("    ").append(escape(auxiliary.name))\r
-                .append(" = ").append(auxiliary.expression.getText()).append(";\n");\r
-        }\r
-        public void visit(Stock stock) {\r
-            b.append("    der(")\r
-             .append(escape(stock.name))\r
-             .append(") =");\r
-            for(Variable flow : stock.incomingFlows)\r
-                b.append("\n        + ").append(escape(flow.name));\r
-            for(Variable flow : stock.outgoingFlows)\r
-                b.append("\n        - ").append(escape(flow.name));\r
-            b.append(";\n");\r
-        }        \r
-        public void visit(Valve valve) {\r
-            b.append("    ").append(escape(valve.name))\r
-                .append(" = ").append(valve.expression.getText()).append(";\n");\r
-        }\r
-    };\r
-    \r
-    IElementVisitorVoid initialEquationWriter = new ElementVisitorVoidAdapter() {\r
-        public void visit(Stock stock) {\r
-            b.append("    ").append(escape(stock.name))\r
-             .append(" = ").append(stock.expression.getText()).append(";\n");\r
-        } \r
-    };\r
+    String app;\r
+    boolean initialEquations = false;\r
     \r
     public void write(Configuration conf) {\r
         conf.update();\r
         b.append("model ").append(conf.name).append('\n');\r
         for(IElement element : conf.elements)\r
-            element.accept(componentWriter);\r
-        b.append("initial equation\n");\r
+            if(element instanceof Variable) {\r
+                app = ((Variable)element).expression.getDeclaration((Variable)element);\r
+                if (app != null) b.append(app);\r
+            }\r
+        \r
         for(IElement element : conf.elements)\r
-            element.accept(initialEquationWriter);\r
+            if(element instanceof Stock) {\r
+                app = ((Stock)element).expression.getInitialEquation((Stock)element);\r
+                if (app != null) {\r
+                    if(initialEquations == false) {\r
+                        initialEquations = true;\r
+                        b.append("initial equation\n");\r
+                    }\r
+                    b.append(app);\r
+                }\r
+            }\r
         b.append("equation\n");\r
         for(IElement element : conf.elements)\r
-            element.accept(equationWriter);\r
+            if(element instanceof Variable) {\r
+               app = ((Variable)element).expression.getEquation((Variable)element);\r
+               if (app != null) b.append(app);\r
+            }\r
         b.append("end ").append(conf.name).append(";\n");\r
     }\r
     \r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IExpression.java
deleted file mode 100644 (file)
index d0e5ec4..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.simantics.sysdyn.representation;\r
-\r
-public interface IExpression {\r
-    String getText();\r
-}\r
index c02ac45ae6175602b0235831d3406d5cc4a60ec4..1c7b861e060fde2c567978633cc5a856564c80c2 100644 (file)
@@ -10,7 +10,7 @@ import org.simantics.objmap.Mappings;
 \r
 public class LoadRepresentation {\r
 \r
-    public static Configuration load(Session session, final Resource configuration) throws DatabaseException {\r
+    public static Configuration loadConfiguration(Session session, final Resource configuration) throws DatabaseException {\r
         return session.syncRequest(new Read<Configuration>() {\r
 \r
             @Override\r
@@ -24,4 +24,18 @@ public class LoadRepresentation {
         });\r
     }\r
     \r
+    public static IElement loadElement(Session session, final Resource element) throws DatabaseException {\r
+        return session.syncRequest(new Read<IElement>() {\r
+\r
+            @Override\r
+            public IElement perform(ReadGraph graph)\r
+                    throws DatabaseException {\r
+                SysdynSchema schema = new SysdynSchema(graph);\r
+                IMapping mapping = Mappings.createWithoutListening(schema);\r
+                return (IElement)mapping.map(graph, element);                \r
+            }\r
+            \r
+        });\r
+    }\r
+    \r
 }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/NormalExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/NormalExpression.java
deleted file mode 100644 (file)
index d9d609f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.simantics.sysdyn.representation;\r
-\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.objmap.annotations.RelatedValue;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn#NormalExpression")\r
-public class NormalExpression implements IExpression {\r
-    @RelatedValue("http://www.simantics.org/Sysdyn#HasText")\r
-    public String text;\r
-\r
-    @Override\r
-    public String getText() {\r
-        return text;\r
-    }\r
-}\r
index 58be1de4684c3e16a2d90cb2d8990ca96ddea815..b2294c38a7be917f8e532f4912c13cd52321c277 100644 (file)
@@ -4,6 +4,9 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.objmap.schema.MappingSchemas;\r
 import org.simantics.objmap.schema.SimpleSchema;\r
+import org.simantics.sysdyn.representation.expressions.NormalExpression;\r
+import org.simantics.sysdyn.representation.expressions.ParameterExpression;\r
+import org.simantics.sysdyn.representation.expressions.StockExpression;\r
 \r
 public class SysdynSchema extends SimpleSchema {\r
     \r
@@ -17,6 +20,9 @@ public class SysdynSchema extends SimpleSchema {
             addLinkType(MappingSchemas.fromAnnotations(g, Stock.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, Valve.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class));\r
+            \r
         } catch (DatabaseException e) {\r
             // TODO Auto-generated catch block\r
             e.printStackTrace();\r
index 653c04ba3ddf53bccbd6e6cba8d1cd723f41ea1c..d9b441192b65e9c877e099b9a2f51da2304f3450 100644 (file)
@@ -2,12 +2,23 @@ package org.simantics.sysdyn.representation;
 \r
 import org.simantics.objmap.annotations.RelatedElement;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.representation.expressions.IExpression;\r
 \r
 public abstract class Variable implements IElement {\r
     @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#HasName")\r
-    public String name;\r
+    protected String name;\r
+    @RelatedValue("http://www.vtt.fi/Simantics/Layer0/1.0/Relations#HasType")\r
+    protected String type;\r
     //@RelatedValue("http://www.simantics.org/Sysdyn#HasValue")\r
     //public String value;\r
     @RelatedElement("http://www.simantics.org/Sysdyn#HasExpression")\r
     public IExpression expression;\r
+    \r
+    public String getName() {\r
+        return this.name;\r
+    }\r
+    \r
+    public String getType() {\r
+        return this.type;\r
+    }\r
 }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java
new file mode 100644 (file)
index 0000000..aab3d0f
--- /dev/null
@@ -0,0 +1,22 @@
+package org.simantics.sysdyn.representation.expressions;\r
+\r
+import org.simantics.sysdyn.representation.Variable;\r
+\r
+public abstract class Expression implements IExpression {\r
+        \r
+    @Override\r
+    public String getDeclaration(Variable variable) {\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public String getEquation(Variable variable) {\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public String getInitialEquation(Variable variable) {\r
+        return null;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java
new file mode 100644 (file)
index 0000000..9260ead
--- /dev/null
@@ -0,0 +1,11 @@
+package org.simantics.sysdyn.representation.expressions;\r
+\r
+import org.simantics.sysdyn.representation.Variable;\r
+\r
+public interface IExpression {\r
+\r
+    String getDeclaration(Variable variable);\r
+    String getInitialEquation(Variable variable);\r
+    String getEquation(Variable variable);\r
+\r
+}\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java
new file mode 100644 (file)
index 0000000..c8242c5
--- /dev/null
@@ -0,0 +1,23 @@
+package org.simantics.sysdyn.representation.expressions;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.representation.Variable;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#NormalExpression")\r
+public class NormalExpression extends Expression {\r
+\r
+    @RelatedValue("http://www.simantics.org/Sysdyn#HasEquation")\r
+    private String equation;\r
+      \r
+    @Override\r
+    public String getDeclaration(Variable variable) {\r
+        return "    " + variable.getType() + " " + variable.getName() + ";\n";\r
+    }\r
+\r
+    @Override\r
+    public String getEquation(Variable variable) {\r
+        return "    " + variable.getName() + " = " + equation + ";\n";\r
+    }\r
+    \r
+}\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java
new file mode 100644 (file)
index 0000000..0c541fb
--- /dev/null
@@ -0,0 +1,17 @@
+package org.simantics.sysdyn.representation.expressions;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.representation.Variable;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#ParameterExpression")\r
+public class ParameterExpression extends Expression {\r
+    \r
+    @RelatedValue("http://www.simantics.org/Sysdyn#HasEquation")\r
+    private String equation;\r
+    \r
+    @Override\r
+    public String getDeclaration(Variable variable) {\r
+        return "    " + variable.getType() + " " + variable.getName() + " = " + equation + ";\n";\r
+    }\r
+}\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java
new file mode 100644 (file)
index 0000000..5ab28c2
--- /dev/null
@@ -0,0 +1,59 @@
+package org.simantics.sysdyn.representation.expressions;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.representation.Stock;\r
+import org.simantics.sysdyn.representation.Variable;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#StockExpression")\r
+public class StockExpression extends Expression {\r
+    \r
+    @RelatedValue("http://www.simantics.org/Sysdyn#HasInitialEquation")\r
+    private String initialEquation;\r
+    \r
+    @Override\r
+    public String getDeclaration(Variable variable) {\r
+        Double value = null;\r
+        try {\r
+            value = Double.parseDouble(initialEquation);\r
+        } catch (Exception e){\r
+            // Is an initial equation\r
+        }\r
+        if (value == null) {\r
+            return "    " + variable.getType() + " " + variable.getName() + "(fixed=false);\n";\r
+        } else {\r
+            return "    " + variable.getType() + " " + variable.getName() + "(start=" + value + ", fixed=true);\n";\r
+        }\r
+\r
+    }\r
+\r
+    @Override\r
+    public String getEquation(Variable variable) {\r
+        StringBuilder b = new StringBuilder();\r
+        b.append("    der(")\r
+        .append(variable.getName())\r
+        .append(") =");\r
+       for(Variable flow : ((Stock)variable).incomingFlows)\r
+           b.append("\n        + ").append(flow.getName());\r
+       for(Variable flow : ((Stock)variable).outgoingFlows)\r
+           b.append("\n        - ").append(flow.getName());\r
+       b.append(";\n");\r
+       return b.toString();\r
+    }\r
+\r
+    @Override\r
+    public String getInitialEquation(Variable variable) {\r
+        Double value = null;\r
+        try {\r
+            value = Double.parseDouble(initialEquation);\r
+        } catch (Exception e){\r
+            // Is an initial equation\r
+        } if (value != null) {\r
+            return null;\r
+        } else {\r
+            return "    " + variable.getName() + " = " + initialEquation + ";\n";\r
+        }\r
+    }\r
+\r
+\r
+}\r
index 32293b37f9c69a70bd1cc822280c7ddb7b8e2f49..2c0814a05a17d900d459abecee2d3a05668ebbb8 100644 (file)
@@ -1,2 +1,2 @@
 @echo off\r
-call "%~dp0..\og\generate2" "%~dp0" ..\foundation_ontologies\foundation.graph ..\sysdyn_ontologies\sysdyn.graph ..\modeling_ontologies\modeling.graph ..\modeling_ontologies\devs.graph ..\webmon_ontologies\webmon.graph
\ No newline at end of file
+call "%~dp0..\org.simantics.db.build\build" "%~dp0" ..\foundation_ontologies\foundation.graph ..\sysdyn_ontologies\sysdyn.graph ..\modeling_ontologies\modeling.graph ..\modeling_ontologies\devs.graph ..\webmon_ontologies\webmon.graph
\ No newline at end of file
index ab012257bf81c96e80f97f0c7945d67dae12a2fc..97cae434e1fb788aeabb58806f497c25b0720139 100644 (file)
@@ -49,9 +49,14 @@ HasY <R L0.HasProperty : L0.FunctionalRelation
     L0.HasRange L0.Double        \r
 HasExpression <R L0.IsRelatedTo : L0.FunctionalRelation\r
     L0.HasRange Expression\r
-\r
+    \r
+HasType <R L0.HasProperty\r
+    L0.HasRange L0.String\r
+    \r
 IndependentVariable <T Variable\r
     [L0.HasName card "1"]\r
+    [HasType card "1"]\r
+    \r
 \r
 Auxiliary <T IndependentVariable\r
     [HasExpression card "0..1"]\r
@@ -88,14 +93,23 @@ Flow <T ST.Connection
 # Expression\r
 ######################################################################\r
     \r
-HasText <R L0.HasProperty\r
+HasEquation <R L0.HasProperty\r
+    L0.HasRange L0.String  \r
+    \r
+HasInitialEquation <R L0.HasProperty\r
     L0.HasRange L0.String  \r
     \r
 Expression <T L0.Entity\r
 \r
 NormalExpression <T Expression\r
-    [HasText card "1"]    \r
+    [HasEquation card "1"]    \r
     \r
+ParameterExpression <T Expression\r
+    [HasEquation card "1"]   \r
+\r
+StockExpression <T Expression\r
+    [HasInitialEquation card "1"]\r
+  \r
 ######################################################################\r
 # Test configuration\r
 ######################################################################\r