Search in sources :

Example 31 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class SurveyJsonTranslater method toJson.

public static JSONObject toJson(Station station, List<Leg> chronoList) throws JSONException {
    JSONObject json = new JSONObject();
    json.put(STATION_NAME_TAG, station.getName());
    json.put(DIRECTION_TAG, station.getExtendedElevationDirection().toString().toLowerCase());
    json.put(COMMENT_TAG, station.getComment());
    JSONArray onwardLegsArray = new JSONArray();
    for (Leg leg : station.getOnwardLegs()) {
        int index = chronoList.indexOf(leg);
        onwardLegsArray.put(toJson(leg, index));
    }
    json.put(ONWARD_LEGS_TAG, onwardLegsArray);
    return json;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 32 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class ManualEntry method editLeg.

public static void editLeg(final TableActivity tableActivity, final Survey survey, final Leg toEdit) {
    AlertDialog dialog = createDialog(R.layout.leg_edit_dialog, tableActivity, (edited, ignore) -> {
        if (toEdit.hasDestination()) {
            edited = new Leg(edited.getDistance(), edited.getAzimuth(), edited.getInclination(), toEdit.getDestination(), new Leg[] {});
        }
        if (toEdit.wasShotBackwards()) {
            edited = edited.reverse();
        }
        SurveyUpdater.editLeg(survey, toEdit, edited);
        tableActivity.getSurveyManager().broadcastSurveyUpdated();
        tableActivity.syncTableWithSurvey();
    });
    dialog.setTitle(R.string.manual_edit_leg_title);
    Leg editData = toEdit.wasShotBackwards() ? toEdit.reverse() : toEdit;
    ((TextView) (dialog.findViewById(R.id.editDistance))).setText(Float.toString(editData.getDistance()));
    ((TextView) (dialog.findViewById(R.id.editAzimuth))).setText(Float.toString(editData.getAzimuth()));
    ((TextView) (dialog.findViewById(R.id.editInclination))).setText(Float.toString(editData.getInclination()));
}
Also used : AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 33 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class ManualEntry method createDialog.

private static AlertDialog createDialog(int layoutId, final TableActivity tableActivity, final EditCallback editCallback) {
    AlertDialog.Builder builder = new AlertDialog.Builder(tableActivity);
    LayoutInflater inflater = tableActivity.getLayoutInflater();
    final View dialogView = inflater.inflate(layoutId, null);
    if (tableActivity.getBooleanPreference("pref_key_deg_mins_secs")) {
        dialogView.findViewById(R.id.azimuth_standard).setVisibility(View.GONE);
        dialogView.findViewById(R.id.azimuth_deg_mins_secs).setVisibility(View.VISIBLE);
    }
    builder.setView(dialogView).setTitle(R.string.manual_add_station_title).setPositiveButton("Save", (dialog, buttonId) -> {
    /* Do nothing */
    }).setNegativeButton("Cancel", (dialog, buttonId) -> {
    /* Do nothing */
    });
    final AlertDialog dialog = builder.create();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    dialog.show();
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Save", (dialogInterface, buttonId) -> {
        Float distance = getFieldValue(dialog, R.id.editDistance);
        Float inclination = getFieldValue(dialog, R.id.editInclination);
        Float azimuth;
        if (tableActivity.getBooleanPreference("pref_key_deg_mins_secs")) {
            Float degrees = getFieldValue(dialog, R.id.editAzimuthDegrees);
            Float minutes = getFieldValue(dialog, R.id.editAzimuthMinutes);
            Float seconds = getFieldValue(dialog, R.id.editAzimuthSeconds);
            if (degrees == null || minutes == null || seconds == null) {
                azimuth = null;
            } else {
                azimuth = degrees + (minutes * (1.0f / 60.0f)) + (seconds * (1.0f / 60.0f) * (1.0f / 60.0f));
            }
        } else {
            azimuth = getFieldValue(dialog, R.id.editAzimuth);
        }
        if (distance == null || !Leg.isDistanceLegal(distance)) {
            TextView editDistance = dialogView.findViewById(R.id.editDistance);
            editDistance.setError("Bad distance");
            tableActivity.showSimpleToast("Bad distance");
        } else if (azimuth == null || !Leg.isAzimuthLegal(azimuth)) {
            TextView editAzimuth = dialogView.findViewById(R.id.editAzimuth);
            tableActivity.showSimpleToast("Bad azimuth");
            editAzimuth.setError("Bad azimuth");
        } else if (inclination == null || !Leg.isInclinationLegal(inclination)) {
            TextView editInclination = dialogView.findViewById(R.id.editInclination);
            editInclination.setError("Bad inclination");
            tableActivity.showSimpleToast("Bad inclination " + inclination);
        } else {
            dialogInterface.dismiss();
            Leg leg = new Leg(distance, azimuth, inclination);
            editCallback.submit(leg, dialog);
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) Leg(org.hwyl.sexytopo.model.survey.Leg) Survey(org.hwyl.sexytopo.model.survey.Survey) LayoutInflater(android.view.LayoutInflater) TableActivity(org.hwyl.sexytopo.control.activity.TableActivity) WindowManager(android.view.WindowManager) Dialog(android.app.Dialog) R(org.hwyl.sexytopo.R) Station(org.hwyl.sexytopo.model.survey.Station) Editable(android.text.Editable) AlertDialog(android.app.AlertDialog) LRUD(org.hwyl.sexytopo.model.table.LRUD) TextView(android.widget.TextView) SurveyUpdater(org.hwyl.sexytopo.control.util.SurveyUpdater) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) View(android.view.View) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) TextWatcher(android.text.TextWatcher) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 34 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class Space3DTransformerForElevation method updateLeg.

