Changeset 31489 in osm for applications


Ignore:
Timestamp:
2015-08-12T12:39:30+02:00 (9 years ago)
Author:
nokutu
Message:

Created join and unjoin commands.

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

Legend:

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

    r31460 r31489  
    66import java.awt.Point;
    77import java.awt.event.MouseEvent;
    8 import java.util.ArrayList;
     8import java.util.Arrays;
    99
    1010import org.openstreetmap.josm.Main;
     
    1515import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    1616import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    17 import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
     17import org.openstreetmap.josm.plugins.mapillary.commands.CommandJoin;
     18import org.openstreetmap.josm.plugins.mapillary.commands.CommandUnjoin;
     19import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
    1820
    1921/**
     
    4446    } else if (this.lastClick != null
    4547        && this.data.getHighlightedImage() instanceof MapillaryImportedImage) {
    46       if (((this.data.getHighlightedImage().previous() == null && this.lastClick.next() == null) || (this.data
    47           .getHighlightedImage().next() == null && this.lastClick.previous() == null))
    48           && (this.data.getHighlightedImage().getSequence() != this.lastClick.getSequence() || this.lastClick
    49               .getSequence() == null)) {
    50         join(this.lastClick, (MapillaryImportedImage) this.data.getHighlightedImage());
     48      if (((this.data.getHighlightedImage().previous() == null && this.lastClick
     49          .next() == null) || (this.data.getHighlightedImage().next() == null && this.lastClick
     50          .previous() == null))
     51          && (this.data.getHighlightedImage().getSequence() != this.lastClick
     52              .getSequence() || this.lastClick.getSequence() == null)) {
     53
     54        MapillaryRecord.getInstance().addCommand(
     55            new CommandJoin(Arrays.asList(new MapillaryAbstractImage[] {
     56                this.lastClick, this.data.getHighlightedImage() })));
    5157      } else if (this.lastClick.next() == this.data.getHighlightedImage()
    5258          || this.lastClick.previous() == this.data.getHighlightedImage())
    53         unjoin(this.lastClick, (MapillaryImportedImage) this.data.getHighlightedImage());
     59        MapillaryRecord.getInstance().addCommand(
     60            new CommandUnjoin(Arrays.asList(new MapillaryAbstractImage[] {
     61                this.lastClick, this.data.getHighlightedImage() })));
    5462      this.lastClick = null;
    5563    }
    56     MapillaryData.dataUpdated();
     64    if (Main.main != null)
     65      MapillaryData.dataUpdated();
    5766  }
    5867
     
    7786  }
    7887
    79   private static void join(MapillaryImportedImage img1, MapillaryImportedImage img2) {
    80     MapillaryImportedImage firstImage = img1;
    81     MapillaryImportedImage secondImage = img2;
    82 
    83     if (img1.next() != null) {
    84       firstImage = img2;
    85       secondImage = img1;
    86     }
    87     if (firstImage.getSequence() == null) {
    88       MapillarySequence seq = new MapillarySequence();
    89       seq.add(firstImage);
    90       firstImage.setSequence(seq);
    91     }
    92     if (secondImage.getSequence() == null) {
    93       MapillarySequence seq = new MapillarySequence();
    94       seq.add(secondImage);
    95       img2.setSequence(seq);
    96     }
    97 
    98     for (MapillaryAbstractImage img : secondImage.getSequence().getImages()) {
    99       firstImage.getSequence().add(img);
    100       img.setSequence(firstImage.getSequence());
    101     }
    102   }
    103 
    104   private static void unjoin(MapillaryImportedImage img1, MapillaryImportedImage img2) {
    105     MapillaryImportedImage firstImage = img1;
    106     MapillaryImportedImage secondImage = img2;
    107 
    108     if (img1.next() != img2) {
    109       firstImage = img2;
    110       secondImage = img1;
    111     }
    112 
    113     ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(firstImage
    114         .getSequence().getImages()
    115         .subList(0, firstImage.getSequence().getImages().indexOf(secondImage)));
    116     ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(firstImage
    117         .getSequence()
    118         .getImages()
    119         .subList(firstImage.getSequence().getImages().indexOf(secondImage),
    120             firstImage.getSequence().getImages().size()));
    121 
    122     MapillarySequence seq1 = new MapillarySequence();
    123     MapillarySequence seq2 = new MapillarySequence();
    124 
    125     for (MapillaryAbstractImage img : firstHalf) {
    126       img.setSequence(seq1);
    127       seq1.add(img);
    128     }
    129     for (MapillaryAbstractImage img : secondHalf) {
    130       img.setSequence(seq2);
    131       seq2.add(img);
    132     }
    133   }
    134 
    13588  @Override
    13689  public String toString() {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31475 r31489  
    77import java.net.URISyntaxException;
    88import java.net.URL;
     9import java.util.ArrayList;
    910
    1011import org.apache.commons.imaging.common.RationalNumber;
    1112import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
    1213import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     15import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     16import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    1317import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     18import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
    1419
    1520/**
     
    120125    }
    121126  }
     127
     128  /**
     129   * Joins two images into the same sequence.
     130   *
     131   * @param img1
     132   * @param img2
     133   */
     134  public synchronized static void join(MapillaryImportedImage img1,
     135      MapillaryImportedImage img2) {
     136    MapillaryImportedImage firstImage = img1;
     137    MapillaryImportedImage secondImage = img2;
     138
     139    if (img1.next() != null) {
     140      firstImage = img2;
     141      secondImage = img1;
     142    }
     143    if (firstImage.getSequence() == null) {
     144      MapillarySequence seq = new MapillarySequence();
     145      seq.add(firstImage);
     146      firstImage.setSequence(seq);
     147    }
     148    if (secondImage.getSequence() == null) {
     149      MapillarySequence seq = new MapillarySequence();
     150      seq.add(secondImage);
     151      img2.setSequence(seq);
     152    }
     153
     154    for (MapillaryAbstractImage img : secondImage.getSequence().getImages()) {
     155      firstImage.getSequence().add(img);
     156      img.setSequence(firstImage.getSequence());
     157    }
     158    if (Main.main != null)
     159      MapillaryData.dataUpdated();
     160  }
     161
     162  /**
     163   * Separates two images belonging to the same sequence.
     164   *
     165   * @param img1
     166   * @param img2
     167   */
     168  public synchronized static void unjoin(MapillaryImportedImage img1,
     169      MapillaryImportedImage img2) {
     170    MapillaryImportedImage firstImage = img1;
     171    MapillaryImportedImage secondImage = img2;
     172
     173    if (img1.next() != img2) {
     174      firstImage = img2;
     175      secondImage = img1;
     176    }
     177
     178    ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(firstImage
     179        .getSequence().getImages()
     180        .subList(0, firstImage.getSequence().getImages().indexOf(secondImage)));
     181    ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(firstImage
     182        .getSequence()
     183        .getImages()
     184        .subList(firstImage.getSequence().getImages().indexOf(secondImage),
     185            firstImage.getSequence().getImages().size()));
     186
     187    MapillarySequence seq1 = new MapillarySequence();
     188    MapillarySequence seq2 = new MapillarySequence();
     189
     190    for (MapillaryAbstractImage img : firstHalf) {
     191      img.setSequence(seq1);
     192      seq1.add(img);
     193    }
     194    for (MapillaryAbstractImage img : secondHalf) {
     195      img.setSequence(seq2);
     196      seq2.add(img);
     197    }
     198    if (Main.main != null)
     199      MapillaryData.dataUpdated();
     200  }
    122201}
Note: See TracChangeset for help on using the changeset viewer.