Skip to content

Commit

Permalink
Prepare for using additional stop properties
Browse files Browse the repository at this point in the history
Prepare for using additional stop properties
Added a possibility to select way for stop position
  • Loading branch information
bwr57 committed May 1, 2019
1 parent 77cce70 commit 41ffa8c
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,63 @@ public Boolean testWay(Way way, StopArea stopArea) {
return false;
}

/**
* The *result* does not depend on the current map selection state, neither does
* the result *order*. It solely depends on the distance to point p.
*
* This code is coped from JOSM code
*
* @return a sorted map with the keys representing the perpendicular distance of
* their associated way segments to point p.
*/
protected Map<Double, List<WaySegment>> getNearestWaySegmentInTheWay(Map<Double, List<WaySegment>> nearestMap,
Point p, Way w, double snapDistanceSq) {
if(null == nearestMap)
nearestMap = new TreeMap<>();
Node lastN = null;
int i = -2;
for (Node n : w.getNodes()) {
i++;
if (n.isDeleted() || n.isIncomplete()) { // FIXME: This shouldn't happen, raise exception?
continue;
}
if (lastN == null) {
lastN = n;
continue;
}

Point2D A = MainApplication.getMap().mapView.getPoint2D(lastN);
Point2D B = MainApplication.getMap().mapView.getPoint2D(n);
double c = A.distanceSq(B);
double a = p.distanceSq(B);
double b = p.distanceSq(A);

/*
* perpendicular distance squared loose some precision to account for possible
* deviations in the calculation above e.g. if identical (A and B) come about
* reversed in another way, values may differ -- zero out least significant 32
* dual digits of mantissa..
*/
double perDistSq = Double.longBitsToDouble(
// resolution in numbers with large exponent not needed here..
Double.doubleToLongBits(a - (a - b + c) * (a - b + c) / 4 / c) >> 32 << 32);

if (perDistSq < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq) {
List<WaySegment> wslist;
if (nearestMap.containsKey(perDistSq)) {
wslist = nearestMap.get(perDistSq);
} else {
wslist = new LinkedList<>();
nearestMap.put(perDistSq, wslist);
}
wslist.add(new WaySegment(w, i));
}

lastN = n;
}
return nearestMap;
}

/**
* The *result* does not depend on the current map selection state, neither does
* the result *order*. It solely depends on the distance to point p.
*
* This code is coped from JOSM code
*
* @return a sorted map with the keys representing the perpendicular distance of
* their associated way segments to point p.
*/
private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p) {
Map<Double, List<WaySegment>> nearestMap = new TreeMap<>();
DataSet ds = getCurrentDataSet();
Expand All @@ -192,47 +240,7 @@ private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p) {
snapDistanceSq *= snapDistanceSq;

for (Way w : ds.searchWays(getBBox(p, Config.getPref().getInt("mappaint.segment.snap-distance", 200)))) {
Node lastN = null;
int i = -2;
for (Node n : w.getNodes()) {
i++;
if (n.isDeleted() || n.isIncomplete()) { // FIXME: This shouldn't happen, raise exception?
continue;
}
if (lastN == null) {
lastN = n;
continue;
}

Point2D A = MainApplication.getMap().mapView.getPoint2D(lastN);
Point2D B = MainApplication.getMap().mapView.getPoint2D(n);
double c = A.distanceSq(B);
double a = p.distanceSq(B);
double b = p.distanceSq(A);

/*
* perpendicular distance squared loose some precision to account for possible
* deviations in the calculation above e.g. if identical (A and B) come about
* reversed in another way, values may differ -- zero out least significant 32
* dual digits of mantissa..
*/
double perDistSq = Double.longBitsToDouble(
// resolution in numbers with large exponent not needed here..
Double.doubleToLongBits(a - (a - b + c) * (a - b + c) / 4 / c) >> 32 << 32);

if (perDistSq < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq) {
List<WaySegment> wslist;
if (nearestMap.containsKey(perDistSq)) {
wslist = nearestMap.get(perDistSq);
} else {
wslist = new LinkedList<>();
nearestMap.put(perDistSq, wslist);
}
wslist.add(new WaySegment(w, i));
}

lastN = n;
}
nearestMap = getNearestWaySegmentInTheWay(nearestMap, p, w, snapDistanceSq);
}
}

