Search in sources :

Example 1 with SurveyConnection

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);
        }
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) Set(java.util.Set) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 2 with SurveyConnection

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);
    }
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection)

Example 3 with SurveyConnection

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();
}
Also used : AlertDialog(android.app.AlertDialog) Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) ArrayAdapter(android.widget.ArrayAdapter)

Example 4 with SurveyConnection

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;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) JSONObject(org.json.JSONObject) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) JSONArray(org.json.JSONArray)

Aggregations

SurveyConnection (org.hwyl.sexytopo.model.survey.SurveyConnection)4 Station (org.hwyl.sexytopo.model.survey.Station)3 Survey (org.hwyl.sexytopo.model.survey.Survey)3 AlertDialog (android.app.AlertDialog)1 ArrayAdapter (android.widget.ArrayAdapter)1 Set (java.util.Set)1 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)1 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1