src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * Cut original element to clipboard, does -not- preserve relation memberships
     * 
     * @param elements elements to copy
     * @param lat latitude where it was located
     * @param lon longitude where it was located
     */
Cut original element to clipboard, does -not- preserve relation memberships

@param elements elements to copy
@param lat latitude where it was located
@param lon longitude where it was located
Cut original element to clipboard does - not - preserve relation memberships @param elements elements to copy @param lat latitude where it was located @param lon longitude where it was located
public void cutToClipboard(@NonNull List<OsmElement> elements, int lat, int lon) {
        dirty = true; 
        List<OsmElement> toCut = new ArrayList<>();
        Map<Long, Node> replacedNodes = new HashMap<>();
        for (OsmElement e : elements) {
            toCut.add(e);
            if (e instanceof Way) {
                undo.save(e);
                List<Node> nodes = new ArrayList<>(((Way) e).getNodes());
                for (Node nd : nodes) {
                    List<Way> ways = currentStorage.getWays(nd);
                    if (ways.size() > 1) { 
                        Node newNode = replacedNodes.get(nd.getOsmId());
                        if (newNode == null) {
                            for (Way w : ways) {
                                if (!elements.contains(w)) {
                                    newNode = factory.createNodeWithNewId(nd.getLat(), nd.getLon());
                                    newNode.setTags(nd.getTags());
                                    insertElementSafe(newNode);
                                    replacedNodes.put(nd.getOsmId(), newNode);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        for (OsmElement removeElement : toCut) {
            if (removeElement instanceof Node) {
                removeNode((Node) removeElement);
            } else if (removeElement instanceof Way) {
                for (Node nd : ((Way) removeElement).getNodes()) {
                    Node replacement = replacedNodes.get(nd.getOsmId());
                    if (replacement != null) {
                        ((Way) removeElement).replaceNode(nd, replacement);
                    }
                }
                removeWay((Way) removeElement);
            }
        }
        for (OsmElement removeElement : toCut) {
            if (removeElement instanceof Way) {
                Set<Node> nodes = new HashSet<>(((Way) removeElement).getNodes());
                for (Node nd : nodes) {
                    removeNode(nd); 
                }
            }
        }
        clipboard.cutTo(toCut, lat, lon);
    }
public void cutToClipboard ( @ NonNull List < OsmElement > elements , int lat , int lon ) { dirty = true ; List < OsmElement > toCut = new ArrayList < > ( ) ; Map < Long , Node > replacedNodes = new HashMap < > ( ) ; for ( OsmElement e : elements ) { toCut . add ( e ) ; if ( e instanceof Way ) { undo . save ( e ) ; List < Node > nodes = new ArrayList < > ( ( ( Way ) e ) . getNodes ( ) ) ; for ( Node nd : nodes ) { List < Way > ways = currentStorage . getWays ( nd ) ; if ( ways . size ( ) > 1 ) { Node newNode = replacedNodes . get ( nd . getOsmId ( ) ) ; if ( newNode == null ) { for ( Way w : ways ) { if ( ! elements . contains ( w ) ) { newNode = factory . createNodeWithNewId ( nd . getLat ( ) , nd . getLon ( ) ) ; newNode . setTags ( nd . getTags ( ) ) ; insertElementSafe ( newNode ) ; replacedNodes . put ( nd . getOsmId ( ) , newNode ) ; break ; } } } } } } } for ( OsmElement removeElement : toCut ) { if ( removeElement instanceof Node ) { removeNode ( ( Node ) removeElement ) ; } else if ( removeElement instanceof Way ) { for ( Node nd : ( ( Way ) removeElement ) . getNodes ( ) ) { Node replacement = replacedNodes . get ( nd . getOsmId ( ) ) ; if ( replacement != null ) { ( ( Way ) removeElement ) . replaceNode ( nd , replacement ) ; } } removeWay ( ( Way ) removeElement ) ; } } for ( OsmElement removeElement : toCut ) { if ( removeElement instanceof Way ) { Set < Node > nodes = new HashSet < > ( ( ( Way ) removeElement ) . getNodes ( ) ) ; for ( Node nd : nodes ) { removeNode ( nd ) ; } } } clipboard . cutTo ( toCut , lat , lon ) ; }
Cut original element to clipboard, does -not- preserve relation memberships
Cut original element to clipboard does - not - preserve relation memberships
// otherwise clipboard will not get saved without other changes // clone all nodes that are members of other ways that are not being cut // 1 is expected (our way will be deleted later) // check if there is actually a Way we are not cutting // we replace nodes here since we are iterating over the ways anyway // and we have to collect all replacements first above // way nodes have to wait till we have removed all the ways //