Changeset 21846 in osm for applications
- Timestamp:
- 2010-06-21T15:53:53+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/buildings_tools/src/buildings_tools
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/AdvancedSettingsDialog.java
r21803 r21846 18 18 JTextField tBTag = new JTextField(); 19 19 JCheckBox cBigMode = new JCheckBox(tr("Big buildings mode")); 20 JCheckBox cSoftCur = new JCheckBox(tr("Rotate crosshair")); 20 21 21 22 public AdvancedSettingsDialog() { … … 29 30 addLabelled(panel, tr("Building tag:"), tBTag); 30 31 panel.add(cBigMode, GBC.eol().fill(GBC.HORIZONTAL)); 32 panel.add(cSoftCur, GBC.eol().fill(GBC.HORIZONTAL)); 31 33 32 34 tBTag.setText(ToolSettings.getTag()); 33 35 cBigMode.setSelected(ToolSettings.isBBMode()); 36 cSoftCur.setSelected(ToolSettings.isSoftCursor()); 34 37 35 38 setContent(panel); … … 45 48 return cBigMode.isSelected(); 46 49 } 50 51 public boolean isSoftCursor() { 52 return cSoftCur.isSelected(); 53 } 54 55 public void saveSettings() { 56 ToolSettings.setTag(getTag()); 57 ToolSettings.setBBMode(isBBMode()); 58 ToolSettings.setSoftCursor(isSoftCursor()); 59 } 47 60 } -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/Building.java
r21806 r21846 36 36 private double width; 37 37 private double heading; 38 private boolean angConstrained; 39 private double angConstraint = 0; 40 41 public void disableAngConstraint() { 42 angConstrained = false; 43 } 44 45 public void setAngConstraint(double angle) { 46 angConstrained = true; 47 angConstraint = angle; 38 private AngleSnap angleSnap = new AngleSnap(); 39 private Double drawingAngle; 40 41 public void clearAngleSnap() { 42 angleSnap.clear(); 43 drawingAngle = null; 44 } 45 46 public void addAngleSnap(Node[] nodes) { 47 drawingAngle = angleSnap.addSnap(nodes); 48 } 49 50 public void addAngleSnap(Way way) { 51 angleSnap.addSnap(way); 52 if (drawingAngle == null) { 53 drawingAngle = angleSnap.getAngle(); 54 } 48 55 } 49 56 … … 57 64 58 65 public boolean isRectDrawing() { 59 return angConstrained && ToolSettings.getWidth() == 0 && ToolSettings.getLenStep() == 0; 66 return drawingAngle != null && ToolSettings.getWidth() == 0 && ToolSettings.getLenStep() == 0; 67 } 68 69 public Double getDrawingAngle() { 70 return drawingAngle; 60 71 } 61 72 … … 108 119 final EastNorth p1 = en[0]; 109 120 en[1] = new EastNorth(p1.east() + Math.sin(heading) * len * meter, p1.north() + Math.cos(heading) * len * meter); 110 en[2] = new EastNorth(p1.east() + Math.sin(heading) * len * meter + Math.cos(heading) * width * meter, p1 111 .north() 112 + Math.cos(heading) * len * meter - Math.sin(heading) * width * meter); 113 en[3] = new EastNorth(p1.east() + Math.cos(heading) * width * meter, p1.north() - Math.sin(heading) * width 114 * meter); 121 en[2] = new EastNorth(p1.east() + Math.sin(heading) * len * meter + Math.cos(heading) * width * meter, 122 p1.north() + Math.cos(heading) * len * meter - Math.sin(heading) * width * meter); 123 en[3] = new EastNorth(p1.east() + Math.cos(heading) * width * meter, 124 p1.north() - Math.sin(heading) * width * meter); 115 125 } 116 126 … … 130 140 throw new IllegalStateException("setPlace() called without the base point"); 131 141 this.heading = en[0].heading(p2); 132 double hdang = 0; 133 if (angConstrained && !ignoreConstraints) { 134 hdang = Math.round((heading - angConstraint) / Math.PI * 4); 135 hdang = hdang % 8; 136 if (hdang < 0) 137 hdang += 8; 138 heading = (hdang * Math.PI / 4 + angConstraint) % (2 * Math.PI); 139 } 142 if (!ignoreConstraints) 143 this.heading = angleSnap.snapAngle(this.heading); 140 144 141 145 this.width = width; … … 147 151 148 152 Main.map.statusLine.setHeading(Math.toDegrees(heading)); 149 if (angConstrained && !ignoreConstraints) { 150 Main.map.statusLine.setAngle(hdang * 45); 153 if (this.drawingAngle != null && !ignoreConstraints) { 154 double ang = Math.toDegrees(heading - this.drawingAngle); 155 if (ang < 0) 156 ang += 360; 157 if (ang > 360) 158 ang -= 360; 159 Main.map.statusLine.setAngle(ang); 151 160 } 152 161 } … … 157 166 if (!isRectDrawing()) 158 167 throw new IllegalStateException("Invalid drawing mode"); 159 heading = angConstraint;168 heading = drawingAngle; 160 169 setLengthWidth(projection1(p2), projection2(p2)); 161 170 Main.map.statusLine.setHeading(Math.toDegrees(heading)); … … 163 172 164 173 public void angFix(EastNorth point) { 165 EastNorth en3 = this.en[2]; 166 heading = en[0].heading(point); 174 EastNorth en3 = en[2]; 175 EastNorth mid = en[0].getCenter(en3); 176 double radius = en3.distance(mid); 177 heading = mid.heading(point); 178 heading = en[0].heading(mid.add(Math.sin(heading) * radius, Math.cos(heading) * radius)); 167 179 setLengthWidth(projection1(en3), projection2(en3)); 168 this.en[2] = en3;180 en[2] = en3; 169 181 } 170 182 … … 226 238 Way w = new Way(); 227 239 w.addNode(nodes[0]); 228 if (projection 1(en[2]) > 0) {240 if (projection2(en[2]) > 0) { 229 241 w.addNode(nodes[1]); 230 242 w.addNode(nodes[2]); -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingSizeAction.java
r21801 r21846 24 24 BuildingSizeDialog dlg = new BuildingSizeDialog(); 25 25 if (dlg.getValue() == 1) { 26 ToolSettings.setSizes(dlg.width(), dlg.lenstep()); 27 ToolSettings.setAddrDialog(dlg.useAddr()); 26 dlg.saveSettings(); 28 27 } 29 28 } -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingSizeDialog.java
r21801 r21846 55 55 AdvancedSettingsDialog dlg = new AdvancedSettingsDialog(); 56 56 if (dlg.getValue() == 1) { 57 ToolSettings.setTag(dlg.getTag()); 58 ToolSettings.setBBMode(dlg.isBBMode()); 57 dlg.saveSettings(); 59 58 } 60 59 } … … 86 85 return caddr.isSelected(); 87 86 } 87 88 public void saveSettings() { 89 ToolSettings.setSizes(width(), lenstep()); 90 ToolSettings.setAddrDialog(useAddr()); 91 } 88 92 } -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java
r21802 r21846 13 13 import java.awt.Graphics2D; 14 14 import java.awt.Point; 15 import java.awt.RenderingHints; 15 16 import java.awt.Toolkit; 16 17 import java.awt.event.AWTEventListener; 17 18 import java.awt.event.KeyEvent; 18 19 import java.awt.event.MouseEvent; 20 import java.awt.geom.GeneralPath; 21 import java.awt.image.BufferedImage; 19 22 import java.util.Collection; 23 import java.util.LinkedList; 20 24 21 25 import org.openstreetmap.josm.Main; … … 37 41 38 42 @SuppressWarnings("serial") 39 public class DrawBuildingAction extends MapMode 40 implements MapViewPaintable, AWTEventListener, SelectionChangedListener { 43 public class DrawBuildingAction extends MapMode implements MapViewPaintable, AWTEventListener, SelectionChangedListener { 41 44 enum Mode { 42 45 None, Drawing, DrawingWidth, DrawingAngFix … … 46 49 final private Cursor cursorJoinNode; 47 50 private Cursor currCursor; 51 private Cursor customCursor; 48 52 49 53 private Mode mode = Mode.None; … … 51 55 52 56 private Color selectedColor; 57 private Point drawStartPos; 53 58 private Point mousePos; 54 private Point drawStartPos; 59 private boolean isCtrlDown; 60 private boolean isShiftDown; 55 61 56 62 Building building = new Building(); … … 129 135 Main.map.mapView.addTemporaryLayer(this); 130 136 DataSet.selListeners.add(this); 131 update Constraint(getCurrentDataSet().getSelected());137 updateSnap(getCurrentDataSet().getSelected()); 132 138 try { 133 139 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); … … 167 173 return; 168 174 KeyEvent ev = (KeyEvent) arg0; 169 if (ev.getKeyCode() == KeyEvent.VK_ESCAPE) 175 int modifiers = ev.getModifiersEx(); 176 boolean isCtrlDown = (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0; 177 boolean isShiftDown = (modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0; 178 if (this.isCtrlDown != isCtrlDown || this.isShiftDown != isShiftDown) { 179 this.isCtrlDown = isCtrlDown; 180 this.isShiftDown = isShiftDown; 181 updCursor(); 182 } 183 ev.getID(); 184 185 if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) { 186 if (mode != Mode.None) 187 ev.consume(); 188 170 189 cancelDrawing(); 171 } 172 173 private EastNorth getPoint(MouseEvent e) { 190 } 191 } 192 193 private EastNorth getEastNorth() { 174 194 Node n; 175 if ( e.isControlDown()) {195 if (isCtrlDown) { 176 196 n = null; 177 197 } else { … … 185 205 } 186 206 187 private Mode modeDrawing(MouseEvent e) { 188 EastNorth p = getPoint(e); 189 if (building.isRectDrawing() && (!e.isShiftDown() || ToolSettings.isBBMode())) { 207 private boolean isRectDrawing() { 208 return building.isRectDrawing() && (!isShiftDown || ToolSettings.isBBMode()); 209 } 210 211 private Mode modeDrawing() { 212 EastNorth p = getEastNorth(); 213 if (isRectDrawing()) { 190 214 building.setPlaceRect(p); 191 return e.isShiftDown() ? Mode.DrawingAngFix : Mode.None; 192 } else { 193 building.setPlace(p, ToolSettings.getWidth(), 194 ToolSettings.getLenStep(), e.isShiftDown()); 215 return isShiftDown ? Mode.DrawingAngFix : Mode.None; 216 } else { 217 building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), isShiftDown); 195 218 Main.map.statusLine.setDist(building.getLength()); 196 219 return this.nextMode = ToolSettings.getWidth() == 0 ? Mode.DrawingWidth : Mode.None; … … 198 221 } 199 222 200 private Mode modeDrawingWidth( MouseEvent e) {201 building.setWidth(get Point(e));223 private Mode modeDrawingWidth() { 224 building.setWidth(getEastNorth()); 202 225 Main.map.statusLine.setDist(Math.abs(building.getWidth())); 203 226 return Mode.None; 204 227 } 205 228 206 private Mode modeDrawingAngFix( MouseEvent e) {207 building.angFix(get Point(e));229 private Mode modeDrawingAngFix() { 230 building.angFix(getEastNorth()); 208 231 return Mode.None; 209 232 } … … 211 234 private void processMouseEvent(MouseEvent e) { 212 235 mousePos = e.getPoint(); 236 isCtrlDown = e.isControlDown(); 237 isShiftDown = e.isShiftDown(); 213 238 if (mode == Mode.None) { 214 239 nextMode = Mode.None; … … 217 242 218 243 if (mode == Mode.Drawing) { 219 nextMode = modeDrawing( e);244 nextMode = modeDrawing(); 220 245 } else if (mode == Mode.DrawingWidth) { 221 nextMode = modeDrawingWidth( e);246 nextMode = modeDrawingWidth(); 222 247 } else if (mode == Mode.DrawingAngFix) { 223 nextMode = modeDrawingAngFix( e);248 nextMode = modeDrawingAngFix(); 224 249 } else 225 250 throw new AssertionError("Invalid drawing mode"); … … 315 340 if (mousePos == null) 316 341 return; 317 Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate); 318 if (n != null) 342 Node n = null; 343 if (!isCtrlDown) 344 n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isUsablePredicate); 345 if (n != null) { 319 346 setCursor(cursorJoinNode); 320 else 321 setCursor(cursorCrosshair); 347 } else { 348 if (customCursor != null && (!isShiftDown || isRectDrawing())) 349 setCursor(customCursor); 350 else 351 setCursor(cursorCrosshair); 352 } 322 353 323 354 } … … 349 380 } 350 381 351 public void updateConstraint(Collection<? extends OsmPrimitive> newSelection) { 352 building.disableAngConstraint(); 353 if (newSelection.size() != 2) 354 return; 355 Object[] arr = newSelection.toArray(); 356 if (!(arr[0] instanceof Node && arr[1] instanceof Node)) 357 return; 358 EastNorth p1, p2; 359 p1 = latlon2eastNorth(((Node) arr[0]).getCoor()); 360 p2 = latlon2eastNorth(((Node) arr[1]).getCoor()); 361 building.setAngConstraint(p1.heading(p2)); 382 public void updateSnap(Collection<? extends OsmPrimitive> newSelection) { 383 building.clearAngleSnap(); 384 // update snap only if selection isn't too big 385 if (newSelection.size() <= 10) { 386 LinkedList<Node> nodes = new LinkedList<Node>(); 387 LinkedList<Way> ways = new LinkedList<Way>(); 388 389 for (OsmPrimitive p : newSelection) { 390 switch (p.getType()) { 391 case NODE: 392 nodes.add((Node) p); 393 break; 394 case WAY: 395 ways.add((Way) p); 396 break; 397 } 398 } 399 400 building.addAngleSnap(nodes.toArray(new Node[0])); 401 for (Way w : ways) { 402 building.addAngleSnap(w); 403 } 404 } 405 updateCustomCursor(); 406 } 407 408 private void updateCustomCursor() { 409 Double angle = building.getDrawingAngle(); 410 if (angle == null || !ToolSettings.isSoftCursor()) { 411 customCursor = null; 412 return; 413 } 414 final int r = 11; // crosshair radius 415 BufferedImage img = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); 416 Graphics2D g = img.createGraphics(); 417 418 GeneralPath b = new GeneralPath(); 419 b.moveTo(16 - Math.cos(angle) * r, 16 - Math.sin(angle) * r); 420 b.lineTo(16 + Math.cos(angle) * r, 16 + Math.sin(angle) * r); 421 b.moveTo(16 + Math.sin(angle) * r, 16 - Math.cos(angle) * r); 422 b.lineTo(16 - Math.sin(angle) * r, 16 + Math.cos(angle) * r); 423 424 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 425 g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); 426 427 g.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 428 g.setColor(Color.WHITE); 429 g.draw(b); 430 431 g.setStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 432 g.setColor(Color.BLACK); 433 g.draw(b); 434 435 customCursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16), "custom crosshair"); 436 437 updCursor(); 362 438 } 363 439 364 440 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 365 update Constraint(newSelection);441 updateSnap(newSelection); 366 442 } 367 443 } -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/ToolSettings.java
r21801 r21846 1 1 package buildings_tools; 2 3 import org.openstreetmap.josm.Main; 2 4 3 5 public class ToolSettings { … … 6 8 private static boolean useAddr; 7 9 private static String tag = "yes"; 8 private static boolean bbMode;9 10 10 11 public static void setAddrDialog(boolean _useAddr) { … … 37 38 } 38 39 39 public static void setBBMode(boolean _bbmode) {40 bbMode = _bbmode;40 public static void setBBMode(boolean bbmode) { 41 Main.pref.put("buildings_tools.bbmode", bbmode); 41 42 } 42 43 43 44 public static boolean isBBMode() { 44 return bbMode; 45 return Main.pref.getBoolean("buildings_tools.bbmode", false); 46 } 47 48 public static void setSoftCursor(boolean softCursor) { 49 Main.pref.put("buildings_tools.softcursor", softCursor); 50 } 51 52 public static boolean isSoftCursor() { 53 return Main.pref.getBoolean("buildings_tools.softcursor", false); 45 54 } 46 55 }
Note:
See TracChangeset
for help on using the changeset viewer.