Search in sources :

Example 1 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D 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 2 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.

the class GraphView method handleDraw.

private boolean handleDraw(MotionEvent event) {
    Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
    Coord2D surveyCoords = viewCoordsToSurveyCoords(touchPointOnView);
    boolean snapToLines = getDisplayPreference(GraphActivity.DisplayPreference.SNAP_TO_LINES);
    switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            actionDownPointOnView = touchPointOnView;
            Coord2D start = surveyCoords;
            if (snapToLines) {
                Coord2D snappedStart = considerSnapToSketchLine(start);
                if (snappedStart != null) {
                    start = snappedStart;
                }
            }
            sketch.startNewPath(start);
            break;
        case MotionEvent.ACTION_MOVE:
            sketch.getActivePath().lineTo(surveyCoords);
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            if (touchPointOnView.equals(actionDownPointOnView)) {
                // handle dots
                sketch.getActivePath().lineTo(surveyCoords);
            } else if (snapToLines) {
                Coord2D snappedEnd = considerSnapToSketchLine(surveyCoords);
                if (snappedEnd != null) {
                    sketch.getActivePath().lineTo(snappedEnd);
                    invalidate();
                }
            }
            sketch.finishPath();
            break;
        default:
            return false;
    }
    return true;
}
Also used : Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 3 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.

the class GraphView method considerSnapToSketchLine.

private Coord2D considerSnapToSketchLine(Coord2D pointTouched) {
    double deltaInMetres = SNAP_TO_LINE_SENSITIVITY_IN_PIXELS / surveyToViewScale;
    Coord2D closestPathEnd = sketch.findEligibleSnapPointWithin(pointTouched, deltaInMetres);
    if (closestPathEnd != null) {
        return closestPathEnd;
    } else {
        return null;
    }
}
Also used : Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 4 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D 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)

Example 5 with Coord2D

use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.

the class GraphView method handleText.

private boolean handleText(MotionEvent event) {
    final Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
    final Coord2D touchPointOnSurvey = viewCoordsToSurveyCoords(touchPointOnView);
    switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            final EditText input = new EditText(getContext());
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setView(input).setPositiveButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    sketch.addTextDetail(touchPointOnSurvey, input.getText().toString());
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // do nothing
                }
            });
            AlertDialog dialog = builder.create();
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            dialog.show();
            return true;
        default:
            return false;
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Paint(android.graphics.Paint)

Aggregations

Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)40 Station (org.hwyl.sexytopo.model.survey.Station)10 Space (org.hwyl.sexytopo.model.graph.Space)8 Line (org.hwyl.sexytopo.model.graph.Line)6 PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)6 Survey (org.hwyl.sexytopo.model.survey.Survey)6 Test (org.junit.Test)6 Leg (org.hwyl.sexytopo.model.survey.Leg)5 Colour (org.hwyl.sexytopo.model.sketch.Colour)4 ArrayList (java.util.ArrayList)3 GraphActivity (org.hwyl.sexytopo.control.activity.GraphActivity)3 PlanActivity (org.hwyl.sexytopo.control.activity.PlanActivity)3 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)3 Paint (android.graphics.Paint)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 CrossSection (org.hwyl.sexytopo.model.sketch.CrossSection)2 CrossSectionDetail (org.hwyl.sexytopo.model.sketch.CrossSectionDetail)2 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)2 JSONArray (org.json.JSONArray)2