Ticket #18670: 18670.2.patch

File 18670.2.patch, 6.2 KB (added by GerdP, 5 years ago)

suppress warning notification for parent relation when unglued node is not first or last node of modified way

  • src/org/openstreetmap/josm/actions/UnGlueAction.java

     
    108108                }
    109109                // If there aren't enough ways, maybe the user wanted to unglue the nodes
    110110                // (= copy tags to a new node)
    111                 if (!selfCrossing)
    112                     if (checkForUnglueNode(selection)) {
     111                if (!selfCrossing) {
     112                    if (selection.size() == 1 && selectedNode.isTagged()) {
    113113                        unglueOneNodeAtMostOneWay(e);
    114114                    } else {
    115115                        errorTime = Notification.TIME_SHORT;
    116116                        errMsg = tr("This node is not glued to anything else.");
    117117                    }
     118                }
    118119            } else {
    119120                // and then do the work.
    120121                unglueWays();
     
    245246    }
    246247
    247248    /**
    248      * Checks if selection is suitable for ungluing. This is the case when there's a single,
    249      * tagged node selected that's part of at least one way (ungluing an unconnected node does
    250      * not make sense. Due to the call order in actionPerformed, this is only called when the
    251      * node is only part of one or less ways.
    252      *
    253      * @param selection The selection to check against
    254      * @return {@code true} if selection is suitable
    255      */
    256     private boolean checkForUnglueNode(Collection<? extends OsmPrimitive> selection) {
    257         if (selection.size() != 1)
    258             return false;
    259         OsmPrimitive n = (OsmPrimitive) selection.toArray()[0];
    260         if (!(n instanceof Node))
    261             return false;
    262         if (((Node) n).getParentWays().isEmpty())
    263             return false;
    264 
    265         selectedNode = (Node) n;
    266         return selectedNode.isTagged();
    267     }
    268 
    269     /**
    270249     * Checks if the selection consists of something we can work with.
    271250     * Checks only if the number and type of items selected looks good.
    272251     *
     
    291270        for (OsmPrimitive p : selection) {
    292271            if (p instanceof Node) {
    293272                selectedNode = (Node) p;
    294                 if (size == 1 || selectedWay != null)
    295                     return size == 1 || selectedWay.containsNode(selectedNode);
     273                if (size == 1 || (selectedWay != null && selectedWay.containsNode(selectedNode)))
     274                    return true;
    296275            } else if (p instanceof Way) {
    297276                selectedWay = (Way) p;
    298277                if (size == 2 && selectedNode != null)
     
    359338     * @param w parent way
    360339     * @param cmds List of commands that will contain the new "add node" command
    361340     * @param newNodes List of nodes that will contain the new node
    362      * @return new way The modified way. Change command mus be handled by the caller
     341     * @return new way The modified way. Change command must be handled by the caller
    363342     */
    364343    private static Way modifyWay(Node originalNode, Way w, List<Command> cmds, List<Node> newNodes) {
    365344        // clone the node for the way
     
    460439            if (wayWithSelectedNode == null) {
    461440                parentWays.removeFirst();
    462441            }
     442            Set<Way> warnParents = new HashSet<>();
    463443            for (Way w : parentWays) {
     444                if (w.isFirstLastNode(selectedNode))
     445                    warnParents.add(w);
    464446                cmds.add(new ChangeCommand(w, modifyWay(selectedNode, w, cmds, newNodes)));
    465447            }
    466             notifyWayPartOfRelation(parentWays);
     448            notifyWayPartOfRelation(warnParents);
    467449        } else {
    468             cmds.add(new ChangeCommand(selectedWay, modifyWay(selectedNode, selectedWay, cmds, newNodes)));
    469             notifyWayPartOfRelation(Collections.singleton(selectedWay));
     450            Way modWay = modifyWay(selectedNode, selectedWay, cmds, newNodes);
     451            addCheckedChangeNodesCmd(cmds, selectedWay, modWay.getNodes());
    470452        }
    471453
    472454        if (dialog != null) {
     
    527509            // selectedNode doesn't need unglue
    528510            return false;
    529511        }
    530         cmds.add(new ChangeNodesCommand(way, newNodes));
    531         notifyWayPartOfRelation(Collections.singleton(way));
     512        addCheckedChangeNodesCmd(cmds, way, newNodes);
    532513        try {
    533514            final PropertiesMembershipChoiceDialog dialog = PropertiesMembershipChoiceDialog.showIfNecessary(
    534515                    Collections.singleton(selectedNode), false);
     
    568549            }
    569550            allNewNodes.addAll(newNodes);
    570551        }
    571         cmds.add(new ChangeCommand(selectedWay, tmpWay)); // only one changeCommand for a way, else garbage will happen
    572         notifyWayPartOfRelation(Collections.singleton(selectedWay));
     552        // only one changeCommand for a way, else garbage will happen
     553        addCheckedChangeNodesCmd(cmds, selectedWay, tmpWay.getNodes());
    573554
    574555        UndoRedoHandler.getInstance().add(new SequenceCommand(
    575556                trn("Dupe {0} node into {1} nodes", "Dupe {0} nodes into {1} nodes",
     
    577558        getLayerManager().getEditDataSet().setSelected(allNewNodes);
    578559    }
    579560
     561    private void addCheckedChangeNodesCmd(List<Command> cmds, Way w, List<Node> nodes) {
     562        boolean relationCheck = w.firstNode() != nodes.get(0) || w.lastNode() != nodes.get(nodes.size() - 1);
     563        cmds.add(new ChangeNodesCommand(w, nodes));
     564        if (relationCheck) {
     565            notifyWayPartOfRelation(Collections.singleton(w));
     566        }
     567    }
     568
    580569    @Override
    581570    protected void updateEnabledState() {
    582571        updateEnabledStateOnCurrentSelection();
  • test/unit/org/openstreetmap/josm/actions/UnGlueActionTest.java

     
    3030     */
    3131    @Rule
    3232    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    33     public JOSMTestRules test = new JOSMTestRules().main();
     33    public JOSMTestRules test = new JOSMTestRules().main().projection().preferences();
    3434
    3535    /**
    3636     * Setup test.