Changeset 22230 in osm for applications/editors


Ignore:
Timestamp:
2010-07-07T21:57:06+02:00 (14 years ago)
Author:
pieren
Message:

fix minor issues before release

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Address.java

    r22188 r22230  
    8989    JLabel link = new JLabel();
    9090    private Way selectedWay;
    91     private Relation selectedRelation;
     91    //private Relation selectedRelation;
    9292    private boolean shift;
    9393
     
    146146            } else {
    147147                // check if the node belongs to an associatedStreet relation
    148                 List<OsmPrimitive> l = currentMouseNode.getReferrers();
    149                 boolean nodeBelongsToRelation = false;
    150                 for (OsmPrimitive osm : l) {
    151                     if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) {
    152                         for (RelationMember rm : ((Relation)osm).getMembers()) {
    153                             if (rm.getRole().equals(relationAddrStreetRole)) {
    154                                 OsmPrimitive osp = rm.getMember();
    155                                 if (osp instanceof Way && osp.hasKey(tagHighwayName)) {
    156                                     inputStreet.setText(osp.get(tagHighwayName));
    157                                     setSelectedWay((Way)osp, (Relation)osm);
    158                                     nodeBelongsToRelation = true;
    159                                     break;
    160                                 }
    161                             }
    162                         }
    163                     }
    164                 }
    165                 if (!nodeBelongsToRelation) {
     148                Way wayInRelationAddr = findWayInRelationAddr(currentMouseNode);
     149                if (wayInRelationAddr == null) {
    166150                    // node exists but doesn't carry address information : add tags like a new node
    167151                    Collection<Command> cmds = new LinkedList<Command>();
    168152                    addAddrToPrimitive(currentMouseNode, cmds);
     153                } else {
     154                    inputStreet.setText(wayInRelationAddr.get(tagHighwayName));
     155                    setSelectedWay(wayInRelationAddr);
    169156                }
    170157            }
     
    201188    }
    202189   
     190    private Way findWayInRelationAddr(Node n) {
     191        List<OsmPrimitive> l = n.getReferrers();
     192        for (OsmPrimitive osm : l) {
     193            if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) {
     194                for (RelationMember rm : ((Relation)osm).getMembers()) {
     195                    if (rm.getRole().equals(relationAddrStreetRole)) {
     196                        OsmPrimitive osp = rm.getMember();
     197                        if (osp instanceof Way && osp.hasKey(tagHighwayName)) {
     198                            return (Way)osp;
     199                        }
     200                    }
     201                }
     202            }
     203        }
     204        return null;
     205    }
     206   
    203207    private void addAddrToPolygon(List<Way> mouseOnExistingBuildingWays, Collection<Command> cmds) {
    204208        for (Way w:mouseOnExistingBuildingWays) {
     
    221225            cmds.add(new ChangePropertyCommand(osm, tagHouseStreet, inputStreet.getText()));
    222226        } else if (selectedWay != null) {
    223            // add the node to its relation
    224            if (selectedRelation != null) {
    225                RelationMember rm = new RelationMember(relationMemberHouse, osm);
    226                Relation newRel = new Relation(selectedRelation);
    227                newRel.addMember(rm);
    228                cmds.add(new ChangeCommand(selectedRelation, newRel));
    229            } else {
    230                // create new relation
    231                Relation newRel = new Relation();
    232                newRel.put("type", relationAddrType);
    233                newRel.put(relationAddrName, selectedWay.get(tagHighwayName));
    234                newRel.addMember(new RelationMember(relationAddrStreetRole, selectedWay));
    235                newRel.addMember(new RelationMember(relationMemberHouse, osm));
    236                cmds.add(new AddCommand(newRel));
    237            }
     227            Relation selectedRelation = findRelationAddr(selectedWay);
     228            // add the node to its relation
     229            if (selectedRelation != null) {
     230                RelationMember rm = new RelationMember(relationMemberHouse, osm);
     231                Relation newRel = new Relation(selectedRelation);
     232                newRel.addMember(rm);
     233                cmds.add(new ChangeCommand(selectedRelation, newRel));
     234            } else {
     235                // create new relation
     236                Relation newRel = new Relation();
     237                newRel.put("type", relationAddrType);
     238                newRel.put(relationAddrName, selectedWay.get(tagHighwayName));
     239                newRel.addMember(new RelationMember(relationAddrStreetRole, selectedWay));
     240                newRel.addMember(new RelationMember(relationMemberHouse, osm));
     241                cmds.add(new AddCommand(newRel));
     242            }
    238243        }
    239244        try {
     
    245250            System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\"");
    246251        }
     252    }
     253   
     254    private Relation findRelationAddr(Way w) {
     255        List<OsmPrimitive> l = w.getReferrers();
     256        for (OsmPrimitive osm : l) {
     257            if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) {
     258                return (Relation)osm;
     259            }
     260        }
     261        return null;
    247262    }
    248263   
     
    480495    private void setSelectedWay(Way w) {
    481496        this.selectedWay = w;
    482         this.selectedRelation = null;
    483497        if (w == null) {
    484498            link.setEnabled(false);
    485499        } else
    486500            link.setEnabled(true);
    487     }
    488    
    489     private void setSelectedWay(Way w, Relation r) {
    490         setSelectedWay(w);
    491         this.selectedRelation = r;
    492501    }
    493502   
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java

    r22186 r22230  
    4343    private JCheckBox autoFirstLayer = new JCheckBox(tr("Select first WMS layer in list."));
    4444   
    45     private JCheckBox dontUseRelation = new JCheckBox(tr("Don't use relation for addresses (but \"addr:street\" on nodes)."));
     45    private JCheckBox dontUseRelation = new JCheckBox(tr("Don't use relation for addresses (but \"addr:street\" on elements)."));
    4646   
    4747    private JRadioButton grabMultiplier1 = new JRadioButton("", true);
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/GeorefImage.java

    r20390 r22230  
    5757        this.orgCroppedRaster[2] = max;
    5858        this.orgCroppedRaster[3] = new EastNorth(max.east(), min.north());
    59         this.imageOriginalHeight = img.getHeight();
    60         this.imageOriginalWidth = img.getWidth();
     59        // img can be null for a hack used in overlapping detection
     60        this.imageOriginalHeight = (img == null ? 1 : img.getHeight());
     61        this.imageOriginalWidth = (img == null ? 1 : img.getWidth());
    6162        updatePixelPer();
    6263    }
Note: See TracChangeset for help on using the changeset viewer.