Changeset 34227 in osm for applications/editors


Ignore:
Timestamp:
2018-05-30T09:58:11+02:00 (7 years ago)
Author:
biswesh
Message:

Draw points on current place

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  
    99import java.awt.GridBagLayout;
    1010import java.awt.Point;
     11import java.awt.Rectangle;
    1112import java.awt.event.ActionEvent;
    1213import java.awt.event.ActionListener;
     
    3132import org.openstreetmap.josm.command.AddCommand;
    3233import org.openstreetmap.josm.command.ChangeCommand;
     34import org.openstreetmap.josm.command.ChangePropertyCommand;
    3335import org.openstreetmap.josm.command.Command;
    3436import org.openstreetmap.josm.command.SequenceCommand;
     
    3840import org.openstreetmap.josm.data.coor.ILatLon;
    3941import org.openstreetmap.josm.data.coor.LatLon;
     42import org.openstreetmap.josm.data.osm.DataSet;
    4043import org.openstreetmap.josm.data.osm.Node;
    4144import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5154import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    5255import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
     56import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils;
    5357import org.openstreetmap.josm.tools.CheckParameterUtil;
    5458import org.openstreetmap.josm.tools.GBC;
    5559import org.openstreetmap.josm.tools.ImageProvider;
     60import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    5661
    5762/**
     
    129134                SegWay1 = null;
    130135                SegWay2 = null;
     136                temporaryLayer.invalidate();
    131137        }
    132138
     
    202208
    203209                // 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);
    205213                if (node1 == null) {
    206214                        resetLayer();
     
    208216                        return;
    209217                }
    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);
    211222                if (node2 == null) {
    212223                        node1.setDeleted(true);
     
    219230                if (node1.equals(node2)) {
    220231                        resetLayer();
     232                        System.out.println("same");
    221233                        return;
    222234                }
     
    333345
    334346                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                }
    337352
    338353                commandList.add(result);
     
    352367                if (selectedWay != null) {
    353368                        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;
    355375                }
    356376        }
     
    380400                if (result1 != null)
    381401                        commandList.add(result1);
     402                else {
     403                        MainApplication.undoRedo.undo();
     404                        resetLayer();
     405                        return;
     406                }
    382407                if (result2 != null)
    383408                        commandList.add(result2);
     409                else {
     410                        MainApplication.undoRedo.undo();
     411                        resetLayer();
     412                        return;
     413                }
     414
    384415                MainApplication.undoRedo.add(new SequenceCommand("Split Way", commandList));
    385416
     
    441472                if (way1 != null && way2 != null) {
    442473                        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();
    444479                }
    445480        }
     
    450485                Way selectedWay = affected;
    451486
    452                 MainApplication.undoRedo.add(new SequenceCommand("Add Nodes", commandList));
    453                 commandList.clear();
    454 
    455487                addParentWay(atNodes.get(0));
    456488                addParentWay(atNodes.get(1));
     
    458490                if (selectedWay != null) {
    459491                        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();
    461495                }
    462496        }
     
    500534
    501535        private void addTags(List<TagMap> affectedKeysList, List<Way> selectedWay, JComboBox<String> keys,
    502                         JComboBox<String> values) {
     536                        JComboBox<String> values, int type) {
    503537                TagMap newKeys1 = affectedKeysList.get(0);
    504                 newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString());
    505538
    506539                if (keys.getSelectedItem() == "bridge") {
     540                        newKeys1.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString());
    507541                        newKeys1.put("layer", "1");
    508542                        selectedWay.get(0).setKeys(newKeys1);
    509543                } 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");
    511547                        selectedWay.get(0).setKeys(newKeys1);
    512548                } 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                        }
    514566                }
    515567
    516568                if (affectedKeysList.size() == 2) {
    517569                        TagMap newKeys2 = affectedKeysList.get(1);
    518                         newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString());
    519570
    520571                        if (keys.getSelectedItem() == "bridge") {
     572                                newKeys2.put(keys.getSelectedItem().toString(), values.getSelectedItem().toString());
    521573                                newKeys2.put("layer", "1");
    522574                                selectedWay.get(1).setKeys(newKeys2);
    523575                        } 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");
    525579                                selectedWay.get(1).setKeys(newKeys2);
    526580                        } 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                                }
    528598                        }
    529599                }
     
    565635                        SegWay1 = MainApplication.getMap().mapView.getNearestWay(e.getPoint(), OsmPrimitive::isSelectable);
    566636                        if (SegWay1 != null) {
    567                                 Pos1 = new LatLon(e.getX(), e.getY());
     637                                Pos1 = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY());
    568638                        }
    569639                } 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()) {
    571642                                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                                }
    574646                        }
    575647                }
     
    613685                boolean z = e.getKeyCode() == KeyEvent.VK_Z;
    614686                updateKeyModifiers(e);
    615                 System.out.println(ctrl);
    616687                if (z) {
    617688                        if (Pos1 != null && Pos2 == null) {
     
    637708                private List<Command> commandList;
    638709                private Node commonNode;
     710                private boolean rightHandTraffic;
    639711
    640712                SelectFromOptionDialog(int type, Node commonNode, Way affected, Way previousAffectedWay,
     
    648720                        this.commonNode = commonNode;
    649721
     722                        rightHandTraffic = true;
     723                        for (Node n: atNodes) {
     724                    if (!RightAndLefthandTraffic.isRightHandTraffic(n.getCoor())) {
     725                        rightHandTraffic = false;
     726                        break;
     727                    }
     728                }
     729
    650730                        setButtonIcons("ok", "cancel");
    651731                        setCancelButton(2);
     
    658738                        values = new JComboBox<>();
    659739                        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() {
    660759                        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"}));
    662765
    663766                        // below code changes the list in values on the basis of key
     
    667770                                        if ("bus_bay".equals(keys.getSelectedItem())) {
    668771                                                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"}));
    669776                                        } else if ("bridge".equals(keys.getSelectedItem())) {
    670777                                                values.setModel(new DefaultComboBoxModel<>(new String[] { "yes" }));
    671778                                        } 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" }));
    673783                                        }
    674784                                }
    675785                        });
    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);
    682876                }
    683877
     
    697891                                }
    698892
    699                         } else if (getValue() == 2) {
     893                        } else if (getValue() != 3){
    700894                                resetLayer();
    701895                        }
     
    708902                public void paint(Graphics2D g, MapView mv, Bounds bbox) {
    709903                        if (Pos1 != null) {
     904                                Point curP1 = MainApplication.getMap().mapView.getPoint(Pos1);
    710905                                CheckParameterUtil.ensureParameterNotNull(mv, "mv");
    711906                                g.setColor(Color.RED);
    712                                 g.fillRect((int) Pos1.lat(), (int) Pos1.lon(), 6, 6);
     907                                g.fill(new Rectangle.Double(curP1.x - 3, curP1.y - 3, 6, 6));
    713908                        }
    714909                        if (Pos2 != null) {
     910                                Point curP2 = MainApplication.getMap().mapView.getPoint(Pos2);
    715911                                CheckParameterUtil.ensureParameterNotNull(mv, "mv");
    716912                                g.setColor(Color.RED);
    717                                 g.fillRect((int) Pos2.lat(), (int) Pos2.lon(), 5, 5);
     913                                g.fill(new Rectangle.Double(curP2.x - 3, curP2.y - 3, 6, 6));
    718914                        }
    719915                }
Note: See TracChangeset for help on using the changeset viewer.