Ignore:
Timestamp:
2011-03-30T20:43:44+02:00 (14 years ago)
Author:
zverik
Message:

execute sort&fix on add/remove; also static refactoring (reltoolbox plugin)

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

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelation.java

    r25748 r25751  
    6363     */
    6464    public boolean isMultipolygon() {
    65         if( chosenRelation == null )
     65        return isMultipolygon(chosenRelation);
     66    }
     67
     68    public static boolean isMultipolygon( Relation r ) {
     69        if( r == null )
    6670            return false;
    67         String type = chosenRelation.get("type");
     71        String type = r.get("type");
    6872        if( type == null )
    6973            return false;
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/AddRemoveMemberAction.java

    r25717 r25751  
    99import org.openstreetmap.josm.actions.JosmAction;
    1010import org.openstreetmap.josm.command.ChangeCommand;
     11import org.openstreetmap.josm.command.Command;
    1112import org.openstreetmap.josm.data.osm.Node;
    1213import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    4950        toAdd.removeAll(r.getMemberPrimitives());
    5051
     52        // 0. check if relation is broken (temporary)
     53        boolean isBroken = !toAdd.isEmpty() && SortAndFixAction.needsFixing(r);
     54
    5155        // 1. remove all present members
    5256        r.removeMembersFor(getCurrentDataSet().getSelected());
     
    6064                r.addMember(pos, new RelationMember("", p));
    6165        }
     66
     67        // 3. check for roles again (temporary)
     68        Command roleFix = !isBroken && SortAndFixAction.needsFixing(r) ? SortAndFixAction.fixRelation(r) : null;
     69        if( roleFix != null )
     70            roleFix.executeCommand();
    6271
    6372        if( !r.getMemberPrimitives().equals(rel.get().getMemberPrimitives()) )
  • applications/editors/josm/plugins/relcontext/src/relcontext/actions/SortAndFixAction.java

    r25698 r25751  
    88import org.openstreetmap.josm.Main;
    99import org.openstreetmap.josm.command.ChangeCommand;
     10import org.openstreetmap.josm.command.Command;
    1011import org.openstreetmap.josm.data.osm.*;
    1112import org.openstreetmap.josm.tools.ImageProvider;
     
    2728
    2829    public void actionPerformed( ActionEvent e ) {
    29         if( rel.get() == null ) return;
    30         Relation r = rel.get();
     30        Command c = fixRelation(rel.get());
     31        if( c != null )
     32            Main.main.undoRedo.add(c);
     33    }
     34
     35    public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
     36        setEnabled(newRelation != null && needsFixing( newRelation));
     37    }
     38
     39    public static boolean needsFixing( Relation rel ) {
     40        return !isIncomplete(rel) && (areMultipolygonTagsEmpty(rel) || areBoundaryTagsNotRight(rel));
     41    }
     42
     43    public static Command fixRelation( Relation rel ) {
     44        Relation r = rel;
    3145        boolean fixed = false;
    3246        // todo: sort members
     
    4458        }
    4559
    46         if( fixed )
    47             Main.main.undoRedo.add(new ChangeCommand(rel.get(), r));
     60        return fixed ? new ChangeCommand(rel, r) : null;
    4861    }
    4962
    50     public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
    51         setEnabled(newRelation != null && !isIncomplete(newRelation) && (areMultipolygonTagsEmpty() || areBoundaryTagsNotRight()));
    52     }
    53 
    54     protected boolean isIncomplete( Relation r ) {
     63    protected static boolean isIncomplete( Relation r ) {
    5564        if( r == null || r.isIncomplete() || r.isDeleted() )
    5665            return true;
     
    6473     * Check for ways that have roles different from "outer" and "inner".
    6574     */
    66     private boolean areMultipolygonTagsEmpty() {
    67         Relation r = rel == null ? null : rel.get();
    68         if( r == null || r.getMembersCount() == 0 || !rel.isMultipolygon() )
     75    private static boolean areMultipolygonTagsEmpty( Relation r ) {
     76        if( r == null || r.getMembersCount() == 0 || !ChosenRelation.isMultipolygon(r) )
    6977            return false;
    7078        for( RelationMember m : r.getMembers() ) {
     
    7886     * Check for nodes and relations without needed roles.
    7987     */
    80     private boolean areBoundaryTagsNotRight() {
    81         Relation r = rel == null ? null : rel.get();
     88    private static boolean areBoundaryTagsNotRight( Relation r ) {
    8289        if( r == null || r.getMembersCount() == 0 || !r.hasKey("type") || !r.get("type").equals("boundary") )
    8390            return false;
     
    94101     * Basically, created multipolygon from scratch, and if successful, replace roles with new ones.
    95102     */
    96     private Relation fixMultipolygonRoles( Relation source ) {
     103    private static Relation fixMultipolygonRoles( Relation source ) {
    97104        Collection<Way> ways = new ArrayList<Way>();
    98105        for( OsmPrimitive p : source.getMemberPrimitives() )
     
    131138    }
    132139
    133     private Relation fixBoundaryRoles( Relation source ) {
     140    private static Relation fixBoundaryRoles( Relation source ) {
    134141        Relation r = new Relation(source);
    135142        boolean fixed = false;
Note: See TracChangeset for help on using the changeset viewer.