Search in sources :

Example 1 with CrossSectionDetail

use of org.hwyl.sexytopo.model.sketch.CrossSectionDetail in project sexytopo by richsmith.

the class GraphView method drawCrossSections.

private void drawCrossSections(Canvas canvas, Set<CrossSectionDetail> crossSectionDetails, int alpha) {
    for (CrossSectionDetail sectionDetail : crossSectionDetails) {
        Coord2D centreOnSurvey = sectionDetail.getPosition();
        Coord2D centreOnView = surveyCoordsToViewCoords(centreOnSurvey);
        drawStationCross(canvas, stationPaint, (float) centreOnView.getX(), (float) centreOnView.getY(), STATION_DIAMETER, alpha);
        String description = sectionDetail.getCrossSection().getStation().getName() + " X-section";
        if (getDisplayPreference(GraphActivity.DisplayPreference.SHOW_STATION_LABELS)) {
            stationPaint.setAlpha(alpha);
            canvas.drawText(description, (float) centreOnView.getX(), (float) centreOnView.getY(), stationPaint);
        }
        Space<Coord2D> projection = sectionDetail.getProjection();
        drawLegs(canvas, projection, alpha);
    }
}
Also used : CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 2 with CrossSectionDetail

use of org.hwyl.sexytopo.model.sketch.CrossSectionDetail in project sexytopo by richsmith.

the class GraphView method drawStations.

