Changeset 24186 in osm for applications/editors/josm
- Timestamp:
- 2010-11-10T20:39:33+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/pdfimport/src/pdfimport
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/src/pdfimport/FilePlacement.java
r24080 r24186 1 1 package pdfimport; 2 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import java.awt.geom.AffineTransform; 6 import java.awt.geom.Point2D; 3 7 import java.util.Properties; 4 8 … … 18 22 public double minNorth = 0; 19 23 public double maxNorth = 10000; 24 25 private AffineTransform transform; 26 20 27 21 28 public void setPdfBounds(double minX, double minY, double maxX, double maxY){ … … 31 38 this.minNorth = minNorth; 32 39 this.maxNorth = maxNorth; 33 } 40 } 34 41 35 42 public Properties toProperties() { … … 91 98 } 92 99 100 101 public String prepareTransform() 102 { 103 if (this.minX >= this.maxX){ 104 return tr("Transform error: Min X must be smaller than max"); 105 } 106 107 if (this.minY >= this.maxY){ 108 return tr("Transform error: Min Y must be smaller than max"); 109 } 110 111 112 if (this.minEast < this.maxEast && this.minNorth < this.maxNorth) { 113 //no rotation 114 this.transform = new AffineTransform(); 115 this.transform.translate(-this.minX, -this.minY); 116 this.transform.scale( 117 (this.maxEast - this.minEast) / (this.maxX - this.minX), 118 (this.maxNorth - this.minNorth) / (this.maxY - this.minY)); 119 this.transform.translate(this.minEast, this.minNorth); 120 } else if (this.minEast < this.maxEast && this.minNorth > this.maxNorth) { 121 //need to rotate 90 degrees counterclockwise 122 //transform to 0..1, 0..1 range 123 this.transform.translate(-this.minX, -this.minY); 124 this.transform.scale(1/(this.maxX - this.minX), 1/(this.minY - this.maxY)); 125 126 //rotate -90 degs around center 127 this.transform.quadrantRotate(-1, 0.5, 0.5); 128 129 //transform back to target range 130 this.transform.scale( 131 (this.maxEast - this.minEast), 132 (this.minNorth - this.maxNorth)); 133 this.transform.translate(this.minEast, this.maxNorth); 134 } else if (this.minEast > this.maxEast && this.minNorth < this.maxNorth) { 135 //need to rotate 90 degrees clockwise 136 //transform to 0..1, 0..1 range 137 this.transform.translate(-this.minX, -this.minY); 138 this.transform.scale(1/(this.maxX - this.minX), 1/(this.maxY - this.minY)); 139 140 //rotate 90 degs around center 141 this.transform.quadrantRotate(1, 0.5, 0.5); 142 143 //transform back to target range 144 this.transform.scale( 145 (this.minEast - this.maxEast), 146 (this.maxNorth - this.minNorth)); 147 this.transform.translate(this.maxEast, this.minNorth); 148 } 149 else 150 { 151 return tr("Transform error: Unsupported orientation"); 152 } 153 154 return null; 155 156 } 157 93 158 EastNorth en = new EastNorth(0, 0); 159 Point2D src = new Point2D.Double(); 94 160 95 public LatLon tranformCoords( double x, double y) {161 public LatLon tranformCoords(Point2D pt) { 96 162 97 163 if (this.projection == null){ 98 //en.setLocation(x * 1024,y * 1024); 99 //return Main.proj.eastNorth2latlon( en); 100 return new LatLon(y / 1000, x / 1000); 164 return new LatLon(pt.getY() / 1000, pt.getX() / 1000); 101 165 } 102 166 else{ 103 104 x = (x - this.minX) * (this.maxEast - this.minEast) / (this.maxX - this.minX) + this.minEast; 105 y = (y - this.minY) * (this.maxNorth - this.minNorth) / (this.maxY - this.minY) + this.minNorth; 106 en.setLocation(x,y); 167 this.transform.transform(pt, en); 107 168 return this.projection.eastNorth2latlon(en); 108 169 } … … 111 172 public EastNorth reverseTransform(LatLon coor) { 112 173 if (this.projection == null){ 113 //EastNorth result = this.projection.latlon2eastNorth(coor); 114 //result.setLocation(result.east() / 1024, result.north() / 1024); 115 //return result; 174 116 175 return new EastNorth(coor.lon() * 1000, coor.lat() * 1000); 117 176 } -
applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java
r24080 r24186 176 176 this.debugModeCheck = new JCheckBox(tr("Debug info")); 177 177 this.mergeCloseNodesCheck = new JCheckBox(tr("Merge close nodes")); 178 this.mergeCloseNodesTolerance = new JTextField("1e- 6");178 this.mergeCloseNodesTolerance = new JTextField("1e-3"); 179 179 180 180 this.removeSmallObjectsCheck = new JCheckBox(tr("Remove objects smaller than")); … … 196 196 c.gridx = 0; c.gridy = 0; c.gridwidth = 1; 197 197 configPanel.add(this.mergeCloseNodesCheck, c); 198 c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.anchor = c.NORTHEAST;198 c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHEAST; 199 199 configPanel.add(new JLabel("Tolerance :"), c); 200 c.gridx = 2; c.gridy = 0; c.gridwidth = 1; c.anchor = c.NORTHWEST;200 c.gridx = 2; c.gridy = 0; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; 201 201 configPanel.add(this.mergeCloseNodesTolerance, c); 202 202 203 203 c.gridx = 0; c.gridy = 1; c.gridwidth = 1; 204 204 configPanel.add(this.removeSmallObjectsCheck, c); 205 c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.anchor = c.NORTHEAST;205 c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHEAST; 206 206 configPanel.add(new JLabel("Tolerance :"), c); 207 c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.anchor = c.NORTHWEST;207 c.gridx = 2; c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; 208 208 configPanel.add(this.removeSmallObjectsSize, c); 209 209 210 210 c.gridx = 0; c.gridy = 2; c.gridwidth = 1; 211 211 configPanel.add(this.removeLargeObjectsCheck, c); 212 c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.anchor = c.NORTHEAST;212 c.gridx = 1; c.gridy = 2; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHEAST; 213 213 configPanel.add(new JLabel("Tolerance :"), c); 214 c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.anchor = c.NORTHWEST;214 c.gridx = 2; c.gridy = 2; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; 215 215 configPanel.add(this.removeLargeObjectsSize, c); 216 216 217 217 c.gridx = 0; c.gridy = 3; c.gridwidth = 1; 218 218 configPanel.add(this.removeParallelSegmentsCheck, c); 219 c.gridx = 1; c.gridy = 3; c.gridwidth = 1; c.anchor = c.NORTHEAST;219 c.gridx = 1; c.gridy = 3; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHEAST; 220 220 configPanel.add(new JLabel("Max distance :"), c); 221 c.gridx = 2; c.gridy = 3; c.gridwidth = 1; c.anchor = c.NORTHWEST;221 c.gridx = 2; c.gridy = 3; c.gridwidth = 1; c.anchor = GridBagConstraints.NORTHWEST; 222 222 configPanel.add(this.removeParallelSegmentsTolerance, c); 223 223 … … 323 323 public void actionPerformed(ActionEvent e) { 324 324 if (data!= null) { 325 LoadPdfDialog.this.placement.projection = null;326 325 OsmBuilder.Mode mode = LoadPdfDialog.this.debugModeCheck.isSelected() ? OsmBuilder.Mode.Debug: OsmBuilder.Mode.Draft; 327 326 LoadPdfDialog.this.fileName = newFileName; 328 LoadPdfDialog.this.makeLayer(tr("PDF file preview"), mode);327 LoadPdfDialog.this.makeLayer(tr("PDF file preview"), new FilePlacement(), mode); 329 328 LoadPdfDialog.this.loadFileButton.setText(tr("Loaded")); 330 329 LoadPdfDialog.this.loadFileButton.setEnabled(true); … … 336 335 } 337 336 338 339 private void okPressed() {340 337 338 private boolean preparePlacement() 339 { 341 340 boolean ok = this.parsePlacement(); 342 341 if (!ok){ 342 JOptionPane.showMessageDialog(Main.parent, tr("Problems parsing placement.")); 343 return false; 344 } 345 346 String transformError = this.placement.prepareTransform(); 347 if (transformError != null){ 348 JOptionPane.showMessageDialog(Main.parent, transformError); 349 } 350 351 this.savePlacement(); 352 353 return true; 354 } 355 356 private void okPressed() { 357 358 if (!preparePlacement()) { 343 359 return; 344 360 } 345 361 346 this.savePlacement();347 348 362 //rebuild layer with latest projection 349 this.makeLayer(tr("Imported PDF: ") + this.fileName, OsmBuilder.Mode.Final);363 this.makeLayer(tr("Imported PDF: ") + this.fileName, this.placement, OsmBuilder.Mode.Final); 350 364 351 365 this.setVisible(false); … … 353 367 354 368 private void savePressed() { 355 boolean ok = this.parsePlacement(); 356 if (! ok){369 370 if (!preparePlacement()) { 357 371 return; 358 } 372 } 359 373 360 374 java.io.File file = this.chooseSaveFile(); … … 362 376 if (file == null){ 363 377 return; 364 } 365 366 this.savePlacement(); 367 378 } 379 368 380 //rebuild layer with latest projection 369 381 this.removeLayer(); 382 383 370 384 this.saveLayer(file); 371 385 this.setVisible(false); … … 675 689 676 690 677 private void makeLayer(String name, OsmBuilder.Mode mode) {691 private void makeLayer(String name, FilePlacement placement, OsmBuilder.Mode mode) { 678 692 this.removeLayer(); 679 693 … … 682 696 } 683 697 684 OsmBuilder builder = new OsmBuilder( this.placement);698 OsmBuilder builder = new OsmBuilder(placement); 685 699 686 700 DataSet data = builder.build(this.data.getLayers(), mode); … … 707 721 } 708 722 709 private void saveLayer(java.io.File file) { 723 private void saveLayer(java.io.File file) { 710 724 OsmBuilder builder = new OsmBuilder(this.placement); 711 725 DataSet data = builder.build(this.data.getLayers(), OsmBuilder.Mode.Final); -
applications/editors/josm/plugins/pdfimport/src/pdfimport/OsmBuilder.java
r24056 r24186 35 35 36 36 public Bounds getWorldBounds(PathOptimizer data) { 37 LatLon min = placement.tranformCoords( data.bounds.getMinX(), data.bounds.getMinY());38 LatLon max = placement.tranformCoords( data.bounds.getMaxX(), data.bounds.getMaxY());37 LatLon min = placement.tranformCoords(new Point2D.Double(data.bounds.getMinX(), data.bounds.getMinY())); 38 LatLon max = placement.tranformCoords(new Point2D.Double(data.bounds.getMaxX(), data.bounds.getMaxY())); 39 39 return new Bounds(min, max); 40 40 } … … 62 62 for(Point2D pt: layer.points) { 63 63 Node node = new Node(); 64 node.setCoor(this.placement.tranformCoords(pt .getX(), pt.getY()));64 node.setCoor(this.placement.tranformCoords(pt)); 65 65 66 66 target.addPrimitive(node);
Note:
See TracChangeset
for help on using the changeset viewer.