Expand All @@ -249,7 +257,15 @@ private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p) {
protected NearestWaySegment getNearestWaySegment(LatLon platformCoord, StopArea stopArea) {
MapView mapView = MainApplication.getMap().mapView;
Point p = mapView.getPoint(platformCoord);
Map<Double, List<WaySegment>> dist_waySegments = getNearestWaySegmentsImpl(p);
Map<Double, List<WaySegment>> dist_waySegments = null;
if(null != stopArea.additionalSelectedObject && stopArea.additionalSelectedObject instanceof Way) {
double sq = Config.getPref().getInt("mappaint.segment.snap-distance", 200);
sq *= sq;
dist_waySegments = getNearestWaySegmentInTheWay(dist_waySegments, p, (Way) stopArea.additionalSelectedObject,
sq);
}
else
dist_waySegments = getNearestWaySegmentsImpl(p);
for (Map.Entry<Double, List<WaySegment>> entry : dist_waySegments.entrySet()) {
for (WaySegment waySegment : entry.getValue()) {
if (testWay(waySegment.way, stopArea)) {
Expand Down Expand Up @@ -304,9 +320,10 @@ public StopArea performCustomizing(StopArea stopArea) {
platformCoord = getCenterOfWay(stopArea.selectedObject);
if (platformCoord == null)
return stopArea;
AbstractMap.SimpleEntry<Double, Node> nearestNode = getNearestNode(platformCoord, stopArea);
NearestWaySegment nearestWaySegment = getNearestWaySegment(platformCoord, stopArea);
Node newStopPointNode = null;
AbstractMap.SimpleEntry<Double, Node> nearestNode = getNearestNode(platformCoord, stopArea);
NearestWaySegment nearestWaySegment = null;
nearestWaySegment = getNearestWaySegment(platformCoord, stopArea);
if (nearestNode != null && nearestWaySegment != null) {
MapView mapView = MainApplication.getMap().mapView;
Double segmentDist = mapView.getPoint2D(platformCoord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.Relation;
import org.openstreetmap.josm.data.osm.RelationMember;
import sun.security.provider.certpath.IndexedCollectionCertStore;

/**
* Operation of constructing of stop area object from selected JOSM object
Expand Down Expand Up @@ -97,7 +96,7 @@ public boolean testIsTransportTypeAssigned(OsmPrimitive platform) {
*
* @param stopArea Selected stop area
*/
public void fromSelectedObject(StopArea stopArea) {
public void fromSelectedObject(StopArea stopArea) {
Collection<OsmPrimitive> selectedObjects = new ArrayList<OsmPrimitive>();
selectedObjects.add(stopArea.selectedObject);
for (Relation rel : OsmPrimitive.getParentRelations(selectedObjects)) {
Expand Down Expand Up @@ -162,8 +161,18 @@ public StopArea performCustomizing(StopArea stopArea) {
OsmPrimitive selectedObject = selectedObjects.iterator().next();
if (selectedObject == null)
return null;
OsmPrimitive additionalSelectedObject = null;
if(selectedObjects.size() > 1)
{
OsmPrimitive[] selectedObjectsArr = new OsmPrimitive[selectedObjects.size()];
selectedObjects.toArray(selectedObjectsArr);
additionalSelectedObject = selectedObjectsArr[1];
}
if (stopArea == null)
stopArea = new StopArea(selectedObject);
if (additionalSelectedObject == null)
stopArea = new StopArea(selectedObject);
else
stopArea = new StopArea(selectedObject, additionalSelectedObject);
fromSelectedObject(stopArea);
return stopArea;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CustomizePublicTransportStopDialog implements ActionListener, ItemL
private static final String SAVE_COMMAND = "save";

private static final String PUBLIC_TRANSPORT_LANG_SECTION_NAME = "PublicTransport";
private static final String CANCEL_BUTTON_CAPTION = "Cancel";
private static final String CANCEL_BUTTON_CAPTION = "Cancel1111";
private static final String SAVE_BUTTON_CAPTION = "Save";
private static final String AREA_CAPTION = "Area";
private static final String COVER_CAPTION = "Cover";
Expand All @@ -58,12 +58,18 @@ public class CustomizePublicTransportStopDialog implements ActionListener, ItemL
public static final String COMMUTER_NETWORK_CAPTION = "Commuter";
public static final String CITY_NETWORK_CAPTION = "City transport";
public static final String HIGH_SPEED_NETWORK_CAPTION = "High speed";
public static final String TOURISM_NETWORK_CAPTION = "Tourism";
public static final String SCHOOL_NETWORK_CAPTION = "School";
public static final String FACTORY_NETWORK_CAPTION = "Factory";


private String[] serviceCaptionStrings = {CITY_NETWORK_CAPTION, COMMUTER_NETWORK_CAPTION, REGIONAL_NETWORK_CAPTION,
LONG_DISTANCE_NETWORK_CAPTION, HIGH_SPEED_NETWORK_CAPTION};
LONG_DISTANCE_NETWORK_CAPTION, HIGH_SPEED_NETWORK_CAPTION, TOURISM_NETWORK_CAPTION, SCHOOL_NETWORK_CAPTION,
FACTORY_NETWORK_CAPTION};
private String[] serviceStrings = {OSMTags.CITY_NETWORK_TAG_VALUE, OSMTags.COMMUTER_NETWORK_TAG_VALUE,
OSMTags.REGIONAL_NETWORK_TAG_VALUE, OSMTags.LONG_DISTANCE_NETWORK_TAG_VALUE,
OSMTags.HIGH_SPEED_NETWORK_TAG_VALUE};
OSMTags.HIGH_SPEED_NETWORK_TAG_VALUE, OSMTags.TOURISM_NETWORK_TAG_VALUE, OSMTags.SCHOOL_NETWORK_TAG_VALUE,
OSMTags.FACTORY_NETWORK_TAG_VALUE};

private JDialog jDialog = null;
private JTextField textFieldName = null;
Expand Down Expand Up @@ -545,6 +551,8 @@ else if (previousNetwork != null)
textFieldOperator.setText(stopArea.operator);
else if (previousOperator != null)
textFieldOperator.setText(previousOperator);
// if (stopArea.additionalSelectedObject != null)
// textFieldOperator.setText(String.valueOf(stopArea.additionalSelectedObject.getId()));
comboBoxService.setSelectedIndex(getServiceIndex(stopArea.service));
setCheckBoxValue(checkBoxIsBus, stopArea.isBus);
setCheckBoxValue(checkBoxIsShareTaxi, stopArea.isShareTaxi);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,59 @@ public final class OSMTags {
public static final String REGIONAL_NETWORK_TAG_VALUE = "regional";
public static final String LONG_DISTANCE_NETWORK_TAG_VALUE = "long_distance";
public static final String HIGH_SPEED_NETWORK_TAG_VALUE = "high_speed";
public static final String TOURISM_NETWORK_TAG_VALUE = "tourism";
public static final String SCHOOL_NETWORK_TAG_VALUE = "school";
public static final String FACTORY_NETWORK_TAG_VALUE = "factory";

public static final String REF_TAG = "ref";
public static final String LOCAL_REF_TAG = "local_ref";
public static final String PASSENGER_INFORMATION_DISPLAY_TAG = "passenger_information_display";
public static final String DEPARTURES_BOARD_TAG = "departures_board";
public static final String TACTILE_PAVING_TAG = "tactile_paving";
public static final String LAYER_TAG = "layer";
public static final String LIT_TAG = "lit";
public static final String BIN_TAG = "bin";
public static final String SURFACE_TAG = "surface";
public static final String ON_DEMAND_TAG = "on_demand";


public static final String DEPARTURES_BOARD_YES_TAG_VALUE = "yes";
public static final String DEPARTURES_BOARD_TIMETABLE_TAG_VALUE = "timetable";
public static final String DEPARTURES_BOARD_DELAY_TAG_VALUE = "delay";
public static final String DEPARTURES_BOARD_REALTIME_TAG_VALUE = "realtime";

public static final String TACTILE_PAVING_YES_TAG_VALUE = "yes";
public static final String TACTILE_PAVING_CONTRASTED_TAG_TAG_VALUE = "contrasted";
public static final String TACTILE_PAVING_PRIMITIVE_TAG_TAG_VALUE = "primitive";
public static final String TACTILE_PAVING_INCORRECT_TAG_TAG_VALUE = "incorrect";

public static final String SURFACE_PAVED_TAG_VALUE = "paved";
public static final String SURFACE_ASPHALT_TAG_VALUE = "asphalt";
public static final String SURFACE_CONCRETE_TAG_VALUE = "concrete";
public static final String SURFACE_PAVING_STONES_TAG_VALUE = "paving_stones";
public static final String SURFACE_SETT_TAG_VALUE = "sett";
public static final String SURFACE_UNHEUN_COBBLESTONE_TAG_VALUE = "unhewn_cobblestone";
public static final String SURFACE_COBBLESTONE_TAG_VALUE = "cobblestone";
public static final String SURFACE_METAL_TAG_VALUE = "metal";
public static final String SURFACE_WOOD_TAG_VALUE = "wood";
public static final String SURFACE_UNPAVED_TAG_VALUE = "unpaved";
public static final String SURFACE_COMPACTED_TAG_VALUE = "compacted";
public static final String SURFACE_FINE_GRAVEL_TAG_VALUE = "fine_gravel";
public static final String SURFACE_GRAVEL_TAG_VALUE = "gravel";
public static final String SURFACE_PEBBLESTONE_TAG_VALUE = "pebblestone";
public static final String SURFACE_DIRT_TAG_VALUE = "dirt";
public static final String SURFACE_GRASS_TAG_VALUE = "grass";
public static final String SURFACE_GRASS_PAVER_TAG_VALUE = "grass_paver";
public static final String SURFACE_GROUND_TAG_VALUE = "ground";
public static final String SURFACE_MUD_TAG_VALUE = "mud";
public static final String SURFACE_SAND_TAG_VALUE = "sand";
public static final String SURFACE_WOODCHIPS_TAG_VALUE = "woodchips";
public static final String SURFACE_SNOW_TAG_VALUE = "snow";
public static final String SURFACE_ICE_TAG_VALUE = "ice";
public static final String SURFACE_SALT_TAG_VALUE = "salt";




private OSMTags() {
// Hide default constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,43 @@ public class StopArea {
/**
* Separate node of bus stop or bus station
*/
public Node separateBusStopNode = null;
public String ref = null;
/**
* Separate node of bus stop or bus station
*/
public String localRef = null;
/**
* Separate node of bus stop or bus station
*/
public Boolean passengerInformationDisplay = false;
/**
* Separate node of bus stop or bus station
*/
public String departuresBoard = null;
/**
* Separate node of bus stop or bus station
*/
public String tactilePaving = null;
/**
* Separate node of bus stop or bus station
*/
public String layer = null;
/**
* Separate node of bus stop or bus station
*/
public Boolean lit = false;
/**
* Separate node of bus stop or bus station
*/
public Boolean bin = false;
/**
* Separate node of bus stop or bus station
*/
public String surface = null;
/**
* Separate node of bus stop or bus station
*/
public String onDemand = null;

/**
* List of nodes of stop positions
Expand All @@ -113,6 +149,10 @@ public class StopArea {
* Selected josm objects. Must be a platform
*/
public OsmPrimitive selectedObject = null;
/**
* Selected josm objects. Must be a platform
*/
public OsmPrimitive additionalSelectedObject = null;

/**
* Constructor of stop area object
Expand All @@ -129,6 +169,17 @@ public StopArea(OsmPrimitive selectedObject) {
this.selectedObject = selectedObject;
}

/**
* Constructor of stop area object from selected object
*
* @param selectedObject Selected object
*/
public StopArea(OsmPrimitive selectedObject, OsmPrimitive additionalSelectedObject) {
this.selectedObject = selectedObject;
// if(null != additionalSelectedObject && additionalSelectedObject instanceof Way) {
this.additionalSelectedObject = (Way)additionalSelectedObject;
// }
}
/**
* Get selected in editor node
*
Expand Down

0 comments on commit 41ffa8c

Please sign in to comment.