Ignore:
Timestamp:
2018-01-13T18:19:22+01:00 (7 years ago)
Author:
donvip
Message:

code cleanup

Location:
applications/editors/josm/plugins/indoorhelper/src/model
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/indoorhelper/src/model/IndoorHelperModel.java

    r33997 r34005  
    4646 * @author rebsc
    4747 */
    48 public class IndoorHelperModel{
     48public class IndoorHelperModel {
    4949
    5050    private TagCatalog tags;
     
    7474     * directly to the relation otherwise add it to nodes and/or ways.
    7575     *
     76     * @author rebsc
    7677     * @param object the object which defines the tag-set you want to add
    7778     * @param userTags the tags which are given by the user input
    78      * @author rebsc
    79      */
    80         public void addTagsToOSM(IndoorObject object, List<Tag> userTags) {
     79     */
     80    public void addTagsToOSM(IndoorObject object, List<Tag> userTags) {
    8181        if (!MainApplication.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty()) {
    8282
    83                 DataSet ds = Main.main.getEditDataSet();
     83            DataSet ds = Main.main.getEditDataSet();
    8484            List<Tag> tags = this.getObjectTags(object);
    8585            Collection<Relation> relations = ds.getRelations();
     
    9292
    9393            // Put value on {@link relationToAdd} if selected object is a relation.
    94             relationToAdd = getRelationFromDataSet(ds,relations);
    95 
    96             if(relationToAdd != null) {
    97                 //Add tags to relation
    98                 for (Tag t : tags) {
    99                                 Main.main.undoRedo.add(new ChangePropertyCommand(relationToAdd, t.getKey(), t.getValue()));
    100                 }
    101             }else{
    102                 //Add tags to ways or nodes
    103                     for (Tag t : tags) {
    104                         Main.main.undoRedo.add(new ChangePropertyCommand(Main.main.getInProgressSelection(), t.getKey(), t.getValue()));
    105                     }
     94            relationToAdd = getRelationFromDataSet(ds, relations);
     95
     96            if (relationToAdd != null) {
     97                //Add tags to relation
     98                for (Tag t : tags) {
     99                        Main.main.undoRedo.add(new ChangePropertyCommand(relationToAdd, t.getKey(), t.getValue()));
     100                }
     101            } else {
     102                //Add tags to ways or nodes
     103                for (Tag t : tags) {
     104                    Main.main.undoRedo.add(new ChangePropertyCommand(Main.main.getInProgressSelection(), t.getKey(), t.getValue()));
     105                }
    106106            }
    107107        //If the selected dataset is empty
    108108        } else if (MainApplication.getLayerManager().getEditDataSet().selectionEmpty()) {
    109109
    110                 JOptionPane.showMessageDialog(null, tr("No data selected."), tr("Error"), JOptionPane.ERROR_MESSAGE);
     110            JOptionPane.showMessageDialog(null, tr("No data selected."), tr("Error"), JOptionPane.ERROR_MESSAGE);
    111111        }
    112112    }
     
    117117     * @param object the object which defines the tag-set you want to add
    118118     */
    119         public void addTagsToOSM(IndoorObject object) {
     119    public void addTagsToOSM(IndoorObject object) {
    120120
    121121        if (!MainApplication.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty()) {
     
    138138     * Method which adds a list of tag-sets to the currently selected OSM data. Tags directly to ways and/or nodes.
    139139     *
     140     * @author rebsc
    140141     * @param userTags the tags which are given by the user input
    141      * @author rebsc
    142      */
    143         public void addTagsToOSM(List<Tag> userTags) {
     142     */
     143    public void addTagsToOSM(List<Tag> userTags) {
    144144
    145145        if (!MainApplication.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty()) {
     
    149149                Main.main.undoRedo.add(new ChangePropertyCommand(Main.main.getInProgressSelection(), t.getKey(), t.getValue()));
    150150            }
    151         }
    152         else if (MainApplication.getLayerManager().getEditDataSet().selectionEmpty()) {
     151        } else if (MainApplication.getLayerManager().getEditDataSet().selectionEmpty()) {
    153152            JOptionPane.showMessageDialog(null, tr("No data selected."), tr("Error"), JOptionPane.ERROR_MESSAGE);
    154153        }
     
    158157     * Method which adds the relation to OSM data. Also adds the selected tag-set to relation object.
    159158     *
     159     * @author rebsc
    160160     * @param String the Multipolygon Role as String
    161      * @author rebsc
    162      */
    163         public void addRelation(String role){
    164         Relation newRelation = new Relation();
    165         RelationMember newMember;
    166         DataSet ds = Main.main.getEditDataSet();
     161     */
     162    public void addRelation(String role) {
     163        Relation newRelation = new Relation();
     164        RelationMember newMember;
     165        DataSet ds = Main.main.getEditDataSet();
    167166
    168167        // Create new relation and add a new member with specific role
    169         if(!MainApplication.getLayerManager().getEditDataSet().selectionEmpty()) {
    170                 for (OsmPrimitive osm : ds.getSelected()) {
     168        if (!MainApplication.getLayerManager().getEditDataSet().selectionEmpty()) {
     169            for (OsmPrimitive osm : ds.getSelected()) {
    171170                 newMember = new RelationMember(role == null ? "" : role, osm);
    172171                 newRelation.addMember(newMember);
    173172            }
    174         }
    175         // Add relation to OSM data
     173        }
     174        // Add relation to OSM data
    176175        MainApplication.undoRedo.add(new AddCommand(MainApplication.getLayerManager().getEditDataSet(), newRelation));
    177176    }
     
    180179     * Method which edits the selected object to the currently selected OSM data (relations).
    181180     *
     181     * @author rebsc
    182182     * @param role The Multipolygon Role as String
    183      * @param relation
    184      * @author rebsc
    185      */
    186         public void editRelation(String role, Collection<OsmPrimitive> innerRelation){
    187 
    188         RelationMember newMember;
    189         DataSet ds = Main.main.getEditDataSet();
    190         Collection<Relation> relations = ds.getRelations();
    191         Relation relation = getRelationFromDataSet(ds,relations);
     183     */
     184    public void editRelation(String role, Collection<OsmPrimitive> innerRelation) {
     185
     186        RelationMember newMember;
     187        DataSet ds = Main.main.getEditDataSet();
     188        Collection<Relation> relations = ds.getRelations();
     189        Relation relation = getRelationFromDataSet(ds, relations);
    192190
    193191        if (!MainApplication.getLayerManager().getEditDataSet().selectionEmpty() && !Main.main.getInProgressSelection().isEmpty() &&
    194                         !innerRelation.isEmpty() && getRole(ds,relations).equals("outer")) {
    195 
    196                 //Add new relation member to selected relation
     192                !innerRelation.isEmpty() && getRole(ds, relations).equals("outer")) {
     193
     194            //Add new relation member to selected relation
    197195            for (OsmPrimitive osm : innerRelation) {
    198196                 newMember = new RelationMember(role == null ? "" : role, osm);
     
    201199
    202200        //Check if dataset is not empty or if {@link innerRelation} has no value
    203         }else if (MainApplication.getLayerManager().getEditDataSet().selectionEmpty() || innerRelation.isEmpty()) {
     201        } else if (MainApplication.getLayerManager().getEditDataSet().selectionEmpty() || innerRelation.isEmpty()) {
    204202            JOptionPane.showMessageDialog(null, tr("No data selected."), tr("Error"), JOptionPane.ERROR_MESSAGE);
    205203
    206204        //If selected object is not a relation member or not a relation member with role "outer"
    207         }else if(!getRole(ds,relations).equals("outer")) {
    208                 JOptionPane.showMessageDialog(null, tr("No relation or no relation member with role \"outer\" selected."), tr("Error"), JOptionPane.ERROR_MESSAGE);
    209         }
    210 
    211     }
    212 
    213   /**
     205        } else if (!getRole(ds, relations).equals("outer")) {
     206            JOptionPane.showMessageDialog(null,
     207                    tr("No relation or no relation member with role \"outer\" selected."), tr("Error"), JOptionPane.ERROR_MESSAGE);
     208        }
     209    }
     210
     211    /**
    214212     * Returns the current ranking of the preset counter, which includes the 4 most used items.
    215213     *
     
    220218    }
    221219
    222 
    223 
    224 /*************************************************
    225 * HELPER METHODS
    226 *
    227 */
    228 
    229220    /**
    230221     * Function which returns the the relation (if any) of the currently selected object.
    231222     * If not returns null.
     223     * @author rebsc
    232224     * @param ds actual working dataset
    233225     * @param relations collection of relations in the dataset
    234226     * @return relation of currently selected dataset
    235      * @author rebsc
    236227     */
    237228    private Relation getRelationFromDataSet(DataSet ds, Collection<Relation> relations) {
    238         for(Relation r: relations) {
    239                 for(RelationMember rm: r.getMembers()) {
    240                         for(OsmPrimitive osm: ds.getSelected()) {
    241                                 if(rm.refersTo(osm)) {
    242                                         return r;
    243                                 }
    244                         }
    245                 }
    246         }
    247         return null;
     229        for (Relation r: relations) {
     230            for (RelationMember rm: r.getMembers()) {
     231                for (OsmPrimitive osm: ds.getSelected()) {
     232                    if (rm.refersTo(osm)) {
     233                        return r;
     234                    }
     235                }
     236            }
     237        }
     238        return null;
    248239    }
    249240
     
    251242     * Function which returns the relation role (if any) of the currently selected object.
    252243     * If object is not a relation returns empty string.
     244     * @author rebsc
    253245     * @param ds active dataset
    254246     * @param relations collection of relations in the dataset
    255247     * @return role of currently selected relation member if any
    256      * @author rebsc
    257248     */
    258249    private String getRole(DataSet ds, Collection<Relation> relations) {
    259250
    260         if(isRelationMember(ds,relations)) {
    261                 for(Relation r: relations) {
    262                         for(RelationMember rm: r.getMembers()) {
    263                                 for(OsmPrimitive osm: ds.getSelected()) {
    264                                         if(rm.refersTo(osm)) {
    265                                                 return rm.getRole();
    266                                         }
    267                                 }
    268                         }
    269                 }
    270         }
    271         return "";
     251        if (isRelationMember(ds, relations)) {
     252            for (Relation r: relations) {
     253                for (RelationMember rm: r.getMembers()) {
     254                    for (OsmPrimitive osm: ds.getSelected()) {
     255                        if (rm.refersTo(osm)) {
     256                            return rm.getRole();
     257                        }
     258                    }
     259                }
     260            }
     261        }
     262        return "";
    272263    }
    273264
    274265    /**
    275266     * Function which returns true if the currently selected object is a relation
     267     * @author rebsc
    276268     * @param ds active dataset
    277269     * @return true if selected object is a relation
    278      * @author rebsc
    279270     */
    280271    private boolean isRelationMember(DataSet ds, Collection<Relation> relations) {
    281         for(Relation r: relations) {
    282                 for(RelationMember rm: r.getMembers()) {
    283                         for(OsmPrimitive osm: ds.getSelected()) {
    284                                 if(rm.refersTo(osm)) {
    285                                         return true;
    286                                 }
    287                         }
    288                 }
    289         }
    290         return false;
    291     }
    292 
    293 
    294 /**
    295 *
    296 *
    297 *
    298 *
    299 *
    300 *
    301 *
    302 *
    303 *
    304 */
     272        for (Relation r: relations) {
     273            for (RelationMember rm: r.getMembers()) {
     274                for (OsmPrimitive osm: ds.getSelected()) {
     275                    if (rm.refersTo(osm)) {
     276                        return true;
     277                    }
     278                }
     279            }
     280        }
     281        return false;
     282    }
    305283}
  • applications/editors/josm/plugins/indoorhelper/src/model/PresetCounter.java

    r33997 r34005  
    137137            return 0;
    138138        }
    139 
    140139    }
    141 
    142 
    143 
    144 /**
    145 *
    146 *
    147 *
    148 *
    149 *
    150 *
    151 *
    152 *
    153 *
    154 */
    155140}
  • applications/editors/josm/plugins/indoorhelper/src/model/TagCatalog.java

    r33997 r34005  
    1919
    2020package model;
    21 
    22 /**
    23  * Class to provide the indoor tagging catalog.
    24  *
    25  * @author egru
    26  * @author rebsc
    27  *
    28  */
    29 import static org.openstreetmap.josm.tools.I18n.tr;
    3021
    3122import java.util.ArrayList;
     
    5344        case DOOR_PRIVATE:
    5445            tagList.add(new Tag("door", "yes"));
    55             tagList.add(new Tag ("access","private"));
     46            tagList.add(new Tag("access", "private"));
    5647            return tagList;
    5748        case DOOR_PUBLIC:
    5849            tagList.add(new Tag("door", "yes"));
    59             tagList.add(new Tag ("access","public"));
     50            tagList.add(new Tag("access", "public"));
    6051            return tagList;
    6152        case ELEVATOR:
     
    6960            return tagList;
    7061        case ACCESS_PRIVATE:
    71                 tagList.add(new Tag("access","private"));
    72                 return tagList;
     62            tagList.add(new Tag("access", "private"));
     63            return tagList;
    7364        case ACCESS_PUBLIC:
    74                 tagList.add(new Tag("access","public"));
    75                 return tagList;
     65            tagList.add(new Tag("access", "public"));
     66            return tagList;
    7667        case TOILET_FEMALE:
    7768            tagList.add(new Tag("indoor", "room"));
     
    9586            return tagList;
    9687        case CORRIDOR:
    97                 tagList.add(new Tag("indoor", "corridor"));
    98                 return tagList;
     88            tagList.add(new Tag("indoor", "corridor"));
     89            return tagList;
    9990        case BENCH:
    100                 tagList.add(new Tag("amenity","bench"));
    101                 return tagList;
     91            tagList.add(new Tag("amenity", "bench"));
     92            return tagList;
    10293        case ZONE:
    103                 tagList.add(new Tag("area","zone"));
    104                 return tagList;
     94            tagList.add(new Tag("area", "zone"));
     95            return tagList;
    10596        case NONE:
    106                 return tagList;
     97            return tagList;
    10798        default:
    10899            tagList = null;
     
    116107     * @author egru
    117108     * @author rebsc
    118      *
    119109     */
    120110    public enum IndoorObject {
    121111        CONCRETE_WALL, GLASS_WALL, ROOM, TOILET_MALE, TOILET_FEMALE, ELEVATOR, DOOR_PRIVATE, DOOR_PUBLIC, ENTRANCE,
    122         ENTRANCE_EXIT_ONLY,ACCESS_PRIVATE,ACCESS_PUBLIC,STEPS,CORRIDOR,BENCH,ZONE,NONE;
     112        ENTRANCE_EXIT_ONLY, ACCESS_PRIVATE, ACCESS_PUBLIC, STEPS, CORRIDOR, BENCH, ZONE, NONE;
    123113    }
    124 
    125 
    126 /**
    127 *
    128 *
    129 *
    130 *
    131 *
    132 *
    133 *
    134 *
    135 *
    136 */
    137114}
Note: See TracChangeset for help on using the changeset viewer.