Changeset 19371 in osm for applications/editors/josm/plugins/cadastre-fr
- Timestamp:
- 2010-01-10T15:46:08+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java
r18838 r19371 49 49 private Lock imagesLock = new ReentrantLock(); 50 50 51 public boolean isCachePipeEmpty() { 52 imagesLock.lock(); 53 boolean ret = imagesToSave.isEmpty(); 54 imagesLock.unlock(); 55 return ret; 56 } 57 51 58 public CacheControl(WMSLayer wmsLayer) { 52 59 cacheEnabled = Main.pref.getBoolean("cadastrewms.enableCaching", true); … … 171 178 for (;;) { 172 179 imagesLock.lock(); 173 // copy locally the images to save for better performance 174 ArrayList<GeorefImage> images = new ArrayList<GeorefImage>(imagesToSave); 175 imagesToSave.clear(); 180 //ArrayList<GeorefImage> images = new ArrayList<GeorefImage>(imagesToSave); 181 int size = imagesToSave.size(); 176 182 imagesLock.unlock(); 177 if ( images != null && !images.isEmpty()) {183 if (size > 0) { 178 184 String extension = String.valueOf((wmsLayer.getLambertZone() + 1)); 179 185 if (Main.proj instanceof LambertCC9Zones) … … 186 192 ObjectOutputStreamAppend oos = new ObjectOutputStreamAppend( 187 193 new BufferedOutputStream(new FileOutputStream(file, true))); 188 for ( GeorefImage img : images) {189 oos.writeObject(im g);194 for (int i=0; i < size; i++) { 195 oos.writeObject(imagesToSave.get(i)); 190 196 } 191 197 oos.close(); … … 194 200 new BufferedOutputStream(new FileOutputStream(file))); 195 201 wmsLayer.write(oos); 196 for ( GeorefImage img : images) {197 oos.writeObject(im g);202 for (int i=0; i < size; i++) { 203 oos.writeObject(imagesToSave.get(i)); 198 204 } 199 205 oos.close(); … … 202 208 e.printStackTrace(System.out); 203 209 } 210 imagesLock.lock(); 211 for (int i=0; i < size; i++) { 212 imagesToSave.remove(0); 213 } 214 imagesLock.unlock(); 204 215 } 205 216 try {wait();} catch (InterruptedException e) { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePlugin.java
r19267 r19371 93 93 * - cookie expiration automatically detected and renewed (after 30 minutes) 94 94 * - proper WMS layer cleanup at destruction (workaround for memory leak) 95 * - new cache format (v3) storing original image and cropped image bbox + angle 96 * - cache management compatible with previous v2 format 97 * - raster image rotation using shift+ctrl key instead of ctrl 98 * - raster image adjustment using default system menu modifier (ctrl for windows) for Mac support 95 99 */ 96 100 public class CadastrePlugin extends Plugin { -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
r18544 r19371 25 25 private static final long serialVersionUID = 1L; 26 26 27 // bbox of the georeferenced image (the nice horizontal and vertical box) 27 28 public EastNorth min; 28 29 public EastNorth max; 30 // bbox of the georeferenced original image (raster only) (inclined if rotated and before cropping) 31 // P[0] is bottom,left then next are clockwise. 32 private EastNorth[] orgRaster = new EastNorth[4]; 33 // bbox of the georeferenced original image (raster only) after cropping 34 private EastNorth[] orgCroppedRaster = new EastNorth[4]; 35 // angle with georeferenced original image after rotation (raster images only)(in radian) 36 private double angle = 0; 37 29 38 public BufferedImage image; 30 39 … … 36 45 this.min = min; 37 46 this.max = max; 47 this.orgRaster[0] = min; 48 this.orgRaster[1] = new EastNorth(min.east(), max.north()); 49 this.orgRaster[2] = max; 50 this.orgRaster[3] = new EastNorth(max.east(), min.north()); 51 this.orgCroppedRaster[0] = min; 52 this.orgCroppedRaster[1] = new EastNorth(min.east(), max.north()); 53 this.orgCroppedRaster[2] = max; 54 this.orgCroppedRaster[3] = new EastNorth(max.east(), min.north()); 38 55 updatePixelPer(); 39 56 } … … 45 62 } 46 63 47 private void getNewBounding(EastNorth min, EastNorth max, EastNorth c, EastNorth d) { 64 /** 65 * Recalculate the new bounding box of the image based on the previous [min,max] bbox 66 * and the new box after rotation [c,d]. 67 * The new bbox defined in [min.max] will retain the extreme values of both boxes. 68 * @param oldMin the original box min point, before rotation 69 * @param oldMax the original box max point, before rotation 70 * @param c the new box min point, after rotation 71 * @param d the new box max point, after rotation 72 */ 73 private EastNorthBound getNewBounding(EastNorth oldMin, EastNorth oldMax, EastNorth c, EastNorth d) { 48 74 EastNorth pt[] = new EastNorth[4]; 49 pt[0] = min;50 pt[1] = max;75 pt[0] = oldMin; 76 pt[1] = oldMax; 51 77 pt[2] = c; 52 78 pt[3] = d; … … 61 87 highestNorth = Math.max(pt[i].north(), highestNorth); 62 88 } 63 min.setLocation(smallestEast, smallestNorth);64 max.setLocation(highestEast, highestNorth);89 return new EastNorthBound(new EastNorth(smallestEast, smallestNorth), 90 new EastNorth(highestEast, highestNorth)); 65 91 } 66 92 … … 84 110 if (drawBoundaries) { 85 111 g.setColor(Color.green); 86 g.drawRect(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y); 112 if (orgCroppedRaster == null) { 113 // this is the old cache format where only [min,max] bbox is stored 114 g.drawRect(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y); 115 } else { 116 Point[] croppedPoint = new Point[5]; 117 for (int i=0; i<4; i++) 118 croppedPoint[i] = nc.getPoint(orgCroppedRaster[i]); 119 croppedPoint[4] = croppedPoint[0]; 120 for (int i=0; i<4; i++) 121 g.drawLine(croppedPoint[i].x, croppedPoint[i].y, croppedPoint[i+1].x, croppedPoint[i+1].y); 122 } 87 123 } 88 124 g.drawImage(image, minPt.x, maxPt.y, maxPt.x, minPt.y, // dest … … 135 171 */ 136 172 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 137 max = new EastNorth(in.readDouble(), in.readDouble()); 138 min = new EastNorth(in.readDouble(), in.readDouble()); 173 if (WMSLayer.currentFormat == 2 || WMSLayer.currentFormat == 3) { 174 max = new EastNorth(in.readDouble(), in.readDouble()); 175 min = new EastNorth(in.readDouble(), in.readDouble()); 176 } 177 if (WMSLayer.currentFormat == 3) { 178 orgRaster = new EastNorth[4]; 179 orgCroppedRaster = new EastNorth[4]; 180 angle = in.readDouble(); 181 orgRaster[0] = new EastNorth(in.readDouble(), in.readDouble()); 182 orgRaster[1] = new EastNorth(in.readDouble(), in.readDouble()); 183 orgRaster[2] = new EastNorth(in.readDouble(), in.readDouble()); 184 orgRaster[3] = new EastNorth(in.readDouble(), in.readDouble()); 185 orgCroppedRaster[0] = new EastNorth(in.readDouble(), in.readDouble()); 186 orgCroppedRaster[1] = new EastNorth(in.readDouble(), in.readDouble()); 187 orgCroppedRaster[2] = new EastNorth(in.readDouble(), in.readDouble()); 188 orgCroppedRaster[3] = new EastNorth(in.readDouble(), in.readDouble()); 189 } else { 190 orgRaster = null; 191 orgCroppedRaster = null; 192 angle = 0; 193 } 139 194 image = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in)); 140 195 updatePixelPer(); … … 143 198 /** 144 199 * Method required by BufferedImage serialization. 145 * Cache uses only primitives to stay independent of software changes.200 * Use only primitives for stability in time (not influenced by josm-core changes). 146 201 */ 147 202 private void writeObject(ObjectOutputStream out) throws IOException { 148 out.writeDouble(max.getX()); 149 out.writeDouble(max.getY()); 150 out.writeDouble(min.getX()); 151 out.writeDouble(min.getY()); 203 out.writeDouble(max.getX()); out.writeDouble(max.getY()); 204 out.writeDouble(min.getX()); out.writeDouble(min.getY()); 205 if (orgRaster == null) { // just in case we save an old format layer already cached 206 orgRaster = new EastNorth[4]; 207 orgCroppedRaster = new EastNorth[4]; 208 } 209 out.writeDouble(angle); 210 out.writeDouble(orgRaster[0].getX()); out.writeDouble(orgRaster[0].getY()); 211 out.writeDouble(orgRaster[1].getX()); out.writeDouble(orgRaster[1].getY()); 212 out.writeDouble(orgRaster[2].getX()); out.writeDouble(orgRaster[2].getY()); 213 out.writeDouble(orgRaster[3].getX()); out.writeDouble(orgRaster[3].getY()); 214 out.writeDouble(orgCroppedRaster[0].getX()); out.writeDouble(orgCroppedRaster[0].getY()); 215 out.writeDouble(orgCroppedRaster[1].getX()); out.writeDouble(orgCroppedRaster[1].getY()); 216 out.writeDouble(orgCroppedRaster[2].getX()); out.writeDouble(orgCroppedRaster[2].getY()); 217 out.writeDouble(orgCroppedRaster[3].getX()); out.writeDouble(orgCroppedRaster[3].getY()); 152 218 ImageIO.write(image, "png", ImageIO.createImageOutputStream(out)); 153 219 } … … 182 248 min = new EastNorth(min.east() + dx, min.north() + dy); 183 249 max = new EastNorth(max.east() + dx, max.north() + dy); 250 for (int i=0; i<4; i++) { 251 orgRaster[i] = new EastNorth(orgRaster[i].east() + dx, orgRaster[i].north() + dy); 252 orgCroppedRaster[i] = new EastNorth(orgCroppedRaster[i].east() + dx, orgCroppedRaster[i].north() + dy); 253 } 184 254 } 185 255 … … 192 262 min = anchor.interpolate(min, proportion); 193 263 max = anchor.interpolate(max, proportion); 264 for (int i=0; i<4; i++) { 265 orgRaster[i] = anchor.interpolate(orgRaster[i], proportion); 266 orgCroppedRaster[i] = anchor.interpolate(orgCroppedRaster[i], proportion); 267 } 194 268 updatePixelPer(); 195 269 } … … 198 272 * Rotate this image and its min/max coordinates around anchor point 199 273 * @param anchor anchor of rotation 200 * @param angle angle of rotation (in radians) 201 */ 202 public void rotate(EastNorth anchor, double angle) { 203 EastNorth min2 = new EastNorth(min.east(), max.north()); 204 EastNorth max2 = new EastNorth(max.east(), min.north()); 205 min = min.rotate(anchor, angle); 206 max = max.rotate(anchor, angle); 207 min2 = min2.rotate(anchor, angle); 208 max2 = max2.rotate(anchor, angle); 209 getNewBounding(min, max, min2, max2); 210 image = tilt(image, angle); 211 } 212 213 /** 214 * Rotate by copying original buffered image into a new one with new dimensions 215 * @param image 216 * @param angle 217 * @return 218 */ 219 public static BufferedImage tilt(BufferedImage image, double angle) { 220 double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); 274 * @param ang angle of rotation (in radian) 275 */ 276 public void rotate(EastNorth anchor, double ang) { 277 // rotate the bounding boxes coordinates first 278 EastNorth min2 = new EastNorth(orgRaster[0].east(), orgRaster[2].north()); 279 EastNorth max2 = new EastNorth(orgRaster[2].east(), orgRaster[0].north()); 280 for (int i=0; i<4; i++) { 281 orgRaster[i] = orgRaster[i].rotate(anchor, ang); 282 orgCroppedRaster[i] = orgCroppedRaster[i].rotate(anchor, ang); 283 } 284 min2 = min2.rotate(anchor, ang); 285 max2 = max2.rotate(anchor, ang); 286 EastNorthBound enb = getNewBounding(orgCroppedRaster[0], orgCroppedRaster[2], min2, max2); 287 min = enb.min; 288 max = enb.max; 289 angle=+ang; 290 291 // rotate the image now 292 double sin = Math.abs(Math.sin(ang)), cos = Math.abs(Math.cos(ang)); 221 293 int w = image.getWidth(), h = image.getHeight(); 222 294 int neww = (int)Math.floor(w*cos+h*sin), newh = (int)Math.floor(h*cos+w*sin); … … 225 297 Graphics2D g = result.createGraphics(); 226 298 g.translate((neww-w)/2, (newh-h)/2); 227 g.rotate(ang le, w/2, h/2);299 g.rotate(ang, w/2, h/2); 228 300 g.drawRenderedImage(image, null); 229 301 g.dispose(); 230 returnresult;302 image = result; 231 303 } 232 304 -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java
r18544 r19371 5 5 6 6 import java.awt.Cursor; 7 import java.awt.Toolkit; 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.MouseEvent; … … 87 88 if (e.getButton() != MouseEvent.BUTTON1) 88 89 return; 89 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;90 boolean ctrl = (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0; 90 91 // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 91 92 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 92 if (shift )93 if (shift && !ctrl) 93 94 mode = Mode.moveZ; 94 else if ( ctrl)95 else if (shift && ctrl) 95 96 mode = Mode.rotate; 96 97 else -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r19267 r19371 51 51 protected Vector<GeorefImage> images = new Vector<GeorefImage>(); 52 52 53 protected final int serializeFormatVersion = 2; 53 /** 54 * v1 to v2 = not supported 55 * v2 to v3 = add 4 more EastNorth coordinates in GeorefImages 56 */ 57 protected final int serializeFormatVersion = 3; 58 59 public static int currentFormat; 54 60 55 61 private ArrayList<EastNorthBound> dividedBbox = new ArrayList<EastNorthBound>(); … … 69 75 public double X0, Y0, angle, fX, fY; 70 76 77 // bbox of the georeferenced raster image (the nice horizontal and vertical box) 71 78 private EastNorth rasterMin; 72 79 private EastNorth rasterMax; … … 89 96 90 97 public void destroy() { 98 // if the layer is currently saving the images in the cache, wait until it's finished 99 while (!cacheControl.isCachePipeEmpty()) { 100 System.out.println("Try to close a WMSLayer which is currently saving in cache : wait 1 sec."); 101 CadastrePlugin.safeSleep(1000); 102 } 91 103 super.destroy(); 92 104 images = null; … … 364 376 double ratio = rasterSizeY/rasterSizeX; 365 377 // keep same ratio on screen as WMS bbox (stored in communeBBox) 366 rasterMin = new EastNorth(eaMin.getX(), rasterCenter.getY()-(eaMax.getX()-eaMin.getX())*ratio/2); 367 rasterMax = new EastNorth(eaMax.getX(), rasterCenter.getY()+(eaMax.getX()-eaMin.getX())*ratio/2); 378 rasterMin = new EastNorth(eaMin.getX(), rasterCenter.getY()-(eaMax.getX()-eaMin.getX())*ratio/2); 379 rasterMax = new EastNorth(eaMax.getX(), rasterCenter.getY()+(eaMax.getX()-eaMin.getX())*ratio/2); 368 380 rasterRatio = (rasterMax.getX()-rasterMin.getX())/rasterSizeX; 369 381 } … … 402 414 */ 403 415 public boolean read(ObjectInputStream ois, int currentLambertZone) throws IOException, ClassNotFoundException { 404 int sfv = ois.readInt();405 if ( sfv != this.serializeFormatVersion) {416 currentFormat = ois.readInt();; 417 if (currentFormat < 2) { 406 418 JOptionPane.showMessageDialog(Main.parent, tr("Unsupported cache file version; found {0}, expected {1}\nCreate a new one.", 407 sfv, this.serializeFormatVersion), tr("Cache Format Error"), JOptionPane.ERROR_MESSAGE);419 currentFormat, this.serializeFormatVersion), tr("Cache Format Error"), JOptionPane.ERROR_MESSAGE); 408 420 return false; 409 421 } … … 531 543 public void setCommuneBBox(EastNorthBound entireCommune) { 532 544 this.communeBBox = entireCommune; 533 // if (Main.proj instanceof LambertCC9Zones)534 // setLambertCC9Zone(communeBBox.min.north());535 545 } 536 546 … … 545 555 return lambertZone; 546 556 } 547 548 // public void setLambertCC9Zone(double north) {549 // int lambertZone = LambertCC9Zones.north2ZoneNumber(north);550 // this.lambertZone = lambertZone;551 // if (((LambertCC9Zones)Main.proj).getLayoutZone() != lambertZone) {552 // String currentZone = MenuActionLambertZone.lambert9zones[((LambertCC9Zones)Main.proj).getLayoutZone()+1];553 // String destZone = MenuActionLambertZone.lambert9zones[lambertZone+1];554 // if (Main.map.mapView.getAllLayers().size() == 1) {555 // /* Enable this code below when JOSM will have a proper support of dynamic projection change556 // *557 // System.out.println("close all layers and change current Lambert zone from "+LambertCC9Zones.layoutZone+" to "+lambertZone);558 // Bounds b = null;559 // if (Main.map != null && Main.map.mapView != null)560 // b = Main.map.mapView.getRealBounds();561 // LambertCC9Zones.layoutZone = lambertZone;562 // Main.map.mapView.zoomTo(b);563 // */564 // } else {565 // JOptionPane.showMessageDialog(Main.parent, tr("Current layer is in Lambert CC9 Zone \"{0}\"\n"+566 // "where the commune is in Lambert CC9 Zone \"{1}\".\n"+567 // "Upload your changes, close all layers and change\n"+568 // "manually the Lambert zone from the Cadastre menu"569 // , currentZone, destZone));570 // }571 // }572 // }573 557 574 558 public EastNorth getRasterCenter() {
Note:
See TracChangeset
for help on using the changeset viewer.