Skip to content

Commit

Permalink
Merge pull request #5 from tsmock/ShapeTools-17177
Browse files Browse the repository at this point in the history
ShapeTools: recompile for compatibility with JOSM r17867
  • Loading branch information
simon04 authored May 18, 2021
2 parents 4927532 + 7535220 commit d952210
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
5 changes: 3 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="ShapeTools" default="dist" basedir=".">
<!-- enter the SVN commit message -->
<property name="commit.message" value="This should be the first commit, not sure yet"/>
<property name="commit.message" value="ShapeTools: update for compatibility with JOSM r17896"/>
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="14153"/>
<property name="plugin.main.version" value="17896"/>

<property name="plugin.author" value="Antochi Adrian and Trifan Adrian"/>
<property name="plugin.class" value="org.openstreetmap.josm.plugins.shapetools.ShapeToolsPlugin"/>
Expand All @@ -15,6 +15,7 @@
<target name="additional-manifest">
<manifest file="MANIFEST" mode="update">
<attribute name="12636_Plugin-Url" value="v1.2.3;https://github.com/JOSM/ShapeTools/releases/download/v1.2.3/ShapeTools.jar" />
<attribute name="14153_Plugin-Url" value="v1.2.4;https://github.com/JOSM/ShapeTools/releases/download/v1.2.4/ShapeTools.jar" />
</manifest>
</target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import java.awt.geom.Line2D;

import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.osm.WaySegment;
import org.openstreetmap.josm.data.osm.IWaySegment;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.gui.MapView;
import org.openstreetmap.josm.gui.layer.MapViewPaintable;

