use of org.hwyl.sexytopo.model.survey.SurveyConnection 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 = 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.SurveyConnection in project sexytopo by richsmith.
the class SexyTopoActivity method unlinkSurvey.
public void unlinkSurvey(final Station station) {
try {
Survey survey = getSurvey();
Set<SurveyConnection> linked = survey.getConnectedSurveys().get(station);
if (linked == null || linked.size() < 1) {
throw new Exception("Can't find any surveys to unlink");
} else if (linked.size() == 1) {
SurveyConnection onlyConnection = linked.iterator().next();
unlinkSurveyConnection(survey, station, onlyConnection.otherSurvey, onlyConnection.stationInOtherSurvey);
} else {
chooseSurveyToUnlink(survey, station);
}
} catch (Exception exception) {
showSimpleToast("Error unlinking survey: " + exception.getMessage());
showException(exception);
}
}
use of org.hwyl.sexytopo.model.survey.SurveyConnection 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();
}
use of org.hwyl.sexytopo.model.survey.SurveyConnection in project sexytopo by richsmith.
the class MetadataTranslater method toJson.
private static JSONObject toJson(Map<Station, Set<SurveyConnection>> connectedSurveys) throws JSONException {
JSONObject connectionMap = new JSONObject();
for (Station connectionPoint : connectedSurveys.keySet()) {
Set<SurveyConnection> connections = connectedSurveys.get(connectionPoint);
JSONArray setObject = new JSONArray();
for (SurveyConnection connection : connections) {
JSONArray connectionObject = toJson(connection);
setObject.put(connectionObject);
}
connectionMap.put(connectionPoint.getName(), setObject);
}
return connectionMap;
}
Aggregations