| 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 |
|
| 24 |
import footleg.cavesurvey.converter.CaveConverter; |
| 25 |
import footleg.cavesurvey.converter.Logger; |
| 26 |
import footleg.cavesurvey.converter.CaveConverter.BearingUnit; |
| 27 |
import footleg.cavesurvey.converter.CaveConverter.GradientUnit; |
| 28 |
import footleg.cavesurvey.converter.CaveConverter.LengthUnit; |
| 29 |
import footleg.cavesurvey.data.model.CaveSurvey; |
| 30 |
import footleg.cavesurvey.data.model.SurveyLeg; |
| 31 |
import footleg.cavesurvey.data.model.SurveySeries; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class CompassWriter { |
| 41 |
private List<String> shortNames = new ArrayList<String>(); |
| 42 |
private Logger logger; |
| 43 |
|
| 44 |
public CompassWriter( Logger logger ) { |
| 45 |
super(); |
| 46 |
this.logger = logger; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public List<String> generateCompassData( CaveSurvey surveyData ) { |
| 58 |
List<String> outputData = new ArrayList<String>(); |
| 59 |
String caveName = "cave"; |
| 60 |
|
| 61 |
|
| 62 |
SurveySeries series1 = surveyData.get(0); |
| 63 |
if ( series1.getSeriesName().length() > 0 ) { |
| 64 |
|
| 65 |
int pos = series1.getSeriesName().indexOf('.'); |
| 66 |
if ( pos > 0) { |
| 67 |
|
| 68 |
caveName = series1.getSeriesName().substring(0, pos); |
| 69 |
} |
| 70 |
else { |
| 71 |
|
| 72 |
for ( int nameIdx = series1.getSeriesName().length() - 1; nameIdx > -1; nameIdx-- ) { |
| 73 |
|
| 74 |
int charCode = series1.getSeriesName().charAt(nameIdx); |
| 75 |
if ( charCode < 48 || charCode > 57 ) { |
| 76 |
|
| 77 |
caveName = series1.getSeriesName().substring(0, nameIdx + 1); |
| 78 |
nameIdx = 0; |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
for ( int seriesIdx = 0; seriesIdx < surveyData.size(); seriesIdx++ ) { |
| 86 |
String seriesName = surveyData.get(seriesIdx).getSeriesName(); |
| 87 |
String reducedName = ""; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
String nameLastPart = seriesName; |
| 97 |
int lstIdx = seriesName.lastIndexOf('.'); |
| 98 |
if ( lstIdx > -1 && lstIdx < (seriesName.length() - 1) ) { |
| 99 |
|
| 100 |
nameLastPart = seriesName.substring(lstIdx + 1); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
for ( int idx = 0; reducedName.length() < 4 && idx < nameLastPart.length(); idx ++ ) { |
| 105 |
if ( nameLastPart.charAt(idx) != '.' ) { |
| 106 |
reducedName += nameLastPart.charAt(idx); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
int trys = 0; |
| 111 |
while ( trys < 110 ) { |
| 112 |
trys++; |
| 113 |
String testName = " "; |
| 114 |
|
| 115 |
switch (trys) { |
| 116 |
case 1: |
| 117 |
|
| 118 |
testName = reducedName; |
| 119 |
break; |
| 120 |
case 2: |
| 121 |
|
| 122 |
reducedName = ""; |
| 123 |
for ( int idx = 0; reducedName.length() < 4 && idx < nameLastPart.length(); idx ++ ) { |
| 124 |
if ( nameLastPart.charAt(idx) != '.' |
| 125 |
&& nameLastPart.charAt(idx) != 'a' |
| 126 |
&& nameLastPart.charAt(idx) != 'e' |
| 127 |
&& nameLastPart.charAt(idx) != 'i' |
| 128 |
&& nameLastPart.charAt(idx) != 'o' |
| 129 |
&& nameLastPart.charAt(idx) != 'u' |
| 130 |
&& nameLastPart.charAt(idx) != 'A' |
| 131 |
&& nameLastPart.charAt(idx) != 'E' |
| 132 |
&& nameLastPart.charAt(idx) != 'I' |
| 133 |
&& nameLastPart.charAt(idx) != 'O' |
| 134 |
&& nameLastPart.charAt(idx) != 'U' |
| 135 |
) { |
| 136 |
reducedName += nameLastPart.charAt(idx); |
| 137 |
} |
| 138 |
} |
| 139 |
testName += reducedName; |
| 140 |
break; |
| 141 |
case 3: |
| 142 |
case 4: |
| 143 |
case 5: |
| 144 |
case 6: |
| 145 |
case 7: |
| 146 |
case 8: |
| 147 |
case 9: |
| 148 |
case 10: |
| 149 |
case 11: |
| 150 |
|
| 151 |
testName += reducedName.substring(0,3) + ( trys - 2 ); |
| 152 |
break; |
| 153 |
default : |
| 154 |
|
| 155 |
testName += reducedName.substring(0,2) + ( trys - 11 ); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
testName = testName.substring( testName.length() - 4 ); |
| 160 |
|
| 161 |
|
| 162 |
if ( nameAlreadyUsed( testName ) == false ) { |
| 163 |
|
| 164 |
shortNames.add( testName ); |
| 165 |
trys = 999; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
if (trys != 999) { |
| 170 |
RuntimeException ex = new RuntimeException("Failed to generate unique short name for series name: " + seriesName ); |
| 171 |
throw ex; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
for ( int seriesIdx = 0; seriesIdx < surveyData.size(); seriesIdx++ ) { |
| 177 |
SurveySeries series = surveyData.get(seriesIdx); |
| 178 |
List<String> legsData = new ArrayList<String>(); |
| 179 |
List<String> fixedStnsData = new ArrayList<String>(); |
| 180 |
List<String> passageData = new ArrayList<String>(); |
| 181 |
|
| 182 |
|
| 183 |
outputData.add( caveName ); |
| 184 |
outputData.add( "SURVEY NAME: " + series.getSeriesName() ); |
| 185 |
outputData.add( "SURVEY DATE: " + series.getSurveyDate() ); |
| 186 |
outputData.add( "SURVEY TEAM: "); |
| 187 |
outputData.add( " "); |
| 188 |
outputData.add( "DECLINATION: " + series.getCompassCalibration(BearingUnit.Degrees) + " FORMAT: DMMDLRUDLADN CORRECTIONS: 0.00 0.00 0.00"); |
| 189 |
outputData.add( " "); |
| 190 |
outputData.add( "FROM TO LENGTH BEARING INC LEFT UP DOWN RIGHT FLAGS COMMENTS"); |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
outputData.add( "*BEGIN " + series.getSeriesName() ); |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
if ( series.getTapeCalibration(LengthUnit.Metres) != 0 ) { |
| 221 |
outputData.add( "*CALIBRATE tape " + series.getTapeCalibration(LengthUnit.Feet) ); |
| 222 |
} |
| 223 |
if ( series.getCompassCalibration(BearingUnit.Degrees) != 0 ) { |
| 224 |
outputData.add( "*CALIBRATE declination " + series.getCompassCalibration(BearingUnit.Degrees) ); |
| 225 |
} |
| 226 |
if ( series.getClinoCalibration(GradientUnit.Degrees) != 0 ) { |
| 227 |
outputData.add( "*CALIBRATE clino " + series.getClinoCalibration(GradientUnit.Degrees) ); |
| 228 |
} |
| 229 |
outputData.add( ""); |
| 230 |
|
| 231 |
|
| 232 |
for ( int legIdx = 0; legIdx < series.legCount(); legIdx++ ) { |
| 233 |
SurveyLeg leg = series.getLegRaw(legIdx); |
| 234 |
|
| 235 |
|
| 236 |
String fromStn = leg.getFromStn().getName(); |
| 237 |
String toStn = leg.getToStn().getName(); |
| 238 |
if ( leg.getLength( LengthUnit.Metres ) > 0 ) { |
| 239 |
|
| 240 |
legsData.add( fromStn + "\t" + toStn + "\t" + |
| 241 |
CaveConverter.padNumber( leg.getLength(LengthUnit.Feet), 2, 5 ) + "\t" + |
| 242 |
CaveConverter.padNumber( leg.getCompass(BearingUnit.Degrees), 2, 6 ) + "\t" + |
| 243 |
CaveConverter.padNumber( leg.getClino(GradientUnit.Degrees), 2, 6 ) + "\t"); |
| 244 |
} |
| 245 |
else { |
| 246 |
|
| 247 |
|
| 248 |
if ( leg.isSplay() == false ) { |
| 249 |
|
| 250 |
legsData.add( "*EQUATE " + fromStn + "\t" + toStn ); |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
if ( leg.getLeft(LengthUnit.Metres) + leg.getRight(LengthUnit.Metres) + |
| 270 |
leg.getUp(LengthUnit.Metres) + leg.getDown(LengthUnit.Metres) > 0.0 ) { |
| 271 |
passageData.add( fromStn + "\t" + leg.getLeft(LengthUnit.Feet) + "\t" + |
| 272 |
leg.getRight(LengthUnit.Feet) + "\t" + leg.getUp(LengthUnit.Feet) + "\t" + |
| 273 |
leg.getDown(LengthUnit.Feet) + "\t" ); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
if ( fixedStnsData.size() > 0 ) { |
| 278 |
outputData.addAll( fixedStnsData ); |
| 279 |
} |
| 280 |
|
| 281 |
outputData.addAll( legsData ); |
| 282 |
|
| 283 |
if ( passageData.size() > 0 ) { |
| 284 |
outputData.add( ""); |
| 285 |
outputData.add( "*data passage station left right up down"); |
| 286 |
outputData.addAll( passageData ); |
| 287 |
} |
| 288 |
|
| 289 |
outputData.add( "*END " + series.getSeriesName() + "\n"); |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
outputData.add( "*END " + caveName ); |
| 294 |
|
| 295 |
return outputData; |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
private String getShortSeriesName( int seriesIdx ) { |
| 304 |
return shortNames.get(seriesIdx); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
private boolean nameAlreadyUsed( String name ) { |
| 313 |
boolean found = false; |
| 314 |
for ( int i = 0; i < shortNames.size(); i++ ) { |
| 315 |
if ( shortNames.get(i).compareToIgnoreCase( name ) == 0 ) { |
| 316 |
found = true; |
| 317 |
i = shortNames.size(); |
| 318 |
} |
| 319 |
} |
| 320 |
return found; |
| 321 |
} |
| 322 |
|
| 323 |
} |