Search in sources :

Example 11 with Station

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

the class ConnectedSurveys method updateTranslatedConnectedSurveys.

private static void updateTranslatedConnectedSurveys(GraphActivity activity, Survey original, Map<Survey, Space<Coord2D>> translated, Survey survey, Space<Coord2D> projection) {
    Map<Station, Set<SurveyConnection>> connections = survey.getConnectedSurveys();
    for (Station connectingStation : connections.keySet()) {
        Coord2D connectingStationLocation = projection.getStationMap().get(connectingStation);
        for (SurveyConnection connection : connections.get(connectingStation)) {
            Station otherConnectingStation = connection.stationInOtherSurvey;
            Survey otherSurvey = connection.otherSurvey;
            if (haveWeAlreadyDoneThisSurvey(translated, otherSurvey, original)) {
                continue;
            }
            // create a new copy of the survey so we can edit the associated sketch
            // (this might seem a bit messy but it's reasonably elegant, honest!)
            Survey lightweightSurveyCopy = new Survey(otherSurvey.getName());
            lightweightSurveyCopy.setOrigin(otherSurvey.getOrigin());
            Space<Coord2D> otherProjection = activity.getProjection(connection.otherSurvey);
            Coord2D otherConnectingStationLocation = otherProjection.getStationMap().get(otherConnectingStation);
            Coord2D transformation = connectingStationLocation.minus(otherConnectingStationLocation);
            Sketch translatedPlan = otherSurvey.getPlanSketch().getTranslatedCopy(transformation);
            lightweightSurveyCopy.setPlanSketch(translatedPlan);
            Sketch translatedElevation = otherSurvey.getElevationSketch().getTranslatedCopy(transformation);
            lightweightSurveyCopy.setElevationSketch(translatedElevation);
            otherProjection = Space2DUtils.transform(otherProjection, transformation);
            translated.put(lightweightSurveyCopy, otherProjection);
            updateTranslatedConnectedSurveys(activity, original, translated, otherSurvey, otherProjection);
        }
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) Set(java.util.Set) SurveyConnection(org.hwyl.sexytopo.model.survey.SurveyConnection) Sketch(org.hwyl.sexytopo.model.sketch.Sketch) Coord2D(org.hwyl.sexytopo.model.graph.Coord2D)

Example 12 with Station

use of org.hwyl.sexytopo.model.survey.Station 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 13 with Station

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

the class SexyTopoActivity method linkToStationInSurvey.

private void linkToStationInSurvey(final Survey surveyToLink) {
    final Station[] stations = surveyToLink.getAllStations().toArray(new Station[] {});
    AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
    builderSingle.setTitle(getString(R.string.link_survey_station));
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
    for (Station station : stations) {
        arrayAdapter.add(station.getName());
    }
    builderSingle.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());
    builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
        String stationName = arrayAdapter.getItem(which);
        try {
            Station selectedStation = Survey.NULL_STATION;
            for (Station station : stations) {
                if (station.getName().equals(stationName)) {
                    selectedStation = station;
                    break;
                }
            }
            Survey current = getSurvey();
            joinSurveys(current, current.getActiveStation(), surveyToLink, selectedStation);
        } catch (Exception exception) {
            showException(exception);
        }
    });
    builderSingle.show();
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) AlertDialog(android.app.AlertDialog) Survey(org.hwyl.sexytopo.model.survey.Survey) ArrayAdapter(android.widget.ArrayAdapter)

Example 14 with Station

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

