Ignore:
Timestamp:
2011-10-09T23:41:21+02:00 (14 years ago)
Author:
pieren
Message:

Add a new possibility to shift cadastre vector maps (not saved in cache)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java

    r24934 r26823  
    1212import java.awt.event.MouseListener;
    1313import java.awt.event.MouseMotionListener;
    14 import java.util.ArrayList;
    1514
    1615import javax.swing.JOptionPane;
     
    2221import org.openstreetmap.josm.data.coor.EastNorth;
    2322import org.openstreetmap.josm.tools.ImageProvider;
    24 import org.openstreetmap.josm.gui.layer.Layer;
    2523
    2624public class WMSAdjustAction extends MapMode implements
     
    2826
    2927    private static final long serialVersionUID = 1L;
    30     private ArrayList<WMSLayer> modifiedLayers = new ArrayList<WMSLayer>();
    31     WMSLayer selectedLayer;
     28    private WMSLayer modifiedLayer = null;
    3229    private boolean rasterMoved;
    3330    private EastNorth prevEastNorth;
     
    3835    public WMSAdjustAction(MapFrame mapFrame) {
    3936        super(tr("Adjust WMS"), "adjustxywms",
    40                         tr("Adjust the position of the WMS layer (raster images only)"), mapFrame,
     37                        tr("Adjust the position of the WMS layer (saved for raster images only)"), mapFrame,
    4138                        ImageProvider.getCursor("normal", "move"));
    4239    }
     
    4441    @Override public void enterMode() {
    4542        if (Main.map != null) {
    46             selectedLayer = null;
    47             WMSLayer possibleLayer = null;
    48             int cRasterLayers = 0;
    49             for (Layer l : Main.map.mapView.getAllLayers()) {
    50                 if (l instanceof WMSLayer && ((WMSLayer)l).isRaster()) {
    51                     possibleLayer = (WMSLayer)l;
    52                     cRasterLayers++;
    53                 }
    54             }
    55             Layer activeLayer = Main.map.mapView.getActiveLayer();
    56             if (activeLayer instanceof WMSLayer && ((WMSLayer)activeLayer).isRaster()) {
    57                 selectedLayer = (WMSLayer)activeLayer;
    58             } else if (cRasterLayers == 1) {
    59                 selectedLayer = possibleLayer;
    60             }
    61             if (selectedLayer != null) {
     43            if (Main.map.mapView.getActiveLayer() instanceof WMSLayer) {
     44                modifiedLayer = (WMSLayer)Main.map.mapView.getActiveLayer();
    6245                super.enterMode();
    6346                Main.map.mapView.addMouseListener(this);
    6447                Main.map.mapView.addMouseMotionListener(this);
    6548                rasterMoved = false;
    66                 selectedLayer.adjustModeEnabled = true;
     49                modifiedLayer.adjustModeEnabled = true;
    6750            } else {
    68                 JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n"
    69                         +"a cadastre \"plan image\" (raster image)"));
     51//                JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n"
     52//                        +"a cadastre layer"));
    7053                exitMode();
    7154                Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction());
     
    7861        Main.map.mapView.removeMouseListener(this);
    7962        Main.map.mapView.removeMouseMotionListener(this);
    80         if (rasterMoved && CacheControl.cacheEnabled) {
     63        if (rasterMoved && CacheControl.cacheEnabled && modifiedLayer.isRaster()) {
    8164            int reply = JOptionPane.showConfirmDialog(null,
    8265                    "Save the changes in cache ?",
     
    8770            }
    8871        }
    89         modifiedLayers.clear();
    90         if (selectedLayer != null) {
    91             selectedLayer.adjustModeEnabled = false;
    92             selectedLayer = null;
     72        rasterMoved = false;
     73        if (modifiedLayer != null) {
     74            modifiedLayer.adjustModeEnabled = false;
     75            modifiedLayer = null;
    9376        }
    9477    }
     
    10184        // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
    10285        boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
    103         if (shift && !ctrl)
     86        if (shift && !ctrl && modifiedLayer.isRaster())
    10487            mode = Mode.moveZ;
    105         else if (shift && ctrl)
     88        else if (shift && ctrl && modifiedLayer.isRaster())
    10689            mode = Mode.rotate;
    10790        else
     
    124107            prevEastNorth = newEastNorth;
    125108        }
    126         if (!modifiedLayers.contains(selectedLayer))
    127             modifiedLayers.add(selectedLayer);
    128109        Main.map.mapView.repaint();
    129110    }
     
    141122
    142123    private void displace(EastNorth start, EastNorth end) {
    143         selectedLayer.displace(end.east()-start.east(), end.north()-start.north());
     124        modifiedLayer.displace(end.east()-start.east(), end.north()-start.north());
    144125    }
    145126
    146127    private void resize(EastNorth newEastNorth) {
    147         EastNorth center = selectedLayer.getRasterCenter();
     128        EastNorth center = modifiedLayer.getRasterCenter();
    148129        double dPrev = prevEastNorth.distance(center.east(), center.north());
    149130        double dNew = newEastNorth.distance(center.east(), center.north());
    150         selectedLayer.resize(center, dNew/dPrev);
     131        modifiedLayer.resize(center, dNew/dPrev);
    151132    }
    152133
    153134    private void rotate(EastNorth start, EastNorth end) {
    154         EastNorth pivot = selectedLayer.getRasterCenter();
     135        EastNorth pivot = modifiedLayer.getRasterCenter();
    155136        double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north());
    156137        double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north());
    157138        double rotationAngle = endAngle - startAngle;
    158         selectedLayer.rotate(pivot, rotationAngle);
     139        modifiedLayer.rotate(pivot, rotationAngle);
    159140    }
    160141
    161142    private void rotateFrameOnly(EastNorth start, EastNorth end) {
    162143        if (start != null && end != null) {
    163             EastNorth pivot = selectedLayer.getRasterCenter();
     144            EastNorth pivot = modifiedLayer.getRasterCenter();
    164145            double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north());
    165146            double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north());
    166147            double rotationAngle = endAngle - startAngle;
    167             if (selectedLayer.getImage(0).orgCroppedRaster != null) {
     148            if (modifiedLayer.getImage(0).orgCroppedRaster != null) {
    168149                for (int i=0; i<4; i++) {
    169                     croppedRaster[i] = selectedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);
     150                    croppedRaster[i] = modifiedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);
    170151                }
    171152                croppedRaster[4] = croppedRaster[0];
     
    197178
    198179    private void saveModifiedLayers() {
    199         for (WMSLayer wmsLayer : modifiedLayers) {
    200             wmsLayer.grabThread.saveNewCache();
    201         }
     180            modifiedLayer.grabThread.saveNewCache();
    202181    }
    203182}
Note: See TracChangeset for help on using the changeset viewer.