Ignore:
Timestamp:
2015-07-09T11:57:35+02:00 (9 years ago)
Author:
nokutu
Message:

Join mode created, press the button on the data menu to enable it. Click in two valid MapillaryImportedImage icons to join the in a single sequence.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31355 r31357  
    106106   * @return The image under the mouse cursor.
    107107   */
    108   public MapillaryAbstractImage getHoveredImage() {
     108  public MapillaryAbstractImage getHighlighted() {
    109109    return highlightedImage;
    110110  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31356 r31357  
    1010import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
    1111import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     12import org.openstreetmap.josm.plugins.mapillary.mode.AbstractMode;
     13import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode;
    1214import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode;
    1315import org.openstreetmap.josm.Main;
     
    4446import java.awt.Rectangle;
    4547import java.awt.TexturePaint;
    46 import java.awt.event.MouseAdapter;
    4748import java.awt.geom.AffineTransform;
    4849import java.awt.geom.Area;
     
    5960import java.util.ArrayList;
    6061
    61 public class MapillaryLayer extends AbstractModifiableLayer implements
    62     DataSetListener, EditLayerChangeListener, LayerChangeListener {
    63 
    64   public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref.getInteger(
    65       "mapillary.sequence-max-jump-distance", 100);
     62public class MapillaryLayer extends AbstractModifiableLayer implements DataSetListener, EditLayerChangeListener,
     63    LayerChangeListener {
     64
     65  public final static int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref
     66      .getInteger("mapillary.sequence-max-jump-distance", 100);
    6667
    6768  private boolean TEMP_MANUAL = false;
     
    7677  public ArrayList<Bounds> bounds;
    7778
    78   private MouseAdapter mode;
    79 
    80   private int highlightPointRadius = Main.pref.getInteger(
    81       "mappaint.highlight.radius", 7);
    82   private int highlightStep = Main.pref
    83       .getInteger("mappaint.highlight.step", 4);
     79  public AbstractMode mode;
     80
     81  private int highlightPointRadius = Main.pref.getInteger("mappaint.highlight.radius", 7);
     82  private int highlightStep = Main.pref.getInteger("mappaint.highlight.step", 4);
    8483
    8584  private volatile TexturePaint hatched;
     
    120119    data.dataUpdated();
    121120  }
    122  
    123   public void setMode(MouseAdapter mode) {
     121
     122  public void setMode(AbstractMode mode) {
    124123    Main.map.mapView.removeMouseListener(this.mode);
    125124    Main.map.mapView.removeMouseMotionListener(this.mode);
     
    143142    if (Main.pref.getBoolean("mapillary.download-manually") || TEMP_MANUAL)
    144143      return;
    145     for (Bounds bounds : Main.map.mapView.getEditLayer().data
    146         .getDataSourceBounds()) {
     144    for (Bounds bounds : Main.map.mapView.getEditLayer().data.getDataSourceBounds()) {
    147145      if (!this.bounds.contains(bounds)) {
    148146        this.bounds.add(bounds);
     
    160158  private void checkAreaTooBig() {
    161159    double area = 0;
    162     for (Bounds bounds : Main.map.mapView.getEditLayer().data
    163         .getDataSourceBounds()) {
     160    for (Bounds bounds : Main.map.mapView.getEditLayer().data.getDataSourceBounds()) {
    164161      area += bounds.getArea();
    165162    }
     
    272269        Point p1 = mv.getPoint(bounds.getMin());
    273270        Point p2 = mv.getPoint(bounds.getMax());
    274         Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y),
    275             Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
     271        Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x - p1.x), Math.abs(p2.y
     272            - p1.y));
    276273        a.subtract(new Area(r));
    277274      }
     
    294291        MapillaryLayer.BLUE = closestImages[0];
    295292        g.setColor(Color.BLUE);
    296         g.drawLine(mv.getPoint(closestImages[0].getLatLon()).x,
    297             mv.getPoint(closestImages[0].getLatLon()).y, selected.x, selected.y);
     293        g.drawLine(mv.getPoint(closestImages[0].getLatLon()).x, mv.getPoint(closestImages[0].getLatLon()).y,
     294            selected.x, selected.y);
    298295        MapillaryMainDialog.getInstance().blueButton.setEnabled(true);
    299296      }
     
    301298        MapillaryLayer.RED = closestImages[1];
    302299        g.setColor(Color.RED);
    303         g.drawLine(mv.getPoint(closestImages[1].getLatLon()).x,
    304             mv.getPoint(closestImages[1].getLatLon()).y, selected.x, selected.y);
     300        g.drawLine(mv.getPoint(closestImages[1].getLatLon()).x, mv.getPoint(closestImages[1].getLatLon()).y,
     301            selected.x, selected.y);
    305302        MapillaryMainDialog.getInstance().redButton.setEnabled(true);
    306303      }
     
    311308        continue;
    312309      Point p = mv.getPoint(imageAbs.getLatLon());
    313      
     310
    314311      Point nextp = null;
    315312      // Draw sequence line
     
    326323          g.drawLine(p.x, p.y, nextp.x, nextp.y);
    327324      }
    328      
     325
    329326      if (imageAbs instanceof MapillaryImage) {
    330327        MapillaryImage image = (MapillaryImage) imageAbs;
     
    336333        draw(g, image, icon, p);
    337334        if (!image.getSigns().isEmpty()) {
    338           g.drawImage(MapillaryPlugin.MAP_SIGN.getImage(),
    339               p.x + icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2,
    340               Main.map.mapView);
     335          g.drawImage(MapillaryPlugin.MAP_SIGN.getImage(), p.x + icon.getIconWidth() / 2, p.y - icon.getIconHeight()
     336              / 2, Main.map.mapView);
    341337        }
    342338      } else if (imageAbs instanceof MapillaryImportedImage) {
     
    350346      }
    351347    }
     348    if (mode instanceof JoinMode) {
     349      mode.paint(g, mv, box);
     350    }
    352351  }
    353352
     
    362361    Color oldColor = g.getColor();
    363362    Color highlightColor = PaintColors.HIGHLIGHT.get();
    364     Color highlightColorTransparent = new Color(highlightColor.getRed(),
    365         highlightColor.getGreen(), highlightColor.getBlue(), 100);
     363    Color highlightColorTransparent = new Color(highlightColor.getRed(), highlightColor.getGreen(),
     364        highlightColor.getBlue(), 100);
    366365    g.setColor(highlightColorTransparent);
    367366    int s = size + highlightPointRadius;
     
    383382   * @param p
    384383   */
    385   private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon,
    386       Point p) {
     384  private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon, Point p) {
    387385    Image imagetemp = icon.getImage();
    388386    BufferedImage bi = (BufferedImage) imagetemp;
     
    394392    double locationX = width / 2;
    395393    double locationY = height / 2;
    396     AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired,
    397         locationX, locationY);
    398     AffineTransformOp op = new AffineTransformOp(tx,
    399         AffineTransformOp.TYPE_BILINEAR);
    400 
    401     g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2),
    402         Main.map.mapView);
    403     if (data.getHoveredImage() == image) {
     394    AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY);
     395    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
     396
     397    g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2), Main.map.mapView);
     398    if (data.getHighlighted() == image) {
    404399      drawPointHighlight(g, p, 16);
    405400    }
     
    418413  @Override
    419414  public void mergeFrom(Layer from) {
    420     throw new UnsupportedOperationException(
    421         "This layer does not support merging yet");
     415    throw new UnsupportedOperationException("This layer does not support merging yet");
    422416  }
    423417
     
    441435    MapillaryImage selected = (MapillaryImage) data.getSelectedImage();
    442436    MapillaryImage[] ret = new MapillaryImage[2];
    443     double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE,
    444         SEQUENCE_MAX_JUMP_DISTANCE };
     437    double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE, SEQUENCE_MAX_JUMP_DISTANCE };
    445438    LatLon selectedCoords = data.getSelectedImage().getLatLon();
    446439    for (MapillaryAbstractImage imagePrev : data.getImages()) {
     
    457450          ret[0] = image;
    458451          distances[0] = image.getLatLon().greatCircleDistance(selectedCoords);
    459         } else if ((ret[1] == null || image.getLatLon().greatCircleDistance(
    460             selectedCoords) < distances[1])
     452        } else if ((ret[1] == null || image.getLatLon().greatCircleDistance(selectedCoords) < distances[1])
    461453            && image.getSequence() != ret[0].getSequence()) {
    462454          ret[1] = image;
     
    467459    // Predownloads the thumbnails
    468460    if (ret[0] != null)
    469       new MapillaryCache(ret[0].getKey(), MapillaryCache.Type.THUMBNAIL)
    470           .submit(data, false);
     461      new MapillaryCache(ret[0].getKey(), MapillaryCache.Type.THUMBNAIL).submit(data, false);
    471462    if (ret[1] != null)
    472       new MapillaryCache(ret[1].getKey(), MapillaryCache.Type.THUMBNAIL)
    473           .submit(data, false);
     463      new MapillaryCache(ret[1].getKey(), MapillaryCache.Type.THUMBNAIL).submit(data, false);
    474464    return ret;
    475465  }
     
    566556      else
    567557        Main.map.statusLine.setHelpText(tr("No images found"));
    568     }
     558      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, true);
     559    } else
     560      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, false);
    569561  }
    570562
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31355 r31357  
    1010import org.openstreetmap.josm.data.cache.JCSCacheManager;
    1111import org.openstreetmap.josm.gui.MainMenu;
    12 import org.openstreetmap.josm.gui.MapView;
    13 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    1412import org.openstreetmap.josm.Main;
    1513import org.openstreetmap.josm.gui.MapFrame;
    16 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1714import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    1815import org.openstreetmap.josm.plugins.Plugin;
     
    2724/**
    2825 * This is the main class of the Mapillary plugin.
    29  * 
     26 *
    3027 * @author nokutu
    3128 *
    3229 */
    33 public class MapillaryPlugin extends Plugin implements EditLayerChangeListener {
     30public class MapillaryPlugin extends Plugin {
    3431
    3532  public static final ImageIcon ICON24 = new ImageProvider("icon24.png").get();
     
    4946  private final MapillaryDownloadViewAction downloadViewAction;
    5047  private final MapillaryImportIntoSequenceAction importIntoSequenceAction;
     48  private final MapillaryJoinAction joinAction;
    5149
    5250  public static JMenuItem DOWNLOAD_MENU;
     
    5654  public static JMenuItem DOWNLOAD_VIEW_MENU;
    5755  public static JMenuItem IMPORT_INTO_SEQUENCE_MENU;
     56  public static JMenuItem JOIN_MENU;
    5857
    5958  public MapillaryPlugin(PluginInformation info) {
     
    6564    downloadViewAction = new MapillaryDownloadViewAction();
    6665    importIntoSequenceAction = new MapillaryImportIntoSequenceAction();
     66    joinAction = new MapillaryJoinAction();
    6767
    6868    if (Main.main != null) { // important for headless mode
     
    7373      ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15);
    7474      DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu, downloadViewAction, false, 14);
     75      JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, joinAction, false);
    7576    }
    7677
     
    8182    ZOOM_MENU.setEnabled(false);
    8283    DOWNLOAD_VIEW_MENU.setEnabled(false);
     84    JOIN_MENU.setEnabled(false);
    8385
    84     MapView.addEditLayerChangeListener(this);
    8586    try {
    8687      CACHE = JCSCacheManager.getCache("mapillary", 10, 10000, this.getPluginDir() + "/cache/");
     
    125126    return new MapillaryPreferenceSetting();
    126127  }
    127 
    128   @Override
    129   public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
    130     if (oldLayer == null && newLayer != null) {
    131     } else if (oldLayer != null && newLayer == null) {
    132     }
    133   }
    134128}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31355 r31357  
    6262      for (int i = 0; i < chooser.getSelectedFiles().length; i++) {
    6363        File file = chooser.getSelectedFiles()[i];
     64        MapillaryLayer.getInstance();
    6465        if (file.isDirectory()) {
    6566          // TODO import directory
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r31356 r31357  
    11package org.openstreetmap.josm.plugins.mapillary.mode;
    22
     3import java.awt.Graphics2D;
    34import java.awt.Point;
    45import java.awt.event.MouseAdapter;
    56
    67import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.data.Bounds;
     9import org.openstreetmap.josm.gui.MapView;
    710import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    811import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     
    1013public abstract class AbstractMode extends MouseAdapter {
    1114
    12   protected MapillaryData data;
     15  protected MapillaryData data = MapillaryData.getInstance();
    1316
    1417  public AbstractMode() {
     
    3235  }
    3336
     37  public abstract void paint(Graphics2D g, MapView mv, Bounds box);
     38
     39
    3440}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/JoinMode.java

    r31356 r31357  
    11package org.openstreetmap.josm.plugins.mapillary.mode;
    22
    3 import java.awt.event.MouseAdapter;
     3import java.awt.Color;
     4import java.awt.Graphics2D;
     5import java.awt.Point;
    46import java.awt.event.MouseEvent;
    57
    68import org.openstreetmap.josm.Main;
    7 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     9import org.openstreetmap.josm.data.Bounds;
     10import org.openstreetmap.josm.gui.MapView;
    811import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     12import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    913import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     14import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
    1015
    1116public class JoinMode extends AbstractMode {
    12  
     17
     18  public MapillaryImportedImage lastClick;
     19  public MouseEvent lastPos;
     20
    1321  @Override
    1422  public void mousePressed(MouseEvent e) {
    15    
     23    if (data.getHighlighted() == null)
     24      return;
     25    if (lastClick == null && data.getHighlighted() instanceof MapillaryImportedImage) {
     26      if (data.getHighlighted().previous() == null || data.getHighlighted().next() == null)
     27        lastClick = (MapillaryImportedImage) data.getHighlighted();
     28    } else if (lastClick != null && data.getHighlighted() instanceof MapillaryImportedImage) {
     29      if ((data.getHighlighted().previous() == null && lastClick.next() == null)
     30          || (data.getHighlighted().next() == null && lastClick.previous() == null)) {
     31        join(lastClick, (MapillaryImportedImage) data.getHighlighted());
     32      } else if (lastClick.next() == data.getHighlighted() || lastClick.previous() == data.getHighlighted())
     33        unjoin(lastClick, (MapillaryImportedImage) data.getHighlighted());
     34      lastClick = null;
     35    }
     36    data.dataUpdated();
    1637  }
    17  
     38
    1839  @Override
    1940  public void mouseMoved(MouseEvent e) {
    20     MapillaryAbstractImage closestTemp = getClosest(e.getPoint());
     41    lastPos = e;
    2142    if (!(Main.map.mapView.getActiveLayer() instanceof MapillaryLayer))
    2243      return;
     44    MapillaryAbstractImage closestTemp = getClosest(e.getPoint());
    2345    data.setHighlightedImage(closestTemp);
     46    data.dataUpdated();
     47  }
     48
     49  @Override
     50  public void paint(Graphics2D g, MapView mv, Bounds box) {
     51    if (lastClick != null) {
     52      g.setColor(Color.WHITE);
     53      Point p0 = mv.getPoint(lastClick.getLatLon());
     54      Point p1 = lastPos.getPoint();
     55      g.drawLine(p0.x, p0.y, p1.x, p1.y);
     56    }
     57  }
     58
     59  private void join(MapillaryImportedImage img1, MapillaryImportedImage img2) {
     60    if (img1.next() != null) {
     61      MapillaryImportedImage temp = img1;
     62      img1 = img2;
     63      img2 = temp;
     64    }
     65    if (img1.getSequence() == null) {
     66      MapillarySequence seq = new MapillarySequence();
     67      seq.add(img1);
     68      img1.setSequence(seq);
     69    }
     70    if (img2.getSequence() == null) {
     71      MapillarySequence seq = new MapillarySequence();
     72      seq.add(img2);
     73      img2.setSequence(seq);
     74    }
     75
     76    for (MapillaryAbstractImage img : img2.getSequence().getImages()) {
     77      img1.getSequence().add(img);
     78      img.setSequence(img1.getSequence());
     79    }
     80  }
     81
     82  private void unjoin(MapillaryImportedImage img1, MapillaryImportedImage img2) {
     83    // TODO
    2484  }
    2585}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31356 r31357  
    11package org.openstreetmap.josm.plugins.mapillary.mode;
    22
     3import java.awt.Graphics2D;
    34import java.awt.Point;
    45import java.awt.event.MouseEvent;
     
    67
    78import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.data.Bounds;
    810import org.openstreetmap.josm.data.coor.LatLon;
    911import org.openstreetmap.josm.data.osm.OsmPrimitive;
     12import org.openstreetmap.josm.gui.MapView;
    1013import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1114import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     
    2124/**
    2225 * Handles the input event related with the layer. Mainly clicks.
    23  * 
     26 *
    2427 * @author nokutu
    2528 *
     
    178181    }
    179182
    180     if (MapillaryData.getInstance().getHoveredImage() != closestTemp && closestTemp != null) {
     183    if (MapillaryData.getInstance().getHighlighted() != closestTemp && closestTemp != null) {
    181184      MapillaryData.getInstance().setHighlightedImage(closestTemp);
    182185      MapillaryMainDialog.getInstance().setImage(closestTemp);
    183186      MapillaryMainDialog.getInstance().updateImage();
    184     } else if (MapillaryData.getInstance().getHoveredImage() != closestTemp && closestTemp == null) {
     187    } else if (MapillaryData.getInstance().getHighlighted() != closestTemp && closestTemp == null) {
    185188      MapillaryData.getInstance().setHighlightedImage(null);
    186189      MapillaryMainDialog.getInstance().setImage(MapillaryData.getInstance().getSelectedImage());
     
    189192    MapillaryData.getInstance().dataUpdated();
    190193  }
     194
     195  @Override
     196  public void paint(Graphics2D g, MapView mv, Bounds box) {
     197  }
    191198}
Note: See TracChangeset for help on using the changeset viewer.