Search in sources :

Example 31 with Station

use of org.hwyl.sexytopo.model.survey.Station 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 32 with Station

use of org.hwyl.sexytopo.model.survey.Station 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 33 with Station

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

the class MetadataTranslater method toJson.

public static JSONObject toJson(Survey survey) throws JSONException {
    JSONObject json = new JSONObject();
    String activeStationName = survey.getActiveStation().getName();
    json.put(ACTIVE_STATION_TAG, activeStationName);
    Map<Station, Set<SurveyConnection>> connectedSurveys = survey.getConnectedSurveys();
    JSONObject jsonMap = toJson(connectedSurveys);
    json.put(CONNECTIONS_TAG, jsonMap);
    return json;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Set(java.util.Set) HashSet(java.util.HashSet) JSONObject(org.json.JSONObject)

Example 34 with Station

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

the class MetadataTranslater method toJson.

private static JSONObject toJson(Map<Station, Set<SurveyConnection>> connectedSurveys) throws JSONException {
    JSONObject connectionMap = new JSONObject();
    for (Station connectionPoint : connectedSurveys.keySet()) {
        Set<SurveyConnection> connections = connectedSurveys.get(connectionPoint);
        JSONArray setObject = new JSONArray();
        for (SurveyConnection connection : connections) {
            JSONArray connectionObject = toJson(connection);
            setObject.put(connectionObject);
        }
        connectionMap.put(connectionPoint.getName(), setObject);
    }
    return connectionMap;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) JSONObject(org.json.JSONObject) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) JSONArray(org.json.JSONArray)

Example 35 with Station

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

the class MetadataTranslater method translateAndUpdateConnections.

@SuppressWarnings("UnnecessaryContinue")
private static void translateAndUpdateConnections(Context context, Survey survey, JSONObject json, Set<String> surveyNamesNotToLoad) throws Exception {
    try {
        JSONObject connectionsObject = json.getJSONObject(CONNECTIONS_TAG);
        Map<String, JSONArray> outerMap = Util.toMap(connectionsObject);
        for (String stationName : outerMap.keySet()) {
            Station station = survey.getStationByName(stationName);
            JSONArray setArray = outerMap.get(stationName);
            for (JSONArray connectionPair : toListOfArrays(setArray)) {
                assert connectionPair.length() == 2;
                String connectedSurveyName = connectionPair.get(0).toString();
                String connectionPointName = connectionPair.get(1).toString();
                if (surveyNamesNotToLoad.contains(connectedSurveyName)) {
                    // if this survey is already loaded, don't do the whole infinite loop thing
                    continue;
                } else {
                    // we *really* want to avoid infinite loops :)
                    // this should be added on load, but just as a precaution..
                    surveyNamesNotToLoad.add(connectedSurveyName);
                    try {
                        Survey connectedSurvey = Loader.loadSurvey(context, connectedSurveyName, surveyNamesNotToLoad, false);
                        Station connectionPoint = connectedSurvey.getStationByName(connectionPointName);
                        if (connectionPoint == null) {
                            Log.e("Connection point not found: " + connectionPoint.getName());
                            throw new Exception("Connection point not found");
                        }
                        survey.connect(station, connectedSurvey, connectionPoint);
                    } catch (Exception exception) {
                        // the linked survey or connecting station has probably been deleted;
                        // not much we can do...
                        Log.e("Could not load connected survey " + connectedSurveyName);
                        continue;
                    }
                }
            }
        }
    } catch (JSONException exception) {
        Log.e(exception.toString());
        throw new Exception("Error loading connected surveys");
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONException(org.json.JSONException)

Aggregations

Station (org.hwyl.sexytopo.model.survey.Station)85 Leg (org.hwyl.sexytopo.model.survey.Leg)32 Survey (org.hwyl.sexytopo.model.survey.Survey)30 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)20 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 SuppressLint (android.annotation.SuppressLint)8 AlertDialog (android.app.AlertDialog)8 JSONException (org.json.JSONException)7 Line (org.hwyl.sexytopo.model.graph.Line)6 SurveyConnection (org.hwyl.sexytopo.model.survey.SurveyConnection)6 JSONObject (org.json.JSONObject)6 View (android.view.View)5 Set (java.util.Set)5 Direction (org.hwyl.sexytopo.model.graph.Direction)5 Space (org.hwyl.sexytopo.model.graph.Space)5 JSONArray (org.json.JSONArray)5 Context (android.content.Context)4 HashSet (java.util.HashSet)4