the class TableActivity method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    final TableCol col = fieldToTableCol.get(cellBeingClicked);
    final GraphToListTranslator.SurveyListEntry surveyEntry = fieldToSurveyEntry.get(cellBeingClicked);
    Context context = this;
    int itemId = menuItem.getItemId();
    if (itemId == R.id.setActiveStation) {
        Station newActive = (Station) (GraphToListTranslator.createMap(surveyEntry).get(col));
        getSurvey().setActiveStation(newActive);
        syncTableWithSurvey();
        return true;
    } else if (itemId == R.id.graph_station_jump_to_plan) {
        Station planStation = (Station) (GraphToListTranslator.createMap(surveyEntry).get(col));
        jumpToStation(planStation, PlanActivity.class);
        return true;
    } else if (itemId == R.id.graph_station_jump_to_ee) {
        Station eeStation = (Station) (GraphToListTranslator.createMap(surveyEntry).get(col));
        jumpToStation(eeStation, ExtendedElevationActivity.class);
        return true;
    } else if (itemId == R.id.renameStation) {
        Station toRename = (Station) (GraphToListTranslator.createMap(surveyEntry).get(col));
        if (toRename == Survey.NULL_STATION) {
            showSimpleToast("Can't rename a splay end");
        } else {
            ManualEntry.renameStation(this, getSurvey(), toRename);
        }
        return true;
    } else if (itemId == R.id.editLeg) {
        Leg toEdit = surveyEntry.getLeg();
        ManualEntry.editLeg(this, getSurvey(), toEdit);
        return true;
    } else if (itemId == R.id.moveRow) {
        final Leg toMove = surveyEntry.getLeg();
        requestMoveLeg(toMove);
        return true;
    } else if (itemId == R.id.upgradeRow) {
        Leg toUpgrade = surveyEntry.getLeg();
        SurveyUpdater.upgradeSplayToConnectedLeg(getSurvey(), toUpgrade, getInputMode());
        syncTableWithSurvey();
        return true;
    } else if (itemId == R.id.deleteStation) {
        Station toDelete = (Station) (GraphToListTranslator.createMap(surveyEntry).get(col));
        askAboutDeleting(context, toDelete, null);
        return true;
    } else if (itemId == R.id.deleteLeg) {
        askAboutDeleting(context, surveyEntry.getFrom(), surveyEntry.getLeg());
        return true;
    } else if (itemId == R.id.deleteSplay) {
        askAboutDeleting(context, surveyEntry.getFrom(), surveyEntry.getLeg());
        return true;
    } else {
        return false;
    }
}
Also used : Context(android.content.Context) Station(org.hwyl.sexytopo.model.survey.Station) GraphToListTranslator(org.hwyl.sexytopo.control.util.GraphToListTranslator) TableCol(org.hwyl.sexytopo.model.table.TableCol) SuppressLint(android.annotation.SuppressLint) Leg(org.hwyl.sexytopo.model.survey.Leg)

Example 15 with Station

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

the class TableActivity method askAboutDeleting.

/*
        This method is a bit convoluted but reflects the UI choices.

        We are either deleting a splay or a leg (if we are deleting a station,
        we still have to delete the source leg). If the latter, we are also deleting any
        onward survey from the station.

        If leg is null, we are deleting the station
        If leg is not null, we are only deleting the leg from the specified station
     */
public void askAboutDeleting(Context context, final Station station, final Leg leg) {
    int numFullLegsToBeDeleted = 0;
    int numSplaysToBeDeleted = 0;
    final boolean deletingLeg = leg != null;
    boolean deletingSplay = (deletingLeg && !leg.hasDestination());
    if (deletingSplay) {
        numSplaysToBeDeleted += 1;
    } else {
        numFullLegsToBeDeleted++;
        Station root = deletingLeg ? leg.getDestination() : station;
        numFullLegsToBeDeleted += SurveyStats.calcNumberSubFullLegs(root);
        numSplaysToBeDeleted += SurveyStats.calcNumberSubSplays(root);
    }
    String message = context.getString(R.string.this_will_delete);
    if (numFullLegsToBeDeleted > 0) {
        String noun = context.getString(R.string.leg).toLowerCase();
        message += "\n" + TextTools.pluralise(numFullLegsToBeDeleted, noun);
        noun = context.getString(R.string.station).toLowerCase();
        message += " (" + TextTools.pluralise(numFullLegsToBeDeleted, noun) + ")";
    }
    if (numSplaysToBeDeleted > 0) {
        String noun = context.getString(R.string.splay).toLowerCase();
        message += "\n" + TextTools.pluralise(numSplaysToBeDeleted, noun);
    }
    new AlertDialog.Builder(context).setMessage(message).setPositiveButton(R.string.delete, (dialog, which) -> {
        Survey survey = getSurvey();
        if (deletingLeg) {
            SurveyUpdater.deleteSplay(survey, station, leg);
        } else {
            SurveyUpdater.deleteStation(survey, station);
        }
        getSurveyManager().broadcastSurveyUpdated();
    }).setNegativeButton(R.string.cancel, null).show();
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) SuppressLint(android.annotation.SuppressLint)

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