protected void updateLeg(Space<Coord3D> space, Leg leg, Coord3D start) {
    Leg adjustedLeg;
    if (leg.getDestination().getExtendedElevationDirection() == Direction.LEFT) {
        adjustedLeg = leg.adjustAzimuth(180);
    } else {
        adjustedLeg = leg.adjustAzimuth(0);
    }
    float delta = adjustedLeg.getAzimuth() - leg.getAzimuth();
    Coord3D end = Space3DUtils.toCartesian(start, adjustedLeg);
    Line<Coord3D> line = new Line<>(start, end);
    space.addLeg(leg, line);
    if (leg.hasDestination()) {
        update(space, leg.getDestination(), end, delta);
    }
}
Also used : Line(org.hwyl.sexytopo.model.graph.Line) Coord3D(org.hwyl.sexytopo.model.graph.Coord3D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 35 with Leg

use of org.hwyl.sexytopo.model.survey.Leg in project sexytopo by richsmith.

the class Space3DTransformerForElevation method updateSplay.

protected void updateSplay(Space<Coord3D> space, Leg leg, Coord3D start, float rotation) {
    Leg adjustedLeg = leg.rotate(rotation);
    Coord3D end = Space3DUtils.toCartesian(start, adjustedLeg);
    Line<Coord3D> line = new Line<>(start, end);
    space.addLeg(leg, line);
}
Also used : Line(org.hwyl.sexytopo.model.graph.Line) Coord3D(org.hwyl.sexytopo.model.graph.Coord3D) Leg(org.hwyl.sexytopo.model.survey.Leg)

Aggregations

Leg (org.hwyl.sexytopo.model.survey.Leg)94 Station (org.hwyl.sexytopo.model.survey.Station)30 Test (org.junit.Test)30 Survey (org.hwyl.sexytopo.model.survey.Survey)23 Coord3D (org.hwyl.sexytopo.model.graph.Coord3D)17 Line (org.hwyl.sexytopo.model.graph.Line)8 ArrayList (java.util.ArrayList)7 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)7 JSONArray (org.json.JSONArray)6 JSONObject (org.json.JSONObject)6 Space (org.hwyl.sexytopo.model.graph.Space)4 TextView (android.widget.TextView)3 GraphToListTranslator (org.hwyl.sexytopo.control.util.GraphToListTranslator)3 TableCol (org.hwyl.sexytopo.model.table.TableCol)3 JSONException (org.json.JSONException)3 AlertDialog (android.app.AlertDialog)2 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2 LRUD (org.hwyl.sexytopo.model.table.LRUD)2 SuppressLint (android.annotation.SuppressLint)1