Changeset 26823 in osm for applications/editors/josm/plugins/cadastre-fr
- Timestamp:
- 2011-10-09T23:41:21+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/DownloadWMSVectorImage.java
r26509 r26823 36 36 if (CacheControl.cacheEnabled) { 37 37 if (wmsLayer.grabThread.getCacheControl().loadCacheIfExist()) { 38 Main.map.mapView.zoomTo(wmsLayer.get CommuneBBox().toBounds());38 Main.map.mapView.zoomTo(wmsLayer.getFirstViewFromCacheBBox().toBounds()); 39 39 //Main.map.mapView.repaint(); 40 40 return; -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java
r24955 r26823 29 29 public EastNorth min; 30 30 public EastNorth max; 31 // offset for vector images temporarily shifted (correcting Cadastre artifacts), in pixels 32 public double deltaEast=0; 33 public double deltaNorth=0; 31 34 // bbox of the georeferenced original image (raster only) (inclined if rotated and before cropping) 32 35 // P[0] is bottom,left then next are clockwise. … … 107 110 return; 108 111 109 Point minPt = nc.getPoint(min), maxPt = nc.getPoint(max); 112 // apply offsets defined manually when vector images are translated manually (not saved in cache) 113 Point minPt = nc.getPoint(new EastNorth(min.east()+deltaEast, min.north()+deltaNorth)); 114 Point maxPt = nc.getPoint(new EastNorth(max.east()+deltaEast, max.north()+deltaNorth)); 110 115 111 116 if (!g.hitClip(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y)) … … 171 176 double maxMaskNorth = (georefImage.max.north() < this.max.north()) ? georefImage.max.north() : this.max.north(); 172 177 if ((maxMaskNorth - minMaskNorth) > 0 && (maxMaskEast - minMaskEast) > 0) { 173 double p ixelPerEast = (max.east() - min.east()) / image.getWidth();174 double p ixelPerNorth = (max.north() - min.north()) / image.getHeight();175 int minXMaskPixel = (int) ((minMaskEast - min.east()) / p ixelPerEast);176 int minYMaskPixel = (int) ((max.north() - maxMaskNorth) / p ixelPerNorth);177 int widthXMaskPixel = Math.abs((int) ((maxMaskEast - minMaskEast) / p ixelPerEast));178 int heightYMaskPixel = Math.abs((int) ((maxMaskNorth - minMaskNorth) / p ixelPerNorth));178 double pxPerEast = (max.east() - min.east()) / image.getWidth(); 179 double pxPerNorth = (max.north() - min.north()) / image.getHeight(); 180 int minXMaskPixel = (int) ((minMaskEast - min.east()) / pxPerEast); 181 int minYMaskPixel = (int) ((max.north() - maxMaskNorth) / pxPerNorth); 182 int widthXMaskPixel = Math.abs((int) ((maxMaskEast - minMaskEast) / pxPerEast)); 183 int heightYMaskPixel = Math.abs((int) ((maxMaskNorth - minMaskNorth) / pxPerNorth)); 179 184 Graphics g = image.getGraphics(); 180 185 for (int x = minXMaskPixel; x < minXMaskPixel + widthXMaskPixel; x++) … … 279 284 } 280 285 } 281 286 282 287 /** 283 288 * Change this image scale by moving the min,max coordinates around an anchor … … 364 369 } 365 370 371 /** 372 * Add a temporary translation (dx, dy) to this image (for vector images only) 373 * @param dx delta added to X image coordinate 374 * @param dy delta added to Y image coordinate 375 */ 376 public void tempShear(double dx, double dy) { 377 this.deltaEast+=dx; 378 this.deltaNorth+=dy; 379 } 366 380 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSAdjustAction.java
r24934 r26823 12 12 import java.awt.event.MouseListener; 13 13 import java.awt.event.MouseMotionListener; 14 import java.util.ArrayList;15 14 16 15 import javax.swing.JOptionPane; … … 22 21 import org.openstreetmap.josm.data.coor.EastNorth; 23 22 import org.openstreetmap.josm.tools.ImageProvider; 24 import org.openstreetmap.josm.gui.layer.Layer;25 23 26 24 public class WMSAdjustAction extends MapMode implements … … 28 26 29 27 private static final long serialVersionUID = 1L; 30 private ArrayList<WMSLayer> modifiedLayers = new ArrayList<WMSLayer>(); 31 WMSLayer selectedLayer; 28 private WMSLayer modifiedLayer = null; 32 29 private boolean rasterMoved; 33 30 private EastNorth prevEastNorth; … … 38 35 public WMSAdjustAction(MapFrame mapFrame) { 39 36 super(tr("Adjust WMS"), "adjustxywms", 40 tr("Adjust the position of the WMS layer (raster images only)"), mapFrame, 37 tr("Adjust the position of the WMS layer (saved for raster images only)"), mapFrame, 41 38 ImageProvider.getCursor("normal", "move")); 42 39 } … … 44 41 @Override public void enterMode() { 45 42 if (Main.map != null) { 46 selectedLayer = null; 47 WMSLayer possibleLayer = null; 48 int cRasterLayers = 0; 49 for (Layer l : Main.map.mapView.getAllLayers()) { 50 if (l instanceof WMSLayer && ((WMSLayer)l).isRaster()) { 51 possibleLayer = (WMSLayer)l; 52 cRasterLayers++; 53 } 54 } 55 Layer activeLayer = Main.map.mapView.getActiveLayer(); 56 if (activeLayer instanceof WMSLayer && ((WMSLayer)activeLayer).isRaster()) { 57 selectedLayer = (WMSLayer)activeLayer; 58 } else if (cRasterLayers == 1) { 59 selectedLayer = possibleLayer; 60 } 61 if (selectedLayer != null) { 43 if (Main.map.mapView.getActiveLayer() instanceof WMSLayer) { 44 modifiedLayer = (WMSLayer)Main.map.mapView.getActiveLayer(); 62 45 super.enterMode(); 63 46 Main.map.mapView.addMouseListener(this); 64 47 Main.map.mapView.addMouseMotionListener(this); 65 48 rasterMoved = false; 66 selectedLayer.adjustModeEnabled = true;49 modifiedLayer.adjustModeEnabled = true; 67 50 } else { 68 JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n" 69 +"a cadastre \"plan image\" (raster image)"));51 // JOptionPane.showMessageDialog(Main.parent,tr("This mode works only if active layer is\n" 52 // +"a cadastre layer")); 70 53 exitMode(); 71 54 Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction()); … … 78 61 Main.map.mapView.removeMouseListener(this); 79 62 Main.map.mapView.removeMouseMotionListener(this); 80 if (rasterMoved && CacheControl.cacheEnabled) { 63 if (rasterMoved && CacheControl.cacheEnabled && modifiedLayer.isRaster()) { 81 64 int reply = JOptionPane.showConfirmDialog(null, 82 65 "Save the changes in cache ?", … … 87 70 } 88 71 } 89 modifiedLayers.clear();90 if ( selectedLayer != null) {91 selectedLayer.adjustModeEnabled = false;92 selectedLayer = null;72 rasterMoved = false; 73 if (modifiedLayer != null) { 74 modifiedLayer.adjustModeEnabled = false; 75 modifiedLayer = null; 93 76 } 94 77 } … … 101 84 // boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0; 102 85 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0; 103 if (shift && !ctrl) 86 if (shift && !ctrl && modifiedLayer.isRaster()) 104 87 mode = Mode.moveZ; 105 else if (shift && ctrl) 88 else if (shift && ctrl && modifiedLayer.isRaster()) 106 89 mode = Mode.rotate; 107 90 else … … 124 107 prevEastNorth = newEastNorth; 125 108 } 126 if (!modifiedLayers.contains(selectedLayer))127 modifiedLayers.add(selectedLayer);128 109 Main.map.mapView.repaint(); 129 110 } … … 141 122 142 123 private void displace(EastNorth start, EastNorth end) { 143 selectedLayer.displace(end.east()-start.east(), end.north()-start.north());124 modifiedLayer.displace(end.east()-start.east(), end.north()-start.north()); 144 125 } 145 126 146 127 private void resize(EastNorth newEastNorth) { 147 EastNorth center = selectedLayer.getRasterCenter();128 EastNorth center = modifiedLayer.getRasterCenter(); 148 129 double dPrev = prevEastNorth.distance(center.east(), center.north()); 149 130 double dNew = newEastNorth.distance(center.east(), center.north()); 150 selectedLayer.resize(center, dNew/dPrev);131 modifiedLayer.resize(center, dNew/dPrev); 151 132 } 152 133 153 134 private void rotate(EastNorth start, EastNorth end) { 154 EastNorth pivot = selectedLayer.getRasterCenter();135 EastNorth pivot = modifiedLayer.getRasterCenter(); 155 136 double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); 156 137 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 157 138 double rotationAngle = endAngle - startAngle; 158 selectedLayer.rotate(pivot, rotationAngle);139 modifiedLayer.rotate(pivot, rotationAngle); 159 140 } 160 141 161 142 private void rotateFrameOnly(EastNorth start, EastNorth end) { 162 143 if (start != null && end != null) { 163 EastNorth pivot = selectedLayer.getRasterCenter();144 EastNorth pivot = modifiedLayer.getRasterCenter(); 164 145 double startAngle = Math.atan2(start.east()-pivot.east(), start.north()-pivot.north()); 165 146 double endAngle = Math.atan2(end.east()-pivot.east(), end.north()-pivot.north()); 166 147 double rotationAngle = endAngle - startAngle; 167 if ( selectedLayer.getImage(0).orgCroppedRaster != null) {148 if (modifiedLayer.getImage(0).orgCroppedRaster != null) { 168 149 for (int i=0; i<4; i++) { 169 croppedRaster[i] = selectedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle);150 croppedRaster[i] = modifiedLayer.getImage(0).orgCroppedRaster[i].rotate(pivot, rotationAngle); 170 151 } 171 152 croppedRaster[4] = croppedRaster[0]; … … 197 178 198 179 private void saveModifiedLayers() { 199 for (WMSLayer wmsLayer : modifiedLayers) { 200 wmsLayer.grabThread.saveNewCache(); 201 } 180 modifiedLayer.grabThread.saveNewCache(); 202 181 } 203 182 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r26509 r26823 11 11 import java.awt.RenderingHints; 12 12 import java.awt.Toolkit; 13 import java.awt.event.ActionEvent; 13 14 import java.awt.image.BufferedImage; 14 15 import java.awt.image.ImageObserver; … … 29 30 30 31 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.actions.JosmAction; 31 33 import org.openstreetmap.josm.data.Bounds; 32 34 import org.openstreetmap.josm.data.coor.EastNorth; … … 87 89 private Action cancelGrab; 88 90 91 @SuppressWarnings("serial") 92 class ResetOffsetActionMenu extends JosmAction { 93 private WMSLayer wmsLayer; 94 public ResetOffsetActionMenu(WMSLayer wmsLayer) { 95 super(tr("Reset offset"), null, tr("Reset offset (only vector images)"), null, false); 96 this.wmsLayer = wmsLayer; 97 } 98 @Override 99 public void actionPerformed(ActionEvent arg0) { 100 for (GeorefImage img:wmsLayer.images) { 101 img.deltaEast = 0; 102 img.deltaNorth = 0; 103 } 104 Main.map.mapView.repaint(); 105 } 106 107 } 108 89 109 public boolean adjustModeEnabled; 90 110 … … 213 233 dividedBbox.add(new EastNorthBound(mid, new EastNorth(mid.east()+c, mid.north()+c))); 214 234 } 215 // // simple algorithm to grab all squares216 // minEast = minEast - minEast % cSquare;217 // minNorth = minNorth - minNorth % cSquare;218 // for (int xEast = (int)minEast; xEast < lambertMax.east(); xEast+=cSquare)219 // for (int xNorth = (int)minNorth; xNorth < lambertMax.north(); xNorth+=cSquare) {220 // dividedBbox.add(new EastNorthBound(new EastNorth(xEast, xNorth),221 // new EastNorth(xEast + cSquare, xNorth + cSquare)));222 // }223 235 } 224 236 } … … 297 309 cancelGrab = new MenuActionCancelGrab(this); 298 310 cancelGrab.setEnabled(!isRaster && grabThread.getImagesToGrabSize() > 0); 311 Action resetOffset = new ResetOffsetActionMenu(this); 312 resetOffset.setEnabled(!isRaster && images.size() > 0 && (images.get(0).deltaEast!=0.0 || images.get(0).deltaNorth!=0.0)); 299 313 return new Action[] { 300 314 LayerListDialog.getInstance().createShowHideLayerAction(), … … 303 317 saveAsPng, 304 318 cancelGrab, 319 resetOffset, 305 320 new LayerListPopup.InfoAction(this), 306 321 … … 566 581 return communeBBox; 567 582 } 583 584 public EastNorthBound getFirstViewFromCacheBBox() { 585 if (isRaster) { 586 return communeBBox; 587 } 588 double min_x = Double.MAX_VALUE; 589 double max_x = Double.MIN_VALUE; 590 double min_y = Double.MAX_VALUE; 591 double max_y = Double.MIN_VALUE; 592 for (GeorefImage image:images){ 593 min_x = image.min.east() < min_x ? image.min.east() : min_x; 594 max_x = image.max.east() > max_x ? image.max.east() : max_x; 595 min_y = image.min.north() < min_y ? image.min.north() : min_y; 596 max_y = image.max.north() > max_y ? image.max.north() : max_y; 597 } 598 EastNorthBound maxGrabbedBBox = new EastNorthBound(new EastNorth(min_x, min_y), new EastNorth(max_x, max_y)); 599 return maxGrabbedBBox; 600 } 568 601 569 602 public void setCommuneBBox(EastNorthBound entireCommune) { … … 588 621 589 622 public void displace(double dx, double dy) { 590 this.rasterMin = new EastNorth(rasterMin.east() + dx, rasterMin.north() + dy); 591 this.rasterMax = new EastNorth(rasterMax.east() + dx, rasterMax.north() + dy); 592 images.get(0).shear(dx, dy); 623 if (isRaster) { 624 this.rasterMin = new EastNorth(rasterMin.east() + dx, rasterMin.north() + dy); 625 this.rasterMax = new EastNorth(rasterMax.east() + dx, rasterMax.north() + dy); 626 images.get(0).shear(dx, dy); 627 } else { 628 for (GeorefImage image:images) 629 image.tempShear(dx, dy); 630 } 593 631 } 594 632
Note:
See TracChangeset
for help on using the changeset viewer.