Search in sources :

Example 1 with Colour

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

the class PocketTopoTxtImporter method parsePolylines.

public static Set<PathDetail> parsePolylines(String text) {
    Set<PathDetail> paths = new HashSet<>();
    boolean inPolyline = false;
    Colour currentPathColour = null;
    PathDetail currentPathDetail = null;
    for (String line : TextTools.toArrayOfLines(text)) {
        if (line.startsWith("POLYLINE")) {
            if (inPolyline) {
                paths.add(currentPathDetail);
                currentPathDetail = null;
            }
            String colourText = line.substring("POLYLINE ".length());
            if (colourText.equals("RED")) {
                colourText = "PURPLE";
            }
            currentPathColour = Colour.valueOf(colourText);
            inPolyline = true;
            continue;
        }
        if (!inPolyline) {
            continue;
        }
        String[] coords = line.split("\t");
        double x = Double.parseDouble(coords[0]);
        double y = Double.parseDouble(coords[1]);
        Coord2D coord = new Coord2D(x, -y);
        if (currentPathDetail == null) {
            currentPathDetail = new PathDetail(coord, currentPathColour);
        } else {
            currentPathDetail.lineTo(coord);
        }
    }
    if (currentPathDetail != null) {
        paths.add(currentPathDetail);
    }
    return paths;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) HashSet(java.util.HashSet) Colour(org.hwyl.sexytopo.model.sketch.Colour)

Example 2 with Colour

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

the class SketchJsonTranslater method toSymbolDetail.

public static SymbolDetail toSymbolDetail(JSONObject json) throws JSONException {
    Colour colour = Colour.valueOf(json.getString(COLOUR_TAG));
    Coord2D location = toCoord2D(json.getJSONObject(POSITION_TAG));
    Symbol symbol = Symbol.valueOf(json.getString(SYMBOL_ID_TAG));
    float size = (float) (json.has(SIZE_TAG) ? json.getDouble(SIZE_TAG) : 1);
    SymbolDetail symbolDetail = new SymbolDetail(location, symbol, colour, size);
    return symbolDetail;
}
Also used : SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) Symbol(org.hwyl.sexytopo.model.sketch.Symbol) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Colour(org.hwyl.sexytopo.model.sketch.Colour)

Example 3 with Colour

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

the class PocketTopoTxtImporter method parsePolylines.

public static List<PathDetail> parsePolylines(String text, Coord2D offset) {
    List<PathDetail> paths = new ArrayList<>();
    boolean inPolyline = false;
    Colour currentPathColour = null;
    PathDetail currentPathDetail = null;
    for (String line : TextTools.toArrayOfLines(text)) {
        if (line.startsWith("POLYLINE")) {
            if (inPolyline) {
                paths.add(currentPathDetail);
                currentPathDetail = null;
            }
            String colourText = line.substring("POLYLINE ".length());
            currentPathColour = interpretColour(colourText);
            inPolyline = true;
            continue;
        }
        if (!inPolyline) {
            continue;
        }
        String[] coords = line.split("\t");
        float x = Float.parseFloat(coords[0]) - offset.x;
        float y = Float.parseFloat(coords[1]) - offset.y;
        Coord2D coord = new Coord2D(x, -y);
        if (currentPathDetail == null) {
            currentPathDetail = new PathDetail(coord, currentPathColour);
        } else {
            currentPathDetail.lineTo(coord);
        }
    }
    if (currentPathDetail != null) {
        paths.add(currentPathDetail);
    }
    return paths;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) BrushColour(org.hwyl.sexytopo.model.sketch.BrushColour) Colour(org.hwyl.sexytopo.model.sketch.Colour)

Example 4 with Colour

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

the class XviImporter method parseSketchEntry.

