Ticket #11905: patch_multiple_image_plugin.patch

File patch_multiple_image_plugin.patch, 12.5 KB (added by francois2, 7 years ago)

Patch move multiple image in the photoadjust plugin v3.1

  • plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java

    Cannot display: file marked as a binary type.
    svn:mime-type = application/java-archive
     
    8383    @Override
    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.");
    8989        }
  • plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java

     
    11// License: GPL. For details, see LICENSE file.
    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;
    1313import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry;
     
    2323    // Offset between center of the photo and point where it is
    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;
    2929
     
    3333    public void reset() {
    3434        dragPhoto = null;
    3535        dragData = null;
    36         dragOffset = null;
     36        dragOffset = EastNorth.ZERO;
    3737    }
    3838
    3939    /**
     
    6565
    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
     68     * there is a photo selected on the map.  Alt+click positions the photo
    6969     * from the ImageViewerDialog.  Click without shift or control checks if
    7070     * there is a photo under the mouse.
    7171     *
     
    8080                && imageLayers != null && !imageLayers.isEmpty()) {
    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
     96                            // otherwise.  Alt+control changes direction, similar to
    9297                            // rotate in select mode.
    9398                            //
    9499                            // Combinations:
    95                             // S ... shift pressed
     100                            // A ... alt pressed
    96101                            // C ... control pressed
    97102                            // pos ... photo has a position set == is displayed on the map
    98103                            // nopos ... photo has no position set
    99104                            //
    100                             // S + pos: position at mouse
    101                             // S + nopos: position at mouse
     105                            // A + C + pos: position at mouse
     106                            // A + C + nopos: position at mouse
    102107                            // C + pos: change orientation
    103108                            // 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);
    109116                                }
    110                             } else { // shift pressed
    111                                 movePhoto(img, layer.getImageData(), evt);
     117                                dragPhoto = img;
    112118                            }
    113                             dragPhoto = img;
    114119                            dragData = layer.getImageData();
    115120                            break;
    116121                        }
     
    140145     */
    141146    public void doMouseReleased(MouseEvent evt) {
    142147        restoreCenterView();
    143         //if (dragLayer != null && dragPhoto != null) {
    144         //    // Re-display the photo to update the OSD.
    145         //    ImageViewerDialog.showImage(dragLayer, dragPhoto);
    146         //}
    147148    }
    148149
    149150    /**
     
    153154     */
    154155    public void doMouseDragged(MouseEvent evt) {
    155156        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                }
    158165            } else {
    159166                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();
    161179            }
    162180        }
    163181    }
     
    169187     * @param evt Mouse event from one of the mouse adapters.
    170188     */
    171189    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);
    175193    }
    176194
    177195    /**
     
    181199     * @param data ImageData of the photo.
    182200     * @param evt Mouse event from one of the mouse adapters.
    183201     */
    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());
    194204        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);
    198205    }
    199206
    200207    /**
     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    /**
    201222     * Set the image direction, i.e. let it point to where the mouse is.
    202223     *
    203224     * @param photo The photo to move.
  • plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java

     
    8686
    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 =
    9393                    new StringBuilder(tr("Edit Photo GPS Data"));
     
    116116         *         image shown, {@code false} otherwise.
    117117         */
    118118        private static boolean enabled() {
    119             return getLayerWithSelectedImage().isPresent();
     119            return getLayerWithOneSelectedImage().isPresent();
    120120        }
    121121
    122         private static Optional<GeoImageLayer> getLayerWithSelectedImage() {
     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
    127127        @Override
     
    157157            // ignored
    158158        }
    159159
    160         @Override
    161         public void selectedImageChanged(ImageData data) {
     160                @Override
     161                public void selectedImageChanged(ImageData data) {
    162162            this.updateEnabledState();
    163         }
     163                }
    164164    }
    165165
    166166    /**