Search in sources :

Example 16 with Station

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

the class TableActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(this);
    broadcastManager.registerReceiver(receiver, new IntentFilter(SexyTopo.SURVEY_UPDATED_EVENT));
    syncTableWithSurvey();
    Bundle bundle = getIntent().getExtras();
    if (bundle != null && bundle.getString(SexyTopo.JUMP_TO_STATION) != null) {
        String requestedStationName = bundle.getString(SexyTopo.JUMP_TO_STATION);
        Station requestedStation = getSurvey().getStationByName(requestedStationName);
        jumpToStation(requestedStation);
    } else {
        final ScrollView scrollView = findViewById(R.id.BodyTableScrollView);
        scrollView.fullScroll(View.FOCUS_DOWN);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) IntentFilter(android.content.IntentFilter) ScrollView(android.widget.ScrollView) Bundle(android.os.Bundle) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager)

Example 17 with Station

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

the class TableActivity method requestMoveLeg.

@SuppressLint("InflateParams")
private void requestMoveLeg(final Leg toMove) {
    View stationView = getLayoutInflater().inflate(R.layout.select_station_dialog, null);
    List<String> spinnerArray = new ArrayList<>();
    List<Station> stations = LegMover.getValidDestinations(getSurvey(), toMove);
    if (stations.isEmpty()) {
        showSimpleToast(R.string.move_leg_no_valid_move);
        return;
    }
    for (Station station : stations) {
        spinnerArray.add(station.getName());
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, spinnerArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    final Spinner spinner = stationView.findViewById(R.id.stationSpinner);
    spinner.setAdapter(adapter);
    new AlertDialog.Builder(this).setMessage(R.string.move_leg_select_station_title).setView(stationView).setPositiveButton(R.string.move, (dialog, which) -> {
        String selectedName = spinner.getSelectedItem().toString();
        Station newStation = getSurvey().getStationByName(selectedName);
        SurveyUpdater.moveLeg(getSurvey(), toMove, newStation);
        syncTableWithSurvey();
    }).setNegativeButton(R.string.cancel, null).show();
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) AlertDialog(android.app.AlertDialog) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) View(android.view.View) GraphView(org.hwyl.sexytopo.control.graph.GraphView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ArrayAdapter(android.widget.ArrayAdapter) SuppressLint(android.annotation.SuppressLint)

Example 18 with Station

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

the class OldStyleLoader method addLegToSurvey.

private static void addLegToSurvey(Survey survey, Map<String, Station> nameToStation, String[] fields, String comment) throws Exception {
    Station from = retrieveOrCreateStation(nameToStation, fields[0], comment);
    Station to = retrieveOrCreateStation(nameToStation, fields[1], comment);
    float distance = Float.parseFloat(fields[2]);
    float azimuth = Float.parseFloat(fields[3]);
    float inclination = Float.parseFloat(fields[4]);
    List<Station> stationsSoFar = survey.getAllStations();
    if (!stationsSoFar.contains(from) && !stationsSoFar.contains(to)) {
        throw new Exception("Stations are out of order in file");
    } else if (stationsSoFar.contains(from) && stationsSoFar.contains(to)) {
        throw new Exception("Duplicate leg encountered");
    } else if (stationsSoFar.contains(from)) {
        // forward leg
        Leg leg = (to == Survey.NULL_STATION) ? new Leg(distance, azimuth, inclination) : new Leg(distance, azimuth, inclination, to, new Leg[] {});
        from.addOnwardLeg(leg);
    } else if (stationsSoFar.contains(to)) {
        // backwards leg
        Leg leg = (from == Survey.NULL_STATION) ? new Leg(distance, azimuth, inclination) : new Leg(distance, azimuth, inclination, from, new Leg[] {});
        to.addOnwardLeg(leg.reverse());
    }
    // Bit of a hack; hopefully the last station processed will be the active one
    // (should probably record the active station in the file somewhere)
    survey.setActiveStation(from);
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 19 with Station

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

the class SexyTopoActivity method chooseSurveyToUnlink.

private void chooseSurveyToUnlink(final Survey survey, final Station station) {
    AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
    builderSingle.setTitle(getString(R.string.unlink_survey));
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
    final Set<SurveyConnection> connections = survey.getSurveysConnectedTo(station);
    for (SurveyConnection connection : connections) {
        arrayAdapter.add(connection.otherSurvey.getName());
    }
    builderSingle.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());
    builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
        String surveyName = arrayAdapter.getItem(which);
        try {
            for (SurveyConnection connection : connections) {
                if (connection.otherSurvey.getName().equals(surveyName)) {
                    Survey to = connection.otherSurvey;
                    Station stationTo = connection.stationInOtherSurvey;
                    unlinkSurveyConnection(survey, station, to, stationTo);
                    return;
                }
            }
            throw new Exception("Couldn't find linked survey");
        } catch (Exception exception) {
            showException(exception);
        }
    });
    builderSingle.show();
}
Also used : AlertDialog(android.app.AlertDialog) Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) ArrayAdapter(android.widget.ArrayAdapter)

Example 20 with Station

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

the class SurvexExporterTest method testCommentsAreIncluded.

@Test
public void testCommentsAreIncluded() {
    SurvexExporter survexExporter = new SurvexExporter();
    Survey oneNorth = BasicTestSurveyCreator.createStraightNorthThroughRepeats();
    Station latest = oneNorth.getActiveStation();
    String testComment = "Comment McComment Face";
    latest.setComment(testComment);
    String content = survexExporter.getContent(oneNorth);
    Assert.assertTrue(content.contains(testComment));
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) Test(org.junit.Test)

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