use of org.hwyl.sexytopo.model.survey.Survey 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();
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class GraphActivity method syncGraphWithSurvey.
private void syncGraphWithSurvey() {
Survey survey = getSurvey();
graphView.setSurvey(survey);
graphView.setSketch(getSketch(survey));
graphView.setProjection(getProjection(survey));
graphView.checkForChangedSurvey();
float surveyLength = SurveyStats.calcTotalLength(survey);
float surveyHeight = SurveyStats.calcHeightRange(survey);
graphView.setCachedStats(surveyLength, surveyHeight);
graphView.invalidate();
}
use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.
the class SurvexImporter method toSurvey.
@Override
public Survey toSurvey(File file) throws Exception {
String text = Loader.slurpFile(file.getAbsolutePath());
Survey survey = new Survey(getDefaultName(file));
parse(text, survey);
return survey;
}
use of org.hwyl.sexytopo.model.survey.Survey 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.Survey in project sexytopo by richsmith.
the class TherionImporter method toSurvey.
public Survey toSurvey(File directory) throws Exception {
Survey survey = null;
for (File file : directory.listFiles()) {
if (file.getName().endsWith("th")) {
survey = parseTh(file);
} else if (file.getName().endsWith("xvi")) {
String filenameNoExtension = FilenameUtils.removeExtension(file.getName());
if (filenameNoExtension.endsWith(SexyTopo.PLAN_SUFFIX)) {
Sketch sketch = XviImporter.getSketch(file);
survey.setPlanSketch(sketch);
} else if (filenameNoExtension.endsWith(SexyTopo.EE_SUFFIX)) {
Sketch sketch = XviImporter.getSketch(file);
survey.setElevationSketch(sketch);
}
}
}
return survey;
}
Aggregations