]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Changed UI to support new ontology with array variables and multiple expressions.
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 2 Dec 2010 12:58:11 +0000 (12:58 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 2 Dec 2010 12:58:11 +0000 (12:58 +0000)
Some UI components added to support using array variables, but they are incomplete and buggy.
MODEL CANNOT BE SIMULATED IF ARRAYS ARE USED!

If array variables are not used, the software should function the way it did before.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@18898 ac1ea38d-2e2b-0410-8846-a27921b304fc

37 files changed:
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultVariable.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableInformationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/VariableNameUtils.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartTableWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ChartWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionTypes.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ExpressionWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ShortcutTabWidget.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/AvailableEnumerations.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/Keys.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerations.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/BasicExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionUtils.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/IExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/WithLookupExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/factories/VariableNamePropertyModifier.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ArrayIndexes.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Enumeration.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java
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
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expressions.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java

index f03840181ac87225049c77bc4f9991e75ff5a663..c911739908aeac56f548acd47f20c10ddb8793df 100644 (file)
             name="System dynamics">\r
       </perspective>\r
    </extension>\r
+   <extension\r
+         point="org.eclipse.ui.perspectiveExtensions">\r
+      <perspectiveExtension\r
+            targetID="org.simantics.sysdyn.ui.perspective">\r
+         <view\r
+               id="org.simantics.browsing.ui.graph.propertyView"\r
+               ratio="0.75f"\r
+               relationship="bottom"\r
+               relative="org.eclipse.ui.editorss">\r
+         </view>\r
+         <view\r
+               id="org.eclipse.ui.console.ConsoleView"\r
+               minimized="false"\r
+               relationship="stack"\r
+               relative="org.simantics.browsing.ui.graph.propertyView">\r
+         </view>\r
+         <view\r
+               id="org.simantics.sysdyn.ui.trend.view"\r
+               ratio="0.4f"\r
+               relationship="left"\r
+               relative="org.simantics.browsing.ui.graph.propertyView">\r
+         </view>\r
+         <view\r
+               id="org.simantics.sysdyn.ui.dependencies.view"\r
+               minimized="false"\r
+               relationship="stack"\r
+               relative="org.simantics.sysdyn.ui.trend.view">\r
+         </view>\r
+         <view\r
+               id="org.simantics.sysdyn.ui.browser"\r
+               ratio="0.25f"\r
+               relationship="left"\r
+               relative="org.eclipse.ui.editorss">\r
+         </view>\r
+         <view\r
+               id="org.simantics.diagram.symbollibrary"\r
+               minimized="false"\r
+               relationship="stack"\r
+               relative="org.simantics.sysdyn.ui.browser">\r
+         </view>\r
+         <view\r
+               id="org.simantics.sysdyn.ui.values.view"\r
+               relationship="stack"\r
+               relative="org.simantics.sysdyn.ui.trend.view">\r
+         </view>\r
+         \r
+      </perspectiveExtension>\r
+   </extension>\r
+   <extension\r
+         point="org.eclipse.ui.contexts">\r
+      <context\r
+            id="org.simantics.sysdyn.ui.basicExperiment"\r
+            name="Basic Experiment">\r
+      </context>\r
+   </extension>\r
    <extension\r
          point="org.eclipse.ui.menus">\r
       <menuContribution\r
          </activeWhen>\r
       </handler>\r
    </extension>\r
-   <extension\r
-         point="org.eclipse.ui.cheatsheets.cheatSheetContent">\r
-      <category\r
-            id="org.simantics.sysdyn.ui.category"\r
-            name="System Dynamics">\r
-      </category>\r
-      <cheatsheet\r
-            category="org.simantics.sysdyn.ui.category"\r
-            composite="false"\r
-            contentFile="$nl$/cheatsheet/tutorial.xml"\r
-            id="org.simantics.sysdyn.ui.cheatsheet1"\r
-            name="Simple System Dynamics Tutorial">\r
-         <description>\r
-            Simple System Dynamics Tutorials\r
-         </description>\r
-      </cheatsheet>\r
-   </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
       <binding\r
         <implementation class="org.simantics.sysdyn.ui.property.OperationModelContributor" preference="1.0"/>\r
         <implementation class="org.simantics.sysdyn.ui.property.OperationVariableContributor" preference="1.0"/>\r
       </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/AvailableVariableIndexes">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.AvailableEnumerations"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/UsedVariableIndexes">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.UsedEnumerations"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.labelerBinding">\r
         <implementation class="org.simantics.sysdyn.ui.property.OperationModelLabels" preference="1.0"/>\r
         <implementation class="org.simantics.sysdyn.ui.property.OperationVariableLabels" preference="1.0"/>\r
       </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/AvailableVariableIndexes">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationLabeler"\r
+               preference="1.0">\r
+         </implementation>\r
+      </binding>\r
+      <binding\r
+            browseContext="http://www.simantics.org/Sysdyn-1.0/UsedVariableIndexes">\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.properties.widgets.arrays.EnumerationLabeler"\r
+               preference="2.0">\r
+         </implementation>\r
+      </binding>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.imagerBinding">\r
       </propertyTester>\r
    </extension>\r
    <extension\r
-         point="org.eclipse.ui.contexts">\r
-      <context\r
-            id="org.simantics.sysdyn.ui.basicExperiment"\r
-            name="Basic Experiment">\r
-      </context>\r
+         point="org.eclipse.ui.cheatsheets.cheatSheetContent">\r
+      <category\r
+            id="org.simantics.sysdyn.ui.category"\r
+            name="System Dynamics">\r
+      </category>\r
+      <cheatsheet\r
+            category="org.simantics.sysdyn.ui.category"\r
+            composite="false"\r
+            contentFile="$nl$/cheatsheet/tutorial.xml"\r
+            id="org.simantics.sysdyn.ui.cheatsheet1"\r
+            name="Simple System Dynamics Tutorial">\r
+         <description>\r
+            Simple System Dynamics Tutorials\r
+         </description>\r
+      </cheatsheet>\r
+   </extension>\r
+   <extension\r
+         point="org.simantics.ui.doubleClick">\r
+      <doubleClickAction\r
+            class="org.simantics.sysdyn.ui.actions.ActivateExperimentAction"\r
+            name="Activate Sysdyn Experiment"\r
+            priority="300.0">\r
+      </doubleClickAction>\r
+      <doubleClickAction\r
+            class="org.simantics.sysdyn.ui.actions.ConsumeUnnecessaryEntersAction"\r
+            name="Consume unnecessary enters"\r
+            priority="200.0">\r
+      </doubleClickAction>\r
+      <doubleClickAction\r
+            class="org.simantics.sysdyn.ui.actions.ShowInstantiatedModuleAction"\r
+            name="Consume unnecessary enters"\r
+            priority="100.0">\r
+      </doubleClickAction>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.selectionProcessorBinding">\r
          </implementation>\r
       </binding>\r
    </extension>\r
-   <extension\r
-         point="org.eclipse.ui.perspectiveExtensions">\r
-      <perspectiveExtension\r
-            targetID="org.simantics.sysdyn.ui.perspective">\r
-         <view\r
-               id="org.simantics.browsing.ui.graph.propertyView"\r
-               ratio="0.75f"\r
-               relationship="bottom"\r
-               relative="org.eclipse.ui.editorss">\r
-         </view>\r
-         <view\r
-               id="org.eclipse.ui.console.ConsoleView"\r
-               minimized="false"\r
-               relationship="stack"\r
-               relative="org.simantics.browsing.ui.graph.propertyView">\r
-         </view>\r
-         <view\r
-               id="org.simantics.sysdyn.ui.trend.view"\r
-               relationship="left"\r
-               relative="org.simantics.browsing.ui.graph.propertyView">\r
-         </view>\r
-         <view\r
-               id="org.simantics.sysdyn.ui.dependencies.view"\r
-               minimized="false"\r
-               relationship="stack"\r
-               relative="org.simantics.sysdyn.ui.trend.view">\r
-         </view>\r
-         <view\r
-               id="org.simantics.sysdyn.ui.browser"\r
-               ratio="0.25f"\r
-               relationship="left"\r
-               relative="org.eclipse.ui.editorss">\r
-         </view>\r
-         <view\r
-               id="org.simantics.diagram.symbollibrary"\r
-               minimized="false"\r
-               relationship="stack"\r
-               relative="org.simantics.sysdyn.ui.browser">\r
-         </view>\r
-         <view\r
-               id="org.simantics.sysdyn.ui.values.view"\r
-               relationship="stack"\r
-               relative="org.simantics.sysdyn.ui.trend.view">\r
-         </view>\r
-         \r
-      </perspectiveExtension>\r
-   </extension>\r
    <extension\r
          id="product"\r
          point="org.eclipse.core.runtime.products">\r
             label="System Dynamics ontology dependencies">\r
       </feature>\r
    </extension>\r
-   <extension\r
-         point="org.simantics.ui.doubleClick">\r
-      <doubleClickAction\r
-            class="org.simantics.sysdyn.ui.actions.ActivateExperimentAction"\r
-            name="Activate Sysdyn Experiment"\r
-            priority="300.0">\r
-      </doubleClickAction>\r
-      <doubleClickAction\r
-            class="org.simantics.sysdyn.ui.actions.ConsumeUnnecessaryEntersAction"\r
-            name="Consume unnecessary enters"\r
-            priority="200.0">\r
-      </doubleClickAction>\r
-      <doubleClickAction\r
-            class="org.simantics.sysdyn.ui.actions.ShowInstantiatedModuleAction"\r
-            name="Consume unnecessary enters"\r
-            priority="100.0">\r
-      </doubleClickAction>\r
-   </extension>\r
 </plugin>\r
index b4ff4c4196a736323eae6d66670a41043808e646..265f2a8a05a1f23abc07bb7096d0304bc9d9865c 100644 (file)
@@ -35,7 +35,7 @@ public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{
                                SysdynResource sr = SysdynResource.getInstance(graph);\r
                                try {\r
                                        if(graph.isInstanceOf(statement.getSubject(), sr.IndependentVariable)) {\r
-                                               if(statement.getPredicate().equals(sr.HasExpression))\r
+                                               if(statement.getPredicate().equals(sr.HasExpressions))\r
                                                        return true;\r
                                        }\r
                                } catch (ServiceException e) {\r
index 19011dfa4b6c9625bb5094c32ab0d98afd5457e5..54608589c37aca2e93a0577ef9d85d6b252e34e8 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.project;\r
 \r
+import java.util.List;\r
+\r
 import org.simantics.databoard.binding.Binding;\r
 import org.simantics.databoard.binding.java.DoubleBindingDefault;\r
 import org.simantics.databoard.binding.java.StringBindingDefault;\r
@@ -20,6 +22,7 @@ import org.simantics.databoard.type.DoubleType;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.ResourceVariable;\r
 import org.simantics.layer0.Layer0;\r
@@ -38,7 +41,11 @@ public class DefaultVariable extends ResourceVariable {
                SysdynResource sr = SysdynResource.getInstance(graph);\r
                Resource represents = graph.getPossibleObject(resource, b.Represents);\r
                if(represents == null) return null;\r
-               Resource expression = graph.getPossibleObject(represents, sr.HasExpression);\r
+               //FIXME: doesn't support multiple expressions\r
+               Resource expressions = graph.getPossibleObject(represents, sr.HasExpressions);\r
+               if(expressions == null) return null;\r
+               List<Resource> expressionList = OrderedSetUtils.toList(graph, expressions);\r
+               Resource expression = expressionList.get(0);\r
                if(expression == null) return null;\r
                if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return null;\r
                String text = graph.getPossibleRelatedValue(expression, sr.HasEquation);\r
@@ -61,7 +68,11 @@ public class DefaultVariable extends ResourceVariable {
 //             if(!MutableDoubleBinding.INSTANCE.equals(binding)) return;\r
                Resource represents = graph.getPossibleObject(resource, l0.Represents);\r
                if(represents == null) return;\r
-               Resource expression = graph.getPossibleObject(represents, sr.HasExpression);\r
+               //FIXME: doesn't support multiple expressions\r
+               Resource expressions = graph.getPossibleObject(represents, sr.HasExpressions);\r
+               if(expressions == null) return;\r
+               List<Resource> expressionList = OrderedSetUtils.toList(graph, expressions);\r
+               Resource expression = expressionList.get(0);\r
                if(expression == null) return;\r
                if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return;\r
                Double value = new Double(((MutableDouble)object).doubleValue());\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ArrayIndexesTab.java
new file mode 100644 (file)
index 0000000..40572ed
--- /dev/null
@@ -0,0 +1,220 @@
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\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.Tree;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
+import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.arrays.Keys;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+\r
+public class ArrayIndexesTab extends PropertyTabContributorImpl {\r
+\r
+       GraphExplorerComposite availableEnumerationsExplorer;\r
+       GraphExplorerComposite usedEnumerationsExplorer;\r
+       \r
+       @Override\r
+       public void createControls(Composite body, IWorkbenchSite site,\r
+                       ISessionContext context, WidgetSupport support) {\r
+               \r
+               GridLayoutFactory.fillDefaults().numColumns(4).applyTo(body);\r
+               \r
+               \r
+               Composite available = new Composite(body, SWT.NONE);\r
+               GridLayoutFactory.fillDefaults().applyTo(available);\r
+               GridDataFactory.fillDefaults().grab(true, true).applyTo(available);\r
+               Label label = new Label(available, SWT.None);\r
+               label.setText("Available Enumerations");\r
+               availableEnumerationsExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                               "displaySelectors", "displayFilter").values(false, false), site, available, support, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI);\r
+               \r
+               availableEnumerationsExplorer\r
+               .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/AvailableVariableIndexes");\r
+               availableEnumerationsExplorer.setColumns(Keys.ENUMERATION_TABLE_COLUMNS);\r
+               availableEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
+                               Resource.class));\r
+\r
+               availableEnumerationsExplorer.finish();\r
+\r
+               GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                               availableEnumerationsExplorer);\r
+               \r
+               Control c = availableEnumerationsExplorer.getExplorerControl();\r
+               if (c instanceof Tree)\r
+                       ((Tree) c).setLinesVisible(true);\r
+               \r
+               \r
+               Button add = new Button(body, support, SWT.NONE);\r
+               add.setText(" -> ");\r
+               \r
+               add.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+                       @Override\r
+                       public void apply(WriteGraph graph, Resource input)\r
+                                       throws DatabaseException {\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes);\r
+\r
+                               List<Resource> enumerationResources = getSelectedResources(availableEnumerationsExplorer);\r
+                               \r
+                               if(arrayIndexes == null) {\r
+                                       arrayIndexes = OrderedSetUtils.create(graph, sr.ArrayIndexes, enumerationResources);\r
+                                       graph.claim(input, sr.HasArrayIndexes, arrayIndexes);\r
+                               } else {\r
+                                       OrderedSetUtils.addAll(graph, arrayIndexes, enumerationResources);\r
+                               }\r
+                               \r
+                               \r
+                       }\r
+               });\r
+               \r
+               Composite used = new Composite(body, SWT.NONE);\r
+               GridLayoutFactory.fillDefaults().applyTo(used);\r
+               GridDataFactory.fillDefaults().grab(true, true).applyTo(used);\r
+               label = new Label(used, SWT.None);\r
+               label.setText("Used Enumerations");\r
+               \r
+               usedEnumerationsExplorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                               "displaySelectors", "displayFilter").values(false, false), site, used, support, SWT.FULL_SELECTION | SWT.BORDER);\r
+               \r
+               usedEnumerationsExplorer\r
+               .setBrowseContexts("http://www.simantics.org/Sysdyn-1.0/UsedVariableIndexes");\r
+               usedEnumerationsExplorer.setColumns(Keys.ENUMERATION_TABLE_COLUMNS);\r
+               usedEnumerationsExplorer.setInputSource(new SingleSelectionInputSource(\r
+                               Resource.class));\r
+\r
+               usedEnumerationsExplorer.finish();\r
+\r
+               GridDataFactory.fillDefaults().grab(true, true).applyTo(\r
+                               usedEnumerationsExplorer);\r
+               \r
+               Control c2 = usedEnumerationsExplorer.getExplorerControl();\r
+               if (c2 instanceof Tree)\r
+                       ((Tree) c2).setLinesVisible(true);\r
+               \r
+               Composite buttons = new Composite(body, SWT.None);\r
+               GridLayoutFactory.fillDefaults().applyTo(buttons);\r
+               \r
+               Button up = new Button(buttons, support, SWT.NONE);\r
+               up.setText("Up");\r
+               up.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+                       @Override\r
+                       public void apply(WriteGraph graph, Resource input)\r
+                                       throws DatabaseException {\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes);\r
+                               if(arrayIndexes == null)\r
+                                       return;\r
+                               \r
+                               List<Resource> enumerationResources = getSelectedResources(usedEnumerationsExplorer);\r
+                               if(enumerationResources.size() != 1)\r
+                                       return;\r
+                               Resource enumeration = enumerationResources.get(0);\r
+                               Resource prev = OrderedSetUtils.prev(graph, arrayIndexes, enumeration);\r
+                               if(prev.equals(arrayIndexes))\r
+                                       return;\r
+                               \r
+                               OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
+                               OrderedSetUtils.addBefore(graph, arrayIndexes, prev, enumeration);\r
+                       }\r
+               });\r
+               \r
+               Button down = new Button(buttons, support, SWT.NONE);\r
+               down.setText("Down");\r
+               down.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+                       @Override\r
+                       public void apply(WriteGraph graph, Resource input)\r
+                                       throws DatabaseException {\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes);\r
+                               if(arrayIndexes == null)\r
+                                       return;\r
+                               \r
+                               List<Resource> enumerationResources = getSelectedResources(usedEnumerationsExplorer);\r
+                               if(enumerationResources.size() != 1)\r
+                                       return;\r
+                               Resource enumeration = enumerationResources.get(0);\r
+                               Resource next = OrderedSetUtils.next(graph, arrayIndexes, enumeration);\r
+                               if(next.equals(arrayIndexes))\r
+                                       return;\r
+                               OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
+                               OrderedSetUtils.addAfter(graph, arrayIndexes, next, enumeration);\r
+                       }\r
+               });\r
+               \r
+               \r
+               Button remove = new Button(buttons, support, SWT.NONE);\r
+               remove.setText("Remove");\r
+               remove.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+                       @Override\r
+                       public void apply(WriteGraph graph, Resource input)\r
+                                       throws DatabaseException {\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes);\r
+                               if(arrayIndexes == null)\r
+                                       return;\r
+                               \r
+                               List<Resource> enumerationResources = getSelectedResources(usedEnumerationsExplorer);\r
+                               if(enumerationResources.size() != 1)\r
+                                       return;\r
+                               Resource enumeration = enumerationResources.get(0);\r
+                               OrderedSetUtils.remove(graph, arrayIndexes, enumeration);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       \r
+       private List<Resource> getSelectedResources(GraphExplorerComposite explorer) {\r
+               List<Resource> result = new ArrayList<Resource>();\r
+               \r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return result;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               @SuppressWarnings("unchecked")\r
+               List<AdaptableHintContext> selections = iss.toList();\r
+               for(AdaptableHintContext ahc : selections) {\r
+                       Resource resource = (Resource) ahc.getAdapter(Resource.class);\r
+                       result.add(resource);\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       private NodeContext getSelectedNodeContext(GraphExplorerComposite explorer) {\r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return null;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               AdaptableHintContext ahc = (AdaptableHintContext)iss.getFirstElement();\r
+               if(ahc == null) \r
+                       return null;\r
+               NodeContext ctx = (NodeContext)ahc.getAdapter(NodeContext.class);\r
+               return ctx;\r
+       }\r
+\r
+}\r
index 67cd6ffa97f95760378ef1d85290b44275e9e2b8..6e1af6e98434077790d02183d773e72b80b64cad 100644 (file)
@@ -13,10 +13,13 @@ package org.simantics.sysdyn.ui.properties;
 \r
 import java.util.Collection;\r
 import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
 import java.util.Map;\r
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.StructuredSelection;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.custom.StyledText;\r
 import org.eclipse.swt.custom.VerifyKeyListener;\r
@@ -36,75 +39,319 @@ import org.eclipse.ui.IWorkbenchPartReference;
 import org.eclipse.ui.IWorkbenchSite;\r
 import org.simantics.browsing.ui.platform.PropertyPageView;\r
 import org.simantics.browsing.ui.swt.PropertyTabContributorImpl;\r
-import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
-import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
 import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
 import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
+import org.simantics.db.AsyncReadGraph;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.VirtualGraph;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.request.WriteResultRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.procedure.AsyncListener;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.db.service.VirtualGraphSupport;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.ArrayExpressionCombo;\r
 import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes;\r
+import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType;\r
 import org.simantics.sysdyn.ui.properties.widgets.ExpressionWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.ShortcutTabWidget;\r
-import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType;\r
-import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
-import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
 \r
-public class EquationTab extends PropertyTabContributorImpl {\r
+public class EquationTab extends PropertyTabContributorImpl implements Widget {\r
 \r
-       TrackedCombo expressionTypeCombo, unitCombo;\r
+       TrackedCombo expressionTypeCombo, unitCombo, arrayEquationCombo;\r
        ShortcutTabWidget shortcutTabWidget;\r
        ExpressionWidget expressionWidget;\r
        org.eclipse.ui.IPartListener2 focusLostListener;  \r
        IWorkbenchSite site;\r
+       WidgetSupport support;\r
+       Button deleteExpression, newExpression;\r
+\r
+       WidgetSupportImpl expressionSupport = new WidgetSupportImpl();\r
 \r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
                this.site = site;\r
+               this.support = support;\r
+               support.register(this);\r
+\r
                Composite composite = new Composite(body, SWT.NONE);\r
                GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
-               GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(6).applyTo(composite);\r
-               TrackedText nameText = new TrackedText(composite, support, SWT.BORDER);\r
+               GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite);\r
+\r
+               Composite nameAndEquations = new Composite(composite, SWT.NONE);\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(nameAndEquations);\r
+               GridLayoutFactory.fillDefaults().numColumns(2).applyTo(nameAndEquations);\r
+\r
+               Composite nameComposite = new Composite(nameAndEquations, SWT.NONE);\r
+               GridLayoutFactory.fillDefaults().numColumns(3).applyTo(nameComposite);\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(nameComposite);\r
+\r
+               arrayEquationCombo =  new ArrayExpressionCombo(nameComposite, support, SWT.DROP_DOWN | SWT.BORDER);\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(arrayEquationCombo.getWidget());\r
+\r
+               deleteExpression = new Button(nameComposite, support, SWT.NONE);\r
+               deleteExpression.setText("Delete");\r
+               GridDataFactory.fillDefaults().applyTo(deleteExpression.getWidget());\r
+\r
+               newExpression = new Button(nameComposite, support, SWT.NONE);\r
+               newExpression.setText("New");\r
+               GridDataFactory.fillDefaults().applyTo(newExpression.getWidget());\r
+               /*\r
+               TrackedText nameText = new TrackedText(nameAndEquations, support, SWT.BORDER);\r
                nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasName));\r
                nameText.addModifyListener(new VariableNamePropertyModifier(context, Layer0.URIs.HasName));\r
                nameText.setInputValidator(new VariableNameValidator(support));\r
-               GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget());\r
+               GridDataFactory.fillDefaults().grab(true, false).span(2,1).applyTo(nameText.getWidget());\r
+                */\r
 \r
+               shortcutTabWidget = new ShortcutTabWidget(composite, support, SWT.NONE);\r
+               GridDataFactory.fillDefaults().span(1, 3).grab(false, true).applyTo(shortcutTabWidget.getWidget());\r
 \r
-               Label label = new Label(composite, SWT.SINGLE );\r
+\r
+               Composite TypeAndUnit = new Composite(composite, SWT.NONE);\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(TypeAndUnit);\r
+               GridLayoutFactory.fillDefaults().numColumns(5).applyTo(TypeAndUnit);\r
+\r
+               Label label = new Label(TypeAndUnit, SWT.SINGLE );\r
                label.setText("Type:");\r
                GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
 \r
-               expressionTypeCombo = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
-\r
+               expressionTypeCombo = new TrackedCombo(TypeAndUnit, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
+               GridDataFactory.fillDefaults().applyTo(expressionTypeCombo.getWidget());\r
 \r
-               label = new Label(composite, SWT.SINGLE );\r
+               label = new Label(TypeAndUnit, SWT.SINGLE );\r
                label.setText("Unit:");\r
                GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
 \r
 \r
-               unitCombo = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER);\r
+               unitCombo = new TrackedCombo(TypeAndUnit, support, SWT.DROP_DOWN | SWT.BORDER);\r
+               GridDataFactory.fillDefaults().applyTo(unitCombo.getWidget());\r
 \r
-               shortcutTabWidget = new ShortcutTabWidget(composite, support, SWT.NONE);\r
+               IsOutputWidget isOutput = new IsOutputWidget(TypeAndUnit, support, SWT.NULL);\r
+               GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.FILL).applyTo(isOutput.getWidget());\r
 \r
 \r
                Composite expressionComposite = new Composite(composite, SWT.NONE);\r
-               GridDataFactory.fillDefaults().grab(true, true).span(5, 1).applyTo(expressionComposite);\r
-               expressionWidget = new ExpressionWidget(expressionComposite, support, SWT.NONE);\r
+               GridDataFactory.fillDefaults().grab(true, true).applyTo(expressionComposite);\r
+               expressionWidget = new ExpressionWidget(expressionComposite, expressionSupport, SWT.NONE);\r
                expressionWidget.setVariableTable(shortcutTabWidget.getVariableTable());\r
 \r
-               addListeners();\r
+               addListeners(context);\r
+       }\r
+\r
+       @Override\r
+       public void setInput(ISessionContext context, final Object input) {\r
+               final Resource variable = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+               Resource expression = null;\r
+               try {\r
+                       expression = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
+\r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+                                       return getActiveExpression(graph, AdaptionUtils.adaptToSingle(input, Resource.class));\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               // No expressions -> creating a new ordered set expressions and the active expression\r
+               if(expression == null && variable != null) {\r
+                       try {\r
+                               expression = SimanticsUI.getSession().syncRequest(new WriteResultRequest<Resource>() {\r
+\r
+                                       @Override\r
+                                       public Resource perform(WriteGraph graph)\r
+                                       throws DatabaseException {\r
+                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                               Layer0 l0 = Layer0.getInstance(graph);\r
+                                               Resource expressions = OrderedSetUtils.create(graph, sr.Expressions);\r
+                                               graph.claim(variable, sr.HasExpressions, expressions);\r
+                                               final Resource expression = graph.newResource();\r
+\r
+                                               if(graph.isInstanceOf(variable, sr.Auxiliary) ||\r
+                                                               graph.isInstanceOf(variable, sr.Valve)) {\r
+                                                       graph.claim(expression, l0.InstanceOf, null, sr.NormalExpression);\r
+                                                       graph.claimLiteral(expression, sr.HasEquation, "");\r
+                                               }\r
+                                               else if(graph.isInstanceOf(variable, sr.Stock)) {\r
+                                                       graph.claim(expression, l0.InstanceOf, null, sr.StockExpression);\r
+                                                       graph.claimLiteral(expression, sr.HasInitialEquation, "");\r
+                                               }\r
+                                               OrderedSetUtils.add(graph, expressions, expression);\r
+\r
+                                               VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
+                                               final Session session = graph.getSession();\r
+                                               session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) {\r
+                                                       @Override\r
+                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                               VirtualGraph runtime = graph.getService(VirtualGraph.class);\r
+                                                               session.asyncRequest(new WriteRequest(runtime) {\r
+                                                                       @Override\r
+                                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                                                               graph.claim(variable, sr.HasActiveExpression, expression);\r
+                                                                       }\r
+                                                               }\r
+                                                               );\r
+                                                       }\r
+                                               });\r
+                                               return expression;\r
+                                       }\r
+                               });\r
+                       } catch (DatabaseException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+\r
+\r
+               SimanticsUI.getSession().asyncRequest(new Read<Pair<Boolean, Boolean>>() {\r
+\r
+                       @Override\r
+                       public Pair<Boolean, Boolean> perform(ReadGraph graph) throws DatabaseException {\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Resource expressions = graph.getPossibleObject(variable, sr.HasExpressions);\r
+                               if(expressions == null) {\r
+                                       return new Pair<Boolean, Boolean>(false, false);\r
+                               }\r
+                               List<Resource> expressionList = OrderedSetUtils.toList(graph, expressions);\r
+                               if(expressionList.isEmpty()) {\r
+                                       return new Pair<Boolean, Boolean>(false, false);\r
+                               }\r
+\r
+                               boolean canAdd = true;\r
+                               boolean canDelete = false;\r
+                               if(expressionList.size() > 1)\r
+                                       canDelete = true;\r
+                               String defaultRange = ArrayExpressionCombo.getDefaultRange(graph, variable);\r
+\r
+                               for(Resource expression : expressionList) {\r
+                                       String range = graph.getPossibleRelatedValue(expression, sr.HasArrayRange);\r
+                                       if(range == null || range.equals("") || range.equals(defaultRange)) {\r
+                                               canAdd = false;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               return new Pair<Boolean, Boolean>(canAdd, canDelete);\r
+                       }\r
+               }, new AsyncListener<Pair<Boolean, Boolean>>() {\r
+\r
+                       @Override\r
+                       public void execute(AsyncReadGraph graph,\r
+                                       final Pair<Boolean, Boolean> result) {\r
+                               newExpression.getWidget().getDisplay().asyncExec(new Runnable() {\r
+                                       \r
+                                       @Override\r
+                                       public void run() {\r
+                                               if(!newExpression.getWidget().isDisposed())\r
+                                                       newExpression.getWidget().setEnabled(result.first);\r
+                                               if(!deleteExpression.getWidget().isDisposed())\r
+                                                       deleteExpression.getWidget().setEnabled(result.second);                                         \r
+                                       }\r
+                               });\r
+\r
+                       }\r
+\r
+                       @Override\r
+                       public void exception(AsyncReadGraph graph, Throwable throwable) {\r
+                               throwable.printStackTrace();\r
+                       }\r
+\r
+                       @Override\r
+                       public boolean isDisposed() {\r
+                               return newExpression.getWidget().isDisposed() || deleteExpression.getWidget().isDisposed();\r
+                       }\r
+               });\r
+\r
+               StructuredSelection ss = new StructuredSelection(expression);\r
+               expressionSupport.fireInput(context, ss);\r
        }\r
 \r
-       private void addListeners() {\r
+       private void addListeners(ISessionContext context) {\r
+\r
+               deleteExpression.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+                       @Override\r
+                       public void apply(WriteGraph graph, final Resource input)\r
+                       throws DatabaseException {\r
+\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression);\r
+                               if(activeExpression == null)\r
+                                       return;\r
+\r
+                               Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, activeExpression);\r
+                               if(OrderedSetUtils.toList(graph, expressionList).size() <= 1)\r
+                                       return;\r
+\r
+                               Resource prev = OrderedSetUtils.prev(graph, expressionList, activeExpression);\r
+                               OrderedSetUtils.remove(graph, expressionList, activeExpression);\r
+                               if(prev.equals(expressionList)) {\r
+                                       Iterator<Resource> iterator = OrderedSetUtils.iterator(graph, expressionList);\r
+                                       prev = iterator.next();\r
+                               }\r
+\r
+                               final Resource newActive = prev;\r
+                               VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
+                               final Session session = graph.getSession();\r
+                               session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) {\r
+                                       @Override\r
+                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                               VirtualGraph runtime = graph.getService(VirtualGraph.class);\r
+                                               session.asyncRequest(new WriteRequest(runtime) {\r
+                                                       @Override\r
+                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                                               if(graph.hasStatement(input, sr.HasActiveExpression))\r
+                                                                       graph.deny(input, sr.HasActiveExpression);\r
+                                                               graph.claim(input, sr.HasActiveExpression, newActive);\r
+                                                       }\r
+                                               }\r
+                                               );\r
+                                       }\r
+                               });\r
+                       }\r
+               });\r
+\r
+               newExpression.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+                       @Override\r
+                       public void apply(WriteGraph graph, Resource input)\r
+                       throws DatabaseException {\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+                               Resource expressions = graph.getPossibleObject(input, sr.HasExpressions);\r
+                               if(expressions == null) {\r
+                                       return;\r
+                               }\r
+                               Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression);\r
+                               Resource newExpression = graph.newResource();\r
+                               if(activeExpression != null)\r
+                                       graph.claim(newExpression, l0.InstanceOf, graph.getSingleObject(activeExpression, l0.InstanceOf));\r
+                               else \r
+                                       graph.claim(newExpression, l0.InstanceOf, sr.NormalExpression);\r
+                               OrderedSetUtils.add(graph, expressions, newExpression);\r
+                       }\r
+               });\r
 \r
                expressionTypeCombo.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
 \r
