Ticket #11905: patch_multiple_image_plugin.patch
| File patch_multiple_image_plugin.patch, 12.5 KB (added by , 7 years ago) |
|---|
-
plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java
Cannot display: file marked as a binary type. svn:mime-type = application/java-archive
83 83 @Override 84 84 public String getModeHelpText() { 85 85 if (hasLayersToAdjust()) { 86 return tr("Click+drag photo, shift+click to position photo, control+click to set direction.");86 return tr("Click+drag photo, control+alt+click to position photo, control+click to set direction."); 87 87 } else { 88 88 return tr("Please load some photos."); 89 89 } -
plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.photoadjust; 3 3 4 import java.awt.event.InputEvent;5 4 import java.awt.event.MouseEvent; 6 import java.awt.geom.Point2D;7 5 import java.util.List; 8 6 9 7 import org.openstreetmap.josm.data.ImageData; 8 import org.openstreetmap.josm.data.coor.EastNorth; 10 9 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 11 11 import org.openstreetmap.josm.gui.MainApplication; 12 12 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 13 13 import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry; … … 23 23 // Offset between center of the photo and point where it is 24 24 // clicked. This must be in pixels to maintain the same offset if 25 25 // the photo is moved very far. 26 private Point2DdragOffset;26 private EastNorth dragOffset; 27 27 private boolean centerViewIsDisabled = false; 28 28 private boolean centerViewNeedsEnable = false; 29 29 … … 33 33 public void reset() { 34 34 dragPhoto = null; 35 35 dragData = null; 36 dragOffset = null;36 dragOffset = EastNorth.ZERO; 37 37 } 38 38 39 39 /** … … 65 65 66 66 /** 67 67 * Mouse click handler. Control+click changes the image direction if 68 * there is a photo selected on the map. Shift+click positions the photo68 * there is a photo selected on the map. Alt+click positions the photo 69 69 * from the ImageViewerDialog. Click without shift or control checks if 70 70 * there is a photo under the mouse. 71 71 * … … 80 80 && imageLayers != null && !imageLayers.isEmpty()) { 81 81 // Check if modifier key is pressed and change to 82 82 // image viewer photo if it is. 83 final boolean isShift = (evt.getModifiers() & InputEvent.SHIFT_MASK) != 0; 84 final boolean isCtrl = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0; 85 if (isShift || isCtrl) { 83 final boolean isAlt = (evt.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) == MouseEvent.ALT_DOWN_MASK; 84 final boolean isCtrl = (evt.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK; 85 final boolean isShift = (evt.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK; 86 // ignore key press with shift, to not conflict with selection 87 if (isShift) { 88 return; 89 } 90 if (isAlt || isCtrl) { 86 91 for (GeoImageLayer layer: imageLayers) { 87 92 if (layer.isVisible()) { 88 final ImageEntry img = layer.getImageData().getSelectedImage();89 if ( img != null) {93 final List<ImageEntry> entries = layer.getImageData().getSelectedImages(); 94 if (!entries.isEmpty()) { 90 95 // Change direction if control is pressed, position 91 // otherwise. Shift+control changes direction, similar to96 // otherwise. Alt+control changes direction, similar to 92 97 // rotate in select mode. 93 98 // 94 99 // Combinations: 95 // S ... shift pressed100 // A ... alt pressed 96 101 // C ... control pressed 97 102 // pos ... photo has a position set == is displayed on the map 98 103 // nopos ... photo has no position set 99 104 // 100 // S+ pos: position at mouse101 // S+ nopos: position at mouse105 // A + C + pos: position at mouse 106 // A + C + nopos: position at mouse 102 107 // C + pos: change orientation 103 108 // C + nopos: ignored 104 // S + C + pos: change orientation 105 // S + C + nopos: ignore 106 if (isCtrl) { 107 if (img.getPos() != null) { 108 changeDirection(img, layer.getImageData(), evt); 109 for (ImageEntry img: entries) { 110 if (isCtrl && !isAlt) { 111 if (img.getPos() != null) { 112 changeDirection(img, layer.getImageData(), evt); 113 } 114 } else if (isCtrl && isAlt) { 115 movePhoto(img, layer.getImageData(), evt); 109 116 } 110 } else { // shift pressed 111 movePhoto(img, layer.getImageData(), evt); 117 dragPhoto = img; 112 118 } 113 dragPhoto = img;114 119 dragData = layer.getImageData(); 115 120 break; 116 121 } … … 140 145 */ 141 146 public void doMouseReleased(MouseEvent evt) { 142 147 restoreCenterView(); 143 //if (dragLayer != null && dragPhoto != null) {144 // // Re-display the photo to update the OSD.145 // ImageViewerDialog.showImage(dragLayer, dragPhoto);146 //}147 148 } 148 149 149 150 /** … … 153 154 */ 154 155 public void doMouseDragged(MouseEvent evt) { 155 156 if (dragData != null && dragPhoto != null) { 156 if ((evt.getModifiers() & InputEvent.CTRL_MASK) != 0) { 157 changeDirection(dragPhoto, dragData, evt); 157 if ((evt.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK) { 158 if (dragData.isImageSelected(dragPhoto)) { 159 for (ImageEntry photo: dragData.getSelectedImages()) { 160 changeDirection(photo, dragData, evt); 161 } 162 } else { 163 changeDirection(dragPhoto, dragData, evt); 164 } 158 165 } else { 159 166 disableCenterView(); 160 movePhoto(dragPhoto, dragData, evt); 167 final EastNorth startEN = dragPhoto.getPos().getEastNorth(ProjectionRegistry.getProjection()).subtract(dragOffset); 168 final EastNorth currentEN = MainApplication.getMap().mapView.getEastNorth(evt.getX(), evt.getY()); 169 final EastNorth translation = currentEN.subtract(startEN); 170 171 if (dragData.isImageSelected(dragPhoto)) { 172 for (ImageEntry photo: dragData.getSelectedImages()) { 173 translatePhoto(photo, dragData, translation); 174 } 175 } else { 176 translatePhoto(dragPhoto, dragData, translation); 177 } 178 dragData.notifyImageUpdate(); 161 179 } 162 180 } 163 181 } … … 169 187 * @param evt Mouse event from one of the mouse adapters. 170 188 */ 171 189 private void setDragOffset(ImageEntry photo, MouseEvent evt) { 172 final Point2D centerPoint = MainApplication.getMap().mapView.getPoint2D(photo.getPos());173 dragOffset = new Point2D.Double(centerPoint.getX() - evt.getX(),174 centerPoint.getY() - evt.getY());190 final EastNorth centerEN = photo.getPos().getEastNorth(ProjectionRegistry.getProjection()); 191 final EastNorth offsetEN = MainApplication.getMap().mapView.getEastNorth(evt.getX(), evt.getY()); 192 dragOffset = centerEN.subtract(offsetEN); 175 193 } 176 194 177 195 /** … … 181 199 * @param data ImageData of the photo. 182 200 * @param evt Mouse event from one of the mouse adapters. 183 201 */ 184 private void movePhoto(ImageEntry photo, ImageData data, 185 MouseEvent evt) { 186 LatLon newPos; 187 if (dragOffset != null) { 188 newPos = MainApplication.getMap().mapView.getLatLon( 189 dragOffset.getX() + evt.getX(), 190 dragOffset.getY() + evt.getY()); 191 } else { 192 newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY()); 193 } 202 private void movePhoto(ImageEntry photo, ImageData data, MouseEvent evt) { 203 LatLon newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY()); 194 204 data.updateImagePosition(photo, newPos); 195 // Re-display the photo because the OSD data might change (new196 // coordinates). Or do that in doMouseReleased().197 //ImageViewerDialog.showImage(layer, photo);198 205 } 199 206 200 207 /** 208 * Apply the given translation to the photo 209 * @param photo The photo to move 210 * @param data ImageData of the photo 211 * @param translation the translation to apply 212 */ 213 private void translatePhoto(ImageEntry photo, ImageData data, EastNorth translation) { 214 final EastNorth startEN = photo.getPos().getEastNorth(ProjectionRegistry.getProjection()); 215 final EastNorth newPosEN = startEN.add(translation); 216 final LatLon newPos = MainApplication.getMap().mapView.getProjection().eastNorth2latlon(newPosEN); 217 photo.setPos(newPos); 218 photo.flagNewGpsData(); 219 } 220 221 /** 201 222 * Set the image direction, i.e. let it point to where the mouse is. 202 223 * 203 224 * @param photo The photo to move. -
plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java
86 86 87 87 @Override 88 88 public void actionPerformed(ActionEvent evt) { 89 final ImageData data = getLayerWith SelectedImage().get().getImageData();90 final ImageEntry photo = data.getSelectedImage ();89 final ImageData data = getLayerWithOneSelectedImage().get().getImageData(); 90 final ImageEntry photo = data.getSelectedImages().get(0); 91 91 92 92 StringBuilder title = 93 93 new StringBuilder(tr("Edit Photo GPS Data")); … … 116 116 * image shown, {@code false} otherwise. 117 117 */ 118 118 private static boolean enabled() { 119 return getLayerWith SelectedImage().isPresent();119 return getLayerWithOneSelectedImage().isPresent(); 120 120 } 121 121 122 private static Optional<GeoImageLayer> getLayerWith SelectedImage() {122 private static Optional<GeoImageLayer> getLayerWithOneSelectedImage() { 123 123 List<GeoImageLayer> list = MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class); 124 return list.stream().filter(l -> l.getImageData().getSelectedImage () != null).findFirst();124 return list.stream().filter(l -> l.getImageData().getSelectedImages().size() == 1).findFirst(); 125 125 } 126 126 127 127 @Override … … 157 157 // ignored 158 158 } 159 159 160 @Override161 public void selectedImageChanged(ImageData data) {160 @Override 161 public void selectedImageChanged(ImageData data) { 162 162 this.updateEnabledState(); 163 }163 } 164 164 } 165 165 166 166 /**
