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 |
|
---|
10 | package render;
|
---|
11 |
|
---|
12 | import java.awt.Color;
|
---|
13 | import java.awt.Font;
|
---|
14 | import java.awt.geom.*;
|
---|
15 | import java.util.ArrayList;
|
---|
16 |
|
---|
17 | import s57.S57att.*;
|
---|
18 | import s57.S57obj.*;
|
---|
19 | import s57.S57val.*;
|
---|
20 | import s57.S57map.*;
|
---|
21 | import symbols.Beacons;
|
---|
22 | import symbols.Topmarks;
|
---|
23 | import symbols.Symbols.*;
|
---|
24 |
|
---|
25 | public class Signals {
|
---|
26 |
|
---|
27 | public static void addSignals(Feature feature) {
|
---|
28 | if (feature.objs.containsKey(Obj.FOGSIG)) fogSignals(feature);
|
---|
29 | if (feature.objs.containsKey(Obj.RTPBCN)) radarStations(feature);
|
---|
30 | if (feature.objs.containsKey(Obj.RADSTA)) radarStations(feature);
|
---|
31 | if (feature.objs.containsKey(Obj.RDOSTA)) radioStations(feature);
|
---|
32 | if (feature.objs.containsKey(Obj.LIGHTS)) lights(feature);
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static void fogSignals(Feature feature) {
|
---|
36 |
|
---|
37 | }
|
---|
38 |
|
---|
39 | public static void radarStations(Feature feature) {
|
---|
40 | Renderer.symbol(feature, Beacons.RadarStation);
|
---|
41 | String bstr = "";
|
---|
42 | CatRTB cat = (CatRTB) Rules.getAttVal(feature, Obj.RTPBCN, 0, Att.CATRTB);
|
---|
43 | switch (cat) {
|
---|
44 | case RTB_RAMK:
|
---|
45 | bstr += " Ramark";
|
---|
46 | break;
|
---|
47 | case RTB_RACN:
|
---|
48 | bstr += " Racon";
|
---|
49 | String astr = (String) Rules.getAttVal(feature, Obj.RTPBCN, 0, Att.SIGGRP);
|
---|
50 | if (!astr.isEmpty()) {
|
---|
51 | bstr += "(" + astr + ")";
|
---|
52 | }
|
---|
53 | Double per = (Double) Rules.getAttVal(feature, Obj.RTPBCN, 0, Att.SIGPER);
|
---|
54 | Double mxr = (Double) Rules.getAttVal(feature, Obj.RTPBCN, 0, Att.VALMXR);
|
---|
55 | if ((per != 0) || (mxr != 0)) {
|
---|
56 | bstr += (astr.isEmpty() ? " " : "");
|
---|
57 | bstr += (per != 0) ? per.toString() + "s" : "";
|
---|
58 | bstr += (mxr != 0) ? mxr.toString() + "M" : "";
|
---|
59 | }
|
---|
60 | break;
|
---|
61 | default:
|
---|
62 | break;
|
---|
63 | }
|
---|
64 | if ((Renderer.zoom >= 15) && !bstr.isEmpty()) {
|
---|
65 | Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40),Color.black, new Delta(Handle.BR, AffineTransform.getTranslateInstance(-30, -30)));
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | public static void radioStations(Feature feature) {
|
---|
70 | Renderer.symbol(feature, Beacons.RadarStation);
|
---|
71 | ArrayList<CatROS> cats = (ArrayList<CatROS>)Rules.getAttVal(feature, Obj.RDOSTA, 0, Att.CATROS);
|
---|
72 | boolean vais = false;
|
---|
73 | String bstr = "";
|
---|
74 | for (CatROS ros : cats) {
|
---|
75 | switch (ros) {
|
---|
76 | case ROS_OMNI:
|
---|
77 | bstr += " RC";
|
---|
78 | break;
|
---|
79 | case ROS_DIRL:
|
---|
80 | bstr += " RD";
|
---|
81 | break;
|
---|
82 | case ROS_ROTP:
|
---|
83 | bstr += " RW";
|
---|
84 | break;
|
---|
85 | case ROS_CNSL:
|
---|
86 | bstr += " Consol";
|
---|
87 | break;
|
---|
88 | case ROS_RDF:
|
---|
89 | bstr += " RG";
|
---|
90 | break;
|
---|
91 | case ROS_QTA:
|
---|
92 | bstr += " R";
|
---|
93 | break;
|
---|
94 | case ROS_AERO:
|
---|
95 | bstr += " AeroRC";
|
---|
96 | break;
|
---|
97 | case ROS_DECA:
|
---|
98 | bstr += " Decca";
|
---|
99 | break;
|
---|
100 | case ROS_LORN:
|
---|
101 | bstr += " Loran";
|
---|
102 | break;
|
---|
103 | case ROS_DGPS:
|
---|
104 | bstr += " DGPS";
|
---|
105 | break;
|
---|
106 | case ROS_TORN:
|
---|
107 | bstr += " Toran";
|
---|
108 | break;
|
---|
109 | case ROS_OMGA:
|
---|
110 | bstr += " Omega";
|
---|
111 | break;
|
---|
112 | case ROS_SYLD:
|
---|
113 | bstr += " Syledis";
|
---|
114 | break;
|
---|
115 | case ROS_CHKA:
|
---|
116 | bstr += " Chiaka";
|
---|
117 | break;
|
---|
118 | case ROS_PCOM:
|
---|
119 | case ROS_COMB:
|
---|
120 | case ROS_FACS:
|
---|
121 | case ROS_TIME:
|
---|
122 | break;
|
---|
123 | case ROS_PAIS:
|
---|
124 | case ROS_SAIS:
|
---|
125 | bstr += " AIS";
|
---|
126 | break;
|
---|
127 | case ROS_VAIS:
|
---|
128 | vais = true;
|
---|
129 | break;
|
---|
130 | case ROS_VANC:
|
---|
131 | vais = true;
|
---|
132 | Renderer.symbol(feature, Topmarks.TopNorth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
133 | break;
|
---|
134 | case ROS_VASC:
|
---|
135 | vais = true;
|
---|
136 | Renderer.symbol(feature, Topmarks.TopSouth, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
137 | break;
|
---|
138 | case ROS_VAEC:
|
---|
139 | vais = true;
|
---|
140 | Renderer.symbol(feature, Topmarks.TopEast, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
141 | break;
|
---|
142 | case ROS_VAWC:
|
---|
143 | vais = true;
|
---|
144 | Renderer.symbol(feature, Topmarks.TopWest, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
145 | break;
|
---|
146 | case ROS_VAPL:
|
---|
147 | vais = true;
|
---|
148 | Renderer.symbol(feature, Topmarks.TopCan, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
149 | break;
|
---|
150 | case ROS_VASL:
|
---|
151 | vais = true;
|
---|
152 | Renderer.symbol(feature, Topmarks.TopCone, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
153 | break;
|
---|
154 | case ROS_VAID:
|
---|
155 | vais = true;
|
---|
156 | Renderer.symbol(feature, Topmarks.TopIsol, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
157 | break;
|
---|
158 | case ROS_VASW:
|
---|
159 | vais = true;
|
---|
160 | Renderer.symbol(feature, Topmarks.TopSphere, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
161 | break;
|
---|
162 | case ROS_VASP:
|
---|
163 | vais = true;
|
---|
164 | Renderer.symbol(feature, Topmarks.TopX, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
165 | break;
|
---|
166 | case ROS_VAWK:
|
---|
167 | vais = true;
|
---|
168 | Renderer.symbol(feature, Topmarks.TopCross, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -25)));
|
---|
169 | break;
|
---|
170 | default:
|
---|
171 | break;
|
---|
172 | }
|
---|
173 | }
|
---|
174 | if (Renderer.zoom >= 15) {
|
---|
175 | if (vais) {
|
---|
176 | Renderer.labelText(feature, "V-AIS", new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, 70)));
|
---|
177 | }
|
---|
178 | if (!bstr.isEmpty()) {
|
---|
179 | Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BR, AffineTransform.getTranslateInstance(-30, -70)));
|
---|
180 | }
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | public static void lights(Feature feature) {
|
---|
185 |
|
---|
186 | }
|
---|
187 |
|
---|
188 | private static Point2D.Double radial(Snode centre, double radius, double angle) {
|
---|
189 | Point2D origin = Renderer.context.getPoint(centre);
|
---|
190 | double mile = Renderer.context.getPoint(Renderer.map.new Snode((centre.lat + Math.toRadians(1/60)), centre.lon)).getY() - origin.getY();
|
---|
191 | return new Point2D.Double(origin.getX() - (radius * mile * Math.sin(angle)), origin.getY() - (radius * mile * Math.cos(angle)));
|
---|
192 | }
|
---|
193 | /*
|
---|
194 | void renderFlare(Item_t *item) {
|
---|
195 | char *col = light_colours[COL_MAG];
|
---|
196 | Obj_t *obj = getObj(item, LIGHTS, 0);
|
---|
197 | Att_t *att;
|
---|
198 | if (((att = getAtt(obj, COLOUR)) != NULL) && (att->val.val.l->next == NULL)) {
|
---|
199 | col = light_colours[att->val.val.l->val];
|
---|
200 | }
|
---|
201 | renderSymbol(item, LIGHTS, "light", "", col, CC, 0, 0, 120);
|
---|
202 | }
|
---|
203 |
|
---|
204 | void renderSector(Item_t *item, int s, char *text, char *style, double offset, int dy) {
|
---|
205 | Obj_t *sector;
|
---|
206 | double start, end;
|
---|
207 | Att_t *att;
|
---|
208 | XY_t p0, p1;
|
---|
209 | double r0, r1;
|
---|
210 | double b0, b1, span;
|
---|
211 | char *col;
|
---|
212 | XY_t pos = findCentroid(item);
|
---|
213 | if ((sector = getObj(item, LIGHTS, s)) != NULL) {
|
---|
214 | strcpy(string1, (att = getAtt(sector, LITRAD)) != NULL ? att->val.val.a : "0.2");
|
---|
215 | if (((att = getAtt(sector, CATLIT)) != NULL) && (testAtt(att, LIT_DIR)) && ((att = getAtt(sector, ORIENT)) != NULL)) {
|
---|
216 | b0 = fmod(540.0 - att->val.val.f, 360.0);
|
---|
217 | if ((att = getAtt(sector, COLOUR)) != NULL) {
|
---|
218 | col = light_colours[att->val.val.l->val];
|
---|
219 | r0 = atof(string1);
|
---|
220 | p0 = radial(pos, r0, b0);
|
---|
221 | printf("<path d=\"M %g,%g L %g,%g\" style=\"fill:none;stroke:#808080;stroke-width:%g;stroke-dasharray:%g\"/>\n",
|
---|
222 | pos.x, pos.y, p0.x, p0.y, (4 * symbolScale[zoom]), (20 * symbolScale[zoom]));
|
---|
223 | start = fmod(b0 + 2.0, 360.0);
|
---|
224 | end = fmod(360.0 + b0 - 2.0, 360.0);
|
---|
225 | Obj_t *adj;
|
---|
226 | for (int i = s-1; i <= s+1; i++) {
|
---|
227 | if (i == s) continue;
|
---|
228 | if ((adj = getObj(item, LIGHTS, i)) == NULL) continue;
|
---|
229 | Att_t *att;
|
---|
230 | if (((att = getAtt(adj, CATLIT)) != NULL) && (testAtt(att, LIT_DIR)) && ((att = getAtt(adj, ORIENT)) != NULL)) {
|
---|
231 | b1 = fmod(540.0 - att->val.val.f, 360.0);
|
---|
232 | if (fabs(b0 - b1) > 180.0) {
|
---|
233 | if (b0 < b1) b0 += 360.0;
|
---|
234 | else b1 += 360.0;
|
---|
235 | }
|
---|
236 | if (fabs(b0 - b1) < 4.0) {
|
---|
237 | if (b1 > b0) start = fmod((720.0 + b0 + b1) / 2.0, 360.0);
|
---|
238 | else end = fmod((720.0 + b0 + b1) / 2.0, 360.0);
|
---|
239 | }
|
---|
240 | }
|
---|
241 | }
|
---|
242 | p0 = radial(pos, r0, start);
|
---|
243 | p1 = radial(pos, r0, end);
|
---|
244 | printf("<path id=\"%d\" d=\"M %g,%g A %g,%g,0,0,1,%g,%g\" style=\"fill:none;stroke:%s;stroke-width:%g\"/>\n",
|
---|
245 | ++ref, p0.x, p0.y, r0*mile, r0*mile, p1.x, p1.y, col, (20 * symbolScale[zoom]));
|
---|
246 | if (att->val.val.l->next != NULL) {
|
---|
247 | char *col = light_colours[att->val.val.l->next->val];
|
---|
248 | r1 = r0 - (20 * symbolScale[zoom]/mile);
|
---|
249 | p0 = radial(pos, r1, start);
|
---|
250 | p1 = radial(pos, r1, end);
|
---|
251 | printf("<path d=\"M %g,%g A %g,%g,0,0,1,%g,%g\" style=\"fill:none;stroke:%s;stroke-width:%g\"/>\n",
|
---|
252 | p0.x, p0.y, r1*mile, r1*mile, p1.x, p1.y, col, (20 * symbolScale[zoom]));
|
---|
253 | }
|
---|
254 | }
|
---|
255 | } else if ((att = getAtt(sector, SECTR1)) != NULL) {
|
---|
256 | start = fmod(540.0 - att->val.val.f, 360.0);
|
---|
257 | if ((att = getAtt(sector, SECTR2)) != NULL) {
|
---|
258 | end = fmod(540.0 - att->val.val.f, 360.0);
|
---|
259 | start += start < end ? 360.0 : 0.0;
|
---|
260 | if ((att = getAtt(sector, COLOUR)) != NULL) {
|
---|
261 | char *ttok, *etok;
|
---|
262 | char *radstr = strdup(string1);
|
---|
263 | int arc = 0;
|
---|
264 | col = light_colours[att->val.val.l->val];
|
---|
265 | r0 = 0.0;
|
---|
266 | b0 = b1 = start;
|
---|
267 | for (char *tpl = strtok_r(radstr, ";", &ttok); tpl != NULL; tpl = strtok_r(NULL, ";", &ttok)) {
|
---|
268 | p0 = radial(pos, r0, b0);
|
---|
269 | span = 0.0;
|
---|
270 | char *ele = strtok_r(tpl, ":", &etok);
|
---|
271 | if ((*tpl == ':') && (r0 == 0.0)) {
|
---|
272 | r1 = 0.2;
|
---|
273 | } else if (*tpl != ':') {
|
---|
274 | r1 = atof(tpl);
|
---|
275 | ele = strtok_r(NULL, ":", &etok);
|
---|
276 | }
|
---|
277 | while (ele != NULL) {
|
---|
278 | if (isalpha(*ele)) {
|
---|
279 | if (strcmp(ele, "suppress") == 0) arc = 2;
|
---|
280 | else if (strcmp(ele, "dashed") == 0) arc = 1;
|
---|
281 | else arc = 0;
|
---|
282 | } else {
|
---|
283 | span = atof(ele);
|
---|
284 | }
|
---|
285 | ele = strtok_r(NULL, ":", &etok);
|
---|
286 | }
|
---|
287 | if (span == 0.0) {
|
---|
288 | char *back = (ttok != NULL) ? strstr(ttok, "-") : NULL;
|
---|
289 | if (back != NULL) {
|
---|
290 | span = b0 - end + atof(back);
|
---|
291 | } else {
|
---|
292 | span = b0 - end;
|
---|
293 | }
|
---|
294 | }
|
---|
295 | if (r1 != r0) {
|
---|
296 | p1 = radial(pos, r1, b0);
|
---|
297 | if (!((start == 180.0) && (end == 180.0)))
|
---|
298 | printf("<path d=\"M %g,%g L %g,%g\" style=\"fill:none;stroke:#808080;stroke-width:%g;stroke-dasharray:%g\"/>\n",
|
---|
299 | p0.x, p0.y, p1.x, p1.y, (4 * symbolScale[zoom]), (20 * symbolScale[zoom]));
|
---|
300 | r0 = r1;
|
---|
301 | p0 = p1;
|
---|
302 | }
|
---|
303 | if (span < 0.0) {
|
---|
304 | b1 = end - span;
|
---|
305 | b1 = b1 > b0 ? b0 : b1;
|
---|
306 | b0 = b1;
|
---|
307 | b1 = end;
|
---|
308 | p0 = radial(pos, r0, b0);
|
---|
309 | } else {
|
---|
310 | b1 = b0 - span;
|
---|
311 | b1 = b1 < end ? end : b1;
|
---|
312 | }
|
---|
313 | p1 = radial(pos, r1, b1);
|
---|
314 | if ((b0 == 180.0) && (b1 == 180.0)) {
|
---|
315 | span = 360.0;
|
---|
316 | p1 = radial(pos, r1, b1+0.01);
|
---|
317 | }
|
---|
318 | if (arc == 0) {
|
---|
319 | if (p0.x < p1.x)
|
---|
320 | printf("<path id=\"%d\" d=\"M %g,%g A %g,%g,0,%d,1,%g,%g\" style=\"fill:none;stroke:%s;stroke-width:%g\"/>\n",
|
---|
321 | ++ref, p0.x, p0.y, r1*mile, r1*mile, span>180.0, p1.x, p1.y, col, (20 * symbolScale[zoom]));
|
---|
322 | else
|
---|
323 | printf("<path id=\"%d\" d=\"M %g,%g A %g,%g,0,%d,0,%g,%g\" style=\"fill:none;stroke:%s;stroke-width:%g\"/>\n",
|
---|
324 | ++ref, p1.x, p1.y, r1*mile, r1*mile, span>180.0, p0.x, p0.y, col, (20 * symbolScale[zoom]));
|
---|
325 | if (text != NULL) {
|
---|
326 | double chord = sqrt(pow((p0.x - p1.x), 2) + pow((p0.y - p1.y), 2));
|
---|
327 | if ((chord > (strlen(text) * textScale[zoom] * 50)) || ((b0 == 180.0) && (b1 == 180.0)))
|
---|
328 | drawLineText(item, text, style, offset, dy, ref);
|
---|
329 | }
|
---|
330 | } else if (arc == 1) {
|
---|
331 | printf("<path d=\"M %g,%g A %g,%g,0,%d,1,%g,%g\" style=\"fill:none;stroke:%s;stroke-width:%g;stroke-opacity:0.5;stroke-dasharray:%g\"/>\n",
|
---|
332 | p0.x, p0.y, r1*mile, r1*mile, span>180.0, p1.x, p1.y, col, (10 * symbolScale[zoom]), (30 * symbolScale[zoom]));
|
---|
333 | }
|
---|
334 | if ((arc == 0) && (att->val.val.l->next != NULL)) {
|
---|
335 | char *col = light_colours[att->val.val.l->next->val];
|
---|
336 | double r2 = r1 - (20 * symbolScale[zoom]/mile);
|
---|
337 | XY_t p2 = radial(pos, r2, b0);
|
---|
338 | XY_t p3 = radial(pos, r2, b1);
|
---|
339 | printf("<path d=\"M %g,%g A %g,%g,0,%d,1,%g,%g\" style=\"fill:none;stroke:%s;stroke-width:%g\"/>\n",
|
---|
340 | p2.x, p2.y, r1*mile, r1*mile, span>180.0, p3.x, p3.y, col, (20 * symbolScale[zoom]));
|
---|
341 | }
|
---|
342 | b0 = b1;
|
---|
343 | if (b0 == end) break;
|
---|
344 | }
|
---|
345 | if (!((start == 180.0) && (end == 180.0)))
|
---|
346 | printf("<path d=\"M %g,%g L %g,%g\" style=\"fill:none;stroke:#808080;stroke-width:%g;stroke-dasharray:%g\"/>\n",
|
---|
347 | pos.x, pos.y, p1.x, p1.y, (4 * symbolScale[zoom]), (20 * symbolScale[zoom]));
|
---|
348 | free(radstr);
|
---|
349 | }
|
---|
350 | }
|
---|
351 | }
|
---|
352 | }
|
---|
353 | }
|
---|
354 | char *charString(Item_t *item, char *type, int idx) {
|
---|
355 | strcpy(string1, "");
|
---|
356 | Att_t *att = NULL;
|
---|
357 | Obj_t *obj = getObj(item, enumType(type), idx);
|
---|
358 | switch (enumType(type)) {
|
---|
359 | case CGUSTA:
|
---|
360 | strcpy(string1, "CG");
|
---|
361 | if ((obj != NULL) && (att = getAtt(obj, COMCHA)) != NULL)
|
---|
362 | sprintf(strchr(string1, 0), " Ch.%s", stringValue(att->val));
|
---|
363 | break;
|
---|
364 | case FOGSIG:
|
---|
365 | if (obj != NULL) {
|
---|
366 | if ((att = getAtt(obj, CATFOG)) != NULL)
|
---|
367 | strcat(string1, fog_signals[att->val.val.e]);
|
---|
368 | if ((att = getAtt(obj, SIGGRP)) != NULL)
|
---|
369 | sprintf(strchr(string1, 0), "(%s)", stringValue(att->val));
|
---|
370 | else
|
---|
371 | strcat(string1, " ");
|
---|
372 | if ((att = getAtt(obj, SIGPER)) != NULL)
|
---|
373 | sprintf(strchr(string1, 0), "%ss ", stringValue(att->val));
|
---|
374 | if ((att = getAtt(obj, VALMXR)) != NULL)
|
---|
375 | sprintf(strchr(string1, 0), "%sM", stringValue(att->val));
|
---|
376 | }
|
---|
377 | break;
|
---|
378 | case SISTAT:
|
---|
379 | strcpy(string1, "SS");
|
---|
380 | if (obj != NULL) {
|
---|
381 | if ((att = getAtt(obj, CATSIT)) != NULL)
|
---|
382 | strcat(string1, sit_map[att->val.val.l->val]);
|
---|
383 | if ((att = getAtt(obj, COMCHA)) != NULL)
|
---|
384 | sprintf(strchr(string1, 0), "\nCh.%s", stringValue(att->val));
|
---|
385 | }
|
---|
386 | break;
|
---|
387 | case SISTAW:
|
---|
388 | strcpy(string1, "SS");
|
---|
389 | if (obj != NULL) {
|
---|
390 | if ((att = getAtt(obj, CATSIW)) != NULL)
|
---|
391 | strcat(string1, siw_map[att->val.val.l->val]);
|
---|
392 | if ((att = getAtt(obj, COMCHA)) != NULL)
|
---|
393 | sprintf(strchr(string1, 0), "\nCh.%s", stringValue(att->val));
|
---|
394 | }
|
---|
395 | break;
|
---|
396 | case LIGHTS:
|
---|
397 | {
|
---|
398 | int secmax = countObjects(item, "light");
|
---|
399 | if ((idx == 0) && (secmax > 0)) {
|
---|
400 | struct SECT {
|
---|
401 | struct SECT *next;
|
---|
402 | int dir;
|
---|
403 | LitCHR_t chr;
|
---|
404 | ColCOL_t col;
|
---|
405 | ColCOL_t alt;
|
---|
406 | char *grp;
|
---|
407 | double per;
|
---|
408 | double rng;
|
---|
409 | } *lights = NULL;
|
---|
410 | for (int i = secmax; i > 0; i--) {
|
---|
411 | struct SECT *tmp = calloc(1, sizeof(struct SECT));
|
---|
412 | tmp->next = lights;
|
---|
413 | lights = tmp;
|
---|
414 | obj = getObj(item, LIGHTS, i);
|
---|
415 | if ((att = getAtt(obj, CATLIT)) != NULL) {
|
---|
416 | lights->dir = testAtt(att, LIT_DIR);
|
---|
417 | }
|
---|
418 | if ((att = getAtt(obj, LITCHR)) != NULL) {
|
---|
419 | lights->chr = att->val.val.e;
|
---|
420 | switch (lights->chr) {
|
---|
421 | case CHR_AL:
|
---|
422 | lights->chr = CHR_F;
|
---|
423 | break;
|
---|
424 | case CHR_ALOC:
|
---|
425 | lights->chr = CHR_OC;
|
---|
426 | break;
|
---|
427 | case CHR_ALLFL:
|
---|
428 | lights->chr = CHR_LFL;
|
---|
429 | break;
|
---|
430 | case CHR_ALFL:
|
---|
431 | lights->chr = CHR_FL;
|
---|
432 | break;
|
---|
433 | case CHR_ALFFL:
|
---|
434 | lights->chr = CHR_FFL;
|
---|
435 | break;
|
---|
436 | default:
|
---|
437 | break;
|
---|
438 | }
|
---|
439 | }
|
---|
440 | if ((att = getAtt(obj, SIGGRP)) != NULL) {
|
---|
441 | lights->grp = att->val.val.a;
|
---|
442 | } else {
|
---|
443 | lights->grp = "";
|
---|
444 | }
|
---|
445 | if ((att = getAtt(obj, SIGPER)) != NULL) {
|
---|
446 | lights->per = att->val.val.f;
|
---|
447 | }
|
---|
448 | if ((att = getAtt(obj, VALNMR)) != NULL) {
|
---|
449 | lights->rng = att->val.val.f;
|
---|
450 | }
|
---|
451 | if ((att = getAtt(obj, COLOUR)) != NULL) {
|
---|
452 | lights->col = att->val.val.l->val;
|
---|
453 | if (att->val.val.l->next != NULL)
|
---|
454 | lights->alt = att->val.val.l->next->val;
|
---|
455 | }
|
---|
456 | }
|
---|
457 | struct COLRNG {
|
---|
458 | int col;
|
---|
459 | double rng;
|
---|
460 | } colrng[14];
|
---|
461 | while (lights != NULL) {
|
---|
462 | strcpy(string2, "");
|
---|
463 | bzero(colrng, 14*sizeof(struct COLRNG));
|
---|
464 | colrng[lights->col].col = 1;
|
---|
465 | colrng[lights->col].rng = lights->rng;
|
---|
466 | struct SECT *this = lights;
|
---|
467 | struct SECT *next = lights->next;
|
---|
468 | while (next != NULL) {
|
---|
469 | if ((this->dir == next->dir) && (this->chr == next->chr) &&
|
---|
470 | (strcmp(this->grp, next->grp) == 0) && (this->per == next->per)) {
|
---|
471 | colrng[next->col].col = 1;
|
---|
472 | if (next->rng > colrng[next->col].rng)
|
---|
473 | colrng[next->col].rng = next->rng;
|
---|
474 | struct SECT *tmp = lights;
|
---|
475 | while (tmp->next != next) tmp = tmp->next;
|
---|
476 | tmp->next = next->next;
|
---|
477 | free(next);
|
---|
478 | next = tmp->next;
|
---|
479 | } else {
|
---|
480 | next = next->next;
|
---|
481 | }
|
---|
482 | }
|
---|
483 | if (this->chr != CHR_UNKN) {
|
---|
484 | if (this->dir) strcpy(string2, "Dir.");
|
---|
485 | strcat(string2, light_characters[this->chr]);
|
---|
486 | if (strcmp(this->grp, "") != 0) {
|
---|
487 | if (this->grp[0] == '(')
|
---|
488 | sprintf(strchr(string2, 0), "%s", this->grp);
|
---|
489 | else
|
---|
490 | sprintf(strchr(string2, 0), "(%s)", this->grp);
|
---|
491 | } else {
|
---|
492 | if (strlen(string2) > 0) strcat(string2, ".");
|
---|
493 | }
|
---|
494 | int n = 0;
|
---|
495 | for (int i = 0; i < 14; i++) if (colrng[i].col) n++;
|
---|
496 | double max = 0.0;
|
---|
497 | for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng > max)) max = colrng[i].rng;
|
---|
498 | double min = max;
|
---|
499 | for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng > 0.0) && (colrng[i].rng < min)) min = colrng[i].rng;
|
---|
500 | if (min == max) {
|
---|
501 | for (int i = 0; i < 14; i++) if (colrng[i].col) strcat(string2, light_letters[i]);
|
---|
502 | } else {
|
---|
503 | for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng == max)) strcat(string2, light_letters[i]);
|
---|
504 | for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng < max) && (colrng[i].rng > min)) strcat(string2, light_letters[i]);
|
---|
505 | for (int i = 0; i < 14; i++) if (colrng[i].col && colrng[i].rng == min) strcat(string2, light_letters[i]);
|
---|
506 | }
|
---|
507 | strcat(string2, ".");
|
---|
508 | if (this->per > 0.0) sprintf(strchr(string2, 0), "%gs", this->per);
|
---|
509 | if (max > 0.0) {
|
---|
510 | sprintf(strchr(string2, 0), "%g", max);
|
---|
511 | if (min != max) {
|
---|
512 | if (n == 2) strcat(string2, "/");
|
---|
513 | else if (n > 2) strcat(string2, "-");
|
---|
514 | if (min < max) sprintf(strchr(string2, 0), "%g", min);
|
---|
515 | }
|
---|
516 | strcat(string2, "M");
|
---|
517 | }
|
---|
518 | if (strlen(string1) > 0) strcat(string1, "\n");
|
---|
519 | strcat(string1, string2);
|
---|
520 | }
|
---|
521 | lights = this->next;
|
---|
522 | free(this);
|
---|
523 | this = lights;
|
---|
524 | }
|
---|
525 | } else {
|
---|
526 | if ((att = getAtt(obj, CATLIT)) != NULL) {
|
---|
527 | if (testAtt(att, LIT_DIR))
|
---|
528 | strcat(string1, "Dir");
|
---|
529 | }
|
---|
530 | if ((att = getAtt(obj, MLTYLT)) != NULL)
|
---|
531 | sprintf(strchr(string1, 0), "%s", stringValue(att->val));
|
---|
532 | if ((att = getAtt(obj, LITCHR)) != NULL) {
|
---|
533 | char *chrstr = strdup(stringValue(att->val));
|
---|
534 | Att_t *grp = getAtt(obj, SIGGRP);
|
---|
535 | if (grp != NULL) {
|
---|
536 | char *strgrp = strdup(stringValue(grp->val));
|
---|
537 | char *grpstr = strtok(strgrp, "()");
|
---|
538 | switch (att->val.val.e) {
|
---|
539 | case CHR_QLFL:
|
---|
540 | sprintf(strchr(string1, 0), "Q(%s)+LFl", grpstr);
|
---|
541 | break;
|
---|
542 | case CHR_VQLFL:
|
---|
543 | sprintf(strchr(string1, 0), "VQ(%s)+LFl", grpstr);
|
---|
544 | break;
|
---|
545 | case CHR_UQLFL:
|
---|
546 | sprintf(strchr(string1, 0), "UQ(%s)+LFl", grpstr);
|
---|
547 | break;
|
---|
548 | default:
|
---|
549 | sprintf(strchr(string1, 0), "%s(%s)", chrstr, grpstr);
|
---|
550 | break;
|
---|
551 | }
|
---|
552 | free(strgrp);
|
---|
553 | } else {
|
---|
554 | sprintf(strchr(string1, 0), "%s", chrstr);
|
---|
555 | }
|
---|
556 | free(chrstr);
|
---|
557 | }
|
---|
558 | if ((att = getAtt(obj, COLOUR)) != NULL) {
|
---|
559 | int n = countValues(att);
|
---|
560 | if (!((n == 1) && (idx == 0) && (testAtt(att, COL_WHT)))) {
|
---|
561 | if ((strlen(string1) > 0) && ((string1[strlen(string1)-1] != ')')))
|
---|
562 | strcat(string1, ".");
|
---|
563 | Lst_t *lst = att->val.val.l;
|
---|
564 | while (lst != NULL) {
|
---|
565 | strcat(string1, light_letters[lst->val]);
|
---|
566 | lst = lst->next;
|
---|
567 | }
|
---|
568 | }
|
---|
569 | }
|
---|
570 | if ((idx == 0) && (att = getAtt(obj, CATLIT)) != NULL) {
|
---|
571 | if (testAtt(att, LIT_VERT))
|
---|
572 | strcat(string1, "(vert)");
|
---|
573 | if (testAtt(att, LIT_HORI))
|
---|
574 | strcat(string1, "(hor)");
|
---|
575 | }
|
---|
576 | if ((strlen(string1) > 0) &&
|
---|
577 | ((getAtt(obj, SIGPER) != NULL) ||
|
---|
578 | (getAtt(obj, HEIGHT) != NULL) ||
|
---|
579 | (getAtt(obj, VALMXR) != NULL)) &&
|
---|
580 | (string1[strlen(string1)-1] != ')'))
|
---|
581 | strcat(string1, ".");
|
---|
582 | if ((att = getAtt(obj, SIGPER)) != NULL)
|
---|
583 | sprintf(strchr(string1, 0), "%ss", stringValue(att->val));
|
---|
584 | if ((idx == 0) && (item->objs.obj != LITMIN)) {
|
---|
585 | if ((att = getAtt(obj, HEIGHT)) != NULL)
|
---|
586 | sprintf(strchr(string1, 0), "%sm", stringValue(att->val));
|
---|
587 | if ((att = getAtt(obj, VALNMR)) != NULL)
|
---|
588 | sprintf(strchr(string1, 0), "%sM", stringValue(att->val));
|
---|
589 | }
|
---|
590 | if ((idx == 0) && (att = getAtt(obj, CATLIT)) != NULL) {
|
---|
591 | if (testAtt(att, LIT_FRNT))
|
---|
592 | strcat(string1, "(Front)");
|
---|
593 | if (testAtt(att, LIT_REAR))
|
---|
594 | strcat(string1, "(Rear)");
|
---|
595 | if (testAtt(att, LIT_UPPR))
|
---|
596 | strcat(string1, "(Upper)");
|
---|
597 | if (testAtt(att, LIT_LOWR))
|
---|
598 | strcat(string1, "(Lower)");
|
---|
599 | }
|
---|
600 | }
|
---|
601 | }
|
---|
602 | break;
|
---|
603 | default: break;
|
---|
604 | }
|
---|
605 | return string1;
|
---|
606 | }
|
---|
607 | */
|
---|
608 |
|
---|
609 | }
|
---|