Changeset 25702 in osm for applications


Ignore:
Timestamp:
2011-03-25T07:32:25+01:00 (14 years ago)
Author:
zverik
Message:

fix move tags for boundary relations (reltoolbox plugin)

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

Legend:

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

    r25696 r25702  
    1111- Solve multipolygon settings button width problem
    1212- Solve width problem for narrows buttons when "fix" and "download" appear simultaneously
     13- Sort relation members button (now it's just role fixer)
    1314
    1415== RELEASE ==
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/CreateMultipolygonAction.java

    r25695 r25702  
    6161            rel.put("type", "boundary");
    6262            rel.put("boundary", "administrative");
    63             askForAdminLevelAndName(rel);
    6463        } else
    6564            rel.put("type", "multipolygon");
     
    7372            addBoundaryMembers(rel);
    7473        List<Command> list = removeTagsFromInnerWays(rel);
     74        if( !askForAdminLevelAndName(rel) )
     75            return;
    7576        if( isBoundary && getPref("boundaryways") )
    7677            list.addAll(fixWayTagsForBoundary(rel));
     
    180181    static public final String[] DEFAULT_LINEAR_TAGS = {"barrier", "source"};
    181182
     183    private static final Set<String> REMOVE_FROM_BOUNDARY_TAGS = new TreeSet<String>(Arrays.asList(new String[] {
     184        "boundary", "boundary_type", "type", "admin_level"
     185    }));
     186
    182187    /**
    183188     * This method removes tags/value pairs from inner ways that are present in relation or outer ways.
     
    196201        List<Way> innerWays = new ArrayList<Way>();
    197202        List<Way> outerWays = new ArrayList<Way>();
     203
    198204        Set<String> conflictingKeys = new TreeSet<String>();
    199205
     
    233239            values.remove("natural");
    234240
     241        boolean isBoundary = getPref("boundary");
     242        String name = values.get("name");
     243        String adminLevel = values.get("admin_level");
     244        if( isBoundary ) {
     245            Set<String> keySet = new TreeSet<String>(values.keySet());
     246            for( String key : keySet )
     247                if( !REMOVE_FROM_BOUNDARY_TAGS.contains(key) )
     248                    values.remove(key);
     249        }
     250
    235251        values.put("area", "yes");
    236252
     
    243259
    244260            for (Way way: innerWays) {
    245                 if (value.equals(way.get(key))) {
     261                if( way.hasKey(key) && (isBoundary || value.equals(way.get(key))) ) {
    246262                    affectedWays.add(way);
    247263                }
     
    264280        if( moveTags ) {
    265281            // add those tag values to the relation
     282            if( isBoundary )
     283                values.put("name", name);
    266284            boolean fixed = false;
    267285            Relation r2 = new Relation(relation);
    268286            for( String key : values.keySet() ) {
    269                 if( !r2.hasKey(key) && !key.equals("area") ) {
    270                     r2.put(key, values.get(key));
     287                if( !r2.hasKey(key) && !key.equals("area")
     288                        && (!isBoundary || key.equals("admin_level") || key.equals("name"))) {
     289                    if( relation.isNew() )
     290                        relation.put(key, values.get(key));
     291                    else
     292                        r2.put(key, values.get(key));
    271293                    fixed = true;
    272294                }
    273295            }
    274             if( fixed )
     296            if( fixed && !relation.isNew() )
    275297                commands.add(new ChangeCommand(relation, r2));
    276298        }
     
    279301    }
    280302
    281     private void askForAdminLevelAndName( Relation rel ) {
     303    /**
     304     *
     305     * @param rel
     306     * @return false if user pressed "cancel".
     307     */
     308    private boolean askForAdminLevelAndName( Relation rel ) {
     309        String relAL = rel.get("admin_level");
     310        String relName = rel.get("name");
     311        if( relAL != null && relName != null )
     312            return true;
     313
    282314        JPanel panel = new JPanel(new GridBagLayout());
    283315        panel.add(new JLabel(tr("Enter admin level and name for the border relation:")), GBC.eol().insets(0, 0, 0, 5));
    284316
    285317        final JTextField admin = new JTextField();
    286         admin.setText(Main.pref.get(PREF_MULTIPOLY + "lastadmin", ""));
     318        admin.setText(relAL != null ? relAL : Main.pref.get(PREF_MULTIPOLY + "lastadmin", ""));
    287319        panel.add(new JLabel(tr("Admin level")), GBC.std());
    288320        panel.add(Box.createHorizontalStrut(10), GBC.std());
     
    290322
    291323        final JTextField name = new JTextField();
     324        if( relName != null )
     325            name.setText(relName);
    292326        panel.add(new JLabel(tr("Name")), GBC.std());
    293327        panel.add(Box.createHorizontalStrut(10), GBC.std());
     
    316350        if( answer == null || answer == JOptionPane.UNINITIALIZED_VALUE
    317351                || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION) ) {
    318             return;
     352            return false;
    319353        }
    320354
     
    327361        if( new_name.length() > 0 )
    328362            rel.put("name", new_name);
     363        return true;
    329364    }
    330365}
Note: See TracChangeset for help on using the changeset viewer.