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.getConnectedSurveys().get(station);
for (SurveyConnection connection : connections) {
arrayAdapter.add(connection.otherSurvey.getName());
}
builderSingle.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int 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();
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class SexyTopoActivity method linkToStationInSurvey.
private void linkToStationInSurvey(final Survey surveyToLink) {
final Station[] stations = surveyToLink.getAllStations().toArray(new Station[] {});
AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
builderSingle.setTitle(getString(R.string.link_survey_station));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
for (Station station : stations) {
arrayAdapter.add(station.getName());
}
builderSingle.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String stationName = arrayAdapter.getItem(which);
try {
Station selectedStation = Survey.NULL_STATION;
for (Station station : stations) {
if (station.getName().equals(stationName)) {
selectedStation = station;
break;
}
}
Survey current = getSurvey();
joinSurveys(current, current.getActiveStation(), surveyToLink, selectedStation);
} catch (Exception exception) {
showException(exception);
}
}
});
builderSingle.show();
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class TableActivity method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
final TableCol col = fieldToTableCol.get(cellBeingClicked);
final GraphToListTranslator.SurveyListEntry surveyEntry = fieldToSurveyEntry.get(cellBeingClicked);
switch(menuItem.getItemId()) {
case R.id.setActiveStation:
Station newActive = (Station) (GraphToListTranslator.createMap(surveyEntry).get(col));
getSurvey().setActiveStation(newActive);
syncTableWithSurvey();
return true;
case R.id.renameStation:
Station toRename = (Station) (GraphToListTranslator.createMap(surveyEntry).get(col));
if (toRename == Survey.NULL_STATION) {
showSimpleToast("Can't rename a splay end");
} else {
ManualEntry.renameStation(this, getSurvey(), toRename);
}
return true;
case R.id.editLeg:
Leg toEdit = surveyEntry.getLeg();
ManualEntry.editLeg(this, getSurvey(), toEdit);
return true;
case R.id.upgradeRow:
Leg toUpgrade = surveyEntry.getLeg();
SurveyUpdater.upgradeSplayToConnectedLeg(getSurvey(), toUpgrade);
syncTableWithSurvey();
return true;
case R.id.deleteRow:
int legsToBeDeleted = SurveyStats.calcNumberSubLegs(surveyEntry.getFrom());
int stationsToBeDeleted = SurveyStats.calcNumberSubStations(surveyEntry.getFrom());
String detailMessage = "This will delete\n" + TextTools.pluralise(legsToBeDeleted, "leg") + " and " + TextTools.pluralise(stationsToBeDeleted, "station");
String message = (legsToBeDeleted > 1 || stationsToBeDeleted > 1) ? detailMessage : getString(R.string.delete_row_question);
new AlertDialog.Builder(this).setMessage(message).setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SurveyUpdater.deleteLeg(getSurvey(), surveyEntry.getLeg());
syncTableWithSurvey();
}
}).setNegativeButton(R.string.cancel, null).show();
return true;
default:
return false;
}
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class ConnectedSurveys method updateTranslatedConnectedSurveys.
private static void updateTranslatedConnectedSurveys(GraphActivity activity, Survey original, Map<Survey, Space<Coord2D>> translated, Survey survey, Space<Coord2D> projection) {
Map<Station, Set<SurveyConnection>> connections = survey.getConnectedSurveys();
for (Station connectingStation : connections.keySet()) {
Coord2D connectingStationLocation = projection.getStationMap().get(connectingStation);
for (SurveyConnection connection : connections.get(connectingStation)) {
Station otherConnectingStation = connection.stationInOtherSurvey;
Survey otherSurvey = connection.otherSurvey;
if (haveWeAlreadyDoneThisSurvey(translated, otherSurvey, original)) {
continue;
}
// create a new copy of the survey so we can edit the associated sketch
// (this might seem a bit messy but it's reasonably elegant, honest!)
Survey lightweightSurveyCopy = new Survey(otherSurvey.getName());
lightweightSurveyCopy.setOrigin(otherSurvey.getOrigin());
Space<Coord2D> otherProjection = SpaceFlipper.flipVertically(activity.getProjection(connection.otherSurvey));
Coord2D otherConnectingStationLocation = otherProjection.getStationMap().get(otherConnectingStation);
Coord2D transformation = connectingStationLocation.minus(otherConnectingStationLocation);
Sketch translatedPlan = otherSurvey.getPlanSketch().getTranslatedCopy(transformation);
lightweightSurveyCopy.setPlanSketch(translatedPlan);
Sketch translatedElevation = otherSurvey.getElevationSketch().getTranslatedCopy(transformation);
lightweightSurveyCopy.setElevationSketch(translatedElevation);
otherProjection = Space2DUtils.transform(otherProjection, transformation);
translated.put(lightweightSurveyCopy, otherProjection);
updateTranslatedConnectedSurveys(activity, original, translated, otherSurvey, otherProjection);
}
}
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class GraphView method findNearestStationWithinDelta.
private static Station findNearestStationWithinDelta(Space<Coord2D> space, Coord2D target, double delta) {
double shortest = Double.MAX_VALUE;
Station best = null;
for (Station station : space.getStationMap().keySet()) {
Coord2D point = space.getStationMap().get(station);
double distance = Space2DUtils.getDistance(point, target);
if (distance > delta) {
continue;
}
if (best == null || (distance < shortest)) {
best = station;
shortest = distance;
}
}
return best;
}
Aggregations