source: osm/applications/editors/josm/plugins/seachart/src/render/Signals.java@ 31063

Last change on this file since 31063 was 31063, checked in by malcolmh, 10 years ago

[SeaChart] update

File size: 13.3 KB
Line 
1/* Copyright 2014 Malcolm Herring
2 *
3 * This is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License.
6 *
7 * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
8 */
9
10package render;
11
12import java.awt.Color;
13import java.awt.Font;
14import java.awt.geom.*;
15import java.util.ArrayList;
16import java.util.EnumMap;
17
18import s57.S57att.*;
19import s57.S57obj.*;
20import s57.S57val.*;
21import s57.S57map.*;
22import symbols.Beacons;
23import symbols.Symbols;
24import symbols.Topmarks;
25import symbols.Symbols.*;
26
27public class Signals {
28
29 static final EnumMap<ColCOL, Color> lightColours = new EnumMap<ColCOL, Color>(ColCOL.class);
30 static {
31 lightColours.put(ColCOL.COL_WHT, new Color(0xffff00));
32 lightColours.put(ColCOL.COL_RED, new Color(0xff0000));
33 lightColours.put(ColCOL.COL_GRN, new Color(0x00ff00));
34 lightColours.put(ColCOL.COL_BLU, new Color(0x0000ff));
35 lightColours.put(ColCOL.COL_YEL, new Color(0xffff00));
36 lightColours.put(ColCOL.COL_AMB, new Color(0xffc200));
37 lightColours.put(ColCOL.COL_VIO, new Color(0xee82ee));
38 lightColours.put(ColCOL.COL_ORG, Color.orange);
39 lightColours.put(ColCOL.COL_MAG, Color.magenta);
40 }
41
42 static final EnumMap<ColCOL, String> lightLetters = new EnumMap<ColCOL, String>(ColCOL.class);
43 static {
44 lightLetters.put(ColCOL.COL_WHT, "W");
45 lightLetters.put(ColCOL.COL_RED, "R");
46 lightLetters.put(ColCOL.COL_GRN, "G");
47 lightLetters.put(ColCOL.COL_BLU, "Bu");
48 lightLetters.put(ColCOL.COL_YEL, "Y");
49 lightLetters.put(ColCOL.COL_AMB, "Am");
50 lightLetters.put(ColCOL.COL_VIO, "Vi");
51 lightLetters.put(ColCOL.COL_ORG, "Or");
52 }
53
54 static final EnumMap<LitCHR, String> lightCharacters = new EnumMap<LitCHR, String>(LitCHR.class);
55 static {
56 lightCharacters.put(LitCHR.CHR_F, "F");
57 lightCharacters.put(LitCHR.CHR_FL, "Fl");
58 lightCharacters.put(LitCHR.CHR_LFL, "LFl");
59 lightCharacters.put(LitCHR.CHR_Q, "Q");
60 lightCharacters.put(LitCHR.CHR_VQ, "VQ");
61 lightCharacters.put(LitCHR.CHR_UQ, "UQ");
62 lightCharacters.put(LitCHR.CHR_ISO, "Iso");
63 lightCharacters.put(LitCHR.CHR_OC, "Oc");
64 lightCharacters.put(LitCHR.CHR_IQ, "IQ");
65 lightCharacters.put(LitCHR.CHR_IVQ, "IVQ");
66 lightCharacters.put(LitCHR.CHR_IUQ, "IUQ");
67 lightCharacters.put(LitCHR.CHR_MO, "Mo");
68 lightCharacters.put(LitCHR.CHR_FFL, "FFl");
69 lightCharacters.put(LitCHR.CHR_FLLFL, "FlLFl");
70 lightCharacters.put(LitCHR.CHR_OCFL, "OcFl");
71 lightCharacters.put(LitCHR.CHR_FLFL, "FLFl");
72 lightCharacters.put(LitCHR.CHR_ALOC, "Al.Oc");
73 lightCharacters.put(LitCHR.CHR_ALLFL, "Al.LFl");
74 lightCharacters.put(LitCHR.CHR_ALFL, "Al.Fl");
75 lightCharacters.put(LitCHR.CHR_ALGR, "Al.Gr");
76 lightCharacters.put(LitCHR.CHR_QLFL, "Q+LFl");
77 lightCharacters.put(LitCHR.CHR_VQLFL, "VQ+LFl");
78 lightCharacters.put(LitCHR.CHR_UQLFL, "UQ+LFl");
79 lightCharacters.put(LitCHR.CHR_AL, "Al");
80 lightCharacters.put(LitCHR.CHR_ALFFL, "Al.FFl");
81 }
82
83 public static void addSignals(Feature feature) {
84 if (feature.objs.containsKey(Obj.FOGSIG)) fogSignals(feature);
85 if (feature.objs.containsKey(Obj.RTPBCN)) radarStations(feature);
86 if (feature.objs.containsKey(Obj.RADSTA)) radarStations(feature);
87 if (feature.objs.containsKey(Obj.RDOSTA)) radioStations(feature);
88 if (feature.objs.containsKey(Obj.LIGHTS)) lights(feature);
89 }
90
91 static final EnumMap<CatFOG, String> fogSignals = new EnumMap<CatFOG, String>(CatFOG.class);
92 static {
93 fogSignals.put(CatFOG.FOG_EXPL, "Explos");
94 fogSignals.put(CatFOG.FOG_DIA, "Dia");
95 fogSignals.put(CatFOG.FOG_SIRN, "Siren");
96 fogSignals.put(CatFOG.FOG_NAUT, "Horn");
97 fogSignals.put(CatFOG.FOG_REED, "Horn");
98 fogSignals.put(CatFOG.FOG_TYPH, "Horn");
99 fogSignals.put(CatFOG.FOG_BELL, "Bell");
100 fogSignals.put(CatFOG.FOG_WHIS, "Whis");
101 fogSignals.put(CatFOG.FOG_GONG, "Gong");
102 fogSignals.put(CatFOG.FOG_HORN, "Horn");
103 }
104
105 public static void fogSignals(Feature feature) {
106 Renderer.symbol(feature, Beacons.FogSignal);
107 AttMap atts = feature.objs.get(Obj.FOGSIG).get(0);
108 String str = "";
109 if (atts.containsKey(Att.CATFOG)) {
110 str += fogSignals.get(((ArrayList<?>)(atts.get(Att.CATFOG).val)).get(0));
111 }
112 if (atts.containsKey(Att.SIGGRP)) {
113 str += "(" + atts.get(Att.SIGGRP).val + ")";
114 } else {
115 str += " ";
116 }
117 if (atts.containsKey(Att.SIGPER)) {
118 str += atts.get(Att.SIGPER).val + "s";
119 }
120 if (atts.containsKey(Att.VALMXR)) {
121 str += atts.get(Att.VALMXR).val + "M";
122 }
123 if ((Renderer.zoom >= 15) && !str.isEmpty()) {
124 Renderer.labelText(feature, str, new Font("Arial", Font.PLAIN, 40),Color.black, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-60, -30)));
125 }
126 }
127
128 public static void radarStations(Feature feature) {
129 Renderer.symbol(feature, Beacons.RadarStation);
130 String bstr = "";
131 CatRTB cat = (CatRTB) Rules.getAttEnum(feature, Obj.RTPBCN, 0, Att.CATRTB);
132 String wal = Rules.getAttStr(feature, Obj.RTPBCN, 0, Att.RADWAL);
133 switch (cat) {
134 case RTB_RAMK:
135 bstr += " Ramark";
136 break;
137 case RTB_RACN:
138 bstr += " Racon";
139 String astr = Rules.getAttStr(feature, Obj.RTPBCN, 0, Att.SIGGRP);
140 if (!astr.isEmpty()) {
141 bstr += "(" + astr + ")";
142 }
143 Double per = (Double) Rules.getAttVal(feature, Obj.RTPBCN, 0, Att.SIGPER);
144 Double mxr = (Double) Rules.getAttVal(feature, Obj.RTPBCN, 0, Att.VALMXR);
145 if ((per != null) || (mxr != null)) {
146 bstr += (astr.isEmpty() ? " " : "");
147 if (per != null) bstr += (per != 0) ? per.toString() + "s" : "";
148 if (mxr != null) bstr += (mxr != 0) ? mxr.toString() + "M" : "";
149 }
150 break;
151 default:
152 break;
153 }
154 if (!wal.isEmpty()) {
155 switch (wal) {
156 case "0.03-X":
157 bstr += "(3cm)";
158 break;
159 case "0.10-S":
160 bstr += "(10cm)";
161 break;
162 }
163 }
164 if ((Renderer.zoom >= 15) && !bstr.isEmpty()) {
165 Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-30, -70)));
166 }
167 }
168
169 public static void radioStations(Feature feature) {
170 Renderer.symbol(feature, Beacons.RadarStation);
171 ArrayList<CatROS> cats = (ArrayList<CatROS>)Rules.getAttList(feature, Obj.RDOSTA, 0, Att.CATROS);
172 boolean vais = false;
173 String bstr = "";
174 for (CatROS ros : cats) {
175 switch (ros) {
176 case ROS_OMNI:
177 bstr += " RC";
178 break;
179 case ROS_DIRL:
180 bstr += " RD";
181 break;
182 case ROS_ROTP:
183 bstr += " RW";
184 break;
185 case ROS_CNSL:
186 bstr += " Consol";
187 break;
188 case ROS_RDF:
189 bstr += " RG";
190 break;
191 case ROS_QTA:
192 bstr += " R";
193 break;
194 case ROS_AERO:
195 bstr += " AeroRC";
196 break;
197 case ROS_DECA:
198 bstr += " Decca";
199 break;
200 case ROS_LORN:
201 bstr += " Loran";
202 break;
203 case ROS_DGPS:
204 bstr += " DGPS";
205 break;
206 case ROS_TORN:
207 bstr += " Toran";
208 break;
209 case ROS_OMGA:
210 bstr += " Omega";
211 break;
212 case ROS_SYLD:
213 bstr += " Syledis";
214 break;
215 case ROS_CHKA:
216 bstr += " Chiaka";
217 break;
218 case ROS_PCOM:
219 case ROS_COMB:
220 case ROS_FACS:
221 case ROS_TIME:
222 break;
223 case ROS_PAIS:
224 case ROS_SAIS:
225 bstr += " AIS";
226 break;
227 case ROS_VAIS:
228 vais = true;
229 break;
230 case ROS_VANC:
231 vais = true;
232 Renderer.symbol(feature, Topmarks.TopNorth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
233 break;
234 case ROS_VASC:
235 vais = true;
236 Renderer.symbol(feature, Topmarks.TopSouth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
237 break;
238 case ROS_VAEC:
239 vais = true;
240 Renderer.symbol(feature, Topmarks.TopEast, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
241 break;
242 case ROS_VAWC:
243 vais = true;
244 Renderer.symbol(feature, Topmarks.TopWest, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
245 break;
246 case ROS_VAPL:
247 vais = true;
248 Renderer.symbol(feature, Topmarks.TopCan, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
249 break;
250 case ROS_VASL:
251 vais = true;
252 Renderer.symbol(feature, Topmarks.TopCone, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
253 break;
254 case ROS_VAID:
255 vais = true;
256 Renderer.symbol(feature, Topmarks.TopIsol, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
257 break;
258 case ROS_VASW:
259 vais = true;
260 Renderer.symbol(feature, Topmarks.TopSphere, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
261 break;
262 case ROS_VASP:
263 vais = true;
264 Renderer.symbol(feature, Topmarks.TopX, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
265 break;
266 case ROS_VAWK:
267 vais = true;
268 Renderer.symbol(feature, Topmarks.TopCross, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
269 break;
270 default:
271 break;
272 }
273 }
274 if (Renderer.zoom >= 15) {
275 if (vais) {
276 Renderer.labelText(feature, "V-AIS", new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 70)));
277 }
278 if (!bstr.isEmpty()) {
279 Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-30, -110)));
280 }
281 }
282 }
283
284 public static void lights(Feature feature) {
285 Enum<ColCOL> col = null;
286 Enum<ColCOL> tcol = null;
287 ObjTab lights = feature.objs.get(Obj.LIGHTS);
288 for (AttMap atts : lights.values()) {
289 if (atts.containsKey(Att.COLOUR)) {
290 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
291 if (cols.size() == 1) {
292 tcol = cols.get(0);
293 if (col == null) {
294 col = tcol;
295 } else if (tcol != col) {
296 col = ColCOL.COL_MAG;
297 break;
298 }
299 } else {
300 col = ColCOL.COL_MAG;
301 break;
302 }
303 }
304 }
305 Renderer.symbol(feature, Beacons.LightFlare, new Scheme(lightColours.get(col)), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.toRadians(120))));
306 if (lights.get(1) != null) {
307 for (AttMap atts : lights.values()) {
308 Enum<ColCOL> col1 = null;
309 Enum<ColCOL> col2 = null;
310 double radius = 0.2;
311 double s1 = 0;
312 double s2 = 0;
313 boolean dir = false;
314 if (atts.containsKey(Att.COLOUR)) {
315 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
316 col1 = cols.get(0);
317 if (cols.size() > 1) col2 = cols.get(1);
318 } else {
319 continue;
320 }
321 if (atts.containsKey(Att.RADIUS)) {
322 radius = (Double) atts.get(Att.RADIUS).val;
323 }
324 if (atts.containsKey(Att.SECTR1)) {
325 s1 = (Double) atts.get(Att.SECTR1).val;
326 } else {
327 continue;
328 }
329 if (atts.containsKey(Att.SECTR2)) {
330 s2 = (Double) atts.get(Att.SECTR2).val;
331 } else {
332 continue;
333 }
334 if (atts.containsKey(Att.CATLIT)) {
335 ArrayList<CatLIT> cats = (ArrayList<CatLIT>) atts.get(Att.CATLIT).val;
336 if (cats.contains(CatLIT.LIT_DIR)) {
337 dir = true;
338 }
339 }
340 String str = "";
341 if (atts.containsKey(Att.LITCHR)) {
342 str += lightCharacters.get(atts.get(Att.LITCHR).val);
343 }
344 if (atts.containsKey(Att.SIGGRP)) {
345 str += "(" + atts.get(Att.SIGGRP).val + ")";
346 } else if (!str.isEmpty()) {
347 str += ".";
348 }
349 if (atts.containsKey(Att.COLOUR)) {
350 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
351 str += lightLetters.get(cols.get(0));
352 if (cols.size() > 1)
353 str += lightLetters.get(cols.get(1));
354 }
355 if (dir && atts.containsKey(Att.ORIENT)) {
356 double orient = (Double)atts.get(Att.ORIENT).val;
357 str += " " + orient + "°";
358 s1 = (orient - 4 + 360) % 360;
359 s2 = (orient + 4) % 360;
360 double n1 = 360;
361 double n2 = 360;
362 for (AttMap sect : lights.values()) {
363 if (sect != atts) {
364
365 }
366 }
367 }
368 Renderer.lightSector(feature, lightColours.get(col1), lightColours.get(col2), radius, s1, s2, dir, str);
369 }
370 }
371 final Att matches[] = { Att.SIGPER, Att.SIGGRP, Att.MLTYLT, Att.LITCHR, Att.CATLIT, Att.HEIGHT };
372 ArrayList<ArrayList<AttMap>> groups = new ArrayList<ArrayList<AttMap>>();
373 for (AttMap sector : lights.values()) {
374 if (sector.containsKey(Att.COLOUR)) {
375 boolean equal = false;
376 for (ArrayList<AttMap> group : groups) {
377 AttMap member = group.get(0);
378 for (Att match : matches) {
379 if (!((sector.containsKey(match) && member.containsKey(match) && sector.get(match).val.equals(member.get(match).val)) || (!sector.containsKey(match) && !member.containsKey(match)))) {
380 equal = false;
381 break;
382 } else {
383 equal = true;
384 }
385 }
386 if (equal) {
387 group.add(sector);
388 break;
389 }
390 }
391 if (!equal) {
392 ArrayList<AttMap> group = new ArrayList<AttMap>();
393 group.add(sector);
394 groups.add(group);
395 }
396 }
397 }
398 for (boolean sorted = false; !sorted;) {
399 sorted = true;
400 for (int i = 0; i < groups.size()-1; i ++) {
401 if (groups.get(i).size() < groups.get(i+1).size()) {
402 ArrayList<AttMap> tmp = groups.remove(i);
403 groups.add(i+1, tmp);
404 sorted = false;
405 }
406 }
407 }
408 for (ArrayList<AttMap> group : groups) {
409 for (boolean sorted = false; !sorted;) {
410 sorted = true;
411 for (int i = 0; i < group.size()-1; i ++) {
412 AttMap m0 = group.get(i);
413 AttMap m1 = group.get(i+1);
414 if (((m0.containsKey(Att.VALNMR) && m1.containsKey(Att.VALNMR) && ((int)m0.get(Att.VALNMR).val < (int)m1.get(Att.VALNMR).val)))
415 || (!m0.containsKey(Att.VALNMR) && m1.containsKey(Att.VALNMR))) {
416 AttMap tmp = group.remove(i);
417 group.add(i+1, tmp);
418 sorted = false;
419 }
420 }
421 }
422 }
423 }
424
425}
Note: See TracBrowser for help on using the repository browser.