Changeset 34227 in osm for applications/editors
- Timestamp:
- 2018-05-30T09:58:11+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/DoubleSplitAction.java
r34217 r34227 9 9 import java.awt.GridBagLayout; 10 10 import java.awt.Point; 11 import java.awt.Rectangle; 11 12 import java.awt.event.ActionEvent; 12 13 import java.awt.event.ActionListener; … … 31 32 import org.openstreetmap.josm.command.AddCommand; 32 33 import org.openstreetmap.josm.command.ChangeCommand; 34 import org.openstreetmap.josm.command.ChangePropertyCommand; 33 35 import org.openstreetmap.josm.command.Command; 34 36 import org.openstreetmap.josm.command.SequenceCommand; … … 38 40 import org.openstreetmap.josm.data.coor.ILatLon; 39 41 import org.openstreetmap.josm.data.coor.LatLon; 42 import org.openstreetmap.josm.data.osm.DataSet; 40 43 import org.openstreetmap.josm.data.osm.Node; 41 44 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 51 54 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 52 55 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 56 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils; 53 57 import org.openstreetmap.josm.tools.CheckParameterUtil; 54 58 import org.openstreetmap.josm.tools.GBC; 55 59 import org.openstreetmap.josm.tools.ImageProvider; 60 import org.openstreetmap.josm.tools.RightAndLefthandTraffic; 56 61 57 62 /** … … 129 134 SegWay1 = null; 130 135 SegWay2 = null; 136 temporaryLayer.invalidate(); 131 137 } 132 138 … … 202 208 203 209 // check if the user has selected an existing node, or a new one 204 Node node1 = createNode(Pos1, commandList); 210 Point curP1 = MainApplication.getMap().mapView.getPoint(Pos1); 211 ILatLon P1 = new LatLon(curP1.getX(), curP1.getY()); 212 Node node1 = createNode(P1, commandList); 205 213 if (node1 == null) { 206 214 resetLayer(); … … 208 216 return; 209 217 } 210 Node node2 = createNode(Pos2, commandList); 218 219 Point curP2 = MainApplication.getMap().mapView.getPoint(Pos2); 220 ILatLon P2 = new LatLon(curP2.getX(), curP2.getY()); 221 Node node2 = createNode(P2, commandList); 211 222 if (node2 == null) { 212 223 node1.setDeleted(true); … … 219 230 if (node1.equals(node2)) { 220 231 resetLayer(); 232 System.out.println("same"); 221 233 return; 222 234 } … … 333 345 334 346 SplitWayCommand result = SplitWayCommand.split(affected, atNodes, Collections.emptyList()); 335 if (result == null) 336 return; 347 if (result == null) { 348 MainApplication.undoRedo.undo(); 349 resetLayer(); 350 return; 351 } 337 352 338 353 commandList.add(result); … … 352 367 if (selectedWay != null) { 353 368 affectedKeysList.add(affected.getKeys()); 354 addTags(affectedKeysList, Arrays.asList(selectedWay), keys, values); 369 addTags(affectedKeysList, Arrays.asList(selectedWay), keys, values, 0); 370 } else { 371 MainApplication.undoRedo.undo(); 372 MainApplication.undoRedo.undo(); 373 resetLayer(); 374 return; 355 375 } 356 376 } … … 380 400 if (result1 != null) 381 401 commandList.add(result1); 402 else { 403 MainApplication.undoRedo.undo(); 404 resetLayer(); 405 return; 406 } 382 407 if (result2 != null) 383 408 commandList.add(result2); 409 else { 410 MainApplication.undoRedo.undo(); 411 resetLayer(); 412 return; 413 } 414 384 415 MainApplication.undoRedo.add(new SequenceCommand("Split Way", commandList)); 385 416 … … 441 472 if (way1 != null && way2 != null) { 442 473 List<Way> selectedWays = Arrays.asList(way1, way2); 443 addTags(affectedKeysList, selectedWays, keys, values); 474 addTags(affectedKeysList, selectedWays, keys, values, 1); 475 } else { 476 MainApplication.undoRedo.undo(); 477 MainApplication.undoRedo.undo(); 478 resetLayer(); 444 479 } 445 480 } … … 450 485 Way selectedWay = affected; 451 486 452 MainApplication.undoRedo.add(new SequenceCommand("Add Nodes", commandList));453 commandList.clear();454 455 487 addParentWay(atNodes.get(0)); 456 488 addParentWay(atNodes.get(1)); … … 458 490 if (selectedWay != null) { 459 491 affectedKeysList.add(affected.getKeys()); 460 addTags(affectedKeysList, Arrays.asList(selectedWay), keys, values); 492 addTags(affectedKeysList, Arrays.asList(selectedWay), keys, values, 2); 493 } else { 494 resetLayer(); 461 495 } 462 496 } … … 500 534 501 535 private void addTags(List<TagMap> affectedKeysList, List<Way> selectedWay, JComboBox<String> keys, 502 JComboBox<String> values) { 536 JComboBox<String> values, int type) { 503 537 TagMap newKeys1 = affectedKeysList.get(0); 504 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString());505 538 506 539 if (keys.getSelectedItem() == "bridge") { 540 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 507 541 newKeys1.put("layer", "1"); 508 542 selectedWay.get(0).setKeys(newKeys1); 509 543 } else if (keys.getSelectedItem() == "tunnel") { 510 newKeys1.put("layer", "-1"); 544 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 545 if (!values.getSelectedItem().toString().equals("building_passage")) 546 newKeys1.put("layer", "-1"); 511 547 selectedWay.get(0).setKeys(newKeys1); 512 548 } else { 513 selectedWay.get(0).setKeys(newKeys1); 549 if (newKeys1.containsKey("bus_bay")) { 550 String value = newKeys1.get("bus_bay"); 551 if (values.getSelectedItem().equals("left") && value.equals("right")) { 552 newKeys1.put(keys.getSelectedItem().toString(), "both"); 553 } else if (values.getSelectedItem().equals("right") && value.equals("left")) { 554 newKeys1.put(keys.getSelectedItem().toString(), "both"); 555 } else { 556 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 557 } 558 } else { 559 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 560 } 561 if (type != 2) { 562 selectedWay.get(0).setKeys(newKeys1); 563 } else { 564 MainApplication.undoRedo.add(new ChangePropertyCommand(Collections.singleton(selectedWay.get(0)), newKeys1)); 565 } 514 566 } 515 567 516 568 if (affectedKeysList.size() == 2) { 517 569 TagMap newKeys2 = affectedKeysList.get(1); 518 newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString());519 570 520 571 if (keys.getSelectedItem() == "bridge") { 572 newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 521 573 newKeys2.put("layer", "1"); 522 574 selectedWay.get(1).setKeys(newKeys2); 523 575 } else if (keys.getSelectedItem() == "tunnel") { 524 newKeys2.put("layer", "-1"); 576 newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 577 if (!values.getSelectedItem().toString().equals("building_passage")) 578 newKeys2.put("layer", "-1"); 525 579 selectedWay.get(1).setKeys(newKeys2); 526 580 } else { 527 selectedWay.get(1).setKeys(newKeys2); 581 if (newKeys2.containsKey("bus_bay")) { 582 String value = newKeys2.get("bus_bay"); 583 if (values.getSelectedItem().equals("left") && value.equals("right")) { 584 newKeys2.put(keys.getSelectedItem().toString(), "both"); 585 } else if (values.getSelectedItem().equals("right") && value.equals("left")) { 586 newKeys2.put(keys.getSelectedItem().toString(), "both"); 587 } else { 588 newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 589 } 590 } else { 591 newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString()); 592 } 593 if (type != 2) { 594 selectedWay.get(1).setKeys(newKeys2); 595 } else { 596 MainApplication.undoRedo.add(new ChangePropertyCommand(Collections.singleton(selectedWay.get(0)), newKeys2)); 597 } 528 598 } 529 599 } … … 565 635 SegWay1 = MainApplication.getMap().mapView.getNearestWay(e.getPoint(), OsmPrimitive::isSelectable); 566 636 if (SegWay1 != null) { 567 Pos1 = newLatLon(e.getX(), e.getY());637 Pos1 = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()); 568 638 } 569 639 } else if (Pos2 == null) { 570 if (Pos1.lat() != e.getX() || Pos1.lon() != e.getY()) { 640 LatLon tempPos = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()); 641 if (Pos1.lat() != tempPos.lat() || Pos1.lon() != tempPos.lon()) { 571 642 SegWay2 = MainApplication.getMap().mapView.getNearestWay(e.getPoint(), OsmPrimitive::isSelectable); 572 if (SegWay2 != null) 573 Pos2 = new LatLon(e.getX(), e.getY()); 643 if (SegWay2 != null) { 644 Pos2 = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()); 645 } 574 646 } 575 647 } … … 613 685 boolean z = e.getKeyCode() == KeyEvent.VK_Z; 614 686 updateKeyModifiers(e); 615 System.out.println(ctrl);616 687 if (z) { 617 688 if (Pos1 != null && Pos2 == null) { … … 637 708 private List<Command> commandList; 638 709 private Node commonNode; 710 private boolean rightHandTraffic; 639 711 640 712 SelectFromOptionDialog(int type, Node commonNode, Way affected, Way previousAffectedWay, … … 648 720 this.commonNode = commonNode; 649 721 722 rightHandTraffic = true; 723 for (Node n: atNodes) { 724 if (!RightAndLefthandTraffic.isRightHandTraffic(n.getCoor())) { 725 rightHandTraffic = false; 726 break; 727 } 728 } 729 650 730 setButtonIcons("ok", "cancel"); 651 731 setCancelButton(2); … … 658 738 values = new JComboBox<>(); 659 739 keys.setEditable(true); 740 Set<Way> newWays = new HashSet<>(); 741 findIntersection(newWays); 742 743 if (previousAffectedWay.hasKey("waterway") || affected.hasKey("waterway")) { 744 setOptionsWithTunnel(); 745 } else if (newWays.size() != 0) { 746 setOptionsWithBridge(); 747 } else { 748 setOptionsDefault(); 749 } 750 751 pane.add(keys, GBC.eop().fill(GBC.HORIZONTAL)); 752 pane.add(values, GBC.eop().fill(GBC.HORIZONTAL)); 753 754 setContent(pane, false); 755 setDefaultCloseOperation(HIDE_ON_CLOSE); 756 } 757 758 private void setOptionsDefault() { 660 759 keys.setModel(new DefaultComboBoxModel<>(new String[] { "bus_bay", "bridge", "tunnel" })); 661 values.setModel(new DefaultComboBoxModel<>(new String[] { "both", "right", "left" })); 760 761 if (rightHandTraffic) 762 values.setModel(new DefaultComboBoxModel<>(new String[] {"right", "left", "both"})); 763 else 764 values.setModel(new DefaultComboBoxModel<>(new String[] {"left", "right", "both"})); 662 765 663 766 // below code changes the list in values on the basis of key … … 667 770 if ("bus_bay".equals(keys.getSelectedItem())) { 668 771 values.setModel(new DefaultComboBoxModel<>(new String[] { "both", "right", "left" })); 772 if (rightHandTraffic) 773 values.setModel(new DefaultComboBoxModel<>(new String[] {"right", "left", "both"})); 774 else 775 values.setModel(new DefaultComboBoxModel<>(new String[] {"left", "right", "both"})); 669 776 } else if ("bridge".equals(keys.getSelectedItem())) { 670 777 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes" })); 671 778 } else if ("tunnel".equals(keys.getSelectedItem())) { 672 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes", "culvert" })); 779 if (previousAffectedWay.hasKey("waterway") || affected.hasKey("waterway")) 780 values.setModel(new DefaultComboBoxModel<>(new String[] { "culvert", "yes", "building_passage" })); 781 else 782 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes", "culvert", "building_passage" })); 673 783 } 674 784 } 675 785 }); 676 677 pane.add(keys, GBC.eop().fill(GBC.HORIZONTAL)); 678 pane.add(values, GBC.eop().fill(GBC.HORIZONTAL)); 679 680 setContent(pane, false); 681 setDefaultCloseOperation(HIDE_ON_CLOSE); 786 } 787 788 private void setOptionsWithTunnel() { 789 keys.setModel(new DefaultComboBoxModel<>(new String[] { "tunnel", "bridge", "bus_bay" })); 790 791 if (previousAffectedWay.hasKey("waterway") || affected.hasKey("waterway")) 792 values.setModel(new DefaultComboBoxModel<>(new String[] { "culvert", "yes", "building_passage" })); 793 else 794 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes", "culvert", "building_passage" })); 795 796 // below code changes the list in values on the basis of key 797 keys.addActionListener(new ActionListener() { 798 @Override 799 public void actionPerformed(ActionEvent e) { 800 if ("tunnel".equals(keys.getSelectedItem())) { 801 if (previousAffectedWay.hasKey("waterway") || affected.hasKey("waterway")) 802 values.setModel(new DefaultComboBoxModel<>(new String[] { "culvert", "yes", "building_passage" })); 803 else 804 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes", "culvert", "building_passage" })); 805 } else if ("bus_bay".equals(keys.getSelectedItem())) { 806 values.setModel(new DefaultComboBoxModel<>(new String[] { "both", "right", "left" })); 807 if (rightHandTraffic) 808 values.setModel(new DefaultComboBoxModel<>(new String[] {"right", "left", "both"})); 809 else 810 values.setModel(new DefaultComboBoxModel<>(new String[] {"left", "right", "both"})); 811 } else if ("bridge".equals(keys.getSelectedItem())) { 812 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes" })); 813 } 814 } 815 }); 816 } 817 818 private void setOptionsWithBridge() { 819 keys.setModel(new DefaultComboBoxModel<>(new String[] { "bridge", "bus_bay", "tunnel"})); 820 821 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes" })); 822 823 // below code changes the list in values on the basis of key 824 keys.addActionListener(new ActionListener() { 825 @Override 826 public void actionPerformed(ActionEvent e) { 827 if ("tunnel".equals(keys.getSelectedItem())) { 828 if (previousAffectedWay.hasKey("waterway") || affected.hasKey("waterway")) 829 values.setModel(new DefaultComboBoxModel<>(new String[] { "culvert", "yes", "building_passage" })); 830 else 831 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes", "culvert", "building_passage" })); 832 } else if ("bus_bay".equals(keys.getSelectedItem())) { 833 values.setModel(new DefaultComboBoxModel<>(new String[] { "both", "right", "left" })); 834 if (rightHandTraffic) 835 values.setModel(new DefaultComboBoxModel<>(new String[] {"right", "left", "both"})); 836 else 837 values.setModel(new DefaultComboBoxModel<>(new String[] {"left", "right", "both"})); 838 } else if ("bridge".equals(keys.getSelectedItem())) { 839 values.setModel(new DefaultComboBoxModel<>(new String[] { "yes" })); 840 } 841 } 842 }); 843 } 844 845 private void findIntersection(Set<Way> newWays) { 846 DataSet ds = getLayerManager().getEditDataSet(); 847 NodeWayUtils.addWaysIntersectingWays( 848 ds.getWays(), 849 Arrays.asList(previousAffectedWay, affected), newWays); 850 Node n1 = previousAffectedWay.firstNode(); 851 Node n2 = previousAffectedWay.lastNode(); 852 Node n3 = affected.firstNode(); 853 Node n4 = affected.lastNode(); 854 List<Way> waysToBeRemoved = new ArrayList<>(); 855 for (Way way : newWays) { 856 int count = 0; 857 if (way.containsNode(n1)) 858 count++; 859 if (way.containsNode(n2)) 860 count++; 861 if (!previousAffectedWay.equals(affected)) { 862 if (way.containsNode(n3)) 863 count++; 864 if (way.containsNode(n4)) 865 count++; 866 } 867 if (count == 1) { 868 waysToBeRemoved.add(way); 869 } else { 870 if (!way.hasKey("highway") && !way.hasKey("waterway") && !way.hasKey("railway")) { 871 waysToBeRemoved.add(way); 872 } 873 } 874 } 875 newWays.removeAll(waysToBeRemoved); 682 876 } 683 877 … … 697 891 } 698 892 699 } else if (getValue() == 2){893 } else if (getValue() != 3){ 700 894 resetLayer(); 701 895 } … … 708 902 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 709 903 if (Pos1 != null) { 904 Point curP1 = MainApplication.getMap().mapView.getPoint(Pos1); 710 905 CheckParameterUtil.ensureParameterNotNull(mv, "mv"); 711 906 g.setColor(Color.RED); 712 g.fill Rect((int) Pos1.lat(), (int) Pos1.lon(), 6, 6);907 g.fill(new Rectangle.Double(curP1.x - 3, curP1.y - 3, 6, 6)); 713 908 } 714 909 if (Pos2 != null) { 910 Point curP2 = MainApplication.getMap().mapView.getPoint(Pos2); 715 911 CheckParameterUtil.ensureParameterNotNull(mv, "mv"); 716 912 g.setColor(Color.RED); 717 g.fill Rect((int) Pos2.lat(), (int) Pos2.lon(), 5, 5);913 g.fill(new Rectangle.Double(curP2.x - 3, curP2.y - 3, 6, 6)); 718 914 } 719 915 }
Note:
See TracChangeset
for help on using the changeset viewer.