Debian Codegraph @

src/footleg/cavesurvey/data/model/SurveyLeg.java

raw symbols SCIP
1 /**
2 * Copyright (C) 2009-2017 Paul Fretwell - aka 'Footleg' ([email protected])
3 *
4 * This file is part of Cave Converter.
5 *
6 * Cave Converter is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Cave Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Cave Converter. If not, see <http://www.gnu.org/licenses/>.
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 * Represents a leg in a cave survey. A leg is a set of measurements which define the
28 * location of a point in the cave relative to another point (a survey station). The
29 * second point defined by the leg can be another survey station or may just be a point
30 * in the cave on the wall or used to measure the position of a significant feature.
31 * Legs can be normal (defined in terms of length, bearing and inclination), or diving.
32 * Diving legs are defined in terms of a length, bearing and change in depth. The change
33 * in depth can be defined explicitly using the depths of both the from and to stations,
34 * or in terms of just a change in depth. If the leg is defined as a 'depth change' leg
35 * then this is stored in the toDepth property (the fromDepth property is set to a
36 * value of 999999m).
37 * Data is stored and calculations done in metric units (metres and degrees), but
38 * conversion to other units on input/output is supported.
39 *
40 * @author Footleg
41 * @version 2017.01.09 (ISO 8601 YYYY.MM.DD)
42 * @since 1.6 (The Java version used)
43 *
44 * @to.do
45 * TODO Add method to convert diving leg into conventional measurements (length,bearing,gradient)
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 //LRUD applies to fromStn
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 //Leg flags
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 * Support sorting by from station name, then to station name
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 //Same from station, so use toStn to sort
79 return this.toStn.getId() - leg.getToStn().getId();
80 }
81 else {
82 return fromTest;
83 }
84 }
85
86 /**
87 * Provides a string representation of a cave survey leg to display in a tree view of the data model
88 * @return String representation of survey leg class
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 * @return A copy of the survey leg
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 * Reverses the direction of a survey leg
131 */
132 public void reverseDirection() {
133 //Reverse leg direction
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 //Depth change, so change sign on toDepth to reverse depth change
149 toDepth = -toDepth;
150 }
151 else {
152 //Specific depths, so swap them
153 double tmpDepth = fromDepth;
154 fromDepth = toDepth;
155 toDepth = tmpDepth;
156 }
157 //Swap clino value avoiding setter so isDiving flag is not unset, just in case it had a value
158 this.clino = -getClino(GradientUnit.Degrees);
159 }
160 else {
161 setClino( -getClino(GradientUnit.Degrees), GradientUnit.Degrees );
162 //Reset depths to null depth in case they had values
163 this.fromDepth = nullDepth;
164 this.toDepth = nullDepth;
165 }
166 }
167
168 /**
169 * Calculates the horizontal length of the leg
170 * @return calculated horizontal length
171 */
172 public double getHorizontalLength() {
173 double hLength = Math.abs( length * Math.cos( Math.toRadians( clino ) ) );
174 return hLength;
175 }
176
177 /**
178 * Calculates the vertical height of the leg
179 * @return calculated vertical height
180 */
181 public double getVerticalLength() {
182 double vLength = Math.abs( length * Math.sin( Math.toRadians( clino ) ) );
183 return vLength;
184 }
185
186 //Getters and Setters
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 * TODO Calculate angle for diving legs
221 * @param units Units to return the value in
222 * @return Gradient of leg in the specified units
223 */
224 public double getClino(GradientUnit units) {
225 return UtilityFunctions.gradientFromDegrees(clino, units);
226 }
227
228 /**
229 * Setting this sets the leg to a non-diving (normal) type leg.
230 * @param clino Gradient value to set for the leg, in the units specified
231 * @param units Units of the specified value
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 * @param units Length units to return the value in
307 * @return The depth change for the diving leg
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 * Setting this sets the leg to a diving type leg.
320 * @param depthChange The depth change to set
321 * @param units Units of the specified depth change
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 * @param units Length units to return the value in
332 * @return The from Depth for a diving leg
333 */
334 public double getFromDepth(LengthUnit units) {
335 return UtilityFunctions.lengthFromMetres( fromDepth, units );
336 }
337
338 /**
339 * @param units Length units to return the value in
340 * @return The to Depth for a diving leg
341 */
342 public double getToDepth(LengthUnit units) {
343 return UtilityFunctions.lengthFromMetres( toDepth, units );
344 }
345
346 /**
347 * Setting this sets the leg to a diving type leg.
348 * @param fromDepth the depth of the from station
349 * @param toDepth the depth of the to station
350 * @param units Units of the specified depth measurements
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 }