Search in sources :

Example 51 with Station

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

the class GraphView method drawStations.

private void drawStations(Survey survey, Canvas canvas, Space<Coord2D> space, int baseAlpha) {
    boolean fadingNonActive = getDisplayPreference(GraphActivity.DisplayPreference.FADE_NON_ACTIVE);
    if (fadingNonActive) {
        baseAlpha = FADED_ALPHA;
    }
    int alpha = baseAlpha;
    stationPaint.setAlpha(alpha);
    boolean showStationLabels = getDisplayPreference(GraphActivity.DisplayPreference.SHOW_STATION_LABELS);
    int crossDiameter = PreferenceAccess.getInt(this.getContext(), "pref_station_diameter", CROSS_DIAMETER);
    for (Map.Entry<Station, Coord2D> entry : space.getStationMap().entrySet()) {
        Station station = entry.getKey();
        if (fadingNonActive && (station == survey.getActiveStation())) {
            alpha = SOLID_ALPHA;
            // setting alpha is measured as a relatively expensive call, so we change this as
            // little as possible
            stationPaint.setAlpha(alpha);
        }
        Coord2D translatedStation = surveyCoordsToViewCoords(entry.getValue());
        int x = (int) (translatedStation.x);
        int y = (int) (translatedStation.y);
        drawStationCross(canvas, stationPaint, x, y, crossDiameter, alpha);
        if (station == survey.getActiveStation()) {
            highlightActiveStation(canvas, x, y);
        }
        int spacing = crossDiameter / 2;
        int nextX = x + crossDiameter;
        if (showStationLabels) {
            String name = station.getName();
            if (station == survey.getOrigin()) {
                name = name + " (" + survey.getName() + ")";
            }
            canvas.drawText(name, nextX, y + STATION_LABEL_OFFSET, stationPaint);
            nextX += stationPaint.measureText(name) + spacing;
        }
        List<Bitmap> icons = new ArrayList<>();
        if (station.hasComment()) {
            icons.add(commentIcon);
        }
        if (survey.hasLinkedSurveys(station)) {
            icons.add(linkIcon);
        }
        for (Bitmap icon : icons) {
            int yTop = y - crossDiameter / 2;
            Rect rect = new Rect(nextX, yTop, nextX + crossDiameter, yTop + crossDiameter);
            canvas.drawBitmap(icon, null, rect, stationPaint);
            nextX += crossDiameter + spacing;
        }
        CrossSectionDetail crossSectionDetail = sketch.getCrossSectionDetail(station);
        if (crossSectionDetail != null) {
            drawCrossSectionIndicator(canvas, crossSectionDetail, x, y, alpha);
        }
        if (fadingNonActive && (station == survey.getActiveStation())) {
            alpha = baseAlpha;
            stationPaint.setAlpha(alpha);
        }
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) Map(java.util.Map) HashMap(java.util.HashMap) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 52 with Station

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

the class GraphView method drawCrossSections.

private void drawCrossSections(Canvas canvas, List<CrossSectionDetail> crossSectionDetails, int alpha) {
    boolean showStationLabels = getDisplayPreference(GraphActivity.DisplayPreference.SHOW_STATION_LABELS);
    crossSectionConnectorPaint.setAlpha(alpha);
    List<CrossSectionDetail> badXSections = new ArrayList<>();
    for (CrossSectionDetail sectionDetail : crossSectionDetails) {
        if (!couldBeOnScreen(sectionDetail)) {
            continue;
        }
        CrossSection crossSection = sectionDetail.getCrossSection();
        if (crossSection == null) {
            badXSections.add(sectionDetail);
            continue;
        }
        Station station = crossSection.getStation();
        if (station == null) {
            badXSections.add(sectionDetail);
            continue;
        }
        Coord2D surveyStationLocation = this.projection.getStationMap().get(station);
        if (surveyStationLocation == null) {
            badXSections.add(sectionDetail);
            continue;
        }
        Coord2D centreOnSurvey = sectionDetail.getPosition();
        Coord2D centreOnView = surveyCoordsToViewCoords(centreOnSurvey);
        drawStationCross(canvas, stationPaint, centreOnView.x, centreOnView.y, STATION_DIAMETER, alpha);
        String description = sectionDetail.getCrossSection().getStation().getName() + " X";
        if (showStationLabels) {
            stationPaint.setAlpha(alpha);
            canvas.drawText(description, centreOnView.x, centreOnView.y, stationPaint);
        }
        Space<Coord2D> projection = sectionDetail.getProjection();
        drawLegs(canvas, projection, alpha);
        Coord2D viewStationLocation = surveyCoordsToViewCoords(surveyStationLocation);
        drawDashedLine(canvas, viewStationLocation, centreOnView, DASHED_LINE_INTERVAL, crossSectionConnectorPaint);
    }
    for (CrossSectionDetail crossSectionDetail : badXSections) {
        Station station = crossSectionDetail.getCrossSection().getStation();
        String name = station == null ? "Unknown" : station.getName();
        Log.e("Missing station details for cross section on station " + name + "; removing");
        crossSectionDetails.remove(crossSectionDetail);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) CrossSectionDetail(org.hwyl.sexytopo.model.sketch.CrossSectionDetail) ArrayList(java.util.ArrayList) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection)

Example 53 with Station

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

the class GraphView method handlePositionCrossSection.

private boolean handlePositionCrossSection(MotionEvent event) {
    Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
    Coord2D touchPointOnSurvey = viewCoordsToSurveyCoords(touchPointOnView);
    final Station station = survey.getActiveStation();
    CrossSection crossSection = CrossSectioner.section(survey, station);
    sketch.addCrossSection(crossSection, touchPointOnSurvey);
    setSketchTool(previousSketchTool);
    invalidate();
    return true;
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D) CrossSection(org.hwyl.sexytopo.model.sketch.CrossSection)

Example 54 with Station

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

the class SexyTopoActivity method continueSurvey.

public void continueSurvey(final Station joinPoint) {
    final Survey currentSurvey = getSurvey();
    if (!currentSurvey.isSaved()) {
        showSimpleToast(R.string.cannot_extend_unsaved_survey);
        return;
    }
    final EditText input = new EditText(this);
    String defaultName = Util.getNextAvailableName(this, currentSurvey.getName());
    input.setText(defaultName);
    new AlertDialog.Builder(this).setTitle(getString(R.string.dialog_new_survey_title)).setView(input).setPositiveButton(getString(R.string.ok), (dialog, whichButton) -> {
        Editable value = input.getText();
        String name = value.toString();
        if (Util.isSurveyNameUnique(SexyTopoActivity.this, name)) {
            Survey newSurvey = new Survey(name);
            newSurvey.getOrigin().setName(joinPoint.getName());
            joinSurveys(currentSurvey, joinPoint, newSurvey, newSurvey.getOrigin());
            setSurvey(newSurvey);
        } else {
            showSimpleToast(R.string.dialog_new_survey_name_must_be_unique);
        }
    }).setNegativeButton(getString(R.string.cancel), (dialog, whichButton) -> {
    /* Do nothing. */
    }).show();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) Arrays(java.util.Arrays) Bundle(android.os.Bundle) Communicator(org.hwyl.sexytopo.comms.Communicator) PackageManager(android.content.pm.PackageManager) TestSurveyCreator(org.hwyl.sexytopo.demo.TestSurveyCreator) R(org.hwyl.sexytopo.R) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) InputMode(org.hwyl.sexytopo.control.util.InputMode) Manifest(android.Manifest) Exporter(org.hwyl.sexytopo.control.io.translation.Exporter) SexyTopo(org.hwyl.sexytopo.SexyTopo) Map(java.util.Map) ActivityInfo(android.content.pm.ActivityInfo) View(android.view.View) PreferenceManager(android.preference.PreferenceManager) Method(java.lang.reflect.Method) ContextCompat(androidx.core.content.ContextCompat) AsyncTask(android.os.AsyncTask) Set(java.util.Set) SubMenu(android.view.SubMenu) AlertDialog(android.app.AlertDialog) List(java.util.List) SurveyManager(org.hwyl.sexytopo.control.SurveyManager) Saver(org.hwyl.sexytopo.control.io.basic.Saver) Context(android.content.Context) NullCommunicator(org.hwyl.sexytopo.comms.missing.NullCommunicator) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) Instrument(org.hwyl.sexytopo.comms.Instrument) Intent(android.content.Intent) HashMap(java.util.HashMap) Station(org.hwyl.sexytopo.model.survey.Station) PackageInfo(android.content.pm.PackageInfo) Editable(android.text.Editable) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) Toast(android.widget.Toast) Menu(android.view.Menu) SelectableExporters(org.hwyl.sexytopo.control.io.translation.SelectableExporters) Build(android.os.Build) Survey(org.hwyl.sexytopo.model.survey.Survey) ActivityCompat(androidx.core.app.ActivityCompat) Log(org.hwyl.sexytopo.control.Log) FirebaseCrashlytics(com.google.firebase.crashlytics.FirebaseCrashlytics) Loader(org.hwyl.sexytopo.control.io.basic.Loader) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) SharedPreferences(android.content.SharedPreferences) ImportManager(org.hwyl.sexytopo.control.io.translation.ImportManager) Util(org.hwyl.sexytopo.control.io.Util) EditText(android.widget.EditText) Survey(org.hwyl.sexytopo.model.survey.Survey) Editable(android.text.Editable)

