Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java	(revision 18837)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java	(revision 18838)
@@ -106,8 +106,9 @@
                 // till here
 
-                if (reply == JOptionPane.OK_OPTION) {
-                    return loadCache(file, wmsLayer.getLambertZone());
-                } else
-                    file.delete();
+                if (reply == JOptionPane.OK_OPTION && loadCache(file, wmsLayer.getLambertZone())) {
+                    return true;
+                } else {
+                    delete(file);
+                }
             }
         } catch (Exception e) {
@@ -122,30 +123,36 @@
             if (Main.proj instanceof LambertCC9Zones)
                 extension = cLambertCC9Z + extension;
-            File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension);
-            if (file.exists())
-                file.delete();
+            delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension));
         } catch (Exception e) {
             e.printStackTrace(System.out);
         }
     }
+    
+    private void delete(File file) {
+        System.out.println("Delete file "+file);
+        if (file.exists())
+            file.delete();
+        while (file.exists()) // wait until file is really gone (otherwise appends to existing one)
+            CadastrePlugin.safeSleep(500);
+    }
 
     public boolean loadCache(File file, int currentLambertZone) {
+        boolean successfulRead = false;
         try {
             FileInputStream fis = new FileInputStream(file);
             ObjectInputStream ois = new ObjectInputStream(fis);
-            if (wmsLayer.read(ois, currentLambertZone) == false)
-                return false;
+            successfulRead = wmsLayer.read(ois, currentLambertZone);
             ois.close();
             fis.close();
         } catch (Exception ex) {
             ex.printStackTrace(System.out);
-            JOptionPane.showMessageDialog(Main.parent, tr("Error loading file"), tr("Error"), JOptionPane.ERROR_MESSAGE);
+            JOptionPane.showMessageDialog(Main.parent, tr("Error loading file.\nProbably an old version of the cache file."), tr("Error"), JOptionPane.ERROR_MESSAGE);
             return false;
         }
-        if (wmsLayer.isRaster()) {
+        if (successfulRead && wmsLayer.isRaster()) {
             // serialized raster bufferedImage hangs-up on Java6. Recreate them here
             wmsLayer.images.get(0).image = RasterImageModifier.fixRasterImage(wmsLayer.images.get(0).image);
         }
-        return true;
+        return successfulRead;
     }
 
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java	(revision 18837)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreInterface.java	(revision 18838)
@@ -182,5 +182,5 @@
             System.out.println("GET "+interfaceURL);
             BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
-            //while(in.readLine() != null) {}  // read the buffer otherwise we sent POST too early
+            // read the buffer otherwise we sent POST too early
             while ((ln = in.readLine()) != null) {
                 lines += ln;
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java	(revision 18837)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java	(revision 18838)
@@ -86,7 +86,8 @@
  *                   support of subprojections in preferences for zones setting and UTM20N
  *                 - removed autosourcing of empty new nodes
+ * 1.6 28-Nov-2009 - Fix minor issues if Grab is called without layer (possible since projection rework)
  */
 public class CadastrePlugin extends Plugin {
-    static String VERSION = "1.4";
+    static String VERSION = "1.6";
 
     static JMenu cadastreJMenu;
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java	(revision 18837)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java	(revision 18838)
@@ -8,5 +8,4 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
-import org.openstreetmap.josm.data.projection.LambertCC9Zones;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
@@ -32,9 +31,11 @@
         try {
             if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) {
+                boolean useFactor = true;
                 if (wmsLayer.images.isEmpty()) {
                     // first time we grab an image for this layer
                     if (CacheControl.cacheEnabled) {
                         if (wmsLayer.getCacheControl().loadCacheIfExist()) {
-                            Main.map.mapView.repaint();
+                            Main.map.mapView.zoomTo(wmsLayer.getCommuneBBox().toBounds());
+                            //Main.map.mapView.repaint();
                             return;
                         }
@@ -46,13 +47,14 @@
                         // set vectorized commune bounding box by opening the standard web window
                         grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer);
-                        // if it is the first layer, use the communeBBox as grab bbox
-                        if (Main.proj instanceof LambertCC9Zones && Main.map.mapView.getAllLayers().size() == 1 ) {
+                        // if it is the first layer, use the communeBBox as grab bbox (and not divided)
+                        if (Main.map.mapView.getAllLayers().size() == 1 ) {
                             bounds = wmsLayer.getCommuneBBox().toBounds();
                             Main.map.mapView.zoomTo(bounds);
+                            useFactor = false;
                         }
                     }
                 }
                 // grab new images from wms server into active layer
-                wmsLayer.grab(grabber, bounds);
+                wmsLayer.grab(grabber, bounds, useFactor);
             }
         } catch (DuplicateLayerException e) {
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java	(revision 18837)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrab.java	(revision 18838)
@@ -11,5 +11,4 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
-import org.openstreetmap.josm.data.projection.LambertCC9Zones;
 import org.openstreetmap.josm.tools.Shortcut;
 
@@ -30,7 +29,5 @@
 
     public void actionPerformed(ActionEvent e) {
-        // with the new projection LambertCC9Zones, we are able to determin the zone and thus lat/lon of 
-        // downloaded commune bounding box
-        if (Main.map != null || Main.proj instanceof LambertCC9Zones) {
+        if (Main.map != null) {
             if (CadastrePlugin.isCadastreProjection()) {
                 WMSLayer wmsLayer = WMSDownloadAction.getLayer();
@@ -43,5 +40,6 @@
                          + "projections and retry"));
             }
-        }
+        } else
+            new MenuActionNewLocation().actionPerformed(e);
     }
 
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java	(revision 18837)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java	(revision 18838)
@@ -36,69 +36,63 @@
 
     public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
-        /*if (Main.map == null) {
-            JOptionPane.showMessageDialog(Main.parent,
-                    tr("Open a layer first (GPX, OSM, cache)"));
+        String location = "";
+        String codeDepartement = "";
+        String codeCommune = "";
+        boolean resetCookie = false;
+        JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));
+        JPanel p = new JPanel(new GridBagLayout());
+        JLabel labelLocation = new JLabel(tr("Location"));
+        final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") );
+        inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>"
+                + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>"));
+
+        p.add(labelSectionNewLocation, GBC.eol());
+        p.add(labelLocation, GBC.std().insets(10, 0, 0, 0));
+        p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
+        JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public void selectInitialValue() {
+                inputTown.requestFocusInWindow();
+                inputTown.selectAll();
+            }
+        };
+        pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true);
+        if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
             return null;
-        } else {*/
-            String location = "";
-            String codeDepartement = "";
-            String codeCommune = "";
-            boolean resetCookie = false;
-            JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));
-            JPanel p = new JPanel(new GridBagLayout());
-            JLabel labelLocation = new JLabel(tr("Location"));
-            final JTextField inputTown = new JTextField( Main.pref.get("cadastrewms.location") );
-            inputTown.setToolTipText(tr("<html>Enter the town,village or city name.<br>"
-                    + "Use the syntax and punctuation known by www.cadastre.gouv.fr .</html>"));
 
