Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastreGrabber.java	(revision 13784)
@@ -69,5 +69,6 @@
 		str += lambertMax.east() + ",";
 		str += lambertMax.north();
-		str += "&width=800&height=600"; // maximum allowed by wms server
+		//str += "&width=800&height=600"; // maximum allowed by wms server
+        str += "&width=1000&height=800"; // maximum allowed by wms server
 		str += "&styles=LS3_90,LS2_90,LS1_90,PARCELLE_90,NUMERO_90,PT3_90,PT2_90,PT1_90,LIEUDIT_90";
 		str += ",SUBSECTION_90";
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java	(revision 13784)
@@ -66,5 +66,7 @@
  * 0.9 05-Feb-2009 - grab vectorized full commune bbox, save in file, convert to OSM way
  *                   and simplify
- * 1.0 05-Feb-2009 - fix various bugs
+ * 1.0 18-Feb-2009 - fix various bugs in color management and preference dialog 
+ *                 - increase PNG picture size requested to WMS (800x1000)
+ *                 - set 4th grab scale fixed size configurable (from 25 to 1000 meters) 
  */
 public class CadastrePlugin extends Plugin {
@@ -87,6 +89,4 @@
     public static boolean alterColors = false;
     
-    public static String colorBackground;
-
     public static boolean backgroundTransparent = false;
     
@@ -103,10 +103,5 @@
      */
     public CadastrePlugin() throws Exception {
-        System.out.println("Pluging \"french cadastre\" started...");
-        if (Main.proj.toString().equals(new Lambert().toString()) != true) {
-            JOptionPane.showMessageDialog(Main.parent,
-                    tr("To enable the cadastre WMS plugin, change\nthe JOSM projection to Lambert and restart"));
-            return;
-        }
+        System.out.println("Pluging \"cadastre-fr\" started...");
         if (Main.pref.get("cadastrewms.cacheDir").equals(""))
             cacheDir = Main.pref.getPreferencesDir()+"plugins/cadastrewms/";
@@ -127,4 +122,5 @@
 
     public void refreshMenu() throws Exception {
+        boolean isLambertProjection = Main.proj.toString().equals(new Lambert().toString());
         JMenuBar menu = Main.main.menu;
 
@@ -133,35 +129,47 @@
             cadastreJMenu.setMnemonic(KeyEvent.VK_C);
             menu.add(cadastreJMenu, menu.getMenuCount()-2);
-            
-            JosmAction grab = new MenuActionGrab();
-            JMenuItem menuGrab = new JMenuItem(grab);
-            KeyStroke ks = grab.getShortcut().getKeyStroke();
-            if (ks != null) {
-                menuGrab.setAccelerator(ks);
+            if (isLambertProjection) {
+                JosmAction grab = new MenuActionGrab();
+                JMenuItem menuGrab = new JMenuItem(grab);
+                KeyStroke ks = grab.getShortcut().getKeyStroke();
+                if (ks != null) {
+                    menuGrab.setAccelerator(ks);
+                }
+                JMenuItem menuSettings = new JMenuItem(new MenuActionNewLocation());
+                final JCheckBoxMenuItem menuSource = new JCheckBoxMenuItem(tr("Auto sourcing"));
+                menuSource.setSelected(autoSourcing);     
+                menuSource.addActionListener(new ActionListener() {
+                    public void actionPerformed(ActionEvent ev) {
+                        Main.pref.put("cadastrewms.autosourcing", menuSource.isSelected());
+                        autoSourcing = menuSource.isSelected();
+                    }
+                });
+    
+                JMenuItem menuResetCookie = new JMenuItem(new MenuActionResetCookie());
+                JMenuItem menuLambertZone = new JMenuItem(new MenuActionLambertZone());
+                JMenuItem menuLoadFromCache = new JMenuItem(new MenuActionLoadFromCache());
+                //JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries());
+                //JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings());
+                
+                cadastreJMenu.add(menuGrab);
+                cadastreJMenu.add(menuSettings);
+                cadastreJMenu.add(menuSource);
+                cadastreJMenu.add(menuResetCookie);
+                cadastreJMenu.add(menuLambertZone);
+                cadastreJMenu.add(menuLoadFromCache);
+                // all SVG features disabled until official WMS is released
+                //cadastreJMenu.add(menuActionBoundaries); 
+                //cadastreJMenu.add(menuActionBuildings);
+            } else {
+                JMenuItem hint = new JMenuItem(tr("Invalid projection"));
+                hint.setToolTipText(tr("Change the projection to {0} first.", new Lambert().toString()));
+                hint.addActionListener(new ActionListener() {
+                    public void actionPerformed(ActionEvent ev) {
+                        JOptionPane.showMessageDialog(Main.parent,
+                                tr("To enable the cadastre WMS plugin, change\nthe JOSM projection to Lambert and restart"));
+                    }
+                });
+                cadastreJMenu.add(hint);
             }
-            JMenuItem menuSettings = new JMenuItem(new MenuActionNewLocation());
-            final JCheckBoxMenuItem menuSource = new JCheckBoxMenuItem(tr("Auto sourcing"));
-            menuSource.setSelected(autoSourcing);     
-            menuSource.addActionListener(new ActionListener() {
-                public void actionPerformed(ActionEvent ev) {
-                    Main.pref.put("cadastrewms.autosourcing", menuSource.isSelected());
-                    autoSourcing = menuSource.isSelected();
-                }
-            });
-
-            JMenuItem menuResetCookie = new JMenuItem(new MenuActionResetCookie());
-            JMenuItem menuLambertZone = new JMenuItem(new MenuActionLambertZone());
-            JMenuItem menuLoadFromCache = new JMenuItem(new MenuActionLoadFromCache());
-            JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries());
-            JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings());
-            
-            cadastreJMenu.add(menuGrab);
-            cadastreJMenu.add(menuSettings);
-            cadastreJMenu.add(menuSource);
-            cadastreJMenu.add(menuResetCookie);
-            cadastreJMenu.add(menuLambertZone);
-            cadastreJMenu.add(menuLoadFromCache);
-            cadastreJMenu.add(menuActionBoundaries);
-            //cadastreJMenu.add(menuActionBuildings);
         }
         setEnabledAll(menuEnabled);
@@ -174,5 +182,4 @@
         alterColors = Main.pref.getBoolean("cadastrewms.alterColors");
         drawBoundaries = Main.pref.getBoolean("cadastrewms.drawBoundaries", false);
-        colorBackground = Main.pref.get("color.background", "#FFFFFF");
         if (alterColors) {
             backgroundTransparent = Main.pref.getBoolean("cadastrewms.backgroundTransparent");
@@ -193,7 +200,7 @@
             JMenuItem item = cadastreJMenu.getItem(i);
             if (item != null)
-                if (item.getText().equals(MenuActionGrab.name) ||
+                if (item.getText().equals(MenuActionGrab.name) /* ||
                     item.getText().equals(MenuActionBoundaries.name) ||
-                    item.getText().equals(MenuActionBuildings.name)) {
+                    item.getText().equals(MenuActionBuildings.name)*/) {
                     item.setEnabled(isEnabled);
                 } else if (item.getText().equals(MenuActionLambertZone.name)) {
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java	(revision 13784)
@@ -3,5 +3,4 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -42,5 +41,8 @@
     
     private JRadioButton grabMultiplier4 = new JRadioButton("", true);
-    
+
+    static final int DEFAULT_SQUARE_SIZE = 100;
+    private JTextField grabMultiplier4Size = new JTextField(5);
+
     private JCheckBox enableCache = new JCheckBox(tr("Enable automatic caching."));
 
@@ -66,11 +68,4 @@
 
         // option to alter the original colors of the wms images
-        alterColors.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent e) {
-                reversGrey.setEnabled(alterColors.isSelected());
-                transparency.setEnabled(alterColors.isSelected());
-                sliderTrans.setEnabled(transparency.isSelected() && alterColors.isSelected());
-            }
-        });
         alterColors.setSelected(Main.pref.getBoolean("cadastrewms.alterColors", false));
         alterColors.setToolTipText(tr("Replace the original white background by the backgound color defined in JOSM preferences."));
@@ -79,7 +74,7 @@
         // option to reverse the grey colors (to see texts background)
         reversGrey.setSelected(Main.pref.getBoolean("cadastrewms.invertGrey", false));
-        reversGrey.setToolTipText(tr("Invert the original texts from black to white (and all intermediate greys)."));
+        reversGrey.setToolTipText(tr("Invert the original black and white colors (and all intermediate greys). Useful for texts on dark backgrounds."));
         reversGrey.setEnabled(alterColors.isSelected());
-        cadastrewms.add(reversGrey, GBC.eop().insets(20, 0, 0, 0));
+        cadastrewms.add(reversGrey, GBC.eop().insets(00, 0, 0, 0));
 
         // option to enable transparency
@@ -91,9 +86,7 @@
         transparency.setSelected(Main.pref.getBoolean("cadastrewms.backgroundTransparent", false));
         transparency.setToolTipText(tr("Allows multiple layers stacking"));
-        transparency.setEnabled(alterColors.isSelected());
-        cadastrewms.add(transparency, GBC.eop().insets(20, 0, 0, 0));
+        cadastrewms.add(transparency, GBC.eop().insets(0, 0, 0, 0));
 
         // slider for transparency level
-        sliderTrans.setPreferredSize(new Dimension(20,200));
         sliderTrans.setSnapToTicks(true);
         sliderTrans.setToolTipText(tr("Set WMS layers transparency. Right is opaque, left is transparent."));
@@ -114,30 +107,47 @@
         cadastrewms.add(jLabelScale, GBC.std().insets(0, 5, 10, 0));
         ButtonGroup bg = new ButtonGroup();
+        ActionListener multiplierActionListener = new ActionListener() {
+            public void actionPerformed(ActionEvent actionEvent) {
+              AbstractButton button = (AbstractButton) actionEvent.getSource();
+              grabMultiplier4Size.setEnabled(button == grabMultiplier4);
+            }
+          };
         grabMultiplier1.setIcon(ImageProvider.get("preferences", "unsel_box_1"));
         grabMultiplier1.setSelectedIcon(ImageProvider.get("preferences", "sel_box_1"));
+        grabMultiplier1.addActionListener( multiplierActionListener);
         grabMultiplier2.setIcon(ImageProvider.get("preferences", "unsel_box_2"));
         grabMultiplier2.setSelectedIcon(ImageProvider.get("preferences", "sel_box_2"));
+        grabMultiplier2.addActionListener( multiplierActionListener);
+        grabMultiplier2.setToolTipText(tr("Grab smaller images (higher quality but use more memory)"));
         grabMultiplier3.setIcon(ImageProvider.get("preferences", "unsel_box_3"));
         grabMultiplier3.setSelectedIcon(ImageProvider.get("preferences", "sel_box_3"));
+        grabMultiplier3.addActionListener( multiplierActionListener);
+        grabMultiplier3.setToolTipText(tr("Grab smaller images (higher quality but use more memory)"));
         grabMultiplier4.setIcon(ImageProvider.get("preferences", "unsel_box_4"));
         grabMultiplier4.setSelectedIcon(ImageProvider.get("preferences", "sel_box_4"));
-        String multiplierTooltip = "Grab smaller images (higher quality but use more memory)";
-        grabMultiplier3.setToolTipText(multiplierTooltip);
+        grabMultiplier4.addActionListener( multiplierActionListener);
+        grabMultiplier4.setToolTipText(tr("Fixed size square (default is 100m)"));
         bg.add(grabMultiplier1);
         bg.add(grabMultiplier2);
         bg.add(grabMultiplier3);
         bg.add(grabMultiplier4);
-        if (Main.pref.get("cadastrewms.scale", "1").equals(Scale.X1))
+        String currentScale = Main.pref.get("cadastrewms.scale", "1");
+        if (currentScale.equals(Scale.X1.value))
             grabMultiplier1.setSelected(true);
-        if (Main.pref.get("cadastrewms.scale", "1").equals(Scale.X2))
+        if (currentScale.equals(Scale.X2.value))
             grabMultiplier2.setSelected(true);
-        if (Main.pref.get("cadastrewms.scale", "1").equals(Scale.X3))
+        if (currentScale.equals(Scale.X3.value))
             grabMultiplier3.setSelected(true);
-        if (Main.pref.get("cadastrewms.scale", "1").equals(Scale.SQUARE_100M))
+        if (currentScale.equals(Scale.SQUARE_100M.value))
             grabMultiplier4.setSelected(true);
         cadastrewms.add(grabMultiplier1, GBC.std().insets(5, 0, 5, 0));
         cadastrewms.add(grabMultiplier2, GBC.std().insets(5, 0, 5, 0));
         cadastrewms.add(grabMultiplier3, GBC.std().insets(5, 0, 5, 0));
-        cadastrewms.add(grabMultiplier4, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 5, 0));
+        cadastrewms.add(grabMultiplier4, GBC.std().insets(5, 0, 5, 0));
+        int squareSize = getNumber("cadastrewms.squareSize", DEFAULT_SQUARE_SIZE);
+        grabMultiplier4Size.setText(String.valueOf(squareSize));
+        grabMultiplier4Size.setToolTipText(tr("Fixed size (from 25 to 1000 meters)"));
+        grabMultiplier4Size.setEnabled(currentScale.equals(Scale.SQUARE_100M.value));
+        cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
         
         // option to enable automatic caching
