Search in sources :

Example 1 with Direction

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

the class GraphView method showContextMenu.

private void showContextMenu(MotionEvent event, final Station station) {
    OnClickListener listener = view -> {
        int id = view.getId();
        // because IDs are no longer final
        if (id == R.id.graph_station_select) {
            setActiveStation(station);
            invalidate();
        } else if (id == R.id.graph_station_toggle_left_right) {
            Direction newDirection = station.getExtendedElevationDirection().opposite();
            SurveyUpdater.setDirectionOfSubtree(station, newDirection);
            broadcastSurveyUpdated();
            invalidate();
        } else if (id == R.id.graph_station_comment) {
            openCommentDialog(station);
        } else if (id == R.id.graph_station_reverse) {
            SurveyUpdater.reverseLeg(survey, station);
            broadcastSurveyUpdated();
            invalidate();
        } else if (id == R.id.graph_station_delete) {
            askAboutDeletingStation(station);
            invalidate();
        } else if (id == R.id.graph_station_new_cross_section) {
            setActiveStation(station);
            setSketchTool(SketchTool.POSITION_CROSS_SECTION);
            activity.showSimpleToast(R.string.position_cross_section_instruction);
        } else if (id == R.id.graph_station_jump_to_table) {
            activity.jumpToStation(station, TableActivity.class);
        } else if (id == R.id.graph_station_jump_to_plan) {
            activity.jumpToStation(station, PlanActivity.class);
        } else if (id == R.id.graph_station_jump_to_ee) {
            activity.jumpToStation(station, ExtendedElevationActivity.class);
        } else if (id == R.id.graph_station_start_new_survey) {
            if (!survey.isSaved()) {
                activity.showSimpleToast(R.string.cannot_extend_unsaved_survey);
            }
            activity.continueSurvey(station);
        } else if (id == R.id.graph_station_unlink_survey) {
            activity.unlinkSurvey(station);
        }
    };
    PopupWindow menu = activity.getContextMenu(station, listener);
    View unlinkSurveyButton = menu.getContentView().findViewById(R.id.graph_station_unlink_survey);
    unlinkSurveyButton.setEnabled(survey.hasLinkedSurveys(station));
    View commentButton = menu.getContentView().findViewById(R.id.graph_station_comment);
    commentButton.setEnabled(station != survey.getOrigin());
    menu.showAtLocation(this, Gravity.START | Gravity.TOP, (int) (event.getX()), (int) (event.getY()));
}
Also used : Rect(android.graphics.Rect) WindowManager(android.view.WindowManager) R(org.hwyl.sexytopo.R) Colour(org.hwyl.sexytopo.model.sketch.Colour) GraphActivity(org.hwyl.sexytopo.control.activity.GraphActivity) AttributeSet(android.util.AttributeSet) Map(java.util.Map) View(android.view.View) Canvas(android.graphics.Canvas) SketchDetail(org.hwyl.sexytopo.model.sketch.SketchDetail) SymbolDetail(org.hwyl.sexytopo.model.sketch.SymbolDetail) Projection2D(org.hwyl.sexytopo.model.graph.Projection2D) TextTools(org.hwyl.sexytopo.control.util.TextTools) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) Set(java.util.Set) SketchTool(org.hwyl.sexytopo.model.sketch.SketchTool) ScaleGestureDetector(android.view.ScaleGestureDetector) Direction(org.hwyl.sexytopo.model.graph.Direction) AlertDialog(android.app.AlertDialog) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) List(java.util.List) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) CrossSectioner(org.hwyl.sexytopo.control.util.CrossSectioner) Symbol(org.hwyl.sexytopo.model.sketch.Symbol) Paint(android.graphics.Paint) Context(android.content.Context) Path(android.graphics.Path) GestureDetector(android.view.GestureDetector) PlanActivity(org.hwyl.sexytopo.control.activity.PlanActivity) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) BitmapFactory(android.graphics.BitmapFactory) HashMap(java.util.HashMap) Station(org.hwyl.sexytopo.model.survey.Station) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) MotionEvent(android.view.MotionEvent) Line(org.hwyl.sexytopo.model.graph.Line) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) PreferenceAccess(org.hwyl.sexytopo.control.util.PreferenceAccess) Space2DUtils(org.hwyl.sexytopo.control.util.Space2DUtils) PopupWindow(android.widget.PopupWindow) Log(org.hwyl.sexytopo.control.Log) BrushColour(org.hwyl.sexytopo.model.sketch.BrushColour) ExtendedElevationActivity(org.hwyl.sexytopo.control.activity.ExtendedElevationActivity) SurveyStats(org.hwyl.sexytopo.control.util.SurveyStats) Space(org.hwyl.sexytopo.model.graph.Space) TextDetail(org.hwyl.sexytopo.model.sketch.TextDetail) Gravity(android.view.Gravity) PathDetail(org.hwyl.sexytopo.model.sketch.PathDetail) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) SharedPreferences(android.content.SharedPreferences) CohenSutherlandAlgorithm(org.hwyl.sexytopo.control.util.CohenSutherlandAlgorithm) Bitmap(android.graphics.Bitmap) EditText(android.widget.EditText) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) PopupWindow(android.widget.PopupWindow) ExtendedElevationActivity(org.hwyl.sexytopo.control.activity.ExtendedElevationActivity) Direction(org.hwyl.sexytopo.model.graph.Direction) View(android.view.View)

