This is an automated email from the git hooks/post-receive script.

sebastic-guest pushed a commit to branch master
in repository josm-plugins.

commit edd9e2cf4587593291aea257c15f4f2134e075ce
Author: Giovanni Mascellani <mascell...@poisson.phc.unipi.it>
Date:   Fri May 14 18:16:57 2010 +0200

    Imported Upstream version 0.0.svn20981
---
 DirectUpload/README                                |   1 -
 .../plugins/DirectUpload/UploadDataGuiPlugin.java  |  12 +-
 cadastre-fr/build.xml                              |   2 +-
 cadastre-fr/images/mapmode/buildings.png           | Bin 0 -> 187 bytes
 cadastre-fr/src/cadastre_fr/Buildings.java         | 656 +++++++++++++++++++++
 .../src/cadastre_fr/BuildingsImageModifier.java    |  21 +
 cadastre-fr/src/cadastre_fr/CacheControl.java      |  72 +--
 .../src/cadastre_fr/CacheFileUTM20NFilter.java     |   3 +-
 cadastre-fr/src/cadastre_fr/CadastreGrabber.java   |  55 +-
 cadastre-fr/src/cadastre_fr/CadastreInterface.java |  17 +-
 cadastre-fr/src/cadastre_fr/CadastrePlugin.java    |  94 +--
 .../src/cadastre_fr/CadastrePreferenceSetting.java |  11 +-
 .../src/cadastre_fr/DownloadSVGBuilding.java       |  12 +-
 cadastre-fr/src/cadastre_fr/DownloadSVGTask.java   |  11 +-
 .../src/cadastre_fr/DownloadWMSPlanImage.java      |   9 +-
 .../src/cadastre_fr/DownloadWMSVectorImage.java    |  25 +-
 cadastre-fr/src/cadastre_fr/GeorefImage.java       |   2 +-
 cadastre-fr/src/cadastre_fr/ImageModifier.java     |  55 ++
 .../src/cadastre_fr/MenuActionBuildings.java       |  26 +-
 cadastre-fr/src/cadastre_fr/MenuActionGrab.java    |   2 +-
 .../src/cadastre_fr/MenuActionLoadFromCache.java   |  10 +-
 .../src/cadastre_fr/MenuActionNewLocation.java     |  12 +-
 cadastre-fr/src/cadastre_fr/SimplifyWay.java       |  54 +-
 .../src/cadastre_fr/VectorImageModifier.java       |   7 +-
 cadastre-fr/src/cadastre_fr/WMSDownloadAction.java |  24 +-
 cadastre-fr/src/cadastre_fr/WMSException.java      |  14 +
 cadastre-fr/src/cadastre_fr/WMSLayer.java          |  93 ++-
 livegps/build.xml                                  |  18 +-
 livegps/src/livegps/AppendableGpxTrackSegment.java |   5 +
 livegps/src/livegps/LiveGpsAcquirer.java           |   3 +-
 livegps/src/livegps/LiveGpsLayer.java              |   1 -
 livegps/src/livegps/LiveGpsPlugin.java             |   1 -
 livegps/src/livegps/SingleSegmentGpxTrack.java     |   5 +
 svn-info.xml                                       |   8 +-
 wmsplugin/build.xml                                |   2 +-
 wmsplugin/src/wmsplugin/WMSGrabber.java            |   5 +-
 36 files changed, 1105 insertions(+), 243 deletions(-)

diff --git a/DirectUpload/README b/DirectUpload/README
index e718dcd..65248fc 100644
--- a/DirectUpload/README
+++ b/DirectUpload/README
@@ -1,4 +1,3 @@
 Directly uploads GPX from active layer in JOSM to OpenStreetMap Server.
-This currently uses OSM Api 0.5.
 
 More Details and FAQ's at : 
http://wiki.openstreetmap.org/index.php/User:Subhodip/GSoC_Doc#DirectUpload_Plugin_in_JOSM_:
diff --git 
a/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGuiPlugin.java
 
b/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGuiPlugin.java
index 7dfad2c..2473982 100644
--- 
a/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGuiPlugin.java
+++ 
b/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGuiPlugin.java
@@ -10,6 +10,7 @@ import static org.openstreetmap.josm.tools.I18n.tr;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
+import java.util.List;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
@@ -43,7 +44,8 @@ public class UploadDataGuiPlugin extends Plugin{
 
         @Override
                protected void updateEnabledState() {
-            if(Main.map == null
+               // enable button if there is "one active GpxLayer" or "exactly 
one GpxLayer in the list of all layers available"
+               if(Main.map == null
                     || Main.map.mapView == null
                     || Main.map.mapView.getActiveLayer() == null
                     || !(Main.map.mapView.getActiveLayer() instanceof 
GpxLayer)) {                
@@ -52,6 +54,12 @@ public class UploadDataGuiPlugin extends Plugin{
                setEnabled(true);
             }
 
-               }               
+            if(Main.map != null && Main.map.mapView.getNumLayers() > 1) {
+                List<GpxLayer> list = 
Main.map.mapView.getLayersOfType(GpxLayer.class);
+                if (list.size() == 1)
+                    setEnabled(true);
+            }
+
+        }              
     }
 }
\ No newline at end of file
diff --git a/cadastre-fr/build.xml b/cadastre-fr/build.xml
index ec7cc5c..785ab37 100644
--- a/cadastre-fr/build.xml
+++ b/cadastre-fr/build.xml
@@ -33,7 +33,7 @@
        
 
        <property name="commit.message" value="Changed constructor for Plugin" 
/>
-       <property name="plugin.main.version" value="2830" />
+       <property name="plugin.main.version" value="3174" />
        
     <target name="init">
         <mkdir dir="${plugin.build.dir}"/>
