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

Last change on this file since 31846 was 31722, checked in by malcolmh, 9 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 @SuppressWarnings("unchecked")
170 public static void radioStations(Feature feature) {
171 Renderer.symbol(feature, Beacons.RadarStation);
172 ArrayList<CatROS> cats = (ArrayList<CatROS>)Rules.getAttList(feature, Obj.RDOSTA, 0, Att.CATROS);
173 boolean vais = false;
174 String bstr = "";
175 for (CatROS ros : cats) {
176 switch (ros) {
177 case ROS_OMNI:
178 bstr += " RC";
179 break;
180 case ROS_DIRL:
181 bstr += " RD";
182 break;
183 case ROS_ROTP:
184 bstr += " RW";
185 break;
186 case ROS_CNSL:
187 bstr += " Consol";
188 break;
189 case ROS_RDF:
190 bstr += " RG";
191 break;
192 case ROS_QTA:
193 bstr += " R";
194 break;
195 case ROS_AERO:
196 bstr += " AeroRC";
197 break;
198 case ROS_DECA:
199 bstr += " Decca";
200 break;
201 case ROS_LORN:
202 bstr += " Loran";
203 break;
204 case ROS_DGPS:
205 bstr += " DGPS";
206 break;
207 case ROS_TORN:
208 bstr += " Toran";
209 break;
210 case ROS_OMGA:
211 bstr += " Omega";
212 break;
213 case ROS_SYLD:
214 bstr += " Syledis";
215 break;
216 case ROS_CHKA:
217 bstr += " Chiaka";
218 break;
219 case ROS_PCOM:
220 case ROS_COMB:
221 case ROS_FACS:
222 case ROS_TIME:
223 break;
224 case ROS_PAIS:
225 case ROS_SAIS:
226 bstr += " AIS";
227 break;
228 case ROS_VAIS:
229 vais = true;
230 break;
231 case ROS_VANC:
232 vais = true;
233 Renderer.symbol(feature, Topmarks.TopNorth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
234 break;
235 case ROS_VASC:
236 vais = true;
237 Renderer.symbol(feature, Topmarks.TopSouth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
238 break;
239 case ROS_VAEC:
240 vais = true;
241 Renderer.symbol(feature, Topmarks.TopEast, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
242 break;
243 case ROS_VAWC:
244 vais = true;
245 Renderer.symbol(feature, Topmarks.TopWest, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
246 break;
247 case ROS_VAPL:
248 vais = true;
249 Renderer.symbol(feature, Topmarks.TopCan, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
250 break;
251 case ROS_VASL:
252 vais = true;
253 Renderer.symbol(feature, Topmarks.TopCone, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
254 break;
255 case ROS_VAID:
256 vais = true;
257 Renderer.symbol(feature, Topmarks.TopIsol, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
258 break;
259 case ROS_VASW:
260 vais = true;
261 Renderer.symbol(feature, Topmarks.TopSphere, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
262 break;
263 case ROS_VASP:
264 vais = true;
265 Renderer.symbol(feature, Topmarks.TopX, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
266 break;
267 case ROS_VAWK:
268 vais = true;
269 Renderer.symbol(feature, Topmarks.TopCross, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
270 break;
271 default:
272 break;
273 }
274 }
275 if (Renderer.zoom >= 15) {
276 if (vais) {
277 Renderer.labelText(feature, "V-AIS", new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 70)));
278 }
279 if (!bstr.isEmpty()) {
280 Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40), Symbols.Msymb, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-30, -110)));
281 }
282 }
283 }
284
285 public static void lights(Feature feature) {
286/* Enum<ColCOL> col = null;
287 Enum<ColCOL> tcol = null;
288 ObjTab lights = feature.objs.get(Obj.LIGHTS);
289 for (AttMap atts : lights.values()) {
290 if (atts.containsKey(Att.COLOUR)) {
291 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
292 if (cols.size() == 1) {
293 tcol = cols.get(0);
294 if (col == null) {
295 col = tcol;
296 } else if (tcol != col) {
297 col = ColCOL.COL_MAG;
298 break;
299 }
300 } else {
301 col = ColCOL.COL_MAG;
302 break;
303 }
304 }
305 }
306 Renderer.symbol(feature, Beacons.LightFlare, new Scheme(lightColours.get(col)), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.toRadians(120))));
307 if (lights.get(1) != null) {
308 for (AttMap atts : lights.values()) {
309 Enum<ColCOL> col1 = null;
310 Enum<ColCOL> col2 = null;
311 double radius = 0.2;
312 double s1 = 0;
313 double s2 = 0;
314 boolean dir = false;
315 if (atts.containsKey(Att.COLOUR)) {
316 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
317 col1 = cols.get(0);
318 if (cols.size() > 1) col2 = cols.get(1);
319 } else {
320 continue;
321 }
322 if (atts.containsKey(Att.RADIUS)) {
323 radius = (Double) atts.get(Att.RADIUS).val;
324 }
325 if (atts.containsKey(Att.SECTR1)) {
326 s1 = (Double) atts.get(Att.SECTR1).val;
327 } else {
328 continue;
329 }
330 if (atts.containsKey(Att.SECTR2)) {
331 s2 = (Double) atts.get(Att.SECTR2).val;
332 } else {
333 continue;
334 }
335 if (atts.containsKey(Att.CATLIT)) {
336 ArrayList<CatLIT> cats = (ArrayList<CatLIT>) atts.get(Att.CATLIT).val;
337 if (cats.contains(CatLIT.LIT_DIR)) {
338 dir = true;
339 }
340 }
341 String str = "";
342 if (atts.containsKey(Att.LITCHR)) {
343 str += lightCharacters.get(atts.get(Att.LITCHR).val);
344 }
345 if (atts.containsKey(Att.SIGGRP)) {
346 str += "(" + atts.get(Att.SIGGRP).val + ")";
347 } else if (!str.isEmpty()) {
348 str += ".";
349 }
350 if (atts.containsKey(Att.COLOUR)) {
351 ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
352 str += lightLetters.get(cols.get(0));
353 if (cols.size() > 1)
354 str += lightLetters.get(cols.get(1));
355 }
356 if (dir && atts.containsKey(Att.ORIENT)) {
357 double orient = (Double)atts.get(Att.ORIENT).val;
358 str += " " + orient + "°";
359 s1 = (orient - 4 + 360) % 360;
360 s2 = (orient + 4) % 360;
361 double n1 = 360;
362 double n2 = 360;
363 for (AttMap sect : lights.values()) {
364 if (sect != atts) {
365
366 }
367 }
368 }
369 Renderer.lightSector(feature, lightColours.get(col1), lightColours.get(col2), radius, s1, s2, dir, str);
370 }
371 }
372 final Att matches[] = { Att.SIGPER, Att.SIGGRP, Att.MLTYLT, Att.LITCHR, Att.CATLIT, Att.HEIGHT };
373 ArrayList<ArrayList<AttMap>> groups = new ArrayList<ArrayList<AttMap>>();
374 for (AttMap sector : lights.values()) {
375 if (sector.containsKey(Att.COLOUR)) {
376 boolean equal = false;
377 for (ArrayList<AttMap> group : groups) {
378 AttMap member = group.get(0);
379 for (Att match : matches) {
380 if (!((sector.containsKey(match) && member.containsKey(match) && sector.get(match).val.equals(member.get(match).val)) || (!sector.containsKey(match) && !member.containsKey(match)))) {
381 equal = false;
382 break;
383 } else {
384 equal = true;
385 }
386 }
387 if (equal) {
388 group.add(sector);
389 break;
390 }
391 }
392 if (!equal) {
393 ArrayList<AttMap> group = new ArrayList<AttMap>();
394 group.add(sector);
395 groups.add(group);
396 }
397 }
398 }
399 for (boolean sorted = false; !sorted;) {
400 sorted = true;
401 for (int i = 0; i < groups.size()-1; i ++) {
402 if (groups.get(i).size() < groups.get(i+1).size()) {
403 ArrayList<AttMap> tmp = groups.remove(i);
404 groups.add(i+1, tmp);
405 sorted = false;
406 }
407 }
408 }
409 for (ArrayList<AttMap> group : groups) {
410 for (boolean sorted = false; !sorted;) {
411 sorted = true;
412 for (int i = 0; i < group.size()-1; i ++) {
413 AttMap m0 = group.get(i);
414 AttMap m1 = group.get(i+1);
415 if (((m0.containsKey(Att.VALNMR) && m1.containsKey(Att.VALNMR) && ((int)(m0.get(Att.VALNMR).val) < (int)(m1.get(Att.VALNMR).val))))
416 || (!m0.containsKey(Att.VALNMR) && m1.containsKey(Att.VALNMR))) {
417 AttMap tmp = group.remove(i);
418 group.add(i+1, tmp);
419 sorted = false;
420 }
421 }
422 }
423 }
424*/ }
425
426}
Note: See TracBrowser for help on using the repository browser.