Changeset 24934 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Timestamp:
- 2011-01-02T00:36:28+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r24907 r24934 153 153 if (successfulRead && wmsLayer.isRaster()) { 154 154 // serialized raster bufferedImage hangs-up on Java6. Recreate them here 155 wmsLayer. images.get(0).image = RasterImageModifier.fixRasterImage(wmsLayer.images.get(0).image);155 wmsLayer.getImage(0).image = RasterImageModifier.fixRasterImage(wmsLayer.getImage(0).image); 156 156 } 157 157 return successfulRead; … … 172 172 for (;;) { 173 173 imagesLock.lock(); 174 //ArrayList<GeorefImage> images = new ArrayList<GeorefImage>(imagesToSave);175 174 int size = imagesToSave.size(); 176 175 imagesLock.unlock(); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSPlanImage.java
r21493 r24934 35 35 try { 36 36 if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) { 37 if (!wmsLayer. images.isEmpty()) {37 if (!wmsLayer.getImages().isEmpty()) { 38 38 //JOptionPane.showMessageDialog(Main.parent,tr("Image already loaded")); 39 39 JOptionPane pane = new JOptionPane( … … 51 51 // first time we grab an image for this layer 52 52 if (CacheControl.cacheEnabled) { 53 if (wmsLayer.getCacheControl().loadCacheIfExist()) { 53 if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) { 54 54 dontGeoreference = true; 55 55 Main.map.mapView.repaint(); … … 64 64 wmsLayer.grab(grabber, bounds); 65 65 if (grabber.getWmsInterface().downloadCancelled) { 66 wmsLayer. images.clear();66 wmsLayer.clearImages(); 67 67 Main.map.mapView.repaint(); 68 68 } else { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
r24913 r24934 33 33 try { 34 34 if (grabber.getWmsInterface().retrieveInterface(wmsLayer)) { 35 if (wmsLayer. images.isEmpty()) {35 if (wmsLayer.getImages().isEmpty()) { 36 36 // first time we grab an image for this layer 37 37 if (CacheControl.cacheEnabled) { 38 if (wmsLayer.getCacheControl().loadCacheIfExist()) { 38 if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) { 39 39 Main.map.mapView.zoomTo(wmsLayer.getCommuneBBox().toBounds()); 40 40 //Main.map.mapView.repaint(); … … 69 69 grabber.getWmsInterface().cancel(); 70 70 if (wmsLayer != null) 71 wmsLayer. cancelled= true;71 wmsLayer.grabThread.setCancelled(true); 72 72 } 73 73 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
r23190 r24934 23 23 import org.openstreetmap.josm.gui.NavigatableComponent; 24 24 25 public class GeorefImage implements Serializable, ImageObserver { 25 public class GeorefImage implements Serializable, ImageObserver, Cloneable { 26 26 private static final long serialVersionUID = 1L; 27 27 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionGrabPlanImage.java
r23190 r24934 106 106 if (loadedFromCache) { 107 107 Main.map.repaint(); 108 } else if (wmsLayer. images.size() == 0) {108 } else if (wmsLayer.getImages().size() == 0) { 109 109 // action cancelled or image loaded from cache (and already georeferenced) 110 110 actionInterrupted(); … … 149 149 countMouseClicked++; 150 150 // ignore clicks outside the image 151 if (ea.east() < wmsLayer. images.get(0).min.east() || ea.east() > wmsLayer.images.get(0).max.east()152 || ea.north() < wmsLayer. images.get(0).min.north() || ea.north() > wmsLayer.images.get(0).max.north())151 if (ea.east() < wmsLayer.getImage(0).min.east() || ea.east() > wmsLayer.getImage(0).max.east() 152 || ea.north() < wmsLayer.getImage(0).min.north() || ea.north() > wmsLayer.getImage(0).max.north()) 153 153 return; 154 154 if (mode == cGetCorners) { … … 259 259 Main.map.mapView.removeMouseListener(this); 260 260 affineTransform(ea1, ea2, georefpoint1, georefpoint2); 261 wmsLayer.saveNewCache(); 261 wmsLayer.grabThread.saveNewCache(); 262 262 Main.map.mapView.repaint(); 263 263 actionCompleted(); … … 378 378 double dx = dst1.getX() - org1.getX(); 379 379 double dy = dst1.getY() - org1.getY(); 380 wmsLayer. images.get(0).shear(dx, dy);380 wmsLayer.getImage(0).shear(dx, dy); 381 381 org1 = org1.add(dx, dy); // org1=dst1 now 382 382 org2 = org2.add(dx, dy); 383 383 // rotate : org1(=dst1 now) is anchor for rotation and scale 384 wmsLayer. images.get(0).rotate(dst1, angle);384 wmsLayer.getImage(0).rotate(dst1, angle); 385 385 org2 = org2.rotate(dst1, angle); 386 386 // scale image from anchor org1(=dst1 now) 387 wmsLayer. images.get(0).scale(dst1, proportion);387 wmsLayer.getImage(0).scale(dst1, proportion); 388 388 } 389 389 … … 392 392 georefpoint2 = new EastNorth(wmsLayer.X0+wmsLayer.fX*wmsLayer.communeBBox.max.getX(), 393 393 wmsLayer.Y0+wmsLayer.fY*wmsLayer.communeBBox.max.getX()); 394 ea1 = new EastNorth(wmsLayer. images.get(0).min.east(), wmsLayer.images.get(0).max.north());395 EastNorth ea2 = wmsLayer. images.get(0).max;394 ea1 = new EastNorth(wmsLayer.getImage(0).min.east(), wmsLayer.getImage(0).max.north()); 395 EastNorth ea2 = wmsLayer.getImage(0).max; 396 396 affineTransform(ea1, ea2, georefpoint1, georefpoint2); 397 wmsLayer.saveNewCache(); 397 wmsLayer.grabThread.saveNewCache(); 398 398 Main.map.mapView.repaint(); 399 399 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionLoadFromCache.java
r23190 r24934 75 75 // create layer and load cache 76 76 WMSLayer wmsLayer = new WMSLayer("", "", Integer.parseInt(ext)-1); 77 if (wmsLayer.getCacheControl().loadCache(file, layoutZone)) { 77 if (wmsLayer.grabThread.getCacheControl().loadCache(file, layoutZone)) { 78 78 CadastrePlugin.addWMSLayer(wmsLayer); 79 79 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java
r18544 r24934 56 56 if (!file.getName().endsWith(".png")) 57 57 file = new File(file.getParent(), file.getName()+".png"); 58 BufferedImage bi = wmsLayer. images.get(0).image;58 BufferedImage bi = wmsLayer.getImage(0).image; 59 59 try { 60 60 ImageIO.write(bi, "png", file); -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java
r20281 r24934 165 165 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 166 166 double rotationAngle = endAngle - startAngle; 167 if (selectedLayer. images.get(0).orgCroppedRaster != null) {167 if (selectedLayer.getImage(0).orgCroppedRaster != null) { 168 168 for (int i=0; i<4; i++) { 169 croppedRaster[i] = selectedLayer. images.get(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);169 croppedRaster[i] = selectedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle); 170 170 } 171 171 croppedRaster[4] = croppedRaster[0]; … … 198 198 private void saveModifiedLayers() { 199 199 for (WMSLayer wmsLayer : modifiedLayers) { 200 wmsLayer.saveNewCache(); 200 wmsLayer.grabThread.saveNewCache(); 201 201 } 202 202 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r24913 r24934 20 20 import java.util.HashSet; 21 21 import java.util.Vector; 22 import java.util.concurrent.locks.Lock; 23 import java.util.concurrent.locks.ReentrantLock; 22 24 23 25 import javax.swing.Action; … … 34 36 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 35 37 import org.openstreetmap.josm.gui.layer.Layer; 36 import org.openstreetmap.josm.io.OsmTransferException;37 38 38 39 /** … … 48 49 CadastrePlugin.class.getResource("/images/cadastre_small.png"))); 49 50 50 protected Vector<GeorefImage> images = new Vector<GeorefImage>(); 51 private Vector<GeorefImage> images = new Vector<GeorefImage>(); 52 53 public Lock imagesLock = new ReentrantLock(); 51 54 52 55 /** … … 61 64 private ArrayList<EastNorthBound> dividedBbox = new ArrayList<EastNorthBound>(); 62 65 63 private CacheControl cacheControl = null;64 65 66 private String location = ""; 66 67 … … 70 71 71 72 public EastNorthBound communeBBox = new EastNorthBound(new EastNorth(0,0), new EastNorth(0,0)); 72 73 public boolean cancelled;74 73 75 74 private boolean isRaster = false; … … 84 83 private Action saveAsPng; 85 84 85 private Action cancelGrab; 86 86 87 public boolean adjustModeEnabled; 87 88 88 89 public GrabThread grabThread; 90 89 91 public WMSLayer() { 90 92 this(tr("Blank Layer"), "", -1); … … 96 98 this.codeCommune = codeCommune; 97 99 this.lambertZone = lambertZone; 100 grabThread = new GrabThread(this); 101 grabThread.start(); 98 102 // enable auto-sourcing option 99 103 CadastrePlugin.pluginUsed = true; … … 103 107 public void destroy() { 104 108 // if the layer is currently saving the images in the cache, wait until it's finished 105 if (cacheControl != null) { 106 while (!cacheControl.isCachePipeEmpty()) { 107 System.out.println("Try to close a WMSLayer which is currently saving in cache : wait 1 sec."); 108 CadastrePlugin.safeSleep(1000); 109 } 110 } 109 grabThread.cancel(); 111 110 super.destroy(); 112 111 images = null; … … 127 126 128 127 public void grab(CadastreGrabber grabber, Bounds b) throws IOException { 129 cancelled = false; 128 grabThread.setCancelled(false); 129 grabThread.setGrabber(grabber); 130 130 // if it is the first layer, use the communeBBox as grab bbox (and not divided) 131 131 if (Main.map.mapView.getAllLayers().size() == 1 ) { … … 142 142 } 143 143 144 int lastSavedImage = images.size(); 145 for (EastNorthBound n : dividedBbox) { 146 if (cancelled) 147 return; 148 GeorefImage newImage; 149 try { 150 newImage = grabber.grab(this, n.min, n.max); 151 } catch (IOException e) { 152 System.out.println("Download action cancelled by user or server did not respond"); 153 break; 154 } catch (OsmTransferException e) { 155 System.out.println("OSM transfer failed"); 156 break; 157 } 158 if (grabber.getWmsInterface().downloadCancelled) { 159 System.out.println("Download action cancelled by user"); 160 break; 161 } 162 if (CadastrePlugin.backgroundTransparent) { 163 for (GeorefImage img : images) { 164 if (img.overlap(newImage)) 165 // mask overlapping zone in already grabbed image 166 img.withdraw(newImage); 167 else 168 // mask overlapping zone in new image only when new 169 // image covers completely the existing image 170 newImage.withdraw(img); 171 } 172 } 173 images.add(newImage); 174 Main.map.mapView.repaint(); 175 } 176 if (!cancelled) { 177 for (int i=lastSavedImage; i < images.size(); i++) 178 saveToCache(images.get(i)); 179 } 144 grabThread.addImages(dividedBbox); 145 Main.map.repaint(); 180 146 } 181 147 … … 255 221 else 256 222 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); 257 synchronized(this){258 259 260 261 }223 imagesLock.lock(); 224 for (GeorefImage img : images) 225 img.paint(g, mv, CadastrePlugin.backgroundTransparent, 226 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); 227 imagesLock.unlock(); 262 228 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation); 263 229 } 264 230 if (this.isRaster) { 265 231 paintCrosspieces(g, mv); 232 } 233 if (grabThread.getImagesToGrabSize() > 0) { 234 grabThread.paintBoxesToGrab(g, mv); 266 235 } 267 236 if (this.adjustModeEnabled) { … … 287 256 saveAsPng = new MenuActionSaveRasterAs(this); 288 257 saveAsPng.setEnabled(isRaster); 258 cancelGrab = new MenuActionCancelGrab(this); 259 cancelGrab.setEnabled(!isRaster && grabThread.getImagesToGrabSize() > 0); 289 260 return new Action[] { 290 261 LayerListDialog.getInstance().createShowHideLayerAction(), … … 292 263 new MenuActionLoadFromCache(), 293 264 saveAsPng, 265 cancelGrab, 294 266 new LayerListPopup.InfoAction(this), 295 267 … … 318 290 } 319 291 return false; 320 }321 322 public void saveToCache(GeorefImage image) {323 if (CacheControl.cacheEnabled && !isRaster()) {324 getCacheControl().saveCache(image);325 }326 }327 328 public void saveNewCache() {329 if (CacheControl.cacheEnabled) {330 getCacheControl().deleteCacheFile();331 for (GeorefImage image : images)332 getCacheControl().saveCache(image);333 }334 }335 336 public CacheControl getCacheControl() {337 if (cacheControl == null)338 cacheControl = new CacheControl(this);339 return cacheControl;340 292 } 341 293 … … 642 594 } 643 595 596 public GeorefImage getImage(int index) { 597 imagesLock.lock(); 598 GeorefImage img = null; 599 try { 600 img = this.images.get(index); 601 } catch (ArrayIndexOutOfBoundsException e) { 602 e.printStackTrace(System.out); 603 } 604 imagesLock.unlock(); 605 return img; 606 } 607 608 public Vector<GeorefImage> getImages() { 609 return this.images; 610 } 611 612 public void addImage(GeorefImage img) { 613 imagesLock.lock(); 614 this.images.add(img); 615 imagesLock.unlock(); 616 } 617 618 public void setImages(Vector<GeorefImage> images) { 619 imagesLock.lock(); 620 this.images = images; 621 imagesLock.unlock(); 622 } 623 624 public void clearImages() { 625 imagesLock.lock(); 626 this.images.clear(); 627 imagesLock.unlock(); 628 } 629 644 630 }
Note:
See TracChangeset
for help on using the changeset viewer.