Changeset 26501 in osm for applications
- Timestamp:
- 2011-08-09T12:27:00+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/DrawnPolyLine.java
r26468 r26501 95 95 96 96 Point getLastPoint() { 97 return getPoint(points.get(lastIdx)); 97 if (lastIdx<points.size()) return getPoint(points.get(lastIdx)); 98 else return null; 98 99 } 99 100 -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FDSettings.java
r26468 r26501 12 12 public Color COLOR_SELECTEDFRAGMENT; 13 13 public Color COLOR_EDITEDFRAGMENT; 14 14 public Color COLOR_SIMPLIFIED; 15 15 16 public double maxDist; 16 17 public double epsilonMult; … … 33 34 //1="Simplify and wait", 2="Save as is" 34 35 public int simplifyMode; 36 public float lineWidth; 35 37 36 38 public void loadPrefs() { … … 40 42 COLOR_NORMAL = Main.pref.getColor("fastdraw.color.normal", Color.red); 41 43 COLOR_SELECTEDFRAGMENT = Main.pref.getColor("fastdraw.color.select", Color.blue); 44 COLOR_SIMPLIFIED = Main.pref.getColor("fastdraw.color.simplified", Color.orange); 42 45 maxDist = Main.pref.getDouble("fastdraw.maxdist", 5); 43 46 epsilonMult = Main.pref.getDouble("fastdraw.epsilonmult", 1.1); … … 52 55 fixedSpacebar = Main.pref.getBoolean("fastdraw.fixedspacebar", false); 53 56 simplifyMode = Main.pref.getInteger("fastdraw.simplifymode", 0); 57 lineWidth = (float) Main.pref.getDouble("fastdraw.linewidth", 2); 54 58 } 55 59 … … 60 64 Main.pref.putColor("fastdraw.color.normal", COLOR_NORMAL); 61 65 Main.pref.putColor("fastdraw.color.select", COLOR_SELECTEDFRAGMENT); 66 Main.pref.getColor("fastdraw.color.simplified", COLOR_SIMPLIFIED); 62 67 Main.pref.putDouble("fastdraw.maxdist", maxDist); 63 68 Main.pref.putDouble("fastdraw.epsilonmult", epsilonMult); … … 72 77 Main.pref.put("fastdraw.fixedspacebar", fixedSpacebar); 73 78 Main.pref.putInteger("fastdraw.simplifymode", simplifyMode); 79 Main.pref.putDouble("fastdraw.linewidth",(double)lineWidth); 74 80 try {Main.pref.save();} catch (IOException e) { 75 81 System.err.println(tr("Can not save preferences")); -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r26490 r26501 43 43 import org.openstreetmap.josm.data.osm.OsmPrimitive; 44 44 import org.openstreetmap.josm.data.osm.Way; 45 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 45 46 import org.openstreetmap.josm.gui.MapFrame; 46 47 import org.openstreetmap.josm.gui.MapView; … … 67 68 private boolean shift; 68 69 private double eps; 69 private finalStroke strokeForSimplified;70 private finalStroke strokeForOriginal;70 private Stroke strokeForSimplified; 71 private Stroke strokeForOriginal; 71 72 private final Cursor cursorDraw; 72 73 private final Cursor cursorCtrl; … … 96 97 KeyEvent.VK_T, Shortcut.GROUP_EDIT), mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 97 98 line=new DrawnPolyLine(); 98 strokeForOriginal = new BasicStroke();99 strokeForDelete = new BasicStroke(3);100 strokeForSimplified = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_BEVEL,5f,101 new float[]{5.f,5f},0f);102 99 cursorDraw = ImageProvider.getCursor("crosshair", null); 103 100 cursorCtrl = ImageProvider.getCursor("crosshair", "fixed"); … … 119 116 settings.loadPrefs(); 120 117 settings.savePrefs(); 118 119 strokeForOriginal = new BasicStroke(settings.lineWidth); 120 strokeForDelete = new BasicStroke(3); 121 //strokeForSimplified = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_BEVEL,5f, 122 // new float[]{5.f,5f},0f); 123 strokeForSimplified = strokeForOriginal; 121 124 122 125 eps=settings.startingEps; … … 130 133 Main.map.mapView.addTemporaryLayer(this); 131 134 132 updateCursor(); 133 Collection<Way> selectedWays = Main.main.getCurrentDataSet().getSelectedWays(); 134 if (selectedWays!=null // if there is a selection 135 && selectedWays.size()==1 // and one way is selected 136 && line.getPoints().size()==0) /* and ther is no already drawn line */ { 137 // we can start drawing new way starting from old one 138 Way w = selectedWays.iterator().next(); 139 140 if (w.isNew()) loadFromWay(w); 141 } 135 //tryToLoadWay(); 136 142 137 timer = new Timer(0, new ActionListener() { 143 138 @Override … … 205 200 g.setColor(settings.COLOR_FIXED); 206 201 g.fillOval(p1.x - 3, p1.y - 3, 7, 7); 207 Color lineColor=settings.COLOR_NORMAL; 202 Color lineColor,initLineColor; 203 initLineColor = line.wasSimplified() ? settings.COLOR_SIMPLIFIED: settings.COLOR_NORMAL; 204 lineColor = initLineColor; 205 int rp,dp; 206 dp=line.wasSimplified() ? 7:(int)(3+((int) settings.lineWidth)/2*2); rp=dp/2; 208 207 if (pts.size() > 1) { 209 208 Iterator<LatLon> it1,it2; 210 209 it1=pts.listIterator(0); 211 210 it2=pts.listIterator(1); 212 211 for (int i = 0; i < pts.size() - 1; i++) { 213 212 pp1 = it1.next(); 214 213 p1 = line.getPoint(pp1); … … 221 220 // g.fillOval(p2.x - 5, p2.y - 5, 11, 11); 222 221 if (line.isFixed(pp2)) { 223 lineColor= settings.COLOR_NORMAL;222 lineColor=initLineColor; 224 223 g.setColor(settings.COLOR_FIXED); 225 224 g.fillOval(p2.x - 3, p2.y - 3, 7, 7); 226 225 } else { 227 g.fillRect(p2.x - 1, p2.y - 1, 3, 3);226 g.fillRect(p2.x - rp, p2.y - rp, dp, dp); 228 227 } 229 228 if (!drawing) { … … 246 245 } 247 246 } 248 if (settings.drawLastSegment && !drawing && !shift && nearestIdx<0 && !line.wasSimplified()) { 249 // draw line to current point 250 g.setColor(lineColor); 251 Point lp=line.getLastPoint(); 252 Point mp=Main.map.mapView.getMousePosition(); 253 if (lp!=null && mp!=null) g.drawLine(lp.x,lp.y,mp.x,mp.y); 254 } 255 if (deltaChanged) { 256 g.setColor(lineColor); 257 Point lp=line.getLastPoint(); 258 int r=(int) settings.minPixelsBetweenPoints; 259 if (lp!=null) g.drawOval(lp.x-r,lp.y-r,2*r,2*r); 260 } 261 } 247 } 248 if (settings.drawLastSegment && !drawing && !shift && nearestIdx<0 && !line.wasSimplified()) { 249 // draw line to current point 250 g.setColor(lineColor); 251 Point lp=line.getLastPoint(); 252 Point mp=Main.map.mapView.getMousePosition(); 253 if (lp!=null && mp!=null) g.drawLine(lp.x,lp.y,mp.x,mp.y); 254 } 255 if (deltaChanged) { 256 g.setColor(lineColor); 257 Point lp=line.getLastPoint(); 258 int r=(int) settings.minPixelsBetweenPoints; 259 if (lp!=null) g.drawOval(lp.x-r,lp.y-r,2*r,2*r); 260 } 261 262 262 } 263 263 … … 487 487 // less details 488 488 e.consume(); 489 Point lastPoint = line.getLastPoint(); 489 490 line.moveToTheEnd(); 491 if (lastPoint==null || lastPoint.equals(line.getLastPoint())) { 492 if (line.getPoints().size()>5) { 493 boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog( 494 "delete_drawn_line", Main.parent, 495 tr("Are you sure you do not want to save the line containing {0} points?", 496 line.getPoints().size()), tr("Delete confirmation"), 497 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_OPTION ); 498 if(!answer) break; 499 } 500 newDrawing(); // stop drawing 501 exitMode(); 502 Main.map.selectSelectTool(false); 503 } 504 break; 505 case KeyEvent.VK_T: 506 tryToLoadWay(); 490 507 break; 491 508 case KeyEvent.VK_Q: … … 541 558 line.clear(); 542 559 } 560 543 561 private void saveAsWay(boolean autoExit) { 544 562 List<LatLon> pts=line.getPoints(); … … 598 616 } else cmds.add(new AddCommand(w)); 599 617 Command c = new SequenceCommand(tr("Draw the way by mouse"), cmds); 618 if (!Main.main.hasEditLayer()) return; 600 619 Main.main.undoRedo.add(c); 601 620 lineWasSaved = true; … … 609 628 } 610 629 611 612 613 private void repaint() {614 Main.map.mapView.repaint();615 }616 617 630 public void back() { 618 631 line.undo(); … … 632 645 settings.minPixelsBetweenPoints*=k; 633 646 deltaChanged=true; 634 setStatusLine(tr("min distance={0} pixes",(int)settings.minPixelsBetweenPoints)); 647 648 setStatusLine(tr("min distance={0} pixels or {1} m",(int)settings.minPixelsBetweenPoints, 649 mv.getDist100Pixel()/100*settings.minPixelsBetweenPoints)); 635 650 repaint(); 636 651 } 637 652 638 private void setStatusLine(String tr) {639 statusText=tr;640 updateStatusLine();641 }642 653 643 654 /*private Node findClosestNode(LatLon p, double d) { … … 658 669 }*/ 659 670 660 661 662 671 private void loadFromWay(Way w) { 672 List<LatLon> pts=line.getPoints(); 673 674 Collection<Command> cmds = new LinkedList<Command>(); 675 676 Node firstNode=null; 677 Object[] nodes = w.getNodes().toArray(); 678 int n=nodes.length; 679 if (w.isClosed()) n--; 680 for (int i=0;i<n;i++) { 681 Node nd=(Node) nodes[i]; 682 line.addLast(nd.getCoor()); 683 } 684 if (w.isClosed()) line.closeLine(); 685 oldNodes = w.getNodes(); 686 List <OsmPrimitive> wl = new ArrayList(); wl.add(w); 687 688 Command c = DeleteCommand.delete(getEditLayer(), wl, false); 689 if (c != null) cmds.add(c); 690 delCmd = new SequenceCommand(tr("Convert way to FastDraw line"), cmds); 691 Main.main.undoRedo.add(delCmd); 692 } 693 694 private void setStatusLine(String tr) { 695 statusText=tr; 696 updateStatusLine(); 697 } 698 699 private void showSimplifyHint() { 700 setStatusLine(tr("Eps={0}, {1} points, {2} p/km", 701 eps, line.getSimplePointsCount(),line.getNodesPerKm(settings.pkmBlockSize))+" " 702 +SIMPLIFYMODE_MESSAGE); 703 } 704 663 705 private void updateCursor() { 664 706 if (shift) Main.map.mapView.setCursor(cursorShift); else … … 671 713 672 714 } 715 716 private void repaint() { 717 Main.map.mapView.repaint(); 718 } 673 719 // </editor-fold> 674 720 … … 686 732 // </editor-fold> 687 733 688 private void showSimplifyHint() { 689 setStatusLine(tr("Eps={0}, {1} points, {2} p/km", 690 eps, line.getSimplePointsCount(),line.getNodesPerKm(settings.pkmBlockSize))+" " 691 +SIMPLIFYMODE_MESSAGE); 692 } 693 694 private void loadFromWay(Way w) { 695 List<LatLon> pts=line.getPoints(); 696 697 Collection<Command> cmds = new LinkedList<Command>(); 698 699 Node firstNode=null; 700 Object[] nodes = w.getNodes().toArray(); 701 int n=nodes.length; 702 if (w.isClosed()) n--; 703 for (int i=0;i<n;i++) { 704 Node nd=(Node) nodes[i]; 705 line.addLast(nd.getCoor()); 706 } 707 if (w.isClosed()) line.closeLine(); 708 oldNodes = w.getNodes(); 709 List <OsmPrimitive> wl = new ArrayList(); wl.add(w); 710 711 Command c = DeleteCommand.delete(getEditLayer(), wl, false); 712 if (c != null) cmds.add(c); 713 delCmd = new SequenceCommand(tr("Convert way to FastDraw line"), cmds); 714 Main.main.undoRedo.add(delCmd); 715 } 734 private void tryToLoadWay() { 735 updateCursor(); 736 Collection<Way> selectedWays = Main.main.getCurrentDataSet().getSelectedWays(); 737 if (selectedWays!=null // if there is a selection 738 && selectedWays.size()==1 // and one way is selected 739 && line.getPoints().size()==0) /* and ther is no already drawn line */ { 740 // we can start drawing new way starting from old one 741 Way w = selectedWays.iterator().next(); 742 743 if (w.isNew()) loadFromWay(w); 744 } 745 } 746 716 747 717 748 }
Note:
See TracChangeset
for help on using the changeset viewer.