public static PathDetail parseSketchEntry(double scale, String entry) throws IllegalArgumentException {
    List<String> tokens = Arrays.asList(entry.split(" "));
    if (tokens.size() <= 1) {
        throw new IllegalArgumentException("Incomplete token? {" + entry + "}");
    }
    String first = tokens.get(0);
    if (first.equals("connect")) {
        throw new IllegalArgumentException("Not sure what to do with token {" + entry + "}");
    }
    if (tokens.size() % 2 != 1) {
        throw new IllegalArgumentException("There was an odd number of data points in the token (excluding first item): " + tokens.size());
    }
    Colour colour = Colour.valueOf(first.toUpperCase());
    List<Coord2D> points = new ArrayList<>(tokens.size() - 1);
    for (int i = 1; i < tokens.size(); ) {
        float x = Float.parseFloat(tokens.get(i++));
        float y = Float.parseFloat(tokens.get(i++));
        x /= scale;
        y /= scale;
        Coord2D coord2D = new Coord2D(x, -y);
        points.add(coord2D);
    }
    PathDetail pathDetail = new PathDetail(points.get(0), colour);
    for (Coord2D point : points.subList(1, points.size())) {
        pathDetail.lineTo(point);
    }
    return pathDetail;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Colour(org.hwyl.sexytopo.model.sketch.Colour)

Example 5 with Colour

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

the class GraphView method drawSketch.

private void drawSketch(Canvas canvas, Sketch sketch, int alpha) {
    if (!getDisplayPreference(GraphActivity.DisplayPreference.SHOW_SKETCH)) {
        return;
    }
    Colour lastColour = Colour.BLACK;
    drawPaint.setColor(lastColour.intValue);
    drawPaint.setAlpha(alpha);
    boolean isDebugMode = activity.isDebugMode();
    for (PathDetail pathDetail : sketch.getPathDetails()) {
        if (!couldBeOnScreen(pathDetail)) {
            continue;
        }
        // are unordered collections
        if (pathDetail.getColour() != lastColour) {
            lastColour = pathDetail.getColour();
            drawPaint.setColor(lastColour.intValue);
        }
        List<Coord2D> path = pathDetail.getPath();
        int lineIndex = 0;
        float fromX = -1, fromY = -1;
        float[] lines = new float[path.size() * 4];
        // constructing many thousands of Coord2D objects (approx. 10% of sketch draw time)
        for (Coord2D point : path) {
            if (fromX == -1) {
                // from = surveyCoordsToViewCoords(point);
                fromX = (point.x - viewpointOffset.x) * surveyToViewScale;
                fromY = (point.y - viewpointOffset.y) * surveyToViewScale;
                if (isDebugMode) {
                    canvas.drawCircle(fromX, fromY, 3, drawPaint);
                }
            } else {
                // Coord2D to = surveyCoordsToViewCoords(point);
                float toX = (point.x - viewpointOffset.x) * surveyToViewScale;
                float toY = (point.y - viewpointOffset.y) * surveyToViewScale;
                lines[lineIndex++] = fromX;
                lines[lineIndex++] = fromY;
                lines[lineIndex++] = toX;
                lines[lineIndex++] = toY;
                if (isDebugMode) {
                    canvas.drawCircle(toX, toY, 3, drawPaint);
                }
                fromX = toX;
                fromY = toY;
            }
        }
        canvas.drawLines(lines, drawPaint);
    }
    labelPaint.setAlpha(alpha);
    for (TextDetail textDetail : sketch.getTextDetails()) {
        Coord2D location = surveyCoordsToViewCoords(textDetail.getPosition());
        float x = location.x, y = location.y;
        String text = textDetail.getText();
        labelPaint.setColor(textDetail.getColour().intValue);
        labelPaint.setTextSize(textDetail.getSize() * surveyToViewScale);
        for (String line : text.split("\n")) {
            canvas.drawText(line, x, y, labelPaint);
            y += labelPaint.descent() - labelPaint.ascent();
        }
    }
    for (SymbolDetail symbolDetail : sketch.getSymbolDetails()) {
        if (!couldBeOnScreen(symbolDetail)) {
            continue;
        }
        Coord2D location = surveyCoordsToViewCoords(symbolDetail.getPosition());
        Bitmap bitmap = symbolDetail.getSymbol().getBitmap();
        int size = (int) (symbolDetail.getSize() * surveyToViewScale);
        if (size == 0) {
            continue;
        }
        bitmap = Bitmap.createScaledBitmap(bitmap, size, size, true);
        float x = location.x, y = location.y;
        canvas.drawBitmap(bitmap, x, y, labelPaint);
    }
}
Also used : SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) Bitmap(android.graphics.Bitmap) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Colour(org.hwyl.sexytopo.model.sketch.Colour) BrushColour(org.hwyl.sexytopo.model.sketch.BrushColour)

Aggregations

Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)7 Colour (org.hwyl.sexytopo.model.sketch.Colour)7 PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)5 ArrayList (java.util.ArrayList)3 BrushColour (org.hwyl.sexytopo.model.sketch.BrushColour)2 SymbolDetail (org.hwyl.sexytopo.model.sketch.SymbolDetail)2 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 HashSet (java.util.HashSet)1 Symbol (org.hwyl.sexytopo.model.sketch.Symbol)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1