@@ -135,7 +382,10 @@ public class EquationTab extends PropertyTabContributorImpl {
 \r
                        @Override\r
                        public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
-                               return ExpressionTypes.getExpressionTypeForVariable(graph, input).toString();\r
+                               Resource activeExpression = getActiveExpression(graph, input);\r
+                               if(activeExpression == null)\r
+                                       return null;\r
+                               return ExpressionTypes.getExpressionType(graph, activeExpression).toString();\r
                        }\r
                });\r
 \r
@@ -293,4 +543,21 @@ public class EquationTab extends PropertyTabContributorImpl {
                        site.getPage().removePartListener(focusLostListener);\r
                super.dispose();\r
        }\r
+\r
+       private Resource getActiveExpression(ReadGraph graph, Resource variable) throws DatabaseException {\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Resource expression = graph.getPossibleObject(variable, sr.HasActiveExpression);\r
+               if(expression == null) {\r
+                       Resource expressions = graph.getPossibleObject(variable, sr.HasExpressions);\r
+                       if(expressions == null) {\r
+                               return null;\r
+                       }\r
+                       List<Resource> expressionList = OrderedSetUtils.toList(graph, expressions);\r
+                       if(expressionList.isEmpty()) {\r
+                               return null;\r
+                       }\r
+                       expression = expressionList.get(0);\r
+               }\r
+               return expression;\r
+       }\r
 }\r
