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();
}
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());
}
}
}
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);
}
}
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");
}
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;
}
Aggregations