Changeset 35108 in osm


Ignore:
Timestamp:
2019-09-09T20:35:38+02:00 (5 years ago)
Author:
holgermappt
Message:

Apply patch to work with multiple photos, see #josm11905

Location:
applications/editors/josm/plugins/photoadjust
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/photoadjust/README

    r30936 r35108  
    3232    License: GPL v2 or later
    3333  src/org/openstreetmap/josm/plugins/photoadjust/
    34     self written code
    35     License: CC0
     34    different authors (see SVN log)
     35    License: GPL v2 or later
    3636  data:
    3737    translations (*.lang):
  • applications/editors/josm/plugins/photoadjust/build.xml

    r34799 r35108  
    55    <property name="commit.message" value="Commit message"/>
    66    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    7     <property name="plugin.main.version" value="14625"/>
     7    <property name="plugin.main.version" value="15334"/>
    88
    99    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java

    r33757 r35108  
    8484    public String getModeHelpText() {
    8585        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.");
    8787        } else {
    8888            return tr("Please load some photos.");
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java

    r34786 r35108  
    22package org.openstreetmap.josm.plugins.photoadjust;
    33
    4 import java.awt.event.InputEvent;
    54import java.awt.event.MouseEvent;
    6 import java.awt.geom.Point2D;
    75import java.util.List;
    86
    97import org.openstreetmap.josm.data.ImageData;
     8import org.openstreetmap.josm.data.coor.EastNorth;
    109import org.openstreetmap.josm.data.coor.LatLon;
     10import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1111import org.openstreetmap.josm.gui.MainApplication;
    1212import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer;
     
    2424    // clicked.  This must be in pixels to maintain the same offset if
    2525    // the photo is moved very far.
    26     private Point2D dragOffset;
     26    private EastNorth dragOffset;
    2727    private boolean centerViewIsDisabled = false;
    2828    private boolean centerViewNeedsEnable = false;
     
    3434        dragPhoto = null;
    3535        dragData = null;
    36         dragOffset = null;
     36        dragOffset = EastNorth.ZERO;
    3737    }
    3838
     
    6666    /**
    6767     * Mouse click handler.  Control+click changes the image direction if
    68      * there is a photo selected on the map.  Shift+click positions the photo
    69      * from the ImageViewerDialog.  Click without shift or control checks if
    70      * there is a photo under the mouse.
     68     * there is a photo selected on the map.  Control+alt+click positions the
     69     * selected photo.  Click without shift or control checks if there is a
     70     * photo under the mouse and uses it for dragging.
    7171     *
    7272     * @param evt Mouse event from MouseAdapter mousePressed().
     
    8181            // Check if modifier key is pressed and change to
    8282            // 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) {
    8691                for (GeoImageLayer layer: imageLayers) {
    8792                    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()) {
    9095                            // Change direction if control is pressed, position
    91                             // otherwise.  Shift+control changes direction, similar to
    92                             // rotate in select mode.
     96                            // with control+alt.
    9397                            //
    9498                            // Combinations:
    95                             // S ... shift pressed
     99                            // A ... alt pressed
    96100                            // C ... control pressed
    97101                            // pos ... photo has a position set == is displayed on the map
    98102                            // nopos ... photo has no position set
    99103                            //
    100                             // S + pos: position at mouse
    101                             // S + nopos: position at mouse
     104                            // C + A + pos: position at mouse
     105                            // C + A + nopos: position at mouse
    102106                            // C + pos: change orientation
    103107                            // 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);
     108                            for (ImageEntry img: entries) {
     109                                if (isCtrl && !isAlt) {
     110                                    if (img.getPos() != null) {
     111                                        changeDirection(img, layer.getImageData(), evt);
     112                                    }
     113                                } else if (isCtrl && isAlt) {
     114                                    movePhoto(img, layer.getImageData(), evt);
    109115                                }
    110                             } else { // shift pressed
    111                                 movePhoto(img, layer.getImageData(), evt);
     116                                dragPhoto = img;
    112117                            }
    113                             dragPhoto = img;
    114118                            dragData = layer.getImageData();
    115119                            break;
     
    141145    public void doMouseReleased(MouseEvent evt) {
    142146        restoreCenterView();
    143         //if (dragLayer != null && dragPhoto != null) {
    144         //    // Re-display the photo to update the OSD.
    145         //    ImageViewerDialog.showImage(dragLayer, dragPhoto);
    146         //}
    147147    }
    148148
     
    154154    public void doMouseDragged(MouseEvent evt) {
    155155        if (dragData != null && dragPhoto != null) {
    156             if ((evt.getModifiers() & InputEvent.CTRL_MASK) != 0) {
    157                 changeDirection(dragPhoto, dragData, evt);
     156            if ((evt.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK) {
     157                if (dragData.isImageSelected(dragPhoto)) {
     158                    for (ImageEntry photo: dragData.getSelectedImages()) {
     159                        changeDirection(photo, dragData, evt);
     160                    }
     161                } else {
     162                    changeDirection(dragPhoto, dragData, evt);
     163                }
    158164            } else {
    159165                disableCenterView();
    160                 movePhoto(dragPhoto, dragData, evt);
     166                final EastNorth startEN = dragPhoto.getPos().getEastNorth(ProjectionRegistry.getProjection()).subtract(dragOffset);
     167                final EastNorth currentEN = MainApplication.getMap().mapView.getEastNorth(evt.getX(), evt.getY());
     168                final EastNorth translation = currentEN.subtract(startEN);
     169
     170                if (dragData.isImageSelected(dragPhoto)) {
     171                    for (ImageEntry photo: dragData.getSelectedImages()) {
     172                        translatePhoto(photo, translation);
     173                    }
     174                } else {
     175                    translatePhoto(dragPhoto, translation);
     176                }
     177                dragData.notifyImageUpdate();
    161178            }
    162179        }
     
    170187     */
    171188    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());
     189        final EastNorth centerEN = photo.getPos().getEastNorth(ProjectionRegistry.getProjection());
     190        final EastNorth offsetEN = MainApplication.getMap().mapView.getEastNorth(evt.getX(), evt.getY());
     191        dragOffset = centerEN.subtract(offsetEN);
    175192    }
    176193
     
    182199     * @param evt Mouse event from one of the mouse adapters.
    183200     */
    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         }
     201    private void movePhoto(ImageEntry photo, ImageData data, MouseEvent evt) {
     202        LatLon newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY());
    194203        data.updateImagePosition(photo, newPos);
    195         // Re-display the photo because the OSD data might change (new
    196         // coordinates).  Or do that in doMouseReleased().
    197         //ImageViewerDialog.showImage(layer, photo);
     204    }
     205
     206    /**
     207     * Apply the given translation to the photo
     208     * @param photo The photo to move
     209     * @param translation the translation to apply
     210     */
     211    private void translatePhoto(ImageEntry photo, EastNorth translation) {
     212        final EastNorth startEN = photo.getPos().getEastNorth(ProjectionRegistry.getProjection());
     213        final EastNorth newPosEN = startEN.add(translation);
     214        final LatLon newPos = MainApplication.getMap().mapView.getProjection().eastNorth2latlon(newPosEN);
     215        photo.setPos(newPos);
     216        photo.flagNewGpsData();
    198217    }
    199218
  • applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java

    r34799 r35108  
    8787        @Override
    8888        public void actionPerformed(ActionEvent evt) {
    89             final ImageData data = getLayerWithSelectedImage().get().getImageData();
    90             final ImageEntry photo = data.getSelectedImage();
     89            final ImageData data = getLayerWithOneSelectedImage().get().getImageData();
     90            final ImageEntry photo = data.getSelectedImages().get(0);
    9191
    9292            StringBuilder title =
     
    117117         */
    118118        private static boolean enabled() {
    119             return getLayerWithSelectedImage().isPresent();
    120         }
    121 
    122         private static Optional<GeoImageLayer> getLayerWithSelectedImage() {
     119            return getLayerWithOneSelectedImage().isPresent();
     120        }
     121
     122        private static Optional<GeoImageLayer> getLayerWithOneSelectedImage() {
    123123            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();
    125125        }
    126126
Note: See TracChangeset for help on using the changeset viewer.