001package armyc2.c5isr.renderer.utilities; 002 003 004import android.graphics.Point; 005import android.graphics.PointF; 006import android.graphics.Rect; 007import android.graphics.RectF; 008 009import java.text.SimpleDateFormat; 010import java.util.ArrayList; 011import java.util.Date; 012import java.util.Locale; 013import java.util.TimeZone; 014import java.util.regex.Pattern; 015 016import armyc2.c5isr.JavaLineArray.TacticalLines; 017 018/** 019 * Has various utility functions for prcessing the symbol code. 020 * See {@link SymbolID} for additional functions related to parsing the symbol code. 021* 022 */ 023public class SymbolUtilities { 024 025 private static SimpleDateFormat dateFormatFront = new SimpleDateFormat("ddHHmmss", Locale.US); 026 private static SimpleDateFormat dateFormatBack = new SimpleDateFormat("MMMyyyy", Locale.US); 027 private static SimpleDateFormat dateFormatFull = new SimpleDateFormat("ddHHmmssZMMMyyyy", Locale.US); 028 private static SimpleDateFormat dateFormatZulu = new SimpleDateFormat("Z", Locale.US); 029 030 //this regex is from: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html 031 private static final String Digits = "(\\p{Digit}+)"; 032 private static final String HexDigits = "(\\p{XDigit}+)"; 033 // an exponent is 'e' or 'E' followed by an optionally 034 // signed decimal integer. 035 private static final String Exp = "[eE][+-]?"+Digits; 036 private static final String fpRegex = 037 ("[\\x00-\\x20]*"+ // Optional leading "whitespace" 038 "[+-]?(" + // Optional sign character 039 "NaN|" + // "NaN" string 040 "Infinity|" + // "Infinity" string 041 042 // A decimal floating-point string representing a finite positive 043 // number without a leading sign has at most five basic pieces: 044 // Digits . Digits ExponentPart FloatTypeSuffix 045 // 046 // Since this method allows integer-only strings as input 047 // in addition to strings of floating-point literals, the 048 // two sub-patterns below are simplifications of the grammar 049 // productions from section 3.10.2 of 050 // The Java™ Language Specification. 051 052 // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt 053 "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+ 054 055 // . Digits ExponentPart_opt FloatTypeSuffix_opt 056 "(\\.("+Digits+")("+Exp+")?)|"+ 057 058 // Hexadecimal strings 059 "((" + 060 // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt 061 "(0[xX]" + HexDigits + "(\\.)?)|" + 062 063 // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt 064 "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + 065 066 ")[pP][+-]?" + Digits + "))" + 067 "[fFdD]?))" + 068 "[\\x00-\\x20]*");// Optional trailing "whitespace" 069 070 private static final Pattern pIsNumber = Pattern.compile(fpRegex); 071 072 /** 073 * Determines if a String represents a valid number 074 * 075 * @param text {@link String} 076 * @return "1.56" == true, "1ab" == false 077 */ 078 public static boolean isNumber(String text) 079 { 080 return pIsNumber.matcher(text).matches(); 081 } 082 083 084 /*private static String convert(int integer) 085 { 086 String hexAlphabet = "0123456789ABCDEF"; 087 String foo = "gfds" + "dhs"; 088 char char1 = hexAlphabet.charAt((integer - integer % 16)/16); 089 char char2 = hexAlphabet.charAt(integer % 16); 090 String returnVal = String.valueOf(char1) + String.valueOf(char2); 091 return returnVal; 092 } 093 094 public static String colorToHexString(Color color, Boolean withAlpha) 095 { 096 if(color != null) { 097 String hex = ""; 098 if (withAlpha == false) { 099 hex = "#" + convert(color.getRed()) + 100 convert(color.getGreen()) + 101 convert(color.getBlue()); 102 } else { 103 hex = "#" + convert(color.getAlpha()) + 104 convert(color.getRed()) + 105 convert(color.getGreen()) + 106 convert(color.getBlue()); 107 } 108 return hex; 109 } 110 else 111 return null; 112 }//*/ 113 114 115 /** 116 * Converts a Java Date object into a properly formatted String for W or W1. 117 * DDHHMMSSZMONYYYY 118 * Field W: D = day, H = hour, M = minute, S = second, Z = Greenwich or local time, MON= month and Y = year. 119 * @param time {@link Date} 120 * @return {@link String} 121 */ 122 public static String getDateLabel(Date time) 123 { 124 125 String modifierString = null; 126 127 String zulu = ""; 128 zulu = dateFormatZulu.format(time); 129 130 if (zulu != null && zulu.length() == 5) 131 { 132 133 if (zulu.startsWith("+"))//Integer.valueOf doesn't like '+' 134 { 135 zulu = zulu.substring(1, 3); 136 } 137 else 138 { 139 zulu = zulu.substring(0, 3); 140 } 141 142 int intZulu = Integer.valueOf(zulu); 143 144 zulu = getZuluCharFromTimeZoneOffset(intZulu); 145 } 146 else 147 { 148 zulu = getZuluCharFromTimeZoneOffset(time); 149 } 150 151 modifierString = dateFormatFront.format(time) + zulu + dateFormatBack.format(time); 152 153 return modifierString.toUpperCase(); 154 } 155 156 /** 157 * Given date, return character String representing which NATO time zone 158 * you're in. 159 * 160 * @param time {@link Date} 161 * @return {@link String} 162 */ 163 private static String getZuluCharFromTimeZoneOffset(Date time) 164 { 165 TimeZone tz = TimeZone.getDefault(); 166 Date offset = new Date(tz.getOffset(time.getTime())); 167 long lOffset = offset.getTime() / 3600000;//3600000 = (1000(ms)*60(s)*60(m)) 168 169 int hour = (int) lOffset; 170 171 return getZuluCharFromTimeZoneOffset(hour); 172 } 173 174 /** 175 * Given hour offset from Zulu return character String representing which 176 * NATO time zone you're in. 177 * 178 * @param hour {@link Integer} 179 * @return {@link String} 180 */ 181 private static String getZuluCharFromTimeZoneOffset(int hour) 182 { 183 if (hour == 0) 184 { 185 return "Z"; 186 } 187 else if (hour == -1) 188 { 189 return "N"; 190 } 191 else if (hour == -2) 192 { 193 return "O"; 194 } 195 else if (hour == -3) 196 { 197 return "P"; 198 } 199 else if (hour == -4) 200 { 201 return "Q"; 202 } 203 else if (hour == -5) 204 { 205 return "R"; 206 } 207 else if (hour == -6) 208 { 209 return "S"; 210 } 211 else if (hour == -7) 212 { 213 return "T"; 214 } 215 else if (hour == -8) 216 { 217 return "U"; 218 } 219 else if (hour == -9) 220 { 221 return "V"; 222 } 223 else if (hour == -10) 224 { 225 return "W"; 226 } 227 else if (hour == -11) 228 { 229 return "X"; 230 } 231 else if (hour == -12) 232 { 233 return "Y"; 234 } 235 else if (hour == 1) 236 { 237 return "A"; 238 } 239 else if (hour == 2) 240 { 241 return "B"; 242 } 243 else if (hour == 3) 244 { 245 return "C"; 246 } 247 else if (hour == 4) 248 { 249 return "D"; 250 } 251 else if (hour == 5) 252 { 253 return "E"; 254 } 255 else if (hour == 6) 256 { 257 return "F"; 258 } 259 else if (hour == 7) 260 { 261 return "G"; 262 } 263 else if (hour == 8) 264 { 265 return "H"; 266 } 267 else if (hour == 9) 268 { 269 return "I"; 270 } 271 else if (hour == 10) 272 { 273 return "K"; 274 } 275 else if (hour == 11) 276 { 277 return "L"; 278 } 279 else if (hour == 12) 280 { 281 return "M"; 282 } 283 else 284 { 285 return "-"; 286 } 287 } 288 289 /** 290 * Determines if a symbol, based on it's symbol ID, can have the specified modifier/amplifier. 291 * @param symbolID 30 Character {@link String} 292 * @param modifier {@link Modifiers} 293 * @return {@link Boolean} 294 */ 295 public static Boolean hasModifier(String symbolID, String modifier) 296 { 297 MSInfo msi = MSLookup.getInstance().getMSLInfo(symbolID); 298 299 if(msi != null)// && msi.getDrawRule() != DrawRules.DONOTDRAW) 300 { 301 ArrayList<String> mods = msi.getModifiers(); 302 303 if(mods != null && mods.contains(modifier)) 304 return true; 305 else if(msi.getSymbolSet() == SymbolID.SymbolSet_ControlMeasure && modifier.equals(Modifiers.AB_FEINT_DUMMY_INDICATOR)) 306 return true; 307 else 308 return false; 309 } 310 return false; 311 } 312 313 /** 314 * Gets Basic Symbol ID which is the Symbol Set + Entity Code 315 * @param id 30 Character {@link String} 316 * @return 8 character {@link String} (Symbol Set + Entity Code) 317 */ 318 public static String getBasicSymbolID(String id) 319 { 320 if(id.length() == 8) 321 { 322 return id; 323 } 324 else if(id.startsWith("B")) 325 return id; 326 else if(id.equals("octagon")) 327 return id; 328 else if (id.length() >= 20 && id.length() <= 30) 329 { 330 String key = id.substring(4, 6) + id.substring(10, 16); 331 return key; 332 } 333 else if (id.length()==15) 334 { 335 return getBasicSymbolID2525C(id); 336 } 337 return id; 338 } 339 340 /** 341 * Gets the basic Symbol ID for a 2525C symbol 342 * S*F*GPU---***** 343 * G*G*GPP---****X 344 * @param strSymbolID 15 Character {@link String} 345 * @return 15 Character {@link String} 346 */ 347 public static String getBasicSymbolID2525C(String strSymbolID) 348 { 349 if(strSymbolID != null && strSymbolID.length() == 15) 350 { 351 StringBuilder sb = new StringBuilder(); 352 char scheme = strSymbolID.charAt(0); 353 if (scheme == 'G') 354 { 355 sb.append(strSymbolID.charAt(0)); 356 sb.append("*"); 357 sb.append(strSymbolID.charAt(2)); 358 sb.append("*"); 359 sb.append(strSymbolID.substring(4, 10)); 360 sb.append("****X"); 361 } 362 else if (scheme != 'W' && scheme != 'B' && scheme != 'P') 363 { 364 sb.append(strSymbolID.charAt(0)); 365 sb.append("*"); 366 sb.append(strSymbolID.charAt(2)); 367 sb.append("*"); 368 sb.append(strSymbolID.substring(4, 10)); 369 if(sb.toString().startsWith("S*G*I"))//Installation 370 sb.append("H****"); 371 else if(sb.toString().startsWith("I"))//SIGINT 372 sb.append("--***"); 373 else//Warfighting and anything else 374 sb.append("*****"); 375 } 376 else 377 { 378 return strSymbolID; 379 } 380 return sb.toString(); 381 } 382 return strSymbolID; 383 } 384 385 /** 386 * Attempts to resolve a bad symbol ID into a value that can be found in {@link MSLookup}. 387 * If it fails, it will return the symbol code for a invalid symbol which is displayed as 388 * an inverted question mark (110098000010000000000000000000) 389 * @param symbolID 30 character {@link String} 390 * @return 30 character {@link String} representing the resolved symbol ID. 391 */ 392 public static String reconcileSymbolID(String symbolID) 393 { 394 395 String newID = ""; 396 try { 397 398 399 int v = SymbolID.getVersion(symbolID); 400 if (v < SymbolID.Version_APP6D) 401 newID = String.valueOf(SymbolID.Version_2525Dch1); 402 else if(v > SymbolID.Version_APP6Ech2) 403 newID = String.valueOf(SymbolID.Version_2525Ech1); 404 v = SymbolID.getVersion(newID); 405 int c = SymbolID.getContext(symbolID); 406 if (c > 4) 407 newID += String.valueOf(SymbolID.StandardIdentity_Context_Reality); 408 else 409 newID += String.valueOf(c); 410 int a = SymbolID.getAffiliation(symbolID); 411 if (a > 6) 412 newID += String.valueOf(SymbolID.StandardIdentity_Affiliation_Unknown); 413 else 414 newID += String.valueOf(a); 415 int ss = SymbolID.getSymbolSet(symbolID); 416 switch (ss) { 417 case SymbolID.SymbolSet_Unknown: 418 case SymbolID.SymbolSet_Air: 419 case SymbolID.SymbolSet_AirMissile: 420 case SymbolID.SymbolSet_SignalsIntelligence_Air: 421 case SymbolID.SymbolSet_Space: 422 case SymbolID.SymbolSet_SpaceMissile: 423 case SymbolID.SymbolSet_SignalsIntelligence_Space: 424 case SymbolID.SymbolSet_LandUnit: 425 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 426 case SymbolID.SymbolSet_LandEquipment: 427 case SymbolID.SymbolSet_SignalsIntelligence_Land: 428 case SymbolID.SymbolSet_LandInstallation: 429 case SymbolID.SymbolSet_DismountedIndividuals: 430 case SymbolID.SymbolSet_SeaSurface: 431 case SymbolID.SymbolSet_SignalsIntelligence_SeaSurface: 432 case SymbolID.SymbolSet_SeaSubsurface: 433 case SymbolID.SymbolSet_MineWarfare: 434 case SymbolID.SymbolSet_SignalsIntelligence_SeaSubsurface: 435 case SymbolID.SymbolSet_Activities: 436 case SymbolID.SymbolSet_ControlMeasure: 437 case SymbolID.SymbolSet_Atmospheric: 438 case SymbolID.SymbolSet_Oceanographic: 439 case SymbolID.SymbolSet_MeteorologicalSpace: 440 case SymbolID.SymbolSet_CyberSpace: 441 newID += String.format("%02d",ss); 442 break; 443 default: 444 newID += String.format("%02d", SymbolID.SymbolSet_Unknown);//String.valueOf(SymbolID.SymbolSet_Unknown); 445 } 446 447 int s = SymbolID.getStatus(symbolID); 448 if (s > SymbolID.Status_Present_FullToCapacity) 449 newID += String.valueOf(SymbolID.Status_Present); 450 else 451 newID += String.valueOf(s); 452 453 newID += String.valueOf(SymbolID.getHQTFD(symbolID));//just add, won't get used if value bad 454 newID += String.format("%02d",SymbolID.getAmplifierDescriptor(symbolID));//just add, won't get used if value bad 455 456 int ec = SymbolID.getEntityCode(symbolID); 457 458 if (ec == 0) 459 newID += "000000";//root symbol for symbol set 460 else if (SVGLookup.getInstance().getSVGLInfo(SVGLookup.getMainIconID(newID + ec + "0000"), v) == null) { 461 //set to blank symbol 462 newID += "000000"; 463 /*//set to invalid symbol since we couldn't find it in the lookup 464 newID = SymbolID.setSymbolSet(newID, 98); 465 newID += 100000;//*/ 466 } 467 else 468 newID += String.format("%06d",ec);//we found it so add the entity code 469 470 //newID += SymbolID.getMod1ID(symbolID);//just add, won't get used if value bad 471 //newID += SymbolID.getMod2ID(symbolID);//just add, won't get used if value bad 472 newID += symbolID.substring(16);//just add, won't get used if value bad 473 } 474 catch(Exception exc) 475 { 476 newID = "110098000010000000000000000000";//invalid symbol 477 } 478 479 return newID; 480 } 481 482 /** 483 * Gets line color used if no line color has been set. The color is specified based on the affiliation of 484 * the symbol and whether it is a unit or not. 485 * @param symbolID 30 character {@link String} 486 * @return {@link Color} 487 */ 488 public static Color getLineColorOfAffiliation(String symbolID) 489 { 490 Color retColor = null; 491 492 int symbolSet = SymbolID.getSymbolSet(symbolID); 493 int set = SymbolID.getSymbolSet(symbolID); 494 int affiliation = SymbolID.getAffiliation(symbolID); 495 int symStd = SymbolID.getVersion(symbolID); 496 int entityCode = SymbolID.getEntityCode(symbolID); 497 498 try 499 { 500 // We can't get the line color if there is no symbol id, since that also means there is no affiliation 501 if((symbolID == null) || (symbolID.equals(""))) 502 { 503 return retColor; 504 } 505 506 if(symbolSet == SymbolID.SymbolSet_ControlMeasure) 507 { 508 int entity = SymbolID.getEntity(symbolID); 509 int entityType = SymbolID.getEntityType(symbolID); 510 int entitySubtype = SymbolID.getEntitySubtype(symbolID); 511 512 if(SymbolUtilities.isGreenProtectionGraphic(entity, entityType, entitySubtype)) 513 { 514 //Obstacles/Protection Graphics, some are green obstacles and we need to 515 //check for those. 516 retColor = AffiliationColors.ObstacleGreen; 517 } 518 //just do color by affiliation if no other color has been set yet. 519 if(retColor == null) 520 { 521 switch (affiliation) { 522 case SymbolID.StandardIdentity_Affiliation_Friend: 523 case SymbolID.StandardIdentity_Affiliation_AssumedFriend: 524 retColor = AffiliationColors.FriendlyGraphicLineColor;//Color.BLACK;//0x000000; // Black 525 break; 526 case SymbolID.StandardIdentity_Affiliation_Hostile_Faker: 527 retColor = AffiliationColors.HostileGraphicLineColor;//Color.RED;//0xff0000; // Red 528 break; 529 case SymbolID.StandardIdentity_Affiliation_Suspect_Joker: 530 if(symStd >= SymbolID.Version_2525E && symStd <= SymbolID.Version_2525Ech1) 531 retColor = AffiliationColors.SuspectGraphicLineColor;//255,188,1 532 else 533 retColor = AffiliationColors.HostileGraphicLineColor;//Color.RED;//0xff0000; // Red 534 break; 535 case SymbolID.StandardIdentity_Affiliation_Neutral: 536 retColor = AffiliationColors.NeutralGraphicLineColor;//Color.GREEN;//0x00ff00; // Green 537 break; 538 default: 539 retColor = AffiliationColors.UnknownGraphicLineColor;//Color.YELLOW;//0xffff00; // Yellow 540 break; 541 } 542 } 543 } 544 else if (set >= 45 && set <= 47)//METOC 545 { 546 // If not black then color will be set in clsMETOC.SetMeTOCProperties() 547 retColor = Color.BLACK; 548 } 549 else if (set == SymbolID.SymbolSet_MineWarfare && (RendererSettings.getInstance().getSeaMineRenderMethod() == RendererSettings.SeaMineRenderMethod_MEDAL)) 550 { 551 if(!(entityCode == 110600 || entityCode == 110700)) 552 { 553 switch(affiliation) 554 { 555 case SymbolID.StandardIdentity_Affiliation_Friend: 556 case SymbolID.StandardIdentity_Affiliation_AssumedFriend: 557 retColor = AffiliationColors.FriendlyUnitFillColor;//0x00ffff; // Cyan 558 break; 559 case SymbolID.StandardIdentity_Affiliation_Hostile_Faker: 560 retColor = AffiliationColors.HostileUnitFillColor;//Color.RED;//0xff0000; // Red 561 break; 562 case SymbolID.StandardIdentity_Affiliation_Suspect_Joker: 563 if(symStd >= SymbolID.Version_2525E && symStd <= SymbolID.Version_2525Ech1) 564 retColor = AffiliationColors.SuspectUnitFillColor;//255,188,1 565 else 566 retColor = AffiliationColors.HostileUnitFillColor;//Color.RED;//0xff0000; // Red 567 break; 568 case SymbolID.StandardIdentity_Affiliation_Neutral: 569 retColor = AffiliationColors.NeutralUnitFillColor;//0x7fff00; // Light Green 570 break; 571 default://unknown, pending, everything else 572 retColor = AffiliationColors.UnknownUnitFillColor;//new Color(255,250, 205); //0xfffacd; // LemonChiffon 255 250 205 573 break; 574 } 575 } 576 else 577 { 578 retColor = Color.BLACK; 579 } 580 } 581 else//everything else 582 { 583 //stopped doing check because all warfighting 584 //should have black for line color. 585 retColor = Color.BLACK; 586 } 587 } 588 catch(Exception e) 589 { 590 // Log Error 591 ErrorLogger.LogException("SymbolUtilities", "getLineColorOfAffiliation", e); 592 //throw e; 593 } // End catch 594 return retColor; 595 } // End get LineColorOfAffiliation 596 597 /** 598 * For Control Measures, returns the default color for a symbol when it differs from the 599 * affiliation line color. If there is no default color, returns the value from {@link #getLineColorOfAffiliation} 600 * @param symbolID 30 Character {@link String} 601 * @return {@link Color} 602 */ 603 public static Color getDefaultLineColor(String symbolID) { 604 try { 605 if (symbolID == null || symbolID.equals("")) { 606 return null; 607 } 608 609 int symbolSet = SymbolID.getSymbolSet(symbolID); 610 int entityCode = SymbolID.getEntityCode(symbolID); 611 int version = SymbolID.getVersion(symbolID); 612 613 if (symbolSet == SymbolID.SymbolSet_ControlMeasure) { 614 if (entityCode == 200600) { //Cued Acquisition Doctrine 615 return Color.WHITE; 616 } else if (entityCode == 200700) { //Radar Search Doctrine 617 return new Color(51, 136, 136); 618 } else if (entityCode == 200101) { //Launch Area 619 return new Color(255, 155, 0); 620 } else if (entityCode == 200201 || entityCode == 200202) { //Defended Area 621 return new Color(85, 119, 136); 622 } else if (version >= SymbolID.Version_2525E && //TODO: check about APP6E3 623 (entityCode == 132100 || //key terrain 624 entityCode == 282001 || //Tower, Low 625 entityCode == 282002 || //Tower, High 626 entityCode == 282003)) { // Overhead Wire 627 return new Color(128, 0, 128);//purple 628 } 629 } 630 } catch (Exception e) { 631 ErrorLogger.LogException("SymbolUtilities", "getDefaultLineColor", e); 632 } 633 return getLineColorOfAffiliation(symbolID); 634 } 635 636 /** 637 * METOCs and several Control measures have colors that should not change 638 * @param symbolID 20-30 character id string for symbol 639 * @return true if color should not change 640 */ 641 public static boolean hasStaticLineColor(String symbolID) 642 { 643 int ss = SymbolID.getSymbolSet(symbolID); 644 int version = SymbolID.getVersion(symbolID); 645 646 if(ss == SymbolID.SymbolSet_ControlMeasure) 647 { 648 int ec = SymbolID.getEntityCode(symbolID); 649 switch (ec) 650 { 651 case 200600: //Cued Acquisition Doctrine 652 case 200700: //Radar Search Doctrine 653 case 200101: //Launch Area 654 //case 200201: //Defended Area Ellipse/Circle may be depicted as orange (RGB: 255,155,0) where, the area fill is 75% transparent. 655 //case 200202: //Defended Area Rectangle may be depicted as gray (RGB:85,119,136) where the gray area fill is 75% transparent. 656 return true; 657 case 132100: //key terrain 658 case 282001: //Tower, Low 659 case 282002: //Tower, High 660 case 282003: // Overhead wire 661 return version >= SymbolID.Version_2525E; 662 default: 663 break; 664 } 665 return isGreenProtectionGraphic(symbolID); 666 } 667 else 668 return ss == SymbolID.SymbolSet_Atmospheric || 669 ss == SymbolID.SymbolSet_Oceanographic || 670 ss == SymbolID.SymbolSet_MeteorologicalSpace; 671 } 672 673 /** 674 * Checks if a symbol should be filled by default 675 * 676 * @param strSymbolID The 20 digit representation of the 2525D symbol 677 * @return true if there is a default fill 678 */ 679 public static boolean hasDefaultFill(String strSymbolID) { 680 int ec = SymbolID.getEntityCode(strSymbolID); 681 switch (ec) { 682 case 200101: 683 case 200201: 684 case 200202: 685 case 200600: 686 case 200700: 687 return true; 688 default: 689 return !SymbolUtilities.isTacticalGraphic(strSymbolID); 690 } 691 } 692 693 /** 694 * Determines if the symbol is a tactical graphic 695 * 696 * @param strSymbolID 30 Character {@link String} 697 * @return true if symbol set is 25 (control measure), or is a weather graphic 698 */ 699 public static boolean isTacticalGraphic(String strSymbolID) { 700 try { 701 int ss = SymbolID.getSymbolSet(strSymbolID); 702 703 if(ss == SymbolID.SymbolSet_ControlMeasure || isWeather(strSymbolID)) { 704 return true; 705 } 706 } 707 catch (Exception e) { 708 ErrorLogger.LogException("SymbolUtilities", "isTacticalGraphic", e); 709 } 710 return false; 711 } 712 713 /** 714 * Determines if the Symbol can be rendered as a multipoint graphic and not just as an icon 715 * @param symbolID 30 Character {@link String} 716 * @return {@link Boolean} 717 */ 718 public static boolean isMultiPoint(String symbolID) 719 { 720 MSInfo msi = MSLookup.getInstance().getMSLInfo(symbolID); 721 if (msi == null) { 722 return false; 723 } 724 int drawRule = msi.getDrawRule(); 725 int ss = msi.getSymbolSet(); 726 if(ss != SymbolID.SymbolSet_ControlMeasure && ss != SymbolID.SymbolSet_Oceanographic && ss != SymbolID.SymbolSet_Atmospheric && ss != SymbolID.SymbolSet_MeteorologicalSpace) 727 { 728 return false; 729 } 730 else if (ss == SymbolID.SymbolSet_ControlMeasure) 731 { 732 if(msi.getMaxPointCount() > 1) 733 return true; 734 else if((drawRule < DrawRules.POINT1 || drawRule > DrawRules.POINT16 || drawRule == DrawRules.POINT12) && 735 drawRule != DrawRules.DONOTDRAW && drawRule != DrawRules.AREA22) 736 { 737 return true; 738 } 739 else 740 return false; 741 } 742 else if(ss == SymbolID.SymbolSet_Oceanographic || ss == SymbolID.SymbolSet_Atmospheric || ss == SymbolID.SymbolSet_MeteorologicalSpace) 743 { 744 if(msi.getMaxPointCount() > 1) 745 return true; 746 else 747 return false; 748 } 749 return false; 750 } 751 752 public static boolean isActionPoint(String symbolID) 753 { 754 MSInfo msi = MSLookup.getInstance().getMSLInfo(symbolID); 755 if(msi != null && msi.getDrawRule()==DrawRules.POINT1) 756 { 757 int ec = SymbolID.getEntityCode(symbolID); 758 if(ec != 131300 && ec != 131301 && ec != 182600 && ec != 212800 759 && ec != 360100 && ec != 360200 && ec != 360300) 760 return true; 761 } 762 return false; 763 } 764 765 /** 766 * Control Measures and Tactical Graphics that have labels but not with the Action Point layout 767 * @param strSymbolID 30 Character {@link String} 768 * @return {@link Boolean} 769 + @deprecated see {@link #isSPWithSpecialModifierLayout(String)} 770 */ 771 public static boolean isTGSPWithSpecialModifierLayout(String strSymbolID) 772 { 773 try 774 { 775 int ss = SymbolID.getSymbolSet(strSymbolID); 776 int entityCode = SymbolID.getEntityCode(strSymbolID); 777 if(ss == SymbolID.SymbolSet_ControlMeasure) //|| isWeather(strSymbolID)) { 778 { 779 if(SymbolUtilities.isCBRNEvent(strSymbolID)) 780 return true; 781 782 if(SymbolUtilities.isSonobuoy(strSymbolID)) 783 return true; 784 785 switch (entityCode) 786 { 787 case 130500: //contact point 788 case 130700: //decision point 789 case 212800: //harbor 790 case 210300: //Defended Asset 791 case 210600: //Air Detonation 792 case 131300: //point of interest 793 case 131800: //waypoint 794 case 240900: //fire support station 795 case 180100: //Air Control point 796 case 180200: //Communications Check point 797 case 160300: //T (target reference point) 798 case 240601: //ap,ap1,x,h (Point/Single Target) 799 case 240602: //ap (nuclear target) 800 case 270701: //static depiction 801 case 282001: //tower, low 802 case 282002: //tower, high 803 return true; 804 default: 805 return false; 806 } 807 } 808 else if(ss == SymbolID.SymbolSet_Atmospheric) 809 { 810 switch (entityCode) 811 { 812 case 162300: //Freezing Level 813 case 162200: //tropopause Level 814 case 110102: //tropopause Low 815 case 110202: //tropopause High 816 return true; 817 default: 818 return false; 819 } 820 } 821 } 822 catch (Exception e) { 823 ErrorLogger.LogException("SymbolUtilities", "isTGSPWithSpecialModifierLayout", e); 824 } 825 return false; 826 } 827 828 /** 829 * Returns the fill color for the symbol based on its affiliation 830 * @param symbolID 30 Character {@link String} 831 * @return {@link Color} 832 */ 833 public static Color getFillColorOfAffiliation(String symbolID) 834 { 835 Color retColor = null; 836 int entityCode = SymbolID.getEntityCode(symbolID); 837 int entity = SymbolID.getEntity(symbolID); 838 int entityType = SymbolID.getEntityType(symbolID); 839 int entitySubtype = SymbolID.getEntitySubtype(symbolID); 840 841 int affiliation = SymbolID.getAffiliation(symbolID); 842 843 try 844 { 845 // We can't get the fill color if there is no symbol id, since that also means there is no affiliation 846 if ((symbolID == null) || (symbolID.equals(""))) { 847 return retColor; 848 } 849 if (SymbolID.getSymbolSet(symbolID) == SymbolID.SymbolSet_ControlMeasure) { 850 switch (entityCode) { 851 case 200101: 852 retColor = new Color(255, 155, 0, (int) (.25 * 255)); 853 break; 854 case 200201: 855 case 200202: 856 case 200600: 857 retColor = new Color(85, 119, 136, (int) (.25 * 255)); 858 break; 859 case 200700: 860 retColor = new Color(51, 136, 136, (int) (.25 * 255)); 861 break; 862 } 863 } 864 else if (SymbolID.getSymbolSet(symbolID) == SymbolID.SymbolSet_MineWarfare && 865 (RendererSettings.getInstance().getSeaMineRenderMethod() == RendererSettings.SeaMineRenderMethod_MEDAL) && 866 (!(entityCode == 110600 || entityCode == 110700))) 867 { 868 retColor = new Color(0,0,0,0);//transparent 869 } 870 //just do color by affiliation if no other color has been set yet 871 if (retColor == null) { 872 switch(affiliation) 873 { 874 case SymbolID.StandardIdentity_Affiliation_Friend: 875 case SymbolID.StandardIdentity_Affiliation_AssumedFriend: 876 retColor = AffiliationColors.FriendlyUnitFillColor;//0x00ffff; // Cyan 877 break; 878 case SymbolID.StandardIdentity_Affiliation_Hostile_Faker: 879 retColor = AffiliationColors.HostileUnitFillColor;//0xfa8072; // Salmon 880 break; 881 case SymbolID.StandardIdentity_Affiliation_Suspect_Joker: 882 if(SymbolID.getVersion(symbolID) >= SymbolID.Version_2525E && SymbolID.getVersion(symbolID) <= SymbolID.Version_2525Ech1) 883 retColor = AffiliationColors.SuspectGraphicFillColor;//255,229,153 884 else 885 retColor = AffiliationColors.HostileGraphicFillColor;//Color.RED;//0xff0000; // Red 886 break; 887 case SymbolID.StandardIdentity_Affiliation_Neutral: 888 retColor = AffiliationColors.NeutralUnitFillColor;//0x7fff00; // Light Green 889 break; 890 default://unknown, pending, everything else 891 retColor = AffiliationColors.UnknownUnitFillColor;//new Color(255,250, 205); //0xfffacd; // LemonChiffon 255 250 205 892 break; 893 } 894 } 895 } // End try 896 catch (Exception e) 897 { 898 // Log Error 899 ErrorLogger.LogException("SymbolUtilities", "getFillColorOfAffiliation", e); 900 //throw e; 901 } // End catch 902 903 return retColor; 904 } // End FillColorOfAffiliation 905 906 /** 907 * 908 * @param symbolID 30 Character {@link String} 909 * @param modifier {@link Modifiers} 910 * @return {@link Boolean} 911 * @deprecated see {@link #hasModifier(String, String)} 912 */ 913 public static Boolean canSymbolHaveModifier(String symbolID, String modifier) 914 { 915 return hasModifier(symbolID, modifier); 916 } 917 918 /** 919 * Checks if the Symbol Code has FDI set. 920 * Does not check if the symbol can have an FDI. 921 * @param symbolID 30 Character {@link String} 922 * @return {@link Boolean} 923 */ 924 public static Boolean hasFDI(String symbolID) 925 { 926 int hqtfd = SymbolID.getHQTFD(symbolID); 927 if(hqtfd == SymbolID.HQTFD_FeintDummy 928 || hqtfd == SymbolID.HQTFD_FeintDummy_TaskForce 929 || hqtfd == SymbolID.HQTFD_FeintDummy_Headquarters 930 || hqtfd == SymbolID.HQTFD_FeintDummy_TaskForce_Headquarters 931 || hqtfd == SymbolID.HQTFD_Unmanned_Marker_FeintDummy 932 || hqtfd == SymbolID.HQTFD_Unmanned_Marker_Autonomous_FeintDummy 933 || hqtfd == SymbolID.HQTFD_Unmanned_Marker_Remotely_Piloted_FeintDummy) 934 { 935 return true; 936 } 937 else 938 return false; 939 } 940 941 /* 942 * For Renderer Use Only 943 * Assumes a fresh SVG String from the SVGLookup with its default values 944 * @param symbolID 945 * @param svg 946 * @param strokeColor 947 * @param fillColor 948 * @return 949 */ 950 /*public static String setSVGFrameColors(String symbolID, String svg, Color strokeColor, Color fillColor) 951 { 952 String hexStrokeColor = null; 953 String hexFillColor = null; 954 955 if(strokeColor != null) 956 hexStrokeColor = colorToHexString(strokeColor,false); 957 if(fillColor != null) 958 hexFillColor = colorToHexString(fillColor,false); 959 return setSVGFrameColors(symbolID, svg, hexStrokeColor,hexFillColor); 960 }//*/ 961 962 /*** 963 * Returns true if graphic is protection graphic (obstacles which render green) 964 * Assumes control measure symbol code where SS == 25 965 * @param entity {@link Integer} 966 * @param entityType {@link Integer} 967 * @param entitySubtype {@link Integer} 968 * @return {@link Boolean} 969 */ 970 public static boolean isGreenProtectionGraphic(int entity, int entityType, int entitySubtype) 971 { 972 if(entity >= 27 && entity <= 29)//Protection Areas, Points and Lines 973 { 974 if(entity == 27) 975 { 976 if(entityType > 0 && entityType <= 5) 977 return true; 978 else if(entityType == 7 || entityType == 8 || entityType == 10 || entityType == 12) 979 { 980 return true; 981 } 982 else 983 return false; 984 } 985 else if(entity == 28) 986 { 987 if(entityType > 0 && entityType <= 7) 988 return true; 989 if(entityType == 19) 990 return true; 991 else 992 return false; 993 } 994 else if(entity == 29) 995 { 996 if(entityType >= 01 && entityType <= 05) 997 return true; 998 else 999 return false; 1000 } 1001 } 1002 else 1003 { 1004 return false; 1005 } 1006 return false; 1007 } 1008 1009 /** 1010 * Returns true if graphic is protection graphic (obstacles which render green) 1011 * @param symbolID 30 Character {@link String} 1012 * @return {@link Boolean} 1013 */ 1014 public static boolean isGreenProtectionGraphic(String symbolID){ 1015 if (SymbolID.getSymbolSet(symbolID) == SymbolID.SymbolSet_ControlMeasure) { 1016 return SymbolUtilities.isGreenProtectionGraphic(SymbolID.getEntity(symbolID), SymbolID.getEntityType(symbolID), SymbolID.getEntitySubtype(symbolID)); 1017 } else { 1018 return false; 1019 } 1020 } 1021 1022 /** 1023 * Returns true if Symbol ID represents a chemical, biological, radiological or nuclear incident. 1024 * @param symbolID 30 Character {@link String} 1025 * @return {@link Boolean} 1026 */ 1027 public static boolean isCBRNEvent(String symbolID) 1028 { 1029 int ss = SymbolID.getSymbolSet(symbolID); 1030 int ec = SymbolID.getEntityCode(symbolID); 1031 1032 if(ss == SymbolID.SymbolSet_ControlMeasure) { 1033 switch (ec) 1034 { 1035 case 281300: 1036 case 281301: 1037 case 281400: 1038 case 281401: 1039 case 281500: 1040 case 281600: 1041 case 281700: 1042 case 281701: 1043 return true; 1044 default: 1045 } 1046 } 1047 return false; 1048 } 1049 1050 /** 1051 * Returns true if Symbol ID represents a Sonobuoy. 1052 * @param symbolID 30 Character {@link String} 1053 * @return {@link Boolean} 1054 */ 1055 public static boolean isSonobuoy(String symbolID) 1056 { 1057 int ss = SymbolID.getSymbolSet(symbolID); 1058 int e = SymbolID.getEntity(symbolID); 1059 int et = SymbolID.getEntityType(symbolID); 1060 if(ss == 25 && e == 21 && et == 35) 1061 return true; 1062 else 1063 return false; 1064 } 1065 1066 /** 1067 * Obstacles are generally required to have a green line color 1068 * @param symbolID 30 Character {@link String} 1069 * @return {@link Boolean} 1070 * @deprecated see {@link #isGreenProtectionGraphic(String)} 1071 */ 1072 public static boolean isObstacle(String symbolID) 1073 { 1074 1075 if(SymbolID.getSymbolSet(symbolID) == SymbolID.SymbolSet_ControlMeasure && 1076 SymbolID.getEntity(symbolID) == 27) 1077 { 1078 return true; 1079 } 1080 else 1081 return false; 1082 } 1083 1084 /** 1085 * Return true if symbol is from the Atmospheric, Oceanographic or Meteorological Space Symbol Sets. 1086 * @param symbolID 30 Character {@link String} 1087 * @return {@link Boolean} 1088 */ 1089 public static boolean isWeather(String symbolID) 1090 { 1091 int ss = SymbolID.getSymbolSet(symbolID); 1092 if(ss >= SymbolID.SymbolSet_Atmospheric && ss <= SymbolID.SymbolSet_MeteorologicalSpace) 1093 return true; 1094 else 1095 return false; 1096 } 1097 1098 /** 1099 * Returns true if the symbol has the HQ staff indicated by the symbol ID 1100 * @param symbolID 30 Character {@link String} 1101 * @return {@link Boolean} 1102 */ 1103 public static boolean isHQ(String symbolID) 1104 { 1105 int hq = SymbolID.getHQTFD(symbolID); 1106 if(SymbolUtilities.hasModifier(symbolID, Modifiers.S_HQ_STAFF_INDICATOR) && 1107 (hq == SymbolID.HQTFD_FeintDummy_Headquarters || 1108 hq == SymbolID.HQTFD_Headquarters || 1109 hq == SymbolID.HQTFD_FeintDummy_TaskForce_Headquarters || 1110 hq == SymbolID.HQTFD_TaskForce_Headquarters)) 1111 return true; 1112 else 1113 return false; 1114 } 1115 1116 /** 1117 * Checks if this is a single point control measure or meteorological graphic with a unique layout. 1118 * Basically anything that's not an action point style graphic with modifiers 1119 * @param symbolID 30 Character {@link String} 1120 * @return {@link Boolean} 1121 */ 1122 public static boolean isSPWithSpecialModifierLayout(String symbolID) 1123 { 1124 int ss = SymbolID.getSymbolSet(symbolID); 1125 int ec = SymbolID.getEntityCode(symbolID); 1126 1127 if(ss == SymbolID.SymbolSet_ControlMeasure) 1128 { 1129 switch(ec) 1130 { 1131 case 130500: //Control Point 1132 case 130700: //Decision Point 1133 case 131300: //Point of Interest 1134 case 131800: //Waypoint 1135 case 131900: //Airfield (AEGIS Only) 1136 case 132000: //Target Handover 1137 case 132100: //Key Terrain 1138 case 132300: //Vital Ground 1139 case 160300: //Target Point Reference 1140 case 180100: //Air Control Point 1141 case 180200: //Communications Check Point 1142 case 180600: //TACAN 1143 case 210300: //Defended Asset 1144 case 210600: //Air Detonation 1145 case 210800: //Impact Point 1146 case 211000: //Launched Torpedo 1147 case 212800: //Harbor 1148 case 213400: //Navigational reference waypoint 1149 case 213500: //Sonobuoy 1150 case 213501: //Ambient Noise Sonobuoy 1151 case 213502: //Air Transportable Communication (ATAC) (Sonobuoy) 1152 case 213503: //Barra (Sonobuoy) 1153 case 213504: 1154 case 213505: 1155 case 213506: 1156 case 213507: 1157 case 213508: 1158 case 213509: 1159 case 213510: 1160 case 213511: 1161 case 213512: 1162 case 213513: 1163 case 213514: 1164 case 213515: 1165 case 214900: //General Sea Subsurface Station 1166 case 215600: //General Sea Station 1167 case 217000: //Shore Control Station 1168 case 240601: //Point or Single Target 1169 case 240602: //Nuclear Target 1170 case 240900: //Fire Support Station 1171 case 250600: //Known Point 1172 case 270701: //Static Depiction 1173 case 282001: //Tower, Low 1174 case 282002: //Tower, High 1175 case 281300: //Chemical Event 1176 case 281301: //Chemical Event - toxic material 1177 case 281400: //Biological Event 1178 case 281402: //Biological Event - toxic material 1179 case 281500: //Nuclear Event 1180 case 281600: //Nuclear Fallout Producing Event 1181 case 281700: //Radiological Event 1182 case 281701: //Radiological Event - toxic material 1183 case 360100: //Protection of cultural property - General 1184 case 360200: //Protection of cultural property - Special 1185 case 360300: //Protection of cultural property - Enhanced 1186 return true; 1187 default: 1188 return false; 1189 } 1190 } 1191 else if(ss == SymbolID.SymbolSet_Atmospheric) 1192 { 1193 switch(ec) 1194 { 1195 case 162300: //Freezing Level 1196 case 162200: //tropopause Level 1197 case 110102: //tropopause low 1198 case 110202: //tropopause high 1199 return true; 1200 default: 1201 return false; 1202 } 1203 } 1204 return false; 1205 } 1206 1207 /** 1208 * Gets the anchor point for single point Control Measure as the anchor point isn't always they center of the symbol. 1209 * @param symbolID 30 Character {@link String} 1210 * @param bounds {@link RectF} representing the bound of the core symbol in the image. 1211 * @return {@link Point} representing the point in the image that is the anchor point of the symbol. 1212 */ 1213 public static Point getCMSymbolAnchorPoint(String symbolID, RectF bounds) { 1214 PointF temp = getCMSymbolAnchorPointF(symbolID,bounds); 1215 return new Point(Math.round(temp.x), Math.round(temp.y)); 1216 } 1217 1218 /** 1219 * Gets the anchor point for single point Control Measure as the anchor point isn't always they center of the symbol. 1220 * @param symbolID 30 Character {@link String} 1221 * @param bounds {@link Rect} representing the bound of the core symbol in the image. 1222 * @return {@link Point} representing the point in the image that is the anchor point of the symbol. 1223 */ 1224 public static Point getCMSymbolAnchorPoint(String symbolID, Rect bounds) { 1225 PointF temp = getCMSymbolAnchorPointF(symbolID,RectUtilities.makeRectFFromRect(bounds)); 1226 return new Point(Math.round(temp.x), Math.round(temp.y)); 1227 } 1228 1229 /** 1230 * Gets the anchor point for single point Control Measure as the anchor point isn't always they center of the symbol. 1231 * @param symbolID 30 Character {@link String} 1232 * @param bounds {@link Rect} representing the bound of the core symbol in the image. 1233 * @return {@link PointF} representing the point in the image that is the anchor point of the symbol. 1234 */ 1235 public static PointF getCMSymbolAnchorPointF(String symbolID, Rect bounds) { 1236 return getCMSymbolAnchorPointF(symbolID,RectUtilities.makeRectFFromRect(bounds)); 1237 } 1238 1239 /** 1240 * Gets the anchor point for single point Control Measure as the anchor point isn't always they center of the symbol. 1241 * @param symbolID 30 Character {@link String} 1242 * @param bounds {@link RectF} representing the bound of the core symbol in the image. 1243 * @return {@link Point} representing the point in the image that is the anchor point of the symbol. 1244 */ 1245 public static PointF getCMSymbolAnchorPointF(String symbolID, RectF bounds) { 1246 float centerX = (bounds.width() / 2f); 1247 float centerY = (bounds.height() / 2f); 1248 1249 int ss = SymbolID.getSymbolSet(symbolID); 1250 int ec = SymbolID.getEntityCode(symbolID); 1251 int drawRule = 0; 1252 1253 //center/anchor point is always half width and half height except for control measures 1254 //and meteorological 1255 if (ss == SymbolID.SymbolSet_ControlMeasure) { 1256 drawRule = MSLookup.getInstance().getMSLInfo(symbolID).getDrawRule(); 1257 switch (drawRule)//here we check the 'Y' value for the anchor point 1258 { 1259 case DrawRules.POINT1://action points 1301 //bottom center 1260 case DrawRules.POINT5://entry point 2105 1261 case DrawRules.POINT6://ground zero 2107 1262 case DrawRules.POINT7://missile detection point 2111 1263 centerY = bounds.height()-1; 1264 break; 1265 case DrawRules.POINT4://drop point 2104 //almost bottom and center 1266 centerY = (bounds.height() * 0.80f); 1267 break; 1268 case DrawRules.POINT10://Sonobuoy 2135 //center of circle which isn't center of symbol 1269 centerY = (bounds.height() * 0.75f); 1270 break; 1271 case DrawRules.POINT13://booby trap 2807 //almost bottom and center 1272 centerY = (bounds.height() * 0.74f); 1273 break; 1274 case DrawRules.POINT15://Marine Life 2189 //center left 1275 centerX = 0; 1276 break; 1277 case DrawRules.POINT16://Tower 282001 //circle at base of tower 1278 centerY = (bounds.height() * 0.89f); 1279 break; 1280 case DrawRules.POINT2://Several different symbols 1281 if (ec == 280500)//Wide Area Antitank Mine 1282 centerY = (bounds.height() * 0.35f); 1283 else if (ec == 280400)//Antitank Mine w/ Anti-handling Device 1284 centerY = (bounds.height() * 0.33f); 1285 else if (ec == 280200)//Antipersonnel Mine 1286 centerY = (bounds.height() * 0.7f); 1287 else if (ec == 280201)//Antipersonnel Mine with Directional Effects 1288 centerY = (bounds.height() * 0.65f); 1289 else if (ec == 219000)//Sea Anomaly 1290 centerY = (bounds.height() * 0.7f); 1291 else if (ec == 212500)//Electromagnetic - Magnetic Anomaly Detections (MAD) 1292 centerY = (bounds.height() * 0.4f); 1293 else if (ec/100 == 2135) {//2525E sonobuoys 1294 centerY = (bounds.height() * 0.75f); 1295 } 1296 break; 1297 default: 1298 } 1299 1300 switch (ec) 1301 //have to adjust center X as some graphics have integrated text outside the symbol 1302 { 1303 case 180400: //Pickup Point (PUP) 1304 centerX = bounds.width() * 0.3341f; 1305 break; 1306 case 240900: //Fire Support Station 1307 centerX = bounds.width() * 0.38f; 1308 break; 1309 case 280201: //Antipersonnel Mine with Directional Effects 1310 centerX = bounds.width() * 0.43f; 1311 break; 1312 case 182300: //Orbit - Figure Eight 1313 case 182400: //Orbit - Race Track 1314 case 182500: //Orbit - Random Closed 1315 if(SymbolID.getVersion(symbolID) >= SymbolID.Version_2525E) 1316 centerY = bounds.height() * 0.27f; 1317 break; 1318 } 1319 } 1320 1321 return new PointF((centerX + bounds.left),(centerY + bounds.top)); 1322 } 1323 1324 /** 1325 * Returns true if the symbol is an installation 1326 * @param symbolID 30 Character {@link String} 1327 * @return {@link Boolean} 1328 */ 1329 public static Boolean isInstallation(String symbolID) 1330 { 1331 int ss = SymbolID.getSymbolSet(symbolID); 1332 int entity = SymbolID.getEntity(symbolID); 1333 if(ss == SymbolID.SymbolSet_LandInstallation && entity == 11) 1334 return true; 1335 else 1336 return false; 1337 } 1338 1339 /** 1340 * Returns true if the symbol is from an air based symbol set 1341 * @param symbolID 30 Character {@link String} 1342 * @return {@link Boolean} 1343 */ 1344 public static Boolean isAir(String symbolID) 1345 { 1346 int ss = SymbolID.getSymbolSet(symbolID); 1347 int entity = SymbolID.getEntity(symbolID); 1348 if(ss == SymbolID.SymbolSet_Air || 1349 ss == SymbolID.SymbolSet_AirMissile || 1350 ss == SymbolID.SymbolSet_SignalsIntelligence_Air) 1351 return true; 1352 else 1353 return false; 1354 } 1355 1356 /** 1357 * Returns true if the symbol is from a space based symbol set 1358 * @param symbolID 30 Character {@link String} 1359 * @return {@link Boolean} 1360 */ 1361 public static Boolean isSpace(String symbolID) 1362 { 1363 int ss = SymbolID.getSymbolSet(symbolID); 1364 int entity = SymbolID.getEntity(symbolID); 1365 if(ss == SymbolID.SymbolSet_Space || 1366 ss == SymbolID.SymbolSet_SpaceMissile || 1367 ss == SymbolID.SymbolSet_SignalsIntelligence_Space) 1368 return true; 1369 else 1370 return false; 1371 } 1372 1373 /** 1374 * Returns true if the symbol is from a land based symbol set 1375 * @param symbolID 30 Character {@link String} 1376 * @return {@link Boolean} 1377 */ 1378 public static Boolean isLand(String symbolID) 1379 { 1380 int ss = SymbolID.getSymbolSet(symbolID); 1381 int entity = SymbolID.getEntity(symbolID); 1382 if(ss == SymbolID.SymbolSet_LandUnit || 1383 ss == SymbolID.SymbolSet_LandCivilianUnit_Organization || 1384 ss == SymbolID.SymbolSet_LandEquipment || 1385 ss == SymbolID.SymbolSet_LandInstallation || 1386 ss == SymbolID.SymbolSet_SignalsIntelligence_Land) 1387 return true; 1388 else 1389 return false; 1390 } 1391 1392 /** 1393 * Returns true if the symbol ID has the task for indicator 1394 * @param symbolID 30 Character {@link String} 1395 * @return {@link Boolean} 1396 */ 1397 public static Boolean isTaskForce(String symbolID) 1398 { 1399 int hqtfd = SymbolID.getHQTFD(symbolID); 1400 if((hqtfd == SymbolID.HQTFD_TaskForce || 1401 hqtfd == SymbolID.HQTFD_TaskForce_Headquarters || 1402 hqtfd == SymbolID.HQTFD_FeintDummy_TaskForce || 1403 hqtfd == SymbolID.HQTFD_FeintDummy_TaskForce_Headquarters) && 1404 SymbolUtilities.canSymbolHaveModifier(symbolID, Modifiers.B_ECHELON)) 1405 return true; 1406 else 1407 return false; 1408 } 1409 1410 /** 1411 * Returns true if the symbol ID indicates the context is Reality 1412 * @param symbolID 30 Character {@link String} 1413 * @return {@link Boolean} 1414 */ 1415 public static Boolean isReality(String symbolID) 1416 { 1417 int c = SymbolID.getContext(symbolID); 1418 if(c == SymbolID.StandardIdentity_Context_Reality || 1419 c == 3 || c == 4) 1420 return true; 1421 else 1422 return false; 1423 } 1424 1425 /** 1426 * Returns true if the symbol ID indicates the context is Exercise 1427 * @param symbolID 30 Character {@link String} 1428 * @return {@link Boolean} 1429 */ 1430 public static Boolean isExercise(String symbolID) 1431 { 1432 int c = SymbolID.getContext(symbolID); 1433 if(c == SymbolID.StandardIdentity_Context_Exercise || 1434 c == 5 || c == 6) 1435 return true; 1436 else 1437 return false; 1438 } 1439 1440 /** 1441 * Returns true if the symbol ID indicates the context is Simulation 1442 * @param symbolID 30 Character {@link String} 1443 * @return {@link Boolean} 1444 */ 1445 public static Boolean isSimulation(String symbolID) 1446 { 1447 int c = SymbolID.getContext(symbolID); 1448 if(c == SymbolID.StandardIdentity_Context_Simulation || 1449 c == 7 || c == 8) 1450 return true; 1451 else 1452 return false; 1453 } 1454 1455 1456 /** 1457 * Reads the Symbol ID string and returns the text that represents the echelon 1458 * code. 1459 * @param echelon {@link Integer} from positions 9-10 in the symbol ID 1460 * See {@link SymbolID#getAmplifierDescriptor(String)} 1461 * @return {@link String} (23 (Army) would be "XXXX") 1462 */ 1463 public static String getEchelonText(int echelon) 1464 { 1465 char[] dots = new char[3]; 1466 dots[0] = (char)8226; 1467 dots[1] = (char)8226; 1468 dots[2] = (char)8226; 1469 String dot = new String(dots); 1470 String text = null; 1471 if(echelon == SymbolID.Echelon_Team_Crew) 1472 { 1473 text = (char) 216 + ""; 1474 } 1475 else if(echelon == SymbolID.Echelon_Squad) 1476 { 1477 text = dot.substring(0, 1); 1478 } 1479 else if(echelon == SymbolID.Echelon_Section) 1480 { 1481 text = dot.substring(0, 2); 1482 } 1483 else if(echelon == SymbolID.Echelon_Platoon_Detachment) 1484 { 1485 text = dot; 1486 } 1487 else if(echelon == SymbolID.Echelon_Company_Battery_Troop) 1488 { 1489 text = "I"; 1490 } 1491 else if(echelon == SymbolID.Echelon_Battalion_Squadron) 1492 { 1493 text = "II"; 1494 } 1495 else if(echelon == SymbolID.Echelon_Regiment_Group) 1496 { 1497 text = "III"; 1498 } 1499 else if(echelon == SymbolID.Echelon_Brigade) 1500 { 1501 text = "X"; 1502 } 1503 else if(echelon == SymbolID.Echelon_Division) 1504 { 1505 text = "XX"; 1506 } 1507 else if(echelon == SymbolID.Echelon_Corps_MEF) 1508 { 1509 text = "XXX"; 1510 } 1511 else if(echelon == SymbolID.Echelon_Army) 1512 { 1513 text = "XXXX"; 1514 } 1515 else if(echelon == SymbolID.Echelon_ArmyGroup_Front) 1516 { 1517 text = "XXXXX"; 1518 } 1519 else if(echelon == SymbolID.Echelon_Region_Theater) 1520 { 1521 text = "XXXXXX"; 1522 } 1523 else if(echelon == SymbolID.Echelon_Region_Command) 1524 { 1525 text = "++"; 1526 } 1527 return text; 1528 } 1529 1530 /** 1531 * Returns the Standard Identity Modifier based on the Symbol ID 1532 * @param symbolID 30 Character {@link String} 1533 * @return {@link String} 1534 */ 1535 public static String getStandardIdentityModifier(String symbolID) 1536 { 1537 String textChar = null; 1538 int si = SymbolID.getStandardIdentity(symbolID); 1539 int context = SymbolID.getContext(symbolID); 1540 int affiliation = SymbolID.getAffiliation(symbolID); 1541 1542 if(context == SymbolID.StandardIdentity_Context_Simulation)//Simulation 1543 textChar = "S"; 1544 else if(context == SymbolID.StandardIdentity_Context_Exercise) 1545 { 1546 if(affiliation == SymbolID.StandardIdentity_Affiliation_Suspect_Joker)//exercise Joker 1547 textChar = "J"; 1548 else if(affiliation == SymbolID.StandardIdentity_Affiliation_Hostile_Faker)//exercise faker 1549 textChar = "K"; 1550 else if(context == SymbolID.StandardIdentity_Context_Exercise)//exercise 1551 textChar = "X"; 1552 } 1553 1554 return textChar; 1555 } 1556 1557 /** 1558 * 1559 * @param symbolID 1560 * @return 1561 */ 1562 public static boolean hasRectangleFrame(String symbolID) 1563 { 1564 int affiliation = SymbolID.getAffiliation(symbolID); 1565 int ss = SymbolID.getSymbolSet(symbolID); 1566 if(ss != SymbolID.SymbolSet_ControlMeasure) 1567 { 1568 if (affiliation == SymbolID.StandardIdentity_Affiliation_Friend 1569 || affiliation == SymbolID.StandardIdentity_Affiliation_AssumedFriend 1570 || (SymbolID.getContext(symbolID)==SymbolID.StandardIdentity_Context_Exercise && 1571 (affiliation == SymbolID.StandardIdentity_Affiliation_Hostile_Faker 1572 || affiliation == SymbolID.StandardIdentity_Affiliation_Suspect_Joker))) 1573 { 1574 return true; 1575 } 1576 else 1577 return false; 1578 } 1579 else 1580 return false; 1581 } 1582 1583 /** 1584 * Returns the height ratio for the unit specified by the symbol ID 1585 * Based on Figure 4 in 2525E. 1586 * @param symbolID 30 Character {@link String} 1587 * @return {@link Float} 1588 */ 1589 public static float getUnitRatioHeight(String symbolID) 1590 { 1591 int ver = SymbolID.getVersion(symbolID); 1592 int aff = SymbolID.getAffiliation(symbolID); 1593 1594 float rh = 0; 1595 1596 if(ver < SymbolID.Version_2525E) 1597 { 1598 int ss = SymbolID.getSymbolSet(symbolID); 1599 1600 if(aff == SymbolID.StandardIdentity_Affiliation_Hostile_Faker || 1601 aff == SymbolID.StandardIdentity_Affiliation_Suspect_Joker) 1602 { 1603 switch (ss){ 1604 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 1605 case SymbolID.SymbolSet_LandUnit: 1606 case SymbolID.SymbolSet_LandInstallation: 1607 case SymbolID.SymbolSet_LandEquipment: 1608 case SymbolID.SymbolSet_SignalsIntelligence_Land: 1609 case SymbolID.SymbolSet_Activities: 1610 case SymbolID.SymbolSet_CyberSpace: 1611 rh = 1.44f; 1612 break; 1613 default: 1614 rh=1.3f; 1615 } 1616 } 1617 else if(aff == SymbolID.StandardIdentity_Affiliation_Friend || 1618 aff == SymbolID.StandardIdentity_Affiliation_AssumedFriend) 1619 { 1620 switch (ss){ 1621 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 1622 case SymbolID.SymbolSet_LandUnit: 1623 case SymbolID.SymbolSet_LandInstallation: 1624 case SymbolID.SymbolSet_Activities: 1625 case SymbolID.SymbolSet_CyberSpace: 1626 rh = 1f; 1627 break; 1628 case SymbolID.SymbolSet_SignalsIntelligence_Land: 1629 default: 1630 rh=1.2f; 1631 } 1632 } 1633 else if(aff == SymbolID.StandardIdentity_Affiliation_Neutral) 1634 { 1635 switch (ss){ 1636 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 1637 case SymbolID.SymbolSet_LandUnit: 1638 case SymbolID.SymbolSet_LandInstallation: 1639 case SymbolID.SymbolSet_LandEquipment: 1640 case SymbolID.SymbolSet_SignalsIntelligence_Land: 1641 case SymbolID.SymbolSet_Activities: 1642 case SymbolID.SymbolSet_CyberSpace: 1643 rh = 1.1f; 1644 break; 1645 default: 1646 rh=1.2f; 1647 } 1648 } 1649 else //UNKNOWN 1650 { 1651 switch (ss){ 1652 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 1653 case SymbolID.SymbolSet_LandUnit: 1654 case SymbolID.SymbolSet_LandInstallation: 1655 case SymbolID.SymbolSet_LandEquipment: 1656 case SymbolID.SymbolSet_SignalsIntelligence_Land: 1657 case SymbolID.SymbolSet_Activities: 1658 case SymbolID.SymbolSet_CyberSpace: 1659 rh = 1.44f; 1660 break; 1661 default: 1662 rh=1.3f; 1663 } 1664 } 1665 } 1666 else //2525E and up 1667 { 1668 String frameID = SVGLookup.getFrameID(symbolID); 1669 if(frameID.length()==6) 1670 aff = Integer.parseInt(frameID.substring(2,3)); 1671 else //"octagon" 1672 return 1f; 1673 char fs = (frameID.charAt(3)); 1674 1675 if(aff == SymbolID.StandardIdentity_Affiliation_Hostile_Faker || 1676 aff == SymbolID.StandardIdentity_Affiliation_Suspect_Joker) 1677 { 1678 switch (fs){ 1679 case SymbolID.FrameShape_LandUnit: 1680 case SymbolID.FrameShape_LandInstallation: 1681 case SymbolID.FrameShape_LandEquipment: 1682 case SymbolID.FrameShape_SeaSurface: 1683 case SymbolID.FrameShape_Activity_Event: 1684 case SymbolID.FrameShape_Cyberspace: 1685 rh = 1.44f; 1686 break; 1687 default: 1688 rh=1.3f; 1689 } 1690 } 1691 else if(aff == SymbolID.StandardIdentity_Affiliation_Friend || 1692 aff == SymbolID.StandardIdentity_Affiliation_AssumedFriend) 1693 { 1694 switch (fs){ 1695 case SymbolID.FrameShape_LandUnit: 1696 case SymbolID.FrameShape_LandInstallation: 1697 case SymbolID.FrameShape_Activity_Event: 1698 case SymbolID.FrameShape_Cyberspace: 1699 rh = 1f; 1700 break; 1701 default: 1702 rh=1.2f; 1703 } 1704 } 1705 else if(aff == SymbolID.StandardIdentity_Affiliation_Neutral) 1706 { 1707 switch (fs){ 1708 case SymbolID.FrameShape_LandUnit: 1709 case SymbolID.FrameShape_LandInstallation: 1710 case SymbolID.FrameShape_LandEquipment: 1711 case SymbolID.FrameShape_SeaSurface: 1712 case SymbolID.FrameShape_Activity_Event: 1713 case SymbolID.FrameShape_Cyberspace: 1714 rh = 1.1f; 1715 break; 1716 default: 1717 rh=1.2f; 1718 } 1719 } 1720 else //UNKNOWN 1721 { 1722 switch (fs){ 1723 case SymbolID.FrameShape_LandUnit: 1724 case SymbolID.FrameShape_LandInstallation: 1725 case SymbolID.FrameShape_LandEquipment: 1726 case SymbolID.FrameShape_SeaSurface: 1727 case SymbolID.FrameShape_Activity_Event: 1728 case SymbolID.FrameShape_Cyberspace: 1729 rh = 1.44f; 1730 break; 1731 default: 1732 rh=1.3f; 1733 } 1734 } 1735 1736 1737 } 1738 1739 return rh; 1740 } 1741 1742 /** 1743 * Returns the width ratio for the unit specified by the symbol ID 1744 * Based on Figure 4 in 2525E. 1745 * @param symbolID 30 Character {@link String} 1746 * @return {@link Float} 1747 */ 1748 public static float getUnitRatioWidth(String symbolID) 1749 { 1750 int ver = SymbolID.getVersion(symbolID); 1751 int aff = SymbolID.getAffiliation(symbolID); 1752 1753 float rw = 0; 1754 1755 if(ver < SymbolID.Version_2525E) 1756 { 1757 int ss = SymbolID.getSymbolSet(symbolID); 1758 1759 if(aff == SymbolID.StandardIdentity_Affiliation_Hostile_Faker || 1760 aff == SymbolID.StandardIdentity_Affiliation_Suspect_Joker) 1761 { 1762 switch (ss){ 1763 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 1764 case SymbolID.SymbolSet_LandUnit: 1765 case SymbolID.SymbolSet_LandInstallation: 1766 case SymbolID.SymbolSet_LandEquipment: 1767 case SymbolID.SymbolSet_SignalsIntelligence_Land: 1768 case SymbolID.SymbolSet_Activities: 1769 case SymbolID.SymbolSet_CyberSpace: 1770 rw = 1.44f; 1771 break; 1772 default: 1773 rw=1.1f; 1774 } 1775 } 1776 else if(aff == SymbolID.StandardIdentity_Affiliation_Friend || 1777 aff == SymbolID.StandardIdentity_Affiliation_AssumedFriend) 1778 { 1779 switch (ss){ 1780 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 1781 case SymbolID.SymbolSet_LandUnit: 1782 case SymbolID.SymbolSet_LandInstallation: 1783 case SymbolID.SymbolSet_Activities: 1784 case SymbolID.SymbolSet_CyberSpace: 1785 rw = 1.5f; 1786 break; 1787 case SymbolID.SymbolSet_LandEquipment: 1788 case SymbolID.SymbolSet_SignalsIntelligence_Land: 1789 rw = 1.2f; 1790 break; 1791 default: 1792 rw=1.1f; 1793 } 1794 } 1795 else if(aff == SymbolID.StandardIdentity_Affiliation_Neutral) 1796 { 1797 rw = 1.1f; 1798 } 1799 else //UNKNOWN 1800 { 1801 switch (ss){ 1802 case SymbolID.SymbolSet_LandCivilianUnit_Organization: 1803 case SymbolID.SymbolSet_LandUnit: 1804 case SymbolID.SymbolSet_LandInstallation: 1805 case SymbolID.SymbolSet_LandEquipment: 1806 case SymbolID.SymbolSet_SignalsIntelligence_Land: 1807 case SymbolID.SymbolSet_Activities: 1808 case SymbolID.SymbolSet_CyberSpace: 1809 rw = 1.44f; 1810 break; 1811 default: 1812 rw=1.5f; 1813 } 1814 } 1815 } 1816 else //2525E and above 1817 { 1818 String frameID = SVGLookup.getFrameID(symbolID); 1819 if(frameID.length()==6) 1820 aff = Integer.parseInt(frameID.substring(2,3)); 1821 else //"octagon" 1822 return 1f; 1823 char fs = (frameID.charAt(3)); 1824 1825 if(aff == SymbolID.StandardIdentity_Affiliation_Hostile_Faker || 1826 aff == SymbolID.StandardIdentity_Affiliation_Suspect_Joker) 1827 { 1828 switch (fs){ 1829 case SymbolID.FrameShape_LandUnit: 1830 case SymbolID.FrameShape_LandInstallation: 1831 case SymbolID.FrameShape_LandEquipment: 1832 case SymbolID.FrameShape_SeaSurface: 1833 case SymbolID.FrameShape_Activity_Event: 1834 case SymbolID.FrameShape_Cyberspace: 1835 rw = 1.44f; 1836 break; 1837 default: 1838 rw=1.1f; 1839 } 1840 } 1841 else if(aff == SymbolID.StandardIdentity_Affiliation_Friend || 1842 aff == SymbolID.StandardIdentity_Affiliation_AssumedFriend) 1843 { 1844 switch (fs){ 1845 case SymbolID.FrameShape_LandUnit: 1846 case SymbolID.FrameShape_LandInstallation: 1847 case SymbolID.FrameShape_Activity_Event: 1848 case SymbolID.FrameShape_Cyberspace: 1849 rw = 1.5f; 1850 break; 1851 case SymbolID.FrameShape_LandEquipment: 1852 case SymbolID.FrameShape_SeaSurface: 1853 rw = 1.2f; 1854 break; 1855 default: 1856 rw=1.1f; 1857 } 1858 } 1859 else if(aff == SymbolID.StandardIdentity_Affiliation_Neutral) 1860 { 1861 rw = 1.1f; 1862 } 1863 else //UNKNOWN 1864 { 1865 switch (fs){ 1866 case SymbolID.FrameShape_LandUnit: 1867 case SymbolID.FrameShape_LandInstallation: 1868 case SymbolID.FrameShape_LandEquipment: 1869 case SymbolID.FrameShape_SeaSurface: 1870 case SymbolID.FrameShape_Activity_Event: 1871 case SymbolID.FrameShape_Cyberspace: 1872 rw = 1.44f; 1873 break; 1874 default: 1875 rw=1.5f; 1876 } 1877 } 1878 } 1879 1880 return rw; 1881 } 1882 1883 /** 1884 * @param linetype the line type 1885 * @return true if the line is a basic shape 1886 */ 1887 public static boolean isBasicShape(int linetype) { 1888 switch (linetype) { 1889 case TacticalLines.BS_AREA: 1890 case TacticalLines.BS_LINE: 1891 case TacticalLines.BS_CROSS: 1892 case TacticalLines.BS_ELLIPSE: 1893 case TacticalLines.PBS_ELLIPSE: 1894 case TacticalLines.PBS_CIRCLE: 1895 case TacticalLines.PBS_SQUARE: 1896 case TacticalLines.PBS_RECTANGLE: 1897 case TacticalLines.BS_RECTANGLE: 1898 case TacticalLines.BBS_AREA: 1899 case TacticalLines.BBS_LINE: 1900 case TacticalLines.BBS_POINT: 1901 case TacticalLines.BBS_RECTANGLE: 1902 case TacticalLines.BS_BBOX: 1903 case TacticalLines.BS_ROUTE: 1904 case TacticalLines.BS_TRACK: 1905 case TacticalLines.BS_RADARC: 1906 case TacticalLines.BS_CAKE: 1907 case TacticalLines.BS_ORBIT: 1908 case TacticalLines.BS_POLYARC: 1909 return true; 1910 default: 1911 return false; 1912 } 1913 } 1914}