use of org.hwyl.sexytopo.model.graph.Coord2D 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 = SpaceFlipper.flipVertically(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);
}
}
}
use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.
the class GraphView method handleDraw.
private boolean handleDraw(MotionEvent event) {
Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
Coord2D surveyCoords = viewCoordsToSurveyCoords(touchPointOnView);
boolean snapToLines = getDisplayPreference(GraphActivity.DisplayPreference.SNAP_TO_LINES);
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
actionDownPointOnView = touchPointOnView;
Coord2D start = surveyCoords;
if (snapToLines) {
Coord2D snappedStart = considerSnapToSketchLine(start);
if (snappedStart != null) {
start = snappedStart;
}
}
sketch.startNewPath(start);
break;
case MotionEvent.ACTION_MOVE:
sketch.getActivePath().lineTo(surveyCoords);
invalidate();
break;
case MotionEvent.ACTION_UP:
if (touchPointOnView.equals(actionDownPointOnView)) {
// handle dots
sketch.getActivePath().lineTo(surveyCoords);
} else if (snapToLines) {
Coord2D snappedEnd = considerSnapToSketchLine(surveyCoords);
if (snappedEnd != null) {
sketch.getActivePath().lineTo(snappedEnd);
invalidate();
}
}
sketch.finishPath();
break;
default:
return false;
}
return true;
}
use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.
the class GraphView method considerSnapToSketchLine.
private Coord2D considerSnapToSketchLine(Coord2D pointTouched) {
double deltaInMetres = SNAP_TO_LINE_SENSITIVITY_IN_PIXELS / surveyToViewScale;
Coord2D closestPathEnd = sketch.findEligibleSnapPointWithin(pointTouched, deltaInMetres);
if (closestPathEnd != null) {
return closestPathEnd;
} else {
return null;
}
}
use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.
the class GraphView method findNearestStationWithinDelta.
private static Station findNearestStationWithinDelta(Space<Coord2D> space, Coord2D target, double delta) {
double shortest = Double.MAX_VALUE;
Station best = null;
for (Station station : space.getStationMap().keySet()) {
Coord2D point = space.getStationMap().get(station);
double distance = Space2DUtils.getDistance(point, target);
if (distance > delta) {
continue;
}
if (best == null || (distance < shortest)) {
best = station;
shortest = distance;
}
}
return best;
}
use of org.hwyl.sexytopo.model.graph.Coord2D in project sexytopo by richsmith.
the class GraphView method handleText.
private boolean handleText(MotionEvent event) {
final Coord2D touchPointOnView = new Coord2D(event.getX(), event.getY());
final Coord2D touchPointOnSurvey = viewCoordsToSurveyCoords(touchPointOnView);
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
final EditText input = new EditText(getContext());
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setView(input).setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sketch.addTextDetail(touchPointOnSurvey, input.getText().toString());
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
});
AlertDialog dialog = builder.create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
dialog.show();
return true;
default:
return false;
}
}
Aggregations