| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
package footleg.cavesurvey.data.model; |
| 20 |
|
| 21 |
import footleg.cavesurvey.converter.CaveConverter.BearingUnit; |
| 22 |
import footleg.cavesurvey.converter.CaveConverter.GradientUnit; |
| 23 |
import footleg.cavesurvey.converter.CaveConverter.LengthUnit; |
| 24 |
import footleg.cavesurvey.tools.UtilityFunctions; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public class SurveyLeg implements Comparable<SurveyLeg> { |
| 48 |
private static final int nullDepth = 999999; |
| 49 |
private SurveyStation fromStn; |
| 50 |
private SurveyStation toStn; |
| 51 |
private double length = -1; |
| 52 |
private double fromDepth = nullDepth; |
| 53 |
private double toDepth = nullDepth; |
| 54 |
private double compass = -1; |
| 55 |
private double clino = -99; |
| 56 |
private String comment = ""; |
| 57 |
|
| 58 |
|
| 59 |
private double left = 0.0; |
| 60 |
private double right = 0.0; |
| 61 |
private double up = 0.0; |
| 62 |
private double down = 0.0; |
| 63 |
|
| 64 |
|
| 65 |
private boolean splay = false; |
| 66 |
private boolean duplicate = false; |
| 67 |
private boolean surface = false; |
| 68 |
private boolean diving = false; |
| 69 |
private boolean nosurvey = false; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public int compareTo(SurveyLeg anotherLeg) { |
| 75 |
SurveyLeg leg = (SurveyLeg)anotherLeg; |
| 76 |
int fromTest = this.fromStn.getId() - leg.getFromStn().getId(); |
| 77 |
if ( fromTest == 0 ) { |
| 78 |
|
| 79 |
return this.toStn.getId() - leg.getToStn().getId(); |
| 80 |
} |
| 81 |
else { |
| 82 |
return fromTest; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public String toString() { |
| 91 |
String text = getFromStn().getName(); |
| 92 |
if ( (toStn != null) && ( toStn.getName() != null ) ) { |
| 93 |
text += " - " + getToStn().getName(); |
| 94 |
} |
| 95 |
return text; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public SurveyLeg clone() { |
| 102 |
SurveyLeg clone = new SurveyLeg(); |
| 103 |
|
| 104 |
if (fromStn != null){ |
| 105 |
clone.fromStn = fromStn.clone(); |
| 106 |
} |
| 107 |
if (toStn != null){ |
| 108 |
clone.toStn = toStn.clone(); |
| 109 |
} |
| 110 |
clone.length = length; |
| 111 |
clone.compass = compass; |
| 112 |
clone.clino = clino; |
| 113 |
clone.fromDepth = fromDepth; |
| 114 |
clone.toDepth = toDepth; |
| 115 |
clone.comment = comment; |
| 116 |
clone.left = left; |
| 117 |
clone.right = right; |
| 118 |
clone.up = up; |
| 119 |
clone.down = down; |
| 120 |
clone.splay = splay; |
| 121 |
clone.duplicate = duplicate; |
| 122 |
clone.surface = surface; |
| 123 |
clone.diving = diving; |
| 124 |
clone.nosurvey = nosurvey; |
| 125 |
|
| 126 |
return clone; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
public void reverseDirection() { |
| 133 |
|
| 134 |
SurveyStation stn = getFromStn(); |
| 135 |
setFromStn( getToStn() ); |
| 136 |
setToStn( stn ); |
| 137 |
double compass = getCompass(BearingUnit.Degrees); |
| 138 |
if ( compass > 180 ) { |
| 139 |
compass -= 180; |
| 140 |
} |
| 141 |
else { |
| 142 |
compass += 180; |
| 143 |
} |
| 144 |
setCompass( compass, BearingUnit.Degrees ); |
| 145 |
|
| 146 |
if ( isDiving() ) { |
| 147 |
if ( isDepthChangeLeg() ) { |
| 148 |
|
| 149 |
toDepth = -toDepth; |
| 150 |
} |
| 151 |
else { |
| 152 |
|
| 153 |
double tmpDepth = fromDepth; |
| 154 |
fromDepth = toDepth; |
| 155 |
toDepth = tmpDepth; |
| 156 |
} |
| 157 |
|
| 158 |
this.clino = -getClino(GradientUnit.Degrees); |
| 159 |
} |
| 160 |
else { |
| 161 |
setClino( -getClino(GradientUnit.Degrees), GradientUnit.Degrees ); |
| 162 |
|
| 163 |
this.fromDepth = nullDepth; |
| 164 |
this.toDepth = nullDepth; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
public double getHorizontalLength() { |
| 173 |
double hLength = Math.abs( length * Math.cos( Math.toRadians( clino ) ) ); |
| 174 |
return hLength; |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
public double getVerticalLength() { |
| 182 |
double vLength = Math.abs( length * Math.sin( Math.toRadians( clino ) ) ); |
| 183 |
return vLength; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
public SurveyStation getFromStn() { |
| 188 |
return fromStn; |
| 189 |
} |
| 190 |
|
| 191 |
public void setFromStn(SurveyStation fromStn) { |
| 192 |
this.fromStn = fromStn; |
| 193 |
} |
| 194 |
|
| 195 |
public SurveyStation getToStn() { |
| 196 |
return toStn; |
| 197 |
} |
| 198 |
|
| 199 |
public void setToStn(SurveyStation toStn) { |
| 200 |
this.toStn = toStn; |
| 201 |
} |
| 202 |
|
| 203 |
public double getLength(LengthUnit units) { |
| 204 |
return UtilityFunctions.lengthFromMetres( length, units ); |
| 205 |
} |
| 206 |
|
| 207 |
public void setLength(double length, LengthUnit units) { |
| 208 |
this.length = UtilityFunctions.lengthToMetres(length, units); |
| 209 |
} |
| 210 |
|
| 211 |
public double getCompass(BearingUnit units) { |
| 212 |
return UtilityFunctions.bearingFromDegrees(compass, units); |
| 213 |
} |
| 214 |
|
| 215 |
public void setCompass(double compass, BearingUnit units) { |
| 216 |
this.compass = UtilityFunctions.bearingToDegrees(compass, units); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
public double getClino(GradientUnit units) { |
| 225 |
return UtilityFunctions.gradientFromDegrees(clino, units); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
public void setClino(double clino, GradientUnit units) { |
| 234 |
this.clino = UtilityFunctions.gradientToDegrees(clino, units); |
| 235 |
diving = false; |
| 236 |
} |
| 237 |
|
| 238 |
public double getLeft(LengthUnit units) { |
| 239 |
return UtilityFunctions.lengthFromMetres( left, units ); |
| 240 |
} |
| 241 |
|
| 242 |
public void setLeft(double left, LengthUnit units) { |
| 243 |
this.left = UtilityFunctions.lengthToMetres(left, units); |
| 244 |
} |
| 245 |
|
| 246 |
public double getRight(LengthUnit units) { |
| 247 |
return UtilityFunctions.lengthFromMetres( right, units ); |
| 248 |
} |
| 249 |
|
| 250 |
public void setRight(double right, LengthUnit units) { |
| 251 |
this.right = UtilityFunctions.lengthToMetres(right, units); |
| 252 |
} |
| 253 |
|
| 254 |
public double getUp(LengthUnit units) { |
| 255 |
return UtilityFunctions.lengthFromMetres( up, units ); |
| 256 |
} |
| 257 |
|
| 258 |
public void setUp(double up, LengthUnit units) { |
| 259 |
this.up = UtilityFunctions.lengthToMetres(up, units); |
| 260 |
} |
| 261 |
|
| 262 |
public double getDown(LengthUnit units) { |
| 263 |
return UtilityFunctions.lengthFromMetres( down, units ); |
| 264 |
} |
| 265 |
|
| 266 |
public void setDown(double down, LengthUnit units) { |
| 267 |
this.down = UtilityFunctions.lengthToMetres(down, units); |
| 268 |
} |
| 269 |
|
| 270 |
public String getComment() { |
| 271 |
return comment; |
| 272 |
} |
| 273 |
|
| 274 |
public void setComment(String comment) { |
| 275 |
this.comment = comment; |
| 276 |
} |
| 277 |
|
| 278 |
public boolean isSplay() { |
| 279 |
return splay; |
| 280 |
} |
| 281 |
|
| 282 |
public void setSplay(boolean splay) { |
| 283 |
this.splay = splay; |
| 284 |
if ( splay == true ) { |
| 285 |
this.nosurvey = false; |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
public boolean isDuplicate() { |
| 290 |
return duplicate; |
| 291 |
} |
| 292 |
|
| 293 |
public void setDuplicate(boolean duplicate) { |
| 294 |
this.duplicate = duplicate; |
| 295 |
} |
| 296 |
|
| 297 |
public boolean isSurface() { |
| 298 |
return surface; |
| 299 |
} |
| 300 |
|
| 301 |
public void setSurface(boolean surface) { |
| 302 |
this.surface = surface; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
public double getDepthChange(LengthUnit units) { |
| 310 |
if ( isDepthChangeLeg() ) { |
| 311 |
return UtilityFunctions.lengthFromMetres( toDepth, units ); |
| 312 |
} |
| 313 |
else { |
| 314 |
return UtilityFunctions.lengthFromMetres( toDepth - fromDepth, units ); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
public void setDepthChange(double depthChange, LengthUnit units) { |
| 324 |
this.fromDepth = nullDepth; |
| 325 |
this.toDepth = UtilityFunctions.lengthToMetres(depthChange, units); |
| 326 |
this.diving = true; |
| 327 |
this.nosurvey = false; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
public double getFromDepth(LengthUnit units) { |
| 335 |
return UtilityFunctions.lengthFromMetres( fromDepth, units ); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
public double getToDepth(LengthUnit units) { |
| 343 |
return UtilityFunctions.lengthFromMetres( toDepth, units ); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
public void setDepths(double fromDepth, double toDepth, LengthUnit units) { |
| 353 |
this.fromDepth = UtilityFunctions.lengthToMetres(fromDepth, units); |
| 354 |
this.toDepth = UtilityFunctions.lengthToMetres(toDepth, units); |
| 355 |
this.diving = true; |
| 356 |
this.nosurvey = false; |
| 357 |
} |
| 358 |
|
| 359 |
public boolean isDiving() { |
| 360 |
return diving; |
| 361 |
} |
| 362 |
|
| 363 |
public boolean isDepthChangeLeg() { |
| 364 |
return ( diving && fromDepth == nullDepth ); |
| 365 |
} |
| 366 |
|
| 367 |
public boolean isNosurvey() { |
| 368 |
return nosurvey; |
| 369 |
} |
| 370 |
|
| 371 |
public void setNosurvey(boolean nosurvey) { |
| 372 |
this.nosurvey = nosurvey; |
| 373 |
if ( nosurvey == true) { |
| 374 |
this.splay = false; |
| 375 |
} |
| 376 |
} |
| 377 |
} |