use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class PocketTopoTxtImporter method parseDataAndUpdateSurvey.
private static void parseDataAndUpdateSurvey(Survey survey, String fullText) {
String text = getSection(fullText, "DATA");
boolean firstStation = true;
for (String line : TextTools.toArrayOfLines(text)) {
String[] fields = line.split("\\t");
if (fields.length < 3) {
continue;
}
String fromStationName = fields[0];
String toStationName = fields[1];
float azimuth = Float.parseFloat(fields[2]);
float inclination = Float.parseFloat(fields[3]);
float distance = Float.parseFloat(fields[4]);
if (firstStation) {
survey.getOrigin().setName(fromStationName);
firstStation = false;
}
Station fromStation = survey.getStationByName(fromStationName);
survey.setActiveStation(fromStation);
if (toStationName.equals("")) {
Leg leg = new Leg(distance, azimuth, inclination);
SurveyUpdater.update(survey, leg);
} else {
Station toStation = new Station(toStationName);
Leg leg = new Leg(distance, azimuth, inclination, toStation, new Leg[] {});
SurveyUpdater.updateWithNewStation(survey, leg);
}
}
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurveyJsonTranslater method createLegs.
public static void createLegs(Map<String, Station> namesToStations, JSONObject json) throws JSONException {
String fromStationName = json.getString(STATION_NAME_TAG);
Station station = namesToStations.get(fromStationName);
JSONArray array = json.getJSONArray(ONWARD_LEGS_TAG);
for (JSONObject object : Util.toList(array)) {
Leg leg = toLeg(namesToStations, object);
station.addOnwardLeg(leg);
}
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurveyJsonTranslater method toJson.
public static JSONObject toJson(Leg leg, Integer index) throws JSONException {
JSONObject json = new JSONObject();
json.put(DISTANCE_TAG, leg.getDistance());
json.put(AZIMUTH_TAG, leg.getAzimuth());
json.put(INCLINATION_TAG, leg.getInclination());
json.put(DESTINATION_TAG, leg.getDestination().getName());
json.put(WAS_SHOT_BACKWARDS_TAG, leg.wasShotBackwards());
if (index != null) {
json.put(INDEX_TAG, index);
}
JSONArray promotedFromArray = new JSONArray();
for (Leg promotedLeg : leg.getPromotedFrom()) {
promotedFromArray.put(toJson(promotedLeg, null));
}
json.put(PROMOTED_FROM_TAG, promotedFromArray);
return json;
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurvexImporter method parseAnyPromotedLegs.
public static Leg[] parseAnyPromotedLegs(String instructions) {
try {
List<Leg> legs = new ArrayList<>();
instructions = instructions.replace("{", "");
instructions = instructions.replace("}", "");
if (instructions.contains("from:")) {
instructions = instructions.replace("from:", "");
} else {
throw new Exception("Not an instruction we understand");
}
String[] legStrings = instructions.split(",");
for (String legString : legStrings) {
legString = legString.trim();
String[] fieldStrings = legString.split(" ");
float distance = Float.parseFloat(fieldStrings[0].trim());
float azimuth = Float.parseFloat(fieldStrings[1].trim());
float inclination = Float.parseFloat(fieldStrings[2].trim());
legs.add(new Leg(distance, azimuth, inclination));
}
return legs.toArray(new Leg[] {});
} catch (Exception exception) {
Log.e("Error parsing promoted leg (ignoring and carrying on): " + exception);
// seems to be corrupted... feature not mission-critical so bail
return new Leg[] {};
}
}
use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.
the class SurvexImporter method addLegToSurvey.
private static void addLegToSurvey(Survey survey, Map<String, Station> nameToStation, String[] fields, String comment) {
String fromName = fields[0];
String toName = fields[1];
float distance = Float.parseFloat(fields[2]);
float azimuth = Float.parseFloat(fields[3]);
float inclination = Float.parseFloat(fields[4]);
if (nameToStation.size() == 0) {
Station origin = new Station(fromName);
survey.setOrigin(origin);
nameToStation.put(origin.getName(), origin);
}
String commentInstructions = extractCommentInstructions(comment);
if (commentInstructions != null) {
comment = comment.replace(commentInstructions, "").trim();
}
Station from = retrieveOrCreateStation(nameToStation, fromName, "");
Station to = retrieveOrCreateStation(nameToStation, toName, comment);
Leg[] promotedFrom = parseAnyPromotedLegs(commentInstructions);
Leg leg = (to == Survey.NULL_STATION) ? new Leg(distance, azimuth, inclination) : new Leg(distance, azimuth, inclination, to, promotedFrom);
from.addOnwardLeg(leg);
// bit of a hack; hopefully the last station processed will be the active one
survey.setActiveStation(from);
}
Aggregations