@@ -153,10 +163,5 @@
 
         // option to fix the cache size(in MB)
-        int size;
-        try {
-            size = Integer.parseInt(Main.pref.get("cadastrewms.cacheSize", String.valueOf(DEFAULT_CACHE_SIZE)));
-        } catch (NumberFormatException e) {
-            size = DEFAULT_CACHE_SIZE;
-        }
+        int size = getNumber("cadastrewms.cacheSize", DEFAULT_CACHE_SIZE);
         cacheSize.setText(String.valueOf(size));
         cacheSize.setToolTipText(tr("Oldest files are automatically deleted when this size is exceeded"));
@@ -182,6 +187,13 @@
         else if (grabMultiplier3.isSelected())
             Main.pref.put("cadastrewms.scale", Scale.X3.toString());
-        else
+        else {
             Main.pref.put("cadastrewms.scale", Scale.SQUARE_100M.toString());
+            try {
+                int squareSize = Integer.parseInt(grabMultiplier4Size.getText());
+                if (squareSize >= 25 && squareSize <= 1000)
+                    Main.pref.put("cadastrewms.squareSize", grabMultiplier4Size.getText());
+            } catch (NumberFormatException e) { // ignore the last input
+            }
+        }
         Main.pref.put("cadastrewms.enableCaching", enableCache.isSelected());
         
