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 5b75e147a08104b821fbf7c567d9c73c02412aab Author: David Paleino <da...@debian.org> Date: Tue Mar 8 09:49:24 2011 +0100 Imported Upstream version 0.0.svn25527 --- DirectUpload/build.xml | 4 +- cadastre-fr/build.xml | 4 +- cadastre-fr/src/cadastre_fr/Address.java | 110 ++++++---- cadastre-fr/src/cadastre_fr/CacheControl.java | 3 +- cadastre-fr/src/cadastre_fr/CadastreInterface.java | 2 + cadastre-fr/src/cadastre_fr/CadastrePlugin.java | 10 +- .../src/cadastre_fr/DownloadSVGBuilding.java | 7 +- cadastre-fr/src/cadastre_fr/DownloadSVGTask.java | 7 +- .../src/cadastre_fr/DownloadWMSPlanImage.java | 21 +- .../src/cadastre_fr/DownloadWMSVectorImage.java | 17 +- cadastre-fr/src/cadastre_fr/GeorefImage.java | 17 +- cadastre-fr/src/cadastre_fr/GrabThread.java | 237 +++++++++++++++++++++ .../src/cadastre_fr/MenuActionCancelGrab.java | 29 +++ .../src/cadastre_fr/MenuActionGrabPlanImage.java | 20 +- .../src/cadastre_fr/MenuActionLoadFromCache.java | 2 +- .../src/cadastre_fr/MenuActionNewLocation.java | 5 - .../src/cadastre_fr/MenuActionResetCookie.java | 2 +- .../src/cadastre_fr/MenuActionSaveRasterAs.java | 2 +- cadastre-fr/src/cadastre_fr/WMSAdjustAction.java | 6 +- cadastre-fr/src/cadastre_fr/WMSLayer.java | 196 +++++++++-------- colorscheme/build.xml | 2 +- editgpx/build.xml | 2 +- .../josm/plugins/editgpx/data/EditGpxTrack.java | 10 +- lakewalker/build.xml | 4 +- livegps/build.xml | 4 +- measurement/build.xml | 4 +- .../plugins/measurement/MeasurementDialog.java | 8 +- .../josm/plugins/measurement/MeasurementLayer.java | 20 +- openvisible/build.xml | 4 +- routing/build.xml | 2 +- surveyor/build.xml | 2 +- svn-info.xml | 8 +- 32 files changed, 535 insertions(+), 236 deletions(-) diff --git a/DirectUpload/build.xml b/DirectUpload/build.xml index 16c1ea7..f1c96cd 100644 --- a/DirectUpload/build.xml +++ b/DirectUpload/build.xml @@ -27,7 +27,7 @@ <project name="DirectUpload" default="dist" basedir="."> <property name="commit.message" value="applied JOSM Ticket 4498 (patch by ax) - oauth support for gpx upload (I accidentally committed parts of the path in [24236])" /> - <property name="plugin.main.version" value="3338" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> <property name="plugin.dist.dir" value="../../dist"/> @@ -54,7 +54,7 @@ <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.DirectUpload.UploadDataGuiPlugin"/> <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> <attribute name="Plugin-Description" value="This plugin directly upload GPS Traces from current active layer in JOSM to openstreetmap.org."/> - <attribute name="Plugin-Icon" value="images/UploadAction.png"/> + <attribute name="Plugin-Icon" value="images/UploadAction.png"/> <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/User:Subhodip/GSoC_Doc#DirectUpload_Plugin_in_JOSM_:"/> <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> diff --git a/cadastre-fr/build.xml b/cadastre-fr/build.xml index f8d743f..4d6175f 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="3408" /> + <property name="plugin.main.version" value="3835" /> <target name="init"> <mkdir dir="${plugin.build.dir}"/> @@ -55,7 +55,7 @@ <attribute name="Plugin-Class" value="cadastre_fr.CadastrePlugin"/> <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> <attribute name="Plugin-Description" value="A special handler for the French land registry WMS server."/> - <attribute name="Plugin-Icon" value="images/preferences/cadastrewms.gif"/> + <attribute name="Plugin-Icon" value="images/preferences/cadastrewms.gif"/> <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/FR:JOSM/Fr:Plugin/Cadastre"/> <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> <attribute name="Plugin-Stage" value="60"/> diff --git a/cadastre-fr/src/cadastre_fr/Address.java b/cadastre-fr/src/cadastre_fr/Address.java index d0cff1d..71710d2 100644 --- a/cadastre-fr/src/cadastre_fr/Address.java +++ b/cadastre-fr/src/cadastre_fr/Address.java @@ -131,38 +131,50 @@ public class Address extends MapMode implements MouseListener, MouseMotionListen // click on existing node setNewSelection(currentMouseNode); String num = currentMouseNode.get(tagHouseNumber); - if (num != null) { - try { - // add new address - Integer.parseInt(num); - inputNumber.setText(num); - applyInputNumberChange(); - } catch (NumberFormatException en) { - System.out.println("Unable to parse house number \"" + num + "\""); - } - } - if (currentMouseNode.get(tagHouseStreet) != null) { - inputStreet.setText(currentMouseNode.get(tagHouseStreet)); - if (ctrl) { - Collection<Command> cmds = new LinkedList<Command>(); - addAddrToPrimitive(currentMouseNode, cmds); - if (num == null) + if (num != null // + && currentMouseNode.get(tagHouseStreet) == null // + && findWayInRelationAddr(currentMouseNode) == null // + && !inputStreet.getText().equals("")) { + // address already present but not linked to a street + Collection<Command> cmds = new LinkedList<Command>(); + addStreetNameOrRelation(currentMouseNode, cmds); + Command c = new SequenceCommand("Add node address", cmds); + Main.main.undoRedo.add(c); + setNewSelection(currentMouseNode); + } else { + if (num != null) { + try { + // add new address + Integer.parseInt(num); + inputNumber.setText(num); applyInputNumberChange(); + } catch (NumberFormatException en) { + System.out.println("Unable to parse house number \"" + num + "\""); + } } - setSelectedWay((Way)null); - } else { - // check if the node belongs to an associatedStreet relation - Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode); - if (wayInRelationAddr == null) { - // node exists but doesn't carry address information : add tags like a new node + if (currentMouseNode.get(tagHouseStreet) != null) { + inputStreet.setText(currentMouseNode.get(tagHouseStreet)); if (ctrl) { - applyInputNumberChange(); + Collection<Command> cmds = new LinkedList<Command>(); + addAddrToPrimitive(currentMouseNode, cmds); + if (num == null) + applyInputNumberChange(); } - Collection<Command> cmds = new LinkedList<Command>(); - addAddrToPrimitive(currentMouseNode, cmds); + setSelectedWay((Way)null); } else { - inputStreet.setText(wayInRelationAddr.get(tagHighwayName)); - setSelectedWay(wayInRelationAddr); + // check if the node belongs to an associatedStreet relation + Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode); + if (wayInRelationAddr == null) { + // node exists but doesn't carry address information : add tags like a new node + if (ctrl) { + applyInputNumberChange(); + } + Collection<Command> cmds = new LinkedList<Command>(); + addAddrToPrimitive(currentMouseNode, cmds); + } else { + inputStreet.setText(wayInRelationAddr.get(tagHighwayName)); + setSelectedWay(wayInRelationAddr); + } } } } else { @@ -233,7 +245,29 @@ public class Address extends MapMode implements MouseListener, MouseMotionListen } } - cmds.add(new ChangePropertyCommand(osm, tagHouseNumber, inputNumber.getText())); + cmds.add(new ChangePropertyCommand(osm, tagHouseNumber, inputNumber.getText())); + addStreetNameOrRelation(osm, cmds); + try { + applyInputNumberChange(); + Command c = new SequenceCommand("Add node address", cmds); + Main.main.undoRedo.add(c); + setNewSelection(osm); + } catch (NumberFormatException en) { + System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\""); + } + } + + private Relation findRelationAddr(Way w) { + List<OsmPrimitive> l = w.getReferrers(); + for (OsmPrimitive osm : l) { + if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) { + return (Relation)osm; + } + } + return null; + } + + private void addStreetNameOrRelation(OsmPrimitive osm, Collection<Command> cmds) { if (Main.pref.getBoolean("cadastrewms.addr.dontUseRelation", false)) { cmds.add(new ChangePropertyCommand(osm, tagHouseStreet, inputStreet.getText())); } else if (selectedWay != null) { @@ -254,26 +288,8 @@ public class Address extends MapMode implements MouseListener, MouseMotionListen cmds.add(new AddCommand(newRel)); } } - try { - applyInputNumberChange(); - Command c = new SequenceCommand("Add node address", cmds); - Main.main.undoRedo.add(c); - setNewSelection(osm); - } catch (NumberFormatException en) { - System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\""); - } - } - - private Relation findRelationAddr(Way w) { - List<OsmPrimitive> l = w.getReferrers(); - for (OsmPrimitive osm : l) { - if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) { - return (Relation)osm; - } - } - return null; } - + private Node createNewNode(MouseEvent e, Collection<Command> cmds) { // DrawAction.mouseReleased() but without key modifiers Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY())); diff --git a/cadastre-fr/src/cadastre_fr/CacheControl.java b/cadastre-fr/src/cadastre_fr/CacheControl.java index 770c7ea..ca14762 100644 --- a/cadastre-fr/src/cadastre_fr/CacheControl.java +++ b/cadastre-fr/src/cadastre_fr/CacheControl.java @@ -152,7 +152,7 @@ public class CacheControl implements Runnable { } if (successfulRead && wmsLayer.isRaster()) { // serialized raster bufferedImage hangs-up on Java6. Recreate them here - wmsLayer.images.get(0).image = RasterImageModifier.fixRasterImage(wmsLayer.images.get(0).image); + wmsLayer.getImage(0).image = RasterImageModifier.fixRasterImage(wmsLayer.getImage(0).image); } return successfulRead; } @@ -171,7 +171,6 @@ public class CacheControl implements Runnable { public synchronized void run() { for (;;) { imagesLock.lock(); - //ArrayList<GeorefImage> images = new ArrayList<GeorefImage>(imagesToSave); int size = imagesToSave.size(); imagesLock.unlock(); if (size > 0) { diff --git a/cadastre-fr/src/cadastre_fr/CadastreInterface.java b/cadastre-fr/src/cadastre_fr/CadastreInterface.java index dafa977..0af2e74 100644 --- a/cadastre-fr/src/cadastre_fr/CadastreInterface.java +++ b/cadastre-fr/src/cadastre_fr/CadastreInterface.java @@ -72,6 +72,8 @@ public class CadastreInterface { boolean isCookieExpired = isCookieExpired(); if (wmsLayer.getName().equals(lastWMSLayerName) && !isCookieExpired) return true; + if (!wmsLayer.getName().equals(lastWMSLayerName)) + interfaceRef = null; // open the session with the French Cadastre web front end downloadCancelled = false; try { diff --git a/cadastre-fr/src/cadastre_fr/CadastrePlugin.java b/cadastre-fr/src/cadastre_fr/CadastrePlugin.java index e8cbd76..05e7cad 100644 --- a/cadastre-fr/src/cadastre_fr/CadastrePlugin.java +++ b/cadastre-fr/src/cadastre_fr/CadastrePlugin.java @@ -111,20 +111,22 @@ import org.openstreetmap.josm.data.projection.*; * 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. + * 2.0 07-Jul-2010 - update projection for "La Reunion" departement to RGR92, UTM40S. * - add 'departement' as option in the municipality selection * - fixed bug in cache directory size control (and disabled by default) * - add map mode for addressing * - from Nicolas Dumoulin: * - add "tableau d'assemblage" in raster images for georeferencing (as option) + * 2.1 14-Jan-2011 - add GrabThread moving the grab to a separate thread + * - the divided BBox mode starts from the central square and loads the next in a spiral + * - move the grabber from CadastrPlugin singleton to each wmsLayer instance to allow grabbing + * of multiple municipalities in parallel. */ public class CadastrePlugin extends Plugin { - static String VERSION = "2.0"; + static String VERSION = "2.1"; static JMenu cadastreJMenu; - public static CadastreGrabber cadastreGrabber = new CadastreGrabber(); - public static String source = ""; // true if the checkbox "auto-sourcing" is set in the plugin menu diff --git a/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java b/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java index 7ac3339..121d804 100644 --- a/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java +++ b/cadastre-fr/src/cadastre_fr/DownloadSVGBuilding.java @@ -36,7 +36,6 @@ import org.openstreetmap.josm.io.ProgressInputStream; public class DownloadSVGBuilding extends PleaseWaitRunnable { private WMSLayer wmsLayer; - private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber; private CadastreInterface wmsInterface; private String svg = null; private static EastNorthBound currentView = null; @@ -48,7 +47,7 @@ public class DownloadSVGBuilding extends PleaseWaitRunnable { super(tr("Downloading {0}", wmsLayer.getName())); this.wmsLayer = wmsLayer; - this.wmsInterface = grabber.getWmsInterface(); + this.wmsInterface = wmsLayer.grabber.getWmsInterface(); } @Override @@ -69,13 +68,13 @@ public class DownloadSVGBuilding extends PleaseWaitRunnable { System.err.println("removed a duplicated layer"); } catch (WMSException e) { errorMessage = e.getMessage(); - grabber.getWmsInterface().resetCookie(); + wmsLayer.grabber.getWmsInterface().resetCookie(); } } @Override protected void cancel() { - grabber.getWmsInterface().cancel(); + wmsLayer.grabber.getWmsInterface().cancel(); } @Override diff --git a/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java b/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java index 925d4e7..b30e816 100644 --- a/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java +++ b/cadastre-fr/src/cadastre_fr/DownloadSVGTask.java @@ -41,7 +41,6 @@ import org.openstreetmap.josm.io.ProgressInputStream; public class DownloadSVGTask extends PleaseWaitRunnable { private WMSLayer wmsLayer; - private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber; private CadastreInterface wmsInterface; private String svg = null; private EastNorthBound viewBox = null; @@ -51,7 +50,7 @@ public class DownloadSVGTask extends PleaseWaitRunnable { super(tr("Downloading {0}", wmsLayer.getName())); this.wmsLayer = wmsLayer; - this.wmsInterface = grabber.getWmsInterface(); + this.wmsInterface = wmsLayer.grabber.getWmsInterface(); } @Override @@ -74,13 +73,13 @@ public class DownloadSVGTask extends PleaseWaitRunnable { System.err.println("removed a duplicated layer"); } catch (WMSException e) { errorMessage = e.getMessage(); - grabber.getWmsInterface().resetCookie(); + wmsLayer.grabber.getWmsInterface().resetCookie(); } } @Override protected void cancel() { - grabber.getWmsInterface().cancel(); + wmsLayer.grabber.getWmsInterface().cancel(); } @Override diff --git a/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java b/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java index c31c982..27f45a2 100644 --- a/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java +++ b/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java @@ -23,7 +23,6 @@ public class DownloadWMSPlanImage { private static String errorMessage; private class Task extends PleaseWaitRunnable { - private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber; public Task(WMSLayer wmsLayer, Bounds bounds) { super(tr("Downloading {0}", wmsLayer.getName())); } @@ -33,8 +32,8 @@ public class DownloadWMSPlanImage { progressMonitor.indeterminateSubTask(tr("Contacting cadastre WMS ...")); errorMessage = null; try { - if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) { - if (!wmsLayer.images.isEmpty()) { + if (wmsLayer.grabber.getWmsInterface().retrieveInterface(wmsLayer)) { + if (!wmsLayer.getImages().isEmpty()) { //JOptionPane.showMessageDialog(Main.parent,tr("Image already loaded")); JOptionPane pane = new JOptionPane( tr("Image already loaded") @@ -45,12 +44,12 @@ public class DownloadWMSPlanImage { dialog.setVisible(true); // till here dontGeoreference = true; - } else if (grabber.getWmsInterface().downloadCancelled){ + } else if (wmsLayer.grabber.getWmsInterface().downloadCancelled){ // do nothing } else { // first time we grab an image for this layer if (CacheControl.cacheEnabled) { - if (wmsLayer.getCacheControl().loadCacheIfExist()) { + if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) { dontGeoreference = true; Main.map.mapView.repaint(); return; @@ -58,12 +57,12 @@ public class DownloadWMSPlanImage { } if (wmsLayer.isRaster()) { // set raster image commune bounding box based on current view (before adjustment) - grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer); + wmsLayer.grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer); wmsLayer.setRasterBounds(bounds); // grab new images from wms server into active layer - wmsLayer.grab(grabber, bounds); - if (grabber.getWmsInterface().downloadCancelled) { - wmsLayer.images.clear(); + wmsLayer.grab(bounds); + if (wmsLayer.grabber.getWmsInterface().downloadCancelled) { + wmsLayer.clearImages(); Main.map.mapView.repaint(); } else { // next steps follow in method finish() when download is terminated @@ -88,13 +87,13 @@ public class DownloadWMSPlanImage { System.err.println("removed a duplicated layer"); } catch (WMSException e) { errorMessage = e.getMessage(); - grabber.getWmsInterface().resetCookie(); + wmsLayer.grabber.getWmsInterface().resetCookie(); } } @Override protected void cancel() { - grabber.getWmsInterface().cancel(); + wmsLayer.grabber.getWmsInterface().cancel(); dontGeoreference = true; } diff --git a/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java b/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java index 2e2cb34..cac4311 100644 --- a/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java +++ b/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java @@ -16,7 +16,6 @@ public class DownloadWMSVectorImage extends PleaseWaitRunnable { private WMSLayer wmsLayer; private Bounds bounds; - private CadastreGrabber grabber = CadastrePlugin.cadastreGrabber; private static String errorMessage; public DownloadWMSVectorImage(WMSLayer wmsLayer, Bounds bounds) { @@ -31,11 +30,11 @@ public class DownloadWMSVectorImage extends PleaseWaitRunnable { progressMonitor.indeterminateSubTask(tr("Contacting WMS Server...")); errorMessage = null; try { - if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) { - if (wmsLayer.images.isEmpty()) { + if (wmsLayer.grabber.getWmsInterface().retrieveInterface(wmsLayer)) { + if (wmsLayer.getImages().isEmpty()) { // first time we grab an image for this layer if (CacheControl.cacheEnabled) { - if (wmsLayer.getCacheControl().loadCacheIfExist()) { + if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) { Main.map.mapView.zoomTo(wmsLayer.getCommuneBBox().toBounds()); //Main.map.mapView.repaint(); return; @@ -49,26 +48,26 @@ public class DownloadWMSVectorImage extends PleaseWaitRunnable { return; } else { // set vectorized commune bounding box by opening the standard web window - grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer); + wmsLayer.grabber.getWmsInterface().retrieveCommuneBBox(wmsLayer); } } // grab new images from wms server into active layer - wmsLayer.grab(grabber, bounds); + wmsLayer.grab(bounds); } } 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(); + wmsLayer.grabber.getWmsInterface().resetCookie(); } } @Override protected void cancel() { - grabber.getWmsInterface().cancel(); + wmsLayer.grabber.getWmsInterface().cancel(); if (wmsLayer != null) - wmsLayer.cancelled = true; + wmsLayer.grabThread.setCancelled(true); } @Override diff --git a/cadastre-fr/src/cadastre_fr/GeorefImage.java b/cadastre-fr/src/cadastre_fr/GeorefImage.java index 5560880..a3dd8aa 100644 --- a/cadastre-fr/src/cadastre_fr/GeorefImage.java +++ b/cadastre-fr/src/cadastre_fr/GeorefImage.java @@ -22,7 +22,7 @@ import javax.imageio.ImageIO; import org.openstreetmap.josm.data.coor.EastNorth; import org.openstreetmap.josm.gui.NavigatableComponent; -public class GeorefImage implements Serializable, ImageObserver { +public class GeorefImage implements Serializable, ImageObserver, Cloneable { private static final long serialVersionUID = 1L; // bbox of the georeferenced image (the nice horizontal and vertical box) @@ -45,7 +45,7 @@ public class GeorefImage implements Serializable, ImageObserver { public GeorefImage(BufferedImage img, EastNorth min, EastNorth max) { image = img; - + this.min = min; this.max = max; this.orgRaster[0] = min; @@ -140,9 +140,9 @@ public class GeorefImage implements Serializable, ImageObserver { */ } } - g.drawImage(image, minPt.x, maxPt.y, maxPt.x, minPt.y, // dest - 0, 0, image.getWidth(), image.getHeight(), // src - null); + g.drawImage(image, minPt.x, maxPt.y, maxPt.x, minPt.y, // dest + 0, 0, image.getWidth(), image.getHeight(), // src + null); if (backgroundTransparent && transparency < 1.0f) g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); } @@ -236,8 +236,11 @@ public class GeorefImage implements Serializable, ImageObserver { out.writeDouble(orgCroppedRaster[1].getX()); out.writeDouble(orgCroppedRaster[1].getY()); out.writeDouble(orgCroppedRaster[2].getX()); out.writeDouble(orgCroppedRaster[2].getY()); out.writeDouble(orgCroppedRaster[3].getX()); out.writeDouble(orgCroppedRaster[3].getY()); - out.writeInt(imageOriginalHeight); - out.writeInt(imageOriginalWidth); + // Write image as a format 3 if cache was loaded with this format to avoid incompatibilities. + if (WMSLayer.currentFormat >= 4) { + out.writeInt(imageOriginalHeight); + out.writeInt(imageOriginalWidth); + } ImageIO.write(image, "png", ImageIO.createImageOutputStream(out)); } diff --git a/cadastre-fr/src/cadastre_fr/GrabThread.java b/cadastre-fr/src/cadastre_fr/GrabThread.java new file mode 100644 index 0000000..65c5b27 --- /dev/null +++ b/cadastre-fr/src/cadastre_fr/GrabThread.java @@ -0,0 +1,237 @@ +// License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pier...@gmail.com> and others +package cadastre_fr; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Point; +import java.io.IOException; +import java.util.ArrayList; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.openstreetmap.josm.Main; +import org.openstreetmap.josm.data.coor.EastNorth; +import org.openstreetmap.josm.gui.MapView; +import org.openstreetmap.josm.io.OsmTransferException; + +public class GrabThread extends Thread { + + private boolean cancelled; + + private CadastreGrabber grabber; + + private WMSLayer wmsLayer; + + private Lock lockImagesToGrag = new ReentrantLock(); + + private ArrayList<EastNorthBound> imagesToGrab = new ArrayList<EastNorthBound>(); + + private CacheControl cacheControl = null; + + private EastNorthBound currentGrabImage; + + private Lock lockCurrentGrabImage = new ReentrantLock(); + + /** + * Call directly grabber for raster images or prepare thread for vector images + * @param moreImages + */ + public void addImages(ArrayList<EastNorthBound> moreImages) { + lockImagesToGrag.lock(); + imagesToGrab.addAll(moreImages); + lockImagesToGrag.unlock(); + synchronized(this) { + this.notify(); + } + System.out.println("Added " + moreImages.size() + " to the grab thread"); + if (wmsLayer.isRaster()) { + waitNotification(); + } + } + + public int getImagesToGrabSize() { + lockImagesToGrag.lock(); + int size = imagesToGrab.size(); + lockImagesToGrag.unlock(); + return size; + } + + public ArrayList<EastNorthBound> getImagesToGrabCopy() { + ArrayList<EastNorthBound> copyList = new ArrayList<EastNorthBound>(); + lockImagesToGrag.lock(); + for (EastNorthBound img : imagesToGrab) { + EastNorthBound imgCpy = new EastNorthBound(img.min, img.max); + copyList.add(imgCpy); + } + lockImagesToGrag.unlock(); + return copyList; + } + + public void clearImagesToGrab() { + lockImagesToGrag.lock(); + imagesToGrab.clear(); + lockImagesToGrag.unlock(); + } + + @Override + public void run() { + for (;;) { + while (getImagesToGrabSize() > 0) { + lockImagesToGrag.lock(); + lockCurrentGrabImage.lock(); + currentGrabImage = imagesToGrab.get(0); + lockCurrentGrabImage.unlock(); + imagesToGrab.remove(0); + lockImagesToGrag.unlock(); + if (cancelled) { + break; + } else { + GeorefImage newImage; + try { + Main.map.repaint(); // paint the current grab box + newImage = grabber.grab(wmsLayer, currentGrabImage.min, currentGrabImage.max); + } catch (IOException e) { + System.out + .println("Download action cancelled by user or server did not respond"); + setCancelled(true); + break; + } catch (OsmTransferException e) { + System.out.println("OSM transfer failed"); + setCancelled(true); + break; + } + if (grabber.getWmsInterface().downloadCancelled) { + System.out.println("Download action cancelled by user"); + setCancelled(true); + break; + } + try { + if (CadastrePlugin.backgroundTransparent) { + wmsLayer.imagesLock.lock(); + for (GeorefImage img : wmsLayer.getImages()) { + if (img.overlap(newImage)) + // mask overlapping zone in already grabbed image + img.withdraw(newImage); + else + // mask overlapping zone in new image only when new image covers completely the + // existing image + newImage.withdraw(img); + } + wmsLayer.imagesLock.unlock(); + } + wmsLayer.addImage(newImage); + Main.map.mapView.repaint(); + saveToCache(newImage); + } catch (NullPointerException e) { + System.out.println("Layer destroyed. Cancel grab thread"); + setCancelled(true); + } + } + } + System.out.println("grab thread list empty"); + lockCurrentGrabImage.lock(); + currentGrabImage = null; + lockCurrentGrabImage.unlock(); + if (cancelled) { + clearImagesToGrab(); + cancelled = false; + } + if (wmsLayer.isRaster()) { + notifyWaiter(); + } + waitNotification(); } + } + + public void saveToCache(GeorefImage image) { + if (CacheControl.cacheEnabled && !wmsLayer.isRaster()) { + getCacheControl().saveCache(image); + } + } + + public void saveNewCache() { + if (CacheControl.cacheEnabled) { + getCacheControl().deleteCacheFile(); + wmsLayer.imagesLock.lock(); + for (GeorefImage image : wmsLayer.getImages()) + getCacheControl().saveCache(image); + wmsLayer.imagesLock.unlock(); + } + } + + public void cancel() { + clearImagesToGrab(); + if (cacheControl != null) { + while (!cacheControl.isCachePipeEmpty()) { + System.out + .println("Try to close a WMSLayer which is currently saving in cache : wait 1 sec."); + CadastrePlugin.safeSleep(1000); + } + } + } + + public CacheControl getCacheControl() { + if (cacheControl == null) + cacheControl = new CacheControl(wmsLayer); + return cacheControl; + } + + public GrabThread(WMSLayer wmsLayer) { + this.wmsLayer = wmsLayer; + } + + public void paintBoxesToGrab(Graphics g, MapView mv) { + if (getImagesToGrabSize() > 0) { + ArrayList<EastNorthBound> imagesToGrab = getImagesToGrabCopy(); + for (EastNorthBound img : imagesToGrab) { + paintBox(g, mv, img, Color.red); + } + } + lockCurrentGrabImage.lock(); + if (currentGrabImage != null) { + paintBox(g, mv, currentGrabImage, Color.orange); + } + lockCurrentGrabImage.unlock(); + } + + private void paintBox(Graphics g, MapView mv, EastNorthBound img, Color color) { + Point[] croppedPoint = new Point[5]; + croppedPoint[0] = mv.getPoint(img.min); + croppedPoint[1] = mv.getPoint(new EastNorth(img.min.east(), img.max.north())); + croppedPoint[2] = mv.getPoint(img.max); + croppedPoint[3] = mv.getPoint(new EastNorth(img.max.east(), img.min.north())); + croppedPoint[4] = croppedPoint[0]; + for (int i=0; i<4; i++) { + g.setColor(color); + g.drawLine(croppedPoint[i].x, croppedPoint[i].y, croppedPoint[i+1].x, croppedPoint[i+1].y); + } + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + public CadastreGrabber getGrabber() { + return grabber; + } + + public void setGrabber(CadastreGrabber grabber) { + this.grabber = grabber; + } + + private synchronized void notifyWaiter() { + this.notify(); + } + + private synchronized void waitNotification() { + try { + wait(); + } catch (InterruptedException e) { + e.printStackTrace(System.out); + } + } + +} diff --git a/cadastre-fr/src/cadastre_fr/MenuActionCancelGrab.java b/cadastre-fr/src/cadastre_fr/MenuActionCancelGrab.java new file mode 100644 index 0000000..4373a0a --- /dev/null +++ b/cadastre-fr/src/cadastre_fr/MenuActionCancelGrab.java @@ -0,0 +1,29 @@ +package cadastre_fr; + +import static org.openstreetmap.josm.tools.I18n.tr; + +import java.awt.event.ActionEvent; + +import org.openstreetmap.josm.actions.JosmAction; + +@SuppressWarnings("serial") +public class MenuActionCancelGrab extends JosmAction { + + public static String name = "Cancel current grab"; + + private WMSLayer wmsLayer; + + public MenuActionCancelGrab(WMSLayer wmsLayer) { + super(tr(name), null, tr("Cancel current grab (only vector images)"), null, false); + this.wmsLayer = wmsLayer; + } + + + @Override + public void actionPerformed(ActionEvent arg0) { + if (wmsLayer.grabThread.getImagesToGrabSize() > 0) { + wmsLayer.grabThread.cancel(); + } + } + +} diff --git a/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java b/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java index b406e1b..0aa025a 100644 --- a/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java +++ b/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java @@ -105,7 +105,7 @@ public class MenuActionGrabPlanImage extends JosmAction implements Runnable, Mou boolean loadedFromCache = downloadWMSPlanImage.waitFinished(); if (loadedFromCache) { Main.map.repaint(); - } else if (wmsLayer.images.size() == 0) { + } else if (wmsLayer.getImages().size() == 0) { // action cancelled or image loaded from cache (and already georeferenced) actionInterrupted(); } else { @@ -148,8 +148,8 @@ public class MenuActionGrabPlanImage extends JosmAction implements Runnable, Mou } else { countMouseClicked++; // ignore clicks outside the image - if (ea.east() < wmsLayer.images.get(0).min.east() || ea.east() > wmsLayer.images.get(0).max.east() - || ea.north() < wmsLayer.images.get(0).min.north() || ea.north() > wmsLayer.images.get(0).max.north()) + if (ea.east() < wmsLayer.getImage(0).min.east() || ea.east() > wmsLayer.getImage(0).max.east() + || ea.north() < wmsLayer.getImage(0).min.north() || ea.north() > wmsLayer.getImage(0).max.north()) return; if (mode == cGetCorners) { if (countMouseClicked == 1) { @@ -258,7 +258,7 @@ public class MenuActionGrabPlanImage extends JosmAction implements Runnable, Mou private void endGeoreferencing() { Main.map.mapView.removeMouseListener(this); affineTransform(ea1, ea2, georefpoint1, georefpoint2); - wmsLayer.saveNewCache(); + wmsLayer.grabThread.saveNewCache(); Main.map.mapView.repaint(); actionCompleted(); clickOnTheMap = false; @@ -377,24 +377,24 @@ public class MenuActionGrabPlanImage extends JosmAction implements Runnable, Mou // move double dx = dst1.getX() - org1.getX(); double dy = dst1.getY() - org1.getY(); - wmsLayer.images.get(0).shear(dx, dy); + wmsLayer.getImage(0).shear(dx, dy); org1 = org1.add(dx, dy); // org1=dst1 now org2 = org2.add(dx, dy); // rotate : org1(=dst1 now) is anchor for rotation and scale - wmsLayer.images.get(0).rotate(dst1, angle); + wmsLayer.getImage(0).rotate(dst1, angle); org2 = org2.rotate(dst1, angle); // scale image from anchor org1(=dst1 now) - wmsLayer.images.get(0).scale(dst1, proportion); + wmsLayer.getImage(0).scale(dst1, proportion); } private void transformGeoreferencedImg() { georefpoint1 = new EastNorth(wmsLayer.X0, wmsLayer.Y0); georefpoint2 = new EastNorth(wmsLayer.X0+wmsLayer.fX*wmsLayer.communeBBox.max.getX(), wmsLayer.Y0+wmsLayer.fY*wmsLayer.communeBBox.max.getX()); - ea1 = new EastNorth(wmsLayer.images.get(0).min.east(), wmsLayer.images.get(0).max.north()); - EastNorth ea2 = wmsLayer.images.get(0).max; + ea1 = new EastNorth(wmsLayer.getImage(0).min.east(), wmsLayer.getImage(0).max.north()); + EastNorth ea2 = wmsLayer.getImage(0).max; affineTransform(ea1, ea2, georefpoint1, georefpoint2); - wmsLayer.saveNewCache(); + wmsLayer.grabThread.saveNewCache(); Main.map.mapView.repaint(); } diff --git a/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java b/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java index f280908..a7de7ba 100644 --- a/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java +++ b/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java @@ -74,7 +74,7 @@ public class MenuActionLoadFromCache extends JosmAction { } // create layer and load cache WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1); - if (wmsLayer.getCacheControl().loadCache(file, layoutZone)) { + if (wmsLayer.grabThread.getCacheControl().loadCache(file, layoutZone)) { CadastrePlugin.addWMSLayer(wmsLayer); } } diff --git a/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java b/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java index 06913e7..5072639 100644 --- a/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java +++ b/cadastre-fr/src/cadastre_fr/MenuActionNewLocation.java @@ -64,7 +64,6 @@ public class MenuActionNewLocation extends JosmAction { String location = ""; String codeDepartement = ""; String codeCommune = ""; - boolean changeInterface = false; JLabel labelSectionNewLocation = new JLabel(tr("Add a new municipality layer")); JPanel p = new JPanel(new GridBagLayout()); JLabel labelLocation = new JLabel(tr("Commune")); @@ -104,7 +103,6 @@ public class MenuActionNewLocation extends JosmAction { if (!inputTown.getText().equals("")) { location = inputTown.getText().toUpperCase(); codeDepartement = departements[inputDepartement.getSelectedIndex()*2]; - changeInterface = true; Main.pref.put("cadastrewms.location", location); Main.pref.put("cadastrewms.codeCommune", codeCommune); Main.pref.put("cadastrewms.codeDepartement", codeDepartement); @@ -129,11 +127,8 @@ public class MenuActionNewLocation extends JosmAction { System.out.println("Add new layer with Location:" + inputTown.getText()); } else if (existingLayers != null && existingLayers.size() > 0 && Main.map.mapView.getActiveLayer() instanceof WMSLayer) { wmsLayer = (WMSLayer)Main.map.mapView.getActiveLayer(); - changeInterface = true; } - if (changeInterface) - CadastrePlugin.cadastreGrabber.getWmsInterface().resetInterfaceRefIfNewLayer(wmsLayer.getName()); return wmsLayer; } diff --git a/cadastre-fr/src/cadastre_fr/MenuActionResetCookie.java b/cadastre-fr/src/cadastre_fr/MenuActionResetCookie.java index bf50dbf..2d10235 100644 --- a/cadastre-fr/src/cadastre_fr/MenuActionResetCookie.java +++ b/cadastre-fr/src/cadastre_fr/MenuActionResetCookie.java @@ -19,6 +19,6 @@ public class MenuActionResetCookie extends JosmAction { } public void actionPerformed(ActionEvent e) { - CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookie(); + //CadastrePlugin.cadastreGrabber.getWmsInterface().resetCookie(); } } diff --git a/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java b/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java index 13d9cf4..cafae80 100644 --- a/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java +++ b/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java @@ -55,7 +55,7 @@ public class MenuActionSaveRasterAs extends JosmAction { file = fc.getSelectedFile(); if (!file.getName().endsWith(".png")) file = new File(file.getParent(), file.getName()+".png"); - BufferedImage bi = wmsLayer.images.get(0).image; + BufferedImage bi = wmsLayer.getImage(0).image; try { ImageIO.write(bi, "png", file); /* diff --git a/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java b/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java index 28d265a..0dc8e29 100644 --- a/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java +++ b/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java @@ -164,9 +164,9 @@ public class WMSAdjustAction extends MapMode implements double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); double rotationAngle = endAngle - startAngle; - if (selectedLayer.images.get(0).orgCroppedRaster != null) { + if (selectedLayer.getImage(0).orgCroppedRaster != null) { for (int i=0; i<4; i++) { - croppedRaster[i] = selectedLayer.images.get(0).orgCroppedRaster[i].rotate(pivot, rotationAngle); + croppedRaster[i] = selectedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle); } croppedRaster[4] = croppedRaster[0]; } @@ -197,7 +197,7 @@ public class WMSAdjustAction extends MapMode implements private void saveModifiedLayers() { for (WMSLayer wmsLayer : modifiedLayers) { - wmsLayer.saveNewCache(); + wmsLayer.grabThread.saveNewCache(); } } } diff --git a/cadastre-fr/src/cadastre_fr/WMSLayer.java b/cadastre-fr/src/cadastre_fr/WMSLayer.java index e779d43..8b6e03a 100644 --- a/cadastre-fr/src/cadastre_fr/WMSLayer.java +++ b/cadastre-fr/src/cadastre_fr/WMSLayer.java @@ -19,6 +19,8 @@ import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.HashSet; import java.util.Vector; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; import javax.swing.Action; import javax.swing.Icon; @@ -33,7 +35,6 @@ import org.openstreetmap.josm.gui.MapView; import org.openstreetmap.josm.gui.dialogs.LayerListDialog; import org.openstreetmap.josm.gui.dialogs.LayerListPopup; import org.openstreetmap.josm.gui.layer.Layer; -import org.openstreetmap.josm.io.OsmTransferException; /** * This is a layer that grabs the current screen from the French cadastre WMS @@ -44,10 +45,14 @@ public class WMSLayer extends Layer implements ImageObserver { private int lambertZone = -1; + public CadastreGrabber grabber = new CadastreGrabber(); + protected static final Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage( CadastrePlugin.class.getResource("/images/cadastre_small.png"))); - protected Vector<GeorefImage> images = new Vector<GeorefImage>(); + private Vector<GeorefImage> images = new Vector<GeorefImage>(); + + public Lock imagesLock = new ReentrantLock(); /** * v1 to v2 = not supported @@ -60,8 +65,6 @@ public class WMSLayer extends Layer implements ImageObserver { private ArrayList<EastNorthBound> dividedBbox = new ArrayList<EastNorthBound>(); - private CacheControl cacheControl = null; - private String location = ""; private String departement = ""; @@ -70,8 +73,6 @@ public class WMSLayer extends Layer implements ImageObserver { public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0)); - public boolean cancelled; - private boolean isRaster = false; private boolean isAlreadyGeoreferenced = false; public double X0, Y0, angle, fX, fY; @@ -83,9 +84,12 @@ public class WMSLayer extends Layer implements ImageObserver { private Action saveAsPng; - public boolean adjustModeEnabled; + private Action cancelGrab; + public boolean adjustModeEnabled; + public GrabThread grabThread; + public WMSLayer() { this(tr("Blank Layer"), "", -1); } @@ -95,6 +99,8 @@ public class WMSLayer extends Layer implements ImageObserver { this.location = location; this.codeCommune = codeCommune; this.lambertZone = lambertZone; + grabThread = new GrabThread(this); + grabThread.start(); // enable auto-sourcing option CadastrePlugin.pluginUsed = true; } @@ -102,12 +108,8 @@ public class WMSLayer extends Layer implements ImageObserver { @Override public void destroy() { // if the layer is currently saving the images in the cache, wait until it's finished - if (cacheControl != null) { - while (!cacheControl.isCachePipeEmpty()) { - System.out.println("Try to close a WMSLayer which is currently saving in cache : wait 1 sec."); - CadastrePlugin.safeSleep(1000); - } - } + grabThread.cancel(); + grabThread = null; super.destroy(); images = null; dividedBbox = null; @@ -125,8 +127,9 @@ public class WMSLayer extends Layer implements ImageObserver { return buildName(this.location.toUpperCase(), this.codeCommune); } - public void grab(CadastreGrabber grabber, Bounds b) throws IOException { - cancelled = false; + public void grab(Bounds b) throws IOException { + grabThread.setCancelled(false); + grabThread.setGrabber(grabber); // if it is the first layer, use the communeBBox as grab bbox (and not divided) if (Main.map.mapView.getAllLayers().size() == 1 ) { b = this.getCommuneBBox().toBounds(); @@ -140,47 +143,11 @@ public class WMSLayer extends Layer implements ImageObserver { } else divideBbox(b, Integer.parseInt(Main.pref.get("cadastrewms.scale", Scale.X1.toString()))); } - - int lastSavedImage = images.size(); - for (EastNorthBound n : dividedBbox) { - if (cancelled) - return; - GeorefImage newImage; - try { - newImage = grabber.grab(this, n.min, n.max); - } catch (IOException e) { - System.out.println("Download action cancelled by user or server did not respond"); - break; - } catch (OsmTransferException e) { - System.out.println("OSM transfer failed"); - break; - } - if (grabber.getWmsInterface().downloadCancelled) { - System.out.println("Download action cancelled by user"); - break; - } - if (CadastrePlugin.backgroundTransparent) { - for (GeorefImage img : images) { - if (img.overlap(newImage)) - // mask overlapping zone in already grabbed image - img.withdraw(newImage); - else - // mask overlapping zone in new image only when new - // image covers completely the existing image - newImage.withdraw(img); - } - } - images.add(newImage); - Main.map.mapView.repaint(); - } - if (!cancelled) { - for (int i=lastSavedImage; i < images.size(); i++) - saveToCache(images.get(i)); - } + grabThread.addImages(dividedBbox); } /** - * Divides the bounding box in smaller polygons. + * Divides the bounding box in smaller squares. Their size (and quantity) is configurable in Preferences. * * @param b the original bbox, usually the current bbox on screen * @param factor 1 = source bbox 1:1 @@ -205,14 +172,54 @@ public class WMSLayer extends Layer implements ImageObserver { } } else { // divide to fixed size squares - int cSquare = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100")); - minEast = minEast - minEast % cSquare; - minNorth = minNorth - minNorth % cSquare; - for (int xEast = (int)minEast; xEast < lambertMax.east(); xEast+=cSquare) - for (int xNorth = (int)minNorth; xNorth < lambertMax.north(); xNorth+=cSquare) { - dividedBbox.add(new EastNorthBound(new EastNorth(xEast, xNorth), - new EastNorth(xEast + cSquare, xNorth + cSquare))); + // grab all square in a spiral starting from the center (usually the most interesting place) + int c = Integer.parseInt(Main.pref.get("cadastrewms.squareSize", "100")); + lambertMin = lambertMin.add(- minEast%c, - minNorth%c); + lambertMax = lambertMax.add(c - lambertMax.east()%c, c - lambertMax.north()%c); + EastNorth mid = lambertMax.getCenter(lambertMin); + mid = mid.add(-1, 1); // in case the boxes side is a pair, select the one one top,left to follow the rotation + mid = mid.add(- mid.east()%c, - mid.north()%c); + int x = (int)(lambertMax.east() - lambertMin.east())/100; + int y = (int)(lambertMax.north() - lambertMin.north())/100; + int dx[] = {+1, 0,-1, 0}; + int dy[] = {0,-1, 0,+1}; + int currDir = -1, lDir = 1, i = 1, j = 0, k = -1; + if (x == 1) + currDir = 0; + dividedBbox.add(new EastNorthBound(mid, new EastNorth(mid.east()+c, mid.north()+c))); + while (i < (x*y)) { + i++; + j++; + if (j >= lDir) { + k++; + if (k > 1) { + lDir++; + k = 0; + } + j = 0; + currDir = (currDir+1)%4; + } else if (currDir >= 0 && j >= (currDir == 0 || currDir == 2 ? x-1 : y-1)) { + // the overall is a rectangle, not a square. Jump to the other side to grab next square. + k++; + if (k > 1) { + lDir++; + k = 0; + } + j = lDir-1; + currDir = (currDir+1)%4; + mid = new EastNorth(mid.east() + dx[currDir]*c*(lDir-1), mid.north() + dy[currDir]*c*(lDir-1)); + } + mid = new EastNorth(mid.east() + dx[currDir]*c, mid.north() + dy[currDir]*c); + dividedBbox.add(new EastNorthBound(mid, new EastNorth(mid.east()+c, mid.north()+c))); } +// // simple algorithm to grab all squares +// minEast = minEast - minEast % cSquare; +// minNorth = minNorth - minNorth % cSquare; +// for (int xEast = (int)minEast; xEast < lambertMax.east(); xEast+=cSquare) +// for (int xNorth = (int)minNorth; xNorth < lambertMax.north(); xNorth+=cSquare) { +// dividedBbox.add(new EastNorthBound(new EastNorth(xEast, xNorth), +// new EastNorth(xEast + cSquare, xNorth + cSquare))); +// } } } @@ -254,16 +261,17 @@ public class WMSLayer extends Layer implements ImageObserver { g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); else g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); - synchronized(this){ - for (GeorefImage img : images) - img.paint(g, mv, CadastrePlugin.backgroundTransparent, - CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); - } + imagesLock.lock(); + for (GeorefImage img : images) + img.paint(g, mv, CadastrePlugin.backgroundTransparent, + CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); + imagesLock.unlock(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation); } if (this.isRaster) { paintCrosspieces(g, mv); } + grabThread.paintBoxesToGrab(g, mv); if (this.adjustModeEnabled) { WMSAdjustAction.paintAdjustFrames(g, mv); } @@ -286,11 +294,14 @@ public class WMSLayer extends Layer implements ImageObserver { public Action[] getMenuEntries() { saveAsPng = new MenuActionSaveRasterAs(this); saveAsPng.setEnabled(isRaster); + cancelGrab = new MenuActionCancelGrab(this); + cancelGrab.setEnabled(!isRaster && grabThread.getImagesToGrabSize() > 0); return new Action[] { LayerListDialog.getInstance().createShowHideLayerAction(), LayerListDialog.getInstance().createDeleteLayerAction(), new MenuActionLoadFromCache(), saveAsPng, + cancelGrab, new LayerListPopup.InfoAction(this), }; @@ -319,26 +330,6 @@ public class WMSLayer extends Layer implements ImageObserver { return false; } - public void saveToCache(GeorefImage image) { - if (CacheControl.cacheEnabled && !isRaster()) { - getCacheControl().saveCache(image); - } - } - - public void saveNewCache() { - if (CacheControl.cacheEnabled) { - getCacheControl().deleteCacheFile(); - for (GeorefImage image : images) - getCacheControl().saveCache(image); - } - } - - public CacheControl getCacheControl() { - if (cacheControl == null) - cacheControl = new CacheControl(this); - return cacheControl; - } - /** * Convert the eastNorth input coordinates to raster coordinates. * The original raster size is [0,0,12286,8730] where 0,0 is the upper left corner and @@ -426,6 +417,7 @@ public class WMSLayer extends Layer implements ImageObserver { * @throws IOException */ public void write(ObjectOutputStream oos) throws IOException { + currentFormat = this.serializeFormatVersion; oos.writeInt(this.serializeFormatVersion); oos.writeObject(this.location); // String oos.writeObject(this.codeCommune); // String @@ -641,4 +633,38 @@ public class WMSLayer extends Layer implements ImageObserver { } } + public GeorefImage getImage(int index) { + imagesLock.lock(); + GeorefImage img = null; + try { + img = this.images.get(index); + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(System.out); + } + imagesLock.unlock(); + return img; + } + + public Vector<GeorefImage> getImages() { + return this.images; + } + + public void addImage(GeorefImage img) { + imagesLock.lock(); + this.images.add(img); + imagesLock.unlock(); + } + + public void setImages(Vector<GeorefImage> images) { + imagesLock.lock(); + this.images = images; + imagesLock.unlock(); + } + + public void clearImages() { + imagesLock.lock(); + this.images.clear(); + imagesLock.unlock(); + } + } diff --git a/colorscheme/build.xml b/colorscheme/build.xml index c06e3b9..c804c2d 100644 --- a/colorscheme/build.xml +++ b/colorscheme/build.xml @@ -28,7 +28,7 @@ <property name="commit.message" value="Uses new constructor for Plugin" /> - <property name="plugin.main.version" value="2830" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> <property name="plugin.dist.dir" value="../../dist"/> diff --git a/editgpx/build.xml b/editgpx/build.xml index 0810b6a..b81c587 100644 --- a/editgpx/build.xml +++ b/editgpx/build.xml @@ -28,7 +28,7 @@ <property name="commit.message" value="Changed constructor signature of plugin main class" /> - <property name="plugin.main.version" value="3408" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> diff --git a/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxTrack.java b/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxTrack.java index 7388e3a..c8b4fda 100644 --- a/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxTrack.java +++ b/editgpx/src/org/openstreetmap/josm/plugins/editgpx/data/EditGpxTrack.java @@ -42,14 +42,22 @@ public class EditGpxTrack { if (anonTime) { // convert to anonymous time for (WayPoint w : points) { - w.attr.put("time", "1970-00-00T00:00:00.000Z"); + w.attr.put("time", "1970-01-01T00:00:00.000Z"); w.setTime(); + if (w.attr.containsKey("name")) { + w.attr.put("name", "anon"); //time information can also be in "name" field. so delete time information + } } } wayPoints.add(points); } } } + if (anonTime) { + if (attributes.containsKey("name")) { + attributes.put("name", "anon");//time information can also be in "name" field. so delete time information + } + } return new ImmutableGpxTrack(wayPoints, attributes); } diff --git a/lakewalker/build.xml b/lakewalker/build.xml index 17d82be..032d74b 100644 --- a/lakewalker/build.xml +++ b/lakewalker/build.xml @@ -27,7 +27,7 @@ <project name="lakewalker" default="dist" basedir="."> <property name="commit.message" value="Changed the constructor signature of the plugin main class" /> - <property name="plugin.main.version" value="2830" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> <property name="plugin.dist.dir" value="../../dist"/> @@ -55,7 +55,7 @@ <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.lakewalker.LakewalkerPlugin" /> <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> <attribute name="Plugin-Description" value="Helps vectorizing WMS images." /> - <attribute name="Plugin-Icon" value="images/lakewalker-sml.png"/> + <attribute name="Plugin-Icon" value="images/lakewalker-sml.png"/> <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> </manifest> diff --git a/livegps/build.xml b/livegps/build.xml index e915efe..2ab917d 100644 --- a/livegps/build.xml +++ b/livegps/build.xml @@ -27,7 +27,7 @@ <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="3119" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> @@ -55,7 +55,7 @@ <attribute name="Plugin-Class" value="livegps.LiveGpsPlugin"/> <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> <attribute name="Plugin-Description" value="Support live GPS input (moving dot) through a connection to gpsd server."/> - <attribute name="Plugin-Icon" value="images/dialogs/livegps.png"/> + <attribute name="Plugin-Icon" value="images/dialogs/livegps.png"/> <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/LiveGPS"/> <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> <attribute name="Plugin-Stage" value="50"/> diff --git a/measurement/build.xml b/measurement/build.xml index 47ef8c2..9dcd049 100644 --- a/measurement/build.xml +++ b/measurement/build.xml @@ -27,7 +27,7 @@ <project name="measurement" default="dist" basedir="."> <property name="commit.message" value="Changed the constructor signature of the plugin main class" /> - <property name="plugin.main.version" value="3408" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> @@ -55,7 +55,7 @@ <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.measurement.MeasurementPlugin"/> <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> <attribute name="Plugin-Description" value="Provide a measurement dialog and a layer to measure length and angle of segments, area surrounded by a (simple) closed way and create measurement paths (which also can be imported from a gps layer)."/> - <attribute name="Plugin-Icon" value="images/dialogs/measure.png"/> + <attribute name="Plugin-Icon" value="images/dialogs/measure.png"/> <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> </manifest> diff --git a/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java b/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java index 288d4ee..ed3aa31 100644 --- a/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java +++ b/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java @@ -103,7 +103,8 @@ public class MeasurementDialog extends ToggleDialog implements ActionListener this.setPreferredSize(new Dimension(0, 92)); final MeasurementDialog dlg = this; - DataSet.selListeners.add(new SelectionChangedListener() { + DataSet.addSelectionListener(new SelectionChangedListener() { + @Override public void selectionChanged(Collection<? extends OsmPrimitive> arg0) { double length = 0.0; double segAngle = 0.0; @@ -116,7 +117,7 @@ public class MeasurementDialog extends ToggleDialog implements ActionListener if(lastNode == null) { lastNode = n; } else { - length += MeasurementLayer.calcDistance(lastNode.getCoor(), n.getCoor()); + length += lastNode.getCoor().greatCircleDistance(n.getCoor()); segAngle = MeasurementLayer.angleBetween(lastNode.getCoor(), n.getCoor()); lastNode = n; } @@ -125,7 +126,7 @@ public class MeasurementDialog extends ToggleDialog implements ActionListener Node lastN = null; for(Node n: w.getNodes()) { if(lastN != null) { - length += MeasurementLayer.calcDistance(lastN.getCoor(), n.getCoor()); + length += lastN.getCoor().greatCircleDistance(n.getCoor()); //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ area += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor())) - (MeasurementLayer.calcY(n.getCoor()) * MeasurementLayer.calcX(lastN.getCoor())); @@ -147,6 +148,7 @@ public class MeasurementDialog extends ToggleDialog implements ActionListener }); } + @Override public void actionPerformed(ActionEvent e) { String actionCommand = e.getActionCommand(); diff --git a/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java b/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java index 087a52a..e728d1a 100644 --- a/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java +++ b/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java @@ -143,23 +143,6 @@ public class MeasurementLayer extends Layer { MeasurementPlugin.measurementDialog.pathLengthLabel.setText(pathLength < 800?nf2.format(pathLength) + " m":nf.format(pathLength/1000) + " km"); } - public static double calcDistance(LatLon p1, LatLon p2){ - double lat1, lon1, lat2, lon2; - double dlon, dlat; - - lat1 = p1.lat() * Math.PI / 180.0; - lon1 = p1.lon() * Math.PI / 180.0; - lat2 = p2.lat() * Math.PI / 180.0; - lon2 = p2.lon() * Math.PI / 180.0; - - dlon = lon2 - lon1; - dlat = lat2 - lat1; - - double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2)); - double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); - return 6367000 * c; - } - public static double calcX(LatLon p1){ double lat1, lon1, lat2, lon2; double dlon, dlat; @@ -195,7 +178,7 @@ public class MeasurementLayer extends Layer { } public static double calcDistance(WayPoint p1, WayPoint p2){ - return calcDistance(p1.getCoor(), p2.getCoor()); + return p1.getCoor().greatCircleDistance(p2.getCoor()); } public static double angleBetween(WayPoint p1, WayPoint p2){ @@ -259,6 +242,7 @@ public class MeasurementLayer extends Layer { super(tr("Import path from GPX layer"), ImageProvider.get("dialogs", "edit")); // TODO: find better image } + @Override public void actionPerformed(ActionEvent e) { Box panel = Box.createVerticalBox(); final JList layerList = new JList(model); diff --git a/openvisible/build.xml b/openvisible/build.xml index 0672a7c..dc0dff3 100644 --- a/openvisible/build.xml +++ b/openvisible/build.xml @@ -32,7 +32,7 @@ <!-- enter the SVN commit message --> <property name="commit.message" value="Changed the constructor signature of the plugin main class; updated build.xml" /> <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> - <property name="plugin.main.version" value="2830" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> <property name="plugin.dist.dir" value="../../dist"/> @@ -60,7 +60,7 @@ <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> <attribute name="Plugin-Dependencies" value="jgrapht-jdk1.5"/> <attribute name="Plugin-Description" value="Allows opening gpx/osm files that intersect the currently visible screen area"/> - <attribute name="Plugin-Icon" value="images/openvisible.png"/> + <attribute name="Plugin-Icon" value="images/openvisible.png"/> <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/> <attribute name="Plugin-Stage" value="50"/> <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> diff --git a/routing/build.xml b/routing/build.xml index 72ae19d..82e63a7 100644 --- a/routing/build.xml +++ b/routing/build.xml @@ -27,7 +27,7 @@ <project name="routing" default="dist" basedir="."> <property name="commit.message" value="Changed the constructor signature of the plugin main class" /> - <property name="plugin.main.version" value="3600" /> + <property name="plugin.main.version" value="3835" /> <!-- Define some properties --> <property name="josm" location="../../core/dist/josm-custom.jar"/> diff --git a/surveyor/build.xml b/surveyor/build.xml index fee1e4f..b2748d6 100644 --- a/surveyor/build.xml +++ b/surveyor/build.xml @@ -32,7 +32,7 @@ <!-- enter the SVN commit message --> <property name="commit.message" value="Changed the constructor signature of the plugin main class" /> <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> - <property name="plugin.main.version" value="2907" /> + <property name="plugin.main.version" value="3835" /> <property name="josm" location="../../core/dist/josm-custom.jar"/> diff --git a/svn-info.xml b/svn-info.xml index 230e96b..212a54c 100644 --- a/svn-info.xml +++ b/svn-info.xml @@ -3,16 +3,16 @@ <entry kind="dir" path="plugins" - revision="24926"> + revision="25537"> <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="24925"> -<author>malcolmh</author> -<date>2010-12-31T15:46:49.494500Z</date> + revision="25527"> +<author>stoecker</author> +<date>2011-03-06T14:57:08.379261Z</date> </commit> </entry> </info> -- 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