-            p.add(labelSectionNewLocation, GBC.eol());
-            p.add(labelLocation, GBC.std().insets(10, 0, 0, 0));
-            p.add(inputTown, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
-            JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null) {
-                private static final long serialVersionUID = 1L;
-
-                @Override
-                public void selectInitialValue() {
-                    inputTown.requestFocusInWindow();
-                    inputTown.selectAll();
-                }
-            };
-            pane.createDialog(Main.parent, tr("Add new layer")).setVisible(true);
-            if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
-                return null;
-
-            WMSLayer wmsLayer = null;
-            if (!inputTown.getText().equals("")) {
-                location = inputTown.getText().toUpperCase();
-                resetCookie = true;
-                Main.pref.put("cadastrewms.location", location);
-                Main.pref.put("cadastrewms.codeCommune", codeCommune);
-                if (Main.map != null) {
-                    for (Layer l : Main.map.mapView.getAllLayers()) {
-                        if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) {
-                            return null;
-                        }
+        WMSLayer wmsLayer = null;
+        if (!inputTown.getText().equals("")) {
+            location = inputTown.getText().toUpperCase();
+            resetCookie = true;
+            Main.pref.put("cadastrewms.location", location);
+            Main.pref.put("cadastrewms.codeCommune", codeCommune);
+            if (Main.map != null) {
+                for (Layer l : Main.map.mapView.getAllLayers()) {
+                    if (l instanceof WMSLayer && l.getName().equalsIgnoreCase(location + codeDepartement)) {
+                        return null;
                     }
                 }
-                // add the layer if it doesn't exist
-                int zone = -1;
-                if (Main.proj instanceof LambertCC9Zones)
-                    zone = ((LambertCC9Zones)Main.proj).getLayoutZone();
-                else if (Main.proj instanceof Lambert)
-                    zone = ((Lambert)Main.proj).getLayoutZone();
-                else if (Main.proj instanceof UTM_20N_France_DOM)
-                    zone = ((UTM_20N_France_DOM)Main.proj).getCurrentGeodesic();
-                wmsLayer = new WMSLayer(location, codeCommune, zone);
-                Main.main.addLayer(wmsLayer);
-                System.out.println("Add new layer with Location:" + inputTown.getText());
-            } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) {
-                wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer();
-                resetCookie = true;
             }
+            // add the layer if it doesn't exist
+            int zone = -1;
+            if (Main.proj instanceof LambertCC9Zones)
+                zone = ((LambertCC9Zones)Main.proj).getLayoutZone();
+            else if (Main.proj instanceof Lambert)
+                zone = ((Lambert)Main.proj).getLayoutZone();
+            else if (Main.proj instanceof UTM_20N_France_DOM)
+                zone = ((UTM_20N_France_DOM)Main.proj).getCurrentGeodesic();
+            wmsLayer = new WMSLayer(location, codeCommune, zone);
+            Main.main.addLayer(wmsLayer);
+            System.out.println("Add new layer with Location:" + inputTown.getText());
+        } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) {
+            wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer();
+            resetCookie = true;
+        }
 
-            if (resetCookie)
-                CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName());
-            return wmsLayer;
-        //}
+        if (resetCookie)
+            CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookieIfNewLayer(wmsLayer.getName());
+        return wmsLayer;
     }
 
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 18837)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 18838)
@@ -100,10 +100,17 @@
 
     public void grab(CadastreGrabber grabber, Bounds b) throws IOException {
-        if (isRaster) {
-            b = new Bounds(Main.proj.eastNorth2latlon(rasterMin), Main.proj.eastNorth2latlon(rasterMax));
-            divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider",
-                    CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER)));
+        grab(grabber, b, true);
+    }
+    
+    public void grab(CadastreGrabber grabber, Bounds b, boolean useFactor) throws IOException {
+        if (useFactor) {
+            if (isRaster) {
+                b = new Bounds(Main.proj.eastNorth2latlon(rasterMin), Main.proj.eastNorth2latlon(rasterMax));
+                divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.rasterDivider",
+                        CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER)));
+            } else
+                divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString())));
         } else
-            divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString())));
+            divideBbox(b, 1);
 
         for (EastNorthBound n : dividedBbox) {
@@ -440,4 +447,5 @@
             }
         }
+        System.out.println("Cache loaded for location "+location+" with "+images.size()+" images");
         return true;
     }