Example 2 with Direction

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

the class TherionImporterTest method testElevationDirectionExtraction.

@Test
public void testElevationDirectionExtraction() throws Exception {
    Survey survey = new Survey("Test");
    TherionImporter.updateCentreline(LINES, survey);
    Station stationTwo = survey.getStationByName("2");
    Direction stationTwoDirection = stationTwo.getExtendedElevationDirection();
    Assert.assertEquals(Direction.LEFT, stationTwoDirection);
    Station stationThree = survey.getStationByName("3");
    Direction stationThreeDirection = stationThree.getExtendedElevationDirection();
    Assert.assertEquals(Direction.LEFT, stationThreeDirection);
    Station stationFive = survey.getStationByName("5");
    Direction stationFiveDirection = stationFive.getExtendedElevationDirection();
    Assert.assertEquals(Direction.RIGHT, stationFiveDirection);
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) Direction(org.hwyl.sexytopo.model.graph.Direction) Test(org.junit.Test)

Example 3 with Direction

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

the class SurveyJsonTranslater method toStation.

public static Station toStation(JSONObject json) throws JSONException {
    String name = json.getString(STATION_NAME_TAG);
    Station station = new Station(name);
    try {
        String comment = json.getString(COMMENT_TAG);
        station.setComment(comment);
    } catch (Exception ignore) {
    // not ideal but not the end of the world; we'd probably prefer to have our data
    }
    try {
        Direction direction = Direction.valueOf(json.getString(DIRECTION_TAG).toUpperCase());
        station.setExtendedElevationDirection(direction);
    } catch (Exception ignore) {
    // not ideal but not the end of the world; we'd probably prefer to have our data
    }
    return station;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Direction(org.hwyl.sexytopo.model.graph.Direction) JSONException(org.json.JSONException) ParseException(java.text.ParseException)

Example 4 with Direction

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

the class TherionImporter method handleElevationDirectionData.

private static void handleElevationDirectionData(List<String> lines, Survey survey) {
    try {
        for (String line : lines) {
            final String EXTEND_PREFIX = "extend ";
            assert line.startsWith(EXTEND_PREFIX);
            String rest = line.substring(EXTEND_PREFIX.length());
            String[] tokens = rest.split(" ");
            assert tokens.length == 2;
            String directionName = tokens[0];
            if (directionName.equals("start")) {
                continue;
            }
            Direction direction = Direction.valueOf(directionName.toUpperCase());
            String stationName = tokens[1];
            Station station = survey.getStationByName(stationName);
            SurveyUpdater.setDirectionOfSubtree(station, direction);
        }
    } catch (Exception exception) {
        Log.e("corrupted survey extended elevation directions: " + exception);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Direction(org.hwyl.sexytopo.model.graph.Direction)

Aggregations

Direction (org.hwyl.sexytopo.model.graph.Direction)4 Station (org.hwyl.sexytopo.model.survey.Station)4 Survey (org.hwyl.sexytopo.model.survey.Survey)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 Path (android.graphics.Path)1 Rect (android.graphics.Rect)1 AttributeSet (android.util.AttributeSet)1 GestureDetector (android.view.GestureDetector)1 Gravity (android.view.Gravity)1 MotionEvent (android.view.MotionEvent)1 ScaleGestureDetector (android.view.ScaleGestureDetector)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1