@@ -190,6 +202,5 @@
             CacheControl.cacheSize = Integer.parseInt(cacheSize.getText());
             Main.pref.put("cadastrewms.cacheSize", String.valueOf(CacheControl.cacheSize));
-        } catch (NumberFormatException e) {
-            // ignore the last input
+        } catch (NumberFormatException e) { // ignore the last input
         }
         CacheControl.cacheEnabled = enableCache.isSelected();
@@ -199,3 +210,10 @@
     }
 
+    private int getNumber(String pref_parameter, int def_value) {
+        try {
+            return Integer.parseInt(Main.pref.get(pref_parameter, String.valueOf(def_value)));
+        } catch (NumberFormatException e) {
+            return def_value;
+        }
+    }
 }
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java	(revision 13784)
@@ -16,5 +16,6 @@
 import java.util.Collection;
 import java.util.LinkedList;
-import java.util.List;
+
+import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
@@ -23,4 +24,5 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Way;
@@ -35,4 +37,5 @@
     private CadastreInterface wmsInterface;
     private String svg = null;
+    private static EastNorthBound currentView = null;
     private EastNorthBound viewBox = null;
     
@@ -49,8 +52,5 @@
         try {
             if (wmsInterface.retrieveInterface(wmsLayer)) {
-                MapView mv = Main.map.mapView;
-                EastNorthBound enb = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()),
-                        mv.getEastNorth(mv.getWidth(), 0));
-                svg = grabBoundary(enb);
+                svg = grabBoundary(currentView);
                 if (svg == null)
                     return;
