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
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
*******************************************************************************/\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
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
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
// 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
--- /dev/null
+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
\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
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
\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
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
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
}\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
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
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
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
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
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
* @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
--- /dev/null
+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
@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
\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
\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
\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
*******************************************************************************/\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
\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
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
}\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
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
} \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
\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
@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
} catch (DatabaseException e1) {\r
e1.printStackTrace();\r
}\r
+ */\r
}\r
\r
public void addModifyListener(ModifyListener listener) {\r
}\r
\r
public void save() {\r
- this.expression.save(variable, data);\r
+ this.expression.save(expr, data);\r
}\r
\r
}\r
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
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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
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
}\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
}\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
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
&& 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
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
*/\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
\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
/*******************************************************************************\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
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
}\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
data.put("initialEquation", initialEquation);\r
}\r
\r
- data.put("integral", getIntegral(variable));\r
+ data.put("integral", getIntegral(expression));\r
\r
}\r
\r
}\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
}\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
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
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
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
@Override\r
public void focusLost(FocusEvent e) {\r
lastSelectedText = lookup;\r
- save(variable, data);\r
+ save(expr, data);\r
}\r
});\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
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
}\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
\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
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
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
*/\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
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
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
\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
}\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
--- /dev/null
+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
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
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
*******************************************************************************/\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
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
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
\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
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
*******************************************************************************/\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
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
--- /dev/null
+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
String getDeclaration(IndependentVariable variable);\r
String getInitialEquation(IndependentVariable variable);\r
String getEquation(IndependentVariable variable);\r
+ String getArrayRange();\r
\r
}\r
\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
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