Search in sources :

Example 56 with Station

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

the class SketchJsonTranslater method toCrossSectionDetail.

public static CrossSectionDetail toCrossSectionDetail(Survey survey, JSONObject json) throws JSONException {
    Coord2D position = toCoord2D(json.getJSONObject(POSITION_TAG));
    float angle = (float) json.getDouble(ANGLE_TAG);
    String stationdId = json.getString(STATION_ID_TAG);
    Station station = survey.getStationByName(stationdId);
    CrossSectionDetail crossSectionDetail = new CrossSectionDetail(new CrossSection(station, angle), position);
    return crossSectionDetail;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection)

Example 57 with Station

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

the class PocketTopoTxtImporter method extractOffset.

public static Coord2D extractOffset(Survey survey, String text, Space<Coord2D> projection) {
    String stationsSection = getNamedSubSection(text, "STATIONS");
    String[] lines = TextTools.toArrayOfLines(stationsSection);
    Station guessedAnchorStation = survey.getOrigin();
    Coord2D offset = getOffsetForNamedStation(lines, guessedAnchorStation);
    if (offset == null) {
        if (guessedAnchorStation.getConnectedOnwardLegs().size() > 0) {
            Leg onward = guessedAnchorStation.getConnectedOnwardLegs().get(0);
            guessedAnchorStation = onward.getDestination();
            offset = getOffsetForNamedStation(lines, guessedAnchorStation);
            Coord2D position = projection.getStationMap().get(guessedAnchorStation);
            offset = offset.minus(position.flipVertically());
        }
    }
    if (offset == null) {
        // ¯\_(ツ)_/¯
        offset = Coord2D.ORIGIN;
    }
    return offset;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 58 with Station

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

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

the class MetadataTranslater method translateAndUpdateActiveStation.

private static void translateAndUpdateActiveStation(Survey survey, JSONObject json) throws Exception {
    try {
        String activeStationName = json.getString(ACTIVE_STATION_TAG);
        Station activeStation = survey.getStationByName(activeStationName);
        survey.setActiveStation(activeStation);
    } catch (JSONException exception) {
        Log.e("Could not load active station: " + exception.toString());
        throw new Exception("Error loading active station");
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) JSONException(org.json.JSONException) JSONException(org.json.JSONException)

Example 60 with Station

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

the class TableActivity method syncTableWithSurvey.

public void syncTableWithSurvey() {
    Survey survey = getSurvey();
    stationsToTableIndex.clear();
    List<GraphToListTranslator.SurveyListEntry> tableEntries = graphToListTranslator.toChronoListOfSurveyListEntries(survey);
    if (tableEntries.size() == 0) {
        Toast.makeText(getApplicationContext(), R.string.no_data, Toast.LENGTH_SHORT).show();
    }
    final TableLayout tableLayout = findViewById(R.id.BodyTable);
    tableLayout.removeAllViews();
    for (GraphToListTranslator.SurveyListEntry entry : tableEntries) {
        TableRow tableRow = (TableRow) LayoutInflater.from(this).inflate(R.layout.table_row, null);
        final Map<TableCol, Object> map = GraphToListTranslator.createMap(entry);
        for (TableCol col : TableCol.values()) {
            if (col == TableCol.COMMENT) {
                continue;
            }
            String display = map.containsKey(col) ? col.format(map.get(col)) : "?";
            int id = TABLE_COL_BY_ANDROID_ID.get(col);
            TextView textView = tableRow.findViewById(id);
            textView.setText(display);
            if (isActiveStation(map.get(col))) {
                textView.setBackgroundColor(GraphView.HIGHLIGHT_COLOUR.intValue);
            }
            if (entry.getLeg().hasDestination()) {
                textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
            } else {
                textView.setTypeface(textView.getTypeface(), Typeface.NORMAL);
            }
            fieldToSurveyEntry.put(textView, entry);
            fieldToTableCol.put(textView, col);
            textView.setOnLongClickListener(this);
        }
        int rowCount = tableLayout.getChildCount();
        tableLayout.addView(tableRow, rowCount);
        if (entry.getLeg().hasDestination()) {
            Station to = entry.getLeg().getDestination();
            stationsToTableIndex.put(to, rowCount);
        }
    }
    tableLayout.requestLayout();
}
Also used : TableCol(org.hwyl.sexytopo.model.table.TableCol) SuppressLint(android.annotation.SuppressLint) Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) GraphToListTranslator(org.hwyl.sexytopo.control.util.GraphToListTranslator) TableRow(android.widget.TableRow) TextView(android.widget.TextView) TableLayout(android.widget.TableLayout)

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