@@ -58,5 +58,5 @@
                 if (viewBox == null)
                     return;
-                createWay(svg);
+                createBuildings(svg);
             }
         } catch (DuplicateLayerException e) {
@@ -89,9 +89,9 @@
      *  which path element is the best fitting to the viewBox and convert it to OSM objects
      */
-    private void createWay(String svg) {
-        String[] SVGpaths = new SVGParser().getPaths(svg);
+    private void createBuildings(String svg) {
+        String[] SVGpaths = new SVGParser().getClosedPaths(svg);
         ArrayList<ArrayList<EastNorth>> eastNorths = new ArrayList<ArrayList<EastNorth>>();
-        Collection<Node> existingNodes = Main.ds.nodes;
         
+        // convert SVG nodes to eastNorth coordinates 
         for (int i=0; i< SVGpaths.length; i++) {
             ArrayList<EastNorth> eastNorth = new ArrayList<EastNorth>();
@@ -100,34 +100,59 @@
                 eastNorths.add(eastNorth);
         }
-        List<Way> wayList = new ArrayList<Way>();
-        List<Node> nodeList = new ArrayList<Node>();
+
+        // create nodes and closed ways
+        DataSet svgDataSet = new DataSet();
         for (ArrayList<EastNorth> path : eastNorths) {
-            List<Node> tmpNodeList = new ArrayList<Node>();
             Way wayToAdd = new Way();
             for (EastNorth eastNorth : path) {
                 Node nodeToAdd = new Node(Main.proj.eastNorth2latlon(eastNorth));
                 // check if new node is not already created by another new path 
-                Node nearestNewNode = checkNearestNode(nodeToAdd, tmpNodeList); 
-                if (nearestNewNode == nodeToAdd) {
-                    // check if new node is not already in existing OSM objects
-                    nearestNewNode = checkNearestNode(nodeToAdd, existingNodes);
-                    if (nearestNewNode == nodeToAdd)
-                        tmpNodeList.add(nodeToAdd);
+                Node nearestNewNode = checkNearestNode(nodeToAdd, svgDataSet.nodes); 
+                if (nearestNewNode == nodeToAdd)
+                    svgDataSet.addPrimitive(nearestNewNode);
+                wayToAdd.nodes.add(nearestNewNode); // either a new node or an existing one
+            }
+            wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the way
+            svgDataSet.addPrimitive(wayToAdd);
+        }
+        
+        // TODO remove small boxes (4 nodes with less than 1 meter distance)
+        /*
+        for (Way w : svgDataSet.ways)
+            if (w.nodes.size() == 5)
+                for (int i = 0; i < w.nodes.size()-2; i++) {
+                    if (w.nodes.get(i).eastNorth.distance(w.nodes.get(i+1).eastNorth))
+                }*/
+
+        // simplify ways and check if we can reuse existing OSM nodes
+        for (Way wayToAdd : svgDataSet.ways)
+            new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5);
+        // check if the new way or its nodes is already in OSM layer
+        for (Node n : svgDataSet.nodes) {
+            Node nearestNewNode = checkNearestNode(n, Main.ds.nodes); 
+            if (nearestNewNode != n) {
+                // replace the SVG node by the OSM node
+                for (Way w : svgDataSet.ways) {
+                    int replaced = 0;
+                    for (Node node : w.nodes)
+                        if (node == n) {
+                            node = nearestNewNode;
+                            replaced++;
+                        }
+                    if (w.nodes.size() == replaced)
+                        w.delete(true);
                 }
-                wayToAdd.nodes.add(nearestNewNode); // either a new node or an existing one
-            }
-            // at least two nodes have to be new, otherwise the polygon is not new (duplicate)
-            if (tmpNodeList.size() > 1) {
-                for (Node n : tmpNodeList)
-                    nodeList.add(n);
-                wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the way
-                wayList.add(wayToAdd);
-            }
-        }
+                n.delete(true);
+            }
+                
+        }
+
         Collection<Command> cmds = new LinkedList<Command>();
-        for (Node node : nodeList)
-            cmds.add(new AddCommand(node));
-        for (Way way : wayList)
-            cmds.add(new AddCommand(way));
+        for (Node node : svgDataSet.nodes)
+            if (!node.deleted)
+                cmds.add(new AddCommand(node));
+        for (Way way : svgDataSet.ways)
+            if (!way.deleted)
+                cmds.add(new AddCommand(way));
         Main.main.undoRedo.add(new SequenceCommand(tr("Create buildings"), cmds));
         Main.map.repaint();
@@ -162,10 +187,9 @@
      */
     private Node checkNearestNode(Node nodeToAdd, Collection<Node> nodes) {
-        double epsilon = 0.01; // smallest distance considering duplicate node
+        double epsilon = 0.05; // smallest distance considering duplicate node
         for (Node n : nodes) {
             if (!n.deleted && !n.incomplete) {
                 double dist = n.eastNorth.distance(nodeToAdd.eastNorth);
                 if (dist < epsilon) {
-                    System.out.println("distance="+dist);
                     return n;
                 }
@@ -197,4 +221,5 @@
         str += bbox.max.north();
         str += "&width=800&height=600"; // maximum allowed by wms server
+        str += "&exception=application/vnd.ogc.se_inimage";
         str += "&styles=";
         str += "LS2_90";
@@ -231,4 +256,18 @@
 
     public static void download(WMSLayer wmsLayer) {
+        MapView mv = Main.map.mapView;
+        currentView = new EastNorthBound(mv.getEastNorth(0, mv.getHeight()),
+                mv.getEastNorth(mv.getWidth(), 0));
+        if ((currentView.max.east() - currentView.min.east()) > 1000 || 
+                (currentView.max.north() - currentView.min.north() > 1000)) {
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("To avoid cadastre WMS overload,\nbuilding import size is limited to 1 km2 max."));
+            return;
+        }
+        if (CadastrePlugin.autoSourcing == false) {
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("Please, enable auto-sourcing and check cadastre millesime."));
+            return;
+        }
         Main.worker.execute(new DownloadSVGBuilding(wmsLayer));
     }
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java	(revision 13784)
@@ -18,4 +18,6 @@
 import java.util.LinkedList;
 import java.util.List;
+
+import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
@@ -94,5 +96,5 @@
      */
     private void createWay(String svg) {
-        String[] SVGpaths = new SVGParser().getPaths(svg);
+        String[] SVGpaths = new SVGParser().getClosedPaths(svg);
         ArrayList<Double> fitViewBox = new ArrayList<Double>();  
         ArrayList<ArrayList<EastNorth>> eastNorths = new ArrayList<ArrayList<EastNorth>>();
@@ -116,5 +118,9 @@
         }
         wayToAdd.nodes.add(wayToAdd.nodes.get(0)); // close the circle
-        new SimplifyWay().simplifyWay(wayToAdd);
+        
+        // simplify the way
+        double threshold = Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0"));
+        new SimplifyWay().simplifyWay(wayToAdd, Main.ds, threshold);
+        
         cmds.add(new AddCommand(wayToAdd));
         Main.main.undoRedo.add(new SequenceCommand(tr("Create boundary"), cmds));
@@ -205,4 +211,9 @@
 
     public static void download(WMSLayer wmsLayer) {
+        if (CadastrePlugin.autoSourcing == false) {
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("Please, enable auto-sourcing and check cadastre millesime."));
+            return;
+        }
         Main.worker.execute(new DownloadSVGTask(wmsLayer));
     }
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java	(revision 13784)
@@ -16,7 +16,7 @@
 import java.io.Serializable;
 import javax.imageio.ImageIO;
+
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.gui.NavigatableComponent;
-import org.openstreetmap.josm.tools.ColorHelper;
 
 public class GeorefImage implements Serializable {
@@ -181,11 +181,7 @@
             int heightYMaskPixel = Math.abs((int) ((maxMaskNorth - minMaskNorth) / pixelPerNorth));
             Graphics g = image.getGraphics();
-            int josmBackgroundColor = ColorHelper.html2color(CadastrePlugin.colorBackground).getRGB();
             for (int x = minXMaskPixel; x < minXMaskPixel + widthXMaskPixel; x++)
                 for (int y = minYMaskPixel; y < minYMaskPixel + heightYMaskPixel; y++)
-                    if (CadastrePlugin.alterColors)
-                        image.setRGB(x, y, josmBackgroundColor);
-                    else
-                        image.setRGB(x, y, ImageModifier.cadastreBackground);
+                    image.setRGB(x, y, ImageModifier.cadastreBackgroundTransp);
             g.dispose();
         }
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java	(revision 13784)
@@ -18,4 +18,6 @@
     public static final int cadastreBackground = -1; // white
 
+    public static final int cadastreBackgroundTransp = 1; // original white but transparent 
+
     public BufferedImage bufferedImage;
 
@@ -28,26 +30,23 @@
     public ImageModifier(BufferedImage bi) {
         bufferedImage = bi;
-        if (Main.pref.getBoolean("cadastrewms.alterColors")) {
-            changeColors();
-            if (Main.pref.getBoolean("cadastrewms.backgroundTransparent")) {
-                makeTransparent();
-            }
-        }
+        if (Main.pref.getBoolean("cadastrewms.backgroundTransparent"))
+            makeTransparent();
+        else if (Main.pref.getBoolean("cadastrewms.alterColors"))
+            replaceBackground();
+        
+        if (Main.pref.getBoolean("cadastrewms.invertGrey"))
+            invertGrey();
     }
 
     /**
      * Replace the background color by the josm color.background color.
-     * @param bi
-     * @return
      */
-    private void changeColors() {
+    private void replaceBackground() {
         int w = bufferedImage.getWidth();
         int h = bufferedImage.getHeight();
-        int pixel;
-        int josmBackgroundColor = ColorHelper.html2color(Main.pref.get("color.background", "#FFFFFF")).getRGB();
-        boolean invertGrey = (Main.pref.getBoolean("cadastrewms.invertGrey"));
+        int josmBackgroundColor = ColorHelper.html2color(Main.pref.get("color.background", "#000000")).getRGB();
         for (int x = 0; x < w; x++) {
             for (int y = 0; y < h; y++) {
-                pixel = bufferedImage.getRGB(x, y);
+                int pixel = bufferedImage.getRGB(x, y);
                 if (pixel == cadastreBackground) {
                     bufferedImage.setRGB(x, y, josmBackgroundColor);
@@ -56,5 +55,19 @@
                     backgroundSampleX = x;
                     backgroundSampleY = y;
-                } else if (invertGrey) {
+                }
+            }
+        }
+    }
+    
+    /**
+     * Invert black/white/grey pixels (to change original black characters to white).
+     */
+    private void invertGrey() {
+        int w = bufferedImage.getWidth();
+        int h = bufferedImage.getHeight();
+        for (int x = 0; x < w; x++) {
+            for (int y = 0; y < h; y++) {
+                int pixel = bufferedImage.getRGB(x, y);
+                if (pixel != cadastreBackground) {
                     bufferedImage.setRGB(x, y, reverseIfGrey(pixel));
                 }
@@ -62,5 +75,5 @@
         }
     }
-    
+
     /**
      * Reverse the grey value if the pixel is grey (light grey becomes dark grey)
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SVGParser.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SVGParser.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SVGParser.java	(revision 13784)
@@ -14,5 +14,5 @@
     private String cViewBoxEnd = "\"";
     private String cPathStart = "<path d=\"";
-    private String cPathEnd = "\"/>";
+    private String cClosedPathEnd = "\"/>";
 
     /**
@@ -40,12 +40,19 @@
     }
     
-    public String [] getPaths(String svg) {
+    /**
+     * Closed SVG paths are finishing with a "Z" at the end of the moves list.
+     * @param svg
+     * @return
+     */
+    public String [] getClosedPaths(String svg) {
         ArrayList<String> path = new ArrayList<String>();
         int i = 0;
         while (svg.indexOf(cPathStart, i) != -1) {
             int s = svg.indexOf(cPathStart, i) + cViewBoxStart.length();
-            int e = svg.indexOf(cPathEnd, s);
+            int e = svg.indexOf(cClosedPathEnd, s);
             if (s != -1 && e != -1) {
-                path.add(svg.substring(s, e));
+                String onePath = svg.substring(s, e); 
+                if (onePath.indexOf("Z") != -1) // only closed SVG path
+                    path.add(onePath);
             } else
                 break;
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/SimplifyWay.java	(revision 13784)
@@ -12,4 +12,5 @@
 import org.openstreetmap.josm.command.DeleteCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Way;
@@ -23,12 +24,10 @@
  */
 public class SimplifyWay {
-    public void simplifyWay(Way w) {
-        double threshold = Double.parseDouble(Main.pref.get("simplify-way.max-error", "3"));
-
+    public void simplifyWay(Way w, DataSet dataSet, double threshold) {
         Way wnew = new Way(w);
 
         int toI = wnew.nodes.size() - 1;
         for (int i = wnew.nodes.size() - 1; i >= 0; i--) {
-            CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(Main.ds, false);
+            CollectBackReferencesVisitor backRefsV = new CollectBackReferencesVisitor(dataSet, false);
             backRefsV.visit(wnew.nodes.get(i));
             boolean used = false;
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java	(revision 13784)
@@ -41,5 +41,5 @@
                 return new MenuActionNewLocation().addNewLayer(existingWMSlayers);
             JOptionPane.showMessageDialog(Main.parent,
-                    tr("More than one WMS layer present.\nSelect one of them first, then retry."));
+                    tr("More than one WMS layer present\nSelect one of them first, then retry"));
         }
         return null;
Index: /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 13783)
+++ /applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java	(revision 13784)
@@ -162,5 +162,5 @@
         } else {
             // divide to fixed size squares
-            int cSquare = 100; // expressed in meters in projection Lambert
+            int cSquare = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100"));
             minEast = minEast - minEast % cSquare;
             minNorth = minNorth - minNorth % cSquare;
