Search in sources :

Example 1 with Trip

use of org.hwyl.sexytopo.model.survey.Trip in project sexytopo by richsmith.

the class SurveyChecker method areEqual.

public static boolean areEqual(Survey one, Survey two) {
    List<Station> oneStations = one.getAllStations();
    List<Station> twoStations = two.getAllStations();
    if (oneStations.size() != twoStations.size()) {
        return false;
    }
    for (Station station : one.getAllStations()) {
        Station other = two.getStationByName(station.getName());
        if (!areEqual(station, other)) {
            return false;
        }
    }
    Trip oneTrip = one.getTrip();
    Trip twoTrip = two.getTrip();
    if ((oneTrip == null) ^ (twoTrip == null)) {
        return false;
    }
    if (oneTrip != null) {
        if (!oneTrip.equalsTripData(twoTrip)) {
            return false;
        }
    }
    return true;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Trip(org.hwyl.sexytopo.model.survey.Trip)

Example 2 with Trip

use of org.hwyl.sexytopo.model.survey.Trip in project sexytopo by richsmith.

the class SurveyJsonTranslater method toSurvey.

public static void toSurvey(Survey survey, JSONObject json) throws JSONException, ParseException {
    errors = false;
    String name = json.getString(SURVEY_NAME_TAG);
    if (!survey.getName().equals(name)) {
        Log.e("This is weird; the survey name in the file is different to the filename. " + "Assuming filename is the correct name.");
    }
    try {
        // have to parse trips before stations etc. so trips can be referenced by them
        if (json.has(TRIP_TAG)) {
            JSONObject tripObject = json.getJSONObject(TRIP_TAG);
            Trip trip = toTrip(tripObject);
            survey.setTrip(trip);
        }
    } catch (JSONException exception) {
        Log.e("Failed to load trip: " + exception);
    // carry on... unfortunate, but not *that* important
    }
    try {
        JSONArray stationsArray = json.getJSONArray(STATIONS_TAG);
        loadSurveyData(survey, stationsArray);
    } catch (JSONException exception) {
        Log.e("Failed to load stations: " + exception);
    }
    try {
        String activeStationName = json.getString(ACTIVE_STATION_TAG);
        Station activeStation = survey.getStationByName(activeStationName);
        survey.setActiveStation(activeStation);
    } catch (Exception ignore) {
    // ah, never mind... not mission-critical
    }
    if (errors) {
        String message = "Partial errors encountered; survey load was incomplete";
        Toast.makeText(SexyTopo.context, message, Toast.LENGTH_SHORT).show();
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Trip(org.hwyl.sexytopo.model.survey.Trip) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONException(org.json.JSONException) ParseException(java.text.ParseException)

Example 3 with Trip

use of org.hwyl.sexytopo.model.survey.Trip in project sexytopo by richsmith.

the class SurveyJsonTranslater method toJson.

public static JSONObject toJson(Trip trip) throws JSONException {
    JSONObject json = new JSONObject();
    DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN);
    String date = dateFormat.format(trip.getDate());
    json.put(TRIP_DATE_TAG, date);
    json.put(COMMENT_TAG, trip.getComments());
    JSONArray teamArray = new JSONArray();
    for (Trip.TeamEntry teamEntry : trip.getTeam()) {
        JSONObject teamEntryJson = new JSONObject();
        teamEntryJson.put(TEAM_MEMBER_NAME_TAG, teamEntry.name);
        JSONArray rolesJson = new JSONArray();
        for (Trip.Role role : teamEntry.roles) {
            rolesJson.put(role.name());
        }
        teamEntryJson.put(TEAM_MEMBER_ROLE_TAG, rolesJson);
        teamArray.put(teamEntryJson);
    }
    json.put(TEAM_TAG, teamArray);
    return json;
}
Also used : Trip(org.hwyl.sexytopo.model.survey.Trip) JSONObject(org.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) JSONArray(org.json.JSONArray) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with Trip

use of org.hwyl.sexytopo.model.survey.Trip in project sexytopo by richsmith.

the class PocketTopoTxtExporter method getContent.

public String getContent(Survey survey) {
    String text = "TRIP\n";
    text += "DATE ";
    if (survey.getTrip() != null) {
        Trip trip = survey.getTrip();
        Date date = trip.getDate();
        text += TextTools.toIsoDate(date);
    } else {
        text += "1970-01-01\n";
    }
    text += "\n";
    text += "DECLINATION\t0.00\n";
    text += exportData(survey) + "\n";
    text += exportPlan(survey) + "\n";
    text += exportExtendedElevation(survey);
    return text;
}
Also used : Trip(org.hwyl.sexytopo.model.survey.Trip) Date(java.util.Date)

Example 5 with Trip

use of org.hwyl.sexytopo.model.survey.Trip in project sexytopo by richsmith.

the class ThExporter method getCentreline.

private static String getCentreline(Survey survey) {
    GraphToListTranslator graphToListTranslator = new GraphToListTranslator();
    StringBuilder builder = new StringBuilder();
    Trip trip = survey.getTrip();
    if (trip != null) {
        builder.append(formatTrip(trip));
    }
    builder.append("data normal from to length compass clino\n\n");
    List<GraphToListTranslator.SurveyListEntry> list = graphToListTranslator.toChronoListOfSurveyListEntries(survey);
    for (GraphToListTranslator.SurveyListEntry entry : list) {
        SurvexTherionUtil.formatEntry(builder, entry, COMMENT_CHAR);
        builder.append("\n");
    }
    return builder.toString();
}
Also used : Trip(org.hwyl.sexytopo.model.survey.Trip) GraphToListTranslator(org.hwyl.sexytopo.control.util.GraphToListTranslator)

Aggregations

Trip (org.hwyl.sexytopo.model.survey.Trip)9 Date (java.util.Date)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Station (org.hwyl.sexytopo.model.survey.Station)2 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 ParseException (java.text.ParseException)1 GraphToListTranslator (org.hwyl.sexytopo.control.util.GraphToListTranslator)1 Leg (org.hwyl.sexytopo.model.survey.Leg)1 Survey (org.hwyl.sexytopo.model.survey.Survey)1 JSONException (org.json.JSONException)1