X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2FDistrictPanZoomRotateHandler.java;h=05866bdabb3fea2b6bf14f4562267d5309bf11f9;hb=refs%2Fchanges%2F83%2F2783%2F1;hp=fecc17548e98c5f995eef4d912112c354007a5f0;hpb=ac559543846448f6523406a926fa7f1b7eaebcac;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java index fecc1754..05866bda 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java @@ -2,13 +2,15 @@ package org.simantics.district.network.ui; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; +import java.util.Collection; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; import org.simantics.g2d.canvas.impl.DependencyReflection.Reference; import org.simantics.g2d.diagram.DiagramHints; -import org.simantics.g2d.diagram.DiagramUtils; import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.diagram.participant.Selection; import org.simantics.g2d.element.ElementUtils; @@ -89,7 +91,7 @@ public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler { if (d == null) return false; - Rectangle2D diagramRect = DiagramUtils.getContentRect(d); + Rectangle2D diagramRect = ElementUtils.getSurroundingElementBoundsOnDiagram(getMapElements(d.getElements())); if (diagramRect == null) return false; if (diagramRect.isEmpty()) @@ -103,6 +105,14 @@ public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler { return true; } + protected static List getMapElements(Collection elements) { + List justMapElements = elements.stream() + .filter(e -> "DistrictNetworkEdgeElement".equals(e.getElementClass().getId()) + || "DistrictNetworkVertexElement".equals(e.getElementClass().getId())) + .collect(Collectors.toList()); + return justMapElements; + } + private boolean zoomToPage() { int currentZoomLevel = MapScalingTransform.zoomLevel(util.getTransform()); @@ -124,7 +134,7 @@ public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler { // no can do, return zoomToPage(); } - Rectangle2D diagramRect = ElementUtils.getSurroundingElementBoundsOnDiagram(selections); + Rectangle2D diagramRect = ElementUtils.getSurroundingElementBoundsOnDiagram(getMapElements(selections)); // Make sure that even empty bounds can be zoomed into. org.simantics.scenegraph.utils.GeometryUtils.expandRectangle(diagramRect, 1);