[josm-dev] How to update changes in dataSet ?

Flávio Henrique yoshimit at gmail.com
Tue Jan 4 19:38:02 GMT 2011


On Tue, Jan 4, 2011 at 16:59, Dirk Stöcker <openstreetmap at dstoecker.de>wrote:

> I don' understand your description, so probably some code would be better.
> But generally I think you violate a basic principle: Take data from the
> dataset, modify it and then give it back.
>
> Your description sounds like you mix the modify and give back steps.
>  - You have a dataset containing all the ways you want to process.
>  - When you combined two ways, then you get a way object back. You need to
>   remove the original ways (from your local dataset) and add the new one
>   instead.
>  - When you are finished with everything you call the UndoRedo-Action to
>   make you changes permanent.
>
> Intermixing the points 2 and 3 will very likely produce a larger number of
> problems.
>
> Ciao


Hmmm..
I thought the combineWayWorker method would take care of point 2 (removing
the original way and adding the new one), as the sequenceCommand returned
has the commands to delete ways. So, after calling Main.main.undoRedo.add(new
SequenceCommand(tr("Your job"), cmds)), the command to delete the original
way would be executed. I'm wrong here?

I promise not to bother you so much. Is that it can save me a lot of time.

So here the code that I insert in SelectionManager.getObjectsInRectangle
method:

    private void test() {
        Set<String> usedWays = new LinkedHashSet<String>();
        Collection<Way> ways = nc.getCurrentDataSet().getWays();
        Collection<Way> sameWays = new LinkedHashSet<Way>();
        LinkedList<Command> cmds = new LinkedList<Command>();
        Pair<Way, Command> pair;
        for (Way w : ways) {
            if (usedWays.contains(w.get("id_log"))) { // do not work with
ways already worked
                continue;
            }
            usedWays.add(w.get("id_log"));
            sameWays = searchOthersWays(w, ways); // search another segment
with same tag
            if (!sameWays.isEmpty()) { // there's another segment with same
tag ?
                sameWays.add(w); // add first segment as the searchOtherWays
don't return it
                pair = new CombineWayAction().combineWaysWorker(sameWays);
                if (pair != null) {
                    cmds.add(pair.b);
                }
            }
        }
        if (!cmds.isEmpty()) {
            Main.main.undoRedo.add(new SequenceCommand(tr("Combinando
ways"), cmds));
        }
    }

    private Set<Way> searchOthersWays(Way w, Collection<Way> selectedWays) {
        Set<Way> waysIguais = new LinkedHashSet<Way>();
        for (Way way : selectedWays) {
            if (!way.equals(w) && way.get("id_log").equals(w.get("id_log")))
{
                waysIguais.add(way);
            }
        }
        return waysIguais;
    }

That's it. The second time that I select the data with mouse (even seeing
the already combined way), the nc.getCurrentDataSet().getWays() method will
return the same previous dataSet, with no combined ways.

Any help?

Thank you!

Flávio Henrique


More information about the josm-dev mailing list