Changeset 8274 in josm for trunk


Ignore:
Timestamp:
2015-04-26T00:19:48+02:00 (10 years ago)
Author:
simon04
Message:

see #10512 - taginfoextract: add initial presets extration, switch all links to HTTPS

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r8061 r8274  
    7676    public TaggingPresetMenu group = null;
    7777    public String name;
     78    public String iconName;
    7879    public String name_context;
    7980    public String locale_name;
     
    147148     */
    148149    public void setIcon(final String iconName) {
     150        this.iconName = iconName;
    149151        File arch = TaggingPresetReader.getZipIcons();
    150152        final Collection<String> s = Main.pref.getCollection("taggingpreset.icon.sources", null);
  • trunk/taginfoextract.groovy

    r8273 r8274  
    55 * Run from the base directory of a JOSM checkout:
    66 *
    7  * groovy -cp dist/josm-custom.jar taginfoextract.groovy
     7 * groovy -cp dist/josm-custom.jar taginfoextract.groovy -t mappaint
     8 * groovy -cp dist/josm-custom.jar taginfoextract.groovy -t presets
    89 */
    910import java.awt.image.BufferedImage
     
    3031import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector
    3132import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
     33import org.openstreetmap.josm.gui.tagging.TaggingPreset
     34import org.openstreetmap.josm.gui.tagging.TaggingPresetItems
     35import org.openstreetmap.josm.gui.tagging.TaggingPresetReader
     36import org.openstreetmap.josm.gui.tagging.TaggingPresetType
    3237import org.openstreetmap.josm.io.CachedFile
     38import org.openstreetmap.josm.tools.Utils
    3339
    3440class taginfoextract {
     
    7480            env.layer = "default"
    7581            return env
    76         }
    77 
    78         /**
    79          * Determine full image url (can refer to JOSM or OSM repository).
    80          */
    81         def find_image_url(path) {
    82             def f = new File("${base_dir}/images/styles/standard/${path}")
    83             if (f.exists()) {
    84                 def rev = osm_svn_revision()
    85                 return "http://trac.openstreetmap.org/export/${rev}/subversion/applications/share/map-icons/classic.small/${path}"
    86             }
    87             f = new File("${base_dir}/images/${path}")
    88             if (f.exists()) {
    89                 return "http://josm.openstreetmap.de/export/${josm_svn_revision}/josm/trunk/images/${path}"
    90             }
    91             assert false, "Cannot find image url for ${path}"
    9282        }
    9383
     
    189179        parse_command_line_arguments(args)
    190180        def script = new taginfoextract()
    191         script.run()
     181        if (!options.t || options.t == 'mappaint') {
     182            script.run()
     183        } else if (options.t == 'presets') {
     184            script.run_presets()
     185        } else {
     186            System.err.println 'Invalid type ' + options.t
     187            System.exit(1)
     188        }
     189
    192190        System.exit(0)
    193191    }
     
    201199            footer:"[inputfile]           the file to process (optional, default is 'resource://styles/standard/elemstyles.mapcss')")
    202200        cli.o(args:1, argName: "file", "output file (json), - prints to stdout (default: -)")
    203         cli._(longOpt:'svnrev', args:1, argName:"revision", "corresponding revision of the repository http://svn.openstreetmap.org/ (optional, current revision is read from the local checkout or from the web if not given, see --svnweb)")
     201        cli.t(args:1, argName: "type", "the project type to be generated")
     202        cli._(longOpt:'svnrev', args:1, argName:"revision", "corresponding revision of the repository https://svn.openstreetmap.org/ (optional, current revision is read from the local checkout or from the web if not given, see --svnweb)")
    204203        cli._(longOpt:'imgdir', args:1, argName:"directory", "directory to put the generated images in (default: ./taginfo-img)")
    205         cli._(longOpt:'svnweb', 'fetch revision of the repository http://svn.openstreetmap.org/ from web and not from the local repository')
     204        cli._(longOpt:'svnweb', 'fetch revision of the repository https://svn.openstreetmap.org/ from web and not from the local repository')
    206205        cli._(longOpt:'imgurlprefix', args:1, argName:'prefix', 'image URLs prefix for generated image files')
    207206        cli.h(longOpt:'help', "show this help")
     
    228227            image_dir_file.mkdirs()
    229228        }
     229    }
     230
     231    void run_presets() {
     232        init()
     233        def tags = []
     234        def presets = TaggingPresetReader.readAll(input_file, true)
     235        for (TaggingPreset preset : presets) {
     236            for (TaggingPresetItems.KeyedItem item : Utils.filteredCollection(preset.data, TaggingPresetItems.KeyedItem.class)) {
     237                def values
     238                switch (TaggingPresetItems.MatchType.ofString(item.match)) {
     239                    case TaggingPresetItems.MatchType.KEY_REQUIRED: values = item.getValues(); break;
     240                    case TaggingPresetItems.MatchType.KEY_VALUE_REQUIRED: values = item.getValues(); break;
     241                    default: values = [];
     242                }
     243                for (String value : values) {
     244                    def tag = [
     245                            description: preset.name,
     246                            key: item.key,
     247                            value: value,
     248                            type: preset.types.collect {it == TaggingPresetType.CLOSEDWAY ? "area" : it.toString().toLowerCase()},
     249                    ]
     250                    if (preset.iconName) tag += [icon: find_image_url(preset.iconName)]
     251                    tags += tag
     252                }
     253            }
     254        }
     255
     256        write_json("JOSM main presets", "Tags supported by the default presets in the OSM editor JOSM", tags)
    230257    }
    231258
     
    266293        }
    267294
    268         def json = get_json("JOSM main mappaint style", "Tags supported by the main mappaint style in the OSM editor JOSM", tags)
     295        write_json("JOSM main mappaint style", "Tags supported by the main mappaint style in the OSM editor JOSM", tags)
     296    }
     297
     298    void write_json(name, description, tags) {
     299        def json = new JsonBuilder()
     300        def project = [
     301                name: name,
     302                description: description,
     303                project_url: "https://josm.openstreetmap.de/",
     304                icon_url: "https://josm.openstreetmap.de/export/7770/josm/trunk/images/logo_16x16x8.png",
     305                contact_name: "JOSM developer team",
     306                contact_email: "josm-dev@openstreetmap.org",
     307        ]
     308        json data_format: 1, data_updated: new Date().format("yyyyMMdd'T'hhmmssZ"), project: project, tags: tags
    269309
    270310        if (output_file != null) {
     
    276316    }
    277317
    278     static JsonBuilder get_json(name, description, tags) {
    279         def json = new JsonBuilder()
    280         def project = [
    281                 name: name,
    282                 description: description,
    283                 project_url: "http://josm.openstreetmap.de/",
    284                 icon_url: "http://josm.openstreetmap.de/export/7770/josm/trunk/images/logo_16x16x8.png",
    285                 contact_name: "JOSM developer team",
    286                 contact_email: "josm-dev@openstreetmap.org",
    287         ]
    288         json data_format: 1, data_updated: new Date().format("yyyyMMdd'T'hhmmssZ"), project: project, tags: tags
    289         return json
    290     }
    291 
    292318    /**
    293319     * Initialize the script.
     
    297323        Main.pref.enableSaveOnPut(false)
    298324        Main.setProjection(Projections.getProjectionByCode("EPSG:3857"))
     325        System.setProperty("josm.home", File.createTempDir().toString());
    299326
    300327        josm_svn_revision = Version.getInstance().getVersion()
    301328        assert josm_svn_revision != Version.JOSM_UNKNOWN_VERSION
    302329
    303         if (options.arguments().size() == 0) {
     330        if (options.arguments().size() == 0 && (!options.t || options.t == 'mappaint')) {
    304331            input_file = "resource://styles/standard/elemstyles.mapcss"
     332        } else if (options.arguments().size() == 0 && options.t == 'presets') {
     333            input_file = "resource://data/defaultpresets.xml"
    305334        } else {
    306335            input_file = options.arguments()[0]
     
    314343
    315344    /**
    316      * Get revision for the repository http://svn.openstreetmap.org.
     345     * Determine full image url (can refer to JOSM or OSM repository).
     346     */
     347    def find_image_url(path) {
     348        def f = new File("${base_dir}/images/styles/standard/${path}")
     349        if (f.exists()) {
     350            def rev = osm_svn_revision()
     351            return "https://trac.openstreetmap.org/export/${rev}/subversion/applications/share/map-icons/classic.small/${path}"
     352        }
     353        f = new File("${base_dir}/images/${path}")
     354        if (f.exists()) {
     355            return "https://josm.openstreetmap.de/export/${josm_svn_revision}/josm/trunk/images/${path}"
     356        }
     357        assert false, "Cannot find image url for ${path}"
     358    }
     359
     360    /**
     361     * Get revision for the repository https://svn.openstreetmap.org.
    317362     */
    318363    def osm_svn_revision() {
     
    324369        def xml
    325370        if (options.svnweb) {
    326             xml = "svn info --xml http://svn.openstreetmap.org/applications/share/map-icons/classic.small".execute().text
     371            xml = "svn info --xml https://svn.openstreetmap.org/applications/share/map-icons/classic.small".execute().text
    327372        } else {
    328373            xml = "svn info --xml ${base_dir}/images/styles/standard/".execute().text
Note: See TracChangeset for help on using the changeset viewer.