Ignore:
Timestamp:
2011-10-14T23:36:20+02:00 (13 years ago)
Author:
zverik
Message:

It's alive! ALIVE!

Location:
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SplittingMultipolygons.java

    r26887 r26888  
    341341            otherRing.putSourceWayFirst();
    342342       
     343        Map<Relation, Relation> relationCache = new HashMap<Relation, Relation>();
    343344        for( TheRing otherRing : otherWays )
    344             commands.addAll(otherRing.getCommands(false));
    345         commands.addAll(theRing.getCommands());
     345            commands.addAll(otherRing.getCommands(false, relationCache));
     346        commands.addAll(theRing.getCommands(relationCache));
     347        TheRing.updateCommandsWithRelations(commands, relationCache);
    346348        resultingCommands.add(new SequenceCommand(tr("Complete multipolygon for way {0}",
    347349                DefaultNameFormatter.getInstance().format(ring)), commands));
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java

    r26887 r26888  
    6666        redistributeSegments(rings);
    6767        List<Relation> relations = new ArrayList<Relation>();
     68        Map<Relation, Relation> relationCache = new HashMap<Relation, Relation>();
    6869        for( TheRing r : rings ) {
    69             commands.addAll(r.getCommands());
     70            commands.addAll(r.getCommands(relationCache));
    7071            relations.add(r.getRelation());
    7172        }
     73        updateCommandsWithRelations(commands, relationCache);
    7274        return relations;
    7375    }
     
    277279   
    278280    public List<Command> getCommands() {
    279         return getCommands(true);
     281        return getCommands(true, null);
     282    }
     283   
     284    public List<Command> getCommands( Map<Relation, Relation> relationChangeMap ) {
     285        return getCommands(true, relationChangeMap);
    280286    }
    281287   
     
    284290     * The first way is copied from the source one, ChangeCommand is issued in this case.
    285291     */
    286     public List<Command> getCommands( boolean createMultipolygon ) {
     292    public List<Command> getCommands( boolean createMultipolygon, Map<Relation, Relation> relationChangeMap ) {
    287293        Way sourceCopy = new Way(source);
    288294        if( createMultipolygon ) {
     
    303309        for( OsmPrimitive p : source.getReferrers() ) {
    304310            if( p instanceof Relation ) {
    305                 Relation rel = new Relation((Relation)p);
    306                 relationCommands.add(new ChangeCommand((Relation)p, rel));
     311                Relation rel = null;
     312                if( relationChangeMap != null ) {
     313                    if( relationChangeMap.containsKey((Relation)p) )
     314                        rel = relationChangeMap.get((Relation)p);
     315                    else {
     316                        rel = new Relation((Relation)p);
     317                        relationChangeMap.put((Relation)p, rel);
     318                    }
     319                } else {                   
     320                    rel = new Relation((Relation)p);
     321                    relationCommands.add(new ChangeCommand((Relation)p, rel));
     322                }
    307323                for( int i = 0; i < rel.getMembersCount(); i++ )
    308324                    if( rel.getMember(i).getMember().equals(source) )
     
    342358            commands.add(new AddCommand(relation));
    343359        return commands;
     360    }
     361   
     362    public static void updateCommandsWithRelations( List<Command> commands, Map<Relation, Relation> relationCache ) {
     363        for( Relation src : relationCache.keySet() )
     364            commands.add(new ChangeCommand(src, relationCache.get(src)));
    344365    }
    345366
Note: See TracChangeset for help on using the changeset viewer.