diff --git a/cadastre-fr/images/mapmode/buildings.png 
b/cadastre-fr/images/mapmode/buildings.png
new file mode 100644
index 0000000..644765f
Binary files /dev/null and b/cadastre-fr/images/mapmode/buildings.png differ
diff --git a/cadastre-fr/src/cadastre_fr/Buildings.java 
b/cadastre-fr/src/cadastre_fr/Buildings.java
new file mode 100644
index 0000000..598a8de
--- /dev/null
+++ b/cadastre-fr/src/cadastre_fr/Buildings.java
@@ -0,0 +1,656 @@
+package cadastre_fr;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.Color;
+import java.awt.Point;
+import java.awt.event.ActionEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.swing.JOptionPane;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.actions.mapmode.MapMode;
+import org.openstreetmap.josm.command.AddCommand;
+import org.openstreetmap.josm.command.ChangeCommand;
+import org.openstreetmap.josm.command.ChangePropertyCommand;
+import org.openstreetmap.josm.command.Command;
+import org.openstreetmap.josm.command.MoveCommand;
+import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.BBox;
+import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.WaySegment;
+import org.openstreetmap.josm.tools.ImageProvider;
+import org.openstreetmap.josm.tools.Shortcut;
+import org.openstreetmap.josm.gui.layer.Layer;
+
+/**
+ * Trace a way around buildings from cadastre images. 
+ * Inspired by Lakewalker plugin.
+ * @author Pieren
+ */
+public class Buildings extends MapMode implements MouseListener, 
MouseMotionListener {
+    
+    private static final long serialVersionUID = 1L;
+    GeorefImage selectedImage;
+    WMSLayer selectedLayer;
+    private EastNorth clickedEastNorth;
+    private class Pixel {
+        public Point p;
+        public int dir;
+        @SuppressWarnings("unused")
+        public boolean toKeep;
+        public Pixel(int x, int y, int dir) {
+            this.p = new Point(x,y);
+            this.dir = dir;
+        }
+        @Override
+        public int hashCode() {
+            return p.hashCode();
+        }
+        @Override
+        public boolean equals(Object obj) {
+            if (obj instanceof Pixel)
+                return p.equals(new Point(((Pixel)obj).p.x, ((Pixel)obj).p.y));
+            return p.equals(obj);
+        }
+        @Override
+        public String toString() {
+            return new String("p="+p+", dir="+dir);
+        }
+    }
+    private ArrayList<Pixel> listPixels = new ArrayList<Pixel>();
+    
+    //  5 6 7
+    //   \|/ 
+    //  4-*-0       'dir' index vs pixel direction
+    //   /|\
+    //  3 2 1
+    private int[] dirsX = new int[] {1,1,0,-1,-1,-1,0,1};
+    private int[] dirsY = new int[] {0,1,1,1,0,-1,-1,-1};
+
+    private int orange = Color.ORANGE.getRGB(); // new color of pixels ending 
nowhere (cul-de-sac)
+    BuildingsImageModifier bim = new BuildingsImageModifier();
+
+    private static final int cMaxnode = 10000;
+    private static final double cDistanceForOptimization = 0.5;
+    private double snapDistance = 
Main.pref.getDouble("cadastrewms.snap-distance", 25); // in centimeters
+    private double SimplifyFactor = 0.1;
+
+    private double snapDistanceSq = snapDistance*snapDistance;
+    private double dx, dy;
+    
+    public Buildings(MapFrame mapFrame) {
+        super(tr("Grab buildings"), "buildings",
+                        tr("Extract building on click (vector images only)"),
+                        Shortcut.registerShortcut("mapmode:buildings", 
tr("Mode: {0}", tr("Buildings")), KeyEvent.VK_E, Shortcut.GROUP_EDIT),
+                        mapFrame, ImageProvider.getCursor("normal", "move"));
+    }
+
+    @Override public void enterMode() {
+        super.enterMode();
+        boolean atLeastOneBuildingLayer = false;
+        for (Layer layer : Main.map.mapView.getAllLayers()) {
+            if (layer instanceof WMSLayer && 
((WMSLayer)layer).isBuildingsOnly()) {
+                atLeastOneBuildingLayer = true;
+                break;
+            }
+        }
+        if (atLeastOneBuildingLayer && Main.main.getCurrentDataSet() != null) {
+            Main.map.mapView.addMouseListener(this);
+            Main.map.mapView.addMouseMotionListener(this);
+        } else {
+            JOptionPane.showMessageDialog(Main.parent,tr("This feature 
requires (at least) one special cadastre\nBuildings layer and an OSM data 
layer."));
+            exitMode();
+            Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction());
+        }
+    }
+
+    @Override public void exitMode() {
+        super.exitMode();
+        Main.map.mapView.removeMouseListener(this);
+        Main.map.mapView.removeMouseMotionListener(this);
+    }
+
+    @Override
+    public void mousePressed(MouseEvent e) {
+        if (e.getButton() != MouseEvent.BUTTON1)
+            return;
+        selectedImage = null;
+        // ctrl = do not merge the new polygon with adjacent elements
+        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
+        // shift = do not use the parcel as a separator
+        boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
+        // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
+        for (Layer layer : Main.map.mapView.getAllLayers()) {
+            if (layer.isVisible() && layer instanceof WMSLayer && 
((WMSLayer)layer).isBuildingsOnly() ) {
+                clickedEastNorth = Main.map.mapView.getEastNorth(e.getX(), 
e.getY());
+                selectedLayer = ((WMSLayer) layer);
+                selectedImage = selectedLayer.findImage(clickedEastNorth);
+            }
+        }
+        if (selectedImage != null) {
+            int x = (int)((clickedEastNorth.east() - 
selectedImage.min.east())*selectedImage.getPixelPerEast());
+            int y = selectedImage.image.getHeight() - 
(int)((clickedEastNorth.north() - 
selectedImage.min.north())*selectedImage.getPixelPerNorth());
+            int rgb = selectedImage.image.getRGB(x, y);
+            System.out.println("image found"+", x="+x+", y="+y+", RGB="+rgb);
+            boolean clickOnRoof = bim.isRoofColor(rgb, shift);
+            boolean clickOnBuilding = bim.isBuildingColor(rgb, shift);
+            if (clickOnRoof || clickOnBuilding) {
+                if (traceBuilding(x, y, clickOnBuilding, shift) && 
listPixels.size() > 3) {
+                    Way wayToCreate = new Way();
+                    Way way2 = new Way();
+                    double pPE = selectedImage.getPixelPerEast();
+                    double pPN = selectedImage.getPixelPerNorth();
+                    for (int i=0; i < listPixels.size(); i++) {
+                        EastNorth en = new EastNorth(selectedImage.min.east() 
+ ((listPixels.get(i).p.x + 0.5)/ pPE),
+                                selectedImage.max.north() - 
((listPixels.get(i).p.y + 0.5)/ pPN));
+                        Node nodeToAdd = new 
Node(Main.proj.eastNorth2latlon(en));
+                        wayToCreate.addNode(nodeToAdd);
+                    }
+                    wayToCreate.addNode(wayToCreate.getNode(0)); // close the 
way
+                    new SimplifyWay().simplifyWay(wayToCreate, SimplifyFactor);
+                    // move the node closing the loop and simplify again
+                    for (int i = 1; i < wayToCreate.getNodesCount(); i++) {
+                        way2.addNode(wayToCreate.getNode(i));
+                    }
+                    way2.addNode(way2.getNode(0));
+                    new SimplifyWay().simplifyWay(way2, SimplifyFactor);
+                    simplifyAngles(way2);
+                    Way wayToAdd = new Way();
+                    Collection<Command> cmds = new LinkedList<Command>();
+                    if (ctrl) {
+                        for (int i = 0; i < way2.getNodesCount()-1; i++) {
+                            wayToAdd.addNode(way2.getNode(i));
+                            cmds.add(new AddCommand(wayToAdd.getNode(i)));
+                        }
+                        wayToAdd.addNode(wayToAdd.getNode(0)); // close the 
polygon !
+                    } else {
+                        for (int i = 0; i < way2.getNodesCount()-1; i++) {
+                            Node nearestNode = getNearestNode(way2.getNode(i));
+                            if (nearestNode == null) {
+                                // check if we can join new node to existing 
ways
+                                List<WaySegment> wss = 
getNearestWaySegments(way2.getNode(i));
+                                wayToAdd.addNode(way2.getNode(i));
+                                cmds.add(new AddCommand(way2.getNode(i)));
+                                if (wss.size() > 0) {
+                                    cmds.add(new MoveCommand(way2.getNode(i), 
dx, dy));
+                                    joinNodeToExistingWays(wss, 
way2.getNode(i), cmds);
+                                }
+                            } else {
+                                // replace new node by an existing nearest node
+                                wayToAdd.addNode(nearestNode);
+                                cmds.add(new MoveCommand(nearestNode, dx, dy));
+                            }
+                        }
+                        wayToAdd.addNode(wayToAdd.getNode(0)); // close the 
polygon !
+                        for (int i = 1; i < wayToAdd.getNodesCount(); i++) {
+                            Node nodeToJoin = 
existingNodesInNewSegment(wayToAdd.getNode(i-1), wayToAdd.getNode(i), wayToAdd);
+                            // check if we join new way to existing nodes
+                            if (nodeToJoin != null) {
+                                List<WaySegment> wss = new 
LinkedList<WaySegment>();
+                                wss.add(new WaySegment(wayToAdd, i-1));
+                                wayToAdd = joinNodeToExistingWays(wss, 
nodeToJoin, cmds);
+                                cmds.add(new MoveCommand(nodeToJoin, dx, dy));
+                                i--; // re-assess the new segment (perhaps 
several nodes to join)
+                            }
+                        }
+                    }
+                    cmds.add(new AddCommand(wayToAdd));
+                    if (clickOnBuilding)
+                        addBuildingTags(cmds, wayToAdd);
+                    if (clickOnRoof) {
+                        addRoofTags(cmds, wayToAdd);
+                    }
+                    Main.main.undoRedo.add(new SequenceCommand(tr("Create 
building"), cmds));
+                    getCurrentDataSet().setSelected(wayToAdd);
+                    Main.map.repaint();
+                }
+            }
+        }
+    }
+    
+    @Override public void mouseDragged(MouseEvent e) {
+    }
+
+    @Override public void mouseReleased(MouseEvent e) {
+    }
+
+    public void mouseEntered(MouseEvent e) {
+    }
+    public void mouseExited(MouseEvent e) {
+    }
+    public void mouseMoved(MouseEvent e) {
+    }
+
+    @Override public void mouseClicked(MouseEvent e) {
+    }
+    
+    private void addBuildingTags(Collection<Command> cmds, Way wayToAdd) {
+        cmds.add(new ChangePropertyCommand(wayToAdd, "building", "yes"));
+    }
+    
+    private void addRoofTags(Collection<Command> cmds, Way wayToAdd) {
+        cmds.add(new ChangePropertyCommand(wayToAdd, "building", "yes"));
+        cmds.add(new ChangePropertyCommand(wayToAdd, "wall", "no"));
+    }
+    
+    private boolean traceBuilding (int x, int y, boolean buildingColors, 
boolean ignoreParcels) {
+        // search start point at same x but smallest y (upper border on the 
screen)
+        int startY = 0; int startX = x;
+        while (y > 0) {
+            y--;
+            if (!bim.isBuildingOrRoofColor(selectedImage.image, x, y, 
buildingColors, ignoreParcels)) {
+                System.out.println("at "+x+","+y+" color was 
"+selectedImage.image.getRGB(x,y));
+                y++;
+                startY = y;
+                break;
+            }
+        }
+        if (startY == 0) {
+            System.out.println("border not found");
+            return false;
+        } else
+            System.out.println("start at x="+startX+", y="+startY);
+        listPixels.clear();
+        int test_x = 0;
+        int test_y = 0;
+        int new_dir = 0;
+        addPixeltoList(x, y, new_dir);
+        int last_dir = 1;
+        for(int i = 0; i < cMaxnode; i++){
+            //System.out.println("node "+i);
+            for(int d = 1; d <= this.dirsY.length; d++){
+                new_dir = (last_dir + d + 4) % 8;
+                test_x = x + this.dirsX[new_dir];
+                test_y = y + this.dirsY[new_dir];
+                if (test_x < 0 || test_x >= selectedImage.image.getWidth() ||
+                        test_y < 0 || test_y >= 
selectedImage.image.getHeight()){
+                    System.out.println("Outside image");
+                    return false;
+                }
+                if (bim.isBuildingOrRoofColor(selectedImage.image, test_x, 
test_y, buildingColors, ignoreParcels)){
+                    System.out.println("building color at 
"+test_x+","+test_y+" new_dir="+new_dir);
+                    break;
+                }
+
+                if(d == this.dirsY.length-1){
+                    System.out.println("Got stuck at "+x+","+y);
+                    // cul-de-sac : disable current pixel and move two steps 
back
+                    selectedImage.image.setRGB(x, y, orange);
+                    if (removeTwoLastPixelsFromList()) {
+                        x = listPixels.get(listPixels.size()-1).p.x;
+                        y = listPixels.get(listPixels.size()-1).p.y;
+                        last_dir = listPixels.get(listPixels.size()-1).dir; 
+                        System.out.println("return at "+x+","+y+" and try 
again");
+                        d = 1;
+                        continue;
+                    } else {
+                        System.out.println("cannot try another way");
+                        return false;
+                    }
+                }
+            }
+//            if (last_dir == new_dir)
+//                // Same direction. First simplification by removing previous 
pixel.
+//                listPixels.remove(listPixels.size()-1);
+            last_dir = new_dir;
+            // Set the pixel we found as current
+            x = test_x;
+            y = test_y;
+            // Break the loop if we managed to get back to our starting point
+            if (x == startX && y == startY) {
+                System.out.println("loop closed at "+x+","+y+", exit");
+                break;
+            } else if (listPixels.contains(new Pixel(x, y, 0))){
+                int j = listPixels.indexOf(new Pixel(x, y, 0));
+                int l = listPixels.size();
+                for (int k = j; k < l; k++)
+                    listPixels.remove(j);
+            }
+            addPixeltoList(x, y, new_dir);
+        }
+        inflate();
+        System.out.println("list size="+listPixels.size());
+        return true;
+    }
+    
+    private void addPixeltoList(int x, int y, int dir) {
+        listPixels.add( new Pixel(x, y, dir));
+        System.out.println("added pixel at "+x+","+y);
+    }
+    
+    private void inflate() {
+        // TODO
+        if (listPixels.size() > 1) {
+//            for (int i=1; i<listPixels.size()-1; i++) {
+//                int delta_dir = Math.abs((listPixels.get(i+1).dir - 
listPixels.get(i-1).dir + 8)%8);
+//                if (delta_dir > 1 && delta_dir < 4) {
+//                    System.out.println(listPixels.get(i).dir);
+//                    int j = i;
+//                    if (listPixels.get(i).dir == 0 || listPixels.get(i).dir 
== 1 || listPixels.get(i).dir == 4 || listPixels.get(i).dir == 2)
+//                        j = i-1;
+//                    listPixels.get(j).toKeep = true;
+//                    i+=2;
+//                    selectedImage.image.setRGB(listPixels.get(j).p.x, 
listPixels.get(j).p.y, Color.GREEN.getRGB());
+//                }
+//            }
+            ArrayList<Pixel> newList = new ArrayList<Pixel>();
+            for (int i=0; i<listPixels.size(); i++) {
+//                    selectedImage.image.setRGB(listPixels.get(i).p.x, 
listPixels.get(i).p.y, Color.GREEN.getRGB());
+                boolean inflatedPixel = false;
+                for (int j=0; j<3; j++) {
+                    if ((i+j-1) > 0 && (i+j-1) < listPixels.size()) {
+                        int inflate_dir = (listPixels.get(i+j-1).dir+6)%8;
+                        Pixel p = new 
Pixel(listPixels.get(i).p.x+dirsX[inflate_dir],
+                              listPixels.get(i).p.y+dirsY[inflate_dir],
+                              listPixels.get(i).dir);
+                        if (bim.isParcelColor(selectedImage.image, p.p.x, 
p.p.y)) {
+                            if (!newList.contains(p))
+                                newList.add(p);
+                            inflatedPixel = true;
+                        } 
+                    }
+                }
+                if (!inflatedPixel) {
+                    if (!newList.contains(listPixels.get(i)))
+                        newList.add(listPixels.get(i));
+                }
+            }
+            listPixels = newList;
+        }
+    }
+    
+    private boolean removeTwoLastPixelsFromList() {
+        if (listPixels.size() > 2) {
+            System.out.println("remove 
"+listPixels.get(listPixels.size()-1).p.x + 
","+listPixels.get(listPixels.size()-1).p.y);
+            listPixels.remove(listPixels.size()-1);
+            System.out.println("remove 
"+listPixels.get(listPixels.size()-1).p.x + 
","+listPixels.get(listPixels.size()-1).p.y);
+            listPixels.remove(listPixels.size()-1);
+            return true;
+        }
+        return false;
+    }
+    
+    private BBox getSnapDistanceBBox(Node n) {
+        return new BBox(Main.proj.eastNorth2latlon(new 
EastNorth(n.getEastNorth().east() - snapDistance, n.getEastNorth().north() - 
snapDistance)),
+                Main.proj.eastNorth2latlon(new 
EastNorth(n.getEastNorth().east() + snapDistance, n.getEastNorth().north() + 
snapDistance)));
+    }
+
+    private Point getPointInCm(Node n) {
+        return new Point(new Double(n.getEastNorth().getX()*100).intValue(),
+                new Double(n.getEastNorth().getY()*100).intValue());
+    }
+    
+    public Node getNearestNode(Node newNode) {
+        Point newPoint = getPointInCm(newNode);
+        DataSet ds = getCurrentDataSet();
+        if (ds == null)
+            return null;
+
+        double minDistanceSq = snapDistanceSq;
+        Node minNode = null;
+        for (Node n : ds.searchNodes(getSnapDistanceBBox(newNode))) {
+            if (!n.isUsable()) {
+                continue;
+            }
+            Point sp = new Point(new 
Double(n.getEastNorth().getX()*100).intValue(),
+                    new Double(n.getEastNorth().getY()*100).intValue());
+            double dist = newPoint.distanceSq(sp); // in centimeter !
+            if (dist < minDistanceSq) {
+                minDistanceSq = dist;
+                minNode = n;
+            }
+            // when multiple nodes on one point, prefer new or selected nodes
+            else if (dist == minDistanceSq && minNode != null
+                    && ((n.isNew() && ds.isSelected(n))
+                            || (!ds.isSelected(minNode) && (ds.isSelected(n) 
|| n.isNew())))) {
+                minNode = n;
+            }
+        }
+        if (minNode != null) {
+            dx = (newNode.getEastNorth().getX() - 
minNode.getEastNorth().getX())/2;
+            dy = (newNode.getEastNorth().getY() - 
minNode.getEastNorth().getY())/2;
+        }
+        return minNode;
+    }
+
+    private List<WaySegment> getNearestWaySegments(Node newNode) {
+        Point newPoint = new Point(new 
Double(newNode.getEastNorth().getX()*100).intValue(),
+                new Double(newNode.getEastNorth().getY()*100).intValue());
+        TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, 
List<WaySegment>>();
+        DataSet ds = getCurrentDataSet();
+        if (ds == null)
+            return null;
+
+        for (Way w : ds.searchWays(getSnapDistanceBBox(newNode))) {
+            if (!w.isUsable()) {
+                continue;
+            }
+            Node lastN = null;
+            int i = -2;
+            for (Node n : w.getNodes()) {
+                i++;
+                if (n.isDeleted() || n.isIncomplete()) {
+                    continue;
+                }
+                if (lastN == null) {
+                    lastN = n;
+                    continue;
+                }
+
+                Point A = getPointInCm(lastN);
+                Point B = getPointInCm(n);
+                double c = A.distanceSq(B);
+                double a = newPoint.distanceSq(B);
+                double b = newPoint.distanceSq(A);
+                double perDist = a - (a - b + c) * (a - b + c) / 4 / c;
+                if (perDist < snapDistanceSq && a < c + snapDistanceSq && b < 
c + snapDistanceSq) {
+                    if (ds.isSelected(w)) {
+                        perDist -= 0.00001;
+                    }
+                    List<WaySegment> l;
+                    if (nearest.containsKey(perDist)) {
+                        l = nearest.get(perDist);
+                    } else {
+                        l = new LinkedList<WaySegment>();
+                        nearest.put(perDist, l);
+                    }
+                    double ratio = A.distance(newPoint)/A.distance(B);
+                    Point perP = new Point(A.x+new 
Double((B.x-A.x)*ratio).intValue(),
+                            A.y+new Double((B.y-A.y)*ratio).intValue());
+                    dx = (perP.x-newPoint.x)/200.0; // back to meters this 
time and whole distance by two 
+                    dy = (perP.y-newPoint.y)/200.0;
+//                    System.out.println(angle+","+ ratio+","+perP );
+                    l.add(new WaySegment(w, i));
+                }
+
+                lastN = n;
+            }
+        }
+        ArrayList<WaySegment> nearestList = new ArrayList<WaySegment>();
+        for (List<WaySegment> wss : nearest.values()) {
+            nearestList.addAll(wss);
+        }
+        return nearestList;
+    }
+    
+    private Node existingNodesInNewSegment(Node n1, Node n2, Way way) {
+        double minx = Math.min(n1.getEastNorth().getX(), 
n2.getEastNorth().getX())*100;
+        double miny = Math.min(n1.getEastNorth().getY(), 
n2.getEastNorth().getY())*100;
+        double maxx = Math.max(n1.getEastNorth().getX(), 
n2.getEastNorth().getX())*100;
+        double maxy = Math.max(n1.getEastNorth().getY(), 
n2.getEastNorth().getY())*100;
+//        if ((maxx-minx)/2 < snapDistance && (maxy-miny)/2 < snapDistance) {
+//            return null;
+//        }
+        BBox bbox = new BBox( Main.proj.eastNorth2latlon(new 
EastNorth((minx-snapDistance)/100, (miny-snapDistance)/100)), 
+                Main.proj.eastNorth2latlon(new 
EastNorth((maxx+snapDistance)/100, (maxy+snapDistance)/100)));
+        DataSet ds = getCurrentDataSet();
+        if (ds == null) {
+            return null;
+        }
+        Node ret = null;
+        List<Node> nodesInBbox = ds.searchNodes(bbox);
+        for (Node n:nodesInBbox) {
+            Point A = getPointInCm(n1);
+            Point B = getPointInCm(n2);
+            Point existingPoint = getPointInCm(n);
+            double c = A.distanceSq(B);
+            double a = existingPoint.distanceSq(B);
+            double b = existingPoint.distanceSq(A);
+            double perDist = a - (a - b + c) * (a - b + c) / 4 / c;
+            if (perDist < snapDistanceSq && a < c + snapDistanceSq && b < c + 
snapDistanceSq
+               && n.isUsable() && !way.getNodes().contains(n)) {
+                ret = n;
+                // shift the existing node to the half distance of the joined 
new segment
+                double ratio = A.distance(existingPoint)/A.distance(B);
+                Point perP = new Point(A.x+new 
Double((B.x-A.x)*ratio).intValue(),
+                        A.y+new Double((B.y-A.y)*ratio).intValue());
+                dx = (perP.x-existingPoint.x)/200.0; // back to meters this 
time and whole distance by two 
+                dy = (perP.y-existingPoint.y)/200.0;
+                break;
+            }
+        }
+//        System.out.println("Found "+nodesInBbox.size()+", join node "+ret+" 
to new segment; 
"+Main.proj.latlon2eastNorth(bbox.getBottomRight())+","+Main.proj.latlon2eastNorth(bbox.getTopLeft()));
+        return ret;
+    }
+    
+    private Way joinNodeToExistingWays(List<WaySegment> wss, Node newNode, 
Collection<Command> cmds) {
+        HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, 
List<Integer>>();
+        for (WaySegment ws : wss) {
+            List<Integer> is;
+            if (insertPoints.containsKey(ws.way)) {
+                is = insertPoints.get(ws.way);
+            } else {
+                is = new ArrayList<Integer>();
+                insertPoints.put(ws.way, is);
+            }
+
+            if (ws.way.getNode(ws.lowerIndex) != newNode && 
ws.way.getNode(ws.lowerIndex+1) != newNode) {
+                is.add(ws.lowerIndex);
+            }
+        }
+        
+        Way wnew = null;
+        for (Map.Entry<Way, List<Integer>> insertPoint : 
insertPoints.entrySet()) {
+            List<Integer> is = insertPoint.getValue();
+            if (is.size() == 0)
+                continue;
+
+            Way w = insertPoint.getKey();
+            List<Node> nodesToAdd = w.getNodes();
+            pruneSuccsAndReverse(is);
+            for (int i : is) {
+                nodesToAdd.add(i+1, newNode);
+            }
+            wnew = new Way(w);
+            wnew.setNodes(nodesToAdd);
+            cmds.add(new ChangeCommand(w, wnew));
+        }
+        return wnew;
+    }
+    
+    private static void pruneSuccsAndReverse(List<Integer> is) {
+        HashSet<Integer> is2 = new HashSet<Integer>();
+        for (int i : is) {
+            if (!is2.contains(i - 1) && !is2.contains(i + 1)) {
+                is2.add(i);
+            }
+        }
+        is.clear();
+        is.addAll(is2);
+        Collections.sort(is);
+        Collections.reverse(is);
+    }
+    
+    /*
+     * The standard simplifier leaves sometimes closed nodes at buildings 
corners. 
+     * We remove here the node not altering the building angle.
+     */
+    private void simplifyAngles(Way way){
+        for (int i=1; i<way.getNodes().size(); i++){
+            Node n1 = way.getNode(i-1);
+            Node n2 = way.getNode(i);
+            double dist = getPointInCm(n1).distance(getPointInCm(n2))/100;
+//            System.out.println("dist="+dist+":"+(dist < 
cDistanceForOptimization));                
+            if (dist < cDistanceForOptimization) {
+                Node n0, n3;
+                if (i > 1)
+                    n0 = way.getNode(i-2);
+                else
+                    n0 = way.getNode(way.getNodes().size()-1);
+                if (i < way.getNodes().size()-1)
+                    n3 = way.getNode(i+1);
+                else
+                    n3 = way.getNode(0);
+                double angle1 = AngleOfView(n1.getCoor().getX(), 
n1.getCoor().getY(),
+                        n0.getCoor().getX(), n0.getCoor().getY(),
+                        n2.getCoor().getX(), n2.getCoor().getY());
+//                System.out.println("angle n0,n1,n2="+(angle1*180/Math.PI));
+                double angle2 = AngleOfView(n2.getCoor().getX(), 
n2.getCoor().getY(),
+                        n1.getCoor().getX(), n1.getCoor().getY(),
+                        n3.getCoor().getX(), n3.getCoor().getY());
+//                System.out.println("angle n1,n2,n3="+(angle2*180/Math.PI));
+                if (angle1 > Math.PI*0.9 && angle1 < Math.PI*1.1) {
+                    way.removeNode(n1);
+                    System.out.println("remove n1");                
+                } else if  (angle2 > Math.PI*0.9 && angle2 < Math.PI*1.1) {
+                    way.removeNode(n2);
+                    System.out.println("remove n2");                
+                } else
+                    System.out.println("no angle near PI");
+            }                
+        }        
+    }
+
+    private double AngleOfView ( double ViewPt_X, double ViewPt_Y,
+            double Pt1_X, double Pt1_Y,
+            double Pt2_X, double Pt2_Y ) {
+        double a1, b1, a2, b2, a, b, t, cosinus ;
+        a1 = Pt1_X - ViewPt_X ;
+        a2 = Pt1_Y - ViewPt_Y ;
+        b1 = Pt2_X - ViewPt_X ;
+        b2 = Pt2_Y - ViewPt_Y ;
+        a = Math.sqrt( (a1*a1) + (a2*a2) );
+        b = Math.sqrt ( (b1*b1) + (b2*b2) );
+        if ( (a == 0.0) || (b == 0.0) )
+            return (0.0) ;
+        cosinus = (a1*b1+a2*b2) / (a*b) ;
+        t = Math.acos ( cosinus );
+        //t = t * 180.0 / Math.PI ;
+        return (t);
+    }
+    
+    /* 
+     * coming from SimplifyWayAction
+     */
+//    private boolean isRequiredNode(Way way, Node node) {
+//        boolean isRequired =  Collections.frequency(way.getNodes(), node) > 
1;
+//        if (! isRequired) {
+//            List<OsmPrimitive> parents = new LinkedList<OsmPrimitive>();
+//            parents.addAll(node.getReferrers());
+//            parents.remove(way);
+//            isRequired = !parents.isEmpty();
+//        }
+//        if (!isRequired) {
+//            isRequired = node.isTagged();
+//        }
+//        return isRequired;
+//    }
+}
diff --git a/cadastre-fr/src/cadastre_fr/BuildingsImageModifier.java 
b/cadastre-fr/src/cadastre_fr/BuildingsImageModifier.java
new file mode 100644
index 0000000..90a9f65
--- /dev/null
+++ b/cadastre-fr/src/cadastre_fr/BuildingsImageModifier.java
@@ -0,0 +1,21 @@
+package cadastre_fr;
+
+public class BuildingsImageModifier extends ImageModifier {
+
+    public BuildingsImageModifier() {super();};
+        
+    public BuildingsImageModifier(GeorefImage buildings, GeorefImage parcels) {
+        bufferedImage = buildings.image;
+        VectorImageModifier vim = new VectorImageModifier();
+        for (int x = 0; x < bufferedImage.getWidth(); x++) {
+            for (int y = 0; y < bufferedImage.getHeight(); y++) {
+                if (vim.isBuildingOrRoofColor(bufferedImage, x, y, false)
+                        && !vim.isBackgroundColor(parcels.image, x, y)) {
+                    // create a clear 'cut' for the parcels
+                    bufferedImage.setRGB(x, y, parcelColor);
+                }
+            }
+        }
+    }
+    
+}
diff --git a/cadastre-fr/src/cadastre_fr/CacheControl.java 
b/cadastre-fr/src/cadastre_fr/CacheControl.java
index 1268bd5..24223fe 100644
--- a/cadastre-fr/src/cadastre_fr/CacheControl.java
+++ b/cadastre-fr/src/cadastre_fr/CacheControl.java
@@ -21,7 +21,7 @@ import javax.swing.JDialog;
 import javax.swing.JOptionPane;
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.projection.LambertCC9Zones;
-import org.openstreetmap.josm.data.projection.UTM_20N_France_DOM;
+import org.openstreetmap.josm.data.projection.UTM_France_DOM;
 
 public class CacheControl implements Runnable {
     
@@ -93,30 +93,32 @@ public class CacheControl implements Runnable {
 
     public boolean loadCacheIfExist() {
         try {
-            String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
-            if (Main.proj instanceof LambertCC9Zones)
-                extension = cLambertCC9Z + extension;
-            else if (Main.proj instanceof UTM_20N_France_DOM)
-                extension = cUTM20N + extension;
-            File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() 
+ "." + extension);
-            if (file.exists()) {
-                JOptionPane pane = new JOptionPane(
-                        tr("Location \"{0}\" found in cache.\n"+
-                        "Load cache first ?\n"+
-                        "(No = new cache)", wmsLayer.getName()),
-                        JOptionPane.QUESTION_MESSAGE, 
JOptionPane.YES_NO_OPTION, null);
-                // this below is a temporary workaround to fix the "always on 
top" issue
-                JDialog dialog = pane.createDialog(Main.parent, tr("Select 
Feuille"));
-                CadastrePlugin.prepareDialog(dialog);
-                dialog.setVisible(true);
-                int reply = (Integer)pane.getValue();
-                // till here
-
-                if (reply == JOptionPane.OK_OPTION && loadCache(file, 
wmsLayer.getLambertZone())) {
-                    return true;
-                } else {
-                    delete(file);
+            if (!wmsLayer.isBuildingsOnly()) {
+                File file = new File(CadastrePlugin.cacheDir + 
wmsLayer.getName() + "." + WMSFileExtension());
+                if (file.exists()) {
+                    JOptionPane pane = new JOptionPane(
+                            tr("Location \"{0}\" found in cache.\n"+
+                            "Load cache first ?\n"+
+                            "(No = new cache)", wmsLayer.getName()),
+                            JOptionPane.QUESTION_MESSAGE, 
JOptionPane.YES_NO_OPTION, null);
+                    // this below is a temporary workaround to fix the "always 
on top" issue
+                    JDialog dialog = pane.createDialog(Main.parent, tr("Select 
Feuille"));
+                    CadastrePlugin.prepareDialog(dialog);
+                    dialog.setVisible(true);
+                    int reply = (Integer)pane.getValue();
+                    // till here
+    
+                    if (reply == JOptionPane.OK_OPTION && loadCache(file, 
wmsLayer.getLambertZone())) {
+                        return true;
+                    } else {
+                        delete(file);
+                    }
                 }
+            } else {
+                int i=0;
+                while (new File(CadastrePlugin.cacheDir + wmsLayer.getName() + 
"."+i+"."+ WMSFileExtension()).exists())
+                    i++;
+                wmsLayer.setName(wmsLayer.getName()+"."+i);
             }
         } catch (Exception e) {
             e.printStackTrace(System.out);
@@ -126,10 +128,7 @@ public class CacheControl implements Runnable {
 
     public void deleteCacheFile() {
         try {
-            String extension = String.valueOf((wmsLayer.getLambertZone() + 1));
-            if (Main.proj instanceof LambertCC9Zones)
-                extension = cLambertCC9Z + extension;
-            delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." 
+ extension));
+            delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." 
+ WMSFileExtension()));
         } catch (Exception e) {
             e.printStackTrace(System.out);
         }
@@ -181,12 +180,7 @@ public class CacheControl implements Runnable {
             int size = imagesToSave.size();
             imagesLock.unlock();
             if (size > 0) {
-                String extension = String.valueOf((wmsLayer.getLambertZone() + 
1));
-                if (Main.proj instanceof LambertCC9Zones)
-                    extension = cLambertCC9Z + extension;
-                else if (Main.proj instanceof UTM_20N_France_DOM)
-                    extension = cUTM20N + extension;
-                File file = new File(CadastrePlugin.cacheDir + 
wmsLayer.getName() + "." + extension);
+                File file = new File(CadastrePlugin.cacheDir + 
wmsLayer.getName() + "." + WMSFileExtension());
                 try {
                     if (file.exists()) {
                         ObjectOutputStreamAppend oos = new 
ObjectOutputStreamAppend(
@@ -218,4 +212,14 @@ public class CacheControl implements Runnable {
             }
         }
     }
+    
+    private String WMSFileExtension() {
+        String ext = String.valueOf((wmsLayer.getLambertZone() + 1));
+        if (Main.proj instanceof LambertCC9Zones)
+            ext = cLambertCC9Z + ext;
+        else if (Main.proj instanceof UTM_France_DOM)
+            ext = cUTM20N + ext;
+        return ext;
+    }
+
 }
diff --git a/cadastre-fr/src/cadastre_fr/CacheFileUTM20NFilter.java 
b/cadastre-fr/src/cadastre_fr/CacheFileUTM20NFilter.java
index cc30d0f..cf22de6 100644
--- a/cadastre-fr/src/cadastre_fr/CacheFileUTM20NFilter.java
+++ b/cadastre-fr/src/cadastre_fr/CacheFileUTM20NFilter.java
@@ -18,7 +18,8 @@ public class CacheFileUTM20NFilter extends FileFilter {
     public static CacheFileUTM20NFilter[] filters = {
         new CacheFileUTM20NFilter("utm1", tr("Guadeloupe Fort-Marigot cache 
file (.UTM1)")),
         new CacheFileUTM20NFilter("utm2", tr("Guadeloupe Ste-Anne cache file 
(.UTM2)")),
-        new CacheFileUTM20NFilter("utm3", tr("Martinique Fort Desaix cache 
file (.UTM3)"))
+        new CacheFileUTM20NFilter("utm3", tr("Martinique Fort Desaix cache 
file (.UTM3)")),
+        new CacheFileUTM20NFilter("utm4", tr("Reunion RGR92 cache file 
(.UTM4)"))
         };
 
     /**
diff --git a/cadastre-fr/src/cadastre_fr/CadastreGrabber.java 
b/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
index 4c4b726..ccaea02 100644
--- a/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
+++ b/cadastre-fr/src/cadastre_fr/CadastreGrabber.java
@@ -34,13 +34,35 @@ public class CadastreGrabber {
             if (wmsLayer.isRaster())
                 imageModified = new RasterImageModifier(img);
             else
-                imageModified = new VectorImageModifier(img);
+                imageModified = new VectorImageModifier(img, false);
             return new GeorefImage(imageModified.bufferedImage, lambertMin, 
lambertMax);
         } catch (MalformedURLException e) {
             throw (IOException) new IOException(tr("CadastreGrabber: Illegal 
url.")).initCause(e);
         }
     }
 
+    public GeorefImage grabBuildings(WMSLayer wmsLayer, EastNorth lambertMin, 
EastNorth lambertMax) throws IOException, OsmTransferException {
+        try {
+            URL url = getURLVectorBuildings(lambertMin, lambertMax);
+            BufferedImage img = grab(url);
+            ImageModifier imageModified = new VectorImageModifier(img, true);
+            return new GeorefImage(imageModified.bufferedImage, lambertMin, 
lambertMax);
+        } catch (MalformedURLException e) {
+            throw (IOException) new IOException(tr("CadastreGrabber: Illegal 
url.")).initCause(e);
+        }
+    }
+    
+    public GeorefImage grabParcels(WMSLayer wmsLayer, EastNorth lambertMin, 
EastNorth lambertMax) throws IOException, OsmTransferException {
+        try {
+            URL url = getURLVectorParcels(lambertMin, lambertMax);
+            BufferedImage img = grab(url);
+            //ImageModifier imageModified = new VectorImageModifier(img, true);
+            return new GeorefImage(/*imageModified.bufferedImage*/img, 
lambertMin, lambertMax);
+        } catch (MalformedURLException e) {
+            throw (IOException) new IOException(tr("CadastreGrabber: Illegal 
url.")).initCause(e);
+        }
+    }
+    
     private URL getURLRaster(WMSLayer wmsLayer, EastNorth lambertMin, 
EastNorth lambertMax) throws MalformedURLException {
         // GET 
/scpc/wms?version=1.1&request=GetMap&layers=CDIF:PMC@QH4480001701&format=image/png&bbox=-1186,0,13555,8830&width=576&height=345&exception=application/vnd.ogc.se_inimage&styles=
 HTTP/1.1
         final int cRasterX = CadastrePlugin.imageWidth; // keep width constant 
and adjust width to original image proportions
@@ -48,31 +70,48 @@ public class CadastreGrabber {
         str += "&layers=CDIF:PMC@";
         str += wmsLayer.getCodeCommune();
         str += "&format=image/png";
+        //str += "&format=image/jpeg";
         str += "&bbox=";
         str += wmsLayer.eastNorth2raster(lambertMin, lambertMax);
-        //str += "&width=1000&height=800"; // maximum allowed by wms server
         str += "&width="+cRasterX+"&height="; // maximum allowed by wms server 
(576/345, 800/378, 1000/634)
         str += (int)(cRasterX*(wmsLayer.communeBBox.max.getY() - 
wmsLayer.communeBBox.min.getY())/(wmsLayer.communeBBox.max.getX() - 
wmsLayer.communeBBox.min.getX()));
-        str += "&exception=application/vnd.ogc.se_inimage&styles=";
+        str += "&exception=application/vnd.ogc.se_inimage&styles="; // 
required for raster images
+        System.out.println("URL="+str);
         return new URL(str.replace(" ", "%20"));
     }
 
-    private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) 
throws MalformedURLException {
+    private URL buildURLVector(String layers, String styles,
+            int width, int height,
+            EastNorth lambertMin, EastNorth lambertMax) throws 
MalformedURLException {
         String str = new 
String(wmsInterface.baseURL+"/scpc/wms?version=1.1&request=GetMap");
-        str += "&layers="+CadastrePlugin.grabLayers;
+        str += "&layers="+ layers;  
         str += "&format=image/png";
         //str += "&format=image/jpeg";
         str += "&bbox="+lambertMin.east()+",";
         str += lambertMin.north() + ",";
         str += lambertMax.east() + ",";
         str += lambertMax.north();
-        str += 
"&width="+CadastrePlugin.imageWidth+"&height="+CadastrePlugin.imageHeight;
-        //str += "&exception=application/vnd.ogc.se_inimage"; // used by 
normal client but not required
-        str += "&styles="+CadastrePlugin.grabStyles;
+        str += "&width="+width+"&height="+height;
+        str += "&exception=application/vnd.ogc.se_inimage"; // works also 
without (but slower ?)
+        str += "&styles=" + styles;
         System.out.println("URL="+str);
         return new URL(str.replace(" ", "%20"));
     }
 
+    private URL getURLVector(EastNorth lambertMin, EastNorth lambertMax) 
throws MalformedURLException {
+        return buildURLVector(CadastrePlugin.grabLayers, 
CadastrePlugin.grabStyles, 
+                CadastrePlugin.imageWidth, CadastrePlugin.imageHeight, 
+                lambertMin, lambertMax);
+    }
+
+    private URL getURLVectorBuildings(EastNorth lambertMin, EastNorth 
lambertMax) throws MalformedURLException {
+        return buildURLVector("CDIF:LS2", "LS2_90", 1000, 800, lambertMin, 
lambertMax);
+    }
+
+    private URL getURLVectorParcels(EastNorth lambertMin, EastNorth 
lambertMax) throws MalformedURLException {
+        return buildURLVector("CDIF:PARCELLE", "PARCELLE_90", 1000, 800, 
lambertMin, lambertMax);
+    }
+
     private BufferedImage grab(URL url) throws IOException, 
OsmTransferException {
         wmsInterface.urlConn = (HttpURLConnection)url.openConnection();
         wmsInterface.urlConn.setRequestMethod("GET");
diff --git a/cadastre-fr/src/cadastre_fr/CadastreInterface.java 
b/cadastre-fr/src/cadastre_fr/CadastreInterface.java
index 58c261c..d48c1db 100644
--- a/cadastre-fr/src/cadastre_fr/CadastreInterface.java
+++ b/cadastre-fr/src/cadastre_fr/CadastreInterface.java
@@ -64,23 +64,24 @@ public class CadastreInterface {
 
     final  int cRetriesGetCookie = 10; // 10 times every 3 seconds means 30 
seconds trying to get a cookie
 
-    public boolean retrieveInterface(WMSLayer wmsLayer) throws 
DuplicateLayerException {
+    public boolean retrieveInterface(WMSLayer wmsLayer) throws 
DuplicateLayerException, WMSException {
         if (wmsLayer.getName().equals(""))
             return false;
-        if (wmsLayer.getName().equals(lastWMSLayerName))
+        boolean isCookieExpired = isCookieExpired();
+        if (wmsLayer.getName().equals(lastWMSLayerName) && !isCookieExpired)
             return true;
         // open the session with the French Cadastre web front end
         downloadCancelled = false;
         try {
-            if (cookie == null || isCookieExpired())
+            if (cookie == null || isCookieExpired) {
                 getCookie();
-            if (cookie != null && interfaceRef == null) {
+                interfaceRef = null;
+            }
+            if (cookie == null)
+                throw new WMSException(tr("Cannot open a new client 
session.\nServer in maintenance or temporary overloaded."));
+            if (interfaceRef == null) {
                     getInterface(wmsLayer);
                     this.lastWMSLayerName = wmsLayer.getName();
-            } else {
-                JOptionPane.showMessageDialog(Main.parent,
-                        tr("Cannot open a new client session.\nServer in 
maintenance or temporary overloaded."));
-                return false;
             }
             openInterface();
         } catch (IOException e) {
diff --git a/cadastre-fr/src/cadastre_fr/CadastrePlugin.java 
b/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
index 8383902..6d338fb 100644
--- a/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
+++ b/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
@@ -8,6 +8,7 @@ import static org.openstreetmap.josm.tools.I18n.tr;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
+import java.io.File;
 
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JDialog;
@@ -89,7 +90,7 @@ import org.openstreetmap.josm.data.projection.*;
  *                 - removed autosourcing of empty new nodes
  * 1.6 28-Nov-2009 - Fix minor issues if Grab is called without layer 
(possible since projection rework)
  * 1.7 12-Dec-2009 - Change URL's changes for cookie and downgrade imgs 
resolution due to WMS changes
- * 1.8 xxx         - filter the mouse button 1 during georeferencing
+ * 1.8 11-Mar-2010 - filter the mouse button 1 during georeferencing
  *                 - retry if getting a new cookie failed (10 times during 30 
seconds)
  *                 - cookie expiration automatically detected and renewed 
(after 30 minutes)
  *                 - proper WMS layer cleanup at destruction (workaround for 
memory leak)
@@ -100,14 +101,20 @@ import org.openstreetmap.josm.data.projection.*;
  *                 - raster image adjustment using default system menu 
modifier (ctrl for windows) for Mac support
  *                 - image resolution configurable (high, medium, low) like 
the online interface
  *                 - layer selection configurable for vectorized images
+ *                 - improved download cancellation
  *                 - from Erik Amzallag:
  *                 -     possibility to modify the auto-sourcing text just 
before upload 
  *                 - from Cl�ment M�nier:
  *                 -     new option allowing an auto-selection of the first 
cadastre layer for grab
- *                 -     non-modal JDialog in MenuActionGrabPlanImage  
+ *                 -     non-modal JDialog in MenuActionGrabPlanImage
+ *                 -     new options in the image filter (bilinear, bicubic)
+ * 1.9 05-Apr-2010 - added a scroll bar in preferences
+ *                 - download cancellation improved
+ *                 - last deployment for Java1.5 compatibility
+ * 2.0 xx-xxx-xxxx - update projection for "La Reunion" departement to RGR92, 
UTM40S. 
  */
 public class CadastrePlugin extends Plugin {
-    static String VERSION = "1.8";
+    static String VERSION = "2.0";
 
     static JMenu cadastreJMenu;
 
@@ -146,11 +153,11 @@ public class CadastrePlugin extends Plugin {
        super(info);
         System.out.println("Pluging cadastre-fr v"+VERSION+" started...");
         if (Main.pref.get("cadastrewms.cacheDir").equals(""))
-            cacheDir = Main.pref.getPreferencesDir()+"plugins/cadastrewms/";
+            cacheDir = 
Main.pref.getPreferencesDir()+"plugins"+File.separatorChar+"cadastrewms"+File.separatorChar;
         else {
             cacheDir = Main.pref.get("cadastrewms.cacheDir");
-            if (cacheDir.charAt(cacheDir.length()-1) != '\\' )
-                cacheDir += '\\';
+            if (cacheDir.charAt(cacheDir.length()-1) != File.separatorChar )
+                cacheDir += File.separatorChar;
         }
         System.out.println("current cache directory: "+cacheDir);
 
@@ -187,7 +194,7 @@ public class CadastrePlugin extends Plugin {
             JMenuItem menuLoadFromCache = new JMenuItem(new 
MenuActionLoadFromCache());
             // temporary disabled:
             //JMenuItem menuActionBoundaries = new JMenuItem(new 
MenuActionBoundaries());
-            //JMenuItem menuActionBuildings = new JMenuItem(new 
MenuActionBuildings());
+            JMenuItem menuActionBuildings = new JMenuItem(new 
MenuActionBuildings());
 
             cadastreJMenu.add(menuGrab);
             cadastreJMenu.add(menuActionGrabPlanImage);
@@ -195,10 +202,11 @@ public class CadastrePlugin extends Plugin {
             cadastreJMenu.add(menuSource);
             //cadastreJMenu.add(menuResetCookie); not required any more
             //cadastreJMenu.add(menuLambertZone);
+            if (Main.pref.getBoolean("cadastrewms.buildingsMenu", false))
+                cadastreJMenu.add(menuActionBuildings);
             cadastreJMenu.add(menuLoadFromCache);
             // all SVG features disabled until official WMS is released
             //cadastreJMenu.add(menuActionBoundaries);
-            //cadastreJMenu.add(menuActionBuildings);
         }
         setEnabledAll(menuEnabled);
     }
@@ -223,6 +231,39 @@ public class CadastrePlugin extends Plugin {
         } else { 
             imageWidth = 600; imageHeight = 400;
         }
+        refreshLayersURL();
+        
+        // overwrite F11 shortcut used from the beginning by this plugin and 
recently used
+        // for full-screen switch in JOSM core
+        int i = 0;
+        String p = Main.pref.get("shortcut.shortcut."+i, null);
+        boolean alreadyRedefined = false;
+        while (p != null) {
+            String[] s = p.split(";");
+            alreadyRedefined = alreadyRedefined || 
s[0].equals("menu:view:fullscreen");
+            i++;
+            p = Main.pref.get("shortcut.shortcut."+i, null);
+        }
+        if (!alreadyRedefined) {
+            int reply = JOptionPane.showConfirmDialog(null,
+                    tr("Plugin cadastre-fr used traditionaly for grabbing the 
key shortcut F11\n"+
+                    "which is currently allocated for full-screen switch by 
default\n"+
+                    "Would you like to restore F11 for grab action ?"),
+                    tr("Restore grab shortcut F11"),
+                    JOptionPane.YES_NO_OPTION);
+            if (reply == JOptionPane.OK_OPTION) {
+                System.out.println("redefine fullscreen shortcut F11 to 
shift+F11");
+                Main.pref.put("shortcut.shortcut."+i, 
"menu:view:fullscreen;Toggle Full Screen view;122;5;122;64;false;true");
+                JOptionPane.showMessageDialog(Main.parent,tr("JOSM is stopped 
for the change to take effect."));
+                System.exit(0);
+            }
+        } else
+            System.out.println("shortcut F11 already redefined; do not 
change");
+
+        refreshMenu();
+    }
+    
+    private static void refreshLayersURL() {
         grabLayers = "";
         grabStyles = "";
         if (Main.pref.getBoolean("cadastrewms.layerWater", true)) {
@@ -265,35 +306,6 @@ public class CadastrePlugin extends Plugin {
             grabLayers = grabLayers.substring(0, grabLayers.length()-1);
             grabStyles = grabStyles.substring(0, grabStyles.length()-1);
         }
-        
-        // overwrite F11 shortcut used from the beginning by this plugin and 
recently used
-        // for full-screen switch in JOSM core
-        int i = 0;
-        String p = Main.pref.get("shortcut.shortcut."+i, null);
-        boolean alreadyRedefined = false;
-        while (p != null) {
-            String[] s = p.split(";");
-            alreadyRedefined = alreadyRedefined || 
s[0].equals("menu:view:fullscreen");
-            i++;
-            p = Main.pref.get("shortcut.shortcut."+i, null);
-        }
-        if (!alreadyRedefined) {
-            int reply = JOptionPane.showConfirmDialog(null,
-                    tr("Plugin cadastre-fr used traditionaly for grabbing the 
key shortcut F11\n"+
-                    "which is currently allocated for full-screen switch by 
default\n"+
-                    "Would you like to restore F11 for grab action ?"),
-                    tr("Restore grab shortcut F11"),
-                    JOptionPane.YES_NO_OPTION);
-            if (reply == JOptionPane.OK_OPTION) {
-                System.out.println("redefine fullscreen shortcut F11 to 
shift+F11");
-                Main.pref.put("shortcut.shortcut."+i, 
"menu:view:fullscreen;Toggle Full Screen view;122;5;122;64;false;true");
-                JOptionPane.showMessageDialog(Main.parent,tr("JOSM is stopped 
for the change to take effect."));
-                System.exit(0);
-            }
-        } else
-            System.out.println("shortcut F11 already redefined; do not 
change");
-
-        refreshMenu();
     }
 
     @Override
@@ -319,8 +331,9 @@ public class CadastrePlugin extends Plugin {
         if (cadastreJMenu != null) {
             if (oldFrame == null && newFrame != null) {
                 setEnabledAll(true);
-                Main.map.addMapMode(new IconToggleButton
-                        (new WMSAdjustAction(Main.map)));
+                Main.map.addMapMode(new IconToggleButton(new 
WMSAdjustAction(Main.map)));
+                if (Main.pref.getBoolean("cadastrewms.buildingsMenu", false))
+                    Main.map.addMapMode(new IconToggleButton(new 
Buildings(Main.map)));
             } else if (oldFrame != null && newFrame == null) {
                 setEnabledAll(false);
                 //Lambert.layoutZone = -1;
@@ -331,8 +344,7 @@ public class CadastrePlugin extends Plugin {
     
     public static boolean isCadastreProjection() {
         return Main.proj.toString().equals(new Lambert().toString())
-            || Main.proj.toString().equals(new UTM_20N_France_DOM().toString())
-            || Main.proj.toString().equals(new 
GaussLaborde_Reunion().toString())
+            || Main.proj.toString().equals(new UTM_France_DOM().toString())
             || Main.proj.toString().equals(new LambertCC9Zones().toString());
     }
 
diff --git a/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java 
b/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java
index 157c9be..01a60d6 100644
--- a/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java
+++ b/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java
@@ -3,6 +3,7 @@ package cadastre_fr;
 
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.awt.GridBagLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import javax.swing.*;
@@ -94,7 +95,10 @@ public class CadastrePreferenceSetting implements 
PreferenceSetting {
                 + "<a 
href=\"http://www.cadastre.gouv.fr/scpc/html/CU_01_ConditionsGenerales_fr.html\";>
 "
                 + 
"http://www.cadastre.gouv.fr/scpc/html/CU_01_ConditionsGenerales_fr.html</a> 
<BR>"
                 + "before any upload of data created by this plugin.");
-        JPanel cadastrewms = gui.createPreferenceTab("cadastrewms.gif", 
I18n.tr("French cadastre WMS"), description);
+        JPanel cadastrewmsMast = gui.createPreferenceTab("cadastrewms.gif", 
I18n.tr("French cadastre WMS"), description);
+        
+        JPanel cadastrewms = new JPanel(new GridBagLayout());
+        cadastrewms.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
 
         // option to automatically set the source tag when uploading
         sourcing.setText(CadastrePlugin.source);
@@ -325,6 +329,11 @@ public class CadastrePreferenceSetting implements 
PreferenceSetting {
         autoFirstLayer.setToolTipText(tr("Automatically selects the first WMS 
layer if multiple layers exist when grabbing."));
         cadastrewms.add(autoFirstLayer, GBC.eop().insets(0, 0, 0, 0));
         cadastrewms.add(Box.createVerticalGlue(), 
GBC.eol().fill(GBC.VERTICAL));
+//        JTabbedPane cadastrecontent = new JTabbedPane();
+//        cadastrecontent.add(cadastrewms);
+        JScrollPane scrollpane = new JScrollPane(cadastrewms);
+        scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
+        cadastrewmsMast.add(scrollpane, GBC.eol().fill(GBC.BOTH));
 
     }
 
diff --git a/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java 
b/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
index f2ce93b..7c035ba 100644
--- a/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
+++ b/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java
@@ -41,6 +41,8 @@ public class DownloadSVGBuilding extends PleaseWaitRunnable {
     private String svg = null;
     private static EastNorthBound currentView = null;
     private EastNorthBound viewBox = null;
+    private static String errorMessage;
+
 
     public DownloadSVGBuilding(WMSLayer wmsLayer) {
         super(tr("Downloading {0}", wmsLayer.getName()));
@@ -52,6 +54,7 @@ public class DownloadSVGBuilding extends PleaseWaitRunnable {
     @Override
     public void realRun() throws IOException, OsmTransferException {
        progressMonitor.indeterminateSubTask(tr("Contacting WMS Server..."));
+        errorMessage = null;
         try {
             if (wmsInterface.retrieveInterface(wmsLayer)) {
                 svg = grabBoundary(currentView);
@@ -64,6 +67,9 @@ public class DownloadSVGBuilding extends PleaseWaitRunnable {
             }
         } catch (DuplicateLayerException e) {
             System.err.println("removed a duplicated layer");
+        } catch (WMSException e) {
+            errorMessage = e.getMessage();
+            grabber.getWmsInterface().resetCookie();
         }
     }
 
@@ -128,8 +134,8 @@ public class DownloadSVGBuilding extends PleaseWaitRunnable 
{
                 }*/
 
         // simplify ways and check if we can reuse existing OSM nodes
-        for (Way wayToAdd : svgDataSet.getWays())
-            new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5);
+//        for (Way wayToAdd : svgDataSet.getWays())
+//            new SimplifyWay().simplifyWay(wayToAdd, svgDataSet, 0.5);
         // check if the new way or its nodes is already in OSM layer
         for (Node n : svgDataSet.getNodes()) {
             Node nearestNewNode = checkNearestNode(n, 
Main.main.getCurrentDataSet().getNodes());
@@ -271,6 +277,8 @@ public class DownloadSVGBuilding extends PleaseWaitRunnable 
{
             return;
         }
         Main.worker.execute(new DownloadSVGBuilding(wmsLayer));
+        if (errorMessage != null)
+            JOptionPane.showMessageDialog(Main.parent, errorMessage);
     }
 
 }
diff --git a/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java 
b/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
index bae5381..eb36b3b 100644
--- a/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
+++ b/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java
@@ -45,6 +45,7 @@ public class DownloadSVGTask extends PleaseWaitRunnable {
     private CadastreInterface wmsInterface;
     private String svg = null;
     private EastNorthBound viewBox = null;
+    private static String errorMessage;
 
     public DownloadSVGTask(WMSLayer wmsLayer) {
         super(tr("Downloading {0}", wmsLayer.getName()));
@@ -56,6 +57,7 @@ public class DownloadSVGTask extends PleaseWaitRunnable {
     @Override
     public void realRun() throws IOException, OsmTransferException {
        progressMonitor.indeterminateSubTask(tr("Contacting WMS Server..."));
+        errorMessage = null;
         try {
             if (wmsInterface.retrieveInterface(wmsLayer)) {
                 svg = grabBoundary(wmsLayer.getCommuneBBox());
@@ -70,6 +72,9 @@ public class DownloadSVGTask extends PleaseWaitRunnable {
             }
         } catch (DuplicateLayerException e) {
             System.err.println("removed a duplicated layer");
+        } catch (WMSException e) {
+            errorMessage = e.getMessage();
+            grabber.getWmsInterface().resetCookie();
         }
     }
 
@@ -122,8 +127,8 @@ public class DownloadSVGTask extends PleaseWaitRunnable {
         wayToAdd.addNode(wayToAdd.getNode(0)); // close the circle
 
         // simplify the way
-        double threshold = 
Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0"));
-        new SimplifyWay().simplifyWay(wayToAdd, Main.main.getCurrentDataSet(), 
threshold);
+//        double threshold = 
Double.parseDouble(Main.pref.get("cadastrewms.simplify-way-boundary", "1.0"));
+//        new SimplifyWay().simplifyWay(wayToAdd, 
Main.main.getCurrentDataSet(), threshold);
 
         cmds.add(new AddCommand(wayToAdd));
         Main.main.undoRedo.add(new SequenceCommand(tr("Create boundary"), 
cmds));
@@ -217,6 +222,8 @@ public class DownloadSVGTask extends PleaseWaitRunnable {
             return;
         }
         Main.worker.execute(new DownloadSVGTask(wmsLayer));
+        if (errorMessage != null)
+            JOptionPane.showMessageDialog(Main.parent, errorMessage);
     }
 
 }
diff --git a/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java 
b/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java
index adb0d6d..648eb15 100644
--- a/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java
+++ b/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java
@@ -20,6 +20,7 @@ public class DownloadWMSPlanImage {
     private WMSLayer wmsLayer;
     private Bounds bounds;
     private boolean dontGeoreference = false;
+    private static String errorMessage;
     
     private class Task extends PleaseWaitRunnable {
         private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber;
@@ -30,6 +31,7 @@ public class DownloadWMSPlanImage {
         @Override
         public void realRun() throws IOException {
             progressMonitor.indeterminateSubTask(tr("Contacting cadastre WMS 
..."));
+            errorMessage = null;
             try {
                 if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) {
                     if (!wmsLayer.images.isEmpty()) {
@@ -65,7 +67,7 @@ public class DownloadWMSPlanImage {
                                 Main.map.mapView.repaint();
                             } else {
                                 // next steps follow in method finish() when 
download is terminated
-                                wmsLayer.joinRasterImages();
+                                wmsLayer.joinBufferedImages();
                             }
                         } else {
                             
/*JOptionPane.showMessageDialog(Main.parent,tr("Municipality vectorized !\n"+
@@ -84,6 +86,9 @@ public class DownloadWMSPlanImage {
             } catch (DuplicateLayerException e) {
                 // we tried to grab onto a duplicated layer (removed)
                 System.err.println("removed a duplicated layer");
+            } catch (WMSException e) {
+                errorMessage = e.getMessage();
+                grabber.getWmsInterface().resetCookie();
             }
         }
         
@@ -107,6 +112,8 @@ public class DownloadWMSPlanImage {
         this.wmsLayer = wmsLayer;
         this.bounds = bounds;
         task = Main.worker.submit(t, t);
+        if (errorMessage != null)
+            JOptionPane.showMessageDialog(Main.parent, errorMessage);
     }
 
     public boolean waitFinished() {
diff --git a/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java 
b/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
index 9bed6c8..0f2756c 100644
--- a/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
+++ b/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
@@ -5,6 +5,8 @@ import static org.openstreetmap.josm.tools.I18n.tr;
 
 import java.io.IOException;
 
+import javax.swing.JOptionPane;
+
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.gui.MapView;
@@ -13,21 +15,22 @@ import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 public class DownloadWMSVectorImage extends PleaseWaitRunnable {
 
     private WMSLayer wmsLayer;
+    private Bounds bounds;    
+    private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber;    
+    private static String errorMessage;
 
-    private Bounds bounds;
-
-    private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber;
-
-    public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds) {
+    public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds, boolean 
buildingsOnly) {
         super(tr("Downloading {0}", wmsLayer.getName()));
 
         this.wmsLayer = wmsLayer;
         this.bounds = bounds;
+        this.wmsLayer.setBuildingsOnly(buildingsOnly);
     }
 
     @Override
     public void realRun() throws IOException {
         progressMonitor.indeterminateSubTask(tr("Contacting WMS Server..."));
+        errorMessage = null;
         try {
             if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) {
                 boolean useFactor = true;
@@ -60,23 +63,29 @@ public class DownloadWMSVectorImage extends 
PleaseWaitRunnable {
         } catch (DuplicateLayerException e) {
             // we tried to grab onto a duplicated layer (removed)
             System.err.println("removed a duplicated layer");
+        } catch (WMSException e) {
+            errorMessage = e.getMessage();
+            grabber.getWmsInterface().resetCookie();
         }
     }
 
     @Override
     protected void cancel() {
         grabber.getWmsInterface().cancel();
+        if (wmsLayer != null)
+            wmsLayer.cancelled = true;
     }
 
     @Override
     protected void finish() {
     }
 
-    public static void download(WMSLayer wmsLayer) {
+    public static void download(WMSLayer wmsLayer, boolean buildingsOnly) {
         MapView mv = Main.map.mapView;
         Bounds bounds = new Bounds(mv.getLatLon(0, mv.getHeight()), 
mv.getLatLon(mv.getWidth(), 0));
 
-        Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds));
-
+        Main.worker.execute(new DownloadWMSVectorImage(wmsLayer, bounds, 
buildingsOnly));
+        if (errorMessage != null)
+            JOptionPane.showMessageDialog(Main.parent, errorMessage);
     }
 }
diff --git a/cadastre-fr/src/cadastre_fr/GeorefImage.java 
b/cadastre-fr/src/cadastre_fr/GeorefImage.java
index c67fe1a..b027861 100644
--- a/cadastre-fr/src/cadastre_fr/GeorefImage.java
+++ b/cadastre-fr/src/cadastre_fr/GeorefImage.java
@@ -336,7 +336,7 @@ public class GeorefImage implements Serializable, 
ImageObserver {
         int sy2 = (int)((max.getY() - adj1.getY())*getPixelPerNorth());
         int newWidth = Math.abs(sx2 - sx1);
         int newHeight = Math.abs(sy2 - sy1);
-        BufferedImage new_img = new BufferedImage(newWidth, newHeight, 
BufferedImage.TYPE_INT_ARGB);
+        BufferedImage new_img = new BufferedImage(newWidth, newHeight, 
image.getType());
         Graphics g = new_img.getGraphics();
         g.drawImage(image, 0, 0, newWidth-1, newHeight-1,
                 sx1, sy1, sx2, sy2,
diff --git a/cadastre-fr/src/cadastre_fr/ImageModifier.java 
b/cadastre-fr/src/cadastre_fr/ImageModifier.java
index 82b7700..2c46401 100644
--- a/cadastre-fr/src/cadastre_fr/ImageModifier.java
+++ b/cadastre-fr/src/cadastre_fr/ImageModifier.java
@@ -2,6 +2,7 @@
 // Some of the procedures below are imported from image4j.sourceforge.net, 
license LGPL.
 package cadastre_fr;
 
+import java.awt.Color;
 import java.awt.Transparency;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorConvertOp;
@@ -16,8 +17,13 @@ public abstract class ImageModifier {
 
     private static final long serialVersionUID = 1L;
 
+    protected int parcelColor = Color.RED.getRGB();
+    
     public BufferedImage bufferedImage;
 
+    public static int[] cRoofColors = new int[] {-197380, -592138};
+    public static int[] cBuilingFootColors = new int[] {-256};
+
     protected BufferedImage convert1(BufferedImage src) {
         IndexColorModel icm = new IndexColorModel(
             1, 2, new byte[] { (byte) 0, (byte) 0xFF },
@@ -106,4 +112,53 @@ public abstract class ImageModifier {
         cco.filter(src, dest);
         return dest;
       }
+
+    public boolean isBuildingColor(int rgb, boolean ignoreParcelColor) {
+        for (int i = 0; i < cBuilingFootColors.length; i++) 
+            if (rgb == cBuilingFootColors[i])
+                    return true;
+        if (ignoreParcelColor && (rgb == parcelColor))
+            return true;
+        return false;
+    }
+
+    public boolean isRoofColor(int rgb, boolean ignoreParcelColor) {
+        for (int i = 0; i < cRoofColors.length; i++) 
+            if (rgb == cRoofColors[i])
+                    return true;
+        if (ignoreParcelColor && (rgb == parcelColor))
+            return true;
+        return false;
+    }
+
+    public boolean isParcelColor(BufferedImage img, int x, int y) {
+        int rgb = img.getRGB(x, y);
+        return (rgb == parcelColor);
+    }
+
+    public boolean isBuildingOrRoofColor(BufferedImage img, int x, int y, 
boolean ignoreParcelColor) {
+        int rgb = img.getRGB(x, y);
+        boolean ret = isBuildingColor(rgb, ignoreParcelColor) || 
isRoofColor(rgb, ignoreParcelColor);
+        return ret;
+    }
+
+    public boolean isBuildingOrRoofColor(BufferedImage img, int x, int y, 
boolean colorType, boolean ignoreParcelColor) {
+        int rgb = img.getRGB(x, y);
+        boolean ret;
+        if (colorType)
+            ret = isBuildingColor(rgb, ignoreParcelColor);
+        else
+            ret = isRoofColor(rgb, ignoreParcelColor);
+        return ret;
+    }
+    
+    /**
+     * Checks if the rgb value is the black background color
+     * @param  
+     * @return
+     */
+    public boolean isBackgroundColor(BufferedImage img, int x, int y) {
+        return (img.getRGB(x, y) == -1);
+    }
+
 }
diff --git a/cadastre-fr/src/cadastre_fr/MenuActionBuildings.java 
b/cadastre-fr/src/cadastre_fr/MenuActionBuildings.java
index 857885b..91c29a2 100644
--- a/cadastre-fr/src/cadastre_fr/MenuActionBuildings.java
+++ b/cadastre-fr/src/cadastre_fr/MenuActionBuildings.java
@@ -12,26 +12,28 @@ import org.openstreetmap.josm.actions.JosmAction;
 
 public class MenuActionBuildings extends JosmAction {
     
-    public static String name = "Building footprints";
+    public static String name = "Grab buildings only";
 
     private static final long serialVersionUID = 1L;
-    private WMSLayer wmsLayer = null;
    
     public MenuActionBuildings() {
-        super(tr(name), "cadastre_small", tr("Extract building footprints"), 
null, false);
+        super(tr(name), "cadastre_small", tr("Grab building layer only"), 
null, false);
     }
 
-    public void actionPerformed(ActionEvent arg0) {
-        wmsLayer = WMSDownloadAction.getLayer();
-        if (wmsLayer != null) {
-            if (wmsLayer.isRaster()) {
+    public void actionPerformed(ActionEvent e) {
+        if (Main.map != null) {
+            if (CadastrePlugin.isCadastreProjection()) {
+                WMSLayer wmsLayer = WMSDownloadAction.getLayer();
+                if (wmsLayer != null)
+                    DownloadWMSVectorImage.download(wmsLayer, true);
+            } else {
                 JOptionPane.showMessageDialog(Main.parent,
-                        tr("Only on vectorized layers"), tr("Error"),
-                        JOptionPane.ERROR_MESSAGE);
-                return;
+                        tr("To enable the cadastre WMS plugin, change\n"
+                         + "the current projection to one of the cadastre\n"
+                         + "projections and retry"));
             }
-            DownloadSVGBuilding.download(wmsLayer);
-        }
+        } else
+            new MenuActionNewLocation().actionPerformed(e);
     }
 
 }
diff --git a/cadastre-fr/src/cadastre_fr/MenuActionGrab.java 
b/cadastre-fr/src/cadastre_fr/MenuActionGrab.java
index 24028d4..1bf802a 100644
--- a/cadastre-fr/src/cadastre_fr/MenuActionGrab.java
+++ b/cadastre-fr/src/cadastre_fr/MenuActionGrab.java
@@ -32,7 +32,7 @@ public class MenuActionGrab extends JosmAction {
             if (CadastrePlugin.isCadastreProjection()) {
                 WMSLayer wmsLayer = WMSDownloadAction.getLayer();
                 if (wmsLayer != null)
-                    DownloadWMSVectorImage.download(wmsLayer);
+                    DownloadWMSVectorImage.download(wmsLayer, false);
             } else {
                 JOptionPane.showMessageDialog(Main.parent,
                         tr("To enable the cadastre WMS plugin, change\n"
diff --git a/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java 
b/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
index c98b8cb..37baa94 100644
--- a/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
+++ b/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
@@ -12,7 +12,7 @@ import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.data.projection.Lambert;
 import org.openstreetmap.josm.data.projection.LambertCC9Zones;
-import org.openstreetmap.josm.data.projection.UTM_20N_France_DOM;
+import org.openstreetmap.josm.data.projection.UTM_France_DOM;
 import org.openstreetmap.josm.gui.layer.Layer;
 
 public class MenuActionLoadFromCache extends JosmAction {
@@ -39,7 +39,7 @@ public class MenuActionLoadFromCache extends JosmAction {
                 if ((ext.length() == 3 && ext.substring(0, 
CacheControl.cLambertCC9Z.length()).equals(CacheControl.cLambertCC9Z) &&
                     !(Main.proj instanceof LambertCC9Zones))
                     || (ext.length() == 4 && ext.substring(0, 
CacheControl.cUTM20N.length()).equals(CacheControl.cUTM20N) &&
-                            !(Main.proj instanceof UTM_20N_France_DOM))
+                            !(Main.proj instanceof UTM_France_DOM))
                     || (ext.length() == 1) && !(Main.proj instanceof Lambert)) 
{
                         JOptionPane.showMessageDialog(Main.parent, tr("{0} not 
allowed with the current projection", filename), tr("Error"), 
JOptionPane.ERROR_MESSAGE);
                         continue;
@@ -92,7 +92,7 @@ public class MenuActionLoadFromCache extends JosmAction {
                 
fc.addChoosableFileFilter(CacheFileLambert4ZoneFilter.filters[layoutZone]);
             else if (Main.proj instanceof LambertCC9Zones)
                 
fc.addChoosableFileFilter(CacheFileLambert9ZoneFilter.filters[layoutZone]);
-            else if (Main.proj instanceof UTM_20N_France_DOM)
+            else if (Main.proj instanceof UTM_France_DOM)
                 
fc.addChoosableFileFilter(CacheFileUTM20NFilter.filters[layoutZone]);
         }
         fc.setAcceptAllFileFilterUsed(false);
@@ -110,8 +110,8 @@ public class MenuActionLoadFromCache extends JosmAction {
             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();
+        else if (Main.proj instanceof UTM_France_DOM)
+            zone = ((UTM_France_DOM)Main.proj).getCurrentGeodesic();
         return zone;
     }
 }
diff --git a/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java 
b/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
index 9a26700..9ddc3f1 100644
--- a/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
+++ b/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java
@@ -16,7 +16,7 @@ import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.data.projection.Lambert;
 import org.openstreetmap.josm.data.projection.LambertCC9Zones;
-import org.openstreetmap.josm.data.projection.UTM_20N_France_DOM;
+import org.openstreetmap.josm.data.projection.UTM_France_DOM;
 import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.tools.GBC;
 
@@ -31,7 +31,7 @@ public class MenuActionNewLocation extends JosmAction {
     public void actionPerformed(ActionEvent e) {
         WMSLayer wmsLayer = addNewLayer(new ArrayList<WMSLayer>());
         if (wmsLayer != null)
-            DownloadWMSVectorImage.download(wmsLayer);
+            DownloadWMSVectorImage.download(wmsLayer, false);
     }
 
     public WMSLayer addNewLayer(ArrayList<WMSLayer> existingLayers) {
@@ -39,9 +39,9 @@ public class MenuActionNewLocation extends JosmAction {
         String codeDepartement = "";
         String codeCommune = "";
         boolean changeInterface = false;
-        JLabel labelSectionNewLocation = new JLabel(tr("Add a new layer"));
+        JLabel labelSectionNewLocation = new JLabel(tr("Add a new municipality 
layer"));
         JPanel p = new JPanel(new GridBagLayout());
-        JLabel labelLocation = new JLabel(tr("Location"));
+        JLabel labelLocation = new JLabel(tr("Commune"));
         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>"));
@@ -81,8 +81,8 @@ public class MenuActionNewLocation extends JosmAction {
                 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();
+            else if (Main.proj instanceof UTM_France_DOM)
+                zone = ((UTM_France_DOM)Main.proj).getCurrentGeodesic();
             wmsLayer = new WMSLayer(location, codeCommune, zone);
             CadastrePlugin.addWMSLayer(wmsLayer);
             System.out.println("Add new layer with Location:" + 
inputTown.getText());
diff --git a/cadastre-fr/src/cadastre_fr/SimplifyWay.java 
b/cadastre-fr/src/cadastre_fr/SimplifyWay.java
index 525126f..88d2826 100644
--- a/cadastre-fr/src/cadastre_fr/SimplifyWay.java
+++ b/cadastre-fr/src/cadastre_fr/SimplifyWay.java
@@ -2,25 +2,10 @@
 package cadastre_fr;
 
 import java.util.ArrayList;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
 
-import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.command.ChangeCommand;
-import org.openstreetmap.josm.command.Command;
-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.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Way;
-import static org.openstreetmap.josm.tools.I18n.trn;
-
- 
 
 /**
  * Imported from plugin UtilsPlugin
@@ -28,44 +13,11 @@ import static org.openstreetmap.josm.tools.I18n.trn;
  *
  */
 public class SimplifyWay {
-    public void simplifyWay(Way w, DataSet dataSet, double threshold) {
+    public void simplifyWay(Way w/*, DataSet dataSet*/, double threshold) {
         Way wnew = new Way(w);
 
-        int toI = wnew.getNodesCount() - 1;
-        List<OsmPrimitive> parents = new ArrayList<OsmPrimitive>();
-        for (int i = wnew.getNodesCount() - 1; i >= 0; i--) {
-            //CollectBackReferencesVisitor backRefsV = new 
CollectBackReferencesVisitor(dataSet, false);
-            //backRefsV.visit(wnew.getNode(i));
-           parents.addAll(w.getNode(i).getReferrers());
-            boolean used = false;
-            if (parents.size() == 1) {
-                used = Collections.frequency(w.getNodes(), wnew.getNode(i)) > 
1;
-            } else {
-                //backRefsV.getData().remove(w);
-                parents.remove(w);
-                used = !parents.isEmpty();
-            }
-            if (!used)
-                used = wnew.getNode(i).isTagged();
-
-            if (used) {
-                simplifyWayRange(wnew, i, toI, threshold);
-                toI = i;
-            }
-        }
-        simplifyWayRange(wnew, 0, toI, threshold);
-
-        HashSet<Node> delNodes = new HashSet<Node>();
-        delNodes.addAll(w.getNodes());
-        delNodes.removeAll(wnew.getNodes());
-
-        if (wnew.getNodesCount() != w.getNodesCount()) {
-            Collection<Command> cmds = new LinkedList<Command>();
-            cmds.add(new ChangeCommand(w, wnew));
-            cmds.add(new DeleteCommand(delNodes));
-            Main.main.undoRedo.add(new SequenceCommand(trn("Simplify Way 
(remove {0} node)", "Simplify Way (remove {0} nodes)", delNodes.size(), 
delNodes.size()), cmds));
-            Main.map.repaint();
-        }
+        simplifyWayRange(wnew, 0, wnew.getNodesCount() - 1, threshold);
+        w.setNodes(wnew.getNodes());
     }
 
     public void simplifyWayRange(Way wnew, int from, int to, double thr) {
diff --git a/cadastre-fr/src/cadastre_fr/VectorImageModifier.java 
b/cadastre-fr/src/cadastre_fr/VectorImageModifier.java
index 81249f7..461ee47 100644
--- a/cadastre-fr/src/cadastre_fr/VectorImageModifier.java
+++ b/cadastre-fr/src/cadastre_fr/VectorImageModifier.java
@@ -17,7 +17,9 @@ public class VectorImageModifier extends ImageModifier {
 
     private int backgroundPixel = 0;
 
-    public VectorImageModifier(BufferedImage bi) {
+    public VectorImageModifier() {super();}
+    
+    public VectorImageModifier(BufferedImage bi, boolean monocolor) {
         bufferedImage = bi;
         if (Main.pref.getBoolean("cadastrewms.backgroundTransparent"))
             makeTransparent();
@@ -25,7 +27,8 @@ public class VectorImageModifier extends ImageModifier {
             replaceBackground();
         if (Main.pref.getBoolean("cadastrewms.invertGrey"))
             invertGrey();
-        //bufferedImage = convert8(convert1(bufferedImage));
+        if (monocolor)
+            bufferedImage = convert8(convert4(bufferedImage));
     }
 
     /**
diff --git a/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java 
b/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
index f6af8eb..60f0777 100644
--- a/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
+++ b/cadastre-fr/src/cadastre_fr/WMSDownloadAction.java
@@ -3,36 +3,36 @@ package cadastre_fr;
 
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.awt.event.ActionEvent;
+//import java.awt.event.ActionEvent;
 import java.util.ArrayList;
 
 import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.actions.JosmAction;
+//import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.gui.layer.Layer;
 
-public class WMSDownloadAction extends JosmAction {
+public class WMSDownloadAction /*extends JosmAction */{
 
     private static final long serialVersionUID = 1L;
 
-    public WMSDownloadAction(String layerName) {
-        super(layerName, "wmsmenu", tr("Download WMS tile from 
{0}",layerName), null, false);
-    }
-
-    public void actionPerformed(ActionEvent e) {
-        DownloadWMSVectorImage.download(getLayer());
-    }
+//    public WMSDownloadAction(String layerName) {
+//        super(layerName, "wmsmenu", tr("Download WMS tile from 
{0}",layerName), null, false);
+//    }
+//
+//    public void actionPerformed(ActionEvent e) {
+//        DownloadWMSVectorImage.download(getLayer());
+//    }
 
     public static WMSLayer getLayer() {
         // check if we already have a layer created. if not, create; if yes, 
reuse.
         ArrayList<WMSLayer> existingWMSlayers = new ArrayList<WMSLayer>();
         if (Main.map != null) {
             Layer activeLayer = Main.map.mapView.getActiveLayer();
-            if (activeLayer instanceof WMSLayer)
+            if (activeLayer instanceof WMSLayer && 
!((WMSLayer)activeLayer).isBuildingsOnly())
                 return (WMSLayer) activeLayer;
             for (Layer l : Main.map.mapView.getAllLayers()) {
-                if (l instanceof WMSLayer) {
+                if (l instanceof WMSLayer && !((WMSLayer)l).isBuildingsOnly()) 
{
                     existingWMSlayers.add((WMSLayer)l);
                 }
             }
diff --git a/cadastre-fr/src/cadastre_fr/WMSException.java 
b/cadastre-fr/src/cadastre_fr/WMSException.java
new file mode 100644
index 0000000..3bca51f
--- /dev/null
+++ b/cadastre-fr/src/cadastre_fr/WMSException.java
@@ -0,0 +1,14 @@
+// License: GPL. v2 and later. Copyright 2008-2009 by Pieren 
<pier...@gmail.com> and others
+package cadastre_fr;
+
+class WMSException extends Exception {
+    private String message;
+    private static final long serialVersionUID = 1L;
+    public WMSException(String message) {
+        super();
+        this.message = message;
+    }
+    public String getMessage() {
+        return message;
+    }
+}
diff --git a/cadastre-fr/src/cadastre_fr/WMSLayer.java 
b/cadastre-fr/src/cadastre_fr/WMSLayer.java
index 7db4c44..d9127e9 100644
--- a/cadastre-fr/src/cadastre_fr/WMSLayer.java
+++ b/cadastre-fr/src/cadastre_fr/WMSLayer.java
@@ -18,6 +18,7 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Vector;
 
 import javax.swing.Icon;
@@ -59,6 +60,8 @@ public class WMSLayer extends Layer implements ImageObserver {
     protected final int serializeFormatVersion = 4;
     
     public static int currentFormat;
+    
+    private static final int cBBoxForBuildings = 50; // hard coded size of 
grabbed boxes for building layers
 
     private ArrayList<EastNorthBound> dividedBbox = new 
ArrayList<EastNorthBound>();
 
@@ -70,10 +73,11 @@ public class WMSLayer extends Layer implements 
ImageObserver {
 
     public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), 
new EastNorth(0,0));
 
-    private boolean isRaster = false;
+    public boolean cancelled;
 
+    private boolean isRaster = false;
     private boolean isAlreadyGeoreferenced = false;
-
+    private boolean buildingsOnly = false;
     public double X0, Y0, angle, fX, fY;
 
     // bbox of the georeferenced raster image (the nice horizontal and 
vertical box)
@@ -85,12 +89,13 @@ public class WMSLayer extends Layer implements 
ImageObserver {
     
     public boolean adjustModeEnabled;
 
+
     public WMSLayer() {
         this(tr("Blank Layer"), "", -1);
     }
 
     public WMSLayer(String location, String codeCommune, int lambertZone) {
-        super(buildName(location, codeCommune));
+        super(buildName(location, codeCommune, false));
         this.location = location;
         this.codeCommune = codeCommune;
         this.lambertZone = lambertZone;
@@ -112,15 +117,17 @@ public class WMSLayer extends Layer implements 
ImageObserver {
         System.out.println("Layer "+location+" destroyed");
     }
     
-    private static String buildName(String location, String codeCommune) {
+    private static String buildName(String location, String codeCommune, 
boolean buildingOnly) {
         String ret = new String(location.toUpperCase());
         if (codeCommune != null && !codeCommune.equals(""))
             ret += "(" + codeCommune + ")";
+        if (buildingOnly)
+            ret += ".b";
         return  ret;
     }
 
     private String rebuildName() {
-        return buildName(this.location.toUpperCase(), this.codeCommune);
+        return buildName(this.location.toUpperCase(), this.codeCommune, 
this.buildingsOnly);
     }
 
     public void grab(CadastreGrabber grabber, Bounds b) throws IOException {
@@ -128,20 +135,33 @@ public class WMSLayer extends Layer implements 
ImageObserver {
     }
     
     public void grab(CadastreGrabber grabber, Bounds b, boolean useFactor) 
throws IOException {
+        cancelled = false;
         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())));
+                        CadastrePreferenceSetting.DEFAULT_RASTER_DIVIDER)), 0);
+            } else if (buildingsOnly)
+                divideBbox(b, 5, cBBoxForBuildings);
+            else
+                divideBbox(b, 
Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString())), 0);
         } else
-            divideBbox(b, 1);
+            divideBbox(b, 1, 0);
 
+        int lastSavedImage = images.size();
         for (EastNorthBound n : dividedBbox) {
+            if (cancelled)
+                return;
             GeorefImage newImage;
             try {
-                newImage = grabber.grab(this, n.min, n.max);
+                if (buildingsOnly == false)
+                    newImage = grabber.grab(this, n.min, n.max);
+                else { // TODO
+                    GeorefImage buildings = grabber.grabBuildings(this, n.min, 
n.max);
+                    GeorefImage parcels = grabber.grabParcels(this, n.min, 
n.max);
+                    new BuildingsImageModifier(buildings, parcels);
+                    newImage = buildings;
+                }
             } catch (IOException e) {
                 System.out.println("Download action cancelled by user or 
server did not respond");
                 break;
@@ -165,9 +185,14 @@ public class WMSLayer extends Layer implements 
ImageObserver {
                 }
             }
             images.add(newImage);
-            saveToCache(newImage);
             Main.map.mapView.repaint();
         }
+        if (!cancelled) {
+            if (buildingsOnly)
+                joinBufferedImages();
+            for (int i=lastSavedImage; i < images.size(); i++)
+                saveToCache(images.get(i));
+        }
     }
 
     /**
@@ -176,10 +201,12 @@ public class WMSLayer extends Layer implements 
ImageObserver {
      * @param factor 1 = source bbox 1:1
      *               2 = source bbox divided by 2x2 smaller boxes
      *               3 = source bbox divided by 3x3 smaller boxes
-     *               4 = hard coded size of boxes (100 meters) rounded allowing
-     *                   grabbing of next contiguous zone
+     *               4 = configurable size from preferences (100 meters per 
default) rounded
+     *                   allowing grabbing of next contiguous zone
+     *               5 = use the size provided in next argument optionalSize
+     * @param optionalSize box size used when factor is 5.
      */
-    private void divideBbox(Bounds b, int factor) {
+    private void divideBbox(Bounds b, int factor, int optionalSize) {
         EastNorth lambertMin = Main.proj.latlon2eastNorth(b.getMin());
         EastNorth lambertMax = Main.proj.latlon2eastNorth(b.getMax());
         double minEast = lambertMin.east();
@@ -195,7 +222,7 @@ public class WMSLayer extends Layer implements 
ImageObserver {
             }
         } else {
             // divide to fixed size squares
-            int cSquare = 
Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100"));
+            int cSquare = factor == 4 ? 
Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100")) : 
optionalSize;   
             minEast = minEast - minEast % cSquare;
             minNorth = minNorth - minNorth % cSquare;
             for (int xEast = (int)minEast; xEast < lambertMax.east(); 
xEast+=cSquare)
@@ -297,7 +324,7 @@ public class WMSLayer extends Layer implements 
ImageObserver {
 
     public boolean isOverlapping(Bounds bounds) {
         GeorefImage georefImage =
-            new GeorefImage(new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB 
), // not really important
+            new GeorefImage(null,
             Main.proj.latlon2eastNorth(bounds.getMin()),
             Main.proj.latlon2eastNorth(bounds.getMax()));
         for (GeorefImage img : images) {
@@ -360,6 +387,15 @@ public class WMSLayer extends Layer implements 
ImageObserver {
         setName(rebuildName());
     }
 
+    public boolean isBuildingsOnly() {
+        return buildingsOnly;
+    }
+
+    public void setBuildingsOnly(boolean buildingsOnly) {
+        this.buildingsOnly = buildingsOnly;
+        setName(rebuildName());
+    }
+
     public boolean isRaster() {
         return isRaster;
     }
@@ -411,6 +447,7 @@ public class WMSLayer extends Layer implements 
ImageObserver {
         oos.writeObject(this.codeCommune); // String
         oos.writeInt(this.lambertZone);
         oos.writeBoolean(this.isRaster);
+        oos.writeBoolean(this.buildingsOnly);
         if (this.isRaster) {
             oos.writeDouble(this.rasterMin.getX());
             oos.writeDouble(this.rasterMin.getY());
@@ -442,6 +479,8 @@ public class WMSLayer extends Layer implements 
ImageObserver {
         this.setCodeCommune((String) ois.readObject());
         this.lambertZone = ois.readInt();
         this.setRaster(ois.readBoolean());
+        if (currentFormat >= 4)
+            this.setBuildingsOnly(ois.readBoolean());
         if (this.isRaster) {
             double X = ois.readDouble();
             double Y = ois.readDouble();
@@ -490,23 +529,27 @@ public class WMSLayer extends Layer implements 
ImageObserver {
 
     /**
      * Join the grabbed images into one single.
-     * Works only for images grabbed from non-georeferenced images (Feuilles 
cadastrales)(same amount of
-     * images in x and y)
      */
-    public void joinRasterImages() {
+    public void joinBufferedImages() {
         if (images.size() > 1) {
             EastNorth min = images.get(0).min;
             EastNorth max = images.get(images.size()-1).max;
             int oldImgWidth = images.get(0).image.getWidth();
             int oldImgHeight = images.get(0).image.getHeight();
-            int newWidth = oldImgWidth*(int)Math.sqrt(images.size());
-            int newHeight = oldImgHeight*(int)Math.sqrt(images.size());
-            BufferedImage new_img = new BufferedImage(newWidth, newHeight, 
BufferedImage.TYPE_INT_ARGB);
+            HashSet<Double> lx = new HashSet<Double>();
+            HashSet<Double> ly = new HashSet<Double>();
+            for (GeorefImage img : images) {
+                lx.add(img.min.east());
+                ly.add(img.min.north());
+            }
+            int newWidth = oldImgWidth*lx.size();
+            int newHeight = oldImgHeight*ly.size();
+            BufferedImage new_img = new BufferedImage(newWidth, newHeight, 
images.get(0).image.getType()/*BufferedImage.TYPE_INT_ARGB*/);
             Graphics g = new_img.getGraphics();
             // Coordinate (0,0) is on top,left corner where images are grabbed 
from bottom left
             int rasterDivider = (int)Math.sqrt(images.size());
-            for (int h = 0; h < rasterDivider; h++) {
-                for (int v = 0; v < rasterDivider; v++) {
+            for (int h = 0; h < lx.size(); h++) {
+                for (int v = 0; v < ly.size(); v++) {
                     int newx = h*oldImgWidth;
                     int newy = newHeight - oldImgHeight - (v*oldImgHeight);
                     int j = h*rasterDivider + v;
@@ -542,7 +585,7 @@ public class WMSLayer extends Layer implements 
ImageObserver {
         setCommuneBBox(new EastNorthBound(new EastNorth(0,0), new 
EastNorth(images.get(0).image.getWidth()-1,images.get(0).image.getHeight()-1)));
         rasterRatio = 
(rasterMax.getX()-rasterMin.getX())/(communeBBox.max.getX() - 
communeBBox.min.getX());
     }
-
+    
     public EastNorthBound getCommuneBBox() {
         return communeBBox;
     }
diff --git a/livegps/build.xml b/livegps/build.xml
index 9f4e8ee..e8a262a 100644
--- a/livegps/build.xml
+++ b/livegps/build.xml
@@ -17,7 +17,7 @@
 **    > ant  install
 **
 ** To build against the core in ../../core, create a correct manifest and 
deploy to
-** SVN, 
+** SVN,
 **    set the properties commit.message and plugin.main.version
 ** and run
 **    > ant  publish
@@ -27,8 +27,8 @@
 <project name="livegps" default="dist" basedir=".">
 
        <property name="commit.message" value="Changed the constructor 
signature of the plugin main class" />
-       <property name="plugin.main.version" value="2907" />
-       
+       <property name="plugin.main.version" value="3119" />
+
 
        <property name="josm"                   
location="../../core/dist/josm-custom.jar"/>
        <property name="plugin.dist.dir"        value="../../dist"/>
@@ -88,10 +88,10 @@
 
 
        <!--
-                ************************** Publishing the plugin 
*********************************** 
+                ************************** Publishing the plugin 
***********************************
                -->
        <!--
-               ** extracts the JOSM release for the JOSM version in ../core 
and saves it in the 
+               ** extracts the JOSM release for the JOSM version in ../core 
and saves it in the
                ** property ${coreversion.info.entry.revision}
                **
                -->
@@ -140,17 +140,17 @@
        </target>
 
        <!--
-               ** commits the plugin.jar 
+               ** commits the plugin.jar
                -->
        <target name="commit-dist">
                <echo>
        ***** Properties of published ${plugin.jar} *****
-       Commit message    : '${commit.message}'                                 
+       Commit message    : '${commit.message}'
        Plugin-Mainversion: ${plugin.main.version}
        JOSM build version: ${coreversion.info.entry.revision}
        Plugin-Version    : ${version.entry.commit.revision}
-       ***** / Properties of published ${plugin.jar} *****                     
                
-                                               
+       ***** / Properties of published ${plugin.jar} *****
+
        Now commiting ${plugin.jar} ...
        </echo>
                <exec append="true" output="svn.log" executable="svn" 
failifexecutionfails="false">
diff --git a/livegps/src/livegps/AppendableGpxTrackSegment.java 
b/livegps/src/livegps/AppendableGpxTrackSegment.java
index 43e2137..dd786d6 100644
--- a/livegps/src/livegps/AppendableGpxTrackSegment.java
+++ b/livegps/src/livegps/AppendableGpxTrackSegment.java
@@ -54,4 +54,9 @@ public class AppendableGpxTrackSegment implements 
GpxTrackSegment {
                return length;
        }
 
+       @Override
+       public int getUpdateCount() {
+               return size;
+       }
+
 }
diff --git a/livegps/src/livegps/LiveGpsAcquirer.java 
b/livegps/src/livegps/LiveGpsAcquirer.java
index 0fac800..fc8c048 100644
--- a/livegps/src/livegps/LiveGpsAcquirer.java
+++ b/livegps/src/livegps/LiveGpsAcquirer.java
@@ -27,7 +27,7 @@ public class LiveGpsAcquirer implements Runnable {
        private PropertyChangeEvent lastDataEvent;
 
        /**
-        * Constructor, initializes the configurable settings. 
+        * Constructor, initializes the configurable settings.
         */
        public LiveGpsAcquirer() {
                super();
@@ -203,6 +203,7 @@ public class LiveGpsAcquirer implements Runnable {
                                                                course = 
Float.NaN;
                                                                haveFix = true;
                                                        }
+                                                       break;
                                                default:
                                                        // not interested
                                                }
diff --git a/livegps/src/livegps/LiveGpsLayer.java 
b/livegps/src/livegps/LiveGpsLayer.java
index c358481..41716ec 100644
--- a/livegps/src/livegps/LiveGpsLayer.java
+++ b/livegps/src/livegps/LiveGpsLayer.java
@@ -29,7 +29,6 @@ public class LiveGpsLayer extends GpxLayer implements 
PropertyChangeListener {
        private final AppendableGpxTrackSegment trackSegment;
        float speed;
        float course;
-       String status;
        // JLabel lbl;
        boolean autocenter;
        private SimpleDateFormat dateFormat = new SimpleDateFormat(
diff --git a/livegps/src/livegps/LiveGpsPlugin.java 
b/livegps/src/livegps/LiveGpsPlugin.java
index c946328..328b6b7 100644
--- a/livegps/src/livegps/LiveGpsPlugin.java
+++ b/livegps/src/livegps/LiveGpsPlugin.java
@@ -31,7 +31,6 @@ public class LiveGpsPlugin extends Plugin implements 
LayerChangeListener {
        private Thread acquirerThread = null;
        private JMenu lgpsmenu;
        private JCheckBoxMenuItem lgpscapture;
-       private JMenuItem lgpscenter;
        private JCheckBoxMenuItem lgpsautocenter;
        private LiveGpsDialog lgpsdialog;
        List<PropertyChangeListener> listenerQueue;
diff --git a/livegps/src/livegps/SingleSegmentGpxTrack.java 
b/livegps/src/livegps/SingleSegmentGpxTrack.java
index 3cded20..68a58a3 100644
--- a/livegps/src/livegps/SingleSegmentGpxTrack.java
+++ b/livegps/src/livegps/SingleSegmentGpxTrack.java
@@ -35,4 +35,9 @@ public class SingleSegmentGpxTrack implements GpxTrack {
                return trackSegment.length();
        }
 
+       @Override
+       public int getUpdateCount() {
+               return trackSegment.getUpdateCount();
+       }
+
 }
diff --git a/svn-info.xml b/svn-info.xml
index ffc5a4c..5fb6705 100644
--- a/svn-info.xml
+++ b/svn-info.xml
@@ -3,16 +3,16 @@
 <entry
    kind="dir"
    path="plugins"
-   revision="20740">
+   revision="21271">
 <url>http://svn.openstreetmap.org/applications/editors/josm/plugins</url>
 <repository>
 <root>http://svn.openstreetmap.org</root>
 <uuid>b9d5c4c9-76e1-0310-9c85-f3177eceb1e4</uuid>
 </repository>
 <commit
-   revision="20736">
-<author>guggis</author>
-<date>2010-03-29T17:15:59.216604Z</date>
+   revision="21258">
+<author>guardian</author>
+<date>2010-05-13T11:33:01.904594Z</date>
 </commit>
 </entry>
 </info>
diff --git a/wmsplugin/build.xml b/wmsplugin/build.xml
index fb132ad..0be9d47 100644
--- a/wmsplugin/build.xml
+++ b/wmsplugin/build.xml
@@ -27,7 +27,7 @@
 <project name="wmsplugin" default="dist" basedir=".">
 
 
-       <property name="commit.message" value="Uses new constructor for plugin" 
/>
+       <property name="commit.message" value="filter control characters that 
are send to the consol and create morse code effect" />
        <property name="plugin.main.version" value="2830" />
 
 
diff --git a/wmsplugin/src/wmsplugin/WMSGrabber.java 
b/wmsplugin/src/wmsplugin/WMSGrabber.java
index 2fb7f2e..47529b4 100644
--- a/wmsplugin/src/wmsplugin/WMSGrabber.java
+++ b/wmsplugin/src/wmsplugin/WMSGrabber.java
@@ -26,6 +26,7 @@ import org.openstreetmap.josm.data.ProjectionBounds;
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.projection.Mercator;
+import org.openstreetmap.josm.data.Version;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.io.CacheFiles;
 import org.openstreetmap.josm.io.OsmTransferException;
@@ -185,6 +186,7 @@ public class WMSGrabber extends Grabber {
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         if(layer.cookies != null && !layer.cookies.equals(""))
             conn.setRequestProperty("Cookie", layer.cookies);
+        conn.setRequestProperty("User-Agent", 
Main.pref.get("wmsplugin.user_agent", Version.getInstance().getAgentString()));
         
conn.setConnectTimeout(Main.pref.getInteger("wmsplugin.timeout.connect", 30) * 
1000);
         conn.setReadTimeout(Main.pref.getInteger("wmsplugin.timeout.read", 30) 
* 1000);
 
@@ -209,7 +211,8 @@ public class WMSGrabber extends Grabber {
 
         String line = null;
         while( (line = br.readLine()) != null) {
-            exception.append(line);
+            // filter non-ASCII characters and control characters
+            exception.append(line.replaceAll("[^\\p{Print}]", ""));
             exception.append('\n');
         }
         return exception.toString();

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-grass/josm-plugins.git

_______________________________________________
Pkg-grass-devel mailing list
Pkg-grass-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

Reply via email to