Search in sources :

Example 1 with PathDetail

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

the class PocketTopoTxtImporter method parseSketch.

private static Sketch parseSketch(String text) {
    Sketch sketch = new Sketch();
    Set<PathDetail> pathDetails = parsePolylines(text);
    sketch.setPathDetails(pathDetails);
    return sketch;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch)

Example 2 with PathDetail

use of org.hwyl.sexytopo.model.sketch.PathDetail 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 3 with PathDetail

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

the class GraphView method handleErase.

private boolean handleErase(MotionEvent event) {
    Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
    Coord2D touchPointOnSurvey = viewCoordsToSurveyCoords(touchPointOnView);
    boolean deleteLineFragments = PreferenceAccess.getBoolean(getContext(), "pref_delete_path_fragments", true);
    switch(event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            SketchDetail closestDetail = sketch.findNearestDetailWithin(touchPointOnSurvey, DELETE_PATHS_WITHIN_N_PIXELS);
            // you missed, try again :P
            if (closestDetail == null) {
                return true;
            // you got part of the line
            } else if (deleteLineFragments && closestDetail instanceof PathDetail) {
                List<SketchDetail> fragments = ((PathDetail) closestDetail).getPathFragmentsOutsideRadius(touchPointOnSurvey, DELETE_PATHS_WITHIN_N_PIXELS / 4);
                sketch.deleteDetail(closestDetail, fragments);
                invalidate();
            // bullseye!
            } else {
                sketch.deleteDetail(closestDetail);
                invalidate();
            }
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
            break;
        default:
            return false;
    }
    return true;
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) List(java.util.List) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) SketchDetail(org.hwyl.sexytopo.model.sketch.SketchDetail)

Example 4 with PathDetail

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

the class PocketTopoTxtImporterTest method testParsePolylines.

@Test
public void testParsePolylines() {
    String section = PocketTopoTxtImporter.getSection(FAKE_TEXT, "PLAN");
    List<PathDetail> paths = PocketTopoTxtImporter.parsePolylines(section, Coord2D.ORIGIN);
    PathDetail brownPath = null;
    for (PathDetail path : paths) {
        if (path.getColour() == Colour.BROWN) {
            brownPath = path;
        }
    }
    Assert.assertEquals(4.980, brownPath.getPath().get(0).x, 0.01);
    Assert.assertEquals(55.180, brownPath.getPath().get(0).y, 0.01);
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Test(org.junit.Test)

Example 5 with PathDetail

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

the class XviImporterTest method testParseSketchEntryParsesFirstEntry.

@Test
public void testParseSketchEntryParsesFirstEntry() throws Exception {
    String simpleText = "red 0 0";
    PathDetail pathDetail = XviImporter.parseSketchEntry(1, simpleText);
    Assert.assertEquals(Coord2D.ORIGIN, pathDetail.getPath().get(0));
    Assert.assertEquals(1, pathDetail.getPath().size());
}
Also used : PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Test(org.junit.Test)

Aggregations

PathDetail (org.hwyl.sexytopo.model.sketch.PathDetail)19 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Colour (org.hwyl.sexytopo.model.sketch.Colour)5 Sketch (org.hwyl.sexytopo.model.sketch.Sketch)5 SymbolDetail (org.hwyl.sexytopo.model.sketch.SymbolDetail)3 TextDetail (org.hwyl.sexytopo.model.sketch.TextDetail)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 BrushColour (org.hwyl.sexytopo.model.sketch.BrushColour)2 CrossSectionDetail (org.hwyl.sexytopo.model.sketch.CrossSectionDetail)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 HashSet (java.util.HashSet)1 List (java.util.List)1 GraphActivity (org.hwyl.sexytopo.control.activity.GraphActivity)1 PlanActivity (org.hwyl.sexytopo.control.activity.PlanActivity)1 Space (org.hwyl.sexytopo.model.graph.Space)1