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

Last change on this file since 32481 was 32394, checked in by donvip, 9 years ago

checkstyle

File size: 32.0 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.AffineTransform;
15import java.text.DecimalFormat;
16import java.util.ArrayList;
17import java.util.EnumMap;
18
19import s57.S57att.Att;
20import s57.S57map.AttMap;
21import s57.S57map.ObjTab;
22import s57.S57obj.Obj;
23import s57.S57val.BoySHP;
24import s57.S57val.CatFOG;
25import s57.S57val.CatLIT;
26import s57.S57val.CatROS;
27import s57.S57val.CatRTB;
28import s57.S57val.ColCOL;
29import s57.S57val.LitCHR;
30import symbols.Beacons;
31import symbols.Symbols;
32import symbols.Symbols.Delta;
33import symbols.Symbols.Handle;
34import symbols.Symbols.Scheme;
35import symbols.Topmarks;
36
37public class Signals extends Rules {
38
39 static final EnumMap<ColCOL, Color> LightColours = new EnumMap<>(ColCOL.class);
40 static {
41 LightColours.put(ColCOL.COL_WHT, new Color(0xffff00));
42 LightColours.put(ColCOL.COL_RED, new Color(0xff0000));
43 LightColours.put(ColCOL.COL_GRN, new Color(0x00ff00));
44 LightColours.put(ColCOL.COL_BLU, new Color(0x0000ff));
45 LightColours.put(ColCOL.COL_YEL, new Color(0xffff00));
46 LightColours.put(ColCOL.COL_AMB, new Color(0xffc200));
47 LightColours.put(ColCOL.COL_VIO, new Color(0xee82ee));
48 LightColours.put(ColCOL.COL_ORG, Color.orange);
49 LightColours.put(ColCOL.COL_MAG, Color.magenta);
50 }
51
52 static final EnumMap<ColCOL, String> LightLetters = new EnumMap<>(ColCOL.class);
53 static {
54 LightLetters.put(ColCOL.COL_WHT, "W");
55 LightLetters.put(ColCOL.COL_RED, "R");
56 LightLetters.put(ColCOL.COL_GRN, "G");
57 LightLetters.put(ColCOL.COL_BLU, "Bu");
58 LightLetters.put(ColCOL.COL_YEL, "Y");
59 LightLetters.put(ColCOL.COL_AMB, "Am");
60 LightLetters.put(ColCOL.COL_VIO, "Vi");
61 LightLetters.put(ColCOL.COL_ORG, "Or");
62 }
63
64 static final EnumMap<LitCHR, String> LightCharacters = new EnumMap<>(LitCHR.class);
65 static {
66 LightCharacters.put(LitCHR.CHR_F, "F");
67 LightCharacters.put(LitCHR.CHR_FL, "Fl");
68 LightCharacters.put(LitCHR.CHR_LFL, "LFl");
69 LightCharacters.put(LitCHR.CHR_Q, "Q");
70 LightCharacters.put(LitCHR.CHR_VQ, "VQ");
71 LightCharacters.put(LitCHR.CHR_UQ, "UQ");
72 LightCharacters.put(LitCHR.CHR_ISO, "Iso");
73 LightCharacters.put(LitCHR.CHR_OC, "Oc");
74 LightCharacters.put(LitCHR.CHR_IQ, "IQ");
75 LightCharacters.put(LitCHR.CHR_IVQ, "IVQ");
76 LightCharacters.put(LitCHR.CHR_IUQ, "IUQ");
77 LightCharacters.put(LitCHR.CHR_MO, "Mo");
78 LightCharacters.put(LitCHR.CHR_FFL, "FFl");
79 LightCharacters.put(LitCHR.CHR_FLLFL, "FlLFl");
80 LightCharacters.put(LitCHR.CHR_OCFL, "OcFl");
81 LightCharacters.put(LitCHR.CHR_FLFL, "FLFl");
82 LightCharacters.put(LitCHR.CHR_ALOC, "Al.Oc");
83 LightCharacters.put(LitCHR.CHR_ALLFL, "Al.LFl");
84 LightCharacters.put(LitCHR.CHR_ALFL, "Al.Fl");
85 LightCharacters.put(LitCHR.CHR_ALGR, "Al.Gr");
86 LightCharacters.put(LitCHR.CHR_QLFL, "Q+LFl");
87 LightCharacters.put(LitCHR.CHR_VQLFL, "VQ+LFl");
88 LightCharacters.put(LitCHR.CHR_UQLFL, "UQ+LFl");
89 LightCharacters.put(LitCHR.CHR_AL, "Al");
90 LightCharacters.put(LitCHR.CHR_ALFFL, "Al.FFl");
91 }
92
93 static final EnumMap<CatFOG, String> fogSignals = new EnumMap<>(CatFOG.class);
94 static {
95 fogSignals.put(CatFOG.FOG_EXPL, "Explos");
96 fogSignals.put(CatFOG.FOG_DIA, "Dia");
97 fogSignals.put(CatFOG.FOG_SIRN, "Siren");
98 fogSignals.put(CatFOG.FOG_NAUT, "Horn");
99 fogSignals.put(CatFOG.FOG_REED, "Horn");
100 fogSignals.put(CatFOG.FOG_TYPH, "Horn");
101 fogSignals.put(CatFOG.FOG_BELL, "Bell");
102 fogSignals.put(CatFOG.FOG_WHIS, "Whis");
103 fogSignals.put(CatFOG.FOG_GONG, "Gong");
104 fogSignals.put(CatFOG.FOG_HORN, "Horn");
105 }
106
107 static final DecimalFormat df = new DecimalFormat("#.#");
108
109 public static void addSignals() {
110 if (feature.objs.containsKey(Obj.RADRFL)) reflectors();
111 if (feature.objs.containsKey(Obj.FOGSIG)) fogSignals();
112 if (feature.objs.containsKey(Obj.RTPBCN)) radarStations();
113 if (feature.objs.containsKey(Obj.RADSTA)) radarStations();
114 if (feature.objs.containsKey(Obj.RDOSTA)) radioStations();
115 if (feature.objs.containsKey(Obj.LIGHTS)) lights();
116 }
117
118 public static void reflectors() {
119 if (Renderer.zoom >= 14) {
120 switch (feature.type) {
121 case BCNLAT:
122 case BCNCAR:
123 case BCNISD:
124 case BCNSAW:
125 case BCNSPP:
126 if ((feature.objs.containsKey(Obj.TOPMAR)) || (feature.objs.containsKey(Obj.DAYMAR))) {
127 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -140)));
128 } else {
129 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -80)));
130 }
131 break;
132 case LITFLT:
133 case LITVES:
134 case BOYINB:
135 if ((feature.objs.containsKey(Obj.TOPMAR)) || (feature.objs.containsKey(Obj.DAYMAR))) {
136 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -110)));
137 } else {
138 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -60)));
139 }
140 break;
141 case LITMAJ:
142 case LITMIN:
143 if ((feature.objs.containsKey(Obj.TOPMAR)) || (feature.objs.containsKey(Obj.DAYMAR))) {
144 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -90)));
145 } else {
146 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -30)));
147 }
148 break;
149 case BOYLAT:
150 case BOYCAR:
151 case BOYISD:
152 case BOYSAW:
153 case BOYSPP:
154 if ((feature.objs.containsKey(Obj.TOPMAR)) || (feature.objs.containsKey(Obj.DAYMAR))) {
155 if (testAttribute(feature.type, Att.BOYSHP, BoySHP.BOY_PILR) || testAttribute(feature.type, Att.BOYSHP, BoySHP.BOY_SPAR)) {
156 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(50, -160)));
157 } else {
158 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(25, -80)));
159 }
160 } else {
161 if (testAttribute(feature.type, Att.BOYSHP, BoySHP.BOY_PILR) || testAttribute(feature.type, Att.BOYSHP, BoySHP.BOY_SPAR)) {
162 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(30, -100)));
163 } else {
164 Renderer.symbol(Topmarks.RadarReflector, new Delta(Handle.BC, AffineTransform.getTranslateInstance(10, -50)));
165 }
166 }
167 break;
168 default:
169 break;
170 }
171 }
172 }
173
174 public static void fogSignals() {
175 if (Renderer.zoom >= 11)
176 Renderer.symbol(Beacons.FogSignal);
177 if (Renderer.zoom >= 15) {
178 AttMap atts = feature.objs.get(Obj.FOGSIG).get(0);
179 if (atts != null) {
180 String str = "";
181 if (atts.containsKey(Att.CATFOG)) {
182 str += fogSignals.get(((ArrayList<?>) (atts.get(Att.CATFOG).val)).get(0));
183 }
184 if (atts.containsKey(Att.SIGGRP)) {
185 str += "(" + atts.get(Att.SIGGRP).val + ")";
186 } else {
187 str += " ";
188 }
189 if (atts.containsKey(Att.SIGPER)) {
190 str += df.format(atts.get(Att.SIGPER).val) + "s";
191 }
192 if (atts.containsKey(Att.VALMXR)) {
193 str += df.format(atts.get(Att.VALMXR).val) + "M";
194 }
195 if (!str.isEmpty()) {
196 Renderer.labelText(str, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-60, -30)));
197 }
198 }
199 }
200 }
201
202 public static void radarStations() {
203 if (Renderer.zoom >= 11)
204 Renderer.symbol(Beacons.RadarStation);
205 if (Renderer.zoom >= 15) {
206 String bstr = "";
207 CatRTB cat = (CatRTB) getAttEnum(Obj.RTPBCN, Att.CATRTB);
208 String wal = getAttStr(Obj.RTPBCN, Att.RADWAL);
209 switch (cat) {
210 case RTB_RAMK:
211 bstr += " Ramark";
212 break;
213 case RTB_RACN:
214 bstr += " Racon";
215 String astr = getAttStr(Obj.RTPBCN, Att.SIGGRP);
216 if (!astr.isEmpty()) {
217 bstr += "(" + astr + ")";
218 }
219 Double per = (Double) getAttVal(Obj.RTPBCN, Att.SIGPER);
220 Double mxr = (Double) getAttVal(Obj.RTPBCN, Att.VALMXR);
221 if ((per != null) || (mxr != null)) {
222 bstr += (astr.isEmpty() ? " " : "");
223 if (per != null)
224 bstr += (per != 0) ? per.toString() + "s" : "";
225 if (mxr != null)
226 bstr += (mxr != 0) ? mxr.toString() + "M" : "";
227 }
228 break;
229 default:
230 break;
231 }
232 if (!wal.isEmpty()) {
233 switch (wal) {
234 case "0.03-X":
235 bstr += "(3cm)";
236 break;
237 case "0.10-S":
238 bstr += "(10cm)";
239 break;
240 }
241 }
242 if (!bstr.isEmpty()) {
243 Renderer.labelText(bstr, new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-30, -70)));
244 }
245 }
246 }
247
248 @SuppressWarnings("unchecked")
249 public static void radioStations() {
250 boolean vais = false;
251 String bstr = "";
252 if (Renderer.zoom >= 11) {
253 ArrayList<CatROS> cats = (ArrayList<CatROS>) getAttList(Obj.RDOSTA, Att.CATROS);
254 for (CatROS ros : cats) {
255 switch (ros) {
256 case ROS_OMNI:
257 bstr += " RC";
258 break;
259 case ROS_DIRL:
260 bstr += " RD";
261 break;
262 case ROS_ROTP:
263 bstr += " RW";
264 break;
265 case ROS_CNSL:
266 bstr += " Consol";
267 break;
268 case ROS_RDF:
269 bstr += " RG";
270 break;
271 case ROS_QTA:
272 bstr += " R";
273 break;
274 case ROS_AERO:
275 bstr += " AeroRC";
276 break;
277 case ROS_DECA:
278 bstr += " Decca";
279 break;
280 case ROS_LORN:
281 bstr += " Loran";
282 break;
283 case ROS_DGPS:
284 bstr += " DGPS";
285 break;
286 case ROS_TORN:
287 bstr += " Toran";
288 break;
289 case ROS_OMGA:
290 bstr += " Omega";
291 break;
292 case ROS_SYLD:
293 bstr += " Syledis";
294 break;
295 case ROS_CHKA:
296 bstr += " Chiaka";
297 break;
298 case ROS_PCOM:
299 case ROS_COMB:
300 case ROS_FACS:
301 case ROS_TIME:
302 break;
303 case ROS_PAIS:
304 case ROS_SAIS:
305 bstr += " AIS";
306 break;
307 case ROS_VAIS:
308 vais = true;
309 break;
310 case ROS_VANC:
311 vais = true;
312 Renderer.symbol(Topmarks.TopNorth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
313 break;
314 case ROS_VASC:
315 vais = true;
316 Renderer.symbol(Topmarks.TopSouth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
317 break;
318 case ROS_VAEC:
319 vais = true;
320 Renderer.symbol(Topmarks.TopEast, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
321 break;
322 case ROS_VAWC:
323 vais = true;
324 Renderer.symbol(Topmarks.TopWest, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
325 break;
326 case ROS_VAPL:
327 vais = true;
328 Renderer.symbol(Topmarks.TopCan, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
329 break;
330 case ROS_VASL:
331 vais = true;
332 Renderer.symbol(Topmarks.TopCone, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
333 break;
334 case ROS_VAID:
335 vais = true;
336 Renderer.symbol(Topmarks.TopIsol, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
337 break;
338 case ROS_VASW:
339 vais = true;
340 Renderer.symbol(Topmarks.TopSphere, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
341 break;
342 case ROS_VASP:
343 vais = true;
344 Renderer.symbol(Topmarks.TopX, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
345 break;
346 case ROS_VAWK:
347 vais = true;
348 Renderer.symbol(Topmarks.TopCross, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
349 break;
350 default:
351 break;
352 }
353 }
354 if (!vais) {
355 Renderer.symbol(Beacons.RadarStation);
356 }
357 }
358 if (Renderer.zoom >= 15) {
359 if (vais) {
360 Renderer.labelText("V-AIS", new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 70)));
361 }
362 if (!bstr.isEmpty()) {
363 Renderer.labelText(bstr, new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-30, -110)));
364 }
365 }
366 }
367
368 class Sect {
369 int dir;
370 LitCHR chr;
371 ColCOL col;
372 ColCOL alt;
373 String grp;
374 double per;
375 double rng;
376 }
377
378 @SuppressWarnings("unchecked")
379 public static void lights() {
380 Enum<ColCOL> col = null;
381 Enum<ColCOL> tcol = null;
382 ObjTab lights = feature.objs.get(Obj.LIGHTS);
383 for (AttMap atts : lights.values()) {
384 if (atts.containsKey(Att.COLOUR)) {
385 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
386 if (cols.size() == 1) {
387 tcol = cols.get(0);
388 if (col == null) {
389 col = tcol;
390 } else if (tcol != col) {
391 col = ColCOL.COL_MAG;
392 break;
393 }
394 } else {
395 col = ColCOL.COL_MAG;
396 break;
397 }
398 }
399 }
400 Renderer.symbol(Beacons.LightFlare, new Scheme(LightColours.get(col)), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.toRadians(120))));
401 if (Renderer.zoom >= 12) {
402 String str = "";
403 if (lights.get(1) != null) {
404 for (AttMap atts : lights.values()) {
405 Enum<ColCOL> col1 = null;
406 Enum<ColCOL> col2 = null;
407 double radius = 0.2;
408 double s1 = 361;
409 double s2 = 361;
410 Double dir = null;
411 if (atts.containsKey(Att.COLOUR)) {
412 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
413 col1 = cols.get(0);
414 if (cols.size() > 1)
415 col2 = cols.get(1);
416 } else {
417 continue;
418 }
419 if (atts.containsKey(Att.LITRAD)) {
420 radius = (Double) atts.get(Att.LITRAD).val;
421 }
422 if (atts.containsKey(Att.CATLIT)) {
423 ArrayList<CatLIT> cats = (ArrayList<CatLIT>) atts.get(Att.CATLIT).val;
424 if (cats.contains(CatLIT.LIT_DIR)) {
425 if (atts.containsKey(Att.ORIENT)) {
426 dir = (Double) atts.get(Att.ORIENT).val;
427 s1 = ((dir - 4) + 360) % 360;
428 s2 = (dir + 4) % 360;
429 for (AttMap satts : lights.values()) {
430 double srad = 0.2;
431 double ss1 = 361;
432 double ss2 = 361;
433 Double sdir = null;
434 if (satts == atts)
435 continue;
436 if (satts.containsKey(Att.LITRAD)) {
437 srad = (Double) satts.get(Att.LITRAD).val;
438 }
439 if (srad == radius) {
440 ArrayList<CatLIT> scats = (satts.containsKey(Att.CATLIT)) ? (ArrayList<CatLIT>) satts.get(Att.CATLIT).val : new ArrayList<CatLIT>();
441 if (scats.contains(CatLIT.LIT_DIR)) {
442 if (satts.containsKey(Att.ORIENT)) {
443 sdir = (Double) satts.get(Att.ORIENT).val;
444 ss1 = sdir;
445 ss2 = sdir;
446 }
447 } else {
448 if (satts.containsKey(Att.SECTR1)) {
449 ss1 = (Double) satts.get(Att.SECTR1).val;
450 }
451 if (satts.containsKey(Att.SECTR2)) {
452 ss2 = (Double) satts.get(Att.SECTR2).val;
453 }
454 }
455 if ((ss1 > 360) || (ss2 > 360))
456 continue;
457 if (sdir != null) {
458 if (((dir - sdir + 360) % 360) < 8) {
459 s1 = ((((sdir > dir) ? 360 : 0) + sdir + dir) / 2) % 360;
460 }
461 if (((sdir - dir + 360) % 360) < 8) {
462 s2 = ((((dir > sdir) ? 360 : 0) + sdir + dir) / 2) % 360;
463 }
464 } else {
465 if (((dir - ss2 + 360) % 360) < 4) {
466 s1 = ss2;
467 }
468 if (((ss1 - dir + 360) % 360) < 4) {
469 s2 = ss1;
470 }
471 }
472 }
473 }
474 }
475 }
476 }
477 if ((s1 > 360) && atts.containsKey(Att.SECTR1)) {
478 s1 = (Double) atts.get(Att.SECTR1).val;
479 } else if (dir == null) {
480 continue;
481 }
482 if ((s2 > 360) && atts.containsKey(Att.SECTR2)) {
483 s2 = (Double) atts.get(Att.SECTR2).val;
484 } else if (dir == null) {
485 continue;
486 }
487 str = "";
488 if (atts.containsKey(Att.LITCHR)) {
489 str += LightCharacters.get(((ArrayList<LitCHR>) atts.get(Att.LITCHR).val).get(0));
490 }
491 if (atts.containsKey(Att.SIGGRP)) {
492 str += "(" + atts.get(Att.SIGGRP).val + ")";
493 } else if (!str.isEmpty()) {
494 str += ".";
495 }
496 if (atts.containsKey(Att.COLOUR)) {
497 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
498 str += LightLetters.get(cols.get(0));
499 if (cols.size() > 1)
500 str += LightLetters.get(cols.get(1));
501 }
502 if (atts.containsKey(Att.SIGPER)) {
503 str += "." + df.format(atts.get(Att.SIGPER).val) + "s";
504 }
505 if ((s1 <= 360) && (s2 <= 360) && (s1 != s2))
506 Renderer.lightSector(LightColours.get(col1), LightColours.get(col2), radius, s1, s2, dir, (Renderer.zoom >= 15) ? str : "");
507 }
508 if (Renderer.zoom >= 15) {
509 class LitSect {
510 boolean dir;
511 LitCHR chr;
512 ColCOL col;
513 String grp;
514 double per;
515 double rng;
516 double hgt;
517 }
518
519 ArrayList<LitSect> litatts = new ArrayList<>();
520 for (AttMap atts : lights.values()) {
521 LitSect sect = new LitSect();
522 sect.dir = (atts.containsKey(Att.CATLIT) && ((ArrayList<CatLIT>) atts.get(Att.CATLIT).val).contains(CatLIT.LIT_DIR));
523 sect.chr = atts.containsKey(Att.LITCHR) ? ((ArrayList<LitCHR>) atts.get(Att.LITCHR).val).get(0) : LitCHR.CHR_UNKN;
524 switch (sect.chr) {
525 case CHR_AL:
526 sect.chr = LitCHR.CHR_F;
527 break;
528 case CHR_ALOC:
529 sect.chr = LitCHR.CHR_OC;
530 break;
531 case CHR_ALLFL:
532 sect.chr = LitCHR.CHR_LFL;
533 break;
534 case CHR_ALFL:
535 sect.chr = LitCHR.CHR_FL;
536 break;
537 case CHR_ALFFL:
538 sect.chr = LitCHR.CHR_FFL;
539 break;
540 default:
541 break;
542 }
543 sect.grp = atts.containsKey(Att.SIGGRP) ? (String) atts.get(Att.SIGGRP).val : "";
544 sect.per = atts.containsKey(Att.SIGPER) ? (Double) atts.get(Att.SIGPER).val : 0.0;
545 sect.rng = atts.containsKey(Att.VALNMR) ? (Double) atts.get(Att.VALNMR).val : 0.0;
546 sect.hgt = atts.containsKey(Att.HEIGHT) ? (Double) atts.get(Att.HEIGHT).val : 0.0;
547 ArrayList<ColCOL> cols = (ArrayList<ColCOL>) (atts.containsKey(Att.COLOUR) ? atts.get(Att.COLOUR).val : new ArrayList<>());
548 sect.col = cols.size() > 0 ? cols.get(0) : ColCOL.COL_UNK;
549 if ((sect.chr != LitCHR.CHR_UNKN) && (sect.col != null))
550 litatts.add(sect);
551 }
552 ArrayList<ArrayList<LitSect>> groupings = new ArrayList<>();
553 for (LitSect lit : litatts) {
554 boolean found = false;
555 for (ArrayList<LitSect> group : groupings) {
556 LitSect mem = group.get(0);
557 if ((lit.dir == mem.dir) && (lit.chr == mem.chr) && (lit.grp.equals(mem.grp)) && (lit.per == mem.per) && (lit.hgt == mem.hgt)) {
558 group.add(lit);
559 found = true;
560 }
561 }
562 if (!found) {
563 ArrayList<LitSect> tmp = new ArrayList<>();
564 tmp.add(lit);
565 groupings.add(tmp);
566 }
567 }
568 for (boolean moved = true; moved;) {
569 moved = false;
570 for (int i = 0; i < groupings.size() - 1; i++) {
571 if (groupings.get(i).size() < groupings.get(i + 1).size()) {
572 ArrayList<LitSect> tmp = groupings.remove(i);
573 groupings.add(i + 1, tmp);
574 moved = true;
575 }
576 }
577 }
578 class ColRng {
579 ColCOL col;
580 double rng;
581
582 ColRng(ColCOL c, double r) {
583 col = c;
584 rng = r;
585 }
586 }
587
588 int y = -30;
589 for (ArrayList<LitSect> group : groupings) {
590 ArrayList<ColRng> colrng = new ArrayList<>();
591 for (LitSect lit : group) {
592 boolean found = false;
593 for (ColRng cr : colrng) {
594 if (cr.col == lit.col) {
595 if (lit.rng > cr.rng) {
596 cr.rng = lit.rng;
597 }
598 found = true;
599 }
600 }
601 if (!found) {
602 colrng.add(new ColRng(lit.col, lit.rng));
603 }
604 }
605 for (boolean moved = true; moved;) {
606 moved = false;
607 for (int i = 0; i < colrng.size() - 1; i++) {
608 if (colrng.get(i).rng < colrng.get(i + 1).rng) {
609 ColRng tmp = colrng.remove(i);
610 colrng.add(i + 1, tmp);
611 moved = true;
612 }
613 }
614 }
615 LitSect tmp = group.get(0);
616 str = (tmp.dir) ? "Dir" : "";
617 str += LightCharacters.get(tmp.chr);
618 if (!tmp.grp.isEmpty())
619 str += "(" + tmp.grp + ")";
620 else
621 str += ".";
622 for (ColRng cr : colrng) {
623 str += LightLetters.get(cr.col);
624 }
625 if ((tmp.per > 0) || (tmp.hgt > 0) || (colrng.get(0).rng > 0))
626 str += ".";
627 if (tmp.per > 0)
628 str += df.format(tmp.per) + "s";
629 if (tmp.hgt > 0)
630 str += df.format(tmp.hgt) + "m";
631 if (colrng.get(0).rng > 0)
632 str += df.format(colrng.get(0).rng) + ((colrng.size() > 1) ? ((colrng.size() > 2) ? ("-" + df.format(colrng.get(colrng.size() - 1).rng)) : ("/" + df.format(colrng.get(1).rng))) : "") + "M";
633 Renderer.labelText(str, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.TL, AffineTransform.getTranslateInstance(60, y)));
634 y += 40;
635 str = "";
636 }
637 }
638 } else {
639 if (Renderer.zoom >= 15) {
640 AttMap atts = lights.get(0);
641 ArrayList<CatLIT> cats = new ArrayList<>();
642 if (atts.containsKey(Att.CATLIT)) {
643 cats = (ArrayList<CatLIT>) atts.get(Att.CATLIT).val;
644 }
645 str = (cats.contains(CatLIT.LIT_DIR)) ? "Dir" : "";
646 str += (atts.containsKey(Att.MLTYLT)) ? atts.get(Att.MLTYLT).val : "";
647 if (atts.containsKey(Att.LITCHR)) {
648 LitCHR chr = ((ArrayList<LitCHR>) atts.get(Att.LITCHR).val).get(0);
649 if (atts.containsKey(Att.SIGGRP)) {
650 String grp = (String) atts.get(Att.SIGGRP).val;
651 switch (chr) {
652 case CHR_QLFL:
653 str += String.format("Q(%s)+LFl", grp);
654 break;
655 case CHR_VQLFL:
656 str += String.format("VQ(%s)+LFl", grp);
657 break;
658 case CHR_UQLFL:
659 str += String.format("UQ(%s)+LFl", grp);
660 break;
661 default:
662 str += String.format("%s(%s)", LightCharacters.get(chr), grp);
663 break;
664 }
665 } else {
666 str += LightCharacters.get(chr);
667 }
668 }
669 if (atts.containsKey(Att.COLOUR)) {
670 ArrayList<ColCOL> cols = (ArrayList<ColCOL>) atts.get(Att.COLOUR).val;
671 if (!((cols.size() == 1) && (cols.get(0) == ColCOL.COL_WHT))) {
672 if (!str.isEmpty() && !str.endsWith(")")) {
673 str += ".";
674 }
675 for (ColCOL acol : cols) {
676 str += LightLetters.get(acol);
677 }
678 }
679 }
680 str += (cats.contains(CatLIT.LIT_VERT)) ? "(vert)" : "";
681 str += (cats.contains(CatLIT.LIT_HORI)) ? "(hor)" : "";
682 str += (!str.isEmpty() && (atts.containsKey(Att.SIGPER) || atts.containsKey(Att.HEIGHT) || atts.containsKey(Att.VALMXR)) && !str.endsWith(")")) ? "." : "";
683 str += (atts.containsKey(Att.SIGPER)) ? df.format(atts.get(Att.SIGPER).val) + "s" : "";
684 str += (atts.containsKey(Att.HEIGHT)) ? df.format(atts.get(Att.HEIGHT).val) + "m" : "";
685 str += (atts.containsKey(Att.VALNMR)) ? df.format(atts.get(Att.VALNMR).val) + "M" : "";
686 str += (cats.contains(CatLIT.LIT_FRNT)) ? "(Front)" : "";
687 str += (cats.contains(CatLIT.LIT_REAR)) ? "(Rear)" : "";
688 str += (cats.contains(CatLIT.LIT_UPPR)) ? "(Upper)" : "";
689 str += (cats.contains(CatLIT.LIT_LOWR)) ? "(Lower)" : "";
690 Renderer.labelText(str, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.TL, AffineTransform.getTranslateInstance(60, -30)));
691 }
692 }
693 }
694 }
695}
Note: See TracBrowser for help on using the repository browser.