]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add profile to show bounding boxes for elevation server
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 5 Jun 2019 08:46:03 +0000 (11:46 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 31 Aug 2019 20:08:43 +0000 (23:08 +0300)
gitlab #45
APROS-15308

Change-Id: I993910384a1fe7b5a740a0282ef23d9114bc3210

org.simantics.district.network.ontology/graph/DistrictNetworkProfiles.pgraph
org.simantics.district.network.ui/adapters.xml
org.simantics.district.network.ui/plugin.xml
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationRectangleStyle.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/ElevationServerNode.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/ElevationServerParticipant.java [new file with mode: 0644]
org.simantics.district.network/META-INF/MANIFEST.MF
org.simantics.maps.elevation.server.ui/src/org/simantics/maps/elevation/server/ui/MapsElevationServerPreferencePage.java
org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/SingletonTiffTileInterface.java
org.simantics.maps.elevation.server/src/org/simantics/maps/elevation/server/TiffTileInterface.java

index 144710aa55f2bda3f8fe9a4c48c736deeff43bca..25c17f4d961dff0ca3525556873984ccd53bf97f 100644 (file)
@@ -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
index 323f4597434f03c4263a2230f96d31a19c82952f..c2a02562c192223014741bfb246e9df9bebae484 100644 (file)
@@ -31,6 +31,9 @@
             class="org.simantics.district.network.ui.nodes.DistrictNetworkStaticInfoStyle">
             <this />
         </resource>
+        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/ElevationRectangleStyle"
+            class="org.simantics.district.network.ui.nodes.ElevationRectangleStyle">
+        </resource>
     </target>
     
     <target interface="org.simantics.g2d.diagram.DiagramClass">
index f33e345a7186f7f2b833ddc061b2f77fd480d57e..1e596f545e1f91dedc85d23e841e451420f434a0 100644 (file)
             name="District Network Breakdown"
             restorable="true">
       </e4view>
+      <e4view
+            class="org.simantics.district.network.ui.table.DistrictCSVTableView"
+            icon="platform:/plugin/com.famfamfam.silk/icons/table_edit.png"
+            id="org.simantics.district.network.ui.table.csvTableView"
+            name="District CSV Import Table"
+            restorable="true"
+            allowMultiple="false">
+      </e4view>
    </extension>
   <extension
          point="org.eclipse.ui.preferencePages">
index 3bd0bfda1cc31d92d69b01f3974681b96f270fea..68b7aa791407b2efdfa68a2065a919baf4490fef 100644 (file)
@@ -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 (file)
index 0000000..c684649
--- /dev/null
@@ -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<Rectangle2D> 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 (file)
index 0000000..c26c175
--- /dev/null
@@ -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<Rectangle2D> 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<Rectangle2D> rectangles) {
+        this.rectangles = rectangles;
+    }
+
+    public Collection<Rectangle2D> 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 (file)
index 0000000..d5f02bb
--- /dev/null
@@ -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);
+    }
+
+}
index 58fd3ab49511a1dadf7bfa2d4f4ff463f92a06b9..dfb47169d7856b6371d1ebb2290bf8d96a06b740 100644 (file)
@@ -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
index 43200ce98a74cd07a26c87ed1625e2ce7d8eba67..a014c315aa02c094d4139f650233ea807d4fa443 100644 (file)
@@ -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);
index 3a3a0f6f9948396e9c9d73a7e87eedaed90c4556..3fc9616c7080e5210aea4b987bb298945276909a 100644 (file)
@@ -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<Rectangle2D> getBoundingBoxes() {
+        return instance.tileInterface.getBoundingBoxes();
+    }
 }
index 900630dc42bffc386eabf0fcf203c872599fe53a..d6f1910e7057efce2c19b6f64e77d64de0c4df2b 100644 (file)
@@ -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<Path, Envelope> envelopes = new ConcurrentHashMap<>();
+
+    public Collection<Rectangle2D> getBoundingBoxes() {
+        Collection<Rectangle2D> 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 {