Changeset 25693 in osm for applications/editors/josm


Ignore:
Timestamp:
2011-03-24T20:56:47+01:00 (14 years ago)
Author:
zverik
Message:

moving tags to multipolygon (relcontext plugin)

Location:
applications/editors/josm/plugins/relcontext
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/relcontext/TODO

    r25692 r25693  
    1 - After creating multipolygon, move tags from outer to relation (setting "tags")
    21- Solve width problem for narrows buttons when "fix" and "download" appear simultaneously
    32- Check all strings to be properly formulated, search for similar ones in josm core and plugins
  • applications/editors/josm/plugins/relcontext/src/relcontext/RelContextDialog.java

    r25692 r25693  
    11package relcontext;
    22
     3import org.openstreetmap.josm.command.SequenceCommand;
     4import org.openstreetmap.josm.command.Command;
    35import java.io.IOException;
    46import java.io.BufferedReader;
     
    4547import org.openstreetmap.josm.tools.GBC;
    4648import org.openstreetmap.josm.command.ChangeCommand;
     49import org.openstreetmap.josm.command.ChangeRelationMemberRoleCommand;
    4750import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    4851import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
     
    514517            Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected();
    515518            Relation r = new Relation(chosenRelation.get());
    516             boolean fixed = false;
     519            List<Command> commands = new ArrayList<Command>();
    517520            for( int i = 0; i < r.getMembersCount(); i++ ) {
    518521                RelationMember m = r.getMember(i);
    519522                if( selected.contains(m.getMember()) ) {
    520523                    if( !role.equals(m.getRole()) ) {
    521                         r.setMember(i, new RelationMember(role, m.getMember()));
    522                         fixed = true;
     524                        commands.add(new ChangeRelationMemberRoleCommand(r, i, role));
    523525                    }
    524526                }
    525527            }
    526             if( fixed )
    527                 Main.main.undoRedo.add(new ChangeCommand(chosenRelation.get(), r));
     528            if( !commands.isEmpty() )
     529                Main.main.undoRedo.add(new SequenceCommand(tr("Change relation member roles to {0}", role), commands));
    528530        }
    529531    }
     
    591593            addMenuItem("boundary", "Create administrative boundary relations");
    592594            addMenuItem("boundaryways", "Add tags boundary and admin_level to boundary relation ways");
    593             addMenuItem("tags", "Move area tags from contour to relation").setEnabled(false);
     595            addMenuItem("tags", "Move area tags from contour to relation");
    594596            addMenuItem("single", "Create a single multipolygon for multiple outer contours").setEnabled(false);
    595597        }
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateMultipolygonAction.java

    r25692 r25693  
    178178    }
    179179
     180    static public final String[] DEFAULT_LINEAR_TAGS = {"barrier", "source"};
     181
    180182    /**
    181183     * This method removes tags/value pairs from inner ways that are present in relation or outer ways.
     
    193195
    194196        List<Way> innerWays = new ArrayList<Way>();
     197        List<Way> outerWays = new ArrayList<Way>();
     198        Set<String> conflictingKeys = new TreeSet<String>();
    195199
    196200        for (RelationMember m: relation.getMembers()) {
     
    202206            if (m.hasRole() && m.getRole() == "outer" && m.isWay() && m.getWay().hasKeys()) {
    203207                Way way = m.getWay();
     208                outerWays.add(way);
    204209                for (String key: way.keySet()) {
    205210                    if (!values.containsKey(key)) { //relation values take precedence
    206211                        values.put(key, way.get(key));
     212                    } else if( !relation.hasKey(key) && !values.get(key).equals(way.get(key)) ) {
     213                        conflictingKeys.add(key);
    207214                    }
    208215                }
     
    210217        }
    211218
     219        // filter out empty key conflicts - we need second iteration
     220        for( RelationMember m: relation.getMembers() )
     221            if( m.hasRole() && m.getRole().equals("outer") && m.isWay() )
     222                for( String key : values.keySet() )
     223                    if( !m.getWay().hasKey(key) && !relation.hasKey(key) )
     224                        conflictingKeys.add(key);
     225
     226        for( String key : conflictingKeys )
     227            values.remove(key);
     228
     229        for( String linearTag : Main.pref.getCollection(PREF_MULTIPOLY + "lineartags", Arrays.asList(DEFAULT_LINEAR_TAGS)))
     230            values.remove(linearTag);
     231
     232        if( values.containsKey("natural") && values.get("natural").equals("coastline") )
     233            values.remove("natural");
     234
     235        values.put("area", "yes");
     236
    212237        List<Command> commands = new ArrayList<Command>();
     238        boolean moveTags = getPref("tags");
    213239
    214240        for(String key: values.keySet()) {
     
    222248            }
    223249
     250            if( moveTags ) {
     251                // remove duplicated tags from outer ways
     252                for (Way way: outerWays) {
     253                    if (way.hasKey(key)) {
     254                        affectedWays.add(way);
     255                    }
     256                }
     257            }
     258
    224259            if (affectedWays.size() > 0) {
    225260                commands.add(new ChangePropertyCommand(affectedWays, key, null));
    226261            }
     262        }
     263
     264        if( moveTags ) {
     265            // add those tag values to the relation
     266            boolean fixed = false;
     267            Relation r2 = new Relation(relation);
     268            for( String key : values.keySet() ) {
     269                if( !r2.hasKey(key) && !key.equals("area") ) {
     270                    r2.put(key, values.get(key));
     271                    fixed = true;
     272                }
     273            }
     274            if( fixed )
     275                commands.add(new ChangeCommand(relation, r2));
    227276        }
    228277
Note: See TracChangeset for help on using the changeset viewer.