Search in sources :

Example 26 with Leg

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);
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) Leg(org.hwyl.sexytopo.model.survey.Leg) Test(org.junit.Test)

Example 27 with Leg

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();
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) GraphToListTranslator(org.hwyl.sexytopo.control.util.GraphToListTranslator) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 28 with Leg

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;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 29 with Leg

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;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONException(org.json.JSONException) ParseException(java.text.ParseException) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 30 with 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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ParseException(java.text.ParseException) Leg(org.hwyl.sexytopo.model.survey.Leg) Station(org.hwyl.sexytopo.model.survey.Station) JSONObject(org.json.JSONObject) TreeSet(java.util.TreeSet)

Aggregations

Leg (org.hwyl.sexytopo.model.survey.Leg)94 Station (org.hwyl.sexytopo.model.survey.Station)30 Test (org.junit.Test)30 Survey (org.hwyl.sexytopo.model.survey.Survey)23 Coord3D (org.hwyl.sexytopo.model.graph.Coord3D)17 Line (org.hwyl.sexytopo.model.graph.Line)8 ArrayList (java.util.ArrayList)7 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)7 JSONArray (org.json.JSONArray)6 JSONObject (org.json.JSONObject)6 Space (org.hwyl.sexytopo.model.graph.Space)4 TextView (android.widget.TextView)3 GraphToListTranslator (org.hwyl.sexytopo.control.util.GraphToListTranslator)3 TableCol (org.hwyl.sexytopo.model.table.TableCol)3 JSONException (org.json.JSONException)3 AlertDialog (android.app.AlertDialog)2 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2 LRUD (org.hwyl.sexytopo.model.table.LRUD)2 SuppressLint (android.annotation.SuppressLint)1