From 3730466cd1e90c50c988292e107639952448d6a6 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Wed, 19 Feb 2020 10:00:20 +0200 Subject: [PATCH] Move remaining profiles to visualisations for perf * Static property information * Dynamic symbols * Not in simulation * Elevation server bounding box gitlab #59 Change-Id: Ia17e7fe59042edcd71426e91c7d8ad5f9996c7c3 --- .../graph/DistrictNetwork.pgraph | 4 + .../graph/DistrictNetworkProfiles.pgraph | 6 +- .../META-INF/MANIFEST.MF | 3 +- .../adapters.xml | 7 - .../network/ui/DistrictDiagramViewer.java | 81 ++++++++++-- .../nodes/DistrictNetworkEdgeArrayNode.java | 2 +- .../ui/nodes/DistrictNetworkEdgeNode.java | 22 +++- .../ui/nodes/DistrictNetworkVertexNode.java | 22 ++++ .../network/ui/nodes/NotInSimulationNode.java | 53 ++++++++ ...VisualisationContributionsParticipant.java | 21 +++ .../ElevationServerParticipant.java | 26 ---- .../DistrictNetworkStaticInfoStyle.java | 111 ++++++++-------- .../DynamicVisualisationsUI.java | 77 ++++++++--- org.simantics.district.network/adapters.xml | 20 --- .../StaticDynamicContribution.scl | 14 ++ .../ActiveDynamicVisualisationsRequest.java | 21 ++- .../network/profile/VertexSymbolStyle.java | 51 +++---- .../visualisations/DynamicVisualisations.java | 21 +++ .../DynamicVisualisationsContributions.java | 124 +++++++++++++++++- .../model/DynamicSymbolContribution.java | 60 +++++++++ .../model/DynamicVisualisation.java | 31 ++++- .../model/StaticInformationContribution.java | 53 ++++++++ 22 files changed, 663 insertions(+), 167 deletions(-) create mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NotInSimulationNode.java delete mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/ElevationServerParticipant.java create mode 100644 org.simantics.district.network/scl/Simantics/District/DynamicVisualisations/StaticDynamicContribution.scl create mode 100644 org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSymbolContribution.java create mode 100644 org.simantics.district.network/src/org/simantics/district/network/visualisations/model/StaticInformationContribution.java diff --git a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph index 87547328..4405434e 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph @@ -279,6 +279,10 @@ DN.Diagram.Visualisations -- DN.Diagram.Visualisations.KeyVariableEdgeHover @defProperty "Key Variables for Edges on Hover" L0.Boolean + >-- DN.Diagram.Visualisations.ShowElevationServerBoundingBox + @defProperty "Show Elevation server bounding box" L0.Boolean + >-- DN.Diagram.Visualisations.NotInSimulation + @defProperty "Not in Simulation" L0.Boolean DN.Diagram.Visualisations.ColorContribution - - - - - diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java index 903c2ffa..19838955 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java @@ -24,7 +24,6 @@ import org.simantics.district.network.ui.nodes.DistrictRenderingPreparationNode; import org.simantics.district.network.ui.nodes.DistrictSelectionNode; import org.simantics.district.network.ui.participants.DNPointerInteractor; import org.simantics.district.network.ui.participants.DynamicVisualisationContributionsParticipant; -import org.simantics.district.network.ui.participants.ElevationServerParticipant; import org.simantics.district.network.ui.participants.MapRulerPainter; import org.simantics.district.network.visualisations.DynamicVisualisations; import org.simantics.district.network.visualisations.model.ColorBarOptions; @@ -76,7 +75,6 @@ public class DistrictDiagramViewer extends DiagramViewer { DynamicVisualisationContributionsParticipant dynamicVisualisationContributionsParticipant = new DynamicVisualisationContributionsParticipant(tr); ctx.add(new NetworkDrawingParticipant(dynamicVisualisationContributionsParticipant, tr)); - ctx.add(new ElevationServerParticipant(tr)); ctx.add(dynamicVisualisationContributionsParticipant); // Optimize AffineTransform memory allocations during district diagram rendering @@ -142,6 +140,7 @@ public class DistrictDiagramViewer extends DiagramViewer { setupColorBarOptions(); setupSizingObjects(); setupSizeBarOptions(); + setupShowElevationServerBoundingBox(); // add listeners DistrictDiagramViewerListener[] listeners = Activator.getInstance().getDistrictDiagramViewerListeners(); @@ -203,13 +202,18 @@ public class DistrictDiagramViewer extends DiagramViewer { () -> DistrictDiagramViewer.this.isDisposed())); } - private void setupSizeBarOptions() { sessionContext.getSession().asyncRequest(new SizeBarOptionsRequest(getInputResource()), new SizeBarOptionsListener( result -> queueSizeBarOptionsChangeEvent(result), () -> DistrictDiagramViewer.this.isDisposed())); } - + + private void setupShowElevationServerBoundingBox() { + sessionContext.getSession().asyncRequest(new ShowElevationServerRequest(getInputResource()), new ShowElevationServerListener( + result -> queueShowElevationServerChangeEvent(result), + () -> DistrictDiagramViewer.this.isDisposed())); + } + public static final Key KEY_MAP_COLOR_BAR_OPTIONS = new KeyOf(ColorBarOptions.class, "colorBarOptions"); public static final Command MAP_COLOR_BAR_OPTIONS_CHANGE = new Command("colorBarOptionsChange"); public static final Key KEY_MAP_SIZE_BAR_OPTIONS = new KeyOf(SizeBarOptions.class, "sizeBarOptions"); @@ -221,11 +225,13 @@ public class DistrictDiagramViewer extends DiagramViewer { public static final Key KEY_MAP_SIZING_OBJECTS = new KeyOf(Map.class, "sizingObjects"); public static final Command MAP_SIZING_OBJECTS_CHANGE = new Command("sizingObjectsChange"); - + public static final Key KEY_SHOW_ELEVATION_SERVER = new KeyOf(Boolean.class, "showElevationServer"); + public static final Command SHOW_ELEVATION_SERVER_CHANGE = new Command("showElevationServerChange"); + private void queueColoringObjectsChangeEvent(Map result) { queueEventInternal(KEY_MAP_COLORING_OBJECTS, MAP_COLORING_OBJECTS_CHANGE, result); } - + private void queueColorBarOptionsChangeEvent(ColorBarOptions result) { queueEventInternal(KEY_MAP_COLOR_BAR_OPTIONS, MAP_COLOR_BAR_OPTIONS_CHANGE, result); } @@ -233,11 +239,15 @@ public class DistrictDiagramViewer extends DiagramViewer { private void queueSizingObjectsChangeEvent(Map result) { queueEventInternal(KEY_MAP_SIZING_OBJECTS, MAP_SIZING_OBJECTS_CHANGE, result); } - + private void queueSizeBarOptionsChangeEvent(SizeBarOptions result) { queueEventInternal(KEY_MAP_SIZE_BAR_OPTIONS, MAP_SIZE_BAR_OPTIONS_CHANGE, result); } + private void queueShowElevationServerChangeEvent(Boolean result) { + queueEventInternal(KEY_SHOW_ELEVATION_SERVER, SHOW_ELEVATION_SERVER_CHANGE, result); + } + private void queueEventInternal(Key key, Command command, Object result) { if (result != null && !canvasContext.isDisposed()) { canvasContext.getThreadAccess().asyncExec(() -> { @@ -411,7 +421,7 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public void exception(Throwable t) { - LOGGER.error("Could not listen ColorBarOptions", t); + LOGGER.error("Could not listen ColoringObjects", t); } @Override @@ -545,7 +555,60 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public void exception(Throwable t) { - LOGGER.error("Could not listen ColorBarOptions", t); + LOGGER.error("Could not listen SizingObjectsOptions", t); + } + + @Override + public boolean isDisposed() { + return isDisposed.get(); + } + } + + private static class ShowElevationServerRequest extends UnaryRead { + + public ShowElevationServerRequest(Resource diagram) { + super(diagram); + } + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + Resource model = graph.syncRequest(new PossibleIndexRoot(parameter)); + if (model != null) { + Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); + if (vf != null) { + Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); + if (activeVisualisation != null) { + return DynamicVisualisations.showElevationServerBoundingBox(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); + } + } + return false; + } + } + + private static class ShowElevationServerListener implements Listener { + + private static final Logger LOGGER = LoggerFactory.getLogger(ShowElevationServerListener.class); + + private Consumer callback; + private Supplier isDisposed; + + public ShowElevationServerListener(Consumer callback, Supplier isDisposed) { + this.callback = callback; + this.isDisposed = isDisposed; + } + + @Override + public void execute(Boolean result) { + callback.accept(result); + } + + @Override + public void exception(Throwable t) { + LOGGER.error("Could not listen Show Elevation Server", t); } @Override diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeArrayNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeArrayNode.java index c387c435..a28abada 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeArrayNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeArrayNode.java @@ -30,7 +30,7 @@ public class DistrictNetworkEdgeArrayNode extends G2DNode implements DeferredNod @Override public void render(Graphics2D g2d) { ParentNode root = (ParentNode) NodeUtil.getNearestParentOfType(this, RTreeNode.class); - DeferredRenderingNode deferred = root != null ? (DeferredRenderingNode) root.getNode(DistrictNetworkStaticInfoStyle.STATIC_INFO_DEFERRED) : null; + DeferredRenderingNode deferred = root != null ? (DeferredRenderingNode) root.getNode(RENDERER_ID) : null; if (deferred != null) deferred.deferNode(g2d.getTransform(), this); else diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java index 195472fc..4d460f5d 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java @@ -5,10 +5,10 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; -import java.awt.geom.Line2D; import java.awt.geom.Path2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.Optional; import org.simantics.district.network.ModelledCRS; import org.simantics.district.network.ui.DistrictNetworkEdge; @@ -290,4 +290,24 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection this.hidden = value; } + public void setStaticInformation(Optional staticInformation) { + DistrictNetworkStaticInfoNode child = getOrCreateNode(DistrictNetworkStaticInfoNode.NODE_KEY, DistrictNetworkStaticInfoNode.class); + child.setEdgeNode(this); + if (staticInformation.isPresent()) { + child.setInfo(staticInformation.get()); + } else { + child.setInfo(null); + } + } + + public void setInSimulation(Optional isInSimulation) { + if (!isInSimulation.isPresent()) { + removeNode(NotInSimulationNode.NODE_NAME); + } else { + NotInSimulationNode child = getOrCreateNode(NotInSimulationNode.NODE_NAME, NotInSimulationNode.class); + child.setZIndex(1000); + child.setIsInSimulation(isInSimulation.get()); + } + } + } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java index 76151a83..b1bb1468 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java @@ -7,6 +7,7 @@ import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.Optional; import org.simantics.district.network.ui.adapters.DistrictNetworkVertex; import org.simantics.maps.MapScalingTransform; @@ -245,4 +246,25 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti public void setHidden(Boolean value) { this.hidden = value; } + + public void setStaticInformation(Optional staticInformation) { + DistrictNetworkStaticInfoNode child = getOrCreateNode(DistrictNetworkStaticInfoNode.NODE_KEY, DistrictNetworkStaticInfoNode.class); + Point2D calculatePoint2D = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), null); + child.setLocation(calculatePoint2D, new Point2D.Double(1.0, 0.0)); + if (staticInformation.isPresent()) { + child.setInfo(staticInformation.get()); + } else { + child.setInfo(null); + } + } + + public void setInSimulation(Optional isInSimulation) { + if (!isInSimulation.isPresent()) { + removeNode(NotInSimulationNode.NODE_NAME); + } else { + NotInSimulationNode child = getOrCreateNode(NotInSimulationNode.NODE_NAME, NotInSimulationNode.class); + child.setZIndex(1000); + child.setIsInSimulation(isInSimulation.get()); + } + } } diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NotInSimulationNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NotInSimulationNode.java new file mode 100644 index 00000000..b0db41cf --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NotInSimulationNode.java @@ -0,0 +1,53 @@ +package org.simantics.district.network.ui.nodes; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.geom.Rectangle2D; + +import org.simantics.scenegraph.ParentNode; +import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.utils.GeometryUtils; + +public class NotInSimulationNode extends G2DNode { + + private static final BasicStroke STROKE = new BasicStroke(1.5f); + public static final String NODE_NAME = "notInSimulation"; + + private static final long serialVersionUID = 1503248449618244809L; + private boolean isInSimulation; + + @Override + public Rectangle2D getBoundsInLocal() { + return null; + } + + @Override + public Rectangle2D getBoundsInLocal(boolean b) { + return null; + } + + @Override + public Rectangle2D getBounds() { + return null; + } + + public void render(java.awt.Graphics2D g) { + if (!isInSimulation) { + ParentNode parent = getParent(); + if (!(parent instanceof DistrictNetworkVertexNode)) + return; + + Rectangle2D bounds = ((DistrictNetworkVertexNode)parent).getBoundsInLocal(); + Rectangle2D expandedBounds = GeometryUtils.expandRectangle( bounds, bounds.getWidth() / 2 ); + + g.setColor(Color.RED); + g.setStroke(GeometryUtils.scaleStroke(STROKE, 1.f / (float)g.getTransform().getScaleX())); + g.draw(expandedBounds); + } + } + + public void setIsInSimulation(boolean isInSimulation) { + this.isInSimulation = isInSimulation; + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java index 36eaaf61..8ddb0491 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java @@ -2,6 +2,9 @@ package org.simantics.district.network.ui.participants; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -21,6 +24,7 @@ import org.simantics.district.network.ui.nodes.DeferredRenderingNode; import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeArrayNode; import org.simantics.district.network.ui.nodes.DistrictNetworkHoverInfoNode; import org.simantics.district.network.ui.nodes.DynamicVisualisationContributionsNode; +import org.simantics.district.network.ui.nodes.ElevationServerNode; import org.simantics.district.network.ui.styles.DistrictNetworkHoverInfoStyle; import org.simantics.district.network.ui.styles.DistrictNetworkHoverInfoStyle.StyleResult; import org.simantics.district.network.visualisations.model.ColorBarOptions; @@ -31,6 +35,7 @@ import org.simantics.district.network.visualisations.model.SizeBarOptions; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; +import org.simantics.maps.elevation.server.SingletonTiffTileInterface; import org.simantics.scenegraph.INode; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; @@ -64,6 +69,8 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas private DistrictNetworkHoverInfoNode hoverInfoNode; private DeferredRenderingNode deferredEdgeArrowRendererNode; + private ElevationServerNode showElevationServerBoundingBoxNode; + public DynamicVisualisationContributionsParticipant(AffineTransform tr) { this.transform = tr; } @@ -75,6 +82,7 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS, hintListener); getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS, hintListener); getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS, hintListener); + getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_SHOW_ELEVATION_SERVER, hintListener); } @Override @@ -88,6 +96,7 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS, hintListener); getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS, hintListener); getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS, hintListener); + getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_SHOW_ELEVATION_SERVER, hintListener); super.removedFromContext(ctx); } @@ -105,6 +114,9 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas Pair> dearn = DistrictNetworkEdgeArrayNode.renderer(); deferredEdgeArrowRendererNode = parent.addNode(dearn.first, dearn.second); + + showElevationServerBoundingBoxNode = parent.addNode(ElevationServerNode.ID, ElevationServerNode.class); + showElevationServerBoundingBoxNode.setTransform(transform); } @EventHandler(priority = 0) @@ -121,6 +133,15 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas node.setColorBarOptions(getColorBarOptions()); node.setDynamicSizingObjects(getDynamicSizingObjects()); node.setSizeBarOptions(getSizeBarOptions()); + + showElevationServerBoundingBoxNode.setRectangles(getRectangles()); + } + + private Collection getRectangles() { + Boolean enabled = getHint(DistrictDiagramViewer.KEY_SHOW_ELEVATION_SERVER); + if (enabled != null && enabled) + return SingletonTiffTileInterface.getBoundingBoxes(); + return Collections.emptyList(); } private Map getDynamicColoringObjects() { diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/ElevationServerParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/ElevationServerParticipant.java deleted file mode 100644 index d5f02bb2..00000000 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/ElevationServerParticipant.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.simantics.district.network.ui.participants; - -import java.awt.geom.AffineTransform; - -import org.simantics.district.network.ui.nodes.ElevationServerNode; -import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; -import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant; -import org.simantics.scenegraph.g2d.G2DParentNode; - -public class ElevationServerParticipant extends AbstractDiagramParticipant { - - private ElevationServerNode node; - - private AffineTransform transform; - - public ElevationServerParticipant(AffineTransform transform) { - this.transform = transform; - } - - @SGInit - public void initSG(G2DParentNode parent) { - node = parent.addNode(ElevationServerNode.ID, ElevationServerNode.class); - node.setTransform(transform); - } - -} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java index 89e48813..d0bc9551 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java @@ -42,6 +42,7 @@ import org.simantics.structural.stubs.StructuralResource2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Deprecated public class DistrictNetworkStaticInfoStyle extends StyleBase { private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkStaticInfoStyle.class); @@ -93,61 +94,65 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase types = graph.getTypes(mapElement); - boolean isEdge = types.contains(DN.Edge); - boolean isVertex = types.contains(DN.Vertex); - if (!isEdge && !isVertex) - return null; - - if (isEdge) { - Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf); - Set edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance()); - if (!edgesToUse.contains(mapElement)) - return null; - } - - Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement); - if (module == null) - return null; - - StructuralResource2 STR = StructuralResource2.getInstance(graph); - Resource moduleType = graph.getPossibleType(module, STR.Component); - if (moduleType == null) - return null; - - Function1 function = getUCPipelineInfoFunctionCached(graph, moduleType); - if (function == null) - return null; - - String result; - try { - Variable variable = Variables.getVariable(graph, module); - Variable moduleVariable = Variables.possibleActiveVariable(graph, variable); - if (moduleVariable == null) - moduleVariable = variable; - - result = Simantics.applySCLRead(graph, function, moduleVariable); - } catch (PendingVariableException | MissingVariableValueException e) { - result = null; - } catch (MissingVariableException e) { - // the requested variable is missing from the UC - String message = e.getMessage(); - LOGGER.warn("Missing variable for calculating style with function {} {}", function, message); - result = "<" + message + ">"; - } - - if (isVertex) { - DiagramResource DIA = DiagramResource.getInstance(graph); - double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation); - Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null); - return new StyleResult(mapElement, p, result); - } else if (isEdge) { - return new StyleResult(mapElement, EDGE, result); - } - return null; + return calculateStyle(graph, entry, mapElement); } + public static StyleResult calculateStyle(ReadGraph graph, Resource entry, Resource mapElement) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + Set types = graph.getTypes(mapElement); + boolean isEdge = types.contains(DN.Edge); + boolean isVertex = types.contains(DN.Vertex); + if (!isEdge && !isVertex) + return null; + + if (isEdge) { + Resource diagram = graph.getSingleObject(mapElement, Layer0.getInstance(graph).PartOf); + Set edgesToUse = graph.syncRequest(new MidBranchEdgeSetRequest(diagram), TransientCacheListener.instance()); + if (!edgesToUse.contains(mapElement)) + return null; + } + + Resource module = DistrictNetworkUtil.getMappedComponentCached(graph, mapElement); + if (module == null) + return null; + + StructuralResource2 STR = StructuralResource2.getInstance(graph); + Resource moduleType = graph.getPossibleType(module, STR.Component); + if (moduleType == null) + return null; + + Function1 function = getUCPipelineInfoFunctionCached(graph, moduleType); + if (function == null) + return null; + + String result; + try { + Variable variable = Variables.getVariable(graph, module); + Variable moduleVariable = Variables.possibleActiveVariable(graph, variable); + if (moduleVariable == null) + moduleVariable = variable; + + result = Simantics.applySCLRead(graph, function, moduleVariable); + } catch (PendingVariableException | MissingVariableValueException e) { + result = null; + } catch (MissingVariableException e) { + // the requested variable is missing from the UC + String message = e.getMessage(); + LOGGER.warn("Missing variable for calculating style with function {} {}", function, message); + result = "<" + message + ">"; + } + + if (isVertex) { + DiagramResource DIA = DiagramResource.getInstance(graph); + double[] coords = graph.getRelatedValue(mapElement, DIA.HasLocation); + Point2D p = DistrictNetworkNodeUtils.calculatePoint2D(new Point2D.Double(coords[0], coords[1]), null); + return new StyleResult(mapElement, p, result); + } else if (isEdge) { + return new StyleResult(mapElement, EDGE, result); + } + return null; + } + @Override public void applyStyleForNode(EvaluationContext evaluationContext, INode parent, StyleResult result) { if (result == null) { diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java index a1b21629..e21bcb2a 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java @@ -101,6 +101,8 @@ public class DynamicVisualisationsUI { private Button resetVisualisationButton; private Button hoveringVertexEnabledButton; private Button hoveringEdgesEnabledButton; + private Button elevationServerEnabledButton; + private Button notInSimulationButton; private List>> edgeArrowSuppliers; @@ -184,6 +186,11 @@ public class DynamicVisualisationsUI { GridLayoutFactory.fillDefaults().numColumns(1).applyTo(intervalElementsComposite); initializeIntervalElements(intervalElementsComposite); + Composite hoverElementsComposite = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(hoverElementsComposite); + GridLayoutFactory.fillDefaults().numColumns(1).applyTo(hoverElementsComposite); + initializeHoverElements(hoverElementsComposite); + Composite hideElementsComposite = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(hideElementsComposite); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(hideElementsComposite); @@ -252,9 +259,9 @@ public class DynamicVisualisationsUI { private void initializeIntervalElements(Composite parent) { Group group = new Group(parent, SWT.NONE); - group.setText("Interval"); + group.setText("Generic"); GridDataFactory.fillDefaults().grab(true, false).applyTo(group); - GridLayoutFactory.fillDefaults().numColumns(6).margins(5, 5).applyTo(group); + GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group); createIntervalElements(group); } @@ -262,8 +269,9 @@ public class DynamicVisualisationsUI { private void createIntervalElements(Composite parent) { Label label = new Label(parent, SWT.NONE); - label.setText("Generic"); + label.setText("Interval (seconds)"); intervalText = new Text(parent, SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(intervalText); addSelectionListener(intervalText); disableUpdatesButton = new Button(parent, SWT.CHECK); @@ -274,6 +282,25 @@ public class DynamicVisualisationsUI { resetVisualisationButton.setText("Reset Visualisation"); addSelectionListener(resetVisualisationButton); + notInSimulationButton = new Button(parent, SWT.CHECK); + notInSimulationButton.setText("Not in Simulation"); + addSelectionListener(notInSimulationButton); + + elevationServerEnabledButton = new Button(parent, SWT.CHECK); + elevationServerEnabledButton.setText("Elevation Server Bounding Box"); + addSelectionListener(elevationServerEnabledButton); + } + + private void initializeHoverElements(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setText("Hover"); + GridDataFactory.fillDefaults().grab(true, false).applyTo(group); + GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5).applyTo(group); + + createHoverElements(group); + } + + private void createHoverElements(Composite parent) { hoveringVertexEnabledButton = new Button(parent, SWT.CHECK); hoveringVertexEnabledButton.setText("Vertex Key Variables on Hover"); addSelectionListener(hoveringVertexEnabledButton); @@ -446,15 +473,14 @@ public class DynamicVisualisationsUI { Combo variableCombo = new Combo(parent, SWT.READ_ONLY); variableCombo.setItems(arrowContributions.keySet().toArray(new String[arrowContributions.size()])); - - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); Text gainText = new Text(parent, SWT.BORDER); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(gainText); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(gainText); addSelectionListener(gainText); Text biasText = new Text(parent, SWT.BORDER); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(biasText); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(biasText); addSelectionListener(biasText); Button defaultButton = new Button(parent, SWT.CHECK); @@ -631,7 +657,9 @@ public class DynamicVisualisationsUI { boolean resetVisualisation = resetVisualisationButton.getSelection(); Long interval; try { - interval = Long.parseLong(intervalText.getText()); + // inteval is in milliseconds but shown as seconds + + interval = (long)(Double.parseDouble(intervalText.getText()) * 1000); } catch (NumberFormatException e) { // ignore interval = 2000L; @@ -641,6 +669,9 @@ public class DynamicVisualisationsUI { boolean hoverVertex = hoveringVertexEnabledButton.getSelection(); boolean hoverEdges = hoveringEdgesEnabledButton.getSelection(); + boolean elevationServerBoundingBox = elevationServerEnabledButton.getSelection(); + boolean notInSimulation = notInSimulationButton.getSelection(); + Simantics.getSession().asyncRequest(new WriteRequest() { @Override @@ -679,6 +710,9 @@ public class DynamicVisualisationsUI { dynamicSymbolsPumpingStations ); DynamicVisualisations.setKeyVariablesHover(graph, exist, hoverVertex, hoverEdges); + + DynamicVisualisations.setElevationServerBoundingBox(graph, exist, elevationServerBoundingBox); + DynamicVisualisations.setNotInSimulation(graph, exist, notInSimulation); } }); } @@ -915,21 +949,21 @@ public class DynamicVisualisationsUI { Combo variableCombo = new Combo(parent, SWT.READ_ONLY); variableCombo.setItems(colorContributions.keySet().toArray(new String[colorContributions.size()])); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); Text minText = new Text(parent, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(minText); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(minText); addSelectionListener(minText); Text maxText = new Text(parent, SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText); addSelectionListener(maxText); Text unit = new Text(parent, SWT.READ_ONLY); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit); + GridDataFactory.fillDefaults().grab(true, false).hint(30, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(unit); Combo colorMapCombo = new Combo(parent, SWT.READ_ONLY); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(colorMapCombo); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(colorMapCombo); colorMapCombo.setItems(colorMaps.keySet().toArray(new String[colorMaps.keySet().size()])); addSelectionListener(colorMapCombo); @@ -1077,22 +1111,21 @@ public class DynamicVisualisationsUI { Combo variableCombo = new Combo(parent, SWT.READ_ONLY); variableCombo.setItems(sizeContributions.keySet().toArray(new String[sizeContributions.size()])); - - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); Text minText = new Text(parent, SWT.BORDER); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(minText); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(minText); addSelectionListener(minText); Text maxText = new Text(parent, SWT.BORDER); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(maxText); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText); addSelectionListener(maxText); Label unit = new Label(parent, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit); + GridDataFactory.fillDefaults().grab(true, false).hint(30, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(unit); Combo sizeMapCombo = new Combo(parent, SWT.READ_ONLY); - GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(sizeMapCombo); + GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(sizeMapCombo); sizeMapCombo.setItems(sizeMaps.keySet().toArray(new String[sizeMaps.keySet().size()])); addSelectionListener(sizeMapCombo); @@ -1449,7 +1482,7 @@ public class DynamicVisualisationsUI { } } - intervalText.setText(Long.toString(visualisation.getInterval())); + intervalText.setText(Double.toString(((double)visualisation.getInterval()) / 1000.0)); disableUpdatesButton.setSelection(visualisation.disabledUpdates()); hoveringVertexEnabledButton.setSelection(visualisation.isKeyVariablesVertexHover()); @@ -1523,6 +1556,10 @@ public class DynamicVisualisationsUI { break; } } + + pointsStaticPropertiesButton.setSelection(visualisation.isStaticPropertiesPoints()); + networkBranchesStaticPropertiesButton.setSelection(visualisation.isStaticPropertiesNetworkBranches()); + consumersStaticPropertiesButton.setSelection(visualisation.isStaticPropertiesConsumers()); } }); } diff --git a/org.simantics.district.network/adapters.xml b/org.simantics.district.network/adapters.xml index 05ecb506..7c574668 100644 --- a/org.simantics.district.network/adapters.xml +++ b/org.simantics.district.network/adapters.xml @@ -8,26 +8,6 @@ - - - - - - " + staticInformationContribution :: String -> String -> String -> String -> StaticInformationContribution + +importJava "org.simantics.district.network.visualisations.model.DynamicSymbolContribution" where + data DynamicSymbolContribution + + @JavaName "" + dynamicSymbolContribution :: [String] -> (Map.T String Integer -> Map.T String String -> Maybe String) -> (() -> Map.T String String) -> DynamicSymbolContribution \ No newline at end of file diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java index 7bff718e..08a1b013 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java @@ -15,6 +15,8 @@ import org.simantics.district.network.visualisations.DynamicVisualisationsContri import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicArrowObject; import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject; import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSymbolContributionObject; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.StaticInformationContributionObject; import org.simantics.district.network.visualisations.model.ColorBarOptions; import org.simantics.district.network.visualisations.model.DynamicArrowContribution; import org.simantics.district.network.visualisations.model.DynamicColorContribution; @@ -60,6 +62,16 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead arrowContributions = DynamicVisualisations.arrowContributions(graph, visualisationResource); + Collection staticInformationContributions = DynamicVisualisationsContributions.staticInformationContributionObjects(graph); + Map staticInformationContributionObjects = staticInformationContributions.stream().collect(Collectors.toMap(dcc -> dcc.getStaticInformationContributionObject().getName(), dcc -> dcc)); + + Collection dynamicSymbolContributions = DynamicVisualisationsContributions.dynamicSymbolContributionObjects(graph); + Map dynamicSymbolContributionObjects = dynamicSymbolContributions.stream().map(dsc -> { + // here we resolve the symbol map with the help of readgraph + dsc.resolveSymbols(graph); + return dsc; + }).collect(Collectors.toMap(dcc -> dcc.getDynamicSymbolContributionObject().getName(), dcc -> dcc)); + Boolean hideEdges = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideEdges, Bindings.BOOLEAN); Boolean hidePoints = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HidePoints, Bindings.BOOLEAN); Boolean hideConsumers = graph.getPossibleRelatedValue(visualisationResource, DN.Diagram_Visualisations_HideConsumers, Bindings.BOOLEAN); @@ -77,6 +89,9 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead { private static final Logger LOGGER = LoggerFactory.getLogger(VertexSymbolStyle.class); - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public String calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { - // Prevent PendingVariableExceptions from coming through - boolean wasSynchronous = graph.setSynchronous(true); - try { - Function symbolFunction = getSymbolFunction(graph, entry); - if (symbolFunction == null) - return null; - - try { - return (String) Simantics.applySCLRead(graph, symbolFunction, groupItem); - } catch (Exception e) { - LOGGER.error("Getting dynamic symbol for " + groupItem + " (" + graph.getPossibleRelatedValue(groupItem, Layer0.getInstance(graph).HasName) + ") failed", e); - return null; - } - } - finally { - graph.setSynchronous(wasSynchronous); - } - } + + @Override + public String calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException { + return calculateStyle(graph, entry, groupItem); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static String calculateStyle(ReadGraph graph, Resource entry, Resource groupItem) throws DatabaseException { + // Prevent PendingVariableExceptions from coming through + boolean wasSynchronous = graph.setSynchronous(true); + try { + Function symbolFunction = getSymbolFunction(graph, entry); + if (symbolFunction == null) + return null; + + try { + return (String) Simantics.applySCLRead(graph, symbolFunction, groupItem); + } catch (Exception e) { + LOGGER.error("Getting dynamic symbol for " + groupItem + " (" + + graph.getPossibleRelatedValue(groupItem, Layer0.getInstance(graph).HasName) + ") failed", e); + return null; + } + } finally { + graph.setSynchronous(wasSynchronous); + } + } @SuppressWarnings("rawtypes") - protected static Function getSymbolFunction(ReadGraph graph, Resource entry) throws DatabaseException { + public static Function getSymbolFunction(ReadGraph graph, Resource entry) throws DatabaseException { // Cache function read for profile entry return graph.syncRequest(new SymbolFunctionRequest(entry), TransientCacheListener.instance()); } diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisations.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisations.java index cf4feead..e2cb72bf 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisations.java +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisations.java @@ -341,5 +341,26 @@ public class DynamicVisualisations { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); graph.claimLiteral(visualisation, DN.Diagram_Visualisations_KeyVariableVertexHover, hoverVertex, Bindings.BOOLEAN); graph.claimLiteral(visualisation, DN.Diagram_Visualisations_KeyVariableEdgeHover, hoverEdges, Bindings.BOOLEAN); + } + + public static void setElevationServerBoundingBox(WriteGraph graph, Resource visualisation, boolean elevationServerBoundingBox) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowElevationServerBoundingBox, elevationServerBoundingBox, Bindings.BOOLEAN); + } + + public static Boolean showElevationServerBoundingBox(ReadGraph graph, Resource visualisation) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + return graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowElevationServerBoundingBox, Bindings.BOOLEAN); + } + + public static void setNotInSimulation(WriteGraph graph, Resource visualisation, boolean notInSimulation) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + graph.claimLiteral(visualisation, DN.Diagram_Visualisations_NotInSimulation, notInSimulation, Bindings.BOOLEAN); + } + + public static Boolean isNotInSimulation(ReadGraph graph, Resource visualisation) throws DatabaseException { + DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); + return graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_NotInSimulation, Bindings.BOOLEAN); } + } diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java index 1a16ee55..3fd5a25f 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/DynamicVisualisationsContributions.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -22,6 +23,8 @@ import org.simantics.district.network.visualisations.model.DynamicColorContribut import org.simantics.district.network.visualisations.model.DynamicColorMap; import org.simantics.district.network.visualisations.model.DynamicSizeContribution; import org.simantics.district.network.visualisations.model.DynamicSizeMap; +import org.simantics.district.network.visualisations.model.DynamicSymbolContribution; +import org.simantics.district.network.visualisations.model.StaticInformationContribution; import org.simantics.layer0.Layer0; import org.simantics.scl.compiler.top.ValueNotFound; import org.simantics.scl.osgi.SCLOsgi; @@ -43,6 +46,8 @@ public class DynamicVisualisationsContributions { private static final String COLOR_CONTRIBUTION = "colorContribution"; private static final String SIZE_CONTRIBUTION = "sizeContribution"; private static final String ARROW_CONTRIBUTION = "arrowContribution"; + private static final String STATIC_INFORMATION_CONTRIBUTION = "staticInformationContribution"; + private static final String DYNAMIC_SYMBOL_CONTRIBUTION = "symbolContribution"; public static Map dynamicColorMaps(ReadGraph graph) throws DatabaseException { List sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); @@ -204,7 +209,64 @@ public class DynamicVisualisationsContributions { } }; } + + public static Collection staticInformationContributionObjects(ReadGraph graph) throws DatabaseException { + + List sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); + + List results = new ArrayList<>(); + + for (Resource sharedOntology : sharedOntologies) { + Collection findByType = graph.syncRequest(new ObjectsWithSupertype(sharedOntology, Layer0.getInstance(graph).ConsistsOf, StructuralResource2.getInstance(graph).Component)); + //Collection findByType = QueryIndexUtils.searchByType(graph, sharedOntology, ); + for (Resource find : findByType) { + NamedResource moduleType = new NamedResource(NameLabelUtil.modalName(graph, find), find); + StaticInformationContributionObject staticInformationContributionObject = staticInformationContributionObject(graph, moduleType); + if (staticInformationContributionObject != null) + results.add(staticInformationContributionObject); + } + } + return results; + } + + private static StaticInformationContributionObject staticInformationContributionObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE); + if (sclModule != null) { + String moduleURI = graph.getURI(sclModule); + return new StaticInformationContributionObject(moduleType, getContributionSupplier(moduleURI, STATIC_INFORMATION_CONTRIBUTION)); + } + return null; + } + + public static Collection dynamicSymbolContributionObjects(ReadGraph graph) throws DatabaseException { + + List sharedOntologies = Simantics.applySCL("Simantics/SharedOntologies", "getSharedOntologies", graph, Tuple0.INSTANCE); + List results = new ArrayList<>(); + + for (Resource sharedOntology : sharedOntologies) { + Collection findByType = graph.syncRequest(new ObjectsWithSupertype(sharedOntology, Layer0.getInstance(graph).ConsistsOf, StructuralResource2.getInstance(graph).Component)); + //Collection findByType = QueryIndexUtils.searchByType(graph, sharedOntology, ); + for (Resource find : findByType) { + NamedResource moduleType = new NamedResource(NameLabelUtil.modalName(graph, find), find); + DynamicSymbolContributionObject dynamicSymbolContributionObject = dynamicSymbolContributionObject(graph, moduleType); + if (dynamicSymbolContributionObject != null) + results.add(dynamicSymbolContributionObject); + } + } + return results; + } + private static DynamicSymbolContributionObject dynamicSymbolContributionObject(ReadGraph graph, NamedResource moduleType) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Resource sclModule = Layer0Utils.getPossibleChild(graph, moduleType.getResource(), L0.SCLModule, DYNAMIC_VISUALISATIONS_CONTRIBUTION_MODULE); + if (sclModule != null) { + String moduleURI = graph.getURI(sclModule); + return new DynamicSymbolContributionObject(moduleType, getContributionSupplier(moduleURI, DYNAMIC_SYMBOL_CONTRIBUTION)); + } + return null; + } + public static class DynamicArrowObject { private final NamedResource arrowObject; @@ -226,7 +288,67 @@ public class DynamicVisualisationsContributions { return arrowContributions; } } - + + public static class StaticInformationContributionObject { + + private final NamedResource staticInformationContributionObject; + private final Supplier> staticInformationContributionSupplier; + private Map staticInformationContributions; + + public StaticInformationContributionObject(NamedResource staticInformationContributionObject, Supplier> staticInformationContributionSupplier) { + this.staticInformationContributionObject = staticInformationContributionObject; + this.staticInformationContributionSupplier = staticInformationContributionSupplier; + } + + public NamedResource getStaticInformationContributionObject() { + return staticInformationContributionObject; + } + + public Map getStaticInformationContributions() { + if (staticInformationContributions == null) + staticInformationContributions = staticInformationContributionSupplier.get().collect(Collectors.toMap(c -> c.getLabel(), c -> c)); + return staticInformationContributions; + } + } + + public static class DynamicSymbolContributionObject { + + private final NamedResource dynamicSymbolContributionObject; + private final Supplier> dynamicSymbolContributionSupplier; + private DynamicSymbolContribution dynamicSymbolContribution; + + public DynamicSymbolContributionObject(NamedResource dynamicSymbolContributionObject, Supplier> dynamicSymbolContributionSupplier) { + this.dynamicSymbolContributionObject = dynamicSymbolContributionObject; + this.dynamicSymbolContributionSupplier = dynamicSymbolContributionSupplier; + } + + public NamedResource getDynamicSymbolContributionObject() { + return dynamicSymbolContributionObject; + } + + public DynamicSymbolContribution getDynamicSymbolContribution() { + if (dynamicSymbolContribution == null) { + Optional findFirst = dynamicSymbolContributionSupplier.get().findFirst(); + findFirst.ifPresent(dsc -> { + dynamicSymbolContribution = dsc; + }); + } + return dynamicSymbolContribution; + } + + public void resolveSymbols(ReadGraph graph) { + SCLContext current = SCLContext.getCurrent(); + Object oldGraph = current.put("graph", graph); + try { + DynamicSymbolContribution dsc = getDynamicSymbolContribution(); + if (dsc != null) + dsc.resolveSymbolMap(); + } finally { + current.put("graph", oldGraph); + } + } + } + public static class DynamicColoringObject { private final NamedResource coloringObject; diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSymbolContribution.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSymbolContribution.java new file mode 100644 index 00000000..cbd3ed84 --- /dev/null +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicSymbolContribution.java @@ -0,0 +1,60 @@ +package org.simantics.district.network.visualisations.model; + +import java.util.List; +import java.util.Map; + +import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.function.Function2; +import org.simantics.scl.runtime.tuple.Tuple0; + +public class DynamicSymbolContribution { + + private List children; + private Function2, Map, String> symbolFunction; + private Function1> symbolMapFunction; + + private Map symbolMap; + + // for graph persistence only + private boolean used; + private boolean useDefault; + + public DynamicSymbolContribution(List children, Function2, Map, String> symbolFunction, Function1> symbolMapFunction) { + this.children = children; + this.symbolFunction = symbolFunction; + this.symbolMapFunction = symbolMapFunction; + } + + public List getChildren() { + return children; + } + + public Function2, Map, String> getSymbolFunction() { + return symbolFunction; + } + + public void resolveSymbolMap() { + symbolMap = symbolMapFunction.apply(Tuple0.INSTANCE); + } + + public Map getSymbolMap() { + return symbolMap; + } + + public boolean isUsed() { + return used; + } + + public void setUsed(boolean used) { + this.used = used; + } + + public boolean isUseDefault() { + return useDefault; + } + + public void setUseDefault(boolean useDefault) { + this.useDefault = useDefault; + } + +} \ No newline at end of file diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java index ca577323..d64461e1 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java @@ -6,6 +6,8 @@ import org.simantics.db.Resource; import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicArrowObject; import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject; import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSymbolContributionObject; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.StaticInformationContributionObject; public class DynamicVisualisation { @@ -24,6 +26,9 @@ public class DynamicVisualisation { private final Map defaultArrowContributions; private final Map arrowContributions; + private final Map staticInformationContributions; + private final Map dynamicSymbolContributions; + private final boolean hideEdges; private final boolean hidePoints; private final boolean hideConsumers; @@ -43,6 +48,9 @@ public class DynamicVisualisation { private boolean keyVariablesEdgesHover; private boolean resetVisualisation; + private boolean showElevationServerBoundingBox; + private boolean isInSimulation; + public DynamicVisualisation(String name, Resource visualisationResource, long interval, boolean disabled, boolean resetVisualisation, Map colorContributions, Map defaultColoringObjects, ColorBarOptions colorBarOptions, @@ -50,6 +58,8 @@ public class DynamicVisualisation { Map defaultSizingObjects, SizeBarOptions sizeBarOptions, Map defaultArrowContributions, Map arrowContributions, + Map staticInformationContributions, + Map dynamicSymbolContributions, boolean hideEdges, boolean hidePoints, boolean hideConsumers, @@ -64,7 +74,9 @@ public class DynamicVisualisation { boolean dynamicSymbolsValves, boolean dynamicSymbolsPumpingStations, boolean keyVariablesVertexHover, - boolean keyVariablesEdgesHover + boolean keyVariablesEdgesHover, + boolean showElevationServerBoundingBox, + boolean isInSimulation ) { this.name = name; this.visualisationResource = visualisationResource; @@ -79,6 +91,8 @@ public class DynamicVisualisation { this.sizeBarOptions = sizeBarOptions; this.defaultArrowContributions = defaultArrowContributions; this.arrowContributions = arrowContributions; + this.staticInformationContributions = staticInformationContributions; + this.dynamicSymbolContributions = dynamicSymbolContributions; this.hidePoints = hidePoints; this.hideConsumers = hideConsumers; @@ -97,6 +111,9 @@ public class DynamicVisualisation { this.keyVariablesVertexHover = keyVariablesVertexHover; this.keyVariablesEdgesHover = keyVariablesEdgesHover; + + this.showElevationServerBoundingBox = showElevationServerBoundingBox; + this.isInSimulation = isInSimulation; } public String getName() { @@ -139,6 +156,10 @@ public class DynamicVisualisation { return arrowContributions; } + public Map getStaticInformationContributions() { + return staticInformationContributions; + } + public boolean isHideEdges() { return hideEdges; } @@ -210,4 +231,12 @@ public class DynamicVisualisation { public boolean isResetVisualisation() { return resetVisualisation; } + + public boolean isInSimulation() { + return isInSimulation; + } + + public Map getDynamicSymbolContributions() { + return dynamicSymbolContributions; + } } diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/StaticInformationContribution.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/StaticInformationContribution.java new file mode 100644 index 00000000..6e8b9363 --- /dev/null +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/StaticInformationContribution.java @@ -0,0 +1,53 @@ +package org.simantics.district.network.visualisations.model; + +public class StaticInformationContribution { + + private String label; + private String moduleName; + private String attributeName; + private String unit; + + // for graph persistence only + private boolean used; + private boolean useDefault; + + public StaticInformationContribution(String label, String moduleName, String attributeName, String unit) { + this.label = label; + this.moduleName = moduleName; + this.attributeName = attributeName; + this.unit = unit; + } + + public String getLabel() { + return label; + } + + public String getModuleName() { + return moduleName; + } + + public String getAttributeName() { + return attributeName; + } + + public String getUnit() { + return unit; + } + + public boolean isUsed() { + return used; + } + + public void setUsed(boolean used) { + this.used = used; + } + + public boolean isUseDefault() { + return useDefault; + } + + public void setUseDefault(boolean useDefault) { + this.useDefault = useDefault; + } + +} \ No newline at end of file -- 2.47.1