<graph />\r
<this />\r
</type>\r
- </target>\r \r <target\r interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Result"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r </target>\r \r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r\r <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r </target>\r \r
+ </target>\r \r <target\r interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Result"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r </target>\r\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r\r <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r </target>\r \r
</adapters>
\ No newline at end of file
import org.simantics.g2d.canvas.ICanvasContext;\r
import org.simantics.g2d.canvas.impl.CanvasContext;\r
import org.simantics.g2d.diagram.participant.DeleteHandler;\r
-import org.simantics.modeling.ui.diagramEditor.PopulateElementDropParticipant;\r
-import org.simantics.modeling.ui.diagramEditor.PopulateElementMonitorDropParticipant;\r
import org.simantics.modeling.ui.diagramEditor.handlers.WorkbenchStructuralSelectionProvider2;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
SysdynResource.getInstance(graph);\r
}\r
\r
- @Override\r
- protected void addDropParticipants(ICanvasContext ctx) {\r
- // FIXME This is a workaround so that this participant can be disabled\r
- // for SymbolViewer\r
- ctx.add(new PopulateElementDropParticipant(synchronizer));\r
- ctx.add(new PopulateElementMonitorDropParticipant(synchronizer, 0.15, 0.15));\r
- }\r
-\r
@Override\r
protected void addStructureParticipants(ICanvasContext ctx) {\r
structuralPath = getResourceInput().getResourceArray().removeFromBeginning(1);\r
package org.simantics.sysdyn.ui.elements2;\r
\r
import java.awt.BasicStroke;\r
-import java.awt.geom.AffineTransform;\r
import java.awt.geom.Ellipse2D;\r
-import java.util.ArrayList;\r
import java.util.Collection;\r
-import java.util.Collections;\r
\r
-import org.simantics.db.Builtins;\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.diagram.G2DUtils;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.content.ResourceTerminal;\r
import org.simantics.diagram.elements.TextElementHandler;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.stubs.G2DResource;\r
-import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
-import org.simantics.diagram.synchronization.IHintSynchronizer;\r
-import org.simantics.diagram.synchronization.SynchronizationHints;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.TextImpl;\r
import org.simantics.g2d.image.Image;\r
import org.simantics.g2d.image.impl.ShapeImage;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class AuxiliaryFactory extends SysdynElementFactory {\r
\r
-public class AuxiliaryFactory extends SyncElementFactory {\r
-\r
- public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
- ComponentNameSynchronizer.INSTANCE,\r
- TransformSynchronizer.INSTANCE);\r
-\r
- @Override\r
- public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- G2DResource g2d = G2DResource.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
-\r
- Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
- String text = null;\r
- if (component != null) {\r
- text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
- }\r
- if (text == null)\r
- text = "[empty]";\r
-\r
- ElementUtils.setText(e, text);\r
-\r
- if (graph.isInstanceOf(element, dr.FontProvider)) {\r
- Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
- if (fontResource != null)\r
- ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
- }\r
- if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
- Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
- if (colorResource != null)\r
- ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
- }\r
-\r
- AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
- ElementUtils.setTransform(e, at);\r
-\r
- // This synchronizes only text and transformation (not font and color)\r
- e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
- }\r
+ // TODO: make the static symbol image a text "AUX"\r
+ private static final Image AUX_STATIC_IMAGE = new ShapeImage(new Ellipse2D.Double(-5, -2, 10, 4), null, new BasicStroke(0.1f), true);\r
\r
@Override\r
- public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
- throws DatabaseException {\r
- StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
-\r
- Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
- Collection<Resource> definedBy = Collections.emptyList();\r
- if (definedByList != null)\r
- definedBy = OrderedSetUtils.toList(graph, definedByList);\r
- Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
- for (Resource r : definedBy) {\r
- if (graph.isInstanceOf(r, dr.Terminal)) {\r
- terminals.add(new ResourceTerminal(r));\r
- }\r
- }\r
-\r
+ protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
return ElementClass.compile(\r
SimpleElementLayers.INSTANCE,\r
OutlinePick.INSTANCE,\r
).setId(AuxiliaryFactory.class.getSimpleName());\r
}\r
\r
- // TODO: make the static symbol image a text "AUX"\r
- private static final Image AUX_STATIC_IMAGE = new ShapeImage(new Ellipse2D.Double(-5, -2, 10, 4), null, new BasicStroke(0.1f), true);\r
-\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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
+ * 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.elements2;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Shape;\r
+import java.awt.geom.Path2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
+import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
+import org.simantics.g2d.element.handler.impl.OutlinePick;\r
+import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
+import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
+import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer;\r
+import org.simantics.g2d.element.handler.impl.StaticSymbolImpl;\r
+import org.simantics.g2d.element.handler.impl.TextColorImpl;\r
+import org.simantics.g2d.element.handler.impl.TextFontImpl;\r
+import org.simantics.g2d.element.handler.impl.TextImpl;\r
+import org.simantics.g2d.image.Image;\r
+import org.simantics.g2d.image.impl.ShapeImage;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+\r
+public class CloudFactory extends SysdynElementFactory {\r
+\r
+ public static final double CLOUD_SIZE_X = 5.0;\r
+ public static final double CLOUD_SIZE_Y = 3.0;\r
+ public static final double CLOUD_CURVES = 7;\r
+\r
+ private static final BasicStroke STROKE = new BasicStroke(1f);\r
+ private static final Image DEFAULT_IMAGE = new ShapeImage(getCloudShape(), null, STROKE, true);\r
+\r
+ static Shape getCloudShape() {\r
+ Path2D path = new Path2D.Double();\r
+ double ox = CLOUD_SIZE_X;\r
+ double oy = 0.0;\r
+ double posX = 0;\r
+ double posY = 0;\r
+ path.moveTo(posX + ox, posY + oy);\r
+ for (int i = 1; i < CLOUD_CURVES + 1; ++i) {\r
+ double angle = (Math.PI * 2.0 / CLOUD_CURVES) * i;\r
+ double x = Math.cos(angle) * CLOUD_SIZE_X;\r
+ double y = Math.sin(angle) * CLOUD_SIZE_Y;\r
+ path.curveTo(\r
+ posX + (2*ox + x)*0.5, posY + (2*oy + y)*0.5,\r
+ posX + (ox + 2*x)*0.5, posY + (oy + 2*y)*0.5,\r
+ posX + x, posY + y);\r
+ ox = x;\r
+ oy = y;\r
+ }\r
+ return path;\r
+ }\r
+\r
+ @Override\r
+ protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
+ return ElementClass.compile(\r
+ SimpleElementLayers.INSTANCE,\r
+ OutlinePick.INSTANCE,\r
+ TextImpl.INSTANCE,\r
+ TextColorImpl.BLACK,\r
+ TextFontImpl.DEFAULT,\r
+ DefaultTransform.INSTANCE,\r
+ new StaticObjectAdapter(elementType),\r
+ new StaticSymbolImpl(DEFAULT_IMAGE),\r
+ StaticSymbolImageInitializer.INSTANCE,\r
+ CloudSceneGraph.INSTANCE,\r
+ BoundsOutline.INSTANCE,\r
+ new WholeElementTerminals(terminals)\r
+ ).setId(CloudFactory.class.getSimpleName());\r
+ }\r
+\r
+\r
+ public static class CloudSceneGraph implements SceneGraph, InternalSize {\r
+\r
+ private static final long serialVersionUID = 5544256245734478634L;\r
+\r
+ public static final CloudSceneGraph INSTANCE = new CloudSceneGraph();\r
+\r
+ private static final Key NODE = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE");\r
+\r
+ @Override\r
+ public void init(IElement e, G2DParentNode parent) {\r
+ ShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", ShapeNode.class);\r
+\r
+ node.setStroke(STROKE);\r
+ node.setScaleStroke(true);\r
+ node.setColor(Color.BLACK);\r
+ node.setShape(getCloudShape());\r
+ }\r
+\r
+ @Override\r
+ public void cleanup(IElement e) {\r
+ ElementUtils.removePossibleNode(e, NODE);\r
+ }\r
+\r
+ @Override\r
+ public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
+ if (size == null)\r
+ size = new Rectangle2D.Double();\r
+ size.setFrame(getCloudShape().getBounds2D());\r
+ return size;\r
+ }\r
+\r
+ }\r
+\r
+}\r
package org.simantics.sysdyn.ui.elements2;\r
\r
import java.awt.BasicStroke;\r
-import java.awt.geom.AffineTransform;\r
import java.awt.geom.Rectangle2D;\r
-import java.util.ArrayList;\r
import java.util.Collection;\r
-import java.util.Collections;\r
\r
-import org.simantics.db.Builtins;\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.diagram.G2DUtils;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.content.ResourceTerminal;\r
import org.simantics.diagram.elements.TextElementHandler;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.stubs.G2DResource;\r
-import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
-import org.simantics.diagram.synchronization.IHintSynchronizer;\r
-import org.simantics.diagram.synchronization.SynchronizationHints;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
import org.simantics.g2d.element.handler.impl.TextImpl;\r
import org.simantics.g2d.image.Image;\r
import org.simantics.g2d.image.impl.ShapeImage;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
\r
-public class StockFactory extends SyncElementFactory {\r
+public class StockFactory extends SysdynElementFactory {\r
\r
- public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
- ComponentNameSynchronizer.INSTANCE,\r
- TransformSynchronizer.INSTANCE);\r
+ private static final BasicStroke STROKE = new BasicStroke(1f);\r
+ private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, STROKE, true);\r
\r
@Override\r
- public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- G2DResource g2d = G2DResource.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
-\r
- Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
- String text = null;\r
- if (component != null) {\r
- text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
- }\r
- if (text == null)\r
- text = "[empty]";\r
-\r
- ElementUtils.setText(e, text);\r
-\r
- if (graph.isInstanceOf(element, dr.FontProvider)) {\r
- Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
- if (fontResource != null)\r
- ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
- }\r
- if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
- Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
- if (colorResource != null)\r
- ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
- }\r
-\r
- AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
- ElementUtils.setTransform(e, at);\r
-\r
- // This synchronizes only text and transformation (not font and color)\r
- e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
- }\r
-\r
- @Override\r
- public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
- throws DatabaseException {\r
- StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
-\r
- Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
- Collection<Resource> definedBy = Collections.emptyList();\r
- if (definedByList != null)\r
- definedBy = OrderedSetUtils.toList(graph, definedByList);\r
- Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
- for (Resource r : definedBy) {\r
- if (graph.isInstanceOf(r, dr.Terminal)) {\r
- terminals.add(new ResourceTerminal(r));\r
- }\r
- }\r
-\r
+ protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
return ElementClass.compile(\r
SimpleElementLayers.INSTANCE,\r
OutlinePick.INSTANCE,\r
).setId(StockFactory.class.getSimpleName());\r
}\r
\r
- private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, new BasicStroke(0.1f), Image.VECTOR);\r
-\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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
+ * 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.elements2;\r
+\r
+import java.awt.geom.AffineTransform;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+import org.simantics.db.Builtins;\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.diagram.G2DUtils;\r
+import org.simantics.diagram.adapter.SyncElementFactory;\r
+import org.simantics.diagram.content.ResourceTerminal;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.diagram.stubs.G2DResource;\r
+import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
+import org.simantics.diagram.synchronization.IHintSynchronizer;\r
+import org.simantics.diagram.synchronization.SynchronizationHints;\r
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
+import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+\r
+/**\r
+ * An ElementFactory that gathers common functionality for system dynamics symbols.\r
+ * Just implement {@link #compileElementClass(Resource, Collection)} to add a symbol.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public abstract class SysdynElementFactory extends SyncElementFactory {\r
+\r
+ public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
+ ComponentNameSynchronizer.INSTANCE,\r
+ TransformSynchronizer.INSTANCE);\r
+\r
+ @Override\r
+ public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ G2DResource g2d = G2DResource.getInstance(graph);\r
+ DiagramResource dr = DiagramResource.getInstance(graph);\r
+ ModelingResources mr = ModelingResources.getInstance(graph);\r
+\r
+ Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
+ String text = null;\r
+ if (component != null) {\r
+ text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
+ }\r
+ if (text == null)\r
+ text = "[empty]";\r
+\r
+ ElementUtils.setText(e, text);\r
+\r
+ if (graph.isInstanceOf(element, dr.FontProvider)) {\r
+ Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
+ if (fontResource != null)\r
+ ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
+ }\r
+ if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
+ Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
+ if (colorResource != null)\r
+ ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
+ }\r
+\r
+ AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
+ ElementUtils.setTransform(e, at);\r
+\r
+ // This synchronizes only text and transformation (not font and color)\r
+ e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
+ }\r
+\r
+ @Override\r
+ public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
+ throws DatabaseException {\r
+ StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
+ DiagramResource dr = DiagramResource.getInstance(graph);\r
+\r
+ Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
+ Collection<Resource> definedBy = Collections.emptyList();\r
+ if (definedByList != null)\r
+ definedBy = OrderedSetUtils.toList(graph, definedByList);\r
+ Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
+ for (Resource r : definedBy) {\r
+ if (graph.isInstanceOf(r, dr.Terminal)) {\r
+ terminals.add(new ResourceTerminal(r));\r
+ }\r
+ }\r
+\r
+ return compileElementClass(elementType, terminals);\r
+ }\r
+\r
+ /**\r
+ * @param elementType the type of the loaded element\r
+ * @param terminals the terminals of the element type being loaded\r
+ * @return an {@link ElementClass} representing the loaded element type\r
+ */\r
+ protected abstract ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals);\r
+\r
+}\r
\r
import java.awt.BasicStroke;\r
import java.awt.Color;\r
-import java.awt.geom.AffineTransform;\r
import java.awt.geom.Path2D;\r
import java.awt.geom.Rectangle2D;\r
-import java.util.ArrayList;\r
import java.util.Collection;\r
-import java.util.Collections;\r
\r
-import org.simantics.db.Builtins;\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.diagram.G2DUtils;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.content.ResourceTerminal;\r
import org.simantics.diagram.elements.TextElementNoBounds;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.stubs.G2DResource;\r
-import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
-import org.simantics.diagram.synchronization.IHintSynchronizer;\r
-import org.simantics.diagram.synchronization.SynchronizationHints;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
import org.simantics.g2d.element.ElementClass;\r
import org.simantics.g2d.element.ElementUtils;\r
import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.image.Image;\r
import org.simantics.g2d.image.impl.ShapeImage;\r
import org.simantics.g2d.utils.Alignment;\r
-import org.simantics.modeling.ModelingResources;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
\r
\r
-public class ValveFactory extends SyncElementFactory {\r
+public class ValveFactory extends SysdynElementFactory {\r
\r
- public static final Key KEY_ROTATED = new KeyOf(Boolean.class, "ROTATED");\r
+ public static final Key KEY_ROTATED = new KeyOf(Boolean.class, "ROTATED");\r
\r
- public static final double VALVE_SIZE = 2.5;\r
+ public static final double VALVE_SIZE = 2.5;\r
\r
- public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
- ComponentNameSynchronizer.INSTANCE,\r
- TransformSynchronizer.INSTANCE);\r
+ private static final ElementHandler TEXT_NODE = new TextElementNoBounds(0, VALVE_SIZE + 2, Alignment.CENTER);\r
\r
- @Override\r
- public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- G2DResource g2d = G2DResource.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
- ModelingResources mr = ModelingResources.getInstance(graph);\r
-\r
- Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
- String text = null;\r
- if (component != null) {\r
- text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
- }\r
- if (text == null)\r
- text = "[empty]";\r
-\r
- ElementUtils.setText(e, text);\r
-\r
- if (graph.isInstanceOf(element, dr.FontProvider)) {\r
- Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
- if (fontResource != null)\r
- ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
- }\r
- if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
- Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
- if (colorResource != null)\r
- ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
- }\r
-\r
- AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
- ElementUtils.setTransform(e, at);\r
-\r
- // This synchronizes only text and transformation (not font and color)\r
- e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
- }\r
+ private static final BasicStroke STROKE = new BasicStroke(1f);\r
+ private static final Image VALVE_STATIC_IMAGE = new ShapeImage(createShape(VALVE_SIZE, false), null, STROKE, true);\r
\r
+ /* (non-Javadoc)\r
+ * @see org.simantics.sysdyn.ui.elements2.SysdynElementFactory#compileElementClass(org.simantics.db.Resource, java.util.Collection)\r
+ */\r
@Override\r
- public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
- throws DatabaseException {\r
- StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
- DiagramResource dr = DiagramResource.getInstance(graph);\r
-\r
- Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
- Collection<Resource> definedBy = Collections.emptyList();\r
- if (definedByList != null)\r
- definedBy = OrderedSetUtils.toList(graph, definedByList);\r
- Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
- for (Resource r : definedBy) {\r
- if (graph.isInstanceOf(r, dr.Terminal)) {\r
- terminals.add(new ResourceTerminal(r));\r
- }\r
- }\r
-\r
+ protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
return ElementClass.compile(\r
SimpleElementLayers.INSTANCE,\r
OutlinePick.INSTANCE,\r
).setId(ValveFactory.class.getSimpleName());\r
}\r
\r
- private static final ElementHandler TEXT_NODE = new TextElementNoBounds(0, VALVE_SIZE+2, Alignment.CENTER);\r
-\r
- private static final BasicStroke STROKE = new BasicStroke(1f);\r
- private static final Image VALVE_STATIC_IMAGE = new ShapeImage(createShape(VALVE_SIZE, false), null, STROKE, true);\r
-\r
/**\r
* @param valveSize\r
* @param rotated <code>true</code> for vertical valve, <code>false</code>\r
public void init(IElement e, G2DParentNode parent) {\r
ShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", ShapeNode.class);\r
\r
- System.out.println("shape node : " + node);\r
// Calculate borders from text node bounds.\r
node.setStroke(STROKE);\r
node.setScaleStroke(true);\r
node.setColor(Color.BLACK);\r
node.setShape(createShape(VALVE_SIZE, Boolean.TRUE.equals(e.getHint(KEY_ROTATED))));\r
- System.out.println("shape node after init: " + node);\r
}\r
\r
@Override\r
ModelingUtils mu = new ModelingUtils(g);\r
\r
Resource model = g.newResource();\r
- g.claimValue(model, b.HasName, "Model1");\r
- g.claimValue(model, b.HasLabel, "Model1");\r
+\r
+ String modelName = GraphUtils.findFreshName(g, "Model", library, b.ConsistsOf, "%s%d");\r
+\r
+ g.claimValue(model, b.HasName, modelName);\r
+ g.claimValue(model, b.HasLabel, modelName);\r
g.claim(model, b.InstanceOf, sr.SysdynModel);\r
g.claim(model, b.PartOf, library);\r
\r
public final Resource AuxiliarySymbol;\r
public final Resource BasicExperiment;\r
public final Resource Cloud;\r
+ public final Resource CloudSymbol;\r
public final Resource Configuration;\r
public final Resource ConfigurationDiagram;\r
public final Resource ConstantExpression;\r
public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol";\r
public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment";\r
public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud";\r
+ public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.0/CloudSymbol";\r
public static final String Configuration = "http://www.simantics.org/Sysdyn-1.0/Configuration";\r
public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram";\r
public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.0/ConstantExpression";\r
AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol);\r
BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
Cloud = getResourceOrNull(graph, URIs.Cloud);\r
+ CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
Configuration = getResourceOrNull(graph, URIs.Configuration);\r
ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression);\r
L0.IsDependencyOf BasicSymbolLibrary\r
ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
_ : SysdynTerminal\r
- terminal(StockSymbol, IsHeadOfTerminal)\r
+ terminal(ValveSymbol, IsHeadOfTerminal)\r
_ : SysdynTerminal\r
- terminal(StockSymbol, IsTailOfTerminal)\r
+ terminal(ValveSymbol, IsTailOfTerminal)\r
\r
######################################################################\r
Auxiliary\r
L0.IsDependencyOf BasicSymbolLibrary\r
ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
_ : SysdynTerminal\r
- terminal(StockSymbol, IsHeadOfTerminal)\r
+ terminal(AuxiliarySymbol, IsHeadOfTerminal)\r
_ : SysdynTerminal\r
- terminal(StockSymbol, IsTailOfTerminal)\r
+ terminal(AuxiliarySymbol, IsTailOfTerminal)\r
+\r
+######################################################################\r
+Cloud\r
+ def()\r
+ connection(IsTailOf)\r
+ connection(IsHeadOf)\r
+\r
+CloudSymbol <T DIA.FontProvider <T DIA.ColorProvider\r
+ defSymbol("Cloud", Cloud)\r
+ L0.IsDependencyOf BasicSymbolLibrary\r
+ ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
+ _ : SysdynTerminal\r
+ terminal(CloudSymbol, IsHeadOfTerminal)\r
+ _ : SysdynTerminal\r
+ terminal(CloudSymbol, IsTailOfTerminal)\r
\r
######################################################################\r
# Diagram connection types\r