| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package uk.me.parabola.imgfmt.app.mdr; |
| 14 |
|
| 15 |
import java.io.File; |
| 16 |
import java.util.Arrays; |
| 17 |
import java.util.Collections; |
| 18 |
import java.util.List; |
| 19 |
import java.util.Set; |
| 20 |
import java.util.TreeSet; |
| 21 |
|
| 22 |
import uk.me.parabola.imgfmt.ExitException; |
| 23 |
import uk.me.parabola.imgfmt.app.srt.Sort; |
| 24 |
import uk.me.parabola.mkgmap.CommandArgs; |
| 25 |
import uk.me.parabola.mkgmap.reader.osm.FeatureKind; |
| 26 |
import uk.me.parabola.mkgmap.reader.osm.GType; |
| 27 |
import uk.me.parabola.mkgmap.scan.SyntaxException; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class MdrConfig { |
| 37 |
private static final int DEFAULT_HEADER_LEN = 568; |
| 38 |
|
| 39 |
private boolean writable; |
| 40 |
private boolean forDevice; |
| 41 |
private int headerLen = DEFAULT_HEADER_LEN; |
| 42 |
private Sort sort; |
| 43 |
private File outputDir; |
| 44 |
private boolean splitName; |
| 45 |
private Set<String> mdr7Excl = Collections.emptySet(); |
| 46 |
private Set<String> mdr7Del = Collections.emptySet(); |
| 47 |
private Set<Integer> poiExclTypes = Collections.emptySet(); |
| 48 |
|
| 49 |
public MdrConfig() { |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public MdrConfig(MdrConfig base) { |
| 58 |
splitName = base.isSplitName(); |
| 59 |
mdr7Del = base.getMdr7Del(); |
| 60 |
mdr7Excl = base.getMdr7Excl(); |
| 61 |
poiExclTypes = base.getPoiExclTypes(); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public boolean isWritable() { |
| 68 |
return writable; |
| 69 |
} |
| 70 |
|
| 71 |
public void setWritable(boolean writable) { |
| 72 |
this.writable = writable; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public boolean isForDevice() { |
| 82 |
return forDevice; |
| 83 |
} |
| 84 |
|
| 85 |
public void setForDevice(boolean forDevice) { |
| 86 |
this.forDevice = forDevice; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public int getHeaderLen() { |
| 95 |
return headerLen; |
| 96 |
} |
| 97 |
|
| 98 |
public void setHeaderLen(int headerLen) { |
| 99 |
this.headerLen = headerLen; |
| 100 |
} |
| 101 |
|
| 102 |
public Sort getSort() { |
| 103 |
return sort; |
| 104 |
} |
| 105 |
|
| 106 |
public void setSort(Sort sort) { |
| 107 |
this.sort = sort; |
| 108 |
} |
| 109 |
|
| 110 |
public File getOutputDir() { |
| 111 |
return outputDir; |
| 112 |
} |
| 113 |
|
| 114 |
public void setOutputDir(String outputDir) { |
| 115 |
if (outputDir != null) |
| 116 |
this.outputDir = new File(outputDir); |
| 117 |
} |
| 118 |
|
| 119 |
public void setSplitName(boolean splitName) { |
| 120 |
this.splitName = splitName; |
| 121 |
} |
| 122 |
|
| 123 |
public boolean isSplitName() { |
| 124 |
return splitName; |
| 125 |
} |
| 126 |
|
| 127 |
public Set<String> getMdr7Excl() { |
| 128 |
return Collections.unmodifiableSet(mdr7Excl); |
| 129 |
} |
| 130 |
|
| 131 |
public Set<String> getMdr7Del() { |
| 132 |
return Collections.unmodifiableSet(mdr7Del); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public void setPoiExcl (List<String> opts) { |
| 141 |
if (opts.isEmpty()) |
| 142 |
poiExclTypes = Collections.emptyNavigableSet(); |
| 143 |
else { |
| 144 |
poiExclTypes = new TreeSet<>(); |
| 145 |
for (String range : opts) { |
| 146 |
if (range.contains("-")) { |
| 147 |
String[] ranges = range.split("-"); |
| 148 |
if (ranges.length != 2) |
| 149 |
throw new IllegalArgumentException("invalid range in option " + range); |
| 150 |
genTypesForRange(poiExclTypes, ranges[0], ranges[1]); |
| 151 |
} else { |
| 152 |
genTypesForRange(poiExclTypes, range,range); |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
private static void genTypesForRange(Set<Integer> set, String start, String stop) { |
| 165 |
GType[] types = new GType[2]; |
| 166 |
String[] ranges = {start, stop}; |
| 167 |
boolean ok = true; |
| 168 |
for (int i = 0; i < 2; i++) { |
| 169 |
try { |
| 170 |
types[i] = new GType(FeatureKind.POINT, ranges[i]); |
| 171 |
} catch (ExitException e) { |
| 172 |
ok = false; |
| 173 |
} |
| 174 |
if (!ok || !GType.checkType(types[i].getFeatureKind(), types[i].getType())){ |
| 175 |
throw new SyntaxException("invalid type " + ranges[i] + " for " + FeatureKind.POINT + " in option " + Arrays.toString(ranges)); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
if (types[0].getType() > types[1].getType()) { |
| 180 |
GType gt = types[0]; |
| 181 |
types[0] = types[1]; |
| 182 |
types[1] = gt; |
| 183 |
} |
| 184 |
for (int i = types[0].getType(); i <= types[1].getType(); i++) { |
| 185 |
if ((i & 0xff) > 0x1f) |
| 186 |
i = ((i >> 8) + 1) << 8; |
| 187 |
set.add(i); |
| 188 |
} |
| 189 |
|
| 190 |
} |
| 191 |
|
| 192 |
public Set<Integer> getPoiExclTypes() { |
| 193 |
return Collections.unmodifiableSet(poiExclTypes); |
| 194 |
} |
| 195 |
|
| 196 |
public void setIndexOptions(CommandArgs args) { |
| 197 |
setSplitName(args.get("split-name-index", false)); |
| 198 |
mdr7Excl = args.argToSet("mdr7-excl", null); |
| 199 |
mdr7Del = args.argToSet("mdr7-del", null); |
| 200 |
setPoiExcl(args.argToList("poi-excl-index", null)); |
| 201 |
} |
| 202 |
} |