001/* 002 * To change this template, choose Tools | Templates 003 * and open the template in the editor. 004 */ 005package armyc2.c5isr.JavaTacticalRenderer; 006 007import armyc2.c5isr.JavaLineArray.TacticalLines; 008import armyc2.c5isr.JavaLineArray.arraysupport; 009import armyc2.c5isr.JavaLineArray.lineutility; 010import armyc2.c5isr.JavaLineArray.POINT2; 011import armyc2.c5isr.JavaLineArray.ref; 012import java.util.ArrayList; 013import java.util.HashMap; 014 015import armyc2.c5isr.JavaLineArray.Shape2; 016import java.io.*; 017 018import armyc2.c5isr.RenderMultipoints.clsRenderer; 019import armyc2.c5isr.renderer.utilities.DrawRules; 020import armyc2.c5isr.renderer.utilities.IPointConversion; 021import armyc2.c5isr.renderer.utilities.MSInfo; 022import armyc2.c5isr.renderer.utilities.MSLookup; 023import armyc2.c5isr.renderer.utilities.RendererUtilities; 024import armyc2.c5isr.renderer.utilities.ErrorLogger; 025import armyc2.c5isr.renderer.utilities.RendererException; 026import armyc2.c5isr.renderer.utilities.Color; 027import armyc2.c5isr.graphics2d.BasicStroke; 028import armyc2.c5isr.graphics2d.BufferedImage; 029import armyc2.c5isr.graphics2d.Graphics2D; 030import armyc2.c5isr.graphics2d.Line2D; 031import armyc2.c5isr.graphics2d.Point2D; 032import armyc2.c5isr.graphics2d.Polygon; 033import armyc2.c5isr.graphics2d.Rectangle2D; 034import armyc2.c5isr.graphics2d.TexturePaint; 035import armyc2.c5isr.renderer.utilities.SymbolID; 036 037/** 038 * A general utility class for the tactical renderer 039* 040 */ 041public final class clsUtility { 042 private static final String _className = "clsUtility"; 043 protected static Point2D POINT2ToPoint2D(POINT2 pt2) { 044 if (pt2 == null) { 045 return null; 046 } 047 048 double x = pt2.x; 049 double y = pt2.y; 050 Point2D pt = new Point2D.Double(x, y); 051 return pt; 052 } 053 /** 054 * returns true if the line segments are all outside the bounds 055 * @param tg the tactical graphic 056 * @param clipBounds the pixels based clip bounds 057 * @return 058 */ 059 public static boolean linesOutsideClipBounds(TGLight tg, 060 Rectangle2D clipBounds) 061 { 062 try 063 { 064 boolean isAutoshape=isAutoshape(tg); 065 if(isAutoshape) 066 return false; 067 068 double xmin=clipBounds.getMinX(); 069 double xmax=clipBounds.getMaxX(); 070 double ymin=clipBounds.getMinY(); 071 double ymax=clipBounds.getMaxY(); 072 int j=0; 073 POINT2 pt0=null,pt1=null; 074 Line2D boundsEdge=null,ptsLine=null; 075 int n=tg.Pixels.size(); 076 //for(j=0;j<tg.Pixels.size()-1;j++) 077 for(j=0;j<n-1;j++) 078 { 079 pt0=tg.Pixels.get(j); 080 pt1=tg.Pixels.get(j+1); 081 082 //if either point is inside the bounds return false 083 if(clipBounds.contains(pt0.x, pt0.y)) 084 return false; 085 if(clipBounds.contains(pt1.x, pt1.y)) 086 return false; 087 088 ptsLine=new Line2D.Double(pt0.x,pt0.y,pt1.x,pt1.y); 089 090 //if the pt0-pt1 line intersects any clip bounds edge then return false 091 boundsEdge=new Line2D.Double(xmin,ymin,xmax,ymin); 092 if(ptsLine.intersectsLine(boundsEdge)) 093 return false; 094 095 boundsEdge=new Line2D.Double(xmax,ymin,xmax,ymax); 096 if(ptsLine.intersectsLine(boundsEdge)) 097 return false; 098 099 boundsEdge=new Line2D.Double(xmax,ymax,xmin,ymax); 100 if(ptsLine.intersectsLine(boundsEdge)) 101 return false; 102 103 boundsEdge=new Line2D.Double(xmin,ymax,xmin,ymin); 104 if(ptsLine.intersectsLine(boundsEdge)) 105 return false; 106 } 107 } 108 catch (Exception exc) 109 { 110 ErrorLogger.LogException(_className ,"linesOutsideClipBounds", 111 new RendererException("Failed inside linesOutsideClipBounds", exc)); 112 } 113 return true; 114 } 115 /** 116 * Returns the minimum client points needed for the symbol 117 * @param lineType line type 118 * @return minimum number of clients required to render the line 119 * @deprecated use MSInfo.getMinPointCount() 120 */ 121 public static int GetMinPoints(int lineType) { 122 int result = -1; 123 switch (lineType) { 124 case TacticalLines.RECTANGULAR: 125 case TacticalLines.CUED_ACQUISITION: 126 case TacticalLines.CIRCULAR: 127 case TacticalLines.PBS_CIRCLE: 128 case TacticalLines.BDZ: 129 case TacticalLines.FSA_CIRCULAR: 130 case TacticalLines.NOTACK: 131 case TacticalLines.FFA_CIRCULAR: 132 case TacticalLines.NFA_CIRCULAR: 133 case TacticalLines.RFA_CIRCULAR: 134 case TacticalLines.ACA_CIRCULAR: 135 case TacticalLines.PAA_CIRCULAR: 136 case TacticalLines.ATI_CIRCULAR: 137 case TacticalLines.CFFZ_CIRCULAR: 138 case TacticalLines.SENSOR_CIRCULAR: 139 case TacticalLines.CENSOR_CIRCULAR: 140 case TacticalLines.DA_CIRCULAR: 141 case TacticalLines.CFZ_CIRCULAR: 142 case TacticalLines.ZOR_CIRCULAR: 143 case TacticalLines.TBA_CIRCULAR: 144 case TacticalLines.TVAR_CIRCULAR: 145 case TacticalLines.KILLBOXBLUE_CIRCULAR: 146 case TacticalLines.KILLBOXPURPLE_CIRCULAR: 147 case TacticalLines.LAUNCH_AREA: 148 case TacticalLines.DEFENDED_AREA_CIRCULAR: 149 case TacticalLines.SHIP_AOI_CIRCULAR: 150 case TacticalLines.PBS_ELLIPSE: 151 case TacticalLines.RANGE_FAN: 152 case TacticalLines.RANGE_FAN_SECTOR: 153 case TacticalLines.RADAR_SEARCH: 154 result = 1; 155 break; 156 case TacticalLines.PAA_RECTANGULAR: 157 case TacticalLines.RECTANGULAR_TARGET: 158 case TacticalLines.FSA_RECTANGULAR: 159 case TacticalLines.SHIP_AOI_RECTANGULAR: 160 case TacticalLines.DEFENDED_AREA_RECTANGULAR: 161 case TacticalLines.FFA_RECTANGULAR: 162 case TacticalLines.RFA_RECTANGULAR: 163 case TacticalLines.NFA_RECTANGULAR: 164 case TacticalLines.ACA_RECTANGULAR: 165 case TacticalLines.ATI_RECTANGULAR: 166 case TacticalLines.CFFZ_RECTANGULAR: 167 case TacticalLines.SENSOR_RECTANGULAR: 168 case TacticalLines.CENSOR_RECTANGULAR: 169 case TacticalLines.DA_RECTANGULAR: 170 case TacticalLines.CFZ_RECTANGULAR: 171 case TacticalLines.ZOR_RECTANGULAR: 172 case TacticalLines.TBA_RECTANGULAR: 173 case TacticalLines.TVAR_RECTANGULAR: 174 case TacticalLines.KILLBOXBLUE_RECTANGULAR: 175 case TacticalLines.KILLBOXPURPLE_RECTANGULAR: 176 result = 2; //was 3 177 break; 178 case TacticalLines.SPTBYFIRE: 179 case TacticalLines.RIP: 180 case TacticalLines.MOBILE_DEFENSE: 181 case TacticalLines.DEMONSTRATE: 182 case TacticalLines.GAP: 183 case TacticalLines.ASLTXING: 184 case TacticalLines.MSDZ: 185 result = 4; 186 break; 187 case TacticalLines.BYPASS: 188 case TacticalLines.BLOCK: 189 case TacticalLines.BREACH: 190 case TacticalLines.CANALIZE: 191 case TacticalLines.CLEAR: 192 case TacticalLines.CONTAIN: 193 case TacticalLines.DELAY: 194 case TacticalLines.DISRUPT: 195 case TacticalLines.PENETRATE: 196 case TacticalLines.RETIRE: 197 case TacticalLines.PURSUIT: 198 case TacticalLines.ENVELOPMENT: 199 case TacticalLines.FPOL: 200 case TacticalLines.RPOL: 201 case TacticalLines.SCREEN: 202 case TacticalLines.COVER: 203 case TacticalLines.GUARD: 204 case TacticalLines.SEIZE: 205 case TacticalLines.CAPTURE: 206 case TacticalLines.ESCORT: 207 case TacticalLines.EVACUATE: 208 case TacticalLines.WITHDRAW: 209 case TacticalLines.DISENGAGE: 210 case TacticalLines.WDRAWUP: 211 //non task autoshapes 212 case TacticalLines.SARA: 213 case TacticalLines.DECEIVE: 214 case TacticalLines.PDF: 215 case TacticalLines.IL: 216 case TacticalLines.ATKBYFIRE: 217 case TacticalLines.AMBUSH: 218 case TacticalLines.RELEASE: 219 case TacticalLines.HOL: 220 case TacticalLines.BHL: 221 case TacticalLines.MNFLDBLK: 222 case TacticalLines.MNFLDDIS: 223 case TacticalLines.TURN_REVD: 224 case TacticalLines.TURN: 225 case TacticalLines.PLANNED: 226 case TacticalLines.ESR1: 227 case TacticalLines.ESR2: 228 case TacticalLines.ROADBLK: 229 case TacticalLines.EASY: 230 case TacticalLines.BYDIF: 231 case TacticalLines.BYIMP: 232 case TacticalLines.FORDSITE: 233 case TacticalLines.FORDIF: 234 //METOCs 235 case TacticalLines.IFR: 236 case TacticalLines.MVFR: 237 case TacticalLines.TURBULENCE: 238 case TacticalLines.ICING: 239 case TacticalLines.NON_CONVECTIVE: 240 case TacticalLines.CONVECTIVE: 241 case TacticalLines.FROZEN: 242 case TacticalLines.THUNDERSTORMS: 243 case TacticalLines.FOG: 244 case TacticalLines.SAND: 245 case TacticalLines.FREEFORM: 246 case TacticalLines.DEPTH_AREA: 247 case TacticalLines.ISLAND: 248 case TacticalLines.BEACH: 249 case TacticalLines.WATER: 250 case TacticalLines.FISH_TRAPS: 251 case TacticalLines.SWEPT_AREA: 252 case TacticalLines.OIL_RIG_FIELD: 253 case TacticalLines.FOUL_GROUND: 254 case TacticalLines.KELP: 255 case TacticalLines.BEACH_SLOPE_MODERATE: 256 case TacticalLines.BEACH_SLOPE_STEEP: 257 case TacticalLines.ANCHORAGE_AREA: 258 case TacticalLines.TRAINING_AREA: 259 case TacticalLines.FORESHORE_AREA: 260 case TacticalLines.DRYDOCK: 261 case TacticalLines.LOADING_FACILITY_AREA: 262 case TacticalLines.PERCHES: 263 case TacticalLines.UNDERWATER_HAZARD: 264 case TacticalLines.DISCOLORED_WATER: 265 case TacticalLines.BEACH_SLOPE_FLAT: 266 case TacticalLines.BEACH_SLOPE_GENTLE: 267 case TacticalLines.MARITIME_AREA: 268 case TacticalLines.OPERATOR_DEFINED: 269 case TacticalLines.SUBMERGED_CRIB: 270 case TacticalLines.VDR_LEVEL_12: 271 case TacticalLines.VDR_LEVEL_23: 272 case TacticalLines.VDR_LEVEL_34: 273 case TacticalLines.VDR_LEVEL_45: 274 case TacticalLines.VDR_LEVEL_56: 275 case TacticalLines.VDR_LEVEL_67: 276 case TacticalLines.VDR_LEVEL_78: 277 case TacticalLines.VDR_LEVEL_89: 278 case TacticalLines.VDR_LEVEL_910: 279 case TacticalLines.SOLID_ROCK: 280 case TacticalLines.CLAY: 281 case TacticalLines.VERY_COARSE_SAND: 282 case TacticalLines.COARSE_SAND: 283 case TacticalLines.MEDIUM_SAND: 284 case TacticalLines.FINE_SAND: 285 case TacticalLines.VERY_FINE_SAND: 286 case TacticalLines.VERY_FINE_SILT: 287 case TacticalLines.FINE_SILT: 288 case TacticalLines.MEDIUM_SILT: 289 case TacticalLines.COARSE_SILT: 290 case TacticalLines.BOULDERS: 291 case TacticalLines.OYSTER_SHELLS: 292 case TacticalLines.PEBBLES: 293 case TacticalLines.SAND_AND_SHELLS: 294 case TacticalLines.BOTTOM_SEDIMENTS_LAND: 295 case TacticalLines.BOTTOM_SEDIMENTS_NO_DATA: 296 case TacticalLines.BOTTOM_ROUGHNESS_SMOOTH: 297 case TacticalLines.BOTTOM_ROUGHNESS_MODERATE: 298 case TacticalLines.BOTTOM_ROUGHNESS_ROUGH: 299 case TacticalLines.CLUTTER_LOW: 300 case TacticalLines.CLUTTER_MEDIUM: 301 case TacticalLines.CLUTTER_HIGH: 302 case TacticalLines.IMPACT_BURIAL_0: 303 case TacticalLines.IMPACT_BURIAL_10: 304 case TacticalLines.IMPACT_BURIAL_20: 305 case TacticalLines.IMPACT_BURIAL_75: 306 case TacticalLines.IMPACT_BURIAL_100: 307 case TacticalLines.BOTTOM_CATEGORY_A: 308 case TacticalLines.BOTTOM_CATEGORY_B: 309 case TacticalLines.BOTTOM_CATEGORY_C: 310 case TacticalLines.BOTTOM_TYPE_A1: 311 case TacticalLines.BOTTOM_TYPE_A2: 312 case TacticalLines.BOTTOM_TYPE_A3: 313 case TacticalLines.BOTTOM_TYPE_B1: 314 case TacticalLines.BOTTOM_TYPE_B2: 315 case TacticalLines.BOTTOM_TYPE_B3: 316 case TacticalLines.BOTTOM_TYPE_C1: 317 case TacticalLines.BOTTOM_TYPE_C2: 318 case TacticalLines.BOTTOM_TYPE_C3: 319 result = 3; 320 break; 321 case TacticalLines.MRR: 322 case TacticalLines.SL: 323 case TacticalLines.TC: 324 case TacticalLines.SC: 325 case TacticalLines.LLTR: 326 case TacticalLines.DIRATKAIR: 327 case TacticalLines.ABATIS: 328 case TacticalLines.CLUSTER: 329 case TacticalLines.MNFLDFIX: 330 case TacticalLines.FERRY: 331 case TacticalLines.MFLANE: 332 case TacticalLines.RAFT: 333 case TacticalLines.FOXHOLE: 334 case TacticalLines.LINTGT: 335 case TacticalLines.LINTGTS: 336 case TacticalLines.FPF: 337 case TacticalLines.CONVOY: 338 case TacticalLines.HCONVOY: 339 result = 2; 340 break; 341 default: 342 result = 2; 343 break; 344 } 345 if (isClosedPolygon(lineType)) { 346 result = 3; 347 } 348 //add code for change 1 areas 349 return result; 350 } 351 /** 352 * @param linetype line type 353 * @return true if the line is a closed area 354 */ 355 public static boolean isClosedPolygon(int linetype) { 356 boolean result = false; 357 switch (linetype) { 358 case TacticalLines.BBS_AREA: 359 case TacticalLines.BS_BBOX: 360 case TacticalLines.AT: 361 case TacticalLines.DEPICT: 362 case TacticalLines.DZ: 363 case TacticalLines.MINED: 364 case TacticalLines.FENCED: 365 case TacticalLines.UXO: 366 case TacticalLines.ROZ: 367 case TacticalLines.AARROZ: 368 case TacticalLines.UAROZ: 369 case TacticalLines.WEZ: 370 case TacticalLines.FEZ: 371 case TacticalLines.JEZ: 372 case TacticalLines.FAADZ: 373 case TacticalLines.HIDACZ: 374 case TacticalLines.MEZ: 375 case TacticalLines.LOMEZ: 376 case TacticalLines.HIMEZ: 377 case TacticalLines.WFZ_REVD: 378 case TacticalLines.WFZ: 379 case TacticalLines.PNO: 380 case TacticalLines.BATTLE: 381 case TacticalLines.EA: 382 case TacticalLines.EZ: 383 case TacticalLines.LZ: 384 case TacticalLines.PZ: 385 case TacticalLines.GENERAL: 386 case TacticalLines.JTAA: 387 case TacticalLines.SAA: 388 case TacticalLines.SGAA: 389 case TacticalLines.BS_AREA: 390 case TacticalLines.ASSAULT: 391 case TacticalLines.ATKPOS: 392 case TacticalLines.OBJ: 393 case TacticalLines.AO: 394 case TacticalLines.AIRHEAD: 395 case TacticalLines.NAI: 396 case TacticalLines.TAI: 397 case TacticalLines.BASE_CAMP_REVD: 398 case TacticalLines.BASE_CAMP: 399 case TacticalLines.GUERILLA_BASE_REVD: 400 case TacticalLines.GUERILLA_BASE: 401 case TacticalLines.GENERIC_AREA: 402 case TacticalLines.OBSFAREA: 403 case TacticalLines.OBSAREA: 404 case TacticalLines.ZONE: 405 case TacticalLines.STRONG: 406 case TacticalLines.DRCL: 407 case TacticalLines.FSA: 408 case TacticalLines.ACA: 409 case TacticalLines.ASSY: 410 case TacticalLines.BSA: 411 case TacticalLines.NFA: 412 case TacticalLines.RFA: 413 case TacticalLines.FARP: 414 case TacticalLines.AIRFIELD: 415 case TacticalLines.LAA: 416 case TacticalLines.BOMB: 417 case TacticalLines.FFA: 418 case TacticalLines.SMOKE: 419 case TacticalLines.PAA: 420 case TacticalLines.ENCIRCLE: 421 case TacticalLines.DHA_REVD: 422 case TacticalLines.DHA: 423 case TacticalLines.KILL_ZONE: 424 case TacticalLines.EPW: 425 case TacticalLines.RHA: 426 case TacticalLines.DSA: 427 case TacticalLines.CSA: 428 case TacticalLines.RSA: 429 case TacticalLines.FORT_REVD: 430 case TacticalLines.FORT: 431 case TacticalLines.PEN: 432 case TacticalLines.BIO: 433 case TacticalLines.BIOT: 434 case TacticalLines.NUC: 435 case TacticalLines.RAD: 436 case TacticalLines.RADT: 437 case TacticalLines.CHEM: 438 case TacticalLines.CHEMT: 439 case TacticalLines.SERIES: 440 case TacticalLines.ATI: 441 case TacticalLines.TBA: 442 case TacticalLines.TVAR: 443 case TacticalLines.CFFZ: 444 case TacticalLines.CENSOR: 445 case TacticalLines.SENSOR: 446 case TacticalLines.ZOR: 447 case TacticalLines.DA: 448 case TacticalLines.CFZ: 449 case TacticalLines.KILLBOXBLUE: 450 case TacticalLines.KILLBOXPURPLE: 451 //METOCs 452 case TacticalLines.IFR: 453 case TacticalLines.MVFR: 454 case TacticalLines.TURBULENCE: 455 case TacticalLines.ICING: 456 case TacticalLines.NON_CONVECTIVE: 457 case TacticalLines.CONVECTIVE: 458 case TacticalLines.FROZEN: 459 case TacticalLines.THUNDERSTORMS: 460 case TacticalLines.FOG: 461 case TacticalLines.SAND: 462 case TacticalLines.FREEFORM: 463 case TacticalLines.DEPTH_AREA: 464 case TacticalLines.ISLAND: 465 case TacticalLines.BEACH: 466 case TacticalLines.WATER: 467 case TacticalLines.FISH_TRAPS: 468 case TacticalLines.SWEPT_AREA: 469 case TacticalLines.OIL_RIG_FIELD: 470 case TacticalLines.FOUL_GROUND: 471 case TacticalLines.KELP: 472 case TacticalLines.BEACH_SLOPE_MODERATE: 473 case TacticalLines.BEACH_SLOPE_STEEP: 474 case TacticalLines.ANCHORAGE_AREA: 475 case TacticalLines.TRAINING_AREA: 476 case TacticalLines.FORESHORE_AREA: 477 case TacticalLines.DRYDOCK: 478 case TacticalLines.LOADING_FACILITY_AREA: 479 case TacticalLines.PERCHES: 480 case TacticalLines.UNDERWATER_HAZARD: 481 case TacticalLines.DISCOLORED_WATER: 482 case TacticalLines.BEACH_SLOPE_FLAT: 483 case TacticalLines.BEACH_SLOPE_GENTLE: 484 case TacticalLines.MARITIME_AREA: 485 case TacticalLines.OPERATOR_DEFINED: 486 case TacticalLines.SUBMERGED_CRIB: 487 case TacticalLines.VDR_LEVEL_12: 488 case TacticalLines.VDR_LEVEL_23: 489 case TacticalLines.VDR_LEVEL_34: 490 case TacticalLines.VDR_LEVEL_45: 491 case TacticalLines.VDR_LEVEL_56: 492 case TacticalLines.VDR_LEVEL_67: 493 case TacticalLines.VDR_LEVEL_78: 494 case TacticalLines.VDR_LEVEL_89: 495 case TacticalLines.VDR_LEVEL_910: 496 case TacticalLines.SOLID_ROCK: 497 case TacticalLines.CLAY: 498 case TacticalLines.VERY_COARSE_SAND: 499 case TacticalLines.COARSE_SAND: 500 case TacticalLines.MEDIUM_SAND: 501 case TacticalLines.FINE_SAND: 502 case TacticalLines.VERY_FINE_SAND: 503 case TacticalLines.VERY_FINE_SILT: 504 case TacticalLines.FINE_SILT: 505 case TacticalLines.MEDIUM_SILT: 506 case TacticalLines.COARSE_SILT: 507 case TacticalLines.BOULDERS: 508 case TacticalLines.OYSTER_SHELLS: 509 case TacticalLines.PEBBLES: 510 case TacticalLines.SAND_AND_SHELLS: 511 case TacticalLines.BOTTOM_SEDIMENTS_LAND: 512 case TacticalLines.BOTTOM_SEDIMENTS_NO_DATA: 513 case TacticalLines.BOTTOM_ROUGHNESS_SMOOTH: 514 case TacticalLines.BOTTOM_ROUGHNESS_MODERATE: 515 case TacticalLines.BOTTOM_ROUGHNESS_ROUGH: 516 case TacticalLines.CLUTTER_LOW: 517 case TacticalLines.CLUTTER_MEDIUM: 518 case TacticalLines.CLUTTER_HIGH: 519 case TacticalLines.IMPACT_BURIAL_0: 520 case TacticalLines.IMPACT_BURIAL_10: 521 case TacticalLines.IMPACT_BURIAL_20: 522 case TacticalLines.IMPACT_BURIAL_75: 523 case TacticalLines.IMPACT_BURIAL_100: 524 case TacticalLines.BOTTOM_CATEGORY_A: 525 case TacticalLines.BOTTOM_CATEGORY_B: 526 case TacticalLines.BOTTOM_CATEGORY_C: 527 case TacticalLines.BOTTOM_TYPE_A1: 528 case TacticalLines.BOTTOM_TYPE_A2: 529 case TacticalLines.BOTTOM_TYPE_A3: 530 case TacticalLines.BOTTOM_TYPE_B1: 531 case TacticalLines.BOTTOM_TYPE_B2: 532 case TacticalLines.BOTTOM_TYPE_B3: 533 case TacticalLines.BOTTOM_TYPE_C1: 534 case TacticalLines.BOTTOM_TYPE_C2: 535 case TacticalLines.BOTTOM_TYPE_C3: 536 case TacticalLines.TGMF: 537 result = true; 538 break; 539 default: 540 break; 541 } 542 return result; 543 } 544 545 /** 546 * Closes the polygon for areas 547 * @param Pixels the client points 548 */ 549 public static void ClosePolygon(ArrayList<POINT2> Pixels) { 550 try { 551 POINT2 pt0 = Pixels.get(0); 552 POINT2 pt1 = Pixels.get(Pixels.size() - 1); 553 if (pt0.x != pt1.x || pt0.y != pt1.y) { 554 Pixels.add(new POINT2(pt0.x, pt0.y)); 555 } 556 } catch (Exception exc) { 557 ErrorLogger.LogException(_className ,"ClosePolygon", 558 new RendererException("Failed inside ClosePolygon", exc)); 559 } 560 } 561 /** 562 * for change 1 symbol the W/w1 modifiers run too close to the symbol outline 563 * so it shifts the line along the line away from the edge 564 * @param p1 565 * @param p2 566 * @param shift 567 */ 568 protected static void shiftModifiersLeft(POINT2 p1, POINT2 p2, double shift) 569 { 570 try 571 { 572 POINT2 pt1=new POINT2(p1); 573 POINT2 pt2=new POINT2(p2); 574 double dist=lineutility.CalcDistanceDouble(pt1, pt2); 575 if(pt1.x<pt2.x || (pt1.x==pt2.x && pt1.y<pt2.y)) 576 { 577 pt1=lineutility.ExtendAlongLineDouble(pt2, pt1, dist+shift); 578 pt2=lineutility.ExtendAlongLineDouble(pt1, pt2, dist-shift); 579 } 580 else 581 { 582 pt1=lineutility.ExtendAlongLineDouble(pt2, pt1, dist-shift); 583 pt2=lineutility.ExtendAlongLineDouble(pt1, pt2, dist+shift); 584 } 585 p1.x=pt1.x; 586 p1.y=pt1.y; 587 p2.x=pt2.x; 588 p2.y=pt2.y; 589 } 590 catch (Exception exc) { 591 ErrorLogger.LogException(_className ,"shiftModifiersLeft", 592 new RendererException("Failed inside shiftModifiersLeft", exc)); 593 } 594 } 595 /** 596 * Overrides shape properties for symbols based on Mil-Std-2525 597 * @param tg 598 * @param shape 599 */ 600 protected static void ResolveModifierShape(TGLight tg, Shape2 shape) { 601 try { 602 //shape style was set by CELineArray and takes precedence 603 //whenever it is set 604 int shapeStyle = shape.get_Style(); 605 int lineStyle = tg.get_LineStyle(); 606 int lineType = tg.get_LineType(); 607 boolean hasFill=LinesWithFill(lineType); 608 int bolMETOC=clsMETOC.IsWeather(tg.get_SymbolId()); 609 if(bolMETOC>0) 610 return; 611 int fillStyle=0; 612 //for some of these the style must be dashed 613 switch (tg.get_LineType()) { 614 case TacticalLines.NFA: 615 case TacticalLines.NFA_CIRCULAR: 616 case TacticalLines.NFA_RECTANGULAR: 617 case TacticalLines.BIO: 618 case TacticalLines.BIOT: 619 case TacticalLines.NUC: 620 case TacticalLines.CHEM: 621 case TacticalLines.CHEMT: 622 case TacticalLines.RAD: 623 case TacticalLines.RADT: 624 case TacticalLines.WFZ_REVD: 625 case TacticalLines.WFZ: 626 //case TacticalLines.OBSAREA: 627 fillStyle=3; 628 if(tg.get_UseHatchFill()) 629 fillStyle=0; 630 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 631 shape.set_Style(tg.get_LineStyle()); 632 shape.setLineColor(tg.get_LineColor()); 633 shape.set_Fillstyle(fillStyle /*GraphicProperties.FILL_TYPE_RIGHT_SLANTS*/);//was 3 634 shape.setFillColor(tg.get_FillColor()); 635 } 636 break; 637 case TacticalLines.OBSAREA: 638 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 639 shape.set_Style(tg.get_LineStyle()); 640 shape.setLineColor(tg.get_LineColor()); 641 shape.set_Fillstyle(0 /*GraphicProperties.FILL_TYPE_RIGHT_SLANTS*/); 642 shape.setFillColor(tg.get_FillColor()); 643 } 644 break; 645 case TacticalLines.LAA: 646 fillStyle=2; 647 if(tg.get_UseHatchFill()) 648 fillStyle=0; 649 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 650 shape.set_Style(tg.get_LineStyle()); 651 shape.setLineColor(tg.get_LineColor()); 652 shape.set_Fillstyle(fillStyle /*GraphicProperties.FILL_TYPE_LEFT_SLANTS*/);//was 2 653 shape.setFillColor(tg.get_FillColor()); 654 } 655 break; 656 case TacticalLines.DIRATKAIR: 657 case TacticalLines.ATDITCHC: 658 case TacticalLines.ATDITCHM: 659 case TacticalLines.SARA: 660 case TacticalLines.FOLSP: 661 case TacticalLines.FERRY: 662 case TacticalLines.MNFLDFIX: 663 case TacticalLines.TURN_REVD: 664 case TacticalLines.TURN: 665 case TacticalLines.MNFLDDIS: 666 case TacticalLines.EASY: 667 case TacticalLines.BYDIF: 668 case TacticalLines.BYIMP: 669 case TacticalLines.MOBILE_DEFENSE: 670 tg.set_lineCap(BasicStroke.CAP_BUTT); 671 if (shape.getShapeType() == Shape2.SHAPE_TYPE_FILL) { 672 shape.set_Fillstyle(1 /*GraphicProperties.FILL_TYPE_SOLID*/); 673 shape.setFillColor(tg.get_LineColor()); 674 } 675 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 676 shape.set_Style(tg.get_LineStyle()); 677 shape.setLineColor(tg.get_LineColor()); 678 } 679 break; 680 case TacticalLines.DECEIVE: 681 case TacticalLines.CLUSTER: 682 case TacticalLines.CATK: 683 case TacticalLines.CATKBYFIRE: 684 case TacticalLines.PLD: 685 case TacticalLines.PLANNED: 686 case TacticalLines.CFL: 687 //case TacticalLines.FORDSITE: 688 case TacticalLines.ACOUSTIC_AMB: 689 //any shape for these symbols is dashed 690 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 691 shape.set_Style(1 /*GraphicProperties.LINE_TYPE_DASHED*/); 692 shape.setLineColor(tg.get_LineColor()); 693 } 694 break; 695 case TacticalLines.PNO: //always dashed 696 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 697 shape.set_Style(1 /*GraphicProperties.LINE_TYPE_DASHED*/); 698 shape.setLineColor(tg.get_LineColor()); 699 shape.setFillColor(tg.get_FillColor()); 700 shape.set_Fillstyle(tg.get_FillStyle()); 701 } 702 break; 703 case TacticalLines.FOLLA: 704 case TacticalLines.ESR1: 705 //case TacticalLines.FORDIF: 706 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 707 shape.setLineColor(tg.get_LineColor()); 708 if (shapeStyle != lineStyle) { 709 if (shapeStyle != 1 /*GraphicProperties.LINE_TYPE_DASHED*/) { 710 shape.set_Style(lineStyle); 711 } 712 } 713 } 714 break; 715 case TacticalLines.FORDSITE: 716 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 717 if(!tg.get_Status().equals("A")) 718 shape.set_Style(5 /*GraphicProperties.LINE_TYPE_DASHED*/); 719 shape.setLineColor(tg.get_LineColor()); 720 } 721 break; 722 case TacticalLines.FORDIF: 723 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 724 shape.setLineColor(tg.get_LineColor()); 725 //linestyle==0 is the second shape which isn't dashed 726 if (shapeStyle != lineStyle) { 727 if (shapeStyle == 1 || tg.get_Status().equals("A")) { 728 //tg.get_Status().equals("A"); 729 shape.set_Style(5);//GraphicProperties.LINE_TYPE_LONG_DASHED 730 } 731 } 732 } 733 break;//*/ 734 case TacticalLines.AREA_DEFENSE: 735 if (shape.getShapeType() == Shape2.SHAPE_TYPE_FILL) { 736 shape.set_Fillstyle(tg.get_FillStyle()); 737 shape.setFillColor(tg.get_FillColor()); 738 // If there are 5 points and the first and last are the same this is 739 // a triangle and should be filled with line color 740 POINT2 firstPt = shape.getPoints().get(0); 741 POINT2 lastPt = shape.getPoints().get(shape.getPoints().size() - 1); 742 if (shape.getPoints().size() == 5 && firstPt.x == lastPt.x && firstPt.y == lastPt.y) { 743 shape.set_Fillstyle(1); 744 shape.setFillColor(tg.get_LineColor()); 745 } 746 } 747 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 748 shape.setLineColor(tg.get_LineColor()); 749 shape.set_Style(lineStyle); 750 if (hasFill || clsUtility.isClosedPolygon(lineType) || clsUtility.IsChange1Area(lineType)) { 751 shape.set_Fillstyle(tg.get_FillStyle()); 752 shape.setFillColor(tg.get_FillColor()); 753 } 754 } 755 break; 756 case TacticalLines.MOVEMENT_TO_CONTACT: 757 if (shape.getShapeType() == Shape2.SHAPE_TYPE_FILL) { 758 shape.set_Fillstyle(tg.get_FillStyle()); 759 shape.setFillColor(tg.get_FillColor()); 760 // If there are 4 points and the first and last are the same this is 761 // an arrow at the end of a jaggy line and should be filled with line color 762 POINT2 firstPt = shape.getPoints().get(0); 763 POINT2 lastPt = shape.getPoints().get(shape.getPoints().size() - 1); 764 if (shape.getPoints().size() == 4 && firstPt.x == lastPt.x && firstPt.y == lastPt.y) 765 shape.setFillColor(tg.get_LineColor()); 766 } 767 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 768 shape.setLineColor(tg.get_LineColor()); 769 shape.set_Style(lineStyle); 770 } 771 break; 772 case TacticalLines.EXPLOIT: 773 // Some shapes have solid lines some have dashed 774 if (shape.getShapeType() == Shape2.SHAPE_TYPE_FILL) { 775 shape.set_Fillstyle(tg.get_FillStyle()); 776 shape.setFillColor(tg.get_FillColor()); 777 } 778 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 779 shape.setLineColor(tg.get_LineColor()); 780 if (shapeStyle != 1 /*GraphicProperties.LINE_TYPE_DASHED*/) { 781 shape.set_Style(lineStyle); 782 } 783 } 784 break; 785 default: 786 if (shape.getShapeType() == Shape2.SHAPE_TYPE_FILL) { 787 shape.set_Fillstyle(tg.get_FillStyle()); 788 shape.setFillColor(tg.get_FillColor()); 789 } 790 if (shape.getShapeType() == Shape2.SHAPE_TYPE_POLYLINE) { 791 if (lineType != TacticalLines.LC) { 792 shape.setLineColor(tg.get_LineColor()); 793 } else { 794 SetLCColor(tg, shape); 795 } 796 shape.set_Style(lineStyle); 797 if (hasFill || clsUtility.isClosedPolygon(lineType) || clsUtility.IsChange1Area(lineType)) 798 { 799 switch(lineType) 800 { 801 case TacticalLines.RANGE_FAN: 802 case TacticalLines.RANGE_FAN_SECTOR: 803 case TacticalLines.RADAR_SEARCH: 804 case TacticalLines.BBS_AREA: 805 case TacticalLines.BBS_RECTANGLE: 806 shape.setFillColor(null); 807 break; 808 default: 809 shape.set_Fillstyle(tg.get_FillStyle()); 810 shape.setFillColor(tg.get_FillColor()); 811 break; 812 } 813 } 814 switch(lineType) 815 { 816 case TacticalLines.BS_ELLIPSE: 817 case TacticalLines.BS_RECTANGLE: 818 //case TacticalLines.BBS_RECTANGLE: 819 shape.set_Fillstyle(tg.get_FillStyle()); 820 shape.setFillColor(tg.get_FillColor()); 821 break; 822 case TacticalLines.BBS_RECTANGLE: 823 case TacticalLines.PBS_RECTANGLE: 824 case TacticalLines.PBS_SQUARE: 825 shape.setFillColor(null); 826 break; 827 default: 828 break; 829 } 830 } 831 break; 832 } 833 834 } catch (Exception exc) { 835 ErrorLogger.LogException(_className ,"ResolveModifierShape", 836 new RendererException("Failed inside ResolveModifierShape", exc)); 837 } 838 } 839 public static Color GetOpaqueColor(Color color) 840 { 841 int r=color.getRed(); 842 int g=color.getGreen(); 843 int b=color.getBlue(); 844 return new Color(r,g,b); 845 } 846 /** 847 * These lines allow fill 848 * @param linetype 849 * @return 850 */ 851 public static boolean LinesWithFill(int linetype) 852 { 853 boolean result=false; 854 try 855 { 856 switch(linetype) 857 { 858 case TacticalLines.BS_LINE: 859 case TacticalLines.PAA_RECTANGULAR: 860 case TacticalLines.RECTANGULAR_TARGET: 861 case TacticalLines.CFL: 862 case TacticalLines.TRIP: 863 case TacticalLines.DIRATKAIR: 864 case TacticalLines.BOUNDARY: 865 case TacticalLines.ISOLATE: 866 case TacticalLines.CORDONKNOCK: 867 case TacticalLines.CORDONSEARCH: 868 case TacticalLines.DENY: 869 case TacticalLines.OCCUPY: 870 case TacticalLines.RETAIN: 871 case TacticalLines.SECURE: 872 case TacticalLines.CONTROL: 873 case TacticalLines.LOCATE: 874 case TacticalLines.AREA_DEFENSE: 875 case TacticalLines.MOBILE_DEFENSE: 876 case TacticalLines.FLOT: 877 case TacticalLines.LC: 878 case TacticalLines.PL: 879 case TacticalLines.FEBA: 880 case TacticalLines.LL: 881 case TacticalLines.EWL: 882// case TacticalLines.AC: 883// case TacticalLines.SAAFR: 884 case TacticalLines.DIRATKGND: 885 case TacticalLines.DIRATKSPT: 886 case TacticalLines.INFILTRATION: 887 case TacticalLines.FCL: 888 case TacticalLines.HOLD: 889 case TacticalLines.BRDGHD: 890 case TacticalLines.HOLD_GE: 891 case TacticalLines.BRDGHD_GE: 892 case TacticalLines.LOA: 893 case TacticalLines.LOD: 894 case TacticalLines.LDLC: 895 case TacticalLines.RELEASE: 896 case TacticalLines.HOL: 897 case TacticalLines.BHL: 898 case TacticalLines.LINE: 899 case TacticalLines.ABATIS: 900 case TacticalLines.ATDITCH: 901 case TacticalLines.ATWALL: 902 case TacticalLines.SFENCE: 903 case TacticalLines.DFENCE: 904 case TacticalLines.UNSP: 905 case TacticalLines.PLD: 906 case TacticalLines.DOUBLEA: 907 case TacticalLines.LWFENCE: 908 case TacticalLines.HWFENCE: 909 case TacticalLines.SINGLEC: 910 case TacticalLines.DOUBLEC: 911 case TacticalLines.TRIPLE: 912 case TacticalLines.FORTL: 913 case TacticalLines.LINTGT: 914 case TacticalLines.LINTGTS: 915 case TacticalLines.FSCL: 916 case TacticalLines.BCL_REVD: 917 case TacticalLines.BCL: 918 case TacticalLines.ICL: 919 case TacticalLines.IFF_OFF: 920 case TacticalLines.IFF_ON: 921 case TacticalLines.GENERIC_LINE: 922 case TacticalLines.NFL: 923 case TacticalLines.MFP: 924 case TacticalLines.RFL: 925 case TacticalLines.CONVOY: 926 case TacticalLines.HCONVOY: 927 case TacticalLines.MSR: 928 case TacticalLines.MSR_ONEWAY: 929 case TacticalLines.MSR_TWOWAY: 930 case TacticalLines.MSR_ALT: 931 case TacticalLines.ASR: 932 case TacticalLines.ASR_ONEWAY: 933 case TacticalLines.ASR_TWOWAY: 934 case TacticalLines.ASR_ALT: 935 case TacticalLines.TRAFFIC_ROUTE: 936 case TacticalLines.TRAFFIC_ROUTE_ONEWAY: 937 case TacticalLines.TRAFFIC_ROUTE_ALT: 938 result = true; 939 break; 940 default: 941 result = false; 942 break; 943 } 944 } 945 catch(Exception exc) 946 { 947 ErrorLogger.LogException(_className ,"LinesWithFill", 948 new RendererException("Failed inside LinesWithFill", exc)); 949 } 950 return result; 951 } 952 /** 953 * @deprecated 954 * if the line color and fill color are the same or very close then we want to 955 * tweak the fill color a bit to make the line appear distinct from the fill. 956 * @param tg 957 */ 958 public static void tweakFillColor(TGLight tg) 959 { 960 try 961 { 962 if(isSameColor(tg.get_LineColor(),tg.get_FillColor())==false) 963 return; 964 965 Color fillColor=tg.get_FillColor(); 966 int r=fillColor.getRed(),g=fillColor.getGreen(),b=fillColor.getBlue(); 967 int alpha=fillColor.getAlpha(); 968 969 r*=0.9; 970 g*=0.9; 971 b*=0.9; 972 alpha*=0.8; 973 974 fillColor=new Color(r,g,b,alpha); 975 tg.set_FillColor(fillColor); 976 } 977 catch(Exception exc) 978 { 979 ErrorLogger.LogException(_className ,"tweakFillColor", 980 new RendererException("Failed inside tweakFillColor", exc)); 981 } 982 } 983 /** 984 * @deprecated 985 * Test to see if two colors are similar 986 * @param c1 987 * @param c2 988 * @return true is same (or similar) color 989 */ 990 public static Boolean isSameColor(Color c1, Color c2) 991 { 992 try 993 { 994 if(c1==null || c2==null) 995 return true; 996 997 int r1=c1.getRed(),r2=c2.getRed(),g1=c1.getGreen(),g2=c2.getGreen(), 998 b1=c1.getBlue(),b2=c2.getBlue(); 999 1000 if(Math.abs(r1-r2)<5) 1001 if(Math.abs(g1-g2)<5) 1002 if(Math.abs(b1-b2)<5) 1003 return true; 1004 } 1005 catch(Exception exc) 1006 { 1007 ErrorLogger.LogException(_className ,"isSameColor", 1008 new RendererException("Failed inside isSameColor", exc)); 1009 } 1010 return false; 1011 } 1012 /** 1013 * Customer requested routine for setting the stroke dash pattern 1014 * Scales dash length with line width and DPI 1015 * @param width 1016 * @param style 0 solid, 1 dashed, 2 dotted, 3 dash dot, 4 dash dot dot, 5 long dash 1017 * @param cap 1018 * @param join 1019 * @return 1020 */ 1021 public static BasicStroke getLineStroke(int width, int style, int cap, int join) { 1022 // Some segments are of length 0.1 because the Java2D renderer adds line caps of 1023 // width/2 size to both ends of the segment when "round" is one of BasicStroke.CAP_ROUND 1024 // or BasicStroke.CAP_SQUARE. This value is small enough not to affect the 1025 // stipple bit pattern calculation for the 3d map and still look good on the 1026 // 2d map. 1027 1028 // NOTE: The dash arrays below do not supportBasisStroke.CAP_BUTT line capping, 1029 // although it would be relatively simple to change them such that they would. 1030 BasicStroke stroke=null; 1031 try { 1032 final float dashLength = 2 * width; 1033 final float dotLength = 1f; 1034 final float dotSpace = 2 * width; 1035 switch (style) { 1036 case 0://GraphicProperties.LINE_TYPE_SOLID: 1037 stroke = new BasicStroke(width, cap, join); 1038 break; 1039 case 1://GraphicProperties.LINE_TYPE_DASHED: 1040 float[] dash = {dashLength, dashLength}; 1041 stroke = new BasicStroke(width, cap, join, 4f, dash, 0f); 1042 break; 1043 case 2://GraphicProperties.LINE_TYPE_DOTTED: 1044 float[] dot = {dotLength, dotSpace}; 1045 stroke = new BasicStroke(width, cap, join, 4f, dot, 0f); 1046 break; 1047 case 3://GraphicProperties.LINE_TYPE_DASHDOT: 1048 float[] dashdot = {2 * dashLength, dotSpace, dotLength, dotSpace}; 1049 stroke = new BasicStroke(width, cap, join, 4f, dashdot,0f ); 1050 break; 1051 case 4://GraphicProperties.LINE_TYPE_DASHDOTDOT: 1052 float[] dashdotdot = {dashLength, dotSpace, dotLength, dotSpace, dotLength, dotSpace}; 1053 stroke = new BasicStroke(width, cap, join, 4f,dashdotdot, 0f ); 1054 break; 1055 case 5://GraphicProperties.LINE_TYPE_LONG_DASH: 1056 float[] longdash = {dashLength * 2, dashLength}; 1057 stroke = new BasicStroke(width, cap, join, 4f,longdash, 0f ); 1058 break; 1059 default: 1060 stroke = new BasicStroke(width, cap, join); 1061 break; 1062 } 1063 } catch(Exception exc) { 1064 ErrorLogger.LogException(_className ,"getLineStroke", 1065 new RendererException("Failed inside getLineStroke", exc)); 1066 } 1067 return stroke; 1068 } 1069 /** 1070 * Sets shape properties based on other properties which were set by JavaLineArray 1071 * @param tg tactical graphic 1072 * @param shapes the ShapeInfo array 1073 * @param bi BufferedImage to use for setting shape TexturePaint 1074 */ 1075 public static void SetShapeProperties(TGLight tg, ArrayList<Shape2> shapes, 1076 BufferedImage bi) { 1077 try 1078 { 1079 if (shapes == null) 1080 { 1081 return; 1082 } 1083 1084 int j = 0; 1085 Shape2 shape = null; 1086 BasicStroke stroke = null; 1087 float[] dash = null; 1088 int lineThickness = tg.get_LineThickness(); 1089 int shapeType = -1; 1090 int lineType = tg.get_LineType(); 1091 boolean hasFill=LinesWithFill(lineType); 1092 boolean isChange1Area = clsUtility.IsChange1Area(lineType); 1093 boolean isClosedPolygon = clsUtility.isClosedPolygon(lineType); 1094 //int n=shapes.size(); 1095 //remove air corridors fill shapes if fill is null 1096 if(tg.get_FillColor()==null) 1097 { 1098 switch(tg.get_LineType()) 1099 { 1100 case TacticalLines.AC: 1101 case TacticalLines.SAAFR: 1102 case TacticalLines.MRR: 1103 case TacticalLines.SL: 1104 case TacticalLines.TC: 1105 case TacticalLines.SC: 1106 case TacticalLines.LLTR: 1107 shape=shapes.get(shapes.size()-1); 1108 shapes.clear(); 1109 shapes.add(shape); 1110 break; 1111 case TacticalLines.CATK: 1112 case TacticalLines.AIRAOA: 1113 case TacticalLines.AAAAA: 1114 case TacticalLines.SPT: 1115 case TacticalLines.FRONTAL_ATTACK: 1116 case TacticalLines.TURNING_MOVEMENT: 1117 case TacticalLines.MOVEMENT_TO_CONTACT: 1118 case TacticalLines.MAIN: 1119 case TacticalLines.CATKBYFIRE: //80 1120 ArrayList<Shape2> tempShapes=new ArrayList(); 1121 for(j=0;j<shapes.size();j++) 1122 { 1123 shape=shapes.get(j); 1124 if(shape.getShapeType() != Shape2.SHAPE_TYPE_FILL) 1125 tempShapes.add(shape); 1126 } 1127 shapes=tempShapes; 1128 break; 1129 default: 1130 break; 1131 } 1132 } 1133 for (j = 0; j < shapes.size(); j++) 1134 { 1135 shape = shapes.get(j); 1136 if (shape == null || shape.getShape() == null) { 1137 continue; 1138 } 1139 1140 if (shape.getShapeType() == Shape2.SHAPE_TYPE_FILL) 1141 { 1142 switch(tg.get_LineType()) 1143 { 1144 case TacticalLines.DEPTH_AREA: 1145 break; 1146 default: 1147 shape.setFillColor(tg.get_FillColor()); 1148 break; 1149 } 1150 } 1151 1152 //if(lineType != TacticalLines.LEADING_LINE) 1153 ResolveModifierShape(tg, shape); 1154 if(lineType==TacticalLines.AIRFIELD) 1155 if(j==1) 1156 shape.setFillColor(null); 1157 //diagnostic 1158 if(lineType==TacticalLines.BBS_POINT) 1159 if(j==0) 1160 shape.setLineColor(null); 1161 //end section 1162 1163 shapeType = shape.getShapeType(); 1164 1165 Rectangle2D.Double rect = null; 1166 Graphics2D grid = null; 1167 TexturePaint tp = tg.get_TexturePaint(); 1168 1169 if(lineThickness==0) 1170 lineThickness=1; 1171 //set the shape with the default properties 1172 //the switch statement below will override specific properties as needed 1173 stroke = getLineStroke(lineThickness,shape.get_Style(),tg.get_lineCap(),BasicStroke.JOIN_ROUND); 1174 if(shape.getShapeType()==Shape2.SHAPE_TYPE_FILL) 1175 { 1176 stroke = new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER); 1177 //shape.setStroke(new BasicStroke(0)); 1178 } 1179 shape.setStroke(stroke); 1180 } // end loop over shapes 1181 if (tg.get_LineType() == TacticalLines.DIRATKAIR) { 1182 // Make arrowhead and bowtie shapes solid even if tg.get_LineStyle() isn't 1183 for (int i = 2; i < shapes.size(); i++) { 1184 Shape2 arrowHeadShape = shapes.get(i); 1185 arrowHeadShape.set_Style(0); 1186 stroke = getLineStroke(lineThickness, 0, tg.get_lineCap(), BasicStroke.JOIN_ROUND); 1187 arrowHeadShape.setStroke(stroke); 1188 } 1189 } else if (tg.get_LineType() == TacticalLines.DIRATKGND || tg.get_LineType() == TacticalLines.DIRATKSPT || tg.get_LineType() == TacticalLines.EXPLOIT || lineType == TacticalLines.INFILTRATION) { 1190 // Make arrowhead shape solid even if tg.get_LineStyle() isn't 1191 Shape2 arrowHeadShape = shapes.get(1); 1192 arrowHeadShape.set_Style(0); 1193 stroke = getLineStroke(lineThickness,0,tg.get_lineCap(),BasicStroke.JOIN_ROUND); 1194 arrowHeadShape.setStroke(stroke); 1195 } else if (tg.get_LineType() == TacticalLines.PDF) { 1196 Shape2 rectShape = shapes.get(1); 1197 rectShape.set_Style(0); 1198 stroke = getLineStroke(lineThickness, 0, tg.get_lineCap(), BasicStroke.JOIN_ROUND); 1199 rectShape.setStroke(stroke); 1200 rectShape.setFillColor(rectShape.getLineColor()); 1201 } 1202 } 1203 catch (Exception exc) { 1204 ErrorLogger.LogException(_className ,"SetShapeProperties", 1205 new RendererException("Failed inside SetShapeProperties", exc)); 1206 } 1207 } 1208 /** 1209 * Returns a boolean indicating whether the line type is a change 1 area 1210 * @param lineType the line type 1211 * @return true if change 1 area 1212 */ 1213 public static boolean IsChange1Area(int lineType) { 1214 try { 1215 switch (lineType) { 1216 case TacticalLines.LAUNCH_AREA: 1217 case TacticalLines.DEFENDED_AREA_CIRCULAR: 1218 case TacticalLines.SHIP_AOI_CIRCULAR: 1219 case TacticalLines.PBS_ELLIPSE: 1220 case TacticalLines.RECTANGULAR: 1221 case TacticalLines.CUED_ACQUISITION: 1222 case TacticalLines.PBS_RECTANGLE: 1223 case TacticalLines.PBS_SQUARE: 1224 case TacticalLines.CIRCULAR: 1225 case TacticalLines.PBS_CIRCLE: 1226 case TacticalLines.BDZ: 1227 case TacticalLines.BBS_POINT: 1228 case TacticalLines.FSA_CIRCULAR: 1229 case TacticalLines.NOTACK: 1230 case TacticalLines.FFA_CIRCULAR: 1231 case TacticalLines.NFA_CIRCULAR: 1232 case TacticalLines.RFA_CIRCULAR: 1233 case TacticalLines.ACA_CIRCULAR: 1234 case TacticalLines.PAA_CIRCULAR: 1235 case TacticalLines.ATI_CIRCULAR: 1236 case TacticalLines.CFFZ_CIRCULAR: 1237 case TacticalLines.SENSOR_CIRCULAR: 1238 case TacticalLines.CENSOR_CIRCULAR: 1239 case TacticalLines.DA_CIRCULAR: 1240 case TacticalLines.CFZ_CIRCULAR: 1241 case TacticalLines.ZOR_CIRCULAR: 1242 case TacticalLines.TBA_CIRCULAR: 1243 case TacticalLines.TVAR_CIRCULAR: 1244 case TacticalLines.KILLBOXBLUE_CIRCULAR: 1245 case TacticalLines.KILLBOXPURPLE_CIRCULAR: 1246 case TacticalLines.RANGE_FAN: 1247 case TacticalLines.RANGE_FAN_FILL: 1248 case TacticalLines.RANGE_FAN_SECTOR: 1249 case TacticalLines.RADAR_SEARCH: 1250 case TacticalLines.BS_RADARC: 1251 case TacticalLines.BS_CAKE: 1252 case TacticalLines.PAA_RECTANGULAR: 1253 case TacticalLines.RECTANGULAR_TARGET: 1254 case TacticalLines.FSA_RECTANGULAR: 1255 case TacticalLines.SHIP_AOI_RECTANGULAR: 1256 case TacticalLines.DEFENDED_AREA_RECTANGULAR: 1257 case TacticalLines.BS_ROUTE: 1258 case TacticalLines.BS_TRACK: 1259 case TacticalLines.FFA_RECTANGULAR: 1260 case TacticalLines.RFA_RECTANGULAR: 1261 case TacticalLines.NFA_RECTANGULAR: 1262 case TacticalLines.ACA_RECTANGULAR: 1263 case TacticalLines.ATI_RECTANGULAR: 1264 case TacticalLines.CFFZ_RECTANGULAR: 1265 case TacticalLines.SENSOR_RECTANGULAR: 1266 case TacticalLines.CENSOR_RECTANGULAR: 1267 case TacticalLines.DA_RECTANGULAR: 1268 case TacticalLines.CFZ_RECTANGULAR: 1269 case TacticalLines.ZOR_RECTANGULAR: 1270 case TacticalLines.TBA_RECTANGULAR: 1271 case TacticalLines.TVAR_RECTANGULAR: 1272 case TacticalLines.KILLBOXBLUE_RECTANGULAR: 1273 case TacticalLines.KILLBOXPURPLE_RECTANGULAR: 1274 case TacticalLines.BS_ORBIT: 1275 case TacticalLines.BS_POLYARC: 1276 return true; 1277 default: 1278 return false; 1279 } 1280 } catch (Exception exc) { 1281 //clsUtility.WriteFile("Error in clsUtility.IsChange1Area"); 1282 ErrorLogger.LogException(_className ,"IsChange1Area", 1283 new RendererException("Failed inside IsChange1Area", exc)); 1284 } 1285 return false; 1286 } 1287 1288 public static void WriteFile(String str) { 1289 try { 1290 BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("Test.txt")); 1291 bufferedWriter.write(str); 1292 //bufferedWriter.newLine(); 1293 //bufferedWriter.write(pointType); 1294 bufferedWriter.close(); 1295 bufferedWriter = null; 1296 } 1297 catch (Exception exc) { 1298 ErrorLogger.LogException(_className ,"WriteFile", 1299 new RendererException("Failed inside WriteFile", exc)); 1300 } 1301 } 1302 1303 /** 1304 * Calculates point where two lines intersect. 1305 * First line defined by pt1, m1. 1306 * Second line defined by pt2, m2. 1307 * result will be written to ptIntersect. 1308 * @param pt1 first line point 1309 * @param m1 slope of first line 1310 * @param pt2 second line point 1311 * @param m2 slope of second line 1312 * @param ptIntersect OUT - intersection point 1313 */ 1314 protected static void CalcIntersectPt(POINT2 pt1, 1315 double m1, 1316 POINT2 pt2, 1317 double m2, 1318 POINT2 ptIntersect) { 1319 try { 1320 if (m1 == m2) { 1321 return; 1322 } 1323 1324 double x1 = pt1.x; 1325 double y1 = pt1.y; 1326 double x2 = pt2.x; 1327 double y2 = pt2.y; 1328 //formula for the intersection of two lines 1329 double dx2 = (double) ((y1 - y2 + m1 * x2 - m1 * x1) / (m2 - m1)); 1330 double x3 = x2 + dx2; 1331 double y3 = (double) (y2 + m2 * dx2); 1332 1333 ptIntersect.x = x3; 1334 ptIntersect.y = y3; 1335 } catch (Exception exc) { 1336 //clsUtility.WriteFile("Error in clsUtility.CalcIntersectPt"); 1337 ErrorLogger.LogException(_className, "CalcIntersectPt", 1338 new RendererException("Failed inside CalcIntersectPt", exc)); 1339 } 1340 } 1341 1342 /** 1343 * Calculates the channel width in pixels for channel types 1344 * @param pixels the client points as 2-tuples x,y in pixels 1345 * @param distanceToChannelPOINT2 OUT - the calculated distance in pixels from the tip of the 1346 * arrowhead to the back of the arrowhead. 1347 * @return the channel width in pixels 1348 */ 1349 protected static int ChannelWidth(double[] pixels, 1350 ref<double[]> distanceToChannelPOINT2) { 1351 int width = 0; 1352 try { 1353 int numPOINT2s = pixels.length / 2; 1354 if (numPOINT2s < 3) { 1355 return 0; 1356 } 1357 1358 POINT2 channelWidthPOINT2 = new POINT2(0, 0); 1359 POINT2 lastSegmentPt1 = new POINT2(0, 0); 1360 POINT2 lastSegmentPt2 = new POINT2(0, 0); 1361 1362 lastSegmentPt1.x = (double) pixels[2 * numPOINT2s - 6]; 1363 lastSegmentPt1.y = (double) pixels[2 * numPOINT2s - 5]; 1364 lastSegmentPt2.x = (double) pixels[2 * numPOINT2s - 4]; 1365 lastSegmentPt2.y = (double) pixels[2 * numPOINT2s - 3]; 1366 channelWidthPOINT2.x = (double) pixels[2 * numPOINT2s - 2]; 1367 channelWidthPOINT2.y = (double) pixels[2 * numPOINT2s - 1]; 1368 1369 ref<double[]> m = new ref(); 1370 double m1 = 0; 1371 //m1.value=new double[1]; 1372 double distance = 0; 1373 POINT2 ptIntersect = new POINT2(0, 0); 1374 //boolean bolVertical = TrueSlope(lastSegmentPt1, lastSegmentPt2, ref m); 1375 boolean bolVertical = lineutility.CalcTrueSlopeDouble2(lastSegmentPt1, lastSegmentPt2, m); 1376 if (bolVertical == true && m.value[0] != 0) { 1377 m1 = -1 / m.value[0]; 1378 CalcIntersectPt(channelWidthPOINT2, m1, lastSegmentPt2, m.value[0], ptIntersect); 1379 distance = lineutility.CalcDistanceDouble(channelWidthPOINT2, ptIntersect); 1380 } 1381 if (bolVertical == true && m.value[0] == 0) //horizontal segment 1382 { 1383 distance = Math.abs(channelWidthPOINT2.y - lastSegmentPt1.y); 1384 } 1385 if (bolVertical == false) //vertical segment 1386 { 1387 distance = Math.abs(channelWidthPOINT2.x - lastSegmentPt1.x); 1388 distanceToChannelPOINT2.value = new double[1]; 1389 distanceToChannelPOINT2.value[0] = distance; 1390 return (int) distance * 4; 1391 } 1392 1393 width = (int) distance * 8; 1394 if (width < 2) { 1395 width = 2; 1396 } 1397 1398 double hypotenuse = lineutility.CalcDistanceDouble(lastSegmentPt2, channelWidthPOINT2); 1399 distanceToChannelPOINT2.value = new double[1]; 1400 distanceToChannelPOINT2.value[0] = Math.sqrt(hypotenuse * hypotenuse - distance * distance); 1401 1402 } catch (Exception exc) { 1403 //clsUtility.WriteFile("Error in clsUtility.ChannelWidth"); 1404 ErrorLogger.LogException(_className, "ChannelWidth", 1405 new RendererException("Failed inside ChannelWidth", exc)); 1406 } 1407 return width; 1408 } 1409 1410 private static boolean InYOrder(POINT2 pt0, 1411 POINT2 pt1, 1412 POINT2 pt2) { 1413 try { 1414 if (pt0.y <= pt1.y && pt1.y <= pt2.y) { 1415 return true; 1416 } 1417 1418 if (pt2.y <= pt1.y && pt1.y <= pt0.y) { 1419 return true; 1420 } 1421 1422 } catch (Exception exc) { 1423 //clsUtility.WriteFile("Error in clsUtility.InYOrder"); 1424 ErrorLogger.LogException(_className, "InYOrder", 1425 new RendererException("Failed inside InYOrder", exc)); 1426 } 1427 return false; 1428 } 1429 /// <summary> 1430 /// tests if POINT2s have successively increasing or decreasing x values. 1431 /// </summary> 1432 /// <param name="pt0"></param> 1433 /// <param name="pt1"></param> 1434 /// <param name="pt2"></param> 1435 /// <returns>true if POINT2s are in X order</returns> 1436 1437 private static boolean InXOrder(POINT2 pt0, 1438 POINT2 pt1, 1439 POINT2 pt2) { 1440 try { 1441 if (pt0.x <= pt1.x && pt1.x <= pt2.x) { 1442 return true; 1443 } 1444 1445 if (pt2.x <= pt1.x && pt1.x <= pt0.x) { 1446 return true; 1447 } 1448 1449 } catch (Exception exc) { 1450 //clsUtility.WriteFile("Error in clsUtility.InXOrder"); 1451 ErrorLogger.LogException(_className, "InXOrder", 1452 new RendererException("Failed inside InXOrder", exc)); 1453 } 1454 return false; 1455 } 1456 1457 /** 1458 * For each sector calculates left azimuth, right azimuth, min radius, max radius 1459 * and stuff H2 with the string delimited result. The function is public, called by JavaRendererServer 1460 * @param tg tactical graphic 1461 */ 1462 public static void GetSectorRadiiFromPoints(TGLight tg) { 1463 try { 1464 if(tg.get_LineType()==TacticalLines.RANGE_FAN_FILL) 1465 return; 1466 POINT2 ptCenter = tg.LatLongs.get(0); 1467 POINT2 ptLeftMin = new POINT2(), ptRightMax = new POINT2(); 1468 int k = 0; 1469 String strLeft = "", strRight = "", strMin = "", strMax = "", temp = ""; 1470 double nLeft = 0, nRight = 0, nMin = 0, nMax = 0; 1471 //if tg.PointCollection has more than one point 1472 //we use the points to calculate left,right,min,max 1473 //and then stuff tg.H2 with the comma delimited string 1474 double dist = 0; 1475 ref<double[]> a12 = new ref(), a21 = new ref(); 1476 int numSectors = 0; 1477 if (tg.LatLongs.size() > 2) { 1478 numSectors = (tg.LatLongs.size() - 2) / 2; 1479 for (k = 0; k < numSectors; k++) { 1480 //get the sector points 1481 ptLeftMin = tg.LatLongs.get(2 * k + 2); 1482 ptRightMax = tg.LatLongs.get(2 * k + 3); 1483 1484 dist = mdlGeodesic.geodesic_distance(ptCenter, ptLeftMin, a12, a21); 1485 nLeft = a12.value[0]; 1486 strLeft = Double.toString(nLeft); 1487 1488 nMin = dist; 1489 strMin = Double.toString(nMin); 1490 1491 dist = mdlGeodesic.geodesic_distance(ptCenter, ptRightMax, a12, a21); 1492 nRight = a12.value[0]; 1493 strRight = Double.toString(nRight); 1494 1495 nMax = dist; 1496 strMax = Double.toString(nMax); 1497 1498 if (k == 0) { 1499 temp = strLeft + "," + strRight + "," + strMin + "," + strMax; 1500 } else { 1501 temp += "," + strLeft + "," + strRight + "," + strMin + "," + strMax; 1502 } 1503 } 1504 if (!temp.equals("")) { 1505 tg.set_LRMM(temp); 1506 } 1507 } 1508 } catch (Exception exc) { 1509 //clsUtility.WriteFile("Error in clsUtility.GetSectorRadiiFromPoints"); 1510 ErrorLogger.LogException(_className, "GetSectorRadiiFromPoints", 1511 new RendererException("Failed inside GetSectorRadiiFromPoints", exc)); 1512 } 1513 } 1514 1515 /** 1516 * Reverses the pixels except for the last point. This is used for 1517 * the axis of advance type routes. The pixels are 2-tuples x,y 1518 * 1519 * @param pixels OUT - Array of client points 1520 */ 1521 protected static void ReorderPixels(double[] pixels) { 1522 try { 1523 double[] tempPixels; 1524 //reverse the pixels 1525 int j; 1526 double x; 1527 double y; 1528 int counter; 1529 int numPoints; 1530 counter = 0; 1531 numPoints = pixels.length / 2; 1532 tempPixels = new double[pixels.length]; 1533 for (j = 0; j < numPoints - 1; j++) { 1534 x = pixels[pixels.length - 2 * j - 4]; 1535 y = pixels[pixels.length - 2 * j - 3]; 1536 tempPixels[counter] = x; 1537 tempPixels[counter + 1] = y; 1538 counter += 2; 1539 } 1540 //put the last pixel point into the last temppixels point 1541 int intPixelSize = pixels.length; 1542 tempPixels[counter] = pixels[intPixelSize - 2]; 1543 tempPixels[counter + 1] = pixels[intPixelSize - 1]; 1544 //stuff the pixels 1545 int n=pixels.length; 1546 //for (j = 0; j < pixels.length; j++) 1547 for (j = 0; j < n; j++) 1548 { 1549 pixels[j] = tempPixels[j]; 1550 } 1551 //tempPixels = null; 1552 } catch (Exception exc) { 1553 ErrorLogger.LogException(_className, "ReorderPixels", 1554 new RendererException("Failed inside ReorderPixels", exc)); 1555 } 1556 } 1557 /** 1558 * do not allow vertical segments for these, move the point x value by 1 pixel 1559 * @param tg tactical graphic 1560 */ 1561 public static void FilterVerticalSegments(TGLight tg) 1562 { 1563 try 1564 { 1565 switch(tg.get_LineType()) 1566 { 1567 case TacticalLines.MAIN: 1568 case TacticalLines.CATK: 1569 case TacticalLines.CATKBYFIRE: 1570 case TacticalLines.AIRAOA: 1571 case TacticalLines.AAAAA: 1572 case TacticalLines.SPT: 1573 case TacticalLines.FRONTAL_ATTACK: 1574 case TacticalLines.TURNING_MOVEMENT: 1575 case TacticalLines.MOVEMENT_TO_CONTACT: 1576 case TacticalLines.LC: 1577 case TacticalLines.UNSP: 1578 case TacticalLines.DFENCE: 1579 case TacticalLines.SFENCE: 1580 case TacticalLines.DOUBLEA: 1581 case TacticalLines.LWFENCE: 1582 case TacticalLines.HWFENCE: 1583 case TacticalLines.BBS_LINE: 1584 case TacticalLines.SINGLEC: 1585 case TacticalLines.DOUBLEC: 1586 case TacticalLines.TRIPLE: 1587 case TacticalLines.MSR_ONEWAY: 1588 case TacticalLines.MSR_TWOWAY: 1589 case TacticalLines.MSR_ALT: 1590 case TacticalLines.ASR_ONEWAY: 1591 case TacticalLines.ASR_TWOWAY: 1592 case TacticalLines.ASR_ALT: 1593 case TacticalLines.TRAFFIC_ROUTE_ONEWAY: 1594 case TacticalLines.TRAFFIC_ROUTE_ALT: 1595 case TacticalLines.ATWALL: 1596 break; 1597 default: 1598 return; 1599 } 1600 POINT2 ptCurrent=null; 1601 POINT2 ptLast=null; 1602 int n=tg.Pixels.size(); 1603 //for(int j=1;j<tg.Pixels.size();j++) 1604 for(int j=1;j<n;j++) 1605 { 1606 ptLast=new POINT2(tg.Pixels.get(j-1)); 1607 ptCurrent=new POINT2(tg.Pixels.get(j)); 1608 //if(Math.round(ptCurrent.x)==Math.round(ptLast.x)) 1609 if(Math.abs(ptCurrent.x-ptLast.x)<1) 1610 { 1611 if (ptCurrent.x>=ptLast.x) 1612 ptCurrent.x += 1; 1613 else 1614 ptCurrent.x -= 1; 1615 tg.Pixels.set(j, ptCurrent); 1616 } 1617 } 1618 } 1619 catch(Exception exc) 1620 { 1621 ErrorLogger.LogException("clsUtility", "FilterVerticalSegments", 1622 new RendererException("Failed inside FilterVerticalSegments", exc)); 1623 1624 } 1625 } 1626 /** 1627 * Client utility to calculate the channel points for channel types. 1628 * This code was ported from CJMTK. 1629 * @param arrLocation the client points 1630 * @return the channel point 1631 */ 1632 public static POINT2 ComputeLastPoint(ArrayList<POINT2> arrLocation) { 1633 POINT2 locD = new POINT2(0, 0); 1634 try { 1635 POINT2 locA = arrLocation.get(1); 1636 //Get the first point (b) in pixels. 1637 //var locB:Point=new Point(arrLocation[0].x,arrLocation[0].y); 1638 POINT2 locB = arrLocation.get(0); 1639 1640 //Compute the distance in pixels from (a) to (b). 1641 double dblDx = locB.x - locA.x; 1642 double dblDy = locB.y - locA.y; 1643 1644 //Compute the dblAngle in radians from (a) to (b). 1645 double dblTheta = Math.atan2(-dblDy, dblDx); 1646 1647 //Compute a reasonable intermediate point along the line from (a) to (b). 1648 POINT2 locC = new POINT2(0, 0); 1649 locC.x = (int) (locA.x + 0.85 * dblDx); 1650 locC.y = (int) (locA.y + 0.85 * dblDy); 1651 //Put the last point on the left side of the line from (a) to (b). 1652 double dblAngle = dblTheta + Math.PI / 2.0; 1653 if (dblAngle > Math.PI) { 1654 dblAngle = dblAngle - 2.0 * Math.PI; 1655 } 1656 if (dblAngle < -Math.PI) { 1657 dblAngle = dblAngle + 2.0 * Math.PI; 1658 } 1659 1660 //Set the magnitude of the dblWidth in pixels. Make sure it is at least 15 pixels. 1661 double dblWidth = 30;//was 15 1662 1663 //Compute the last point in pixels. 1664 locD.x = (locC.x + dblWidth * Math.cos(dblAngle)); 1665 locD.y = (locC.y - dblWidth * Math.sin(dblAngle)); 1666 } catch (Exception exc) { 1667 //clsUtility.WriteFile("Error in clsUtility.ComputeLatPoint"); 1668 ErrorLogger.LogException(_className, "ComputeLastPoint", 1669 new RendererException("Failed inside ComputeLastPoint", exc)); 1670 } 1671 return locD; 1672 } 1673 1674 /** 1675 * Called by clsChannelUtility. The segments are used for managing double-backed segments 1676 * for channel types. If the new point is double-backed then the segment at that index will be false. 1677 * 1678 * @param pixels the client points as 2-tuples x,y in pixels 1679 * @param segments OUT - the segments 1680 * @param factor a steepness factor for calculating whether the segment is double-backed 1681 */ 1682 protected static void GetSegments(double[] pixels, 1683 boolean[] segments, 1684 double factor) { 1685 try 1686 { 1687 int j = 0; 1688 ref<double[]> m1 = new ref(); 1689 ref<double[]> m2 = new ref(); 1690 long numPoints = 0; 1691 boolean bolVertical1 = false; 1692 boolean bolVertical2 = false; 1693 1694 POINT2 pt0F = new POINT2(0, 0); 1695 POINT2 pt1F = new POINT2(0, 0); 1696 POINT2 pt2F = new POINT2(0, 0); 1697 1698 segments[0] = true; 1699 1700 numPoints = pixels.length / 2; 1701 for (j = 0; j < numPoints - 2; j++) 1702 { 1703 pt0F.x = (double) pixels[2 * j]; 1704 pt0F.y = (double) pixels[2 * j + 1]; 1705 1706 pt1F.x = (double) pixels[2 * j + 2]; 1707 pt1F.y = (double) pixels[2 * j + 3]; 1708 1709 pt2F.x = (double) pixels[2 * j + 4]; 1710 pt2F.y = (double) pixels[2 * j + 5]; 1711 1712 bolVertical1 = lineutility.CalcTrueSlopeDoubleForRoutes(pt0F, pt1F, m1); 1713 bolVertical2 = lineutility.CalcTrueSlopeDoubleForRoutes(pt1F, pt2F, m2); 1714 1715 segments[j + 1] = true; 1716 if (bolVertical1 == true && bolVertical2 == true) 1717 { 1718 if (Math.abs(Math.atan(m1.value[0]) - Math.atan(m2.value[0])) < 1 / factor && InXOrder(pt0F, pt1F, pt2F) == false) //was 0.1 1719 { 1720 segments[j + 1] = false; 1721 } 1722 } 1723 1724 if ((bolVertical1 == false || Math.abs(m1.value[0]) > factor) && (bolVertical2 == false || Math.abs(m2.value[0]) > factor) && InYOrder(pt0F, pt1F, pt2F) == false) //was 10 1725 { 1726 segments[j + 1] = false; 1727 } 1728 } //end for 1729 //int n=segments.length; 1730 } 1731 catch (Exception exc) 1732 { 1733 //System.out.println(e.getMessage()); 1734 //clsUtility.WriteFile("Error in clsUtility.GetSegments"); 1735 ErrorLogger.LogException(_className, "GetSegments", 1736 new RendererException("Failed inside GetSegments", exc)); 1737 } 1738 } 1739 1740 protected static void GetLCPartitions(double[] pixels, 1741 double LCChannelWith, 1742 ArrayList<P1> partitions, 1743 ArrayList<P1> singleLinePartitions) { 1744 try 1745 { 1746 int numPoints = pixels.length / 2; 1747 POINT2 pt0F = new POINT2(0, 0); 1748 POINT2 pt1F = new POINT2(0, 0); 1749 POINT2 pt2F = new POINT2(0, 0); 1750 1751 P1 nextP = new P1(); 1752 nextP.start = 0; 1753 1754 //used for debugging 1755 double[] angles = new double[numPoints - 1]; 1756 1757 for (int i = 0; i < numPoints - 2; i++) { 1758 pt0F.x = (double) pixels[2 * i]; 1759 pt0F.y = (double) pixels[2 * i + 1]; 1760 1761 pt1F.x = (double) pixels[2 * i + 2]; 1762 pt1F.y = (double) pixels[2 * i + 3]; 1763 1764 pt2F.x = (double) pixels[2 * i + 4]; 1765 pt2F.y = (double) pixels[2 * i + 5]; 1766 1767 double angle1 = Math.atan2(pt1F.y - pt0F.y, pt1F.x - pt0F.x); 1768 double angle2 = Math.atan2(pt1F.y - pt2F.y, pt1F.x - pt2F.x); 1769 double angle = angle1-angle2;// * 180/Math.PI; 1770 double degrees = angle * 180/Math.PI; 1771 if (angle < 0) { 1772 degrees = 360 + degrees; 1773 } 1774 1775 if (degrees > 270) { 1776 boolean angleTooSmall = false; 1777 1778 if (lineutility.CalcDistanceDouble(pt0F, pt1F) < lineutility.CalcDistanceDouble(pt1F, pt2F)) { 1779 POINT2 newPt = lineutility.ExtendAlongLineDouble2(pt1F, pt2F, lineutility.CalcDistanceDouble(pt1F, pt0F)); 1780 if (lineutility.CalcDistanceDouble(pt0F, newPt) < LCChannelWith) 1781 angleTooSmall = true; 1782 } else { 1783 POINT2 newPt = lineutility.ExtendAlongLineDouble2(pt1F, pt0F, lineutility.CalcDistanceDouble(pt1F, pt2F)); 1784 if (lineutility.CalcDistanceDouble(pt2F, newPt) < LCChannelWith) 1785 angleTooSmall = true; 1786 } 1787 if (angleTooSmall) { 1788 // Angle is too small to fit channel, make it a single line partition 1789 nextP.end_Renamed = i - 1; 1790 partitions.add(nextP); 1791 nextP = new P1(); 1792 nextP.start = i; 1793 nextP.end_Renamed=i + 2; 1794 singleLinePartitions.add(nextP); 1795 i++; 1796 nextP = new P1(); 1797 nextP.start = i + 1; 1798 } 1799 } else if(degrees < 90) { 1800 // new Partition 1801 nextP.end_Renamed = i; 1802 partitions.add(nextP); 1803 nextP = new P1(); 1804 nextP.start = i + 1; 1805 } 1806 angles[i] = degrees; 1807 } //end for 1808 nextP.end_Renamed = numPoints - 2; 1809 partitions.add(nextP); 1810 } catch (Exception exc) { 1811 ErrorLogger.LogException(_className, "GetLCPartitions", 1812 new RendererException("Failed inside GetLCPartitions", exc)); 1813 } 1814 } 1815 1816 /** 1817 * Sets the color for the current shape depending on the affiliation 1818 * @param tg 1819 * @param shape 1820 */ 1821 protected static void SetLCColor(TGLight tg, Shape2 shape) { 1822 try { 1823 if (tg.isHostile()) { 1824 if (shape.getLineColor() == Color.RED) { 1825 shape.setLineColor(tg.get_LineColor()); 1826 } else { 1827 shape.setLineColor(Color.RED); 1828 } 1829 } else { 1830 if (shape.getLineColor() != Color.RED) { 1831 shape.setLineColor(tg.get_LineColor()); 1832 } else { 1833 shape.setLineColor(Color.RED); 1834 } 1835 } 1836 1837 } catch (Exception exc) { 1838 //WriteFile("Error in clsUtility.SetLCColor"); 1839 ErrorLogger.LogException(_className, "SetLCColor", 1840 new RendererException("Failed inside SetLCColor", exc)); 1841 } 1842 } 1843 /** 1844 * USAS requires a left-right orientation for ENY, which negates the upper-lower 1845 * orientation we used for Mil-Std-2525 ENY compliance. Therefore we must reverse 1846 * the client points for two of the quadrants 1847 * @param tg tactical graphic 1848 */ 1849 public static void ReverseUSASLCPointsByQuadrant(TGLight tg) 1850 { 1851 try 1852 { 1853 if(tg.Pixels.size()<2) 1854 return; 1855 int quadrant=lineutility.GetQuadrantDouble(tg.Pixels.get(0), tg.Pixels.get(1)); 1856 switch(tg.get_LineType()) 1857 { 1858 case TacticalLines.LC: 1859 if(tg.isHostile()) 1860 { 1861 switch(quadrant) 1862 { 1863 case 2: 1864 case 3: 1865 break; 1866 case 1://reverse the points for these two quadrants 1867 case 4: 1868 int n=tg.Pixels.size(); 1869 ArrayList<POINT2> pts2=(ArrayList<POINT2>)tg.Pixels.clone(); 1870 //for(int j=0;j<tg.Pixels.size();j++) 1871 for(int j=0;j<n;j++) 1872 tg.Pixels.set(j, pts2.get(n-j-1)); 1873 break; 1874 }//end switch quadrant 1875 }//end if 1876 else 1877 { 1878 switch(quadrant) 1879 { 1880 case 1: 1881 case 4: 1882 break; 1883 case 2://reverse the points for these two quadrants 1884 case 3: 1885 int n=tg.Pixels.size(); 1886 ArrayList<POINT2> pts2=(ArrayList<POINT2>)tg.Pixels.clone(); 1887 //for(int j=0;j<tg.Pixels.size();j++) 1888 for(int j=0;j<n;j++) 1889 tg.Pixels.set(j, pts2.get(n-j-1)); 1890 break; 1891 }//end switch quadrant 1892 }//end else 1893 break; 1894 default: 1895 break; 1896 }//end switch linetype 1897 } 1898 catch (Exception exc) { 1899 //WriteFile("Error in clsUtility.SetLCColor"); 1900 ErrorLogger.LogException(_className, "ReverseUSASLCPointsByQuadrant", 1901 new RendererException("Failed inside ReverseUSASLCPointsByQuadrant", exc)); 1902 } 1903 }//end ReverseUSASLCPointsByQuadrant 1904 1905 /** 1906 * use str if tg is null 1907 * @param symbolId Mil=Standard-2525 symbol id 1908 * @return line type 1909 */ 1910 public static int GetLinetypeFromString(String symbolId) 1911 { 1912 try 1913 { 1914 if (symbolId.length() < 16){ 1915 return -1; 1916 } 1917 int symbolSet = SymbolID.getSymbolSet(symbolId); 1918 int entityCode = SymbolID.getEntityCode(symbolId); 1919 int version = SymbolID.getVersion(symbolId); 1920 if (symbolSet == 25) { 1921 return clsRenderer.getCMLineType(version, entityCode); 1922 } else if (symbolSet == 45 || symbolSet == 46) { 1923 return clsMETOC.getWeatherLinetype(version, entityCode); 1924 } 1925 } 1926 catch (Exception exc) { 1927 ErrorLogger.LogException(_className ,"GetLinetypeFromString", 1928 new RendererException("Failed inside GetLinetypeFromString", exc)); 1929 } 1930 return -1; 1931 } 1932 1933 /** 1934 * An auto-shape is a symbol with a fixed number of anchor points 1935 * 1936 * @param tg tactical graphic 1937 * @return true if auto-shape 1938 */ 1939 public static boolean isAutoshape(TGLight tg) { 1940 try { 1941 switch(tg.get_LineType()) 1942 { 1943 case TacticalLines.BBS_RECTANGLE: 1944 case TacticalLines.BS_RECTANGLE: 1945 case TacticalLines.BS_ELLIPSE: 1946 case TacticalLines.PBS_CIRCLE: 1947 case TacticalLines.BS_CROSS: 1948 case TacticalLines.BS_BBOX: 1949 case TacticalLines.BBS_POINT: 1950 return true; 1951 } 1952 MSInfo msInfo = MSLookup.getInstance().getMSLInfo(tg.get_SymbolId()); 1953 if (msInfo == null || IsChange1Area(tg.get_LineType())) { 1954 return false; 1955 } 1956 switch (tg.get_LineType()) { 1957 case TacticalLines.DIRATKAIR: 1958 case TacticalLines.DIRATKGND: 1959 case TacticalLines.DIRATKSPT: 1960 case TacticalLines.INFILTRATION: 1961 // Direction of attack symbols only have two points but can handle more 1962 return false; 1963 default: 1964 break; 1965 } 1966 switch (msInfo.getDrawRule()) { 1967 case DrawRules.LINE26: // Two ways to draw but fixed points 1968 case DrawRules.LINE27: // Two ways to draw but fixed points 1969 case DrawRules.AREA26: // Need same number of points in first half and second half to make two shapes 1970 case DrawRules.CORRIDOR1: // Each point represents an Air Control Point or Communications Checkpoint 1971 return true; 1972 default: 1973 return msInfo.getMaxPointCount() == msInfo.getMinPointCount(); 1974 } 1975 } catch (Exception exc) { 1976 ErrorLogger.LogException(_className, "isAutoshape", 1977 new RendererException("Failed inside isAutoshape", exc)); 1978 } 1979 return false; 1980 } 1981 /** 1982 * Client will send the segment colors within a modifier. 1983 * Format is 0:FFBBBB,4:FFAAAA,... 1984 * For the time being will assume the modifier being used is the H modifier 1985 * @param tg 1986 * @return 1987 */ 1988 public static HashMap<Integer,Color> getMSRSegmentColors(TGLight tg) 1989 { 1990 HashMap<Integer,Color> hMap=null; 1991 try 1992 { 1993 int linetype=tg.get_LineType(); 1994 switch(linetype) 1995 { 1996 case TacticalLines.MSR: 1997 case TacticalLines.ASR: 1998 case TacticalLines.TRAFFIC_ROUTE: 1999 case TacticalLines.BOUNDARY: 2000 if(tg.get_H()==null || tg.get_H().isEmpty()) 2001 return null; 2002 hMap=new HashMap<Integer,Color>(); 2003 break; 2004 default: 2005 return null; 2006 } 2007 String[]colorStrs=tg.get_H().split(","); 2008 int j=0,numSegs=colorStrs.length; 2009 String segPlusColor=""; 2010 String[]seg=null; 2011 Color color=null; 2012 int index=-1; 2013 for(j=0;j<numSegs;j++) 2014 { 2015 segPlusColor=colorStrs[j]; 2016 if(!segPlusColor.contains(":")) 2017 continue; 2018 seg=segPlusColor.split(":"); 2019 color= RendererUtilities.getColorFromHexString(seg[1]); 2020 index=Integer.parseInt(seg[0]); 2021 hMap.put(index, color); 2022 } 2023 } 2024 catch (Exception exc) 2025 { 2026 ErrorLogger.LogException(_className ,"getMSRSegmentColors", 2027 new RendererException("Failed inside getMSRSegmentColors", exc)); 2028 } 2029 return hMap; 2030 } 2031 public static HashMap<Integer,String> getMSRSegmentColorStrings(TGLight tg) 2032 { 2033 HashMap<Integer,String> hMap=null; 2034 try 2035 { 2036 int linetype = tg.get_LineType(); 2037 switch (linetype) { 2038 case TacticalLines.MSR: 2039 case TacticalLines.ASR: 2040 case TacticalLines.TRAFFIC_ROUTE: 2041 case TacticalLines.BOUNDARY: 2042 if (tg.get_H() == null || tg.get_H().isEmpty()) 2043 return null; 2044 hMap = new HashMap<>(); 2045 break; 2046 default: 2047 return null; 2048 } 2049 String[] colorStrs = tg.get_H().split(","); 2050 int j = 0; 2051 int numSegs = colorStrs.length; 2052 String segPlusColor = ""; 2053 String[] seg = null; 2054 //Color color = null; 2055 int index = -1; 2056 for (j = 0; j < numSegs; j++) { 2057 segPlusColor = colorStrs[j]; 2058 if (!segPlusColor.contains(":")) 2059 continue; 2060 seg = segPlusColor.split(":"); 2061 //color = armyc2.c5isr.renderer.utilities.SymbolUtilitiesD.getColorFromHexString(seg[1]); 2062 index = Integer.parseInt(seg[0]); 2063 //hMap.put(new Integer(index), color); 2064 hMap.put(new Integer(index), seg[1]); 2065 } 2066 } 2067 catch (Exception exc) 2068 { 2069 ErrorLogger.LogException(_className ,"getMSRSegmentColorStrings", 2070 new RendererException("Failed inside getMSRSegmentColorStrings", exc)); 2071 } 2072 return hMap; 2073 } 2074 /** 2075 * tg.H must be revised for clipped MSR, ASR and Boundary 2076 * This function is called after the pixels were clipped 2077 * @param originalPixels the tactical graphic pixels before clipping 2078 * @param tg 2079 * @deprecated 2080 */ 2081 public static void reviseHModifier(ArrayList<POINT2>originalPixels, 2082 TGLight tg) 2083 { 2084 try 2085 { 2086 //only revise tg.H if it is not null or empty 2087 //and the linetype is bounday, MSR, or ASR 2088 if(tg.get_H()==null || tg.get_H().isEmpty()) 2089 return; 2090 int linetype=tg.get_LineType(); 2091 switch(linetype) 2092 { 2093 case TacticalLines.ASR: 2094 case TacticalLines.MSR: 2095 case TacticalLines.TRAFFIC_ROUTE: 2096 case TacticalLines.BOUNDARY: 2097 break; 2098 default: 2099 return; 2100 } 2101 int j=0,k=0; 2102 //Line2D line=new Line2D.Double(); 2103 2104 //get the first common point between the original points and tg.Pixels 2105 //if it is n then n segments will have been dropped at the front end of 2106 //the clipped array (from the original pixels) so then we would want to 2107 //set the start index to n for the loop through the original points 2108 int n=-1; 2109 boolean foundPt=false; 2110 int t=originalPixels.size(); 2111 int u=tg.Pixels.size(); 2112 //for(j=0;j<originalPixels.size();j++) 2113 for(j=0;j<t;j++) 2114 { 2115 //for(k=0;k<tg.Pixels.size();k++) 2116 for(k=0;k<u;k++) 2117 { 2118 if(originalPixels.get(j).x==tg.Pixels.get(k).x && originalPixels.get(j).y==tg.Pixels.get(k).y) 2119 { 2120 n=j; 2121 foundPt=true; 2122 break; 2123 } 2124 } 2125 if(foundPt) 2126 break; 2127 } 2128 HashMap<Integer,Color> hmap=getMSRSegmentColors(tg); 2129 //use a 2nd hashmap to store the revised segment numbers, and exisitng Colors 2130 HashMap<Integer,Color> hmap2=new HashMap<Integer,Color>(); 2131 POINT2 segPt0=null,segPt1=null; //the original segments 2132 POINT2 pt0=null,pt1=null; //the clipped segments 2133 Color color=null; 2134 if(n<1) 2135 n=1; 2136 for(Integer key : hmap.keySet()) //keys can begin at 0 2137 { 2138 if(key<n-1) 2139 continue; 2140 if(key+1>originalPixels.size()-1) 2141 break; 2142 color=hmap.get(key); 2143 segPt0=originalPixels.get(key); 2144 segPt1=originalPixels.get(key+1); 2145 u=tg.Pixels.size(); 2146 //for(j=0;j<tg.Pixels.size()-1;j++) 2147 for(j=0;j<u-1;j++) 2148 { 2149 pt0=tg.Pixels.get(j);//clipped pixels 2150 pt1=tg.Pixels.get(j+1); 2151 if(segPt0.x==pt0.x && segPt0.y==pt0.y) 2152 { 2153 hmap2.put(j, color); 2154 break; 2155 } 2156 else if(segPt1.x==pt1.x && segPt1.y==pt1.y) 2157 { 2158 hmap2.put(j, color); 2159 break; 2160 } 2161 else 2162 { 2163 if(pt0.x==segPt1.x && pt0.y==segPt1.y) 2164 continue; 2165 if(pt1.x==segPt0.x && pt1.y==segPt0.y) 2166 continue; 2167 else 2168 { 2169 //if the original segment straddles or clips the clipping area 2170 //then the original segment will contain the clipped segment 2171 double dist0=lineutility.CalcDistanceToLineDouble(segPt0, segPt1, pt0); 2172 double dist1=lineutility.CalcDistanceToLineDouble(segPt0, segPt1, pt1); 2173 Line2D lineOrigPts=new Line2D.Double(segPt0.x,segPt0.y, segPt1.x,segPt1.y); 2174 Rectangle2D rectOrigPts=lineOrigPts.getBounds2D(); 2175 Line2D lineClipPts=new Line2D.Double(pt0.x,pt0.y, pt1.x, pt1.y); 2176 Rectangle2D rectClipPts=lineClipPts.getBounds2D(); 2177 //test if the lines coincide and the clipped segment is within the original segment 2178 if(dist0<1 && dist1<1 && rectOrigPts.contains(rectClipPts)) 2179 { 2180 hmap2.put(j, color); 2181 } 2182 } 2183 } 2184 } 2185 } 2186 if(hmap2.isEmpty()) 2187 { 2188 tg.set_H(""); 2189 return; 2190 } 2191 2192 String h="",temp=""; 2193 for(Integer key : hmap2.keySet()) 2194 { 2195 color=hmap2.get(key); 2196 temp=Integer.toHexString(color.toARGB()); 2197 h+=key.toString()+":"+temp+","; 2198 } 2199 h=h.substring(0, h.length()-1); 2200 tg.set_H(h); 2201 } 2202 catch (Exception exc) { 2203 ErrorLogger.LogException(_className, "reviseHModifer", 2204 new RendererException("Failed inside reviseHModifier", exc)); 2205 } 2206 } 2207 2208 /** 2209 * Adds extra points to LC if there are angles too small to fit the channel 2210 * @param tg 2211 * @param converter 2212 */ 2213 public static void SegmentLCPoints(TGLight tg, IPointConversion converter) { 2214 try { 2215 if (tg.get_LineType() != TacticalLines.LC) 2216 return; 2217 2218 ArrayList<POINT2> points = tg.get_Pixels(); 2219 2220 double LCChannelWith = arraysupport.getScaledSize(40, tg.get_LineThickness(), tg.get_patternScale()); 2221 2222 for (int i = 0; i < points.size() - 2; i++) { 2223 POINT2 ptA = new POINT2(points.get(i).x, points.get(i).y); 2224 POINT2 ptB = new POINT2(points.get(i+1).x, points.get(i+1).y); 2225 POINT2 ptC = new POINT2(points.get(i+2).x, points.get(i+2).y); 2226 2227 double angle1 = Math.atan2(ptB.y - ptA.y, ptB.x - ptA.x); 2228 double angle2 = Math.atan2(ptB.y - ptC.y, ptB.x - ptC.x); 2229 double angle = angle1 - angle2; 2230 double degrees = angle * 180/Math.PI; 2231 2232 if(angle < 0) { 2233 degrees = 360 + degrees; 2234 } 2235 2236 if (degrees > 270) { 2237 // For acute angles where red is the outer line 2238 // Determine shorter segment (BA or BC) 2239 // On longer segment calculate potential new point (newPt) that is length of smaller segment from B 2240 // If distance between smaller segment end point (A or C) and newPt is smaller than the channel width add newPt to points 2241 // In GetLCPartitions() the black line won't be included between the smaller line and newPt since there isn't enough space to fit the channel 2242 if (lineutility.CalcDistanceDouble(ptB, ptA) < lineutility.CalcDistanceDouble(ptB, ptC)) { 2243 // BA is smaller segment 2244 POINT2 newPt = lineutility.ExtendAlongLineDouble2(ptB, ptC, lineutility.CalcDistanceDouble(ptB, ptA)); 2245 if (lineutility.CalcDistanceDouble(ptA, newPt) < LCChannelWith) { 2246 points.add(i + 2, new POINT2(newPt.x, newPt.y)); 2247 i++; 2248 } 2249 } else { 2250 // BC is smaller segment 2251 POINT2 newPt = lineutility.ExtendAlongLineDouble2(ptB, ptA, lineutility.CalcDistanceDouble(ptB, ptC)); 2252 if (lineutility.CalcDistanceDouble(ptC, newPt) < LCChannelWith) { 2253 points.add(i + 1, new POINT2(newPt.x, newPt.y)); 2254 i++; 2255 } 2256 } 2257 } 2258 } 2259 tg.Pixels = points; 2260 tg.LatLongs = armyc2.c5isr.RenderMultipoints.clsUtility.PixelsToLatLong(points, converter); 2261 } catch (Exception exc) { 2262 ErrorLogger.LogException(_className, "segmentLCPoints", 2263 new RendererException("Failed inside segmentLCPoints", exc)); 2264 } 2265 } 2266 /** 2267 * Interpolate pixels for lines with points too close together. 2268 * Drops successive points until the next point is at least 10 pixels from the preceding point 2269 * @param tg 2270 */ 2271 public static void InterpolatePixels(TGLight tg) 2272 { 2273 try 2274 { 2275 if(tg.get_UseLineInterpolation()==false) 2276 return; 2277 2278 int linetype=tg.get_LineType(); 2279 double glyphSize=10; 2280 switch(linetype) 2281 { 2282 case TacticalLines.ATDITCH: 2283 case TacticalLines.ATDITCHC: 2284 glyphSize=25; 2285 break; 2286 case TacticalLines.ATDITCHM: 2287 glyphSize=50; 2288 break; 2289 case TacticalLines.FLOT: 2290 case TacticalLines.LC: 2291 case TacticalLines.FORT_REVD: 2292 case TacticalLines.FORT: 2293 case TacticalLines.FORTL: 2294 case TacticalLines.ENCIRCLE: 2295 case TacticalLines.ZONE: 2296 case TacticalLines.OBSFAREA: 2297 case TacticalLines.OBSAREA: 2298 case TacticalLines.DOUBLEA: 2299 case TacticalLines.LWFENCE: 2300 case TacticalLines.HWFENCE: 2301 case TacticalLines.BBS_LINE: 2302 case TacticalLines.SINGLEC: 2303 case TacticalLines.DOUBLEC: 2304 case TacticalLines.TRIPLE: 2305 case TacticalLines.STRONG: 2306 glyphSize= arraysupport.getScaledSize(30, tg.get_LineThickness(), tg.get_patternScale()); 2307 break; 2308 case TacticalLines.UNSP: 2309 case TacticalLines.LINE: 2310 case TacticalLines.ATWALL: 2311 case TacticalLines.SFENCE: 2312 glyphSize=arraysupport.getScaledSize(40, tg.get_LineThickness(), tg.get_patternScale()); 2313 break; 2314 case TacticalLines.DFENCE: 2315 glyphSize=arraysupport.getScaledSize(50, tg.get_LineThickness(), tg.get_patternScale()); 2316 break; 2317 default: 2318 return; 2319 } 2320 HashMap<Integer,POINT2> hmapPixels=new HashMap<Integer,POINT2>(); 2321 HashMap<Integer,POINT2> hmapGeo=new HashMap<Integer,POINT2>(); 2322 int j=0,currentIndex=0; 2323 double dist=0,dist2=0; 2324 double direction1=0,direction2=0,delta=0; 2325 POINT2 pt0=null,pt1=null,pt2=null; 2326 int n=tg.Pixels.size(); 2327 //for(j=0;j<tg.Pixels.size();j++) 2328 for(j=0;j<n;j++) 2329 { 2330 if(j==0) 2331 { 2332 hmapPixels.put(j, tg.Pixels.get(j)); 2333 hmapGeo.put(j, tg.LatLongs.get(j)); 2334 currentIndex=0; 2335 } 2336 else if(j==tg.Pixels.size()-1) 2337 { 2338 hmapPixels.put(j, tg.Pixels.get(j)); 2339 hmapGeo.put(j, tg.LatLongs.get(j)); 2340 } 2341 else 2342 { 2343 dist=lineutility.CalcDistanceDouble(tg.Pixels.get(currentIndex), tg.Pixels.get(j)); 2344 dist2=lineutility.CalcDistanceDouble(tg.Pixels.get(j), tg.Pixels.get(j+1)); 2345 2346 //change of direction test 2-28-13 2347 pt0=tg.Pixels.get(currentIndex); 2348 pt1=tg.Pixels.get(j); 2349 pt2=tg.Pixels.get(j+1); 2350 direction1=(180/Math.PI)*Math.atan((pt0.y-pt1.y)/(pt0.x-pt1.x)); 2351 direction2=(180/Math.PI)*Math.atan((pt1.y-pt2.y)/(pt1.x-pt2.x)); 2352 delta=Math.abs(direction1-direction2); 2353 if(dist>glyphSize || dist2>glyphSize || delta>20) 2354 { 2355 hmapPixels.put(j, tg.Pixels.get(j)); 2356 hmapGeo.put(j, tg.LatLongs.get(j)); 2357 currentIndex=j; 2358 } 2359 } 2360 } 2361 ArrayList<POINT2>pixels=new ArrayList(); 2362 ArrayList<POINT2>geo=new ArrayList(); 2363 n=tg.Pixels.size(); 2364 //for(j=0;j<tg.Pixels.size();j++) 2365 for(j=0;j<n;j++) 2366 { 2367 if(hmapPixels.containsKey(j)) 2368 pixels.add((POINT2)hmapPixels.get(j)); 2369 if(hmapGeo.containsKey(j)) 2370 geo.add((POINT2)hmapGeo.get(j)); 2371 } 2372 switch(linetype) 2373 { 2374 case TacticalLines.FORT_REVD: 2375 case TacticalLines.FORT: 2376 case TacticalLines.ENCIRCLE: 2377 case TacticalLines.ZONE: 2378 case TacticalLines.OBSFAREA: 2379 case TacticalLines.OBSAREA: 2380 case TacticalLines.STRONG: 2381 if(pixels.size()==2) 2382 { 2383 n=tg.Pixels.size(); 2384 //for(j=0;j<tg.Pixels.size();j++) 2385 for(j=0;j<n;j++) 2386 { 2387 if(hmapPixels.containsKey(j)==false && hmapGeo.containsKey(j)==false) 2388 { 2389 pixels.add(j,tg.Pixels.get(j)); 2390 geo.add(j,tg.LatLongs.get(j)); 2391 break; 2392 } 2393 } 2394 } 2395 break; 2396 default: 2397 break; 2398 } 2399 tg.Pixels=pixels; 2400 tg.LatLongs=geo; 2401 } 2402 catch (Exception exc) { 2403 ErrorLogger.LogException(_className, "InterpolatePixels", 2404 new RendererException("Failed inside InterpolatePixels", exc)); 2405 } 2406 } 2407 /** 2408 * construct a line segment outside the polygon corresponding to some index 2409 * @param tg 2410 * @param index 2411 * @param dist 2412 * @return 2413 */ 2414 protected static Line2D getExtendedLine(TGLight tg, 2415 int index, 2416 double dist) 2417 { 2418 Line2D line=null; 2419 try 2420 { 2421 Polygon polygon=new Polygon(); 2422 int j=0; 2423 int n=tg.Pixels.size(); 2424 //for(j=0;j<tg.Pixels.size();j++) 2425 for(j=0;j<n;j++) 2426 { 2427 polygon.addPoint((int)tg.Pixels.get(j).x, (int)tg.Pixels.get(j).y); 2428 } 2429 POINT2 pt0=null; 2430 POINT2 pt1=null; 2431 if(tg.Pixels.size()>3) 2432 { 2433 pt0=tg.Pixels.get(index); 2434 pt1=tg.Pixels.get(index+1); 2435 } 2436 else 2437 { 2438 pt0=tg.Pixels.get(1); 2439 pt1=tg.Pixels.get(2); 2440 } 2441 2442 POINT2 ptExtend=null; 2443 int extend=-1; 2444 POINT2 midPt=lineutility.MidPointDouble(pt0, pt1,0); 2445 double slope=Math.abs(pt1.y-pt0.y)/(pt1.x-pt0.x); 2446 if(slope<=1) 2447 { 2448 ptExtend=lineutility.ExtendDirectedLine(pt0, pt1, midPt, lineutility.extend_above, 2); 2449 if(polygon.contains(ptExtend.x,ptExtend.y)) 2450 extend=lineutility.extend_below; 2451 else 2452 extend=lineutility.extend_above; 2453 } 2454 else 2455 { 2456 ptExtend=lineutility.ExtendDirectedLine(pt0, pt1, midPt, lineutility.extend_left, 2); 2457 if(polygon.contains(ptExtend.x,ptExtend.y)) 2458 extend=lineutility.extend_right; 2459 else 2460 extend=lineutility.extend_left; 2461 2462 } 2463 POINT2 pt3=null; 2464 POINT2 pt4=null; 2465 pt3=lineutility.ExtendDirectedLine(pt0, pt1, pt0, extend, dist); 2466 pt4=lineutility.ExtendDirectedLine(pt0, pt1, pt1, extend, dist); 2467 line=new Line2D.Double(pt3.x, pt3.y, pt4.x, pt4.y); 2468 } 2469 catch (Exception exc) { 2470 ErrorLogger.LogException(_className, "getExtendedLine", 2471 new RendererException("Failed inside getExtendedLine", exc)); 2472 } 2473 return line; 2474 } 2475 2476}//end clsUtility