From: jplaine Date: Wed, 3 Mar 2010 12:51:16 +0000 (+0000) Subject: Initial implementation of ISceneGraphProvider for Sysdyn resources. Can be used to... X-Git-Tag: simantics-1.0~55 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=32384431406dbe28b25b077cb61afb114c3fbeca;p=simantics%2Fsysdyn.git Initial implementation of ISceneGraphProvider for Sysdyn resources. Can be used to display Sysdyn models in applet, but event handling is not implemented. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14525 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml index 3af512f2..21a73a13 100644 --- a/org.simantics.sysdyn.ui/adapters.xml +++ b/org.simantics.sysdyn.ui/adapters.xml @@ -6,4 +6,13 @@ uri="http://www.simantics.org/Sysdyn#SysdynProject" class="org.simantics.sysdyn.ui.project.SysdynProject" /> + + + + + + \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java new file mode 100644 index 00000000..98a7f246 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java @@ -0,0 +1,161 @@ +package org.simantics.sysdyn.ui.sg; + +import java.awt.AWTEvent; +import java.awt.event.AWTEventListener; +import java.awt.geom.Rectangle2D; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.h2d.diagram.IDiagram; +import org.simantics.h2d.diagram.IDiagramListener; +import org.simantics.h2d.element.IElement; +import org.simantics.objmap.IMapping; +import org.simantics.objmap.IMappingListener; +import org.simantics.objmap.MappingException; +import org.simantics.objmap.Mappings; +import org.simantics.scenegraph.adapters.ISceneGraphProvider; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.scenegraph.g2d.G2DSceneGraph; +import org.simantics.scenegraph.g2d.nodes.NavigationNode; +import org.simantics.scenegraph.g2d.nodes.PageBorderNode; +import org.simantics.scenegraph.g2d.nodes.TransformNode; +import org.simantics.sysdyn.ui.editor.SysdynDiagramSchema; + +public class SysdynSceneGraphProvider implements ISceneGraphProvider, AWTEventListener { + + protected Resource resource; + + IDiagram diagram; + IMapping mapping; + + public SysdynSceneGraphProvider(ReadGraph g, final Resource resource) { + this.resource = resource; + + SysdynDiagramSchema schema; + try { + schema = new SysdynDiagramSchema(g); + } catch (DatabaseException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + return; + } + + mapping = Mappings.createWithListening(schema); + + try { + diagram = (IDiagram)mapping.map(g, resource); + } catch (MappingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + final Session session = g.getSession(); + mapping.addMappingListener(new IMappingListener() { + + @Override + public void rangeModified() { + session.asyncRequest(new WriteRequest() { + + @Override + public void perform(WriteGraph graph) + throws DatabaseException { + try { + mapping.updateDomain(graph); + } catch(Exception e) { + e.printStackTrace(); + } + } + + }); + } + + @Override + public void domainModified() { + session.asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + try { + mapping.updateRange(graph); + } catch(Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + } + + @Override + public void dispose() { + + } + + @Override + public AWTEventListener getEventListener() { + return this; + } + + @Override + public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg) { + return initializeSceneGraph(sg, null); + } + + G2DSceneGraph sceneGraph; + TransformNode diagramCoordinatesNode; + G2DParentNode elementsNode; + G2DParentNode selectionNode; + G2DParentNode actionNode; + + @Override + public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg, String view) { + sceneGraph = sg; + diagramCoordinatesNode = sceneGraph.addNode(NavigationNode.class); + + PageBorderNode border = diagramCoordinatesNode.addNode(PageBorderNode.class); + border.init(new Rectangle2D.Double(0.0, 0.0, 297.0, 210.0), new Rectangle2D.Double(10.0, 10.0, 277.0, 190.0), Boolean.TRUE); + + elementsNode = diagramCoordinatesNode.addNode(G2DParentNode.class); + elementsNode.setZIndex(0); + + selectionNode = diagramCoordinatesNode.addNode(G2DParentNode.class); + selectionNode.setZIndex(1); + + actionNode = diagramCoordinatesNode.addNode(G2DParentNode.class); + actionNode.setZIndex(2); + + for(IElement element : diagram.getElements()) + element.init(elementsNode); + diagram.addDiagramListener(new IDiagramListener() { + + @Override + public void elementAdded(IElement element) { + element.init(elementsNode); + } + + @Override + public void elementRemoved(IElement element) { + element.remove(); + } + }); + + return sg; + } + + @Override + public void setHint(Object key, Object value) { + // TODO Auto-generated method stub + + } + + @Override + public void eventDispatched(AWTEvent event) { + + } + +}