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()));
}
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);
}
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;
}
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);
}
}
Aggregations