- Timestamp:
- 2015-04-26T00:19:48+02:00 (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r8061 r8274 76 76 public TaggingPresetMenu group = null; 77 77 public String name; 78 public String iconName; 78 79 public String name_context; 79 80 public String locale_name; … … 147 148 */ 148 149 public void setIcon(final String iconName) { 150 this.iconName = iconName; 149 151 File arch = TaggingPresetReader.getZipIcons(); 150 152 final Collection<String> s = Main.pref.getCollection("taggingpreset.icon.sources", null); -
trunk/taginfoextract.groovy
r8273 r8274 5 5 * Run from the base directory of a JOSM checkout: 6 6 * 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 8 9 */ 9 10 import java.awt.image.BufferedImage … … 30 31 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector 31 32 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser 33 import org.openstreetmap.josm.gui.tagging.TaggingPreset 34 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems 35 import org.openstreetmap.josm.gui.tagging.TaggingPresetReader 36 import org.openstreetmap.josm.gui.tagging.TaggingPresetType 32 37 import org.openstreetmap.josm.io.CachedFile 38 import org.openstreetmap.josm.tools.Utils 33 39 34 40 class taginfoextract { … … 74 80 env.layer = "default" 75 81 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}"92 82 } 93 83 … … 189 179 parse_command_line_arguments(args) 190 180 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 192 190 System.exit(0) 193 191 } … … 201 199 footer:"[inputfile] the file to process (optional, default is 'resource://styles/standard/elemstyles.mapcss')") 202 200 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)") 204 203 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') 206 205 cli._(longOpt:'imgurlprefix', args:1, argName:'prefix', 'image URLs prefix for generated image files') 207 206 cli.h(longOpt:'help', "show this help") … … 228 227 image_dir_file.mkdirs() 229 228 } 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) 230 257 } 231 258 … … 266 293 } 267 294 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 269 309 270 310 if (output_file != null) { … … 276 316 } 277 317 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: tags289 return json290 }291 292 318 /** 293 319 * Initialize the script. … … 297 323 Main.pref.enableSaveOnPut(false) 298 324 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")) 325 System.setProperty("josm.home", File.createTempDir().toString()); 299 326 300 327 josm_svn_revision = Version.getInstance().getVersion() 301 328 assert josm_svn_revision != Version.JOSM_UNKNOWN_VERSION 302 329 303 if (options.arguments().size() == 0 ) {330 if (options.arguments().size() == 0 && (!options.t || options.t == 'mappaint')) { 304 331 input_file = "resource://styles/standard/elemstyles.mapcss" 332 } else if (options.arguments().size() == 0 && options.t == 'presets') { 333 input_file = "resource://data/defaultpresets.xml" 305 334 } else { 306 335 input_file = options.arguments()[0] … … 314 343 315 344 /** 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. 317 362 */ 318 363 def osm_svn_revision() { … … 324 369 def xml 325 370 if (options.svnweb) { 326 xml = "svn info --xml http ://svn.openstreetmap.org/applications/share/map-icons/classic.small".execute().text371 xml = "svn info --xml https://svn.openstreetmap.org/applications/share/map-icons/classic.small".execute().text 327 372 } else { 328 373 xml = "svn info --xml ${base_dir}/images/styles/standard/".execute().text
Note:
See TracChangeset
for help on using the changeset viewer.