Search in sources :

Example 1 with Station

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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) 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 2 with Station

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

Example 3 with Station

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;
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) GraphToListTranslator(org.hwyl.sexytopo.control.util.GraphToListTranslator) DialogInterface(android.content.DialogInterface) TableCol(org.hwyl.sexytopo.model.table.TableCol) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 4 with Station

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);
        }
    }
}
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 5 with Station

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

Aggregations

Station (org.hwyl.sexytopo.model.survey.Station)47 Leg (org.hwyl.sexytopo.model.survey.Leg)18 Survey (org.hwyl.sexytopo.model.survey.Survey)16 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)4 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 Line (org.hwyl.sexytopo.model.graph.Line)3 Space (org.hwyl.sexytopo.model.graph.Space)3 SurveyConnection (org.hwyl.sexytopo.model.survey.SurveyConnection)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 ArrayAdapter (android.widget.ArrayAdapter)2 Map (java.util.Map)2 Set (java.util.Set)2 GraphToListTranslator (org.hwyl.sexytopo.control.util.GraphToListTranslator)2 CrossSection (org.hwyl.sexytopo.model.sketch.CrossSection)2 TableCol (org.hwyl.sexytopo.model.table.TableCol)2 JSONArray (org.json.JSONArray)2