index 1bb77cb0ae9bed57d802bb024757e9d0d12a1387..57ac1c52405a5bb92b73f195977cd0c3e6824daf 100644 (file)
@@ -14,11 +14,14 @@ package org.simantics.sysdyn.ui.properties;
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.Collections;\r
+import java.util.List;\r
 \r
 import org.simantics.browsing.ui.SelectionProcessor;\r
 import org.simantics.browsing.ui.swt.ComparableTabContributor;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
 import org.simantics.db.exception.ServiceException;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
@@ -51,19 +54,40 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                 }\r
             }\r
             if (backend.isInstanceOf(r, sr.IndependentVariable)) {\r
-                Resource expression = backend.getPossibleObject(r, sr.HasExpression);\r
+\r
+               \r
+               Resource activeExpression = backend.getPossibleObject(r, sr.HasActiveExpression);\r
+               Resource expression = null;\r
+               if(activeExpression != null)\r
+                       expression = activeExpression;\r
+               else if (backend.hasStatement(r, sr.HasExpressions)){\r
+                       Resource expressions = backend.getPossibleObject(r, sr.HasExpressions);\r
+                       List<Resource> expressionList = OrderedSetUtils.toList(backend, expressions);\r
+                       if(expressionList.isEmpty()) {\r
+                               System.err.println("expressionList is empty for " + r);\r
+                               return Collections.emptyList();\r
+                       }\r
+                       expression = expressionList.get(0);\r
+               }\r
                 tabs.add(new ComparableTabContributor(\r
                         new EquationTab(),\r
-                        2,\r
+                        3,\r
                         r,\r
                 "Equation"));\r
                 if(expression != null && backend.isInstanceOf(expression, sr.WithLookupExpression)) {\r
                     tabs.add(new ComparableTabContributor(\r
                             new LookupTableTab(),\r
-                            1,\r
+                            2,\r
                             expression,\r
                     "Lookup Table"));\r
                 }\r
+                \r
+                tabs.add(new ComparableTabContributor(\r
+                        new ArrayIndexesTab(),\r
+                        1,\r
+                        r,\r
+                "Indexes"));\r
+                \r
                 tabs.add(new ComparableTabContributor(\r
                         new VariableInformationTab(),\r
                         0,\r
@@ -164,7 +188,9 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
             e.printStackTrace();\r
         } catch (ManyObjectsForFunctionalRelationException e) {\r
             e.printStackTrace();\r
-        }\r
+        } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
         return Collections.emptyList();\r
     }\r
 }\r
