Search in sources :

Example 66 with Station

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

the class ManualEntry method renameStation.

public static void renameStation(final TableActivity activity, final Survey survey, final Station toRename) {
    final EditText renameField = new EditText(activity);
    renameField.setText(toRename.getName());
    renameField.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // nothing
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // nothing
        }

        public void afterTextChanged(Editable s) {
            String currentName = toRename.getName();
            String currentText = renameField.getText().toString();
            // only check for non-null or max length
            if (currentText.isEmpty()) {
                renameField.setError("Cannot be blank");
            } else if (currentText.equals("-")) {
                renameField.setError("Station cannot be named \"-\"");
            } else if (!currentText.equals(currentName) && (survey.getStationByName(currentText) != null)) {
                renameField.setError("Station name must be unique");
            } else {
                renameField.setError(null);
            }
        }
    });
    AlertDialog dialog = new AlertDialog.Builder(activity).setTitle("Edit name").setView(renameField).setPositiveButton("Rename", (ignore, buttonId) -> {
        String newName = renameField.getText().toString();
        try {
            SurveyUpdater.renameStation(survey, toRename, newName);
            activity.syncTableWithSurvey();
        } catch (Exception e) {
            activity.showSimpleToast("Rename failed");
        }
    }).setNegativeButton("Cancel", (ignore, buttonId) -> {
    /* Do nothing */
    }).create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    dialog.show();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) LayoutInflater(android.view.LayoutInflater) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) WindowManager(android.view.WindowManager) Dialog(android.app.Dialog) R(org.hwyl.sexytopo.R) Station(org.hwyl.sexytopo.model.survey.Station) Editable(android.text.Editable) AlertDialog(android.app.AlertDialog) LRUD(org.hwyl.sexytopo.model.table.LRUD) TextView(android.widget.TextView) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) View(android.view.View) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) TextWatcher(android.text.TextWatcher) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Example 67 with Station

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

the class SurvexTherionUtil method formatEntry.

public static void formatEntry(StringBuilder builder, GraphToListTranslator.SurveyListEntry entry, char commentChar) {
    Station from = entry.getFrom();
    String fromName = from.getName();
    Leg leg = entry.getLeg();
    Station to = leg.getDestination();
    String toName = to.getName();
    if (leg.wasShotBackwards()) {
        leg = leg.reverse();
        fromName = to.getName();
        toName = from.getName();
    }
    formatField(builder, fromName);
    formatField(builder, toName);
    formatField(builder, TableCol.DISTANCE.format(leg.getDistance(), Locale.UK));
    formatField(builder, TableCol.AZIMUTH.format(leg.getAzimuth(), Locale.UK));
    formatField(builder, TableCol.INCLINATION.format(leg.getInclination(), Locale.UK));
    if (leg.wasPromoted() || to.hasComment()) {
        builder.append("\t").append(commentChar).append(" ");
        if (leg.wasPromoted()) {
            builder.append(" ");
            formatPromotedFrom(builder, leg.getPromotedFrom());
        }
        if (to.hasComment()) {
            builder.append(" ");
            formatComment(builder, to.getComment());
        }
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 68 with Station

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

the class TherionImporter method handleElevationDirectionData.

private static void handleElevationDirectionData(List<String> lines, Survey survey) {
    try {
        for (String line : lines) {
            final String EXTEND_PREFIX = "extend ";
            assert line.startsWith(EXTEND_PREFIX);
            String rest = line.substring(EXTEND_PREFIX.length());
            String[] tokens = rest.split(" ");
            assert tokens.length == 2;
            String directionName = tokens[0];
            if (directionName.equals("start")) {
                continue;
            }
            Direction direction = Direction.valueOf(directionName.toUpperCase());
            String stationName = tokens[1];
            Station station = survey.getStationByName(stationName);
            SurveyUpdater.setDirectionOfSubtree(station, direction);
        }
    } catch (Exception exception) {
        Log.e("corrupted survey extended elevation directions: " + exception);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Direction(org.hwyl.sexytopo.model.graph.Direction)

Example 69 with Station

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

the class SurvexImporterTest method testBasicImportHandlesComments.

@Test
public void testBasicImportHandlesComments() throws Exception {
    final String testContent = "1\t2\t5.0\t0.0\t0.0\t; {from: 5.0 0.0 0.0, 5.0 0.0 0.0, 5.0 0.0 0.0} testComment";
    Survey survey = new Survey("Test");
    SurvexImporter.parse(testContent, survey);
    Station created = survey.getStationByName("2");
    Assert.assertEquals(created.getComment(), "testComment");
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) Test(org.junit.Test)

Example 70 with Station

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

the class TestSurveyCreator method create.

public static Survey create(String name, int numStations, int numBranches) {
    Survey survey = new Survey(name);
    createBranch(survey, numStations);
    for (int i = 0; i < numBranches; i++) {
        List<Station> stations = survey.getAllStations();
        Station active = getRandom(stations);
        survey.setActiveStation(active);
        createBranch(survey, 3);
    }
    return survey;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey)

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