Changeset 31417 in osm for applications/editors/josm


Ignore:
Timestamp:
2015-07-30T13:17:43+02:00 (9 years ago)
Author:
nokutu
Message:

Created a few more tests. In order to run them, a JOSM window is opened.

Location:
applications/editors/josm/plugins/mapillary
Files:
3 added
1 deleted
11 edited

Legend:

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

    r31399 r31417  
    11package org.openstreetmap.josm.plugins.mapillary;
    22
     3import java.io.File;
    34import java.io.IOException;
    45
     
    3132public class MapillaryPlugin extends Plugin {
    3233
     34  /** Plugin's directory */
     35  public static String directory;
    3336  /** 24x24 icon. */
    34   public static final ImageIcon ICON24 = new ImageProvider("icon24.png").get();
     37  public static ImageIcon ICON24;
    3538  /** 16x16 icon. */
    36   public static final ImageIcon ICON16 = new ImageProvider("icon16.png").get();
     39  public static ImageIcon ICON16;
    3740  /** Icon representing an image in the map. */
    38   public static final ImageIcon MAP_ICON = new ImageProvider("mapicon.png")
    39       .get();
     41  public static ImageIcon MAP_ICON;
    4042  /** Icon representing a selected image in the map. */
    41   public static final ImageIcon MAP_ICON_SELECTED = new ImageProvider(
    42       "mapiconselected.png").get();
     43  public static ImageIcon MAP_ICON_SELECTED;
    4344  /** Icon representing an imported image in the map. */
    44   public static final ImageIcon MAP_ICON_IMPORTED = new ImageProvider(
    45       "mapiconimported.png").get();
     45  public static ImageIcon MAP_ICON_IMPORTED;
    4646  /** Icon used to identify which images have signs on them */
    47   public static final ImageIcon MAP_SIGN = new ImageProvider("sign.png").get();
     47  public static ImageIcon MAP_SIGN;
    4848
    4949  /** Cache that stores the pictures the downloaded pictures. */
     
    5252  private final MapillaryDownloadAction downloadAction;
    5353  private final MapillaryExportAction exportAction;
    54   private final MapillaryImportAction importAction;
     54  public static MapillaryImportAction importAction;
    5555  private final MapillaryZoomAction zoomAction;
    5656  private final MapillaryDownloadViewAction downloadViewAction;
     
    5858  private final MapillaryJoinAction joinAction;
    5959  /** Walk action */
    60   public final static MapillaryWalkAction walkAction = new MapillaryWalkAction();
     60  public static MapillaryWalkAction walkAction;
    6161
    6262  /** Menu button for the {@link MapillaryDownloadAction} action. */
     
    8484  public MapillaryPlugin(PluginInformation info) {
    8585    super(info);
     86
     87    directory = new File("").getAbsolutePath() + "/";
     88    ICON24 = new ImageProvider(directory + "images/icon24.png").get();
     89    ICON16 = new ImageProvider(directory + "images/icon16.png").get();
     90    MAP_ICON = new ImageProvider(directory + "images/mapicon.png").get();
     91    MAP_ICON_SELECTED = new ImageProvider(directory
     92        + "images/mapiconselected.png").get();
     93    MAP_ICON_IMPORTED = new ImageProvider(directory
     94        + "images/mapiconimported.png").get();
     95    MAP_SIGN = new ImageProvider(directory + "images/sign.png").get();
     96
    8697    downloadAction = new MapillaryDownloadAction();
     98    walkAction = new MapillaryWalkAction();
    8799    exportAction = new MapillaryExportAction();
    88100    importAction = new MapillaryImportAction();
     
    106118      JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, joinAction, false);
    107119      WALK_MENU = MainMenu.add(Main.main.menu.moreToolsMenu, walkAction, false);
     120
     121      EXPORT_MENU.setEnabled(false);
     122      DOWNLOAD_MENU.setEnabled(false);
     123      IMPORT_MENU.setEnabled(false);
     124      IMPORT_INTO_SEQUENCE_MENU.setEnabled(false);
     125      ZOOM_MENU.setEnabled(false);
     126      DOWNLOAD_VIEW_MENU.setEnabled(false);
     127      JOIN_MENU.setEnabled(false);
     128      WALK_MENU.setEnabled(false);
    108129    }
    109 
    110     EXPORT_MENU.setEnabled(false);
    111     DOWNLOAD_MENU.setEnabled(false);
    112     IMPORT_MENU.setEnabled(false);
    113     IMPORT_INTO_SEQUENCE_MENU.setEnabled(false);
    114     ZOOM_MENU.setEnabled(false);
    115     DOWNLOAD_VIEW_MENU.setEnabled(false);
    116     JOIN_MENU.setEnabled(false);
    117     WALK_MENU.setEnabled(false);
    118130
    119131    try {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadAction.java

    r31409 r31417  
    1212import org.openstreetmap.josm.actions.JosmAction;
    1313import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     14import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    1415import org.openstreetmap.josm.tools.ImageProvider;
    1516import org.openstreetmap.josm.tools.Shortcut;
     
    3031   */
    3132  public MapillaryDownloadAction() {
    32     super(tr("Mapillary"), new ImageProvider("icon24.png"),
     33    super(tr("Mapillary"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
    3334        tr("Create Mapillary layer"), Shortcut.registerShortcut("Mapillary",
    3435            tr("Start Mapillary layer"), KeyEvent.VK_COMMA, Shortcut.SHIFT),
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryDownloadViewAction.java

    r31399 r31417  
    1111import org.openstreetmap.josm.actions.JosmAction;
    1212import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     13import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    1314import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    1415import org.openstreetmap.josm.tools.ImageProvider;
     
    3435  public MapillaryDownloadViewAction() {
    3536    super(tr("Download Mapillary images in current view"), new ImageProvider(
    36         "icon24.png"), tr("Download Mapillary images in current view"),
     37        MapillaryPlugin.directory + "images/icon24.png"), tr("Download Mapillary images in current view"),
    3738        Shortcut.registerShortcut("Mapillary area",
    3839            tr("Download Mapillary images in current view"),
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java

    r31401 r31417  
    2121import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
    2222import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
     23import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    2324import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryExportManager;
    2425import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryExportDialog;
     
    4243   */
    4344  public MapillaryExportAction() {
    44     super(tr("Export pictures"), new ImageProvider("icon24.png"),
     45    super(tr("Export pictures"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
    4546        tr("Export pictures"), Shortcut.registerShortcut("Export Mapillary",
    4647            tr("Export Mapillary pictures"), KeyEvent.CHAR_UNDEFINED,
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31415 r31417  
    2525import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2626import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     27import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    2728import org.openstreetmap.josm.tools.ImageProvider;
    2829import org.openstreetmap.josm.tools.Shortcut;
     
    4950   */
    5051  public MapillaryImportAction() {
    51     super(tr("Import pictures"), new ImageProvider("icon24.png"),
     52    super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
    5253        tr("Import local pictures"), Shortcut.registerShortcut(
    5354            "Import Mapillary", tr("Import pictures into Mapillary layer"),
     
    8586            try {
    8687              if (extension.equals("jpg") || extension.equals("jpeg"))
    87                 readJPG(file.listFiles()[j]);
     88                MapillaryData.getInstance().add(readJPG(file.listFiles()[j]));
    8889
    8990              else if (extension.equals("png"))
    90                 readPNG(file.listFiles()[j]);
     91                MapillaryData.getInstance().add(readPNG(file.listFiles()[j]));
    9192            } catch (ImageReadException | IOException | NullPointerException e1) {
    9293              Main.error(e1);
     
    99100                  .equals(".jpeg")) {
    100101            try {
    101               readJPG(file);
     102              MapillaryData.getInstance().add(readJPG(file));
    102103            } catch (ImageReadException ex) {
    103104              Main.error(ex);
     
    107108          } else if (file.getPath().substring(file.getPath().length() - 4)
    108109              .equals(".png")) {
    109             readPNG(file);
     110            MapillaryData.getInstance().add(readPNG(file));
    110111          }
    111112        }
    112113      }
    113     }
    114   }
    115 
    116   /**
    117    * Reads a jpg pictures that contains the needed GPS information (position and
     114      MapillaryLayer.getInstance().showAllPictures();
     115
     116    }
     117  }
     118
     119  /**
     120   * Reads a JPG pictures that contains the needed GPS information (position and
    118121   * direction) and creates a new icon in that position.
    119122   *
    120123   * @param file
     124   * @return The imported image.
    121125   * @throws ImageReadException
    122126   * @throws IOException
    123127   */
    124   public void readJPG(File file) throws ImageReadException, IOException {
     128  public MapillaryImportedImage readJPG(File file) throws ImageReadException,
     129      IOException {
    125130    final ImageMetadata metadata = Imaging.getMetadata(file);
    126131    if (metadata instanceof JpegImageMetadata) {
     
    139144          .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    140145      if (lat_ref == null || lat == null || lon == null || lon_ref == null) {
    141         readNoTags(file);
    142         return;
     146        return readNoTags(file);
    143147      }
    144148      double latValue = 0;
     
    154158        caValue = ((RationalNumber) ca.getValue()).doubleValue();
    155159      if (datetimeOriginal != null)
    156         MapillaryData.getInstance().add(
    157             new MapillaryImportedImage(latValue, lonValue, caValue, file,
    158                 datetimeOriginal.getStringValue()));
     160        return new MapillaryImportedImage(latValue, lonValue, caValue, file,
     161            datetimeOriginal.getStringValue());
    159162      else
    160         MapillaryData.getInstance().add(
    161             new MapillaryImportedImage(latValue, lonValue, caValue, file));
    162     }
    163 
    164     MapillaryLayer.getInstance().showAllPictures();
     163        return new MapillaryImportedImage(latValue, lonValue, caValue, file);
     164    }
     165    throw new IllegalStateException("Invalid format.");
    165166  }
    166167
     
    170171   *
    171172   * @param file
    172    */
    173   private void readNoTags(File file) {
     173   * @return The imported image.
     174   */
     175  public MapillaryImportedImage readNoTags(File file) {
    174176    double HORIZONTAL_DISTANCE = 0.0001;
    175177    double horDev;
     
    180182    LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(
    181183        Main.map.mapView.getCenter());
    182     MapillaryData.getInstance().add(
    183         new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file));
    184184    noTagsPics++;
    185   }
    186 
    187   private void readPNG(File file) {
    188     readNoTags(file);
     185    return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);
     186  }
     187
     188  /**
     189   * Reads an image in PNG format.
     190   *
     191   * @param file
     192   * @return The imported image.
     193   */
     194  public MapillaryImportedImage readPNG(File file) {
     195    return readNoTags(file);
    189196  }
    190197
     
    219226  public static double degMinSecToDouble(RationalNumber[] degMinSec, String ref) {
    220227    if (degMinSec == null || degMinSec.length != 3) {
    221       throw new IllegalArgumentException();
    222     }
     228      throw new IllegalArgumentException("Array's length must be 3.");
     229    }
     230    for (int i = 0; i < 3; i++)
     231      if (degMinSec[i] == null)
     232        throw new IllegalArgumentException("Null value in array.");
     233
    223234    switch (ref) {
    224235      case GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH:
     
    228239        break;
    229240      default:
    230         throw new IllegalArgumentException();
     241        throw new IllegalArgumentException("Invalid ref.");
    231242    }
    232243
     
    235246    result += degMinSec[2].doubleValue() / 3600; // seconds
    236247
     248    while (result >= 180) {
     249      result -= 180;
     250    }
     251    while (result <= -180) {
     252      result += 180;
     253    }
     254
    237255    if (GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH.equals(ref)
    238256        || GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST.equals(ref)) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31415 r31417  
    2828import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2929import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     30import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    3031import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
    3132import org.openstreetmap.josm.tools.ImageProvider;
     
    5051   */
    5152  public MapillaryImportIntoSequenceAction() {
    52     super(tr("Import pictures into sequence"), new ImageProvider("icon24.png"),
     53    super(tr("Import pictures into sequence"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
    5354        tr("Import local pictures"), Shortcut.registerShortcut(
    5455            "Import Mapillary Sequence",
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryJoinAction.java

    r31386 r31417  
    88import org.openstreetmap.josm.actions.JosmAction;
    99import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     10import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    1011import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode;
    1112import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode;
     
    2728   */
    2829  public MapillaryJoinAction() {
    29     super(tr("Join mode"), new ImageProvider("icon24.png"),
     30    super(tr("Join mode"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
    3031        tr("Join/unjoin pictures"), Shortcut.registerShortcut("Mapillary join",
    3132            tr("Join Mapillary pictures"), KeyEvent.CHAR_UNDEFINED,
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java

    r31416 r31417  
    3939   */
    4040  public MapillaryWalkAction() {
    41     super(tr("Walk mode"), new ImageProvider("icon24.png"), tr("Walk mode"),
    42         Shortcut.registerShortcut("Mapillary walk", tr("Start walk mode"),
    43             KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryWalk",
    44         false);
     41    super(tr("Walk mode"), new ImageProvider(MapillaryPlugin.directory
     42        + "images/icon24.png"), tr("Walk mode"), Shortcut.registerShortcut(
     43        "Mapillary walk", tr("Start walk mode"), KeyEvent.CHAR_UNDEFINED,
     44        Shortcut.NONE), false, "mapillaryWalk", false);
    4545    this.setEnabled(false);
    4646  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryZoomAction.java

    r31387 r31417  
    3030   */
    3131  public MapillaryZoomAction() {
    32     super(tr("Zoom to selected image"), new ImageProvider("icon24.png"),
     32    super(tr("Zoom to selected image"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
    3333        tr("Zoom to selected image"), Shortcut.registerShortcut(
    3434            "Zoom Mapillary",
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31415 r31417  
    9696        LOCK.lock();
    9797        MapillaryImage.LOCK.lock();
    98         for (MapillaryImage img : finalImages) {
    99           if (layer.getMapillaryData().getImages().contains(img)) {
    100             // The image in finalImages is substituted by the one in the
    101             // database, as they represent the same picture.
    102             img = (MapillaryImage) layer.getMapillaryData().getImages()
    103                 .get(layer.getMapillaryData().getImages().indexOf(img));
    104             sequence.add(img);
    105             ((MapillaryImage) layer.getMapillaryData().getImages()
    106                 .get(layer.getMapillaryData().getImages().indexOf(img)))
    107                 .setSequence(sequence);
    108             finalImages.set(finalImages.indexOf(img), img);
    109           } else {
    110             img.setSequence(sequence);
    111             sequence.add(img);
     98        try {
     99          for (MapillaryImage img : finalImages) {
     100            if (layer.getMapillaryData().getImages().contains(img)) {
     101              // The image in finalImages is substituted by the one in the
     102              // database, as they represent the same picture.
     103              img = (MapillaryImage) layer.getMapillaryData().getImages()
     104                  .get(layer.getMapillaryData().getImages().indexOf(img));
     105              sequence.add(img);
     106              ((MapillaryImage) layer.getMapillaryData().getImages()
     107                  .get(layer.getMapillaryData().getImages().indexOf(img)))
     108                  .setSequence(sequence);
     109              finalImages.set(finalImages.indexOf(img), img);
     110            } else {
     111              img.setSequence(sequence);
     112              sequence.add(img);
     113            }
    112114          }
     115        } finally {
     116          MapillaryImage.LOCK.unlock();
     117          LOCK.unlock();
    113118        }
    114         MapillaryImage.LOCK.unlock();
    115         LOCK.unlock();
    116119
    117120        layer.getMapillaryData().addWithoutUpdate(
     
    121124      Main.error("Error reading the url " + URL + queryString
    122125          + " might be a Mapillary problem.");
    123     } finally {
    124       LOCK.unlock();
    125       MapillaryImage.LOCK.unlock();
    126126    }
    127127  }
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/util/TestUtil.java

    r31347 r31417  
    11package org.openstreetmap.josm.plugins.mapillary.util;
     2
     3import java.io.File;
    24
    35import org.openstreetmap.josm.Main;
    46import org.openstreetmap.josm.data.projection.Projections;
     7import org.openstreetmap.josm.plugins.PluginException;
     8import org.openstreetmap.josm.plugins.PluginInformation;
    59import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     10import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    611import org.openstreetmap.josm.tools.I18n;
    712
     
    3035            I18n.set(Main.pref.get("language", "en"));
    3136            Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
    32 
     37            try {
     38              new MapillaryPlugin(new PluginInformation(new File("/home/nokutu/.josm/plugins/Mapillary.jar")));
     39            } catch (PluginException e) {
     40              // TODO Auto-generated catch block
     41              e.printStackTrace();
     42            }
    3343            isInitialized = true;
    3444        }
Note: See TracChangeset for help on using the changeset viewer.