index 122106f18ffe65936acd8262b42e83d70c1a1883..43ce723d4612f6b325dc49bdce033d35ce51a031 100644 (file)
@@ -27,7 +27,6 @@ import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
 import org.simantics.db.Builtins;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 \r
@@ -83,8 +82,6 @@ public class VariableInformationTab extends PropertyTabContributorImpl {
         rangeStep.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(rangeStep.getWidget());\r
 \r
-        new IsOutputWidget(composite, support, SWT.NULL);\r
-\r
     }\r
 \r
     private class DoubleValidator implements IInputValidator {\r
index 5c1a3d76b1c0db1d738a4997ae9ad24508130743..ee10eeec4395be25dbb2dd7b2aef9363f642dd58 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.sysdyn.ui.properties;\r
 \r
 import java.util.HashSet;\r
+import java.util.List;\r
 import java.util.Set;\r
 import java.util.StringTokenizer;\r
 import java.util.regex.Matcher;\r
@@ -20,6 +21,7 @@ import java.util.regex.Pattern;
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
@@ -39,19 +41,26 @@ public class VariableNameUtils {
         * @param newName New name of the variable\r
         */\r
        public static void renameInEquations(WriteGraph graph, Resource variable, String originalName, String newName) throws DatabaseException {\r
+               /*FIXME: \r
+                * How this works when range used in equations has the same string as\r
+                * the renamed variable? Should it be possible? \r
+               */ \r
                Layer0 l0 = Layer0.getInstance(graph);\r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
                Resource configuration = graph.getSingleObject(variable, l0.PartOf);\r
                for(Resource r : graph.getObjects(configuration, l0.ConsistsOf)) {\r
                        if(graph.isInstanceOf(r, sr.IndependentVariable)) {\r
-                               Resource s = graph.getPossibleObject(r, sr.HasExpression);\r
-                               if(s == null) continue;\r
-                               for(Resource p : graph.getPredicates(s)) {\r
-                                       Resource o = graph.getPossibleObject(s, p);\r
-                                       if(o != null && graph.isInstanceOf(o, l0.String)) {\r
-                                               String string = graph.getRelatedValue(s, p);\r
-                                               String replaced  = replaceAllWords(string, originalName, newName);\r
-                                               graph.claimLiteral(s, p, replaced);\r
+                               Resource expressions = graph.getPossibleObject(r, sr.HasExpressions);\r
+                               if(expressions == null) continue;\r
+                               List<Resource> expressionList = OrderedSetUtils.toList(graph, expressions);\r
+                               for(Resource s : expressionList) {\r
+                                       for(Resource p : graph.getPredicates(s)) {\r
+                                               Resource o = graph.getPossibleObject(s, p);\r
+                                               if(o != null && graph.isInstanceOf(o, l0.String) && !p.equals(sr.HasArrayRange)) {\r
+                                                       String string = graph.getRelatedValue(s, p);\r
+                                                       String replaced  = replaceAllWords(string, originalName, newName);\r
+                                                       graph.claimLiteral(s, p, replaced);\r
+                                               }\r
                                        }\r
                                }\r
                        }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java
new file mode 100644 (file)
index 0000000..2a1f6ab
--- /dev/null
@@ -0,0 +1,269 @@
+package org.simantics.sysdyn.ui.properties.widgets;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+import java.util.StringTokenizer;\r
+import java.util.LinkedHashMap;\r
+\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.service.VirtualGraphSupport;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.VariableNameUtils;\r
+\r
+public class ArrayExpressionCombo extends TrackedCombo {\r
+\r
+       int lastSelectedIndex = -2;\r
+\r
+       public ArrayExpressionCombo(Composite parent, WidgetSupport support,\r
+                       int style) {\r
+               super(parent, support, style);\r
+\r
+               /*\r
+               this.setInputValidator(new VariableNameValidator(support));\r
+                */\r
+\r
+               this.setItemFactory(new ReadFactoryImpl<Resource, Map<String, Object>>()  {\r
+\r
+                       @Override\r
+                       public Map<String, Object> perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+                               Map<String, Object> map = new LinkedHashMap<String, Object>();\r
+                               if(input == null) {\r
+                                       return map;\r
+                               }\r
+\r
+                               Layer0 l0 = Layer0.getInstance(graph);\r
+                               String name = graph.getPossibleRelatedValue(input, l0.HasName);\r
+\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+                               String defaultRange = getDefaultRange(graph, input);\r
+                               for(Resource expression : getExpressions(graph, input)) {\r
+                                       String arrayRange = graph.getPossibleRelatedValue(expression, sr.HasArrayRange); \r
+                                       if(arrayRange != null) {\r
+                                               map.put(name + arrayRange, expression);\r
+                                       } else if(defaultRange != null) {\r
+                                               map.put(name + defaultRange, expression);\r
+                                       } else {\r
+                                               map.put(name, expression);\r
+                                       }\r
+                               }\r
+                               if(map.isEmpty()) {\r
+                                       map.put(name, input);\r
+                               }\r
+                               return map;\r
+                       }\r
+\r
+               });\r
+\r
+\r
+               this.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+                       @Override\r
+                       public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+                               String name = graph.getPossibleRelatedValue(input,  Layer0.getInstance(graph).HasName);\r
+\r
+                               String defaultRange = getDefaultRange(graph, input);\r
+                               if(defaultRange == null)\r
+                                       return name;\r
+\r
+                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+                               Resource activeExpression = graph.getPossibleObject(input, sr.HasActiveExpression);\r
+                               Resource expression;\r
+                               if(activeExpression == null) {\r
+                                       ArrayList<Resource> expressions = getExpressions(graph, input);\r
+                                       if(expressions == null || expressions.isEmpty())\r
+                                               return name;\r
+                                       expression = expressions.get(0);\r
+                               } else {\r
+                                       expression = activeExpression;\r
+                               }\r
+                               String range = graph.getPossibleRelatedValue(expression, sr.HasArrayRange);\r
+                               if(range != null)\r
+                                       return name + range;\r
+                               else\r
+                                       return name + defaultRange;\r
+                       }\r
+               });\r
+\r
+               this.addModifyListener(new NameAndArrayRangeModifyListener(support));\r
+       }\r
+\r
+\r
+       @Override\r
+       public void setInput(ISessionContext context, Object input) {\r
+               super.setInput(context, input);\r
+\r
+               if(selectionFactory != null) {\r
+                       selectionFactory.listen(context, input, new Listener<String>() {\r
+\r
+                               @Override\r
+                               public void execute(final String result) {\r
+                                       getWidget().getDisplay().asyncExec(new Runnable() {\r
+                                               \r
+                                               @Override\r
+                                               public void run() {\r
+                                                       Combo combo = getWidget();\r
+                                                       if(combo != null && !combo.isDisposed()) {\r
+                                                               Object o = getWidget().getData(result);\r
+                                                               if(o != null)\r
+                                                                       lastSelectedIndex = (Integer)o;\r
+                                                       }\r
+                                                               \r
+                                               }\r
+                                       });\r
+                               }\r
+\r
+                               @Override\r
+                               public void exception(Throwable t) {\r
+                                       t.printStackTrace();\r
+                               }\r
+\r
+                               @Override\r
+                               public boolean isDisposed() {\r
+                                       return getWidget().isDisposed();\r
+                               }\r
+\r
+                       });\r
+               }\r
+       }\r
+\r
+       private ArrayList<Resource> getExpressions(ReadGraph graph, Resource variable) throws DatabaseException {\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Resource hasExpressions = graph.getPossibleObject(variable, sr.HasExpressions);\r
+               if(hasExpressions == null)\r
+                       return new ArrayList<Resource>();\r
+               else\r
+                       return new ArrayList<Resource>(OrderedSetUtils.toList(graph, hasExpressions));\r
+       }\r
+\r
+       public static String getDefaultRange(ReadGraph graph, Resource variable) throws DatabaseException {\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Resource hasArrayIndexes = graph.getPossibleObject(variable, sr.HasArrayIndexes);\r
+\r
+               if(hasArrayIndexes == null)\r
+                       return null;\r
+\r
+               Iterator<Resource> iterator = OrderedSetUtils.iterator(graph, hasArrayIndexes);\r
+               if(!iterator.hasNext())\r
+                       return null;\r
+\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("[");\r
+\r
+               while(iterator.hasNext()) {\r
+                       sb.append(NameUtils.getSafeName(graph, iterator.next()));\r
+                       if(iterator.hasNext()) {\r
+                               sb.append(", ");\r
+                       }\r
+               }\r
+               sb.append("]");\r
+               return sb.toString();\r
+       }\r
+\r
+       private class NameAndArrayRangeModifyListener extends ComboModifyListenerImpl<Resource> implements Widget {\r
+\r
+               Resource lastExpression; \r
+\r
+               public NameAndArrayRangeModifyListener(WidgetSupport support) {\r
+                       support.register(this);\r
+               }\r
+\r
+               @Override\r
+               public void setInput(ISessionContext context, Object input) {\r
+                       super.setInput(context, input);\r
+               }\r
+\r
+               @Override\r
+               public void modifyText(TrackedModifyEvent e) {\r
+\r
+                       Combo combo = (Combo)e.getWidget();\r
+                       LinkedHashMap<?, ?> data = (LinkedHashMap<?, ?>) combo.getData();\r
+\r
+                       Resource expression = (Resource) data.get(combo.getText());\r
+                       if(expression != null) {\r
+                               lastExpression = expression;\r
+                               lastSelectedIndex = combo.getSelectionIndex();\r
+                       } else {\r
+                               for(Object key : data.keySet()) {\r
+                                       int index = lastSelectedIndex < 0 ? 0 : lastSelectedIndex;\r
+                                       if((Integer)combo.getData((String)key) == index) {\r
+                                               lastExpression =  (Resource) data.get((String)key);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       super.modifyText(e);\r
+               }\r
+\r
+               @Override\r
+               public void applyText(WriteGraph graph, final Resource variable, String text)\r
+               throws DatabaseException {\r
+                       StringTokenizer st = new StringTokenizer(text, "[]");\r
+                       final String newName = st.nextToken();\r
+                       String range = null;\r
+                       if(st.hasMoreTokens()) {\r
+                               range = st.nextToken();\r
+                       }\r
+                       String originalName = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName);\r
+                       if(!originalName.equals(newName)) {\r
+                               VariableNameUtils.renameInEquations(graph, variable, originalName, newName);\r
+                               graph.claimLiteral(variable, Layer0.getInstance(graph).HasName, newName);\r
+                       }\r
+\r
+                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+                       if(range != null && lastExpression != null) {\r
+                               String oldRange = graph.getPossibleRelatedValue(lastExpression, sr.HasArrayRange);\r
+                               if(oldRange == null || !range.equals(oldRange)) {\r
+                                       graph.claimLiteral(lastExpression, sr.HasArrayRange, "[" + range + "]");\r
+                               }\r
+                       }\r
+\r
+                       Resource activeExpression = graph.getPossibleObject(variable, sr.HasActiveExpression);\r
+\r
+                       if(lastExpression != null && !lastExpression.equals(activeExpression)) {\r
+                               VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
+                               final Session session = graph.getSession();\r
+                               session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) {\r
+                                       @Override\r
+                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                               VirtualGraph runtime = graph.getService(VirtualGraph.class);\r
+                                               session.asyncRequest(new WriteRequest(runtime) {\r
+                                                       @Override\r
+                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                                               if(graph.hasStatement(variable, sr.HasActiveExpression))\r
+                                                                       graph.deny(variable, sr.HasActiveExpression);\r
+                                                               graph.claim(variable, sr.HasActiveExpression, lastExpression);\r
+                                                       }\r
+                                               }\r
+                                               );\r
+                                       }\r
+                               });\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
index 4ae9bdce6a8732714f60ba5afb2a1db77e690540..0a5c8bc29053ae550c48c998f62a64317be56128 100644 (file)
@@ -167,8 +167,9 @@ public class ChartTableWidget implements Widget {
                 @Override\r
                 public String perform(ReadGraph graph) throws DatabaseException {\r
                     SysdynResource sr = SysdynResource.getInstance(graph);\r
-                    String lookup = graph.getRelatedValue(expression, sr.HasLookup);\r
-                    return lookup;\r
+                    if(!graph.isInstanceOf(expression, sr.WithLookupExpression))\r
+                       return null;\r
+                    return graph.getRelatedValue(expression, sr.HasLookup);\r
                 }\r
             }, new Listener<String>() {\r
 \r
@@ -179,6 +180,7 @@ public class ChartTableWidget implements Widget {
 \r
                 @Override\r
                 public void execute(String lookup) {\r
+                       if(lookup == null) return;\r
                     TableParser parser = new TableParser(new StringReader(""));\r
                     parser.ReInit(new StringReader(lookup));\r
                     table.clearTable();\r
index 0cbcbd0ab74cc966b6bb6995450a56fd75104819..990bb3de7cd8131e3183ba6e119647f12fc3235b 100644 (file)
@@ -98,8 +98,10 @@ public class ChartWidget implements Widget {
 \r
                 @Override\r
                 public Auxiliary perform(ReadGraph graph) throws DatabaseException {\r
-                    Auxiliary auxiliary = new Auxiliary();\r
-                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                       if(!graph.isInstanceOf(expression, sr.WithLookupExpression))\r
+                               return null;\r
+                       Auxiliary auxiliary = new Auxiliary();\r
                     auxiliary.minX = graph.getRelatedValue(expression, sr.HasMinX);\r
                     auxiliary.maxX = graph.getRelatedValue(expression, sr.HasMaxX);\r
                     auxiliary.minY = graph.getRelatedValue(expression, sr.HasMinY);\r
@@ -116,7 +118,7 @@ public class ChartWidget implements Widget {
 \r
                 @Override\r
                 public void execute(Auxiliary result) {\r
-\r
+                       if(result == null) return;\r
                     XYDataset dataset = createDataset(result.table);\r
                     chartPanel.resetChart(dataset);\r
                     chartPanel.addSeriesChangeListener(new _SeriesChangeListener(expression));\r
index 70210fa9c8e9f6f3400174c13f986951adc7b6b0..967b1ff48f7de18411979afcc4a685c9b84821a5 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.properties.widgets;\r
 \r
+import java.util.List;\r
+\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -20,80 +23,61 @@ import org.simantics.ui.SimanticsUI;
 \r
 public class ExpressionTypes {\r
 \r
-    public static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay, Empty};\r
-\r
-    public static ExpressionType[] auxiliaryExpressions = new ExpressionType[] {\r
-        ExpressionType.Auxiliary, \r
-        ExpressionType.Parameter, \r
-        ExpressionType.Constant, \r
-       // ExpressionType.Lookup, \r
-        ExpressionType.WithLookup};\r
-\r
-    public static ExpressionType[] valveExpressions = new ExpressionType[] {\r
-        ExpressionType.Auxiliary, \r
-        ExpressionType.Parameter, \r
-        ExpressionType.Constant, \r
-        ExpressionType.WithLookup};\r
+       public static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay, Empty};\r
 \r
-    public static ExpressionType[] stockExpressions = new ExpressionType[] {\r
-        ExpressionType.Stock};\r
+       public static ExpressionType[] auxiliaryExpressions = new ExpressionType[] {\r
+               ExpressionType.Auxiliary, \r
+               ExpressionType.Parameter, \r
+               ExpressionType.Constant, \r
+               // ExpressionType.Lookup, \r
+               ExpressionType.WithLookup};\r
 \r
-    public static ExpressionType getExpressionTypeForVariable(final Resource variable) {\r
-        try {\r
-            return SimanticsUI.getSession().syncRequest(new Read<ExpressionType>() {\r
+       public static ExpressionType[] valveExpressions = new ExpressionType[] {\r
+               ExpressionType.Auxiliary, \r
+               ExpressionType.Parameter, \r
+               ExpressionType.Constant, \r
+               ExpressionType.WithLookup};\r
 \r
-                @Override\r
-                public ExpressionType perform(ReadGraph graph) throws DatabaseException {\r
-                    return getExpressionTypeForVariable(graph, variable);\r
-                }\r
-            });\r
-        } catch (DatabaseException e) {\r
-            e.printStackTrace();\r
-            return null;\r
-        }\r
+       public static ExpressionType[] stockExpressions = new ExpressionType[] {\r
+               ExpressionType.Stock};\r
 \r
-    }\r
+       public static ExpressionType getExpressionType(final Resource expression) {\r
+               try {\r
+                       return SimanticsUI.getSession().syncRequest(new Read<ExpressionType>() {\r
 \r
-    public static ExpressionType getExpressionTypeForVariable(ReadGraph graph, final Resource variable) {\r
-        ExpressionType et = null;\r
-        try {\r
-            SysdynResource sr = SysdynResource.getInstance(graph);\r
+                               @Override\r
+                               public ExpressionType perform(ReadGraph graph) throws DatabaseException {\r
+                                       return getExpressionType(graph, expression);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+                       return null;\r
+               }\r
 \r
-            Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
-            if(expression == null) {\r
-                if(graph.isInstanceOf(variable, sr.Auxiliary)) {\r
-                    et = ExpressionType.Auxiliary;\r
-                }\r
-                else if(graph.isInstanceOf(variable, sr.Valve)) {\r
-                    et = ExpressionType.Auxiliary;\r
-                }\r
-                else if(graph.isInstanceOf(variable, sr.Stock)) {\r
-                    et = ExpressionType.Stock;\r
-                } else\r
-                    et = ExpressionType.Empty;\r
-            } else {\r
-                if(graph.isInstanceOf(expression, sr.NormalExpression)) {\r
-                    et = ExpressionType.Auxiliary;\r
-                } else if (graph.isInstanceOf(expression, sr.StockExpression)) {\r
-                    et = ExpressionType.Stock;\r
-                } else if (graph.isInstanceOf(expression, sr.ParameterExpression)) {\r
-                    et = ExpressionType.Parameter;\r
-                } else if (graph.isInstanceOf(expression, sr.ConstantExpression)) {\r
-                    et = ExpressionType.Constant;\r
-                } else if (graph.isInstanceOf(expression, sr.DelayExpression)) {\r
-                    et = ExpressionType.Delay;\r
-                } else if (graph.isInstanceOf(expression, sr.LookupExpression)) {\r
-                    et = ExpressionType.Lookup;\r
-                } else if (graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
-                    et = ExpressionType.WithLookup;\r
-                } else {\r
-                    et =  ExpressionType.Empty;\r
-                }\r
-            }\r
-        } catch (DatabaseException e) {\r
-            e.printStackTrace();\r
-        }\r
-        return et;\r
-    }\r
+       }\r
+       \r
+       public static ExpressionType getExpressionType(ReadGraph graph, final Resource expression) throws DatabaseException {\r
+               ExpressionType et = null;\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               if(graph.isInstanceOf(expression, sr.NormalExpression)) {\r
+                       et = ExpressionType.Auxiliary;\r
+               } else if (graph.isInstanceOf(expression, sr.StockExpression)) {\r
+                       et = ExpressionType.Stock;\r
+               } else if (graph.isInstanceOf(expression, sr.ParameterExpression)) {\r
+                       et = ExpressionType.Parameter;\r
+               } else if (graph.isInstanceOf(expression, sr.ConstantExpression)) {\r
+                       et = ExpressionType.Constant;\r
+               } else if (graph.isInstanceOf(expression, sr.DelayExpression)) {\r
+                       et = ExpressionType.Delay;\r
+               } else if (graph.isInstanceOf(expression, sr.LookupExpression)) {\r
+                       et = ExpressionType.Lookup;\r
+               } else if (graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
+                       et = ExpressionType.WithLookup;\r
+               } else {\r
+                       et =  ExpressionType.Empty;\r
+               }\r
+               return et;\r
+       }\r
 \r
 }\r
index fa4c88a3ef32275aad5d1c879a6848ff00ed4e62..9aec199d984d14c614ac14dfb85b9a5ed410697c 100644 (file)
@@ -14,41 +14,31 @@ package org.simantics.sysdyn.ui.properties.widgets;
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.custom.VerifyKeyListener;\r
 import org.eclipse.swt.events.FocusListener;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.swt.widgets.TableItem;\r
 import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.AuxiliaryExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.ConstantExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.DelayExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.EmptyExpression;\r
-import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionUtils;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.LookupExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.ParameterExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.StockExpression;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.WithLookupExpression;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
 \r
 public class ExpressionWidget implements Widget {\r
     \r
-    private Resource variable;\r
+    private Resource expr;\r
     private Composite parent;\r
     private Map<String, Object> data;\r
     private IExpression expression;\r
@@ -65,27 +55,16 @@ public class ExpressionWidget implements Widget {
     }\r
 \r
     @Override\r
-    public void setInput(ISessionContext context, Object input) {\r
-        if(input instanceof ISelection) {\r
-            ISelection selection = (ISelection)input;\r
-            if(selection instanceof IStructuredSelection) {\r
-                Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class);\r
-                if(resource != null) {\r
-                    variable = resource;\r
-                }\r
-            }\r
-        }\r
-        \r
-        ExpressionType et = ExpressionTypes.getExpressionTypeForVariable(variable);\r
-        \r
+    public void setInput(ISessionContext context, Object input) {  \r
+       expr = AdaptionUtils.adaptToSingle(input, Resource.class);\r
+        ExpressionType et = ExpressionTypes.getExpressionType(expr);\r
         displayExpression(et.toString(), true);\r
-        \r
     }\r
     \r
-    \r
     public void displayExpression(String expressionType, boolean original) {\r
-        if(expressionType == null)\r
-            return;\r
+        if(expressionType == null) {\r
+                       return;\r
+        }\r
 \r
         if(this.expression != null) expression.updateData(data);\r
         ExpressionType et = ExpressionType.valueOf(expressionType);\r
@@ -100,7 +79,7 @@ public class ExpressionWidget implements Widget {
             case Lookup: \r
                 exp = new LookupExpression(); break;\r
             case WithLookup: \r
-                exp = new WithLookupExpression(variable); break;\r
+                exp = new WithLookupExpression(expr); break;\r
             case Stock: \r
                 exp = new StockExpression(); break;\r
             case Delay: \r
@@ -115,7 +94,7 @@ public class ExpressionWidget implements Widget {
             } \r
 \r
             if(original) \r
-                exp.readData(variable, data);\r
+                exp.readData(expr, data);\r
             \r
             exp.createExpressionFields(parent, data);\r
             if(modifyListener != null)\r
@@ -142,6 +121,7 @@ public class ExpressionWidget implements Widget {
     \r
     public void validateFields() {\r
         if(this.variableTable == null) return;\r
+        /*\r
         TableItem[] connectedVariables = this.variableTable.getItems();\r
         try {\r
             final Resource configuration = SimanticsUI.getSession().syncRequest(new Read<Resource>() {\r
@@ -149,6 +129,9 @@ public class ExpressionWidget implements Widget {
                 @Override\r
                 public Resource perform(ReadGraph graph) throws DatabaseException {\r
                     SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    \r
+                    \r
+                    \r
                     Resource configuration = variable;\r
                     \r
                     do {\r
@@ -164,6 +147,7 @@ public class ExpressionWidget implements Widget {
         } catch (DatabaseException e1) {\r
             e1.printStackTrace();\r
         }\r
+        */\r
     }\r
     \r
     public void addModifyListener(ModifyListener listener) {\r
@@ -179,7 +163,7 @@ public class ExpressionWidget implements Widget {
     }\r
     \r
     public void save() {\r
-        this.expression.save(variable, data);\r
+        this.expression.save(expr, data);\r
     }\r
 \r
 }\r
index fb61ce7c9b38a1fc6afe89d472bad13c336d788e..ded5da750ee9993d234068f1296eca1cf09c845b 100644 (file)
@@ -45,14 +45,15 @@ public class ShortcutTabWidget implements Widget {
     TabItem functions;\r
     Table variableTable;\r
     Table functionTable;\r
+    Composite composite;\r
 \r
     public ShortcutTabWidget(Composite parent, WidgetSupport support, int style) {\r
-        support.register(this);\r
+       if(support!=null)\r
+               support.register(this);\r
 \r
-        Composite composite = new Composite(parent, style);\r
-        GridDataFactory.fillDefaults().span(1, 2).grab(false, true).applyTo(composite);\r
+        composite = new Composite(parent, style);\r
         GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);\r
-\r
+        \r
         tabFolder = new TabFolder (composite, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(false, true).applyTo(tabFolder);\r
         GridLayoutFactory.fillDefaults().applyTo(tabFolder);\r
@@ -89,6 +90,10 @@ public class ShortcutTabWidget implements Widget {
         functions.setControl(functionTable);\r
     }\r
 \r
+    public Composite getWidget() {\r
+       return composite;\r
+    }\r
+    \r
     @Override\r
     public void setInput(ISessionContext context, Object input) {\r
         if(input instanceof IStructuredSelection) {\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/AvailableEnumerations.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/AvailableEnumerations.java
new file mode 100644 (file)
index 0000000..9b2c37e
--- /dev/null
@@ -0,0 +1,39 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\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.impl.contributor.viewpoint.ViewpointContributorImpl;\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.SysdynResource;\r
+\r
+public class AvailableEnumerations extends ViewpointContributorImpl<Resource> {\r
+\r
+       @Override\r
+       public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+                       throws DatabaseException {\r
+               if(input == null) return null;\r
+               Layer0 l0 = Layer0.getInstance(graph);\r
+               Resource configuration = graph.getPossibleObject(input, l0.PartOf);\r
+        ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        if(configuration == null) \r
+               return result;\r
+        for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
+                result.add(new EnumerationNode(r));\r
+        }\r
+        return result;\r
+       }\r
+\r
+       @Override\r
+       public String getViewpointId() {\r
+               return "Used enumerations";\r
+       }\r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationLabeler.java
new file mode 100644 (file)
index 0000000..d55a10f
--- /dev/null
@@ -0,0 +1,43 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import java.util.HashMap;\r
+import java.util.ListIterator;\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.graph.impl.contributor.labeler.ColumnLabelerContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class EnumerationLabeler extends ColumnLabelerContributorImpl<EnumerationNode>{\r
+\r
+       @Override\r
+       public Map<String, String> getLabel(ReadGraph graph, EnumerationNode input)\r
+                       throws DatabaseException {\r
+               \r
+               String name =  NameUtils.getSafeName(graph, input.data);\r
+               HashMap<String, String> map = new HashMap<String, String>();\r
+               map.put(Keys.ENUMERATION, name);\r
+               \r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               Resource enumerationIndexes = graph.getPossibleObject(input.data, sr.HasEnumerationIndexes);\r
+               ListIterator<Resource> indexes = OrderedSetUtils.iterator(graph, enumerationIndexes);\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("[");\r
+               while(indexes.hasNext()) {\r
+                       Resource i = indexes.next();\r
+                       sb.append(NameUtils.getSafeName(graph, i));\r
+                       if(indexes.hasNext())\r
+                               sb.append(", ");\r
+               }\r
+               sb.append("]");\r
+               map.put(Keys.INDEXES, sb.toString());\r
+               return map;\r
+       }\r
+\r
+\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/EnumerationNode.java
new file mode 100644 (file)
index 0000000..2d96005
--- /dev/null
@@ -0,0 +1,12 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.Resource;\r
+\r
+public class EnumerationNode  extends AbstractNode<Resource> {\r
+\r
+       public EnumerationNode(Resource resource) {\r
+               super(resource);\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/Keys.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/Keys.java
new file mode 100644 (file)
index 0000000..57dd8e2
--- /dev/null
@@ -0,0 +1,18 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import org.simantics.browsing.ui.Column;\r
+import org.simantics.browsing.ui.Column.Align;\r
+\r
+public class Keys {\r
+       \r
+       public static final String   ENUMERATION        = "Enumeration";\r
+       public static final String   INDEXES            = "Indexes";\r
+        \r
+       public static String[] ENUMERATION_COLUMNS_KEYS = { ENUMERATION, INDEXES };\r
+    public static Column[] ENUMERATION_TABLE_COLUMNS = new Column[] {\r
+        new Column(ENUMERATION, Align.LEFT, 100, "Enumeration", false),\r
+        new Column(INDEXES, Align.LEFT, 100, "Indexes", true),\r
+    };\r
+    \r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerations.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/UsedEnumerations.java
new file mode 100644 (file)
index 0000000..35d094f
--- /dev/null
@@ -0,0 +1,37 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\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.impl.contributor.viewpoint.ViewpointContributorImpl;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class UsedEnumerations extends ViewpointContributorImpl<Resource> {\r
+\r
+               @Override\r
+               public Collection<?> getContribution(ReadGraph graph, Resource input)\r
+                               throws DatabaseException {\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+               \r
+               ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+               \r
+               Resource arrayIndexes = graph.getPossibleObject(input, sr.HasArrayIndexes);\r
+               if(arrayIndexes == null) {\r
+                       return result;\r
+               }\r
+               for(Resource r : OrderedSetUtils.toList(graph, arrayIndexes)) {\r
+                       result.add(new EnumerationNode(r));\r
+               }\r
+               return result;\r
+               }\r
+\r
+               @Override\r
+               public String getViewpointId() {\r
+                       return "Available enumerations";\r
+               }\r
+}\r
index a805d3be0ecd073c7448a94024f80ef901a01f0a..ebf4d4205981fdeb94b1d3d7813a8790aff72cd8 100644 (file)
@@ -27,13 +27,14 @@ import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.graphics.Point;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\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.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
@@ -68,16 +69,15 @@ public class BasicExpression implements IExpression {
     }\r
 \r
     @Override\r
-    public void readData(final Resource variable, Map<String, Object> data) {\r
+    public void readData(final Resource expression, Map<String, Object> data) {\r
         String equation = null;\r
-        if (variable != null && data.get("equation") == null) {\r
+        if (expression != null && data.get("equation") == null) {\r
             try {\r
                 equation = 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) {\r
                             String equation = graph.getPossibleRelatedValue(expression, sr.HasEquation);\r
                             if(equation != null)\r
@@ -111,8 +111,8 @@ public class BasicExpression implements IExpression {
     }\r
 \r
     @Override\r
-    public void save(final Resource variable, Map<String, Object> data) {\r
-        final String currentText = expression.getExpression();\r
+    public void save(final Resource expression, Map<String, Object> data) {\r
+        final String currentText = this.expression.getExpression();\r
         final String oldEquation = (String)data.get("equation");\r
         if(oldEquation == null || \r
                 (currentText != null && expressionType != null)) {\r
@@ -122,7 +122,6 @@ public class BasicExpression implements IExpression {
                 public void perform(WriteGraph g)\r
                 throws DatabaseException {\r
                     SysdynResource sr = SysdynResource.getInstance(g);\r
-                    Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
                     if(ExpressionUtils.isParameter(currentText)) {\r
                        if(!expressionType.equals(sr.ConstantExpression))\r
                                expressionType = sr.ParameterExpression;\r
@@ -135,16 +134,13 @@ public class BasicExpression implements IExpression {
                             && currentText.equals(oldEquation)) {\r
                         return;\r
                     }\r
-                    Builtins b = g.getBuiltins();\r
-                    if(expression != null && !g.isInstanceOf(expression, expressionType)) {\r
-                        g.deny(variable, sr.HasExpression);\r
-                        expression = null;\r
-                    }\r
-                    if(expression == null) {\r
-                        expression = g.newResource();\r
-                        g.claim(expression, b.InstanceOf, null, expressionType);\r
-                        g.claim(variable, sr.HasExpression, expression);\r
-                    }\r
+                    \r
+                    Layer0 l0 = Layer0.getInstance(g);\r
+                    \r
+                    g.deny(expression, l0.InstanceOf);\r
+                    g.deny(expression, sr.HasEquation);\r
+                    \r
+                    g.claim(expression, l0.InstanceOf, null, expressionType);\r
                     g.claimLiteral(expression, sr.HasEquation, currentText);\r
                 }\r
 \r
index cbf98765b0c22d0b234bc2921507716d1676d754..191960cb1873e84b9372a7ef44fd941ee31c97cf 100644 (file)
@@ -17,6 +17,7 @@ import java.util.HashMap;
 import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Set;\r
+import java.util.StringTokenizer;\r
 \r
 import org.eclipse.jface.text.Position;\r
 import org.eclipse.swt.custom.StyledText;\r
@@ -47,7 +48,10 @@ public class ExpressionUtils {
         */\r
        static public boolean isParameter(String expression) {\r
                try {\r
-                       Double.parseDouble(expression);\r
+                       StringTokenizer st = new StringTokenizer(expression, "{}[],;");\r
+                       while(st.hasMoreTokens()) {\r
+                               Double.parseDouble(st.nextToken().trim());\r
+                       }\r
                        return true;\r
                } catch (NumberFormatException e) {\r
                        return false;\r
index e36371ff6892bd3967ef931177bca0a93c23f758..1491cd322a653ab26905e9d20b17592c1cf8b8da 100644 (file)
@@ -25,9 +25,9 @@ public interface IExpression {
 \r
     public void createExpressionFields(Composite parent, Map<String, Object> data);\r
 \r
-    public void readData(final Resource variable, Map<String, Object> data);\r
+    public void readData(final Resource expression, Map<String, Object> data);\r
 \r
-    public void save(final Resource variable, Map<String, Object> data);\r
+    public void save(final Resource expression, Map<String, Object> data);\r
 \r
     public void focus();\r
 \r
index dd03e20c97d0bd3f6085f13ba8e5d3dc21dbee2a..9357b4cf1713b003e1461b6a86e630d41038b519 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -33,6 +33,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.layer0.Layer0;\r
@@ -81,18 +82,17 @@ public class StockExpression implements IExpression {
     }\r
 \r
     @Override\r
-    public void readData(final Resource variable, Map<String, Object> data) {\r
+    public void readData(final Resource expression, Map<String, Object> data) {\r
         String initialEquation = null;\r
 \r
-        if (variable != null && data.get("initialEquation") == null) {\r
+        if (expression != null && data.get("initialEquation") == null) {\r
             try {\r
                 initialEquation = 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
+                        if (graph.isInstanceOf(expression, sr.StockExpression)) {\r
                             return graph.getRelatedValue(expression, sr.HasInitialEquation);\r
                         } else {\r
                             return "";\r
@@ -106,7 +106,7 @@ public class StockExpression implements IExpression {
             data.put("initialEquation", initialEquation);\r
         }\r
 \r
-        data.put("integral", getIntegral(variable));\r
+        data.put("integral", getIntegral(expression));\r
 \r
     }\r
 \r
@@ -125,32 +125,34 @@ public class StockExpression implements IExpression {
     }\r
 \r
     @Override\r
-    public void save(final Resource variable, Map<String, Object> data) {\r
-        final String currentText = expression.getExpression();\r
+    public void save(final Resource expression, Map<String, Object> data) {\r
+        final String currentText = this.expression.getExpression();\r
         if(currentText != null) {\r
             SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
 \r
                 @Override\r
                 public void perform(WriteGraph g)\r
                 throws DatabaseException {\r
+                       System.out.println("write stock");\r
                     SysdynResource sr = SysdynResource.getInstance(g);\r
-                    Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
                     Layer0 l0 = Layer0.getInstance(g);\r
-                    if(expression != null && !g.isInstanceOf(expression, sr.StockExpression)) {\r
-                        g.deny(variable, sr.HasExpression);\r
-                        expression = null;\r
+                    \r
+                    if(!g.isInstanceOf(expression, sr.StockExpression)) {\r
+                       Resource expressionList = g.getSingleObject(expression, l0.HasNext);\r
+                       Resource temp = g.newResource();\r
+                       OrderedSetUtils.replace(g, expressionList, expression, temp);\r
+                       for(Resource predicate : g.getPredicates(expression)) {\r
+                               g.deny(expression, predicate);\r
+                       }\r
+                       g.claim(expression, l0.InstanceOf, null, sr.StockExpression);\r
+                       OrderedSetUtils.replace(g, expressionList, temp, expression);\r
                     }\r
-                    if(expression == null) {\r
-                        expression = g.newResource();\r
-                        g.claim(expression, l0.InstanceOf, null, sr.StockExpression);\r
-                        g.claim(variable, sr.HasExpression, expression);\r
-                    } \r
                     g.claimLiteral(expression, sr.HasInitialEquation, currentText);\r
                 }\r
 \r
             });\r
         }\r
-        expression.setExpression(currentText);\r
+        this.expression.setExpression(currentText);\r
     }\r
 \r
     @Override\r
@@ -162,8 +164,10 @@ public class StockExpression implements IExpression {
     }\r
 \r
 \r
-    private String getIntegral(final Resource variable) {\r
+    private String getIntegral(final Resource expression) {\r
         String integral = "";\r
+        if(expression == null)\r
+               return integral;\r
         try {\r
             integral = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
 \r
@@ -171,6 +175,10 @@ public class StockExpression implements IExpression {
                 public String perform(ReadGraph graph) throws DatabaseException {\r
                     SysdynResource sr = SysdynResource.getInstance(graph);\r
                     Layer0 l0 = Layer0.getInstance(graph);\r
+                    \r
+                    // find the variable\r
+                    Resource expressionList = OrderedSetUtils.getSingleOwnerList(graph, expression);\r
+                    Resource variable = graph.getSingleObject(expressionList, sr.HasExpressions_Inverse);\r
                     Collection<Resource> heads = graph.getObjects(variable, sr.IsHeadOf);\r
                     Collection<Resource> tails = graph.getObjects(variable, sr.IsTailOf);\r
 \r
index 96eecd763793ea6f9a7b7e5716caf2d04a8ded1c..d01c6ce0be73947a4e7c4113410ccc25cae16147 100644 (file)
@@ -51,6 +51,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.db.request.Read;\r
@@ -72,10 +73,10 @@ public class WithLookupExpression implements IExpression {
     private ChartPanel smallPanel;\r
     private Frame smallFrame;\r
 \r
-    private Resource variable;\r
+    private Resource expr;\r
 \r
-    public WithLookupExpression(Resource variable) {\r
-        this.variable = variable;\r
+    public WithLookupExpression(Resource expression) {\r
+        this.expr = expression;\r
     }\r
 \r
     @Override\r
@@ -125,7 +126,7 @@ public class WithLookupExpression implements IExpression {
             @Override\r
             public void focusLost(FocusEvent e) {\r
                 lastSelectedText = lookup;\r
-                save(variable, data);\r
+                save(expr, data);\r
             }\r
         });\r
 \r
@@ -146,10 +147,9 @@ public class WithLookupExpression implements IExpression {
             @Override\r
             public String perform(ReadGraph graph) throws DatabaseException {\r
                 SysdynResource sr = SysdynResource.getInstance(graph);\r
-                Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
                 String result = "";\r
-                if (expression != null && graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
-                    result = graph.getRelatedValue(expression, sr.HasLookup);\r
+                if (expr != null && graph.isInstanceOf(expr, sr.WithLookupExpression)) {\r
+                    result = graph.getRelatedValue(expr, sr.HasLookup);\r
                 }\r
                 return result;\r
             }\r
@@ -196,7 +196,7 @@ public class WithLookupExpression implements IExpression {
     }\r
 \r
     @Override\r
-    public void readData(final Resource variable, Map<String, Object> data) {\r
+    public void readData(final Resource expression, Map<String, Object> data) {\r
 \r
         class Auxiliary {\r
             String equation, lookup;\r
@@ -204,7 +204,7 @@ public class WithLookupExpression implements IExpression {
 \r
         Auxiliary results = null;\r
 \r
-        if (variable != null && data.get("equation") == null) {\r
+        if (data.get("equation") == null) {\r
             try {\r
                 results = SimanticsUI.getSession().syncRequest(new Read<Auxiliary>() {\r
 \r
@@ -212,7 +212,6 @@ public class WithLookupExpression implements IExpression {
                     public Auxiliary perform(ReadGraph graph) throws DatabaseException {\r
                         Auxiliary results = new Auxiliary();\r
                         SysdynResource sr = SysdynResource.getInstance(graph);\r
-                        Resource expression = graph.getPossibleObject(variable, sr.HasExpression);\r
                         if (expression != null && graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
                             results.equation = graph.getRelatedValue(expression, sr.HasEquation);\r
                             results.lookup = graph.getRelatedValue(expression, sr.HasLookup);\r
@@ -265,24 +264,23 @@ public class WithLookupExpression implements IExpression {
                 public void perform(WriteGraph g)\r
                 throws DatabaseException {\r
                     SysdynResource sr = SysdynResource.getInstance(g);\r
-                    Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
                     Layer0 l0 = Layer0.getInstance(g);\r
-                    if(expression != null && !g.isInstanceOf(expression, sr.WithLookupExpression)) {\r
-                        g.deny(variable, sr.HasExpression);\r
-                        expression = null;\r
+                    if(!g.isInstanceOf(expr, sr.WithLookupExpression)) {\r
+                               Resource expressionList = g.getSingleObject(expr, l0.HasNext);\r
+                       Resource temp = g.newResource();\r
+                       OrderedSetUtils.replace(g, expressionList, expr, temp);\r
+                       for(Resource predicate : g.getPredicates(expr)) {\r
+                               g.deny(expr, predicate);\r
+                       }\r
+                        g.claim(expr, l0.InstanceOf, null, sr.WithLookupExpression);\r
+                        g.claimLiteral(expr, sr.HasMinX, 0.0);\r
+                        g.claimLiteral(expr, sr.HasMaxX, 10.0);\r
+                        g.claimLiteral(expr, sr.HasMinY, 0.0);\r
+                        g.claimLiteral(expr, sr.HasMaxY, 10.0);\r
+                       OrderedSetUtils.replace(g, expressionList, temp, expr);\r
                     }\r
-                    if(expression == null) {\r
-                        expression = g.newResource();\r
-                        g.claim(expression, l0.InstanceOf, null, sr.WithLookupExpression);\r
-                        g.claim(variable, sr.HasExpression, expression);\r
-                        g.claimLiteral(expression, sr.HasMinX, 0.0);\r
-                        g.claimLiteral(expression, sr.HasMaxX, 10.0);\r
-                        g.claimLiteral(expression, sr.HasMinY, 0.0);\r
-                        g.claimLiteral(expression, sr.HasMaxY, 10.0);\r
-\r
-                    } \r
-                    g.claimLiteral(expression, sr.HasEquation, currentExpression);\r
-                    g.claimLiteral(expression, sr.HasLookup, currentLookupTable);\r
+                    g.claimLiteral(expr, sr.HasEquation, currentExpression);\r
+                    g.claimLiteral(expr, sr.HasLookup, currentLookupTable);\r
                 }\r
             });\r
         }\r
index 09363bb80db7827c6ae8c63e7bb53045336553d9..4025beb84694601b3b62f142b62331b34b260942 100644 (file)
@@ -33,6 +33,10 @@ public class VariableNamePropertyModifier extends TextModifyListenerImpl<Resourc
         */\r
        @Override\r
        public void applyText(WriteGraph graph, Resource variable, String text) throws DatabaseException {\r
+               \r
+               // TODO: separate possible array indexes\r
+               \r
+               // TODO: add enumerations to the variable\r
                String originalName = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName);\r
                VariableNameUtils.renameInEquations(graph, variable, originalName, text);\r
                graph.claimLiteral(variable, graph.getResource(propertyURI), text, StringBindingDefault.INSTANCE);\r
index 9221c70aa85c9cca1e8ad1f9f66cc64bfd239e35..163f9abb4048063e481ae4cc22a4a55773e5b60a 100644 (file)
@@ -55,6 +55,7 @@ import org.simantics.sysdyn.representation.IndependentVariable;
 import org.simantics.sysdyn.representation.Model;\r
 import org.simantics.sysdyn.representation.Module;\r
 import org.simantics.sysdyn.representation.SysdynSchema;\r
+import org.simantics.sysdyn.representation.expressions.IExpression;\r
 import org.simantics.sysdyn.representation.expressions.ParameterExpression;\r
 \r
 /**\r
@@ -439,8 +440,10 @@ public class SysdynModel implements IMappingListener, IModel {
                                inits.putAll(getInits(conf, prefix + module.getName() + "."));\r
                        } else if (element instanceof IndependentVariable) {\r
                                IndependentVariable variable = (IndependentVariable) element;\r
-                               if (variable.getExpression() instanceof ParameterExpression) {\r
-                                       inits.put(prefix + variable.getName(), "" + ((ParameterExpression)variable.getExpression()).getValue());\r
+                               //FIXME: more general solution?\r
+                               IExpression expression = variable.getExpressions().getExpressions().get(0);\r
+                               if (expression instanceof ParameterExpression) {\r
+                                       inits.put(prefix + variable.getName(), "" +((ParameterExpression)expression).getValue());\r
                                }\r
                        }\r
                }\r
index cb05625818abaa7785513648e59dd21d41620ada..68225ac1ec22e63dc1853571dec636e122b26426 100644 (file)
@@ -156,11 +156,8 @@ public class ModelicaWriter {
 \r
         b.append("// Variable definitions\n");\r
         for(IndependentVariable variable : variables) {\r
-            IExpression expr = variable.getExpression();\r
-            if(expr != null) {\r
-                app = expr.getDeclaration(variable);\r
-                if (app != null) b.append(app);\r
-            }\r
+               app = variable.getDeclaration();\r
+               if (app != null) b.append(app);\r
         }\r
 \r
         if(!modules.isEmpty()) {\r
@@ -185,29 +182,23 @@ public class ModelicaWriter {
         }\r
 \r
         for(Stock stock : stocks) {\r
-            IExpression expr = stock.getExpression();\r
-            if(expr != null) {\r
-                app = expr.getInitialEquation(stock);\r
-                if (app != null) {\r
-                    if(initialEquations == false) {\r
-                        initialEquations = true;\r
-                        b.append("// Initial Equations\n");\r
-                        b.append("initial equation\n");\r
-                    }\r
-                    b.append(app);\r
-                }\r
-            }\r
+               app = stock.getInitialEquation();\r
+               if (app != null) {\r
+                       if(initialEquations == false) {\r
+                               initialEquations = true;\r
+                               b.append("// Initial Equations\n");\r
+                               b.append("initial equation\n");\r
+                       }\r
+                       b.append(app);\r
+               }\r
         }\r
 \r
         b.append("equation\n");\r
 \r
         b.append("// Equations\n");\r
         for(IndependentVariable variable : variables) {\r
-            IExpression expr = variable.getExpression();\r
-            if(expr != null) {\r
-                app = expr.getEquation(variable);\r
-                if (app != null) b.append(app);\r
-            }\r
+               app = variable.getEquation();\r
+               if (app != null) b.append(app);\r
         }\r
 \r
 \r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ArrayIndexes.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ArrayIndexes.java
new file mode 100644 (file)
index 0000000..a148b0c
--- /dev/null
@@ -0,0 +1,18 @@
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedOrderedSetElements;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/ArrayIndexes")\r
+public class ArrayIndexes {\r
+       \r
+    @RelatedOrderedSetElements\r
+    private ArrayList<Enumeration> enumerations = new ArrayList<Enumeration>();\r
+\r
+    public ArrayList<Enumeration> getEnumerations() {\r
+       return enumerations;\r
+    }\r
+\r
+}\r
index 4176277f21fa733412daa5341ff47f92a1c19f75..96aed4cc459f995160dd342188d74bd72f301fef 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.sysdyn.representation;\r
 \r
+import java.util.ArrayList;\r
+\r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedElement;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
@@ -28,4 +30,20 @@ public class Enumeration extends Variable {
                sb.append(");\n");\r
                return sb.toString();\r
        }\r
+       \r
+       public ArrayList<EnumerationIndex> getEnumerationIndexes() {\r
+       return enumerationIndexes.getEnumerationIndexes();\r
+       }\r
+       \r
+       public int indexOf(String index) {\r
+               int result = -1;\r
+               ArrayList<EnumerationIndex> indexes = getEnumerationIndexes();\r
+               for(int i = 0; i < indexes.size(); i++) {\r
+                       if(indexes.get(i).equals(index)) {\r
+                               result = i  +1;\r
+                               break;\r
+                       }\r
+               }\r
+               return result;\r
+       }\r
 }\r
index cdc559eedb5f5f3fcab704bdfbf9e39b73a3dc33..50fed1bbafc0ecd356389ce332580370a41b7924 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation;\r
 \r
-import org.simantics.objmap.annotations.RelatedElement;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+\r
 import org.simantics.sysdyn.representation.expressions.IExpression;\r
+import org.simantics.sysdyn.representation.expressions.ParameterExpression;\r
 \r
 public abstract class IndependentVariable extends Variable {\r
-\r
-    @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasExpression")\r
-    protected IExpression expression;\r
     \r
-    public IExpression getExpression() {\r
-        return this.expression;\r
+    public String getDeclaration() {\r
+       ArrayList<IExpression> expressions = this.expressions.getExpressions();\r
+       ArrayIndexes ai = this.getArrayIndexes();\r
+       ArrayList<Enumeration> enumerations = null;\r
+       if(ai != null) \r
+               enumerations = ai.getEnumerations();\r
+       if(enumerations == null || enumerations.size() < 1) {\r
+               // NOT an array variable, get declaration from the only expression.\r
+               if(expressions.get(0) == null)\r
+                       return null;\r
+               else\r
+                       return expressions.get(0).getDeclaration(this);\r
+       } else {\r
+               // ARRAY variable. Create declaration according to the type, name and indexes\r
+               //TODO: check if all of them are parameters -> form a parameter\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("    ");\r
+               sb.append(this.getType());\r
+               sb.append(" ");\r
+               sb.append(this.getName());\r
+               sb.append("[");\r
+               Iterator<Enumeration> iterator = enumerations.iterator();\r
+               while(iterator.hasNext()) {\r
+                       sb.append(iterator.next().getName());\r
+                       if(iterator.hasNext()) {\r
+                               sb.append(", ");\r
+                       }\r
+               }\r
+               sb.append("];\n");\r
+               return sb.toString();\r
+       }\r
+    }\r
+    \r
+    public String getInitialEquation() {\r
+       return expressions.getExpressions().get(0).getInitialEquation(this);\r
+    }\r
+    \r
+    public String getEquation() {\r
+       ArrayList<IExpression> expressions = this.expressions.getExpressions();\r
+       ArrayIndexes ai = this.getArrayIndexes();\r
+       ArrayList<Enumeration> enumerations = null;\r
+       if(ai != null) \r
+               enumerations = ai.getEnumerations();\r
+       if(enumerations == null || enumerations.size() < 1) {\r
+               // NOT an array variable, get equation from the only expression.\r
+               IExpression expression = expressions.get(0);\r
+               if(expression == null || expression instanceof ParameterExpression)\r
+                       return null;\r
+               else\r
+                       return expressions.get(0).getEquation(this);\r
+       } else {\r
+               // ARRAY variable. Create all equations for the variable\r
+               //TODO: check that it has not been a parameter\r
+               StringBuilder sb = new StringBuilder();                 \r
+               for(IExpression expression : expressions) {\r
+                       sb.append(expression.getEquation(this));\r
+               }\r
+               return sb.toString();\r
+       }\r
+       \r
     }\r
 }\r
index 3c0888e0193628e6de63a9801b87476736f0ed66..ed8e9f8dda70277052314b43c2c4ae5e1a9ead39 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.objmap.schema.MappingSchemas;\r
 import org.simantics.objmap.schema.SimpleSchema;\r
 import org.simantics.sysdyn.representation.expressions.ConstantExpression;\r
+import org.simantics.sysdyn.representation.expressions.Expressions;\r
 import org.simantics.sysdyn.representation.expressions.LookupExpression;\r
 import org.simantics.sysdyn.representation.expressions.NormalExpression;\r
 import org.simantics.sysdyn.representation.expressions.ParameterExpression;\r
@@ -37,9 +38,11 @@ public class SysdynSchema extends SimpleSchema {
             addLinkType(MappingSchemas.fromAnnotations(g, Input.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, ModuleType.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, Model.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, Expressions.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, Enumeration.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndex.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, EnumerationIndexes.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, ArrayIndexes.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, NormalExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, ParameterExpression.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, StockExpression.class));\r
index 1b9c19905a7d8c05cfc2a0024add35a81ad52745..4ad6ab4170506dbf88d2487d9a63786520a65669 100644 (file)
@@ -13,15 +13,25 @@ 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.Expressions;\r
 \r
 public abstract class Variable implements IElement {\r
     \r
     @RelatedValue("http://www.simantics.org/Layer0-1.0/HasType")\r
     protected String type;\r
+    \r
     @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
     protected String name;\r
+    \r
     @RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf")\r
     protected Configuration configuration;\r
+    \r
+    @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasArrayIndexes")\r
+    protected ArrayIndexes arrayIndexes;\r
+    \r
+    @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasExpressions")\r
+    protected Expressions expressions;\r
+    \r
 \r
     public String getName() {\r
         return this.name;\r
@@ -34,4 +44,12 @@ public abstract class Variable implements IElement {
     public String getType() {\r
         return this.type;\r
     }\r
+    \r
+    public ArrayIndexes getArrayIndexes() {\r
+       return this.arrayIndexes;\r
+    }\r
+    \r
+    public Expressions getExpressions() {\r
+        return this.expressions;\r
+    }\r
 }\r
index 64ac5ce233d03c5f4a603bf9c9d13150c842caa7..1fd149ef76e8ea0444d1ae2a6e155d0b9f7b18d5 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation.expressions;\r
 \r
+import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 \r
 public abstract class Expression implements IExpression {\r
         \r
+    @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasArrayRange")\r
+    private String range;\r
+    \r
     @Override\r
     public String getDeclaration(IndependentVariable variable) {\r
         return null;\r
@@ -29,5 +33,13 @@ public abstract class Expression implements IExpression {
     public String getInitialEquation(IndependentVariable variable) {\r
         return null;\r
     }\r
+    \r
+    @Override\r
+    public String getArrayRange() {\r
+       if(range == null)\r
+               return "";\r
+       else\r
+               return range;\r
+    }\r
 \r
 }\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expressions.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expressions.java
new file mode 100644 (file)
index 0000000..d92336d
--- /dev/null
@@ -0,0 +1,17 @@
+package org.simantics.sysdyn.representation.expressions;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedOrderedSetElements;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn-1.0/Expressions")\r
+public class Expressions {\r
+\r
+    @RelatedOrderedSetElements\r
+    private ArrayList<IExpression> expressions = new ArrayList<IExpression>();\r
+\r
+    public ArrayList<IExpression> getExpressions() {\r
+       return expressions;\r
+    }\r
+}\r
index 5bf4d10229b7d24b0042aa0a148bb1854f3055f3..544313479b7c8c647d587279b4fd715f7ca5edcc 100644 (file)
@@ -18,5 +18,6 @@ public interface IExpression {
     String getDeclaration(IndependentVariable variable);\r
     String getInitialEquation(IndependentVariable variable);\r
     String getEquation(IndependentVariable variable);\r
+    String getArrayRange();\r
 \r
 }\r
index 1d8be4bbaf6609212f2cf34c83384a1b8afa31f7..09949c5828eb607f16c3aaf251397737f9f50fae 100644 (file)
@@ -28,7 +28,7 @@ public class NormalExpression extends Expression {
 \r
     @Override\r
     public String getEquation(IndependentVariable variable) {\r
-        return "    " + variable.getName() + " = " + equation + ";\n";\r
+        return "    " + variable.getName() + this.getArrayRange() + " = " + equation + ";\n";\r
     }\r
 \r
 }\r
index fc5c7f69324b9266ac66af7dbd7da08a8a73b3b8..91ec0c018b8868cffe9250f7709397fb70b0d22a 100644 (file)
@@ -29,7 +29,16 @@ public class ParameterExpression extends Expression {
         return  b.toString();\r
     }\r
     \r
-    public double getValue() {\r
-        return Double.parseDouble(equation);\r
+    \r
+    /**\r
+     * Used when the expression is a part of an array variable. Then it is like a normal auxiliary.\r
+     */\r
+    @Override\r
+    public String getEquation(IndependentVariable variable) {\r
+       return "    " + variable.getName() + this.getArrayRange() + " = " + equation + ";\n";\r
+    };\r
+    \r
+    public Double getValue() {\r
+       return Double.parseDouble(equation);\r
     }\r
 }\r