X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2FDistrictDiagramViewer.java;h=198389551768a250b22c6be34a293f6f99ba2acb;hb=3730466cd1e90c50c988292e107639952448d6a6;hp=25956b31aaa701d772a2cc4fb3be0af0e7786c61;hpb=bc05b1b2f95286aea041032325626fec71dc39b7;p=simantics%2Fdistrict.git 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 25956b31..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 @@ -12,7 +12,7 @@ import java.util.function.Supplier; import org.simantics.datatypes.literal.RGB; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.request.IndexRoot; +import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.Listener; @@ -21,9 +21,9 @@ import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.district.network.ui.internal.Activator; 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; @@ -35,6 +35,7 @@ import org.simantics.g2d.canvas.impl.CanvasContext; import org.simantics.g2d.diagram.handler.PickRequest.PickFilter; import org.simantics.g2d.diagram.participant.DelayedBatchElementPainter; import org.simantics.g2d.diagram.participant.ElementPainter; +import org.simantics.g2d.diagram.participant.ElementPainterConfiguration; import org.simantics.g2d.diagram.participant.Selection; import org.simantics.g2d.diagram.participant.ZOrderHandler; import org.simantics.g2d.participant.BackgroundPainter; @@ -66,7 +67,7 @@ public class DistrictDiagramViewer extends DiagramViewer { protected void addDiagramParticipants(ICanvasContext ctx) { ctx.add(new ZOrderHandler()); ctx.add(new Selection()); - ctx.add(new ElementPainter()); + ctx.add(new ElementPainter(new ElementPainterConfiguration().selectionNodeClass(DistrictSelectionNode.class))); ctx.add(new DNPointerInteractor()); AffineTransform tr = new AffineTransform(MapScalingTransform.INSTANCE); @@ -74,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 @@ -140,6 +140,7 @@ public class DistrictDiagramViewer extends DiagramViewer { setupColorBarOptions(); setupSizingObjects(); setupSizeBarOptions(); + setupShowElevationServerBoundingBox(); // add listeners DistrictDiagramViewerListener[] listeners = Activator.getInstance().getDistrictDiagramViewerListeners(); @@ -154,8 +155,9 @@ public class DistrictDiagramViewer extends DiagramViewer { public void dispose() { DistrictDiagramViewerListener[] listeners = Activator.getInstance().getDistrictDiagramViewerListeners(); if (listeners != null) { + Resource runtime = getRuntime(); for (DistrictDiagramViewerListener listener : listeners) { - listener.diagramDisposed(getRuntime(), canvasContext); + listener.diagramDisposed(runtime, canvasContext); } } super.dispose(); @@ -200,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"); @@ -218,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); } @@ -230,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(() -> { @@ -346,15 +359,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public ColorBarOptions perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.colorBarOptions(graph, activeVisualisation); + 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.colorBarOptions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return ColorBarOptions.useDefault(); } @@ -369,15 +384,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public Map perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.colorContributions(graph, activeVisualisation); + 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.colorContributions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return Collections.emptyMap(); } @@ -404,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 @@ -450,15 +467,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public SizeBarOptions perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.sizeBarOptions(graph, activeVisualisation); + 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.sizeBarOptions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return SizeBarOptions.useDefault(); } @@ -501,15 +520,17 @@ public class DistrictDiagramViewer extends DiagramViewer { @Override public Map perform(ReadGraph graph) throws DatabaseException { DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - Resource model = graph.syncRequest(new IndexRoot(parameter)); - Resource vf = DynamicVisualisations.getVisualisationFolder(graph, model); - if (vf != null) { - Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation); - if (activeVisualisation != null) { - return DynamicVisualisations.sizeContributions(graph, activeVisualisation); + 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.sizeContributions(graph, activeVisualisation); + } + } else { + LOGGER.debug("No visualisation folder available for model {}", model); } - } else { - LOGGER.debug("No visualisation folder available for model {}", model); } return Collections.emptyMap(); } @@ -534,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