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

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

[SeaChart] Fix floats

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