private void drawStations(Survey survey, Canvas canvas, Space<Coord2D> space, int baseAlpha) {
    boolean fadingNonActive = getDisplayPreference(GraphActivity.DisplayPreference.FADE_NON_ACTIVE);
    if (fadingNonActive) {
        baseAlpha = FADED_ALPHA;
    }
    int alpha = baseAlpha;
    stationPaint.setAlpha(alpha);
    boolean showStationLabels = getDisplayPreference(GraphActivity.DisplayPreference.SHOW_STATION_LABELS);
    int crossDiameter = PreferenceAccess.getInt(this.getContext(), "pref_station_diameter", CROSS_DIAMETER);
    for (Map.Entry<Station, Coord2D> entry : space.getStationMap().entrySet()) {
        Station station = entry.getKey();
        if (fadingNonActive && (station == survey.getActiveStation())) {
            alpha = SOLID_ALPHA;
            // setting alpha is measured as a relatively expensive call, so we change this as
            // little as possible
            stationPaint.setAlpha(alpha);
        }
        Coord2D translatedStation = surveyCoordsToViewCoords(entry.getValue());
        int x = (int) (translatedStation.x);
        int y = (int) (translatedStation.y);
        drawStationCross(canvas, stationPaint, x, y, crossDiameter, alpha);
        if (station == survey.getActiveStation()) {
            highlightActiveStation(canvas, x, y);
        }
        int spacing = crossDiameter / 2;
        int nextX = x + crossDiameter;
        if (showStationLabels) {
            String name = station.getName();
            if (station == survey.getOrigin()) {
                name = name + " (" + survey.getName() + ")";
            }
            canvas.drawText(name, nextX, y + STATION_LABEL_OFFSET, stationPaint);
            nextX += stationPaint.measureText(name) + spacing;
        }
        List<Bitmap> icons = new ArrayList<>();
        if (station.hasComment()) {
            icons.add(commentIcon);
        }
        if (survey.hasLinkedSurveys(station)) {
            icons.add(linkIcon);
        }
        for (Bitmap icon : icons) {
            int yTop = y - crossDiameter / 2;
            Rect rect = new Rect(nextX, yTop, nextX + crossDiameter, yTop + crossDiameter);
            canvas.drawBitmap(icon, null, rect, stationPaint);
            nextX += crossDiameter + spacing;
        }
        CrossSectionDetail crossSectionDetail = sketch.getCrossSectionDetail(station);
        if (crossSectionDetail != null) {
            drawCrossSectionIndicator(canvas, crossSectionDetail, x, y, alpha);
        }
        if (fadingNonActive && (station == survey.getActiveStation())) {
            alpha = baseAlpha;
            stationPaint.setAlpha(alpha);
        }
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Map(java.util.Map) HashMap(java.util.HashMap) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 3 with CrossSectionDetail

use of org.hwyl.sexytopo.model.sketch.CrossSectionDetail in project sexytopo by richsmith.

the class GraphView method drawCrossSections.

private void drawCrossSections(Canvas canvas, List<CrossSectionDetail> crossSectionDetails, int alpha) {
    boolean showStationLabels = getDisplayPreference(GraphActivity.DisplayPreference.SHOW_STATION_LABELS);
    crossSectionConnectorPaint.setAlpha(alpha);
    List<CrossSectionDetail> badXSections = new ArrayList<>();
    for (CrossSectionDetail sectionDetail : crossSectionDetails) {
        if (!couldBeOnScreen(sectionDetail)) {
            continue;
        }
        CrossSection crossSection = sectionDetail.getCrossSection();
        if (crossSection == null) {
            badXSections.add(sectionDetail);
            continue;
        }
        Station station = crossSection.getStation();
        if (station == null) {
            badXSections.add(sectionDetail);
            continue;
        }
        Coord2D surveyStationLocation = this.projection.getStationMap().get(station);
        if (surveyStationLocation == null) {
            badXSections.add(sectionDetail);
            continue;
        }
        Coord2D centreOnSurvey = sectionDetail.getPosition();
        Coord2D centreOnView = surveyCoordsToViewCoords(centreOnSurvey);
        drawStationCross(canvas, stationPaint, centreOnView.x, centreOnView.y, STATION_DIAMETER, alpha);
        String description = sectionDetail.getCrossSection().getStation().getName() + " X";
        if (showStationLabels) {
            stationPaint.setAlpha(alpha);
            canvas.drawText(description, centreOnView.x, centreOnView.y, stationPaint);
        }
        Space<Coord2D> projection = sectionDetail.getProjection();
        drawLegs(canvas, projection, alpha);
        Coord2D viewStationLocation = surveyCoordsToViewCoords(surveyStationLocation);
        drawDashedLine(canvas, viewStationLocation, centreOnView, DASHED_LINE_INTERVAL, crossSectionConnectorPaint);
    }
    for (CrossSectionDetail crossSectionDetail : badXSections) {
        Station station = crossSectionDetail.getCrossSection().getStation();
        String name = station == null ? "Unknown" : station.getName();
        Log.e("Missing station details for cross section on station " + name + "; removing");
        crossSectionDetails.remove(crossSectionDetail);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection)

Example 4 with CrossSectionDetail

use of org.hwyl.sexytopo.model.sketch.CrossSectionDetail in project sexytopo by richsmith.

the class SketchJsonTranslater method toCrossSectionDetail.

public static CrossSectionDetail toCrossSectionDetail(Survey survey, JSONObject json) throws JSONException {
    Coord2D position = toCoord2D(json.getJSONObject(POSITION_TAG));
    float angle = (float) json.getDouble(ANGLE_TAG);
    String stationdId = json.getString(STATION_ID_TAG);
    Station station = survey.getStationByName(stationdId);
    CrossSectionDetail crossSectionDetail = new CrossSectionDetail(new CrossSection(station, angle), position);
    return crossSectionDetail;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection)

Example 5 with CrossSectionDetail

use of org.hwyl.sexytopo.model.sketch.CrossSectionDetail in project sexytopo by richsmith.

the class SketchJsonTranslater method toSketch.

public static Sketch toSketch(Survey survey, JSONObject json) {
    Sketch sketch = new Sketch();
    try {
        JSONArray pathsArray = json.getJSONArray(PATHS_TAG);
        List<PathDetail> pathDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(pathsArray)) {
            pathDetails.add(toPathDetail(object));
        }
        sketch.setPathDetails(pathDetails);
    } catch (JSONException e) {
        Log.e("Failed to load sketch paths: " + e);
    }
    try {
        JSONArray symbolsArray = json.getJSONArray(SYMBOLS_TAG);
        List<SymbolDetail> symbolDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(symbolsArray)) {
            symbolDetails.add(toSymbolDetail(object));
        }
        sketch.setSymbolDetails(symbolDetails);
    } catch (JSONException e) {
        Log.e("Failed to load symbols: " + e);
    }
    try {
        JSONArray labelsArray = json.getJSONArray(LABELS_TAG);
        List<TextDetail> textDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(labelsArray)) {
            textDetails.add(toTextDetail(object));
        }
        sketch.setTextDetails(textDetails);
    } catch (JSONException e) {
        Log.e("Failed to load sketch labels: " + e);
    }
    try {
        JSONArray crossSectionsArray = json.getJSONArray(CROSS_SECTIONS_TAG);
        List<CrossSectionDetail> crossSectionDetails = new ArrayList<>();
        for (JSONObject object : Util.toList(crossSectionsArray)) {
            crossSectionDetails.add(toCrossSectionDetail(survey, object));
        }
        sketch.setCrossSectionDetails(crossSectionDetails);
    } catch (JSONException e) {
        Log.e("Failed to load cross-sections: " + e);
    }
    return sketch;
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) JSONException(org.json.JSONException) SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) JSONObject(org.json.JSONObject) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail)

Aggregations

CrossSectionDetail (org.hwyl.sexytopo.model.sketch.CrossSectionDetail)6 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)4 ArrayList (java.util.ArrayList)3 Station (org.hwyl.sexytopo.model.survey.Station)3 CrossSection (org.hwyl.sexytopo.model.sketch.CrossSection)2 PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)2 SymbolDetail (org.hwyl.sexytopo.model.sketch.SymbolDetail)2 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)1 JSONException (org.json.JSONException)1