Search in sources :

Example 51 with Leg

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

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

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

Example 54 with Leg

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[] {};
    }
}
Also used : ArrayList(java.util.ArrayList) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 55 with 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);
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Leg(org.hwyl.sexytopo.model.survey.Leg)

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