Expand All @@ -19,15 +21,15 @@
*/
public class DrawableSegment implements MapViewPaintable {

protected final WaySegment segment;
protected final IWaySegment<Node, Way> segment;
protected final Color color;
protected final Stroke stroke;

/**
* Constructs a new {@code DrawableSegment}.
* @param segment way segment
*/
public DrawableSegment(WaySegment segment) {
public DrawableSegment(IWaySegment<Node, Way> segment) {
this(segment, Color.WHITE);
}

Expand All @@ -36,7 +38,7 @@ public DrawableSegment(WaySegment segment) {
* @param segment way segment
* @param color color
*/
public DrawableSegment(WaySegment segment, Color color) {
public DrawableSegment(IWaySegment<Node, Way> segment, Color color) {
int strokeThickness = 3;
this.segment = segment;
this.color = color;
Expand All @@ -45,7 +47,7 @@ public DrawableSegment(WaySegment segment, Color color) {

@Override
public void paint(Graphics2D g, MapView mv, Bounds bbox) {
if (segment != null && segment.way.getNodesCount() > 1) {
if (segment != null && segment.getWay().getNodesCount() > 1) {
g.setColor(color);
g.setStroke(stroke);

Expand All @@ -61,7 +63,7 @@ public Color getColor() {
return color;
}

public WaySegment getSegment() {
public IWaySegment<Node, Way> getSegment() {
return segment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import java.awt.Color;

import org.openstreetmap.josm.data.osm.WaySegment;
import org.openstreetmap.josm.data.osm.IWaySegment;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;

/**
* Adding this as a temporary layer on mapview will color the selected segment green
Expand All @@ -15,7 +17,7 @@ public class DrawableSegmentBuilding extends DrawableSegment {
* Constructs a new {@code DrawableSegmentBuilding}.
* @param segment way segment
*/
public DrawableSegmentBuilding(WaySegment segment) {
public DrawableSegmentBuilding(IWaySegment<Node, Way> segment) {
super(segment, Color.GREEN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import java.awt.Color;

import org.openstreetmap.josm.data.osm.WaySegment;
import org.openstreetmap.josm.data.osm.IWaySegment;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;

/**
* Adding this as a temporary layer on mapview will color the selected segment yellow
Expand All @@ -16,7 +18,7 @@ public class DrawableSegmentRoad extends DrawableSegment {
* Constructs a new {@code DrawableSegmentRoad}.
* @param segment way segment
*/
public DrawableSegmentRoad(WaySegment segment) {
public DrawableSegmentRoad(IWaySegment<Node, Way> segment) {
super(segment, Color.YELLOW);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import javax.swing.JTextField;

import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.IWaySegment;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.data.osm.WaySegment;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
Expand Down Expand Up @@ -148,7 +148,7 @@ public void mouseClicked(MouseEvent e) {
DrawableSegmentRoad road = ShapeMode.roadSegm;
if (building != null && road != null) {
Logging.debug("NearestSegment button pressed, non-null parameters found");
WaySegment segm = ShapeMath.getClosestSegment(building.getSegment().way, road.segment);
IWaySegment<Node, Way> segm = ShapeMath.getClosestSegment(building.getSegment().getWay(), road.segment);
DrawableSegment dSegm = new DrawableSegment(segm, Color.magenta);
Logging.debug("closest nodes" + segm.getFirstNode() + " " + segm.getSecondNode());
MainApplication.getMap().mapView.addTemporaryLayer(dSegm);
Expand Down
28 changes: 14 additions & 14 deletions src/org/openstreetmap/josm/plugins/shapetools/ShapeMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import org.openstreetmap.josm.command.SequenceCommand;
import org.openstreetmap.josm.data.UndoRedoHandler;
import org.openstreetmap.josm.data.coor.EastNorth;
import org.openstreetmap.josm.data.osm.IWaySegment;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.data.osm.WaySegment;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.tools.Geometry;
import org.openstreetmap.josm.tools.Logging;
Expand All @@ -34,12 +34,12 @@ private ShapeMath() {
/**
* @return closest segment contained in the way, regarding the segment
*/
public static WaySegment getClosestSegment(Way fromThisway, WaySegment regardingThisSegment) {
public static IWaySegment<Node, Way> getClosestSegment(Way fromThisway, IWaySegment<Node, Way> regardingThisSegment) {
double maxDistance = Double.MAX_VALUE;
WaySegment closestSegment = null;
IWaySegment<Node, Way> closestSegment = null;
for (int i = 0; i < fromThisway.getNodesCount() - 1; i++) {

WaySegment currentSegment = new WaySegment(fromThisway, i);
IWaySegment<Node, Way> currentSegment = new IWaySegment<>(fromThisway, i);
EastNorth currentSegmentCentroid = getCentroid(currentSegment);
Point p = new Point(currentSegmentCentroid.getX(), currentSegmentCentroid.getY());
EastNorth en1 = regardingThisSegment.getFirstNode().getEastNorth();
Expand All @@ -50,7 +50,7 @@ public static WaySegment getClosestSegment(Way fromThisway, WaySegment regarding

if (distance < maxDistance) {
maxDistance = distance;
closestSegment = new WaySegment(fromThisway, i);
closestSegment = new IWaySegment<>(fromThisway, i);
}
}
return closestSegment;
Expand All @@ -61,13 +61,13 @@ public static WaySegment getClosestSegment(Way fromThisway, WaySegment regarding
* @return closest segment contained in the way,
* regarding the segment if the distance between the two is smaller than epsilon, otherwise returns null
*/
public static WaySegment getClosestSegmentUsingEpsilon(Way fromThisway, WaySegment regardingThisSegment, double epsilon) {
public static IWaySegment<Node, Way> getClosestSegmentUsingEpsilon(Way fromThisway, IWaySegment<Node, Way> regardingThisSegment, double epsilon) {
double maxDistance = Double.MAX_VALUE;
WaySegment closestSegment = null;
IWaySegment<Node, Way> closestSegment = null;

for (int i = 0; i < fromThisway.getNodesCount() - 1; i++) {

WaySegment currentSegment = new WaySegment(fromThisway, i);
IWaySegment<Node, ?> currentSegment = new IWaySegment<>(fromThisway, i);
EastNorth currentSegmentCentroid = getCentroid(currentSegment);
Point p = new Point(currentSegmentCentroid.getX(), currentSegmentCentroid.getY());
EastNorth en1 = regardingThisSegment.getFirstNode().getEastNorth();
Expand All @@ -78,7 +78,7 @@ public static WaySegment getClosestSegmentUsingEpsilon(Way fromThisway, WaySegme

if (distance < maxDistance && distance < epsilon) {
maxDistance = distance;
closestSegment = new WaySegment(fromThisway, i);
closestSegment = new IWaySegment<>(fromThisway, i);
}
}
return closestSegment;
Expand Down Expand Up @@ -146,7 +146,7 @@ public static EastNorth getCentroid(Way way) {
/**
* @return the center-point of a way, calculated by taking the averange of all east and north coordinates of a way
*/
public static EastNorth getCentroid(WaySegment segment) {
public static EastNorth getCentroid(IWaySegment<Node, ?> segment) {
return getCentroid(Arrays.asList(segment.getFirstNode(), segment.getSecondNode()));
}

Expand Down Expand Up @@ -217,18 +217,18 @@ public static void align(Way firstWay, Way secondWay) {
* @param roadSegment segment of the road
* @param toRotateSegment segment(wall) of the building that needs to be rotated
*/
public static void align(WaySegment roadSegment, WaySegment toRotateSegment) {
public static void align(IWaySegment<Node, Way> roadSegment, IWaySegment<Node, Way> toRotateSegment) {
double requiredAngle = normalise(computeAngle(
roadSegment.getFirstNode(), roadSegment.getSecondNode(),
toRotateSegment.getFirstNode(), toRotateSegment.getSecondNode()));
commitCommands("AlignCommand", rotate(toRotateSegment.way, requiredAngle, getCentroid(toRotateSegment.way)));
commitCommands("AlignCommand", rotate(toRotateSegment.getWay(), requiredAngle, getCentroid(toRotateSegment.getWay())));
}

/**
* Aligns the building only if the distance between the closest wall of the building and it's closest road-segment is smaller than epsilon
*/
public static void alignUsingEpsilon(WaySegment roadSegment, Way building, double epsilon) {
WaySegment closestSegment = getClosestSegmentUsingEpsilon(building, roadSegment, epsilon);
public static void alignUsingEpsilon(IWaySegment<Node, Way> roadSegment, Way building, double epsilon) {
IWaySegment<Node, Way> closestSegment = getClosestSegmentUsingEpsilon(building, roadSegment, epsilon);
if (closestSegment != null) {
double requiredAngle = normalise(computeAngle(
roadSegment.getFirstNode(), roadSegment.getSecondNode(),
Expand Down

0 comments on commit d952210

Please sign in to comment.