org.simantics.objmap;bundle-version="0.1.0",
org.simantics.sysdyn;bundle-version="1.0.0",
org.simantics.project;bundle-version="1.0.0",
- org.apache.log4j;bundle-version="1.2.15"
+ org.apache.log4j;bundle-version="1.2.15",
+ org.eclipse.jface.text;bundle-version="3.5.0",
+ org.eclipse.ui.editors;bundle-version="3.5.0"
Bundle-Activator: org.simantics.sysdyn.ui.Activator
Bundle-ActivationPolicy: lazy
class="org.simantics.sysdyn.ui.editor.SysdynDiagramEditor"\r
default="false"\r
id="org.simantics.sysdyn.ui.diagramEditor"\r
- name="Sysdyn diagram editor">\r
+ name="System dynamic diagram editor">\r
+ </editor>\r
+ <editor\r
+ class="org.simantics.sysdyn.ui.modelica.SysdynModelicaEditor"\r
+ contributorClass="org.simantics.sysdyn.ui.modelica.TextEditorActionBarContributor"\r
+ default="false"\r
+ id="org.simantics.sysdyn.ui.modelicaEditor"\r
+ name="Sysdyn Modelica editor">\r
</editor>\r
</extension>\r
<extension\r
priority="3"\r
type_uris="http://www.simantics.org/Sysdyn#Configuration">\r
</adapter>\r
+ <adapter\r
+ editorId="org.simantics.sysdyn.ui.modelicaEditor"\r
+ priority="2"\r
+ type_uris="http://www.simantics.org/Sysdyn#Configuration">\r
+ </adapter>\r
</extension>\r
<extension\r
point="org.eclipse.ui.views">\r
id="org.simantics.sysdyn.ui.category"\r
name="System Dynamics">\r
</category>\r
- <view\r
- category="org.simantics.sysdyn.ui.category"\r
- class="org.simantics.sysdyn.ui.modelica.ModelicaView"\r
- id="org.simantics.sysdyn.ui.modelica.view"\r
- 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
0.5 * (fromOrigo.getY() + toOrigo.getY())\r
);\r
editor.getDiagram().addElement(new FlowElement(from, (ValveElement)newElement));\r
- editor.getDiagram().addElement(new FlowElement(to, (ValveElement)newElement));\r
+ editor.getDiagram().addElement(new FlowElement(to, (ValveElement)newElement)); \r
}\r
else if(from instanceof ValveElement && to instanceof AuxiliaryElement)\r
newElement = new DependencyElement(to, from);\r
else \r
newElement = new DependencyElement(from, to);\r
editor.getDiagram().addElement(newElement);\r
+ if(newElement instanceof ValveElement)\r
+ ((ValveElement)newElement).beginRenameAction(editor);\r
}\r
\r
from = null;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
\r
@GraphType("http://www.simantics.org/Sysdyn#Valve")\r
-public class ValveElement extends RectangularElement implements Connectable, Rotatable {\r
+public class ValveElement extends TextElement implements Rotatable {\r
\r
public static final double VALVE_SIZE = 5.0;\r
\r
valveNode.setColor(Color.BLACK);\r
valveNode.setScaleStroke(true);\r
valveNode.setStroke(new BasicStroke(1));\r
- update();\r
+ super.init(parent);\r
}\r
\r
@Override\r
public void remove() {\r
valveNode.remove();\r
+ super.remove();\r
}\r
\r
@Override\r
- protected void update() {\r
- bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE);\r
+ protected void update() { \r
Path2D path = new Path2D.Double();\r
path.moveTo(posX-VALVE_SIZE, posY-VALVE_SIZE);\r
if(rotated) {\r
path.closePath();\r
valveNode.setShape(path);\r
super.update();\r
+ bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE);\r
}\r
\r
@Override\r
--- /dev/null
+package org.simantics.sysdyn.ui.elements;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.geom.Path2D;\r
+\r
+import org.simantics.h2d.element.handler.Connectable;\r
+import org.simantics.h2d.element.handler.Rotatable;\r
+import org.simantics.h2d.node.ShapeNode;\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+\r
+@GraphType("http://www.simantics.org/Sysdyn#Valve")\r
+public class ValveElementOld extends RectangularElement implements Connectable, Rotatable {\r
+ \r
+ public static final double VALVE_SIZE = 5.0;\r
+ \r
+ ShapeNode valveNode;\r
+ boolean rotated = false;\r
+ \r
+ public ValveElementOld() { \r
+ }\r
+ \r
+ public ValveElementOld(double x, double y) {\r
+ this.posX = x;\r
+ this.posY = y; \r
+ }\r
+\r
+ @Override\r
+ public void init(G2DParentNode parent) {\r
+ valveNode = parent.addNode(ShapeNode.class);\r
+ valveNode.setColor(Color.BLACK);\r
+ valveNode.setScaleStroke(true);\r
+ valveNode.setStroke(new BasicStroke(1));\r
+ update();\r
+ }\r
+\r
+ @Override\r
+ public void remove() {\r
+ valveNode.remove();\r
+ }\r
+ \r
+ @Override\r
+ protected void update() {\r
+ bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE);\r
+ Path2D path = new Path2D.Double();\r
+ path.moveTo(posX-VALVE_SIZE, posY-VALVE_SIZE);\r
+ if(rotated) {\r
+ path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE);\r
+ path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE);\r
+ }\r
+ else { \r
+ path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE);\r
+ path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE); \r
+ }\r
+ path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE);\r
+ path.closePath();\r
+ valveNode.setShape(path);\r
+ super.update();\r
+ }\r
+\r
+ @Override\r
+ public void rotate(int amount) {\r
+ if((amount & 1) == 1) {\r
+ rotated = !rotated;\r
+ update();\r
+ }\r
+ }\r
+\r
+ public boolean isRotated() {\r
+ return rotated;\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.modelica;\r
+\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.eclipse.jface.text.IDocument;\r
+import org.eclipse.jface.text.TextAttribute;\r
+import org.eclipse.jface.text.presentation.IPresentationReconciler;\r
+import org.eclipse.jface.text.presentation.PresentationReconciler;\r
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;\r
+import org.eclipse.jface.text.rules.ICharacterScanner;\r
+import org.eclipse.jface.text.rules.IRule;\r
+import org.eclipse.jface.text.rules.IToken;\r
+import org.eclipse.jface.text.rules.RuleBasedScanner;\r
+import org.eclipse.jface.text.rules.Token;\r
+import org.eclipse.jface.text.source.ISourceViewer;\r
+import org.eclipse.jface.text.source.SourceViewerConfiguration;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Color;\r
+\r
+public class ModelicaSourceViewerConfiguration extends SourceViewerConfiguration {\r
+\r
+ public IPresentationReconciler getPresentationReconciler(\r
+ ISourceViewer sourceViewer) {\r
+ PresentationReconciler pr = new PresentationReconciler();\r
+ DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(\r
+ new RuleBasedScanner() { \r
+ {\r
+ setRules(new IRule[] {new IRule() {\r
+\r
+ @Override\r
+ public IToken evaluate(ICharacterScanner scanner) {\r
+ int ch;\r
+ try {\r
+ scanner.unread();\r
+ ch = scanner.read();\r
+ } catch (Throwable t) {\r
+ ch = -1;\r
+ }\r
+ if (ch <= 0 || !isIdentifierChar((char) ch)) {\r
+ ch = scanner.read();\r
+ if(isIdentifierChar((char)ch)) {\r
+ StringBuilder b = new StringBuilder();\r
+ do {\r
+ b.append((char)ch);\r
+ ch = scanner.read();\r
+ } while(isIdentifierChar((char) ch));\r
+ String str = b.toString();\r
+ if(keywords.contains(str))\r
+ return getModelicaKeywordToken();\r
+ }\r
+ scanner.unread();\r
+ }\r
+ return Token.UNDEFINED;\r
+ } \r
+ \r
+ }});\r
+ } \r
+ }\r
+ );\r
+ pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE);\r
+ pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE);\r
+ return pr;\r
+ }\r
+ \r
+ static boolean isIdentifierChar(char c) {\r
+ return \r
+ (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') \r
+ || (c >= '0' && c <= '9') || c == '_';\r
+ }\r
+ \r
+ static final Set<String> keywords = new HashSet<String>();\r
+ \r
+ static {\r
+ keywords.add("within");\r
+ keywords.add("final");\r
+ keywords.add("public");\r
+ keywords.add("protected");\r
+ keywords.add("connect");\r
+ keywords.add("when");\r
+ keywords.add("then");\r
+ keywords.add("elsewhen");\r
+ keywords.add("if");\r
+ keywords.add("end");\r
+ keywords.add("elseif");\r
+ keywords.add("else");\r
+ keywords.add("for");\r
+ keywords.add("while");\r
+ keywords.add("loop");\r
+ keywords.add("der");\r
+ keywords.add("enumeration");\r
+ keywords.add("extends");\r
+ keywords.add("class");\r
+ keywords.add("partial");\r
+ keywords.add("encapsulated");\r
+ keywords.add("model");\r
+ keywords.add("record");\r
+ keywords.add("block");\r
+ keywords.add("expandable");\r
+ keywords.add("connector");\r
+ keywords.add("type");\r
+ keywords.add("package");\r
+ keywords.add("function");\r
+ keywords.add("import");\r
+ keywords.add("external");\r
+ keywords.add("constrainedby");\r
+ keywords.add("redeclare");\r
+ keywords.add("replaceable");\r
+ keywords.add("flow");\r
+ keywords.add("discrete");\r
+ keywords.add("parameter");\r
+ keywords.add("constant");\r
+ keywords.add("input");\r
+ keywords.add("output");\r
+ keywords.add("annotation");\r
+ keywords.add("false");\r
+ keywords.add("true");\r
+ keywords.add("each");\r
+ keywords.add("initial");\r
+ keywords.add("algorithm");\r
+ keywords.add("equation");\r
+ keywords.add("or");\r
+ keywords.add("and");\r
+ keywords.add("not");\r
+ keywords.add("break");\r
+ keywords.add("return"); \r
+ }\r
+\r
+ static IToken modelicaKeywordToken = null;\r
+ public IToken getModelicaKeywordToken() {\r
+ if(modelicaKeywordToken == null) {\r
+ modelicaKeywordToken = \r
+ new Token(\r
+ new TextAttribute(\r
+ new Color(null, 127, 0, 85),\r
+ new Color(null, 255, 255, 255),\r
+ SWT.BOLD\r
+ ));\r
+ }\r
+ return modelicaKeywordToken;\r
+ }\r
+ \r
+}\r
+++ /dev/null
-package org.simantics.sysdyn.ui.modelica;\r
-\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.ui.ISelectionListener;\r
-import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.part.ViewPart;\r
-\r
-public class ModelicaView extends ViewPart implements ISelectionListener {\r
- \r
- @Override \r
- public void createPartControl(Composite parent) {\r
- getSite().getPage().addPostSelectionListener(this);\r
- new Label(parent, SWT.NONE).setText("Hello World!");\r
- } \r
-\r
- @Override\r
- public void setFocus() {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- @Override\r
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
- System.out.println("selection changed");\r
- }\r
-\r
-}\r
--- /dev/null
+package org.simantics.sysdyn.ui.modelica;\r
+\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.jface.operation.IRunnableContext;\r
+import org.eclipse.jface.text.Document;\r
+import org.eclipse.jface.text.IDocument;\r
+import org.eclipse.jface.text.PaintManager;\r
+import org.eclipse.jface.text.source.AnnotationModel;\r
+import org.eclipse.jface.text.source.AnnotationPainter;\r
+import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;\r
+import org.eclipse.jface.text.source.IAnnotationModel;\r
+import org.eclipse.jface.text.source.MatchingCharacterPainter;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.graphics.RGB;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.editors.text.TextEditor;\r
+import org.eclipse.ui.texteditor.AbstractDocumentProvider;\r
+\r
+\r
+public class SysdynModelicaEditor extends TextEditor {\r
+\r
+ AnnotationModel annotationModel = new AnnotationModel();\r
+ AnnotationPainter apainter;\r
+ \r
+ public SysdynModelicaEditor() {\r
+ super();\r
+ showOverviewRuler();\r
+ setDocumentProvider(new AbstractDocumentProvider() {\r
+\r
+ @Override\r
+ protected IAnnotationModel createAnnotationModel(Object element)\r
+ throws CoreException {\r
+ return annotationModel;\r
+ }\r
+\r
+ @Override\r
+ protected IDocument createDocument(Object element)\r
+ throws CoreException {\r
+ return new Document((String)getEditorInput().getAdapter(String.class));\r
+ }\r
+\r
+ @Override\r
+ protected void doSaveDocument(IProgressMonitor monitor,\r
+ Object element, IDocument document, boolean overwrite)\r
+ throws CoreException {\r
+ }\r
+\r
+ @Override\r
+ protected IRunnableContext getOperationRunner(\r
+ IProgressMonitor monitor) {\r
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow();\r
+ }\r
+ \r
+ @Override\r
+ public boolean isModifiable(Object element) {\r
+ return false;\r
+ }\r
+ \r
+ @Override\r
+ public boolean isReadOnly(Object element) {\r
+ return true;\r
+ }\r
+ \r
+ }); \r
+ \r
+ setSourceViewerConfiguration(new ModelicaSourceViewerConfiguration());\r
+ \r
+ }\r
+ \r
+ @Override\r
+ protected void createActions() {\r
+ super.createActions();\r
+ \r
+ PaintManager paintManager = new PaintManager(getSourceViewer());\r
+ MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(getSourceViewer(),\r
+ new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} ));\r
+ matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160)));\r
+ paintManager.addPainter(matchingCharacterPainter);\r
+ }\r
+ \r
+ \r
+}\r
+\r
--- /dev/null
+package org.simantics.sysdyn.ui.modelica;\r
+\r
+import org.eclipse.ui.part.EditorActionBarContributor;\r
+\r
+public class TextEditorActionBarContributor extends EditorActionBarContributor {\r
+\r
+ public TextEditorActionBarContributor() {\r
+ // TODO Auto-generated constructor stub\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.objmap.IMapping;\r
+import org.simantics.objmap.Mappings;\r
+\r
+public class LoadRepresentation {\r
+\r
+ public static Configuration load(Session session, final Resource configuration) throws DatabaseException {\r
+ return session.syncRequest(new Read<Configuration>() {\r
+\r
+ @Override\r
+ public Configuration perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ SysdynSchema schema = new SysdynSchema(graph);\r
+ IMapping mapping = Mappings.createWithoutListening(schema);\r
+ return (Configuration)mapping.map(graph, configuration); \r
+ }\r
+ \r
+ });\r
+ }\r
+ \r
+}\r
--- /dev/null
+package org.simantics.sysdyn.representation;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.objmap.schema.MappingSchemas;\r
+import org.simantics.objmap.schema.SimpleSchema;\r
+\r
+public class SysdynSchema extends SimpleSchema {\r
+ \r
+ public SysdynSchema(ReadGraph g) { \r
+ try {\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Auxiliary.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Cloud.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Configuration.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Dependency.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Flow.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Stock.class));\r
+ addLinkType(MappingSchemas.fromAnnotations(g, Valve.class));\r
+ } catch (DatabaseException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (InstantiationException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (IllegalAccessException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } \r
+ }\r
+\r
+}\r