From: jsimomaa Date: Wed, 5 Jun 2019 08:46:03 +0000 (+0300) Subject: Add profile to show bounding boxes for elevation server X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=75b7219d78b67919436a99631905e4d3fd57e765;p=simantics%2Fdistrict.git Add profile to show bounding boxes for elevation server gitlab #45 APROS-15308 Change-Id: I993910384a1fe7b5a740a0282ef23d9114bc3210 --- diff --git a/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph index 144710aa..25c17f4d 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph @@ -26,6 +26,7 @@ DN.ArrowLengthStyle : DIA.Style DN.HideStyle : DIA.Style DN.VertexSymbolStyle : DIA.Style DN.ConnectionLineStyle : DIA.Style +DN.ElevationRectangleStyle : DIA.Style // Style for user component-specified text grid entries DN.DistrictNetworkHoverInfoStyle : DIA.Style diff --git a/org.simantics.district.network.ui/adapters.xml b/org.simantics.district.network.ui/adapters.xml index 323f4597..c2a02562 100644 --- a/org.simantics.district.network.ui/adapters.xml +++ b/org.simantics.district.network.ui/adapters.xml @@ -31,6 +31,9 @@ class="org.simantics.district.network.ui.nodes.DistrictNetworkStaticInfoStyle"> + + diff --git a/org.simantics.district.network.ui/plugin.xml b/org.simantics.district.network.ui/plugin.xml index f33e345a..1e596f54 100644 --- a/org.simantics.district.network.ui/plugin.xml +++ b/org.simantics.district.network.ui/plugin.xml @@ -32,6 +32,14 @@ name="District Network Breakdown" restorable="true"> + + 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 3bd0bfda..68b7aa79 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 @@ -15,6 +15,7 @@ import org.simantics.db.procedure.Listener; import org.simantics.diagram.ui.DiagramModelHints; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ui.participants.DNPointerInteractor; +import org.simantics.district.network.ui.participants.ElevationServerParticipant; import org.simantics.district.network.ui.participants.MapRulerPainter; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.impl.CanvasContext; @@ -55,6 +56,7 @@ public class DistrictDiagramViewer extends DiagramViewer { ctx.add(new MapPainter(tr)); ctx.add(new NetworkDrawingParticipant(tr)); + ctx.add(new ElevationServerParticipant(tr)); } protected String getPopupId() { diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationRectangleStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationRectangleStyle.java new file mode 100644 index 00000000..c6846495 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationRectangleStyle.java @@ -0,0 +1,67 @@ +package org.simantics.district.network.ui.nodes; + +import java.awt.geom.Rectangle2D; +import java.util.Collection; +import java.util.Collections; + +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.maps.elevation.server.SingletonTiffTileInterface; +import org.simantics.scenegraph.g2d.IG2DNode; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.Group; +import org.simantics.scenegraph.profile.Style; +import org.simantics.scenegraph.profile.common.ObserverGroupListener; +import org.simantics.scenegraph.utils.NodeUtil; + +public class ElevationRectangleStyle implements Style { + + private ObserverGroupListener listener = null; + private double priority; + + @Override + public void activate(RequestProcessor backend, Resource runtimeDiagram, Resource entry, Group group, EvaluationContext observer) throws DatabaseException { + if (listener != null && !listener.isDisposed()) + return; + listener = new ObserverGroupListener(this, group, observer); + group.trackItems(backend, runtimeDiagram, listener); + } + + @Override + public void deactivate(Resource runtimeDiagram, Resource entry, Group group, EvaluationContext observer) { + if (listener != null && !listener.isDisposed()) { + setRectangles(observer, Collections.emptyList()); + listener.dispose(); + observer.update(); + } + } + + @Override + public void apply(Resource entry, Group group, EvaluationContext observer) { + apply2(entry, observer); + } + + @Override + public void apply2(Object item, EvaluationContext observer) { + setRectangles(observer, SingletonTiffTileInterface.getBoundingBoxes()); + } + + private void setRectangles(EvaluationContext observer, Collection rectangles) { + IG2DNode node = NodeUtil.getNearestChildByClass(observer.getSceneGraph(), ElevationServerNode.class); + if (node != null) { + ((ElevationServerNode) node).setRectangles(rectangles); + } + } + + @Override + public void setPriority(double priority) { + this.priority = priority; + } + + @Override + public double getPriority() { + return priority; + } + +} diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationServerNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationServerNode.java new file mode 100644 index 00000000..c26c1759 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationServerNode.java @@ -0,0 +1,81 @@ +package org.simantics.district.network.ui.nodes; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Stroke; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.Collection; +import java.util.Collections; + +import org.simantics.scenegraph.g2d.G2DNode; +import org.simantics.scenegraph.utils.GeometryUtils; + +public class ElevationServerNode extends G2DNode { + + private static final long serialVersionUID = 3832908017166017921L; + + private static final Stroke DASHED_STROKE = new BasicStroke(2.0f, + BasicStroke.CAP_ROUND, + BasicStroke.JOIN_ROUND, + 4.0f, new float[]{4.0f}, 0.0f); + + private static final Color BLUE_ALPHA = new Color(0, 0, 255, 100); + + public static final String ID = "elevationServerNode"; + + private Collection rectangles; + + @Override + public void render(Graphics2D g2d) { + + Color old = g2d.getColor(); + Stroke oldStroke = g2d.getStroke(); + + g2d.setColor(BLUE_ALPHA); + BasicStroke stroke = GeometryUtils.scaleStroke(DASHED_STROKE, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform()))); + g2d.setStroke(stroke); + + double scale = getTransform().getScaleY(); + + for (Rectangle2D rect : getRectangles()) { + + Point2D point = new Point2D.Double(rect.getY(), rect.getX()); + Point2D result = DistrictNetworkNodeUtils.calculatePoint2D(point, null); + + Point2D point2 = new Point2D.Double(rect.getY() + rect.getHeight(), rect.getX() + rect.getWidth()); + Point2D result2 = DistrictNetworkNodeUtils.calculatePoint2D(point2, null); + + double x = result.getX() * scale; + double y = result.getY() * scale; + double width = result2.getX() * scale - result.getX() * scale; + double height = result2.getY() * scale - result.getY() * scale; + + Rectangle2D translated = new Rectangle2D.Double(x, y, width, Math.abs(height)); + g2d.draw(translated); + } + + g2d.setStroke(oldStroke); + g2d.setColor(old); + } + + @Override + public Rectangle2D getBoundsInLocal() { + Rectangle2D bounds = new Rectangle2D.Double(); + for (Rectangle2D rect : getRectangles()) { + bounds.add(rect); + } + return bounds; + } + + public void setRectangles(Collection rectangles) { + this.rectangles = rectangles; + } + + public Collection getRectangles() { + if (rectangles == null) + return Collections.emptyList(); + return rectangles; + } +} 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 new file mode 100644 index 00000000..d5f02bb2 --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/ElevationServerParticipant.java @@ -0,0 +1,26 @@ +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/META-INF/MANIFEST.MF b/org.simantics.district.network/META-INF/MANIFEST.MF index 58fd3ab4..dfb47169 100644 --- a/org.simantics.district.network/META-INF/MANIFEST.MF +++ b/org.simantics.district.network/META-INF/MANIFEST.MF @@ -15,7 +15,8 @@ Require-Bundle: org.simantics.db, org.simantics.diagram, org.simantics.scenegraph.profile;bundle-version="1.0.0", org.simantics;bundle-version="1.0.0", - org.slf4j.api + org.slf4j.api, + org.simantics.maps.elevation.server;bundle-version="1.0.0" Export-Package: org.simantics.district.network, org.simantics.district.network.changeset, org.simantics.district.network.profile diff --git a/org.simantics.maps.elevation.server.ui/src/org/simantics/maps/elevation/server/ui/MapsElevationServerPreferencePage.java b/org.simantics.maps.elevation.server.ui/src/org/simantics/maps/elevation/server/ui/MapsElevationServerPreferencePage.java index 43200ce9..a014c315 100644 --- a/org.simantics.maps.elevation.server.ui/src/org/simantics/maps/elevation/server/ui/MapsElevationServerPreferencePage.java +++ b/org.simantics.maps.elevation.server.ui/src/org/simantics/maps/elevation/server/ui/MapsElevationServerPreferencePage.java @@ -39,6 +39,7 @@ public class MapsElevationServerPreferencePage extends FieldEditorPreferencePage addField(automatically); IntegerFieldEditor pipeDepth = new IntegerFieldEditor(MapsElevationServerPreferences.P_PIPE_DEPTH_UNDER_GROUND, "Pipe depth under ground", serverGroup); + pipeDepth.setValidRange(Integer.MIN_VALUE, Integer.MAX_VALUE); addField(pipeDepth); GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).extendedMargins(12, 12, 12, 12).spacing(5, 4).applyTo(serverGroup); diff --git a/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/SingletonTiffTileInterface.java b/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/SingletonTiffTileInterface.java index 3a3a0f6f..3fc9616c 100644 --- a/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/SingletonTiffTileInterface.java +++ b/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/SingletonTiffTileInterface.java @@ -1,9 +1,11 @@ package org.simantics.maps.elevation.server; +import java.awt.geom.Rectangle2D; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,4 +42,8 @@ public class SingletonTiffTileInterface { public static Number lookup(double x, double y) { return instance.tileInterface.lookup(x, y); } + + public static Collection getBoundingBoxes() { + return instance.tileInterface.getBoundingBoxes(); + } } diff --git a/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/TiffTileInterface.java b/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/TiffTileInterface.java index 900630dc..d6f1910e 100644 --- a/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/TiffTileInterface.java +++ b/org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/TiffTileInterface.java @@ -1,18 +1,17 @@ package org.simantics.maps.elevation.server; +import java.awt.geom.Rectangle2D; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import java.util.stream.Stream; -import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.LoadingCache; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Envelope; -import com.vividsolutions.jts.index.strtree.STRtree; - import org.geotools.geometry.DirectPosition2D; import org.geotools.geometry.Envelope2D; import org.geotools.referencing.CRS; @@ -22,6 +21,12 @@ import org.opengis.referencing.operation.MathTransform; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Envelope; +import com.vividsolutions.jts.index.strtree.STRtree; + public class TiffTileInterface { private static final Logger LOGGER = LoggerFactory.getLogger(TiffTileInterface.class); @@ -79,6 +84,7 @@ public class TiffTileInterface { synchronized(index) { index.insert(envelope, tifFile); } + envelopes.put(tifFile, envelope); } catch (Exception e) { LOGGER.error("Could not initialize index for file {}", tifFile, e); } finally { @@ -91,6 +97,17 @@ public class TiffTileInterface { }); } + private Map envelopes = new ConcurrentHashMap<>(); + + public Collection getBoundingBoxes() { + Collection rects = envelopes.values().stream().map(env -> { + double x = env.getMinX(); + double y = env.getMinY(); + return new Rectangle2D.Double(x, y, env.getMaxX() - x, env.getMaxY() - y); + }).collect(Collectors.toList()); + return rects; + } + private static CoordinateReferenceSystem c4326; static {