kopia lustrzana https://github.com/JOSM/MapWithAI
Fix error prone issues and some pmd issues
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
d3ea8f2d82
commit
c9f2201a16
|
@ -17,12 +17,14 @@ public final class RapiDPlugin extends Plugin {
|
|||
public static final String NAME = "RapiD";
|
||||
private static String versionInfo;
|
||||
|
||||
private final PreferenceSetting preferences = new RapiDPreferences();
|
||||
private final PreferenceSetting preferenceSetting;
|
||||
|
||||
public RapiDPlugin(PluginInformation info) {
|
||||
super(info);
|
||||
|
||||
JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
||||
preferenceSetting = new RapiDPreferences();
|
||||
|
||||
final JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
||||
MainMenu.add(dataMenu, new RapiDAction(), false);
|
||||
MainMenu.add(dataMenu, new RapiDMoveAction(), false);
|
||||
|
||||
|
@ -33,7 +35,7 @@ public final class RapiDPlugin extends Plugin {
|
|||
|
||||
@Override
|
||||
public PreferenceSetting getPreferenceSetting() {
|
||||
return preferences;
|
||||
return preferenceSetting;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,31 +21,34 @@ import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
|||
import org.openstreetmap.josm.plugins.rapid.backend.RapiDDataUtils;
|
||||
|
||||
public class RapiDPreferences implements SubPreferenceSetting {
|
||||
protected final JLabel rapidApiUrl = new JLabel(tr("RapiD API URL"));
|
||||
protected final JComboBox<String> possibleRapidApiUrl = new JComboBox<>();
|
||||
private final JComboBox<String> possibleRapidApiUrl;
|
||||
|
||||
protected final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
|
||||
protected final JCheckBox switchLayerCheckBox = new JCheckBox();
|
||||
private final JCheckBox switchLayerCheckBox;
|
||||
|
||||
protected final JLabel maximumAddition = new JLabel(
|
||||
tr("Maximum features (add)"));
|
||||
protected final JSpinner maximumAdditionSpinner = new JSpinner(
|
||||
new SpinnerNumberModel(RapiDDataUtils.getMaximumAddition(), 0, 100, 1));
|
||||
private final JSpinner maximumAdditionSpinner;
|
||||
|
||||
public RapiDPreferences() {
|
||||
possibleRapidApiUrl = new JComboBox<>();
|
||||
switchLayerCheckBox = new JCheckBox();
|
||||
maximumAdditionSpinner = new JSpinner(new SpinnerNumberModel(RapiDDataUtils.getMaximumAddition(), 0, 100, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGui(PreferenceTabbedPane gui) {
|
||||
final JLabel rapidApiUrl = new JLabel(tr("RapiD API URL"));
|
||||
final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
|
||||
final JLabel maximumAddition = new JLabel(tr("Maximum features (add)"));
|
||||
final JPanel container = new JPanel(new GridBagLayout());
|
||||
container.setAlignmentY(JPanel.TOP_ALIGNMENT);
|
||||
final GridBagConstraints constraints = new GridBagConstraints();
|
||||
|
||||
|
||||
possibleRapidApiUrl.setEditable(true);
|
||||
possibleRapidApiUrl.setPrototypeDisplayValue("https://example.url/some/end/point");
|
||||
Component textField = possibleRapidApiUrl.getEditor().getEditorComponent();
|
||||
final Component textField = possibleRapidApiUrl.getEditor().getEditorComponent();
|
||||
if (textField instanceof JTextField) {
|
||||
((JTextField) textField).setColumns(36);
|
||||
}
|
||||
for (String url : RapiDDataUtils.getRapiDURLs()) {
|
||||
for (final String url : RapiDDataUtils.getRapiDURLs()) {
|
||||
possibleRapidApiUrl.addItem(url);
|
||||
}
|
||||
possibleRapidApiUrl.setSelectedItem(RapiDDataUtils.getRapiDURL());
|
||||
|
@ -84,7 +87,7 @@ public class RapiDPreferences implements SubPreferenceSetting {
|
|||
public boolean ok() {
|
||||
RapiDDataUtils.setRapiDUrl((String) possibleRapidApiUrl.getSelectedItem());
|
||||
RapiDDataUtils.setSwitchLayers(switchLayerCheckBox.isSelected());
|
||||
Object value = maximumAdditionSpinner.getValue();
|
||||
final Object value = maximumAdditionSpinner.getValue();
|
||||
if (value instanceof Number) {
|
||||
RapiDDataUtils.setMaximumAddition(((Number) value).intValue());
|
||||
}
|
||||
|
@ -100,4 +103,25 @@ public class RapiDPreferences implements SubPreferenceSetting {
|
|||
public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) {
|
||||
return gui.getPluginPreference();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code JComboBox} with possible rapid api urls
|
||||
*/
|
||||
public JComboBox<String> getPossibleRapidApiUrl() {
|
||||
return possibleRapidApiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@code JCheckBox} for whether or not we are switching layers.
|
||||
*/
|
||||
public JCheckBox getSwitchLayerCheckBox() {
|
||||
return switchLayerCheckBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code JSpinner} for the maximum additions
|
||||
*/
|
||||
public JSpinner getMaximumAdditionSpinner() {
|
||||
return maximumAdditionSpinner;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public class RapiDAction extends JosmAction {
|
|||
/** UID */
|
||||
private static final long serialVersionUID = 8886705479253246588L;
|
||||
|
||||
private static final Object layerLock = new Object();
|
||||
private static final Object LAYER_LOCK = new Object();
|
||||
|
||||
public RapiDAction() {
|
||||
super(RapiDPlugin.NAME, null, tr("Get data from RapiD"),
|
||||
|
@ -41,15 +41,13 @@ public class RapiDAction extends JosmAction {
|
|||
*/
|
||||
public static RapiDLayer getLayer(boolean create) {
|
||||
final List<RapiDLayer> rapidLayers = MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class);
|
||||
RapiDLayer layer;
|
||||
synchronized (layerLock) {
|
||||
RapiDLayer layer = null;
|
||||
synchronized (LAYER_LOCK) {
|
||||
if (rapidLayers.isEmpty() && create) {
|
||||
layer = new RapiDLayer(new DataSet(), RapiDPlugin.NAME, null);
|
||||
MainApplication.getLayerManager().addLayer(layer);
|
||||
} else if (!rapidLayers.isEmpty()) {
|
||||
layer = rapidLayers.get(0);
|
||||
} else {
|
||||
layer = null;
|
||||
}
|
||||
}
|
||||
return layer;
|
||||
|
@ -86,7 +84,7 @@ public class RapiDAction extends JosmAction {
|
|||
final DataSet newData = RapiDDataUtils.getData(bound.toBBox());
|
||||
/* Microsoft buildings don't have a source, so we add one */
|
||||
RapiDDataUtils.addSourceTags(newData, "building", "Microsoft");
|
||||
synchronized (layerLock) {
|
||||
synchronized (LAYER_LOCK) {
|
||||
layer.unlock();
|
||||
layer.mergeFrom(newData);
|
||||
layer.lock();
|
||||
|
|
|
@ -53,22 +53,20 @@ public final class RapiDDataUtils {
|
|||
* @return A DataSet with data inside the bbox
|
||||
*/
|
||||
public static DataSet getData(BBox bbox) {
|
||||
DataSet dataSet = new DataSet();
|
||||
if (!bbox.isValid())
|
||||
return dataSet;
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
for (BBox tbbox : reduceBBoxSize(bbox)) {
|
||||
futures.add(MainApplication.worker.submit(new GetDataRunnable(tbbox, dataSet)));
|
||||
}
|
||||
for (Future<?> future : futures) {
|
||||
synchronized (future) {
|
||||
final DataSet dataSet = new DataSet();
|
||||
if (bbox.isValid()) {
|
||||
final List<Future<?>> futures = new ArrayList<>();
|
||||
for (final BBox tbbox : reduceBBoxSize(bbox)) {
|
||||
futures.add(MainApplication.worker.submit(new GetDataRunnable(tbbox, dataSet)));
|
||||
}
|
||||
for (final Future<?> future : futures) {
|
||||
try {
|
||||
int count = 0;
|
||||
while (!future.isDone() && !future.isCancelled() && count < 100) {
|
||||
future.wait(100);
|
||||
Thread.sleep(100);
|
||||
count++;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
Logging.debug(e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
@ -79,7 +77,7 @@ public final class RapiDDataUtils {
|
|||
|
||||
private static class GetDataRunnable implements Runnable {
|
||||
private final BBox bbox;
|
||||
private DataSet dataSet = null;
|
||||
private final DataSet dataSet;
|
||||
|
||||
public GetDataRunnable(BBox bbox, DataSet dataSet) {
|
||||
this.bbox = bbox;
|
||||
|
@ -88,7 +86,7 @@ public final class RapiDDataUtils {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
DataSet temporaryDataSet = getDataReal(bbox);
|
||||
final DataSet temporaryDataSet = getDataReal(bbox);
|
||||
synchronized (RapiDDataUtils.GetDataRunnable.class) {
|
||||
dataSet.mergeFrom(temporaryDataSet);
|
||||
}
|
||||
|
@ -98,12 +96,12 @@ public final class RapiDDataUtils {
|
|||
|
||||
private static DataSet getDataReal(BBox bbox) {
|
||||
InputStream inputStream = null;
|
||||
DataSet dataSet = new DataSet();
|
||||
String urlString = getRapiDURL();
|
||||
final DataSet dataSet = new DataSet();
|
||||
final String urlString = getRapiDURL();
|
||||
try {
|
||||
final URL url = new URL(urlString.replace("{bbox}", bbox.toStringCSV(",")));
|
||||
HttpClient client = HttpClient.create(url);
|
||||
StringBuilder defaultUserAgent = new StringBuilder();
|
||||
final HttpClient client = HttpClient.create(url);
|
||||
final StringBuilder defaultUserAgent = new StringBuilder();
|
||||
defaultUserAgent.append(client.getHeaders().get("User-Agent"));
|
||||
if (defaultUserAgent.toString().trim().length() == 0) {
|
||||
defaultUserAgent.append("JOSM");
|
||||
|
@ -111,7 +109,7 @@ public final class RapiDDataUtils {
|
|||
defaultUserAgent.append(tr("/ {0} {1}", RapiDPlugin.NAME, RapiDPlugin.getVersionInfo()));
|
||||
client.setHeader("User-Agent", defaultUserAgent.toString());
|
||||
Logging.debug("{0}: Getting {1}", RapiDPlugin.NAME, client.getURL().toString());
|
||||
Response response = client.connect();
|
||||
final Response response = client.connect();
|
||||
inputStream = response.getContent();
|
||||
dataSet.mergeFrom(OsmReader.parseDataSet(inputStream, null));
|
||||
response.disconnect();
|
||||
|
@ -121,7 +119,7 @@ public final class RapiDDataUtils {
|
|||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
Logging.debug(e);
|
||||
}
|
||||
}
|
||||
|
@ -150,18 +148,18 @@ public final class RapiDDataUtils {
|
|||
* @param primitives The primitives to remove
|
||||
*/
|
||||
public static void removePrimitivesFromDataSet(Collection<OsmPrimitive> primitives) {
|
||||
for (OsmPrimitive primitive : primitives) {
|
||||
for (final OsmPrimitive primitive : primitives) {
|
||||
if (primitive instanceof Relation) {
|
||||
removePrimitivesFromDataSet(((Relation) primitive).getMemberPrimitives());
|
||||
} else if (primitive instanceof Way) {
|
||||
for (Node node : ((Way) primitive).getNodes()) {
|
||||
DataSet ds = node.getDataSet();
|
||||
for (final Node node : ((Way) primitive).getNodes()) {
|
||||
final DataSet ds = node.getDataSet();
|
||||
if (ds != null) {
|
||||
ds.removePrimitive(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
DataSet ds = primitive.getDataSet();
|
||||
final DataSet ds = primitive.getDataSet();
|
||||
if (ds != null) {
|
||||
ds.removePrimitive(primitive);
|
||||
}
|
||||
|
@ -176,8 +174,8 @@ public final class RapiDDataUtils {
|
|||
*/
|
||||
public static void addPrimitivesToCollection(Collection<OsmPrimitive> collection,
|
||||
Collection<OsmPrimitive> primitives) {
|
||||
Collection<OsmPrimitive> temporaryCollection = new TreeSet<>();
|
||||
for (OsmPrimitive primitive : primitives) {
|
||||
final Collection<OsmPrimitive> temporaryCollection = new TreeSet<>();
|
||||
for (final OsmPrimitive primitive : primitives) {
|
||||
if (primitive instanceof Way) {
|
||||
temporaryCollection.addAll(((Way) primitive).getNodes());
|
||||
} else if (primitive instanceof Relation) {
|
||||
|
@ -194,7 +192,7 @@ public final class RapiDDataUtils {
|
|||
* @return A RapiD url
|
||||
*/
|
||||
public static String getRapiDURL() {
|
||||
List<String> urls = getRapiDURLs();
|
||||
final List<String> urls = getRapiDURLs();
|
||||
String url = Config.getPref().get(RapiDPlugin.NAME.concat(".current_api"), DEFAULT_RAPID_API);
|
||||
if (!urls.contains(url)) {
|
||||
url = DEFAULT_RAPID_API;
|
||||
|
@ -209,7 +207,7 @@ public final class RapiDDataUtils {
|
|||
* @param url The url to set as the default
|
||||
*/
|
||||
public static void setRapiDUrl(String url) {
|
||||
List<String> urls = getRapiDURLs();
|
||||
final List<String> urls = getRapiDURLs();
|
||||
if (!urls.contains(url)) {
|
||||
urls.add(url);
|
||||
setRapiDURLs(urls);
|
||||
|
@ -241,12 +239,13 @@ public final class RapiDDataUtils {
|
|||
*/
|
||||
public static void addRapiDPaintStyles() {
|
||||
// TODO figure out how to use the one in the jar file
|
||||
ExtendedSourceEntry rapid = new ExtendedSourceEntry(SourceType.MAP_PAINT_STYLE, "rapid.mapcss",
|
||||
final ExtendedSourceEntry rapid = new ExtendedSourceEntry(SourceType.MAP_PAINT_STYLE, "rapid.mapcss",
|
||||
"https://gitlab.com/smocktaylor/rapid/raw/master/src/resources/styles/standard/rapid.mapcss");
|
||||
List<SourceEntry> paintStyles = MapPaintPrefHelper.INSTANCE.get();
|
||||
for (SourceEntry paintStyle : paintStyles) {
|
||||
if (rapid.url.equals(paintStyle.url))
|
||||
final List<SourceEntry> paintStyles = MapPaintPrefHelper.INSTANCE.get();
|
||||
for (final SourceEntry paintStyle : paintStyles) {
|
||||
if (rapid.url.equals(paintStyle.url)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
paintStyles.add(rapid);
|
||||
MapPaintPrefHelper.INSTANCE.put(paintStyles);
|
||||
|
@ -288,23 +287,24 @@ public final class RapiDDataUtils {
|
|||
}
|
||||
|
||||
public static List<BBox> reduceBBoxSize(BBox bbox) {
|
||||
List<BBox> returnBounds = new ArrayList<>();
|
||||
double width = getWidth(bbox);
|
||||
double height = getHeight(bbox);
|
||||
Double widthDivisions = width / MAXIMUM_SIDE_DIMENSIONS;
|
||||
Double heightDivisions = height / MAXIMUM_SIDE_DIMENSIONS;
|
||||
int widthSplits = widthDivisions.intValue() + (widthDivisions - widthDivisions.intValue() > 0 ? 1 : 0);
|
||||
int heightSplits = heightDivisions.intValue() + (heightDivisions - heightDivisions.intValue() > 0 ? 1 : 0);
|
||||
final List<BBox> returnBounds = new ArrayList<>();
|
||||
final double width = getWidth(bbox);
|
||||
final double height = getHeight(bbox);
|
||||
final Double widthDivisions = width / MAXIMUM_SIDE_DIMENSIONS;
|
||||
final Double heightDivisions = height / MAXIMUM_SIDE_DIMENSIONS;
|
||||
final int widthSplits = widthDivisions.intValue() + (widthDivisions - widthDivisions.intValue() > 0 ? 1 : 0);
|
||||
final int heightSplits = heightDivisions.intValue()
|
||||
+ (heightDivisions - heightDivisions.intValue() > 0 ? 1 : 0);
|
||||
|
||||
double newMinWidths = Math.abs((bbox.getTopLeftLon() - bbox.getBottomRightLon())) / widthSplits;
|
||||
double newMinHeights = Math.abs((bbox.getBottomRightLat() - bbox.getTopLeftLat())) / heightSplits;
|
||||
final double newMinWidths = Math.abs(bbox.getTopLeftLon() - bbox.getBottomRightLon()) / widthSplits;
|
||||
final double newMinHeights = Math.abs(bbox.getBottomRightLat() - bbox.getTopLeftLat()) / heightSplits;
|
||||
|
||||
double minx = bbox.getTopLeftLon();
|
||||
double miny = bbox.getBottomRightLat();
|
||||
final double minx = bbox.getTopLeftLon();
|
||||
final double miny = bbox.getBottomRightLat();
|
||||
for (int x = 1; x <= widthSplits; x++) {
|
||||
for (int y = 1; y <= heightSplits; y++) {
|
||||
LatLon lowerLeft = new LatLon(miny + newMinHeights * (y - 1), minx + newMinWidths * (x - 1));
|
||||
LatLon upperRight = new LatLon(miny + newMinHeights * y, minx + newMinWidths * x);
|
||||
final LatLon lowerLeft = new LatLon(miny + newMinHeights * (y - 1), minx + newMinWidths * (x - 1));
|
||||
final LatLon upperRight = new LatLon(miny + newMinHeights * y, minx + newMinWidths * x);
|
||||
returnBounds.add(new BBox(lowerLeft, upperRight));
|
||||
}
|
||||
}
|
||||
|
@ -313,24 +313,24 @@ public final class RapiDDataUtils {
|
|||
|
||||
public static double getWidth(BBox bbox) {
|
||||
// Lat is y, Lon is x
|
||||
LatLon bottomRight = bbox.getBottomRight();
|
||||
LatLon topLeft = bbox.getTopLeft();
|
||||
double maxx = bottomRight.getX();
|
||||
double minx = topLeft.getX();
|
||||
double miny = bottomRight.getY();
|
||||
double maxy = topLeft.getY();
|
||||
LatLon bottomLeft = new LatLon(miny, minx);
|
||||
LatLon topRight = new LatLon(maxy, maxx);
|
||||
final LatLon bottomRight = bbox.getBottomRight();
|
||||
final LatLon topLeft = bbox.getTopLeft();
|
||||
final double maxx = bottomRight.getX();
|
||||
final double minx = topLeft.getX();
|
||||
final double miny = bottomRight.getY();
|
||||
final double maxy = topLeft.getY();
|
||||
final LatLon bottomLeft = new LatLon(miny, minx);
|
||||
final LatLon topRight = new LatLon(maxy, maxx);
|
||||
// TODO handle meridian
|
||||
return Math.max(bottomRight.greatCircleDistance(bottomLeft), topRight.greatCircleDistance(topLeft));
|
||||
}
|
||||
|
||||
public static double getHeight(BBox bbox) {
|
||||
LatLon bottomRight = bbox.getBottomRight();
|
||||
LatLon topLeft = bbox.getTopLeft();
|
||||
double minx = topLeft.getX();
|
||||
double miny = bottomRight.getY();
|
||||
LatLon bottomLeft = new LatLon(miny, minx);
|
||||
final LatLon bottomRight = bbox.getBottomRight();
|
||||
final LatLon topLeft = bbox.getTopLeft();
|
||||
final double minx = topLeft.getX();
|
||||
final double miny = bottomRight.getY();
|
||||
final LatLon bottomLeft = new LatLon(miny, minx);
|
||||
// TODO handle poles
|
||||
return topLeft.greatCircleDistance(bottomLeft);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,9 @@ public class RapiDLayer extends OsmDataLayer {
|
|||
|
||||
/**
|
||||
* Create a new RapiD layer
|
||||
* @param data OSM data from rapid
|
||||
* @param name Layer name
|
||||
*
|
||||
* @param data OSM data from rapid
|
||||
* @param name Layer name
|
||||
* @param associatedFile an associated file (can be null)
|
||||
*/
|
||||
public RapiDLayer(DataSet data, String name, File associatedFile) {
|
||||
|
|
|
@ -30,17 +30,17 @@ public class RapiDMoveAction extends JosmAction {
|
|||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
for (RapiDLayer rapid : MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class)) {
|
||||
List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
|
||||
for (final RapiDLayer rapid : MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class)) {
|
||||
final List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
|
||||
OsmDataLayer editLayer = null;
|
||||
int maxAddition = RapiDDataUtils.getMaximumAddition();
|
||||
final int maxAddition = RapiDDataUtils.getMaximumAddition();
|
||||
Collection<OsmPrimitive> selected;
|
||||
if (maxAddition > 0) {
|
||||
selected = rapid.getDataSet().getSelected().stream().limit(maxAddition).collect(Collectors.toList());
|
||||
} else {
|
||||
selected = rapid.getDataSet().getSelected();
|
||||
}
|
||||
for (OsmDataLayer osmLayer : osmLayers) {
|
||||
for (final OsmDataLayer osmLayer : osmLayers) {
|
||||
if (!osmLayer.isLocked() && osmLayer.isVisible() && osmLayer.isUploadable()
|
||||
&& osmLayer.getClass().equals(OsmDataLayer.class)) {
|
||||
editLayer = osmLayer;
|
||||
|
@ -48,11 +48,11 @@ public class RapiDMoveAction extends JosmAction {
|
|||
}
|
||||
}
|
||||
if (editLayer != null) {
|
||||
RapiDAddCommand command = new RapiDAddCommand(rapid, editLayer, selected);
|
||||
final RapiDAddCommand command = new RapiDAddCommand(rapid, editLayer, selected);
|
||||
UndoRedoHandler.getInstance().add(command);
|
||||
if (RapiDDataUtils.getSwitchLayers()) {
|
||||
MainApplication.getLayerManager().setActiveLayer(editLayer);
|
||||
DataSet editable = editLayer.getDataSet();
|
||||
final DataSet editable = editLayer.getDataSet();
|
||||
editable.setSelected(
|
||||
editable.getSelected().stream().filter(OsmPrimitive::isTagged).collect(Collectors.toSet()));
|
||||
}
|
||||
|
@ -75,12 +75,13 @@ public class RapiDMoveAction extends JosmAction {
|
|||
}
|
||||
|
||||
private boolean checkIfActionEnabled() {
|
||||
Layer active = getLayerManager().getActiveLayer();
|
||||
boolean returnValue = false;
|
||||
final Layer active = getLayerManager().getActiveLayer();
|
||||
if (active instanceof RapiDLayer) {
|
||||
RapiDLayer rapid = (RapiDLayer) active;
|
||||
Collection<OsmPrimitive> selection = rapid.getDataSet().getAllSelected();
|
||||
return (selection != null && !selection.isEmpty());
|
||||
} else
|
||||
return false;
|
||||
final RapiDLayer rapid = (RapiDLayer) active;
|
||||
final Collection<OsmPrimitive> selection = rapid.getDataSet().getAllSelected();
|
||||
returnValue = selection != null && !selection.isEmpty();
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class AddNodeToWayCommand extends Command {
|
|||
|
||||
@Override
|
||||
public boolean executeCommand() {
|
||||
int index = Math.max(way.getNodes().indexOf(first), way.getNodes().indexOf(second));
|
||||
final int index = Math.max(way.getNodes().indexOf(first), way.getNodes().indexOf(second));
|
||||
way.addNode(index, toAddNode);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -42,14 +42,14 @@ public class AddPrimitivesCommand extends Command {
|
|||
public boolean executeCommand() {
|
||||
actuallyAdded.addAll(addPrimitives(getAffectedDataSet(), add));
|
||||
if (selection != null) {
|
||||
Collection<OsmPrimitive> realSelection = selection.stream()
|
||||
final Collection<OsmPrimitive> realSelection = selection.stream()
|
||||
.filter(primitive -> getAffectedDataSet().allPrimitives().contains(primitive))
|
||||
.collect(Collectors.toList());
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> getAffectedDataSet().setSelected(realSelection));
|
||||
} catch (InvocationTargetException e) {
|
||||
} catch (final InvocationTargetException e) {
|
||||
Logging.error(e);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
Logging.error(e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
@ -59,13 +59,13 @@ public class AddPrimitivesCommand extends Command {
|
|||
|
||||
@Override
|
||||
public void undoCommand() {
|
||||
DataSet ds = getAffectedDataSet();
|
||||
final DataSet ds = getAffectedDataSet();
|
||||
Utils.filteredCollection(actuallyAdded, Relation.class).stream().filter(ds::containsRelation)
|
||||
.forEach(ds::removePrimitive);
|
||||
.forEach(ds::removePrimitive);
|
||||
Utils.filteredCollection(actuallyAdded, Way.class).stream().filter(ds::containsWay)
|
||||
.forEach(ds::removePrimitive);
|
||||
.forEach(ds::removePrimitive);
|
||||
Utils.filteredCollection(actuallyAdded, Node.class).stream().filter(ds::containsNode)
|
||||
.forEach(ds::removePrimitive);
|
||||
.forEach(ds::removePrimitive);
|
||||
actuallyAdded.clear();
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class AddPrimitivesCommand extends Command {
|
|||
* @return The primitives actually added
|
||||
*/
|
||||
public static Collection<OsmPrimitive> addPrimitives(DataSet ds, Collection<OsmPrimitive> primitives) {
|
||||
Collection<OsmPrimitive> returnCollection = new ArrayList<>();
|
||||
final Collection<OsmPrimitive> returnCollection = new ArrayList<>();
|
||||
returnCollection.addAll(addRelations(ds, Utils.filteredCollection(primitives, Relation.class)));
|
||||
returnCollection.addAll(addWays(ds, Utils.filteredCollection(primitives, Way.class)));
|
||||
returnCollection.addAll(addNodes(ds, Utils.filteredCollection(primitives, Node.class)));
|
||||
|
@ -85,29 +85,29 @@ public class AddPrimitivesCommand extends Command {
|
|||
}
|
||||
|
||||
private static Collection<OsmPrimitive> addNodes(DataSet ds, Collection<Node> nodes) {
|
||||
Collection<OsmPrimitive> toAdd = nodes.stream().filter(node -> node.getDataSet() == null)
|
||||
.distinct().collect(Collectors.toList());
|
||||
final Collection<OsmPrimitive> toAdd = nodes.stream().filter(node -> node.getDataSet() == null).distinct()
|
||||
.collect(Collectors.toList());
|
||||
toAdd.stream().forEach(ds::addPrimitive);
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
private static Collection<OsmPrimitive> addWays(DataSet ds, Collection<Way> ways) {
|
||||
Collection<OsmPrimitive> toAdd = new ArrayList<>();
|
||||
final Collection<OsmPrimitive> toAdd = new ArrayList<>();
|
||||
ways.stream().map(Way::getNodes).forEach(list -> toAdd.addAll(addNodes(ds, list)));
|
||||
ways.stream().distinct()
|
||||
.filter(way -> way.getDataSet() == null
|
||||
&& way.getNodes().stream().filter(node -> node.getDataSet() != ds).count() == 0)
|
||||
.forEach(way -> {
|
||||
ds.addPrimitive(way);
|
||||
toAdd.add(way);
|
||||
});
|
||||
.filter(way -> way.getDataSet() == null
|
||||
&& way.getNodes().stream().filter(node -> node.getDataSet() != ds).count() == 0)
|
||||
.forEach(way -> {
|
||||
ds.addPrimitive(way);
|
||||
toAdd.add(way);
|
||||
});
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
// This might break with relations. TODO (not needed right now)
|
||||
private static Collection<OsmPrimitive> addRelations(DataSet ds, Collection<Relation> relations) {
|
||||
Collection<OsmPrimitive> toAdd = relations.stream().distinct().filter(relation -> relation.getDataSet() != null)
|
||||
.collect(Collectors.toList());
|
||||
final Collection<OsmPrimitive> toAdd = relations.stream().distinct()
|
||||
.filter(relation -> relation.getDataSet() != null).collect(Collectors.toList());
|
||||
toAdd.forEach(ds::addPrimitive);
|
||||
return toAdd;
|
||||
}
|
||||
|
|
|
@ -71,31 +71,32 @@ public class CreateConnectionsCommand extends Command {
|
|||
* @return
|
||||
*/
|
||||
public SequenceCommand createConnections(DataSet dataSet, Collection<OsmPrimitive> collection) {
|
||||
Collection<Node> nodes = Utils.filteredCollection(collection, Node.class);
|
||||
List<Command> changedKeyList = new ArrayList<>();
|
||||
for (Node node : nodes) {
|
||||
final Collection<Node> nodes = Utils.filteredCollection(collection, Node.class);
|
||||
final List<Command> changedKeyList = new ArrayList<>();
|
||||
for (final Node node : nodes) {
|
||||
if (node.hasKey(CONN_KEY)) {
|
||||
changedKeyList.addAll(connectedCommand(dataSet, node));
|
||||
}
|
||||
if (node.hasKey(DUPE_KEY)) {
|
||||
Command replaceCommand = duplicateNode(dataSet, node);
|
||||
final Command replaceCommand = duplicateNode(dataSet, node);
|
||||
if (replaceCommand != null) {
|
||||
changedKeyList.add(replaceCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!changedKeyList.isEmpty())
|
||||
if (!changedKeyList.isEmpty()) {
|
||||
return new SequenceCommand(getDescriptionText(), changedKeyList);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Command> connectedCommand(DataSet dataSet, Node node) {
|
||||
List<Command> commands = new ArrayList<>();
|
||||
OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(CONN_KEY));
|
||||
private static List<Command> connectedCommand(DataSet dataSet, Node node) {
|
||||
final List<Command> commands = new ArrayList<>();
|
||||
final OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(CONN_KEY));
|
||||
for (int i = 0; i < primitiveConnections.length / 3; i++) {
|
||||
if (primitiveConnections[i] instanceof Way && primitiveConnections[i + 1] instanceof Node
|
||||
&& primitiveConnections[i + 2] instanceof Node) {
|
||||
Command addNodesToWayCommand = addNodesToWay(node, (Way) primitiveConnections[i],
|
||||
final Command addNodesToWayCommand = addNodesToWay(node, (Way) primitiveConnections[i],
|
||||
(Node) primitiveConnections[i + 1], (Node) primitiveConnections[i + 2]);
|
||||
if (addNodesToWayCommand != null) {
|
||||
commands.add(addNodesToWayCommand);
|
||||
|
@ -110,8 +111,8 @@ public class CreateConnectionsCommand extends Command {
|
|||
return commands;
|
||||
}
|
||||
|
||||
private Command duplicateNode(DataSet dataSet, Node node) {
|
||||
OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(DUPE_KEY));
|
||||
private static Command duplicateNode(DataSet dataSet, Node node) {
|
||||
final OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get(DUPE_KEY));
|
||||
if (primitiveConnections.length != 1) {
|
||||
Logging.error("RapiD: dupe connection connected to more than one node? (dupe={0})", node.get(DUPE_KEY));
|
||||
}
|
||||
|
@ -126,13 +127,13 @@ public class CreateConnectionsCommand extends Command {
|
|||
* @return The primitives that the ids point to, if in the dataset.
|
||||
*/
|
||||
private static OsmPrimitive[] getPrimitives(DataSet dataSet, String ids) {
|
||||
Map<Integer, Pair<Long, OsmPrimitiveType>> missingPrimitives = new TreeMap<>();
|
||||
String[] connections = ids.split(",", -1);
|
||||
OsmPrimitive[] primitiveConnections = new OsmPrimitive[connections.length];
|
||||
final Map<Integer, Pair<Long, OsmPrimitiveType>> missingPrimitives = new TreeMap<>();
|
||||
final String[] connections = ids.split(",", -1);
|
||||
final OsmPrimitive[] primitiveConnections = new OsmPrimitive[connections.length];
|
||||
for (int i = 0; i < connections.length; i++) {
|
||||
String member = connections[i];
|
||||
long id = Long.parseLong(member.substring(1));
|
||||
char firstChar = member.charAt(0);
|
||||
final String member = connections[i];
|
||||
final long id = Long.parseLong(member.substring(1));
|
||||
final char firstChar = member.charAt(0);
|
||||
OsmPrimitiveType type = null;
|
||||
if (firstChar == 'w') {
|
||||
type = OsmPrimitiveType.WAY;
|
||||
|
@ -140,12 +141,13 @@ public class CreateConnectionsCommand extends Command {
|
|||
type = OsmPrimitiveType.NODE;
|
||||
} else if (firstChar == 'r') {
|
||||
type = OsmPrimitiveType.RELATION;
|
||||
} else
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
tr("{0}: We don't know how to handle {1} types", RapiDPlugin.NAME, firstChar));
|
||||
}
|
||||
primitiveConnections[i] = dataSet.getPrimitiveById(id, type);
|
||||
if (primitiveConnections[i] == null) {
|
||||
missingPrimitives.put(i, new Pair<Long, OsmPrimitiveType>(id, type));
|
||||
missingPrimitives.put(i, new Pair<>(id, type));
|
||||
}
|
||||
}
|
||||
getMissingPrimitives(dataSet, primitiveConnections, missingPrimitives);
|
||||
|
@ -154,24 +156,25 @@ public class CreateConnectionsCommand extends Command {
|
|||
|
||||
private static void getMissingPrimitives(DataSet dataSet, OsmPrimitive[] primitiveConnections,
|
||||
Map<Integer, Pair<Long, OsmPrimitiveType>> missingPrimitives) {
|
||||
Map<PrimitiveId, Integer> ids = missingPrimitives.entrySet().stream().collect(Collectors.toMap(
|
||||
entry -> new SimplePrimitiveId(entry.getValue().a, entry.getValue().b), Entry::getKey));
|
||||
List<PrimitiveId> toFetch = new ArrayList<>(ids.keySet());
|
||||
Optional<OsmDataLayer> optionalLayer = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)
|
||||
.parallelStream().filter(layer -> layer.getDataSet().equals(dataSet)).findFirst();
|
||||
final Map<PrimitiveId, Integer> ids = missingPrimitives.entrySet().stream().collect(Collectors
|
||||
.toMap(entry -> new SimplePrimitiveId(entry.getValue().a, entry.getValue().b), Entry::getKey));
|
||||
final List<PrimitiveId> toFetch = new ArrayList<>(ids.keySet());
|
||||
final Optional<OsmDataLayer> optionalLayer = MainApplication.getLayerManager()
|
||||
.getLayersOfType(OsmDataLayer.class).parallelStream()
|
||||
.filter(layer -> layer.getDataSet().equals(dataSet)).findFirst();
|
||||
OsmDataLayer layer;
|
||||
if (optionalLayer.isPresent()) {
|
||||
layer = optionalLayer.get();
|
||||
} else {
|
||||
layer = new OsmDataLayer(dataSet, "generated layer", null);
|
||||
}
|
||||
PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Downloading additional OsmPrimitives"));
|
||||
DownloadPrimitivesTask downloadPrimitivesTask = new DownloadPrimitivesTask(layer, toFetch, true,
|
||||
monitor);
|
||||
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(
|
||||
tr("Downloading additional OsmPrimitives"));
|
||||
final DownloadPrimitivesTask downloadPrimitivesTask = new DownloadPrimitivesTask(layer, toFetch, true, monitor);
|
||||
downloadPrimitivesTask.run();
|
||||
for (Entry<PrimitiveId, Integer> entry : ids.entrySet()) {
|
||||
int index = entry.getValue().intValue();
|
||||
OsmPrimitive primitive = dataSet.getPrimitiveById(entry.getKey());
|
||||
for (final Entry<PrimitiveId, Integer> entry : ids.entrySet()) {
|
||||
final int index = entry.getValue().intValue();
|
||||
final OsmPrimitive primitive = dataSet.getPrimitiveById(entry.getKey());
|
||||
primitiveConnections[index] = primitive;
|
||||
}
|
||||
}
|
||||
|
@ -187,10 +190,10 @@ public class CreateConnectionsCommand extends Command {
|
|||
*/
|
||||
public static Command addNodesToWay(Node toAddNode, Way way, Node first, Node second) {
|
||||
Command tCommand = null;
|
||||
Way tWay = new Way();
|
||||
final Way tWay = new Way();
|
||||
tWay.addNode(first);
|
||||
tWay.addNode(second);
|
||||
double distance = Geometry.getDistanceWayNode(tWay, toAddNode);
|
||||
final double distance = Geometry.getDistanceWayNode(tWay, toAddNode);
|
||||
if (distance < 5) {
|
||||
tCommand = new AddNodeToWayCommand(toAddNode, way, first, second);
|
||||
}
|
||||
|
|
|
@ -2,16 +2,20 @@ package org.openstreetmap.josm.plugins.rapid.commands;
|
|||
|
||||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.openstreetmap.josm.command.Command;
|
||||
import org.openstreetmap.josm.data.osm.DataSet;
|
||||
import org.openstreetmap.josm.data.osm.Node;
|
||||
import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
||||
import org.openstreetmap.josm.data.osm.Way;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
public class DeletePrimitivesCommand extends Command {
|
||||
private final Collection<OsmPrimitive> selection;
|
||||
|
@ -48,18 +52,25 @@ public class DeletePrimitivesCommand extends Command {
|
|||
|
||||
@Override
|
||||
public boolean executeCommand() {
|
||||
for (OsmPrimitive primitive : selection) {
|
||||
DataSet dataSet = primitive.getDataSet();
|
||||
for (final OsmPrimitive primitive : selection) {
|
||||
final DataSet dataSet = primitive.getDataSet();
|
||||
|
||||
if (from.equals(dataSet)) {
|
||||
dataSet.removePrimitive(primitive);
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> dataSet.removePrimitive(primitive));
|
||||
} catch (final InvocationTargetException e) {
|
||||
Logging.debug(e);
|
||||
} catch (final InterruptedException e) {
|
||||
Logging.debug(e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
removed.add(primitive);
|
||||
}
|
||||
if (primitive instanceof Way) {
|
||||
List<OsmPrimitive> nodes = ((Way) primitive).getNodes().stream()
|
||||
final List<OsmPrimitive> nodes = ((Way) primitive).getNodes().stream()
|
||||
.filter(node -> (!node.hasKeys() || deleteChildren) && !selection.contains(node))
|
||||
.collect(Collectors.toList());
|
||||
DeletePrimitivesCommand delNodes = new DeletePrimitivesCommand(from, nodes);
|
||||
final DeletePrimitivesCommand delNodes = new DeletePrimitivesCommand(from, nodes);
|
||||
delNodes.executeCommand();
|
||||
commands.add(delNodes);
|
||||
}
|
||||
|
@ -69,16 +80,16 @@ public class DeletePrimitivesCommand extends Command {
|
|||
|
||||
@Override
|
||||
public void undoCommand() {
|
||||
for (Command command : commands) {
|
||||
for (final Command command : commands) {
|
||||
command.undoCommand();
|
||||
}
|
||||
for (OsmPrimitive primitive : removed) {
|
||||
DataSet removedPrimitiveDataSet = primitive.getDataSet();
|
||||
for (final OsmPrimitive primitive : removed) {
|
||||
final DataSet removedPrimitiveDataSet = primitive.getDataSet();
|
||||
if (removedPrimitiveDataSet != null) {
|
||||
removedPrimitiveDataSet.removePrimitive(primitive);
|
||||
}
|
||||
if (primitive instanceof Way) {
|
||||
for (Node node : ((Way) primitive).getNodes()) {
|
||||
for (final Node node : ((Way) primitive).getNodes()) {
|
||||
if (node.getDataSet() == null) {
|
||||
from.addPrimitive(node);
|
||||
}
|
||||
|
@ -96,7 +107,7 @@ public class DeletePrimitivesCommand extends Command {
|
|||
@Override
|
||||
public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
||||
Collection<OsmPrimitive> added) {
|
||||
for (Command command : commands) {
|
||||
for (final Command command : commands) {
|
||||
command.fillModifiedData(modified, deleted, added);
|
||||
}
|
||||
deleted.addAll(removed);
|
||||
|
|
|
@ -43,6 +43,7 @@ public class MovePrimitiveDataSetCommand extends Command {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move primitives from one dataset to another
|
||||
*
|
||||
|
@ -56,13 +57,13 @@ public class MovePrimitiveDataSetCommand extends Command {
|
|||
return null;
|
||||
}
|
||||
|
||||
List<Command> commands = new ArrayList<>();
|
||||
final List<Command> commands = new ArrayList<>();
|
||||
|
||||
Collection<OsmPrimitive> allNeededPrimitives = new ArrayList<>();
|
||||
final Collection<OsmPrimitive> allNeededPrimitives = new ArrayList<>();
|
||||
RapiDDataUtils.addPrimitivesToCollection(allNeededPrimitives, selection);
|
||||
|
||||
commands.add(new DeletePrimitivesCommand(from, selection, true));
|
||||
AddPrimitivesCommand addPrimitivesCommand = new AddPrimitivesCommand(to, allNeededPrimitives, selection);
|
||||
final AddPrimitivesCommand addPrimitivesCommand = new AddPrimitivesCommand(to, allNeededPrimitives, selection);
|
||||
commands.add(addPrimitivesCommand);
|
||||
|
||||
return new SequenceCommand(trn("Move {0} OSM Primitive between data sets",
|
||||
|
|
|
@ -21,20 +21,20 @@ public class RapiDAddCommand extends Command implements Runnable {
|
|||
DataSet editable;
|
||||
DataSet rapid;
|
||||
Collection<OsmPrimitive> primitives;
|
||||
Collection<OsmPrimitive> modifiedPrimitives;
|
||||
Command command = null;
|
||||
|
||||
OsmDataLayer editLayer = null;
|
||||
|
||||
/**
|
||||
* Add primitives from RapiD to the OSM data layer
|
||||
*
|
||||
* @param rapidLayer The rapid layer
|
||||
* @param editableLayer The OSM layer
|
||||
* @param selection The primitives to add from RapiD
|
||||
*/
|
||||
public RapiDAddCommand(RapiDLayer rapidLayer, OsmDataLayer editLayer, Collection<OsmPrimitive> selection) {
|
||||
super(rapidLayer.getDataSet());
|
||||
this.rapid = rapidLayer.getDataSet();
|
||||
this.editable = editLayer.getDataSet();
|
||||
this.primitives = selection;
|
||||
this.editLayer = editLayer;
|
||||
modifiedPrimitives = null;
|
||||
this(rapidLayer.getDataSet(), editLayer.getDataSet(), selection);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add primitives from RapiD to the OSM data layer
|
||||
*
|
||||
|
@ -47,7 +47,6 @@ public class RapiDAddCommand extends Command implements Runnable {
|
|||
this.rapid = rapid;
|
||||
this.editable = editable;
|
||||
this.primitives = selection;
|
||||
modifiedPrimitives = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,12 +69,12 @@ public class RapiDAddCommand extends Command implements Runnable {
|
|||
primitives = new HashSet<>(primitives);
|
||||
RapiDDataUtils.addPrimitivesToCollection(/* collection= */ primitives, /* primitives= */ primitives);
|
||||
synchronized (this) {
|
||||
boolean locked = rapid.isLocked();
|
||||
final boolean locked = rapid.isLocked();
|
||||
if (locked) {
|
||||
rapid.unlock();
|
||||
}
|
||||
Command tCommand = new MovePrimitiveDataSetCommand(editable, rapid, primitives);
|
||||
Command createConnectionsCommand = createConnections(editable, primitives);
|
||||
final Command tCommand = new MovePrimitiveDataSetCommand(editable, rapid, primitives);
|
||||
final Command createConnectionsCommand = createConnections(editable, primitives);
|
||||
command = new SequenceCommand(getDescriptionText(), tCommand, createConnectionsCommand);
|
||||
command.executeCommand();
|
||||
|
||||
|
@ -99,12 +98,14 @@ public class RapiDAddCommand extends Command implements Runnable {
|
|||
|
||||
@Override
|
||||
public void undoCommand() {
|
||||
boolean locked = rapid.isLocked();
|
||||
final boolean locked = rapid.isLocked();
|
||||
if (locked) {
|
||||
rapid.unlock();
|
||||
}
|
||||
if (command != null) {
|
||||
command.undoCommand();
|
||||
synchronized (this) {
|
||||
if (command != null) {
|
||||
command.undoCommand();
|
||||
}
|
||||
}
|
||||
if (locked) {
|
||||
rapid.lock();
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.rapid;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
|
||||
|
@ -25,14 +26,14 @@ public class RapiDPluginTest {
|
|||
public PluginInformation info;
|
||||
public RapiDPlugin plugin;
|
||||
|
||||
private static String VERSION = "no-such-version";
|
||||
private static final String VERSION = "no-such-version";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
InputStream in = new ByteArrayInputStream("".getBytes());
|
||||
final InputStream in = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8));
|
||||
info = new PluginInformation(in, "Rapid", null);
|
||||
info.localversion = VERSION;
|
||||
}
|
||||
|
@ -51,9 +52,9 @@ public class RapiDPluginTest {
|
|||
*/
|
||||
@Test
|
||||
public void testRapiDPlugin() {
|
||||
JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
||||
int originalPaintStyles = MapPaintPrefHelper.INSTANCE.get().size();
|
||||
int dataMenuSize = dataMenu.getMenuComponentCount();
|
||||
final JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
||||
final int originalPaintStyles = MapPaintPrefHelper.INSTANCE.get().size();
|
||||
final int dataMenuSize = dataMenu.getMenuComponentCount();
|
||||
plugin = new RapiDPlugin(info);
|
||||
Assert.assertEquals(dataMenuSize + 2, dataMenu.getMenuComponentCount());
|
||||
Assert.assertEquals(originalPaintStyles + 1, MapPaintPrefHelper.INSTANCE.get().size());
|
||||
|
|
|
@ -34,38 +34,40 @@ public class RapiDPreferencesTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAddGui() {
|
||||
PreferenceTabbedPane pane = new PreferenceTabbedPane();
|
||||
final PreferenceTabbedPane pane = new PreferenceTabbedPane();
|
||||
pane.buildGui();
|
||||
int tabs = pane.getPluginPreference().getTabPane().getTabCount();
|
||||
final int tabs = pane.getPluginPreference().getTabPane().getTabCount();
|
||||
|
||||
preferences.addGui(pane);
|
||||
|
||||
Assert.assertEquals(tabs + 1, pane.getPluginPreference().getTabPane().getTabCount());
|
||||
Assert.assertEquals(pane.getPluginPreference(), preferences.getTabPreferenceSetting(pane));
|
||||
|
||||
boolean switchLayers = RapiDDataUtils.getSwitchLayers();
|
||||
final boolean switchLayers = RapiDDataUtils.getSwitchLayers();
|
||||
|
||||
Assert.assertEquals(switchLayers, preferences.switchLayerCheckBox.isSelected());
|
||||
Assert.assertEquals(switchLayers, preferences.getSwitchLayerCheckBox().isSelected());
|
||||
preferences.ok();
|
||||
Assert.assertEquals(switchLayers, RapiDDataUtils.getSwitchLayers());
|
||||
|
||||
preferences.switchLayerCheckBox.setSelected(!switchLayers);
|
||||
preferences.getSwitchLayerCheckBox().setSelected(!switchLayers);
|
||||
Assert.assertNotEquals(!switchLayers, RapiDDataUtils.getSwitchLayers());
|
||||
preferences.ok();
|
||||
Assert.assertEquals(!switchLayers, RapiDDataUtils.getSwitchLayers());
|
||||
|
||||
Object tmp = preferences.maximumAdditionSpinner.getModel();
|
||||
final Object tmp = preferences.getMaximumAdditionSpinner().getModel();
|
||||
SpinnerNumberModel spinnerModel = null;
|
||||
if (tmp instanceof SpinnerNumberModel) {
|
||||
spinnerModel = (SpinnerNumberModel) tmp;
|
||||
}
|
||||
Assert.assertNotNull(spinnerModel);
|
||||
Number currentNumber = RapiDDataUtils.getMaximumAddition();
|
||||
final Number currentNumber = RapiDDataUtils.getMaximumAddition();
|
||||
Assert.assertEquals(currentNumber.intValue(), spinnerModel.getNumber().intValue());
|
||||
spinnerModel.setValue(currentNumber.intValue() + 3);
|
||||
Assert.assertNotEquals(spinnerModel.getNumber().intValue(), RapiDDataUtils.getMaximumAddition());
|
||||
preferences.ok();
|
||||
Assert.assertEquals(spinnerModel.getNumber().intValue(), RapiDDataUtils.getMaximumAddition());
|
||||
|
||||
Assert.assertNotNull(preferences.getPossibleRapidApiUrl().getSelectedItem());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,8 +33,8 @@ public class RapiDActionTest {
|
|||
|
||||
@Test
|
||||
public void testGetData() {
|
||||
RapiDLayer rapid = RapiDAction.getLayer(true);
|
||||
OsmDataLayer osm = new OsmDataLayer(new DataSet(), "test", null);
|
||||
final RapiDLayer rapid = RapiDAction.getLayer(true);
|
||||
final OsmDataLayer osm = new OsmDataLayer(new DataSet(), "test", null);
|
||||
MainApplication.getLayerManager().addLayer(osm);
|
||||
RapiDAction.getRapiDData(rapid, osm);
|
||||
|
||||
|
|
|
@ -26,20 +26,22 @@ public class RapiDDataUtilsTest {
|
|||
public JOSMTestRules test = new JOSMTestRules().preferences();
|
||||
|
||||
/**
|
||||
* This gets data from RapiD. This test may fail if someone adds the data to OSM.
|
||||
* This gets data from RapiD. This test may fail if someone adds the data to
|
||||
* OSM.
|
||||
*/
|
||||
@Test
|
||||
public void testGetData() {
|
||||
BBox testBBox = getTestBBox();
|
||||
DataSet ds = new DataSet(RapiDDataUtils.getData(testBBox));
|
||||
final BBox testBBox = getTestBBox();
|
||||
final DataSet ds = new DataSet(RapiDDataUtils.getData(testBBox));
|
||||
Assert.assertEquals(1, ds.getWays().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddSourceTags() {
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0.1, 0.1)));
|
||||
DataSet ds = new DataSet(way1.firstNode(), way1.lastNode(), way1);
|
||||
String source = "random source";
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0.1, 0.1)));
|
||||
final DataSet ds = new DataSet(way1.firstNode(), way1.lastNode(), way1);
|
||||
final String source = "random source";
|
||||
|
||||
Assert.assertNull(way1.get("source"));
|
||||
RapiDDataUtils.addSourceTags(ds, "highway", source);
|
||||
|
@ -47,7 +49,7 @@ public class RapiDDataUtilsTest {
|
|||
}
|
||||
|
||||
public static BBox getTestBBox() {
|
||||
BBox testBBox = new BBox();
|
||||
final BBox testBBox = new BBox();
|
||||
testBBox.add(new LatLon(39.076, -108.547));
|
||||
testBBox.add(new LatLon(39.078, -108.545));
|
||||
return testBBox;
|
||||
|
@ -55,8 +57,9 @@ public class RapiDDataUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testAddPrimitivesToCollection() {
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.1)));
|
||||
Collection<OsmPrimitive> collection = new TreeSet<>();
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0, 0.1)));
|
||||
final Collection<OsmPrimitive> collection = new TreeSet<>();
|
||||
Assert.assertEquals(0, collection.size());
|
||||
RapiDDataUtils.addPrimitivesToCollection(collection, Collections.singletonList(way1));
|
||||
Assert.assertEquals(3, collection.size());
|
||||
|
@ -64,9 +67,10 @@ public class RapiDDataUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testRemovePrimitivesFromDataSet() {
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.1)));
|
||||
DataSet ds1 = new DataSet();
|
||||
for (Node node : way1.getNodes()) {
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0, 0.1)));
|
||||
final DataSet ds1 = new DataSet();
|
||||
for (final Node node : way1.getNodes()) {
|
||||
ds1.addPrimitive(node);
|
||||
}
|
||||
ds1.addPrimitive(way1);
|
||||
|
@ -92,11 +96,11 @@ public class RapiDDataUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testRapiDURLPreferences() {
|
||||
String fakeUrl = "https://fake.url";
|
||||
final String fakeUrl = "https://fake.url";
|
||||
Assert.assertEquals(RapiDDataUtils.DEFAULT_RAPID_API, RapiDDataUtils.getRapiDURL());
|
||||
RapiDDataUtils.setRapiDUrl(fakeUrl);
|
||||
Assert.assertEquals(fakeUrl, RapiDDataUtils.getRapiDURL());
|
||||
List<String> urls = new ArrayList<>(RapiDDataUtils.getRapiDURLs());
|
||||
final List<String> urls = new ArrayList<>(RapiDDataUtils.getRapiDURLs());
|
||||
Assert.assertEquals(2, urls.size());
|
||||
RapiDDataUtils.setRapiDUrl(RapiDDataUtils.DEFAULT_RAPID_API);
|
||||
Assert.assertEquals(RapiDDataUtils.DEFAULT_RAPID_API, RapiDDataUtils.getRapiDURL());
|
||||
|
@ -109,7 +113,7 @@ public class RapiDDataUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testSplitBounds() {
|
||||
BBox bbox = new BBox(0, 0, 0.0001, 0.0001);
|
||||
final BBox bbox = new BBox(0, 0, 0.0001, 0.0001);
|
||||
List<BBox> bboxes = RapiDDataUtils.reduceBBoxSize(bbox);
|
||||
Assert.assertEquals(1, bboxes.size());
|
||||
checkInBBox(bbox, bboxes);
|
||||
|
@ -135,8 +139,8 @@ public class RapiDDataUtilsTest {
|
|||
checkInBBox(bbox, bboxes);
|
||||
}
|
||||
|
||||
private void checkInBBox(BBox bbox, Collection<BBox> bboxes) {
|
||||
for (BBox tBBox : bboxes) {
|
||||
private static void checkInBBox(BBox bbox, Collection<BBox> bboxes) {
|
||||
for (final BBox tBBox : bboxes) {
|
||||
Assert.assertTrue(bbox.bounds(tBBox));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,18 +28,20 @@ public class RapiDMoveActionTest {
|
|||
|
||||
@Test
|
||||
public void testMoveAction() {
|
||||
DataSet osmData = new DataSet();
|
||||
DataSet rapidData = new DataSet();
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0.1, 0.1)));
|
||||
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.1)),
|
||||
final DataSet osmData = new DataSet();
|
||||
final DataSet rapidData = new DataSet();
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0.1, 0.1)));
|
||||
final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.1)),
|
||||
new Node(new LatLon(0.1, 0.1)));
|
||||
way1.getNodes().forEach(node -> rapidData.addPrimitive(node));
|
||||
way2.getNodes().forEach(node -> osmData.addPrimitive(node));
|
||||
osmData.addPrimitive(way2);
|
||||
rapidData.addPrimitive(way1);
|
||||
|
||||
OsmDataLayer osmLayer = new OsmDataLayer(osmData, "osm", null);
|
||||
RapiDLayer rapidLayer = new RapiDLayer(RapiDDataUtils.getData(RapiDDataUtilsTest.getTestBBox()), "rapid", null);
|
||||
final OsmDataLayer osmLayer = new OsmDataLayer(osmData, "osm", null);
|
||||
final RapiDLayer rapidLayer = new RapiDLayer(RapiDDataUtils.getData(RapiDDataUtilsTest.getTestBBox()), "rapid",
|
||||
null);
|
||||
MainApplication.getLayerManager().addLayer(osmLayer);
|
||||
MainApplication.getLayerManager().addLayer(rapidLayer);
|
||||
MainApplication.getLayerManager().setActiveLayer(rapidLayer);
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.openstreetmap.josm.data.osm.DataSet;
|
|||
import org.openstreetmap.josm.data.osm.Node;
|
||||
import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
||||
import org.openstreetmap.josm.data.osm.Way;
|
||||
import org.openstreetmap.josm.plugins.rapid.commands.AddNodeToWayCommand;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;;
|
||||
|
||||
public class AddNodeToWayCommandTest {
|
||||
|
@ -56,9 +55,9 @@ public class AddNodeToWayCommandTest {
|
|||
|
||||
@Test
|
||||
public void testModifiedAddedDeleted() {
|
||||
List<OsmPrimitive> added = new ArrayList<>();
|
||||
List<OsmPrimitive> modified = new ArrayList<>();
|
||||
List<OsmPrimitive> deleted = new ArrayList<>();
|
||||
final List<OsmPrimitive> added = new ArrayList<>();
|
||||
final List<OsmPrimitive> modified = new ArrayList<>();
|
||||
final List<OsmPrimitive> deleted = new ArrayList<>();
|
||||
command.fillModifiedData(modified, deleted, added);
|
||||
Assert.assertTrue(deleted.isEmpty());
|
||||
Assert.assertTrue(added.isEmpty());
|
||||
|
|
|
@ -23,11 +23,12 @@ public class AddPrimitivesCommandTest {
|
|||
|
||||
@Test
|
||||
public void testAddPrimitives() {
|
||||
DataSet dataSet = new DataSet();
|
||||
Way way1 = TestUtils.newWay("highway=secondary", new Node(new LatLon(0, 0)), new Node(new LatLon(0.1, 0.1)));
|
||||
final DataSet dataSet = new DataSet();
|
||||
final Way way1 = TestUtils.newWay("highway=secondary", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0.1, 0.1)));
|
||||
Assert.assertNull(way1.getDataSet());
|
||||
|
||||
Collection<OsmPrimitive> added = AddPrimitivesCommand.addPrimitives(dataSet, Collections.singleton(way1));
|
||||
final Collection<OsmPrimitive> added = AddPrimitivesCommand.addPrimitives(dataSet, Collections.singleton(way1));
|
||||
Assert.assertEquals(3, added.size());
|
||||
Assert.assertSame(dataSet, way1.getDataSet());
|
||||
}
|
||||
|
@ -35,13 +36,14 @@ public class AddPrimitivesCommandTest {
|
|||
@SuppressWarnings("UndefinedEquals")
|
||||
@Test
|
||||
public void testUndoRedo() {
|
||||
DataSet dataSet = new DataSet();
|
||||
List<OsmPrimitive> added = new ArrayList<>();
|
||||
List<OsmPrimitive> modified = new ArrayList<>();
|
||||
List<OsmPrimitive> deleted = new ArrayList<>();
|
||||
Way way1 = TestUtils.newWay("highway=secondary", new Node(new LatLon(0, 0)), new Node(new LatLon(0.1, -0.1)));
|
||||
final DataSet dataSet = new DataSet();
|
||||
final List<OsmPrimitive> added = new ArrayList<>();
|
||||
final List<OsmPrimitive> modified = new ArrayList<>();
|
||||
final List<OsmPrimitive> deleted = new ArrayList<>();
|
||||
final Way way1 = TestUtils.newWay("highway=secondary", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0.1, -0.1)));
|
||||
AddPrimitivesCommand command = new AddPrimitivesCommand(dataSet, Collections.singleton(way1), null);
|
||||
Collection<OsmPrimitive> selection = dataSet.getAllSelected();
|
||||
final Collection<OsmPrimitive> selection = dataSet.getAllSelected();
|
||||
Assert.assertNull(way1.getDataSet());
|
||||
|
||||
command.executeCommand();
|
||||
|
|
|
@ -32,15 +32,15 @@ public class CreateConnectionsCommandTest {
|
|||
*/
|
||||
@Test
|
||||
public void testCreateConnections() {
|
||||
Node node1 = new Node(new LatLon(0, 0));
|
||||
Node node2 = new Node(new LatLon(1, 0));
|
||||
Node node3 = new Node(new LatLon(0.5, 0));
|
||||
Node dupe = new Node(new LatLon(0, 0));
|
||||
Way way = TestUtils.newWay("highway=residential", node1, node2);
|
||||
Collection<OsmPrimitive> added = new ArrayList<>();
|
||||
Collection<OsmPrimitive> modified = new ArrayList<>();
|
||||
Collection<OsmPrimitive> deleted = new ArrayList<>();
|
||||
DataSet dataSet = new DataSet(node1, node2, node3, dupe, way);
|
||||
final Node node1 = new Node(new LatLon(0, 0));
|
||||
final Node node2 = new Node(new LatLon(1, 0));
|
||||
final Node node3 = new Node(new LatLon(0.5, 0));
|
||||
final Node dupe = new Node(new LatLon(0, 0));
|
||||
final Way way = TestUtils.newWay("highway=residential", node1, node2);
|
||||
final Collection<OsmPrimitive> added = new ArrayList<>();
|
||||
final Collection<OsmPrimitive> modified = new ArrayList<>();
|
||||
final Collection<OsmPrimitive> deleted = new ArrayList<>();
|
||||
final DataSet dataSet = new DataSet(node1, node2, node3, dupe, way);
|
||||
|
||||
Command createConnections = new CreateConnectionsCommand(dataSet, Collections.singleton(node3));
|
||||
createConnections.executeCommand();
|
||||
|
@ -84,10 +84,10 @@ public class CreateConnectionsCommandTest {
|
|||
*/
|
||||
@Test
|
||||
public void testAddNodesToWay() {
|
||||
Node node1 = new Node(new LatLon(0, 0));
|
||||
Node node2 = new Node(new LatLon(1, 0));
|
||||
Node node3 = new Node(new LatLon(0.5, 0));
|
||||
Way way = TestUtils.newWay("highway=residential", node1, node2);
|
||||
final Node node1 = new Node(new LatLon(0, 0));
|
||||
final Node node2 = new Node(new LatLon(1, 0));
|
||||
final Node node3 = new Node(new LatLon(0.5, 0));
|
||||
final Way way = TestUtils.newWay("highway=residential", node1, node2);
|
||||
new DataSet(node1, node2, node3, way);
|
||||
Command addNodeToWayCommand = CreateConnectionsCommand.addNodesToWay(node3, way, node1, node2);
|
||||
Assert.assertEquals(2, way.getNodesCount());
|
||||
|
@ -117,10 +117,10 @@ public class CreateConnectionsCommandTest {
|
|||
*/
|
||||
@Test
|
||||
public void testReplaceNode() {
|
||||
Node node1 = new Node(new LatLon(0, 0));
|
||||
Node node2 = new Node(new LatLon(0, 0));
|
||||
final Node node1 = new Node(new LatLon(0, 0));
|
||||
final Node node2 = new Node(new LatLon(0, 0));
|
||||
new DataSet(node1, node2);
|
||||
Command replaceNodeCommand = CreateConnectionsCommand.replaceNode(node1, node2);
|
||||
final Command replaceNodeCommand = CreateConnectionsCommand.replaceNode(node1, node2);
|
||||
replaceNodeCommand.executeCommand();
|
||||
Assert.assertTrue(node1.isDeleted());
|
||||
replaceNodeCommand.undoCommand();
|
||||
|
@ -135,7 +135,7 @@ public class CreateConnectionsCommandTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetDescriptionText() {
|
||||
String text = new CreateConnectionsCommand(new DataSet(), null).getDescriptionText();
|
||||
final String text = new CreateConnectionsCommand(new DataSet(), null).getDescriptionText();
|
||||
Assert.assertNotNull(text);
|
||||
Assert.assertFalse(text.isEmpty());
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.openstreetmap.josm.data.coor.LatLon;
|
|||
import org.openstreetmap.josm.data.osm.DataSet;
|
||||
import org.openstreetmap.josm.data.osm.Node;
|
||||
import org.openstreetmap.josm.data.osm.Way;
|
||||
import org.openstreetmap.josm.plugins.rapid.commands.DeletePrimitivesCommand;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
|
||||
public class DeletePrimitivesCommandTest {
|
||||
|
@ -20,8 +19,9 @@ public class DeletePrimitivesCommandTest {
|
|||
|
||||
@Test
|
||||
public void testDeletePrimitives() {
|
||||
DataSet ds = new DataSet();
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(-0.1, 0.1)));
|
||||
final DataSet ds = new DataSet();
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(-0.1, 0.1)));
|
||||
way1.getNodes().forEach(node -> ds.addPrimitive(node));
|
||||
ds.addPrimitive(way1);
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class DeletePrimitivesCommandTest {
|
|||
Assert.assertTrue(ds.containsWay(way1));
|
||||
Assert.assertEquals(3, ds.allPrimitives().size());
|
||||
|
||||
Node tNode = new Node(new LatLon(0.1, 0.1));
|
||||
final Node tNode = new Node(new LatLon(0.1, 0.1));
|
||||
ds.addPrimitive(tNode);
|
||||
Assert.assertEquals(4, ds.allPrimitives().size());
|
||||
|
||||
|
|
|
@ -23,12 +23,13 @@ public class MovePrimitiveDataSetCommandTest {
|
|||
|
||||
@Test
|
||||
public void testMovePrimitives() {
|
||||
Collection<OsmPrimitive> added = new ArrayList<>();
|
||||
Collection<OsmPrimitive> modified = new ArrayList<>();
|
||||
Collection<OsmPrimitive> deleted = new ArrayList<>();
|
||||
DataSet to = new DataSet();
|
||||
DataSet from = new DataSet();
|
||||
Way way1 = TestUtils.newWay("highway=tertiary", new Node(new LatLon(0, 0)), new Node(new LatLon(0.1, 0.1)));
|
||||
final Collection<OsmPrimitive> added = new ArrayList<>();
|
||||
final Collection<OsmPrimitive> modified = new ArrayList<>();
|
||||
final Collection<OsmPrimitive> deleted = new ArrayList<>();
|
||||
final DataSet to = new DataSet();
|
||||
final DataSet from = new DataSet();
|
||||
final Way way1 = TestUtils.newWay("highway=tertiary", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0.1, 0.1)));
|
||||
way1.getNodes().stream().forEach(node -> from.addPrimitive(node));
|
||||
from.addPrimitive(way1);
|
||||
from.addPrimitive(new Node(new LatLon(-0.1, 0.1)));
|
||||
|
@ -70,7 +71,7 @@ public class MovePrimitiveDataSetCommandTest {
|
|||
Assert.assertEquals(4, from.allPrimitives().size());
|
||||
Assert.assertEquals(from, way1.getDataSet());
|
||||
|
||||
for (DataSet ds : Arrays.asList(from, to)) {
|
||||
for (final DataSet ds : Arrays.asList(from, to)) {
|
||||
ds.lock();
|
||||
move.executeCommand();
|
||||
Assert.assertEquals(0, to.allPrimitives().size());
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.openstreetmap.josm.data.osm.DataSet;
|
|||
import org.openstreetmap.josm.data.osm.Node;
|
||||
import org.openstreetmap.josm.data.osm.Tag;
|
||||
import org.openstreetmap.josm.data.osm.Way;
|
||||
import org.openstreetmap.josm.plugins.rapid.commands.RapiDAddCommand;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
|
||||
public class RapiDAddComandTest {
|
||||
|
@ -22,13 +21,15 @@ public class RapiDAddComandTest {
|
|||
|
||||
@Test
|
||||
public void testMoveCollection() {
|
||||
DataSet ds1 = new DataSet();
|
||||
DataSet ds2 = new DataSet();
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.1)));
|
||||
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.2)), way1.firstNode());
|
||||
Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(65, 65)), new Node(new LatLon(66, 66)));
|
||||
for (Way way : Arrays.asList(way1, way2, way3)) {
|
||||
for (Node node : way.getNodes()) {
|
||||
final DataSet ds1 = new DataSet();
|
||||
final DataSet ds2 = new DataSet();
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0, 0.1)));
|
||||
final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.2)), way1.firstNode());
|
||||
final Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(65, 65)),
|
||||
new Node(new LatLon(66, 66)));
|
||||
for (final Way way : Arrays.asList(way1, way2, way3)) {
|
||||
for (final Node node : way.getNodes()) {
|
||||
if (!ds1.containsNode(node)) {
|
||||
ds1.addPrimitive(node);
|
||||
}
|
||||
|
@ -66,14 +67,15 @@ public class RapiDAddComandTest {
|
|||
|
||||
@Test
|
||||
public void testCreateConnections() {
|
||||
DataSet ds1 = new DataSet();
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.15)));
|
||||
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0.05)),
|
||||
final DataSet ds1 = new DataSet();
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0, 0.15)));
|
||||
final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0.05)),
|
||||
new Node(new LatLon(0.05, 0.2)));
|
||||
way2.firstNode().put("conn",
|
||||
"w".concat(Long.toString(way1.getUniqueId())).concat(",n")
|
||||
.concat(Long.toString(way1.firstNode().getUniqueId())).concat(",n")
|
||||
.concat(Long.toString(way1.lastNode().getUniqueId())));
|
||||
.concat(Long.toString(way1.firstNode().getUniqueId())).concat(",n")
|
||||
.concat(Long.toString(way1.lastNode().getUniqueId())));
|
||||
way1.getNodes().forEach(node -> ds1.addPrimitive(node));
|
||||
way2.getNodes().forEach(node -> ds1.addPrimitive(node));
|
||||
ds1.addPrimitive(way2);
|
||||
|
@ -82,12 +84,12 @@ public class RapiDAddComandTest {
|
|||
Assert.assertEquals(3, way1.getNodesCount());
|
||||
Assert.assertFalse(way1.isFirstLastNode(way2.firstNode()));
|
||||
|
||||
Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
final Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(-0.1, -0.1)));
|
||||
way3.firstNode().put("dupe", "n".concat(Long.toString(way1.firstNode().getUniqueId())));
|
||||
way3.getNodes().forEach(node -> ds1.addPrimitive(node));
|
||||
ds1.addPrimitive(way3);
|
||||
Node way3Node1 = way3.firstNode();
|
||||
final Node way3Node1 = way3.firstNode();
|
||||
RapiDAddCommand.createConnections(ds1, Collections.singletonList(way3.firstNode())).executeCommand();
|
||||
Assert.assertNotEquals(way3Node1, way3.firstNode());
|
||||
Assert.assertEquals(way1.firstNode(), way3.firstNode());
|
||||
|
@ -96,10 +98,11 @@ public class RapiDAddComandTest {
|
|||
|
||||
@Test
|
||||
public void testCreateConnectionsUndo() {
|
||||
DataSet osmData = new DataSet();
|
||||
DataSet rapidData = new DataSet();
|
||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0.1, 0.1)));
|
||||
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.1)),
|
||||
final DataSet osmData = new DataSet();
|
||||
final DataSet rapidData = new DataSet();
|
||||
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||
new Node(new LatLon(0.1, 0.1)));
|
||||
final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.1)),
|
||||
new Node(new LatLon(0.1, 0.1)));
|
||||
way1.getNodes().forEach(node -> rapidData.addPrimitive(node));
|
||||
way2.getNodes().forEach(node -> osmData.addPrimitive(node));
|
||||
|
@ -110,7 +113,7 @@ public class RapiDAddComandTest {
|
|||
Assert.assertEquals(3, osmData.allPrimitives().size());
|
||||
Assert.assertEquals(3, rapidData.allPrimitives().size());
|
||||
|
||||
RapiDAddCommand command = new RapiDAddCommand(rapidData, osmData, rapidData.getSelected());
|
||||
final RapiDAddCommand command = new RapiDAddCommand(rapidData, osmData, rapidData.getSelected());
|
||||
command.executeCommand();
|
||||
Assert.assertEquals(6, osmData.allPrimitives().size());
|
||||
Assert.assertTrue(rapidData.allPrimitives().isEmpty());
|
||||
|
@ -119,7 +122,7 @@ public class RapiDAddComandTest {
|
|||
Assert.assertEquals(3, osmData.allPrimitives().size());
|
||||
Assert.assertEquals(3, rapidData.allPrimitives().size());
|
||||
|
||||
Tag dupe = new Tag("dupe", "n".concat(Long.toString(way2.lastNode().getUniqueId())));
|
||||
final Tag dupe = new Tag("dupe", "n".concat(Long.toString(way2.lastNode().getUniqueId())));
|
||||
way1.lastNode().put(dupe);
|
||||
command.executeCommand();
|
||||
Assert.assertEquals(6, osmData.allPrimitives().size());
|
||||
|
|
Ładowanie…
Reference in New Issue