| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.data.writer; |
| 20 |
|
| 21 |
import java.util.ArrayList; |
| 22 |
import java.util.List; |
| 23 |
import java.util.ListIterator; |
| 24 |
|
| 25 |
import footleg.cavesurvey.converter.CaveConverter; |
| 26 |
import footleg.cavesurvey.converter.Logger; |
| 27 |
import footleg.cavesurvey.converter.CaveConverter.BearingUnit; |
| 28 |
import footleg.cavesurvey.converter.CaveConverter.GradientUnit; |
| 29 |
import footleg.cavesurvey.converter.CaveConverter.LengthUnit; |
| 30 |
import footleg.cavesurvey.data.model.CaveSurvey; |
| 31 |
import footleg.cavesurvey.data.model.SeriesLink; |
| 32 |
import footleg.cavesurvey.data.model.SurveyLeg; |
| 33 |
import footleg.cavesurvey.data.model.SurveySeries; |
| 34 |
import footleg.cavesurvey.data.model.SurveySeries.ToStnLRUD; |
| 35 |
import footleg.cavesurvey.data.model.SurveyStation; |
| 36 |
import footleg.cavesurvey.tools.UtilityFunctions; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public class SurvexWriter { |
| 57 |
private Logger logger; |
| 58 |
|
| 59 |
public SurvexWriter( Logger logger ) { |
| 60 |
super(); |
| 61 |
this.logger = logger; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public static enum SplayFormats { |
| 68 |
None, |
| 69 |
Flagged, |
| 70 |
Anonymous |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public List<String> generateSurvexData( CaveSurvey surveyData, SplayFormats splaysOutput ) { |
| 81 |
List<String> outputData = new ArrayList<String>(); |
| 82 |
|
| 83 |
logger.logMessage("Generating Survex format data..."); |
| 84 |
|
| 85 |
|
| 86 |
SurveySeries parentSeries = new SurveySeries("parent"); |
| 87 |
|
| 88 |
|
| 89 |
ListIterator<SurveySeries> seriesIterator = surveyData.listIterator(); |
| 90 |
while ( seriesIterator.hasNext() ) { |
| 91 |
SurveySeries series = seriesIterator.next(); |
| 92 |
|
| 93 |
outputData.addAll( generateSurvexDataSeries( series, parentSeries, splaysOutput ) ); |
| 94 |
} |
| 95 |
|
| 96 |
return outputData; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
private List<String> generateSurvexDataSeries( SurveySeries series, SurveySeries parentSeries, SplayFormats splaysOutput ) { |
| 107 |
List<String> outputData = new ArrayList<String>(); |
| 108 |
List<String> legsData = new ArrayList<String>(); |
| 109 |
List<String> fixedStnsData = new ArrayList<String>(); |
| 110 |
|
| 111 |
|
| 112 |
List<List<String[]>> passageData = new ArrayList<List<String[]>>(); |
| 113 |
|
| 114 |
boolean duplicateFlagOn = false; |
| 115 |
boolean surfaceFlagOn = false; |
| 116 |
boolean splayFlagOn = false; |
| 117 |
boolean nosurveyFlagOn = false; |
| 118 |
int splayNameSequence = 0; |
| 119 |
|
| 120 |
|
| 121 |
outputData.add( "*BEGIN " + substIllegalNameChars( series.getSeriesName() ) ); |
| 122 |
|
| 123 |
|
| 124 |
if ( series.getComment().length() > 0 ) { |
| 125 |
String[] dataItems = UtilityFunctions.parseTripComment( series.getComment() ); |
| 126 |
for (String line : dataItems) { |
| 127 |
outputData.add( ";" + line ); |
| 128 |
} |
| 129 |
outputData.add( "" ); |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
if ( series.getSurveyDate() != null ) { |
| 134 |
outputData.add( "*DATE " + UtilityFunctions.dateToString( series.getSurveyDate(), UtilityFunctions.SURVEXDATE_FORMAT) ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
if ( series.getDeclination() != parentSeries.getDeclination() ) { |
| 140 |
outputData.add( "*CALIBRATE declination " + series.getDeclination() ); |
| 141 |
} |
| 142 |
if ( series.getTapeCalibration(LengthUnit.Metres) != parentSeries.getTapeCalibration(LengthUnit.Metres) ) { |
| 143 |
outputData.add( "*CALIBRATE tape " + CaveConverter.padNumber( series.getTapeCalibration(LengthUnit.Metres), 2, 0 ) ); |
| 144 |
} |
| 145 |
if ( series.getCompassCalibration(BearingUnit.Degrees) != parentSeries.getCompassCalibration(BearingUnit.Degrees) ) { |
| 146 |
outputData.add( "*CALIBRATE compass " + series.getCompassCalibration(BearingUnit.Degrees) ); |
| 147 |
} |
| 148 |
if ( series.getClinoCalibration(GradientUnit.Degrees) != parentSeries.getClinoCalibration(GradientUnit.Degrees) ) { |
| 149 |
outputData.add( "*CALIBRATE clino " + series.getClinoCalibration(GradientUnit.Degrees) ); |
| 150 |
} |
| 151 |
outputData.add( "" ); |
| 152 |
|
| 153 |
|
| 154 |
if ( splaysOutput == SplayFormats.Anonymous ) { |
| 155 |
outputData.add( "*alias station - .." ); |
| 156 |
outputData.add( "" ); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
ListIterator<SeriesLink> linksIterator = series.getLinks().listIterator(); |
| 162 |
while ( linksIterator.hasNext() ) { |
| 163 |
SeriesLink link = linksIterator.next(); |
| 164 |
String equate = "*EQUATE "; |
| 165 |
|
| 166 |
String series1Prefix = ""; |
| 167 |
String series2Prefix = ""; |
| 168 |
if ( link.getSeries1().length() > 0 ) { |
| 169 |
series1Prefix = substIllegalNameChars( link.getSeries1() ) + "."; |
| 170 |
} |
| 171 |
if ( link.getSeries2().length() > 0 ) { |
| 172 |
series2Prefix = substIllegalNameChars( link.getSeries2() ) + "."; |
| 173 |
} |
| 174 |
equate += series1Prefix + substIllegalNameChars( link.getStn1().getName() ) + " " + |
| 175 |
series2Prefix + substIllegalNameChars( link.getStn2().getName() ); |
| 176 |
|
| 177 |
outputData.add( equate ); |
| 178 |
} |
| 179 |
outputData.add( ""); |
| 180 |
|
| 181 |
|
| 182 |
boolean skipDataOrderLine = false; |
| 183 |
if ( series.hasDataOrder() ) { |
| 184 |
if ( parentSeries.hasDataOrder() ) { |
| 185 |
if ( UtilityFunctions.compareStringLists( series.getDataOrder(), parentSeries.getDataOrder() ) ) { |
| 186 |
if ( series.getDataOrder2().size() == 0 && parentSeries.getDataOrder2().size() == 0 ) { |
| 187 |
|
| 188 |
skipDataOrderLine = true; |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
if ( ( skipDataOrderLine == false ) && ( series.legCount() == 0 ) && ( series.hasDataOrder() ) ) { |
| 197 |
outputData.add( "*" + UtilityFunctions.dataFormatLineForSeries( series, false ) ); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
int psuedoLegCount = series.legCount() + series.getToStnLRUDs().size(); |
| 202 |
boolean lastLegWasDiving = false; |
| 203 |
for ( int psuedoLegIdx = 0; psuedoLegIdx < psuedoLegCount; psuedoLegIdx++ ) { |
| 204 |
|
| 205 |
SurveyLeg leg; |
| 206 |
if ( psuedoLegIdx < series.legCount() ) { |
| 207 |
|
| 208 |
leg = series.getLegRaw(psuedoLegIdx); |
| 209 |
|
| 210 |
if ( ( series.hasDataOrder() == false ) && ( leg.isDiving() == false ) ) { |
| 211 |
|
| 212 |
skipDataOrderLine = true; |
| 213 |
} |
| 214 |
} |
| 215 |
else { |
| 216 |
|
| 217 |
leg = new SurveyLeg(); |
| 218 |
ToStnLRUD lrud = series.getToStnLRUDs().get( psuedoLegIdx - series.legCount() ); |
| 219 |
leg.setFromStn( lrud.getFromStn() ); |
| 220 |
leg.setLeft( lrud.getLeft(), LengthUnit.Metres ); |
| 221 |
leg.setRight( lrud.getRight(), LengthUnit.Metres ); |
| 222 |
leg.setUp( lrud.getUp(), LengthUnit.Metres ); |
| 223 |
leg.setDown( lrud.getDown(), LengthUnit.Metres ); |
| 224 |
} |
| 225 |
|
| 226 |
String fromStn = leg.getFromStn().getName(); |
| 227 |
String fromStnVal = substIllegalNameChars( fromStn ); |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
if ( ( leg.isSplay() ) || ( leg.getToStn() != null ) ) { |
| 234 |
String toStn; |
| 235 |
if ( leg.getToStn() == null ) { |
| 236 |
|
| 237 |
toStn = leg.getFromStn().getName() + "-" + splayNameSequence++; |
| 238 |
} |
| 239 |
else { |
| 240 |
toStn = leg.getToStn().getName(); |
| 241 |
} |
| 242 |
String toStnVal = substIllegalNameChars( toStn ); |
| 243 |
|
| 244 |
if ( leg.isNosurvey() || leg.getLength( LengthUnit.Metres ) > 0 ) { |
| 245 |
|
| 246 |
if ( ( leg.isNosurvey() ) && nosurveyFlagOn == false ) { |
| 247 |
legsData.add( "*data nosurvey from to"); |
| 248 |
nosurveyFlagOn = true; |
| 249 |
} |
| 250 |
else if ( ( leg.isNosurvey() == false ) && nosurveyFlagOn ) { |
| 251 |
legsData.add( "*" + UtilityFunctions.dataFormatLineForSeries( series, leg.isDiving() ) ); |
| 252 |
nosurveyFlagOn = false; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
String flagsSetting = ""; |
| 257 |
|
| 258 |
if ( ( leg.isDuplicate() ) && duplicateFlagOn == false ) { |
| 259 |
flagsSetting += " DUPLICATE"; |
| 260 |
duplicateFlagOn = true; |
| 261 |
} |
| 262 |
else if ( ( leg.isDuplicate() == false ) && duplicateFlagOn ) { |
| 263 |
flagsSetting += " NOT DUPLICATE"; |
| 264 |
duplicateFlagOn = false; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
if ( ( leg.isSurface() ) && surfaceFlagOn == false ) { |
| 269 |
flagsSetting += " SURFACE"; |
| 270 |
surfaceFlagOn = true; |
| 271 |
} |
| 272 |
else if ( ( leg.isSurface() == false ) && surfaceFlagOn ) { |
| 273 |
flagsSetting += " NOT SURFACE"; |
| 274 |
surfaceFlagOn = false; |
| 275 |
} |
| 276 |
if ( splaysOutput == SplayFormats.Flagged ) { |
| 277 |
|
| 278 |
if ( ( leg.isSplay() ) && splayFlagOn == false ) { |
| 279 |
flagsSetting += " SPLAY"; |
| 280 |
splayFlagOn = true; |
| 281 |
} |
| 282 |
else if ( ( leg.isSplay() == false ) && splayFlagOn ) { |
| 283 |
flagsSetting += " NOT SPLAY"; |
| 284 |
splayFlagOn = false; |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
if ( flagsSetting.length() > 0 ) { |
| 289 |
legsData.add( "*FLAGS" + flagsSetting); |
| 290 |
} |
| 291 |
if ( ( ( splaysOutput == SplayFormats.None ) && leg.isSplay() ) == false ) { |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
boolean needDataOrderHeader = false; |
| 296 |
if ( psuedoLegIdx == 0 ) { |
| 297 |
|
| 298 |
if ( skipDataOrderLine == false ) { |
| 299 |
needDataOrderHeader = true; |
| 300 |
} |
| 301 |
} |
| 302 |
else { |
| 303 |
|
| 304 |
if ( series.getDataOrder2().size() > 0 ) { |
| 305 |
if ( lastLegWasDiving != leg.isDiving() ) { |
| 306 |
needDataOrderHeader = true; |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
lastLegWasDiving = leg.isDiving(); |
| 312 |
|
| 313 |
if ( needDataOrderHeader ) { |
| 314 |
legsData.add( "*" + UtilityFunctions.dataFormatLineForSeries( series, leg.isDiving() ) ); |
| 315 |
} |
| 316 |
|
| 317 |
List<String> dataOrder = series.getDataOrder(); |
| 318 |
if ( dataOrder.size() == 0 ) { |
| 319 |
|
| 320 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_FROMSTN ); |
| 321 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_TOSTN ); |
| 322 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_LENGTH ); |
| 323 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_BEARING ); |
| 324 |
dataOrder.add( CaveConverter.DATA_ORDER_CAT_CLINO ); |
| 325 |
} |
| 326 |
else { |
| 327 |
List<String> dataOrder2 = series.getDataOrder2(); |
| 328 |
|
| 329 |
|
| 330 |
if ( dataOrder2.size() > 0 ) { |
| 331 |
if ( UtilityFunctions.dataOrderIsDiving( dataOrder ) != leg.isDiving() ) { |
| 332 |
|
| 333 |
dataOrder = dataOrder2; |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
String legLine = ""; |
| 339 |
|
| 340 |
|
| 341 |
for ( int i = 0; i < dataOrder.size(); i++ ) { |
| 342 |
String item = dataOrder.get(i); |
| 343 |
if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_FROMSTN ) == 0 ) { |
| 344 |
legLine += fromStnVal + "\t"; |
| 345 |
} |
| 346 |
else if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_TOSTN ) == 0 ) { |
| 347 |
if ( ( splaysOutput == SplayFormats.Anonymous ) && leg.isSplay() ) { |
| 348 |
|
| 349 |
legLine += "-\t"; |
| 350 |
} |
| 351 |
else { |
| 352 |
legLine += toStnVal + "\t"; |
| 353 |
} |
| 354 |
} |
| 355 |
else if ( nosurveyFlagOn == false ) { |
| 356 |
if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_LENGTH ) == 0 ) { |
| 357 |
legLine += CaveConverter.padNumber( leg.getLength(LengthUnit.Metres), 2, 5 ) + "\t"; |
| 358 |
} |
| 359 |
else if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_BEARING ) == 0 ) { |
| 360 |
legLine += CaveConverter.padNumber( leg.getCompass(BearingUnit.Degrees), 2, 6 ) + "\t"; |
| 361 |
} |
| 362 |
else if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_CLINO ) == 0 ) { |
| 363 |
legLine += CaveConverter.padNumber( leg.getClino(GradientUnit.Degrees), 2, 6 ) + "\t"; |
| 364 |
} |
| 365 |
else if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_FROMDEPTH ) == 0 ) { |
| 366 |
legLine += CaveConverter.padNumber( leg.getFromDepth(LengthUnit.Metres), 2, 5 ) + "\t"; |
| 367 |
} |
| 368 |
else if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_TODEPTH ) == 0 ) { |
| 369 |
legLine += CaveConverter.padNumber( leg.getToDepth(LengthUnit.Metres), 2, 5 ) + "\t"; |
| 370 |
} |
| 371 |
else if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_DEPTHCHANGE ) == 0 ) { |
| 372 |
legLine += CaveConverter.padNumber( leg.getDepthChange(LengthUnit.Metres), 2, 5 ) + "\t"; |
| 373 |
} |
| 374 |
else if ( item.compareTo( CaveConverter.DATA_ORDER_CAT_IGNOREALL ) == 0 ) { |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
if ( leg.getComment().length() > 0 ) { |
| 381 |
if ( dataOrder.get( dataOrder.size() - 1 ).compareTo( CaveConverter.DATA_ORDER_CAT_IGNOREALL ) != 0 ) { |
| 382 |
|
| 383 |
legLine += ";"; |
| 384 |
} |
| 385 |
legLine += leg.getComment(); |
| 386 |
} |
| 387 |
else { |
| 388 |
|
| 389 |
legLine = legLine.trim(); |
| 390 |
} |
| 391 |
|
| 392 |
legsData.add( legLine ); |
| 393 |
} |
| 394 |
} |
| 395 |
else { |
| 396 |
|
| 397 |
if ( leg.isSplay() == false ) { |
| 398 |
|
| 399 |
legsData.add( "*EQUATE " + fromStnVal + "\t" + toStnVal ); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
SurveyStation stn = leg.getFromStn(); |
| 405 |
for (int i=0; i < 2; i++) { |
| 406 |
|
| 407 |
if ( stn.isFixed() == true ) { |
| 408 |
String fixedStnLine = "*FIX " + substIllegalNameChars( stn.getName() ); |
| 409 |
fixedStnLine += "\t" + stn.getEasting() + "\t" + stn.getNorthing() + "\t" + |
| 410 |
stn.getAltitude(); |
| 411 |
fixedStnsData.add( fixedStnLine ); |
| 412 |
} |
| 413 |
|
| 414 |
if ( leg.getToStn() == null ) { |
| 415 |
break; |
| 416 |
} |
| 417 |
stn = leg.getToStn(); |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
if ( ( leg.isSplay() == false ) && ( leg.isSurface() == false ) ) { |
| 423 |
|
| 424 |
|
| 425 |
boolean newBlock = false; |
| 426 |
int activeBlockIdx = passageData.size() - 1; |
| 427 |
boolean addAtFront = false; |
| 428 |
if ( passageData.size() == 0 ) { |
| 429 |
|
| 430 |
newBlock = true; |
| 431 |
} |
| 432 |
else { |
| 433 |
|
| 434 |
|
| 435 |
boolean foundExistingBlock = false; |
| 436 |
|
| 437 |
for (int idx = 0; idx < passageData.size(); idx++ ) { |
| 438 |
List<String[]> block = passageData.get(idx); |
| 439 |
|
| 440 |
if ( leg.getToStn() != null ) { |
| 441 |
|
| 442 |
if ( ( block.size() == 1 ) && ( block.get(0)[0].equals( leg.getToStn().getName() ) ) ) { |
| 443 |
|
| 444 |
|
| 445 |
if ( block.get(0)[2].equals( leg.getFromStn().getName() ) ) { |
| 446 |
|
| 447 |
activeBlockIdx = idx; |
| 448 |
addAtFront = false; |
| 449 |
foundExistingBlock = true; |
| 450 |
} |
| 451 |
else { |
| 452 |
|
| 453 |
activeBlockIdx = idx; |
| 454 |
addAtFront = true; |
| 455 |
foundExistingBlock = true; |
| 456 |
} |
| 457 |
} |
| 458 |
else if ( block.get(block.size() - 1)[0].equals( leg.getToStn().getName() ) ) { |
| 459 |
|
| 460 |
activeBlockIdx = idx; |
| 461 |
addAtFront = false; |
| 462 |
foundExistingBlock = true; |
| 463 |
} |
| 464 |
else if ( block.get(0)[0].equals( leg.getToStn().getName() ) ) { |
| 465 |
|
| 466 |
activeBlockIdx = idx; |
| 467 |
addAtFront = true; |
| 468 |
foundExistingBlock = true; |
| 469 |
} |
| 470 |
} |
| 471 |
if ( foundExistingBlock == false ) { |
| 472 |
|
| 473 |
for (int idx2 = 0; idx2 < series.legCount(); idx2++ ) { |
| 474 |
SurveyLeg chkLeg = series.getLegRaw(idx2); |
| 475 |
if ( ( chkLeg.getToStn() != null ) |
| 476 |
&& ( chkLeg.getToStn().getName().equals(leg.getFromStn().getName() ) ) ) { |
| 477 |
|
| 478 |
|
| 479 |
if ( block.get(block.size() - 1)[0].equals( chkLeg.getFromStn().getName() ) ) { |
| 480 |
|
| 481 |
activeBlockIdx = idx; |
| 482 |
addAtFront = false; |
| 483 |
foundExistingBlock = true; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
if ( foundExistingBlock ) { |
| 505 |
break; |
| 506 |
} |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
if ( foundExistingBlock ) { |
| 511 |
break; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
if ( foundExistingBlock == false ) { |
| 516 |
|
| 517 |
newBlock = true; |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
if (newBlock) { |
| 522 |
passageData.add( new ArrayList<String[]>() ); |
| 523 |
activeBlockIdx = passageData.size() - 1; |
| 524 |
} |
| 525 |
|
| 526 |
String[] lrudLine = createLrudLine( leg ); |
| 527 |
if ( addAtFront ) { |
| 528 |
passageData.get(activeBlockIdx).add(0, lrudLine); |
| 529 |
} |
| 530 |
else { |
| 531 |
passageData.get(activeBlockIdx).add( lrudLine ); |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
addMissingPassageDataAtLoopClosureStations( series, passageData ); |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
reprocessPassageDataBlocks( series, passageData ); |
| 541 |
|
| 542 |
|
| 543 |
combinePassageDataBlocks( passageData ); |
| 544 |
|
| 545 |
|
| 546 |
if ( fixedStnsData.size() > 0 ) { |
| 547 |
outputData.addAll( fixedStnsData ); |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
outputData.addAll( legsData ); |
| 552 |
|
| 553 |
|
| 554 |
if ( splayFlagOn ) { |
| 555 |
outputData.add( "*FLAGS NOT SPLAY"); |
| 556 |
splayFlagOn = false; |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
if ( passageData.size() > 0 ) { |
| 561 |
outputData.add( ""); |
| 562 |
|
| 563 |
ListIterator<List<String[]>> blocksIter = passageData.listIterator(); |
| 564 |
while ( blocksIter.hasNext() ) { |
| 565 |
List<String[]> block = blocksIter.next(); |
| 566 |
outputData.add("*data passage station left right up down"); |
| 567 |
ListIterator<String[]> blockIter = block.listIterator(); |
| 568 |
while ( blockIter.hasNext() ) { |
| 569 |
String[] line = blockIter.next(); |
| 570 |
|
| 571 |
|
| 572 |
outputData.add( substIllegalNameChars( line[0] ) + "\t" + line[1] ); |
| 573 |
} |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
ListIterator<SurveySeries> seriesIterator = series.getInnerSeriesList().listIterator(); |
| 579 |
while ( seriesIterator.hasNext() ) { |
| 580 |
SurveySeries innerSeries = seriesIterator.next(); |
| 581 |
|
| 582 |
outputData.addAll( generateSurvexDataSeries( innerSeries, series, splaysOutput ) ); |
| 583 |
} |
| 584 |
|
| 585 |
|
| 586 |
outputData.add( "*END " + substIllegalNameChars( series.getSeriesName() ) ); |
| 587 |
outputData.add( "" ); |
| 588 |
|
| 589 |
return outputData; |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
private String substIllegalNameChars( String stnName ) { |
| 601 |
String result = ""; |
| 602 |
|
| 603 |
for (int i=0; i < stnName.length(); i++){ |
| 604 |
char c = stnName.charAt(i); |
| 605 |
String sub = String.valueOf(c); |
| 606 |
|
| 607 |
if ( c < 48 ) { |
| 608 |
|
| 609 |
switch (c) { |
| 610 |
case 33: |
| 611 |
|
| 612 |
sub = "_ex"; |
| 613 |
break; |
| 614 |
case 34: |
| 615 |
|
| 616 |
sub = "_dq"; |
| 617 |
break; |
| 618 |
case 35: |
| 619 |
|
| 620 |
sub = "_hs"; |
| 621 |
break; |
| 622 |
case 36: |
| 623 |
|
| 624 |
sub = "_dl"; |
| 625 |
break; |
| 626 |
case 37: |
| 627 |
|
| 628 |
sub = "_pc"; |
| 629 |
break; |
| 630 |
case 38: |
| 631 |
|
| 632 |
sub = "_am"; |
| 633 |
break; |
| 634 |
case 39: |
| 635 |
|
| 636 |
sub = "_sq"; |
| 637 |
break; |
| 638 |
case 40: |
| 639 |
|
| 640 |
sub = "_ob"; |
| 641 |
break; |
| 642 |
case 41: |
| 643 |
|
| 644 |
sub = "_cb"; |
| 645 |
break; |
| 646 |
case 42: |
| 647 |
|
| 648 |
sub = "_as"; |
| 649 |
break; |
| 650 |
case 43: |
| 651 |
|
| 652 |
sub = "_pl"; |
| 653 |
break; |
| 654 |
case 44: |
| 655 |
|
| 656 |
sub = "_cm"; |
| 657 |
break; |
| 658 |
case 47: |
| 659 |
|
| 660 |
sub = "_fs"; |
| 661 |
break; |
| 662 |
} |
| 663 |
} |
| 664 |
else if ( c > 57 ) { |
| 665 |
if ( c < 65 ) { |
| 666 |
|
| 667 |
switch (c) { |
| 668 |
case 58: |
| 669 |
|
| 670 |
sub = "_co"; |
| 671 |
break; |
| 672 |
case 59: |
| 673 |
|
| 674 |
sub = "_sc"; |
| 675 |
break; |
| 676 |
case 60: |
| 677 |
|
| 678 |
sub = "_lt"; |
| 679 |
break; |
| 680 |
case 61: |
| 681 |
|
| 682 |
sub = "_eq"; |
| 683 |
break; |
| 684 |
case 62: |
| 685 |
|
| 686 |
sub = "_gt"; |
| 687 |
break; |
| 688 |
case 63: |
| 689 |
|
| 690 |
sub = "_qm"; |
| 691 |
break; |
| 692 |
case 64: |
| 693 |
|
| 694 |
sub = "_at"; |
| 695 |
break; |
| 696 |
} |
| 697 |
} |
| 698 |
else if ( c > 90 ) { |
| 699 |
if ( c < 97 ) { |
| 700 |
|
| 701 |
switch (c) { |
| 702 |
case 91: |
| 703 |
|
| 704 |
sub = "_os"; |
| 705 |
break; |
| 706 |
case 92: |
| 707 |
|
| 708 |
sub = "_bs"; |
| 709 |
break; |
| 710 |
case 93: |
| 711 |
|
| 712 |
sub = "_cs"; |
| 713 |
break; |
| 714 |
case 94: |
| 715 |
|
| 716 |
sub = "_ht"; |
| 717 |
break; |
| 718 |
case 95: |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
break; |
| 723 |
case 96: |
| 724 |
|
| 725 |
sub = "_gr"; |
| 726 |
break; |
| 727 |
} |
| 728 |
} |
| 729 |
else if ( c > 122 ) { |
| 730 |
|
| 731 |
switch (c) { |
| 732 |
case 123: |
| 733 |
|
| 734 |
sub = "_oc"; |
| 735 |
break; |
| 736 |
case 124: |
| 737 |
|
| 738 |
sub = "_pi"; |
| 739 |
break; |
| 740 |
case 125: |
| 741 |
|
| 742 |
sub = "_cc"; |
| 743 |
break; |
| 744 |
case 126: |
| 745 |
|
| 746 |
sub = "_ti"; |
| 747 |
break; |
| 748 |
default: |
| 749 |
|
| 750 |
int code = 0 + c; |
| 751 |
sub = "_asc" + code; |
| 752 |
} |
| 753 |
} |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
result += sub; |
| 759 |
} |
| 760 |
|
| 761 |
return result; |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
private void reprocessPassageDataBlocks( SurveySeries series, List<List<String[]>> passageData ) { |
| 771 |
|
| 772 |
ListIterator<List<String[]>> blocksIter = passageData.listIterator(); |
| 773 |
while ( blocksIter.hasNext() ) { |
| 774 |
List<String[]> block = blocksIter.next(); |
| 775 |
|
| 776 |
|
| 777 |
if ( block.size() < 2 ) { |
| 778 |
blocksIter.remove(); |
| 779 |
} |
| 780 |
else { |
| 781 |
|
| 782 |
boolean noLrudDataInBlock = true; |
| 783 |
|
| 784 |
for ( int blockIdx = 0; blockIdx < ( block.size() - 1 ); blockIdx++ ) { |
| 785 |
String[] line1 = block.get(blockIdx); |
| 786 |
String[] line2 = block.get(blockIdx + 1); |
| 787 |
|
| 788 |
|
| 789 |
boolean legMatchesPassageData = false; |
| 790 |
for ( int legIdx = 0; legIdx < series.legCount(); legIdx++ ) { |
| 791 |
SurveyLeg leg = series.getLegRaw(legIdx); |
| 792 |
if ( ( leg.isSplay() == false ) |
| 793 |
&& ( leg.getToStn() != null ) |
| 794 |
&& ( leg.getLeft(LengthUnit.Metres) + leg.getRight(LengthUnit.Metres) + |
| 795 |
leg.getUp(LengthUnit.Metres) + leg.getDown(LengthUnit.Metres) > 0.0 ) ) { |
| 796 |
|
| 797 |
if ( ( line1[0].equals( leg.getFromStn().getName() ) ) |
| 798 |
&& ( line2[0].equals( leg.getToStn().getName() ) ) ) { |
| 799 |
legMatchesPassageData = true; |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
} |
| 807 |
|
| 808 |
if ( legMatchesPassageData ) { |
| 809 |
|
| 810 |
String[] newLine = createLrudLine(leg); |
| 811 |
if ( line1[1].equals( newLine[1] ) == false ) { |
| 812 |
block.remove(blockIdx); |
| 813 |
block.add(blockIdx, newLine); |
| 814 |
} |
| 815 |
break; |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
if ( ( noLrudDataInBlock ) |
| 821 |
&& ( ( line1[1].equals( " 0.00\t 0.00\t 0.00\t 0.00" ) == false ) |
| 822 |
|| ( line2[1].equals( " 0.00\t 0.00\t 0.00\t 0.00" ) == false ) ) |
| 823 |
) { |
| 824 |
noLrudDataInBlock = false; |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
|
| 829 |
if ( noLrudDataInBlock ) { |
| 830 |
blocksIter.remove(); |
| 831 |
} |
| 832 |
} |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
private void combinePassageDataBlocks( List<List<String[]>> passageData ) { |
| 840 |
|
| 841 |
int outerIdx = 0; |
| 842 |
while ( outerIdx < passageData.size() ) { |
| 843 |
List<String[]> block = passageData.get( outerIdx ); |
| 844 |
|
| 845 |
String lastStn = block.get( block.size() - 1 )[0]; |
| 846 |
|
| 847 |
|
| 848 |
for ( int innerIdx1 = 0; innerIdx1 < passageData.size(); innerIdx1++ ) { |
| 849 |
List<String[]> innerBlock = passageData.get( innerIdx1 ); |
| 850 |
|
| 851 |
if ( innerBlock.equals( block ) == false ) { |
| 852 |
String innerStartStn = innerBlock.get( 0 )[0]; |
| 853 |
|
| 854 |
if ( innerStartStn.equals( lastStn ) ) { |
| 855 |
boolean removeInner = true; |
| 856 |
|
| 857 |
for ( int innerIdx2 = 0; innerIdx2 < innerBlock.size(); innerIdx2++ ) { |
| 858 |
if ( innerIdx2 == 0 ) { |
| 859 |
|
| 860 |
if ( block.get( block.size() - 1 )[1].equals( innerBlock.get( 0 )[1] ) == false ) { |
| 861 |
logger.logMessage("Unable to merge passage data blocks due to LRUD data mismatch: " + |
| 862 |
"Block ending " + block.get( block.size() - 1 )[0] + "=" + block.get( block.size() - 1 )[1] + ", " + |
| 863 |
"Block starting " + innerBlock.get( 0 )[0] + "=" + innerBlock.get( 0 )[1]); |
| 864 |
removeInner = false; |
| 865 |
break; |
| 866 |
} |
| 867 |
} |
| 868 |
else { |
| 869 |
block.add( innerBlock.get( innerIdx2 ) ); |
| 870 |
} |
| 871 |
} |
| 872 |
if ( removeInner ) { |
| 873 |
|
| 874 |
passageData.remove( innerIdx1 ); |
| 875 |
outerIdx--; |
| 876 |
|
| 877 |
lastStn = block.get( block.size() - 1 )[0]; |
| 878 |
} |
| 879 |
} |
| 880 |
} |
| 881 |
} |
| 882 |
outerIdx++; |
| 883 |
} |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
private void addMissingPassageDataAtLoopClosureStations( SurveySeries series, List<List<String[]>> passageData ) { |
| 892 |
|
| 893 |
|
| 894 |
for ( int legIdx = 0; legIdx < series.legCount(); legIdx++ ) { |
| 895 |
SurveyLeg leg = series.getLegRaw(legIdx); |
| 896 |
if ( ( leg.isSplay() == false ) && ( leg.getLeft(LengthUnit.Metres) + leg.getRight(LengthUnit.Metres) + |
| 897 |
leg.getUp(LengthUnit.Metres) + leg.getDown(LengthUnit.Metres) > 0.0 ) ) { |
| 898 |
|
| 899 |
for ( int legIdx2 = 0; legIdx2 < series.legCount(); legIdx2++ ) { |
| 900 |
SurveyLeg leg2 = series.getLegRaw(legIdx2); |
| 901 |
if ( ( leg.isSplay() == false ) |
| 902 |
&& ( leg.getToStn() != null ) |
| 903 |
&& ( leg.getLeft(LengthUnit.Metres) + leg.getRight(LengthUnit.Metres) + |
| 904 |
leg.getUp(LengthUnit.Metres) + leg.getDown(LengthUnit.Metres) > 0.0 ) |
| 905 |
&& ( leg.getToStn().getName().equals( leg2.getFromStn().getName() ) ) ) { |
| 906 |
|
| 907 |
boolean foundLegInPassData = false; |
| 908 |
ListIterator<List<String[]>> blocksIter = passageData.listIterator(); |
| 909 |
while ( blocksIter.hasNext() ) { |
| 910 |
List<String[]> block = blocksIter.next(); |
| 911 |
|
| 912 |
for ( int blockIdx = 0; blockIdx < ( block.size() - 1 ); blockIdx++ ) { |
| 913 |
String[] line1 = block.get(blockIdx); |
| 914 |
String[] line2 = block.get(blockIdx + 1); |
| 915 |
if ( ( line1[0].equals( leg.getFromStn().getName() ) ) |
| 916 |
&& ( line2[0].equals( leg.getToStn().getName() ) ) ) { |
| 917 |
foundLegInPassData = true; |
| 918 |
break; |
| 919 |
} |
| 920 |
else if ( ( line2[0].equals( leg.getFromStn().getName() ) ) |
| 921 |
&& ( line1[0].equals( leg.getToStn().getName() ) ) ) { |
| 922 |
foundLegInPassData = true; |
| 923 |
break; |
| 924 |
} |
| 925 |
} |
| 926 |
if ( foundLegInPassData ) { |
| 927 |
break; |
| 928 |
} |
| 929 |
} |
| 930 |
if ( foundLegInPassData == false ) { |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
ListIterator<List<String[]>> blocksIter2 = passageData.listIterator(); |
| 935 |
while ( blocksIter2.hasNext() ) { |
| 936 |
List<String[]> blockForAdd = blocksIter2.next(); |
| 937 |
int insertPoint = 0; |
| 938 |
if ( blockForAdd.get(blockForAdd.size() - 1)[0].equals( leg.getFromStn().getName() ) ) { |
| 939 |
|
| 940 |
insertPoint = 2; |
| 941 |
} |
| 942 |
else if ( blockForAdd.get(0)[0].equals( leg.getFromStn().getName() ) ) { |
| 943 |
|
| 944 |
insertPoint = 1; |
| 945 |
} |
| 946 |
if ( insertPoint > 0 ) { |
| 947 |
|
| 948 |
ListIterator<List<String[]>> blocksIter3 = passageData.listIterator(); |
| 949 |
while ( blocksIter3.hasNext() ) { |
| 950 |
List<String[]> blockToCopyFrom = blocksIter3.next(); |
| 951 |
boolean lineAdded = false; |
| 952 |
ListIterator<String[]> blockIter = blockToCopyFrom.listIterator(); |
| 953 |
while ( blockIter.hasNext() ) { |
| 954 |
String[] line = blockIter.next(); |
| 955 |
|
| 956 |
if ( line[0].equals( leg.getToStn().getName() ) ) { |
| 957 |
|
| 958 |
if ( insertPoint == 1) { |
| 959 |
|
| 960 |
blockForAdd.add(0, line); |
| 961 |
} |
| 962 |
else { |
| 963 |
|
| 964 |
blockForAdd.add(line); |
| 965 |
} |
| 966 |
lineAdded = true; |
| 967 |
break; |
| 968 |
} |
| 969 |
} |
| 970 |
|
| 971 |
if ( lineAdded ) { |
| 972 |
break; |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
break; |
| 977 |
} |
| 978 |
} |
| 979 |
} |
| 980 |
break; |
| 981 |
} |
| 982 |
} |
| 983 |
} |
| 984 |
} |
| 985 |
|
| 986 |
|
| 987 |
} |
| 988 |
|
| 989 |
private String[] createLrudLine( SurveyLeg bestLeg ) { |
| 990 |
String[] lrudLine = new String[3]; |
| 991 |
lrudLine[0] = bestLeg.getFromStn().getName(); |
| 992 |
lrudLine[1] = |
| 993 |
CaveConverter.padNumber(bestLeg.getLeft(LengthUnit.Metres),2,5) + "\t" + |
| 994 |
CaveConverter.padNumber(bestLeg.getRight(LengthUnit.Metres),2,5) + "\t" + |
| 995 |
CaveConverter.padNumber(bestLeg.getUp(LengthUnit.Metres),2,5) + "\t" + |
| 996 |
CaveConverter.padNumber(bestLeg.getDown(LengthUnit.Metres),2,5); |
| 997 |
if ( bestLeg.getToStn() != null ) { |
| 998 |
lrudLine[2] = bestLeg.getToStn().getName(); |
| 999 |
} |
| 1000 |
return lrudLine; |
| 1001 |
|
| 1002 |
} |
| 1003 |
|
| 1004 |
} |