use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurveyUpdaterTest method testUpdateWithOneLegAddsOneLegToSurvey.
@Test
public void testUpdateWithOneLegAddsOneLegToSurvey() {
Leg leg = new Leg(5, 0, 0);
Survey survey = new Survey("Test Survey");
SurveyUpdater.update(survey, leg);
Assert.assertEquals(survey.getAllLegs().size(), 1);
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class CompassExporter method getContent.
/**
* Export a SexyTopo Survey as a Compass .DAT file.
* @param survey
* @return
*/
public String getContent(Survey survey) {
List<GraphToListTranslator.SurveyListEntry> data = graphToListTranslator.toChronoListOfSurveyListEntries(survey);
String surveyDate = dateFormat.format(Calendar.getInstance().getTime());
StringBuilder sb = new StringBuilder(1024);
sb.append("SexyTopo Export\r\n");
sb.append(String.format("SURVEY NAME: %s\r\n", survey.getName()));
sb.append(String.format("SURVEY DATE: %s\tCOMMENT: \r\n", surveyDate));
sb.append("SURVEY TEAM:\r\n\r\n");
sb.append("DECLINATION: 0.00\tFORMAT: DMMDLRUDLADNF\tCORRECTIONS: 0.00 0.00 0.00\r\n");
sb.append("\r\n");
sb.append("FROM\tTO\tLENGTH\tBEARING\tINC\tLEFT\tUP\tDOWN\tRIGHT\tFLAGS\tCOMMENTS\r\n");
sb.append("\r\n");
for (GraphToListTranslator.SurveyListEntry entry : data) {
Leg leg = entry.getLeg();
Station from = entry.getFrom();
String to = leg.hasDestination() ? leg.getDestination().toString() : this.splayStationFrom(from);
// all Compass lengths are decimal feet!
double dist = leg.getDistance() * METERS_TO_FEET;
double azm = leg.getAzimuth();
double inc = leg.getInclination();
sb.append(String.format("%s\t%s\t%.2f\t%.2f\t%.2f\t", from, to, dist, azm, inc));
// LUDR, must be in that order
sb.append("-9.99\t-9.99\t-9.99\t-9.99\t");
if (!leg.hasDestination()) {
// exclude splay shots from cave length calculations
sb.append("#|L#");
}
// empty comments field
sb.append("\t\t\r\n");
}
// ASCII formfeed denotes end of survey
sb.append('\f');
return sb.toString();
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurveyJsonTranslater method toJson.
public static JSONObject toJson(Survey survey, String versionName, int versionCode) throws JSONException {
JSONObject json = new JSONObject();
json.put(VERSION_NAME_TAG, versionName);
json.put(VERSION_CODE_TAG, versionCode);
json.put(SURVEY_NAME_TAG, survey.getName());
JSONArray stationArray = new JSONArray();
List<Leg> chronoList = survey.getAllLegsInChronoOrder();
stationArray.put(toJson(survey.getOrigin(), chronoList));
for (Leg leg : chronoList) {
if (leg.hasDestination()) {
stationArray.put(toJson(leg.getDestination(), chronoList));
}
}
json.put(STATIONS_TAG, stationArray);
if (survey.getTrip() != null) {
JSONObject trip = toJson(survey.getTrip());
json.put(TRIP_TAG, trip);
}
return json;
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurveyJsonTranslater method toLeg.
public static Leg toLeg(Map<String, Station> namesToStations, JSONObject json) throws JSONException {
float distance = (float) json.getDouble(DISTANCE_TAG);
float azimuth = (float) json.getDouble(AZIMUTH_TAG);
float inclination = (float) json.getDouble(INCLINATION_TAG);
boolean wasShotBackwards = json.getBoolean(WAS_SHOT_BACKWARDS_TAG);
String destinationName = json.getString(DESTINATION_TAG);
Leg leg;
if (destinationName.equals(SexyTopo.BLANK_STATION_NAME)) {
leg = new Leg(distance, azimuth, inclination, wasShotBackwards);
} else {
if (!namesToStations.containsKey(destinationName)) {
throw new JSONException("Survey file corrupted: station " + destinationName + " missing or out of order");
}
List<Leg> promotedFromList = new ArrayList<>();
try {
JSONArray array = json.getJSONArray(PROMOTED_FROM_TAG);
for (JSONObject object : Util.toList(array)) {
Leg promotedFrom = toLeg(namesToStations, object);
promotedFromList.add(promotedFrom);
}
} catch (Exception ignore) {
// not ideal but not the end of the world; we'd probably prefer to have our data
}
Leg[] promotedFrom = promotedFromList.toArray(new Leg[] {});
Station destination = namesToStations.get(destinationName);
leg = new Leg(distance, azimuth, inclination, destination, promotedFrom, wasShotBackwards);
}
return leg;
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurveyJsonTranslater method loadSurveyData.
public static void loadSurveyData(Survey survey, JSONArray json) throws JSONException {
Map<String, Station> namesToStations = new HashMap<>();
List<JSONObject> stationData = Util.toList(json);
// first pass: add all the stations in case there's some weird data order
boolean first = true;
for (JSONObject stationObject : stationData) {
Station station;
try {
station = toStation(stationObject);
} catch (Exception exception) {
Log.e("Error loading a station; skipping. Exception was: " + exception + "; text was: " + stationObject);
errors = true;
continue;
}
String name = station.getName();
if (namesToStations.containsKey(station.getName())) {
Log.e("Found duplicate station " + name + "; skipping");
errors = true;
continue;
}
namesToStations.put(station.getName(), station);
if (first) {
first = false;
survey.setOrigin(station);
}
}
// second pass: add the legs
Map<Integer, Leg> indexToLegs = new HashMap<>();
List<Leg> unindexedLegs = new ArrayList<>();
List<Station> connectedDestinations = new ArrayList<>();
for (JSONObject stationObject : stationData) {
String name = stationObject.getString(STATION_NAME_TAG);
Station station = namesToStations.get(name);
JSONArray legArray = stationObject.getJSONArray(ONWARD_LEGS_TAG);
for (JSONObject legObject : Util.toList(legArray)) {
Leg leg;
try {
leg = toLeg(namesToStations, legObject);
if (leg.hasDestination()) {
if (connectedDestinations.contains(leg.getDestination())) {
Log.e("Duplicate connection found for " + leg.getDestination().getName() + "; skipping leg");
errors = true;
continue;
} else {
connectedDestinations.add(leg.getDestination());
}
}
if (leg.hasDestination() && leg.getDestination() == survey.getOrigin()) {
survey.setOrigin(station);
}
} catch (Exception exception) {
Log.e("Error loading a leg. Exception was " + exception + "; text was " + legObject);
errors = true;
continue;
}
if (legObject.has(INDEX_TAG)) {
int index = legObject.getInt(INDEX_TAG);
indexToLegs.put(index, leg);
} else {
unindexedLegs.add(leg);
}
station.addOnwardLeg(leg);
}
}
for (Leg leg : unindexedLegs) {
survey.addLegRecord(leg);
}
TreeSet<Integer> indices = new TreeSet<>(indexToLegs.keySet());
for (int i : indices) {
Leg leg = indexToLegs.get(i);
survey.addLegRecord(leg);
}
survey.checkSurveyIntegrity();
}
Aggregations