Example 55 with Station

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

the class OldStyleLoader method parse.

public static void parse(String text, Survey survey) throws Exception {
    Map<String, Station> nameToStation = new HashMap<>();
    Station origin = survey.getOrigin();
    nameToStation.put(origin.getName(), origin);
    String[] lines = text.split("\n");
    for (String line : lines) {
        line = line.trim();
        if (line.equals("") || line.startsWith("*")) {
            continue;
        }
        String comment = "";
        if (line.contains("; ")) {
            comment = line.substring(line.indexOf("; ") + 2);
            comment = comment.replaceAll("\\\\n", "\n");
            line = line.substring(0, line.indexOf("; "));
        }
        String[] fields = line.trim().split("\t");
        addLegToSurvey(survey, nameToStation, fields, comment);
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) HashMap(java.util.HashMap)

Aggregations

Station (org.hwyl.sexytopo.model.survey.Station)85 Leg (org.hwyl.sexytopo.model.survey.Leg)32 Survey (org.hwyl.sexytopo.model.survey.Survey)30 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)20 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 SuppressLint (android.annotation.SuppressLint)8 AlertDialog (android.app.AlertDialog)8 JSONException (org.json.JSONException)7 Line (org.hwyl.sexytopo.model.graph.Line)6 SurveyConnection (org.hwyl.sexytopo.model.survey.SurveyConnection)6 JSONObject (org.json.JSONObject)6 View (android.view.View)5 Set (java.util.Set)5 Direction (org.hwyl.sexytopo.model.graph.Direction)5 Space (org.hwyl.sexytopo.model.graph.Space)5 JSONArray (org.json.JSONArray)5 Context (android.content.Context)4 HashSet (java.util.HashSet)4