org.simantics.ui;bundle-version="1.0.0",
org.eclipse.ui;bundle-version="3.5.0",
org.eclipse.core.runtime;bundle-version="3.5.0",
- org.simantics.objmap;bundle-version="0.1.0"
+ org.simantics.objmap;bundle-version="0.1.0",
+ org.simantics.sysdyn;bundle-version="1.0.0"
name="Modelica View"\r
restorable="true">\r
</view>\r
+ <view\r
+ category="org.simantics.sysdyn.ui.category"\r
+ class="org.simantics.sysdyn.ui.equation.EquationView"\r
+ id="org.simantics.sysdyn.ui.equation.view"\r
+ name="Equation View"\r
+ restorable="true">\r
+ </view>\r
</extension>\r
\r
</plugin>\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\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
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.ui;\r
-\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-\r
-public class SysdynResource {\r
- \r
- public final Resource HasX;\r
- public final Resource HasY;\r
- public final Resource SysdynModel;\r
- public final Resource SysdynModelManager;\r
- public final Resource SysdynModellingDomain;\r
- public final Resource TestDiagram;\r
- public final Resource Variable;\r
- public final Resource VariableElement;\r
- \r
- public static class URIs {\r
- public static final String HasX = "http://www.simantics.org/Sysdyn#HasX";\r
- public static final String HasY = "http://www.simantics.org/Sysdyn#HasY";\r
- public static final String SysdynModel = "http://www.simantics.org/Sysdyn#SysdynModel";\r
- public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn#SysdynModelManager";\r
- public static final String SysdynModellingDomain = "http://www.simantics.org/Sysdyn#SysdynModellingDomain";\r
- public static final String TestDiagram = "http://www.simantics.org/Sysdyn#TestDiagram";\r
- public static final String Variable = "http://www.simantics.org/Sysdyn#Variable";\r
- public static final String VariableElement = "http://www.simantics.org/Sysdyn#VariableElement";\r
- }\r
- \r
- public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
- try {\r
- return graph.getResourceByURI(uri);\r
- } catch(DatabaseException e) {\r
- System.err.println(e.getMessage());\r
- return null;\r
- }\r
- }\r
- \r
- public SysdynResource(ReadGraph graph) {\r
- HasX = getResourceOrNull(graph, URIs.HasX);\r
- HasY = getResourceOrNull(graph, URIs.HasY);\r
- SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
- SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager);\r
- SysdynModellingDomain = getResourceOrNull(graph, URIs.SysdynModellingDomain);\r
- TestDiagram = getResourceOrNull(graph, URIs.TestDiagram);\r
- Variable = getResourceOrNull(graph, URIs.Variable);\r
- VariableElement = getResourceOrNull(graph, URIs.VariableElement);\r
- }\r
- \r
- public static SysdynResource getInstance(ReadGraph graph) {\r
- Session session = graph.getSession();\r
- SysdynResource ret = session.getService(SysdynResource.class);\r
- if(ret == null) {\r
- ret = new SysdynResource(graph);\r
- session.registerService(SysdynResource.class, ret);\r
- }\r
- return ret;\r
- }\r
- \r
-}\r
-\r
\r
@Override\r
public void selectionChanged(ISelection selection) {\r
- ArrayList<Resource> resources = new ArrayList<Resource>(selection.size());\r
+ final ArrayList<Resource> resources = new ArrayList<Resource>(selection.size());\r
for(IElement element : selection)\r
resources.add(mapping.inverseGet(element));\r
- selectionProvider.setSelection(new StructuredSelection(resources));\r
+ composite.getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ selectionProvider.setSelection(new StructuredSelection(resources));\r
+ }\r
+ \r
+ });\r
}\r
\r
});\r
--- /dev/null
+package org.simantics.sysdyn.ui.equation;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.FocusAdapter;\r
+import org.eclipse.swt.events.FocusEvent;\r
+import org.eclipse.swt.events.KeyAdapter;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.graphics.Font;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.eclipse.ui.ISelectionListener;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.part.ViewPart;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class EquationView extends ViewPart implements ISelectionListener {\r
+ \r
+ static final Font FONT = new Font(null, "Courier New", 12, SWT.NORMAL);\r
+ \r
+ Text text;\r
+ Resource auxiliary;\r
+ String originalText;\r
+ \r
+ @Override \r
+ public void createPartControl(Composite parent) {\r
+ getSite().getPage().addPostSelectionListener(this);\r
+ text = new Text(parent, SWT.MULTI);\r
+ text.setFont(FONT);\r
+ text.addFocusListener(new FocusAdapter() {\r
+ \r
+ @Override\r
+ public void focusLost(FocusEvent e) {\r
+ final String currentText = text.getText();\r
+ if(originalText != null && !originalText.equals(currentText)) {\r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+ @Override\r
+ public void perform(WriteGraph g)\r
+ throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ g.claimValue(auxiliary, sr.HasValue, currentText);\r
+ }\r
+ \r
+ });\r
+ }\r
+ } \r
+ \r
+ });\r
+ text.addKeyListener(new KeyAdapter() { \r
+ \r
+ @Override\r
+ public void keyPressed(KeyEvent e) {\r
+ if(e.keyCode == SWT.ESC) {\r
+ text.setText(originalText);\r
+ } \r
+ }\r
+ \r
+ });\r
+ } \r
+\r
+ class UpdateViewRequest extends ReadRequest {\r
+\r
+ Resource resource;\r
+ \r
+ public UpdateViewRequest(Resource resource) {\r
+ this.resource = resource;\r
+ }\r
+ \r
+ @Override\r
+ public void run(ReadGraph g) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(g);\r
+ Builtins b = g.getBuiltins();\r
+ if(g.isInstanceOf(resource, sr.Auxiliary)) {\r
+ auxiliary = resource;\r
+ final String name = g.getRelatedValue(resource, b.HasName);\r
+ final String value = g.getPossibleRelatedValue(resource, sr.HasValue);\r
+ text.getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ if(value == null)\r
+ originalText = "";\r
+ else\r
+ originalText = value;\r
+ text.setText(originalText);\r
+ setPartName(name + " equation");\r
+ }\r
+ \r
+ });\r
+ }\r
+ }\r
+ \r
+ }\r
+ \r
+ @Override\r
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
+ if(selection instanceof IStructuredSelection) {\r
+ IStructuredSelection structuredSelection = \r
+ (IStructuredSelection)selection;\r
+ if(structuredSelection.size() == 1) {\r
+ Object element = structuredSelection.getFirstElement();\r
+ if(element instanceof Resource)\r
+ SimanticsUI.getSession().asyncRequest(new UpdateViewRequest((Resource)element));\r
+ }\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void setFocus() {\r
+ text.setFocus();\r
+ }\r
+\r
+}\r
Bundle-SymbolicName: org.simantics.sysdyn
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.simantics.objmap;bundle-version="0.1.0"
+Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
+ org.simantics.db;bundle-version="0.6.2"
+Export-Package: org.simantics.sysdyn,
+ org.simantics.sysdyn.modelica,
+ org.simantics.sysdyn.representation,
+ org.simantics.sysdyn.representation.visitors
public final Resource HasAngle;\r
public final Resource HasHead;\r
public final Resource HasTail;\r
+ public final Resource HasValue;\r
public final Resource HasX;\r
public final Resource HasY;\r
public final Resource IndependentVariable;\r
public static final String HasAngle = "http://www.simantics.org/Sysdyn#HasAngle";\r
public static final String HasHead = "http://www.simantics.org/Sysdyn#HasHead";\r
public static final String HasTail = "http://www.simantics.org/Sysdyn#HasTail";\r
+ public static final String HasValue = "http://www.simantics.org/Sysdyn#HasValue";\r
public static final String HasX = "http://www.simantics.org/Sysdyn#HasX";\r
public static final String HasY = "http://www.simantics.org/Sysdyn#HasY";\r
public static final String IndependentVariable = "http://www.simantics.org/Sysdyn#IndependentVariable";\r
HasAngle = getResourceOrNull(graph, URIs.HasAngle);\r
HasHead = getResourceOrNull(graph, URIs.HasHead);\r
HasTail = getResourceOrNull(graph, URIs.HasTail);\r
+ HasValue = getResourceOrNull(graph, URIs.HasValue);\r
HasX = getResourceOrNull(graph, URIs.HasX);\r
HasY = getResourceOrNull(graph, URIs.HasY);\r
IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
Variable <T ST.Component \r
[HasX card "1"]\r
[HasY card "1"]\r
-HasX <R L0.HasProperty\r
+HasX <R L0.HasProperty : L0.FunctionalRelation\r
L0.HasRange L0.Double\r
-HasY <R L0.HasProperty\r
+HasY <R L0.HasProperty : L0.FunctionalRelation\r
L0.HasRange L0.Double \r
+HasValue <R L0.HasProperty : L0.FunctionalRelation\r
+ L0.HasRange L0.String\r
\r
IndependentVariable <T Variable\r
[L0.HasName card "1"]\r
Auxiliary <T IndependentVariable\r
Stock <T IndependentVariable\r
Valve <T IndependentVariable\r
+ [HasValue card "0..1"]\r
Cloud <T IndependentVariable \r
\r
######################################################################\r