Changeset 31955 in osm for applications/editors/josm/plugins/seachart/src/render/Signals.java
- Timestamp:
- 2016-01-06T09:33:48+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/seachart/src/render/Signals.java
r31722 r31955 283 283 } 284 284 285 class Sect { 286 int dir; 287 LitCHR chr; 288 ColCOL col; 289 ColCOL alt; 290 String grp; 291 double per; 292 double rng; 293 } 294 295 @SuppressWarnings("unchecked") 285 296 public static void lights(Feature feature) { 286 /*Enum<ColCOL> col = null;297 Enum<ColCOL> col = null; 287 298 Enum<ColCOL> tcol = null; 288 299 ObjTab lights = feature.objs.get(Obj.LIGHTS); … … 370 381 } 371 382 } 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 } 383 /* int secmax = countObjects(item, "light"); 384 if ((idx == 0) && (secmax > 0)) { 385 struct SECT { 386 struct SECT *next; 387 int dir; 388 LitCHR_t chr; 389 ColCOL_t col; 390 ColCOL_t alt; 391 char *grp; 392 double per; 393 double rng; 394 } *lights = NULL; 395 for (int i = secmax; i > 0; i--) { 396 struct SECT *tmp = calloc(1, sizeof(struct SECT)); 397 tmp->next = lights; 398 lights = tmp; 399 obj = getObj(item, LIGHTS, i); 400 if ((att = getAtt(obj, CATLIT)) != NULL) { 401 lights->dir = testAtt(att, LIT_DIR); 402 } 403 if ((att = getAtt(obj, LITCHR)) != NULL) { 404 lights->chr = att->val.val.e; 405 switch (lights->chr) { 406 case CHR_AL: 407 lights->chr = CHR_F; 408 break; 409 case CHR_ALOC: 410 lights->chr = CHR_OC; 411 break; 412 case CHR_ALLFL: 413 lights->chr = CHR_LFL; 414 break; 415 case CHR_ALFL: 416 lights->chr = CHR_FL; 417 break; 418 case CHR_ALFFL: 419 lights->chr = CHR_FFL; 420 break; 421 default: 422 break; 423 } 424 } 425 if ((att = getAtt(obj, SIGGRP)) != NULL) { 426 lights->grp = att->val.val.a; 427 } else { 428 lights->grp = ""; 429 } 430 if ((att = getAtt(obj, SIGPER)) != NULL) { 431 lights->per = att->val.val.f; 432 } 433 if ((att = getAtt(obj, VALNMR)) != NULL) { 434 lights->rng = att->val.val.f; 435 } 436 if ((att = getAtt(obj, COLOUR)) != NULL) { 437 lights->col = att->val.val.l->val; 438 if (att->val.val.l->next != NULL) 439 lights->alt = att->val.val.l->next->val; 440 } 441 } 442 struct COLRNG { 443 int col; 444 double rng; 445 } colrng[14]; 446 while (lights != NULL) { 447 strcpy(string2, ""); 448 bzero(colrng, 14*sizeof(struct COLRNG)); 449 colrng[lights->col].col = 1; 450 colrng[lights->col].rng = lights->rng; 451 struct SECT *this = lights; 452 struct SECT *next = lights->next; 453 while (next != NULL) { 454 if ((this->dir == next->dir) && (this->chr == next->chr) && 455 (strcmp(this->grp, next->grp) == 0) && (this->per == next->per)) { 456 colrng[next->col].col = 1; 457 if (next->rng > colrng[next->col].rng) 458 colrng[next->col].rng = next->rng; 459 struct SECT *tmp = lights; 460 while (tmp->next != next) tmp = tmp->next; 461 tmp->next = next->next; 462 free(next); 463 next = tmp->next; 464 } else { 465 next = next->next; 466 } 467 } 468 if (this->chr != CHR_UNKN) { 469 if (this->dir) strcpy(string2, "Dir."); 470 strcat(string2, light_characters[this->chr]); 471 if (strcmp(this->grp, "") != 0) { 472 if (this->grp[0] == '(') 473 sprintf(strchr(string2, 0), "%s", this->grp); 474 else 475 sprintf(strchr(string2, 0), "(%s)", this->grp); 476 } else { 477 if (strlen(string2) > 0) strcat(string2, "."); 478 } 479 int n = 0; 480 for (int i = 0; i < 14; i++) if (colrng[i].col) n++; 481 double max = 0.0; 482 for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng > max)) max = colrng[i].rng; 483 double min = max; 484 for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng > 0.0) && (colrng[i].rng < min)) min = colrng[i].rng; 485 if (min == max) { 486 for (int i = 0; i < 14; i++) if (colrng[i].col) strcat(string2, light_letters[i]); 487 } else { 488 for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng == max)) strcat(string2, light_letters[i]); 489 for (int i = 0; i < 14; i++) if (colrng[i].col && (colrng[i].rng < max) && (colrng[i].rng > min)) strcat(string2, light_letters[i]); 490 for (int i = 0; i < 14; i++) if (colrng[i].col && colrng[i].rng == min) strcat(string2, light_letters[i]); 491 } 492 strcat(string2, "."); 493 if (this->per > 0.0) sprintf(strchr(string2, 0), "%gs", this->per); 494 if (max > 0.0) { 495 sprintf(strchr(string2, 0), "%g", max); 496 if (min != max) { 497 if (n == 2) strcat(string2, "/"); 498 else if (n > 2) strcat(string2, "-"); 499 if (min < max) sprintf(strchr(string2, 0), "%g", min); 500 } 501 strcat(string2, "M"); 502 } 503 if (strlen(string1) > 0) strcat(string1, "\n"); 504 strcat(string1, string2); 505 } 506 lights = this->next; 507 free(this); 508 this = lights; 509 } 510 } else { 511 if ((att = getAtt(obj, CATLIT)) != NULL) { 512 if (testAtt(att, LIT_DIR)) 513 strcat(string1, "Dir"); 514 } 515 if ((att = getAtt(obj, MLTYLT)) != NULL) 516 sprintf(strchr(string1, 0), "%s", stringValue(att->val)); 517 if ((att = getAtt(obj, LITCHR)) != NULL) { 518 char *chrstr = strdup(stringValue(att->val)); 519 Att_t *grp = getAtt(obj, SIGGRP); 520 if (grp != NULL) { 521 char *strgrp = strdup(stringValue(grp->val)); 522 char *grpstr = strtok(strgrp, "()"); 523 switch (att->val.val.e) { 524 case CHR_QLFL: 525 sprintf(strchr(string1, 0), "Q(%s)+LFl", grpstr); 526 break; 527 case CHR_VQLFL: 528 sprintf(strchr(string1, 0), "VQ(%s)+LFl", grpstr); 529 break; 530 case CHR_UQLFL: 531 sprintf(strchr(string1, 0), "UQ(%s)+LFl", grpstr); 532 break; 533 default: 534 sprintf(strchr(string1, 0), "%s(%s)", chrstr, grpstr); 535 break; 536 } 537 free(strgrp); 538 } else { 539 sprintf(strchr(string1, 0), "%s", chrstr); 540 } 541 free(chrstr); 542 } 543 if ((att = getAtt(obj, COLOUR)) != NULL) { 544 int n = countValues(att); 545 if (!((n == 1) && (idx == 0) && (testAtt(att, COL_WHT)))) { 546 if ((strlen(string1) > 0) && ((string1[strlen(string1)-1] != ')'))) 547 strcat(string1, "."); 548 Lst_t *lst = att->val.val.l; 549 while (lst != NULL) { 550 strcat(string1, light_letters[lst->val]); 551 lst = lst->next; 552 } 553 } 554 } 555 if ((idx == 0) && (att = getAtt(obj, CATLIT)) != NULL) { 556 if (testAtt(att, LIT_VERT)) 557 strcat(string1, "(vert)"); 558 if (testAtt(att, LIT_HORI)) 559 strcat(string1, "(hor)"); 560 } 561 if ((strlen(string1) > 0) && 562 ((getAtt(obj, SIGPER) != NULL) || 563 (getAtt(obj, HEIGHT) != NULL) || 564 (getAtt(obj, VALMXR) != NULL)) && 565 (string1[strlen(string1)-1] != ')')) 566 strcat(string1, "."); 567 if ((att = getAtt(obj, SIGPER)) != NULL) 568 sprintf(strchr(string1, 0), "%ss", stringValue(att->val)); 569 if ((idx == 0) && (item->objs.obj != LITMIN)) { 570 if ((att = getAtt(obj, HEIGHT)) != NULL) 571 sprintf(strchr(string1, 0), "%sm", stringValue(att->val)); 572 if ((att = getAtt(obj, VALNMR)) != NULL) 573 sprintf(strchr(string1, 0), "%sM", stringValue(att->val)); 574 } 575 if ((idx == 0) && (att = getAtt(obj, CATLIT)) != NULL) { 576 if (testAtt(att, LIT_FRNT)) 577 strcat(string1, "(Front)"); 578 if (testAtt(att, LIT_REAR)) 579 strcat(string1, "(Rear)"); 580 if (testAtt(att, LIT_UPPR)) 581 strcat(string1, "(Upper)"); 582 if (testAtt(att, LIT_LOWR)) 583 strcat(string1, "(Lower)"); 584 } 585 } 586 } 424 587 */ } 425 588
Note:
See TracChangeset
for help on using the changeset viewer.