Changeset 30883 in osm
- Timestamp:
- 2014-12-27T22:56:29+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java
r30774 r30883 70 70 public String getModeHelpText() { 71 71 if (hasLayersToAdjust()) { 72 return tr("Click+drag photo or shift+click to position photo.");72 return tr("Click+drag photo, shift+click to position photo, control+click to set direction."); 73 73 } 74 74 else { -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java
r30130 r30883 34 34 35 35 /** 36 * Mouse click handler. Shift+click positions the photo from the 37 * ImageViewerDialog. Click without shift checks if there is a 38 * photo under the mouse. 36 * Mouse click handler. Control+click changes the image direction if 37 * there is a photo selected on the map. Shift+click positions the photo 38 * from the ImageViewerDialog. Click without shift or control checks if 39 * there is a photo under the mouse. 39 40 * 40 41 * @param evt Mouse event from MouseAdapter mousePressed(). 41 * @param imageLayers GeoImageLayerto be considered.42 * @param imageLayers List of GeoImageLayers to be considered. 42 43 */ 43 44 public void doMousePressed(MouseEvent evt, … … 47 48 if (evt.getButton() == MouseEvent.BUTTON1 48 49 && imageLayers != null && imageLayers.size() > 0) { 49 // Check if modifier key was pressed and change to 50 // image viewer photo if it was. 51 if ((evt.getModifiers() & InputEvent.SHIFT_MASK) != 0) { 52 GeoImageLayer viewerLayer = ImageViewerDialog.getCurrentLayer(); 53 ImageEntry img = ImageViewerDialog.getCurrentImage(); 50 // Check if modifier key is pressed and change to 51 // image viewer photo if it is. 52 final boolean isShift = (evt.getModifiers() & InputEvent.SHIFT_MASK) != 0; 53 final boolean isCtrl = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0; 54 if (isShift || isCtrl) { 55 final GeoImageLayer viewerLayer = ImageViewerDialog.getCurrentLayer(); 56 final ImageEntry img = ImageViewerDialog.getCurrentImage(); 54 57 if ( img != null && viewerLayer != null 55 58 && viewerLayer.isVisible() 56 59 && imageLayers.contains(viewerLayer)) { 57 img.setPos(Main.map.mapView.getLatLon(evt.getX(), evt.getY())); 58 img.flagNewGpsData(); 59 viewerLayer.updateBufferAndRepaint(); 60 // Need to re-display the photo because the 61 // OSD data might change (new coordinates). 62 ImageViewerDialog.showImage(viewerLayer, img); 60 // Change direction if control is pressed, position 61 // otherwise. Shift+control changes direction, similar to 62 // rotate in select mode. 63 // 64 // Combinations: 65 // S ... shift pressed 66 // C ... control pressed 67 // pos ... photo has a position set == is displayed on the map 68 // nopos ... photo has no position set 69 // 70 // S + pos: position at mouse 71 // S + nopos: position at mouse 72 // C + pos: change orientation 73 // C + nopos: ignored 74 // S + C + pos: change orientation 75 // S + C + nopos: ignore 76 if (isCtrl) { 77 if (img.getPos() != null) { 78 changeDirection(img, viewerLayer, evt); 79 } 80 } 81 else { // shift pressed 82 movePhoto(img, viewerLayer, evt); 83 } 63 84 dragPhoto = img; 64 85 dragLayer = viewerLayer; … … 72 93 if (dragPhoto != null) { 73 94 dragLayer = layer; 74 Point2D centerPoint = Main.map.mapView.getPoint2D(dragPhoto.getPos()); 75 dragOffset = new Point2D.Double(centerPoint.getX() - evt.getX(), 76 centerPoint.getY() - evt.getY()); 95 setDragOffset(dragPhoto, evt); 77 96 break; 78 97 } … … 84 103 85 104 /** 86 * Mouse drag handler. Moves photo.105 * Mouse drag handler. Changes direction or moves photo. 87 106 * 88 107 * @param evt Mouse event from MouseMotionAdapter mouseDragged(). … … 91 110 if ( dragLayer != null && dragLayer.isVisible() 92 111 && dragPhoto != null) { 93 LatLon newPos; 94 if (dragOffset != null) { 95 newPos = Main.map.mapView.getLatLon(dragOffset.getX() + evt.getX(), 96 dragOffset.getY() + evt.getY()); 112 if ((evt.getModifiers() & InputEvent.CTRL_MASK) != 0) { 113 changeDirection(dragPhoto, dragLayer, evt); 97 114 } 98 115 else { 99 newPos = Main.map.mapView.getLatLon(evt.getX(), evt.getY());116 movePhoto(dragPhoto, dragLayer, evt); 100 117 } 101 dragPhoto.setPos(newPos);102 dragPhoto.flagNewGpsData();103 dragLayer.updateBufferAndRepaint();104 118 } 105 119 } 120 121 /** 122 * Set the offset between a photo and the current mouse position. 123 * 124 * @param photo The photo to move. 125 * @param evt Mouse event from one of the mouse adapters. 126 */ 127 private void setDragOffset(ImageEntry photo, MouseEvent evt) { 128 final Point2D centerPoint = Main.map.mapView.getPoint2D(photo.getPos()); 129 dragOffset = new Point2D.Double(centerPoint.getX() - evt.getX(), 130 centerPoint.getY() - evt.getY()); 131 } 132 133 /** 134 * Move the photo to the mouse position. 135 * 136 * @param photo The photo to move. 137 * @param layer GeoImageLayer of the photo. 138 * @param evt Mouse event from one of the mouse adapters. 139 */ 140 private void movePhoto(ImageEntry photo, GeoImageLayer layer, 141 MouseEvent evt) { 142 LatLon newPos; 143 if (dragOffset != null) { 144 newPos = Main.map.mapView.getLatLon(dragOffset.getX() + evt.getX(), 145 dragOffset.getY() + evt.getY()); 146 } 147 else { 148 newPos = Main.map.mapView.getLatLon(evt.getX(), evt.getY()); 149 } 150 photo.setPos(newPos); 151 photo.flagNewGpsData(); 152 layer.updateBufferAndRepaint(); 153 // Need to re-display the photo because the OSD data might change (new 154 // coordinates). 155 ImageViewerDialog.showImage(viewerLayer, img); 156 } 157 158 /** 159 * Set the image direction, i.e. let it point to where the mouse is. 160 * 161 * @param photo The photo to move. 162 * @param layer GeoImageLayer of the photo. 163 * @param evt Mouse event from one of the mouse adapters. 164 */ 165 private void changeDirection(ImageEntry photo, GeoImageLayer layer, 166 MouseEvent evt) { 167 final LatLon photoLL = photo.getPos(); 168 final LatLon mouseLL = Main.map.mapView.getLatLon(evt.getX(), evt.getY()); 169 // The projection doesn't matter here. 170 double direction = 360.0 - photoLL.heading(mouseLL) * 360.0 / 2.0 / Math.PI; 171 if (direction < 0.0) { 172 direction += 360.0; 173 } else if (direction >= 360.0) { 174 direction -= 360.0; 175 } 176 photo.setExifImgDir(direction); 177 photo.flagNewGpsData(); 178 layer.updateBufferAndRepaint(); 179 ImageViewerDialog.showImage(layer, photo); 180 setDragOffset(photo, evt); 181 } 106 182 }
Note:
See TracChangeset
for help on using the changeset viewer.