Changeset 33784 in osm for applications
- Timestamp:
- 2017-11-05T19:45:14+01:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/alignways
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/alignways/build.xml
r33133 r33784 4 4 <property name="commit.message" value="AlignWays: moved to Shift-Spacebar due to shortcut confilcts with core. A is too overloaded"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1 0580"/>6 <property name="plugin.main.version" value="12840"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAction.java
r32466 r33784 1 1 /** 2 * 2 * 3 3 */ 4 4 package com.tilusnet.josm.plugins.alignways; … … 13 13 import org.openstreetmap.josm.actions.JosmAction; 14 14 import org.openstreetmap.josm.command.Command; 15 import org.openstreetmap.josm.data.osm.DataSet; 15 16 import org.openstreetmap.josm.data.osm.Node; 17 import org.openstreetmap.josm.gui.MainApplication; 16 18 import org.openstreetmap.josm.tools.Shortcut; 17 19 … … 20 22 /** 21 23 * @author tilusnet <tilusnet@gmail.com> 22 * 24 * 23 25 */ 24 26 public class AlignWaysAction extends JosmAction { … … 31 33 "alignways", 32 34 tr("Makes a pair of selected way segments parallel by rotating one of them " 33 + "around a chosen pivot."), 35 + "around a chosen pivot."), 34 36 Shortcut.registerShortcut("tools:alignways", tr("Tool: {0}", tr("Align Ways")), 35 37 KeyEvent.VK_SPACE, Shortcut.SHIFT) … … 42 44 if (!isEnabled()) 43 45 return; 44 if (getLayerManager().getEditDataSet() == null) 46 DataSet ds = getLayerManager().getEditDataSet(); 47 if (ds == null) 45 48 return; 46 49 47 50 Collection<Node> affectableNodes = AlignWaysSegmentMgr.getInstance( 48 Main .map.mapView).getSelectedNodes();51 MainApplication.getMap().mapView).getSelectedNodes(); 49 52 50 53 // c is the last command launched, if any … … 59 62 AlignWaysCmdKeepLength cmdAW; 60 63 if (AlignWaysPlugin.getAwDialog().getAwOpt() == AligningModeOption.ALGN_OPT_KEEP_ANGLE) { 61 cmdAW = new AlignWaysCmdKeepAngles( );64 cmdAW = new AlignWaysCmdKeepAngles(ds); 62 65 } else { 63 cmdAW = new AlignWaysCmdKeepLength( );66 cmdAW = new AlignWaysCmdKeepLength(ds); 64 67 } 65 68 … … 70 73 } 71 74 72 Main .map.mapView.repaint();75 MainApplication.getMap().mapView.repaint(); 73 76 74 77 return; 75 78 } 76 77 79 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAlgnSegment.java
r33136 r33784 5 5 import java.awt.Graphics2D; 6 6 import java.awt.Point; 7 import java.awt.RenderingHints; 7 8 import java.awt.Shape; 8 import java.awt.RenderingHints;9 9 import java.awt.geom.Ellipse2D; 10 10 import java.awt.geom.Line2D; … … 16 16 import java.util.Map; 17 17 18 import org.openstreetmap.josm.Main;19 18 import org.openstreetmap.josm.data.Bounds; 20 19 import org.openstreetmap.josm.data.coor.EastNorth; … … 22 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 22 import org.openstreetmap.josm.data.osm.WaySegment; 23 import org.openstreetmap.josm.gui.MainApplication; 24 24 import org.openstreetmap.josm.gui.MapView; 25 25 import org.openstreetmap.josm.gui.NavigatableComponent; 26 import org.openstreetmap.josm.tools.Logging; 26 27 27 28 /** … … 132 133 } 133 134 } catch (IndexOutOfBoundsException e) { 134 Main.error(e);135 Logging.error(e); 135 136 return null; 136 137 } … … 194 195 final double incrementOnCircle = 2 * Math.PI / stepsOnCircle; 195 196 196 Point p = Main .map.mapView.getPoint(node);197 Point p = MainApplication.getMap().mapView.getPoint(node); 197 198 for (int i = 0; i < stepsOnCircle; i++) { 198 199 double ang = i * incrementOnCircle; … … 201 202 Point pnew = new Point(); 202 203 pnew.setLocation(x, y); 203 WaySegment ws = Main .map.mapView.getNearestWaySegment(pnew, OsmPrimitive::isUsable);204 WaySegment ws = MainApplication.getMap().mapView.getNearestWaySegment(pnew, OsmPrimitive::isUsable); 204 205 if (ws != null && !ws.equals(this.segment) && 205 206 (ws.getFirstNode().equals(node) || ws.getSecondNode().equals(node))) { … … 233 234 // If they are, it's a bug, possibly related to tracking of DataSet deletions. 234 235 if (segment.way.getNodesCount() <= segment.lowerIndex + 1) { 235 Main.warn("Not drawing AlignWays pivot points: underlying nodes disappeared");236 Logging.warn("Not drawing AlignWays pivot points: underlying nodes disappeared"); 236 237 return; 237 238 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepAngles.java
r30737 r33784 1 1 /** 2 * 2 * 3 3 */ 4 4 package com.tilusnet.josm.plugins.alignways; … … 13 13 import org.openstreetmap.josm.Main; 14 14 import org.openstreetmap.josm.data.coor.EastNorth; 15 import org.openstreetmap.josm.data.osm.DataSet; 15 16 import org.openstreetmap.josm.data.osm.Node; 16 17 import org.openstreetmap.josm.data.osm.WaySegment; … … 28 29 private AlignableStatus alignableStatKeepAngles = AlignableStatus.ALGN_VALID; 29 30 30 public AlignWaysCmdKeepAngles() { 31 public AlignWaysCmdKeepAngles(DataSet ds) { 32 super(ds); 31 33 // Now the calculatedNodes reflect the coordinates that we'd have 32 34 // without preserving the angles, i.e. preserving the length. … … 36 38 // Now we'll proceed with the hypothetical recalculation of the endpoint coordinates 37 39 // following the rule of preserving angles instead. The new nodes will be stored in nodeArr[]. 38 40 39 41 Node[] nodeArr = algnSeg.getSegmentEndPoints().toArray(new Node[2]); 40 42 … … 53 55 return; 54 56 } 55 57 56 58 ArrayList<WaySegment> alws = algnSeg.getAdjacentWaySegments(endpoint); 57 59 int alwsSize = alws.size(); … … 60 62 // - the alignee following the keep length rule 61 63 // - the adjacent way segment 62 64 63 65 Node adjOther1 = getNonEqualNode(alws.get(0), endpoint); 64 66 EastNorth enAdjOther1 = adjOther1.getEastNorth(); … … 69 71 adjOther2 = getNonEqualNode(alws.get(1), endpoint); 70 72 enAdjOther2 = adjOther2.getEastNorth(); 71 73 72 74 // In order have a chance to align, (enAdjOther1, enAdjOther2 and endpoint) must be collinear 73 75 ArrayList<EastNorth> enAdjPts = new ArrayList<>(3); … … 80 82 return; 81 83 } 82 84 83 85 } 84 86 85 87 // Update the calculated node for angle preserving alignment 86 AlignWaysGeomPoint isectPnt = alignedLineKeepLength.getIntersection(new AlignWaysGeomLine(enAdjOther1.getX(), enAdjOther1.getY(), 88 AlignWaysGeomPoint isectPnt = alignedLineKeepLength.getIntersection(new AlignWaysGeomLine(enAdjOther1.getX(), enAdjOther1.getY(), 87 89 endpoint.getEastNorth().getX(), endpoint.getEastNorth().getY())); 88 90 EastNorth enIsectPt = null; … … 96 98 return; 97 99 } 98 99 // For the case of two adjacent segments with collinear points, the new endpoint may 100 // not fall between enAdjOther1 and enAdjOther2; 101 // this scenario is not allowed for the time being as placing the new intersection point on the line 100 101 // For the case of two adjacent segments with collinear points, the new endpoint may 102 // not fall between enAdjOther1 and enAdjOther2; 103 // this scenario is not allowed for the time being as placing the new intersection point on the line 102 104 // triggers complications. 103 105 // TODO - find a solution 104 106 if (alwsSize == 2 && enIsectPt != null) { 105 107 int middlePtIdx = AlignWaysGeomPoint.getMiddleOf3( 106 new AlignWaysGeomPoint(enIsectPt), 107 new AlignWaysGeomPoint(enAdjOther1), 108 new AlignWaysGeomPoint(enIsectPt), 109 new AlignWaysGeomPoint(enAdjOther1), 108 110 new AlignWaysGeomPoint(enAdjOther2)); 109 111 if (middlePtIdx != 0) { … … 126 128 alignableStatKeepAngles = AlignableStatus.ALGN_INV_XPOINT_FALLSOUT; 127 129 return; 128 130 129 131 /* 130 132 if (middlePt.equalsEpsilon(enAdjOther1, eps)) { … … 140 142 } 141 143 } 142 144 143 145 if (isectPnt != null) { 144 146 // Angle preserving alignment passed all verification tests: record it. 145 147 calculatedNodes.put(endpoint, enIsectPt); 146 148 } 147 148 149 150 149 151 } else { 150 152 // angle preserving alignment not possible … … 155 157 private boolean isEnSetCollinear(ArrayList<EastNorth> enAdjPts) { 156 158 ArrayList<AlignWaysGeomPoint> awAdjPts = new ArrayList<>(); 157 159 158 160 for (EastNorth en : enAdjPts) { 159 161 AlignWaysGeomPoint pt = new AlignWaysGeomPoint(en.getX(), en.getY()); 160 162 awAdjPts.add(pt); 161 163 } 162 164 163 165 return AlignWaysGeomPoint.isSetCollinear(awAdjPts); 164 166 } … … 175 177 /** 176 178 * Reports invalid alignable statuses on screen in dialog boxes. 177 * 179 * 178 180 * @param stat The invalid status to report 179 181 */ -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepLength.java
r33136 r33784 1 1 /** 2 * 2 * 3 3 */ 4 4 package com.tilusnet.josm.plugins.alignways; … … 7 7 8 8 import java.util.Collection; 9 import java.util.Collections; 9 10 import java.util.HashMap; 10 11 import java.util.HashSet; 11 12 import java.util.Map; 12 import java.util.Collections;13 13 14 14 import javax.swing.Icon; … … 18 18 import org.openstreetmap.josm.command.Command; 19 19 import org.openstreetmap.josm.data.coor.EastNorth; 20 import org.openstreetmap.josm.data.osm.DataSet; 20 21 import org.openstreetmap.josm.data.osm.Node; 21 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 23 import org.openstreetmap.josm.data.osm.WaySegment; 23 import org.openstreetmap.josm.data.projection.Projections; 24 import org.openstreetmap.josm.gui.MainApplication; 25 import org.openstreetmap.josm.gui.MapView; 24 26 import org.openstreetmap.josm.tools.ImageProvider; 25 27 … … 27 29 * Executes one of the desired geometric actions 28 30 * needed to align the ways. 29 * 31 * 30 32 * @author tilusnet <tilusnet@gmail.com> 31 33 */ 32 33 34 public class AlignWaysCmdKeepLength extends Command { 34 35 … … 54 55 final Map<Node,EastNorth> calculatedNodes = new HashMap<>(); 55 56 56 57 57 /** 58 58 * Set of nodes that were affected by the last command execution. … … 67 67 /** 68 68 * Computed rotation angle to rotate the segment 69 * 69 * 70 70 */ 71 71 private final double rotationAngle; … … 80 80 * TODO Limitation (for now): constructor assumes areSegsAlignable() returns true. 81 81 */ 82 public AlignWaysCmdKeepLength( ) {83 82 public AlignWaysCmdKeepLength(DataSet ds) { 83 super(ds); 84 84 lastAffectedNodes = null; 85 85 86 algnSeg = AlignWaysSegmentMgr.getInstance(Main.map.mapView)87 86 MapView mapView = MainApplication.getMap().mapView; 87 algnSeg = AlignWaysSegmentMgr.getInstance(mapView).getAlgnSeg(); 88 88 WaySegment algnWS = algnSeg.getSegment(); 89 WaySegment refWS = AlignWaysSegmentMgr.getInstance(Main.map.mapView) 90 .getRefSeg().getSegment(); 89 WaySegment refWS = AlignWaysSegmentMgr.getInstance(mapView).getRefSeg().getSegment(); 91 90 92 91 this.pivot = algnSeg.getCurrPivotCoord(); … … 123 122 } 124 123 125 126 124 /* 127 125 * For debug only … … 133 131 * + Math.toDegrees(rotationAngle) + ")"; 134 132 */ 135 136 133 } 137 134 138 135 /** 139 136 * Helper for actually rotating the nodes. 140 * 137 * 141 138 * @param setModified 142 139 * - true if rotated nodes should be flagged "modified" … … 236 233 Collection<Node> algnNodes = displaceableNodes; 237 234 Collection<Node> refNodes = AlignWaysSegmentMgr 238 .getInstance(Main .map.mapView).getRefSeg()235 .getInstance(MainApplication.getMap().mapView).getRefSeg() 239 236 .getSegmentEndPoints(); 240 237 … … 256 253 // Deny action if the nodes would end up outside world 257 254 for (EastNorth en : calculatedNodes.values()) { 258 259 if (Projections.inverseProject(en).isOutSideWorld()) 255 if (Main.getProjection().eastNorth2latlon(en).isOutSideWorld()) 260 256 return AlignableStatus.ALGN_INV_OUTSIDE_WORLD; 261 262 257 } 263 258 … … 268 263 /** 269 264 * Validates the circumstances of the alignment command to be executed. 270 * 265 * 271 266 * @return true if the aligning action can be done, false otherwise. 272 267 */ … … 284 279 /** 285 280 * Reports invalid alignable statuses on screen in dialog boxes. 286 * 281 * 287 282 * @param stat The invalid status to report 288 283 */ -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysMode.java
r33136 r33784 31 31 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 32 32 import org.openstreetmap.josm.gui.IconToggleButton; 33 import org.openstreetmap.josm.gui.Ma pFrame;33 import org.openstreetmap.josm.gui.MainApplication; 34 34 import org.openstreetmap.josm.gui.layer.Layer; 35 35 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 52 52 boolean tipShown; 53 53 54 public AlignWaysMode( MapFrame mapFrame,String name, String desc) {54 public AlignWaysMode(String name, String desc) { 55 55 super(tr(name), "alignways.png", tr(desc), 56 56 Shortcut.registerShortcut("mapmode:alignways", 57 57 tr("Mode: {0}", tr("Align Ways")), 58 58 KeyEvent.VK_N, Shortcut.SHIFT), 59 mapFrame,Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));59 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 60 60 noneSelected = new AlignWaysSelNoneState(); 61 61 referenceSelected = new AlignWaysSelRefState(); … … 63 63 bothSelected = new AlignWaysSelBothState(); 64 64 tipShown = false; 65 66 65 } 67 66 … … 86 85 } 87 86 88 awSegs = AlignWaysSegmentMgr.getInstance(Main .map.mapView);89 Main .map.mapView.addMouseListener(this);90 DataSet ds = Main .getLayerManager().getEditDataSet();87 awSegs = AlignWaysSegmentMgr.getInstance(MainApplication.getMap().mapView); 88 MainApplication.getMap().mapView.addMouseListener(this); 89 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 91 90 if (ds != null) 92 91 ds.addDataSetListener(this); … … 107 106 108 107 setCurrentState(noneSelected); 109 Main .map.mapView.removeMouseListener(this);110 DataSet ds = Main .getLayerManager().getEditDataSet();108 MainApplication.getMap().mapView.removeMouseListener(this); 109 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 111 110 if (ds != null) 112 111 ds.removeDataSetListener(this); … … 144 143 } 145 144 146 Main .map.mapView.repaint();145 MainApplication.getMap().mapView.repaint(); 147 146 } 148 147 … … 234 233 tipDialog.dispose(); 235 234 236 Main.pref.put ("alignways.showtips", !atp.isChkBoxSelected());235 Main.pref.putBoolean("alignways.showtips", !atp.isChkBoxSelected()); 237 236 } 238 237 … … 273 272 @Override 274 273 public void primitivesRemoved(PrimitivesRemovedEvent event) { 275 awSegs = AlignWaysSegmentMgr.getInstance(Main .map.mapView);274 awSegs = AlignWaysSegmentMgr.getInstance(MainApplication.getMap().mapView); 276 275 277 276 // Check whether any of the removed primitives were part of a highlighted alignee or reference segment. -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysPlugin.java
r29771 r33784 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import org.openstreetmap.josm.Main;6 5 import org.openstreetmap.josm.actions.JosmAction; 7 6 import org.openstreetmap.josm.gui.IconToggleButton; 7 import org.openstreetmap.josm.gui.MainApplication; 8 8 import org.openstreetmap.josm.gui.MainMenu; 9 9 import org.openstreetmap.josm.gui.MapFrame; … … 15 15 * 16 16 */ 17 18 17 public class AlignWaysPlugin extends Plugin { 19 18 … … 29 28 public AlignWaysPlugin(PluginInformation info) { 30 29 super(info); 31 30 32 31 // Add the action entries to the Tools Menu 33 Main .main.menu.moreToolsMenu.addSeparator();32 MainApplication.getMenu().moreToolsMenu.addSeparator(); 34 33 awAction = new AlignWaysAction(); 35 MainMenu.add(Main .main.menu.moreToolsMenu, awAction);34 MainMenu.add(MainApplication.getMenu().moreToolsMenu, awAction); 36 35 } 37 36 … … 40 39 if (newFrame != null) { 41 40 // Construct the AlignWays mode toggle button 42 awMode = new AlignWaysMode( Main.map,"alignways", tr("Align Ways mode"));41 awMode = new AlignWaysMode("alignways", tr("Align Ways mode")); 43 42 btn = new IconToggleButton(awMode); 44 43 btn.setVisible(true); -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegment.java
r33136 r33784 16 16 import java.util.Objects; 17 17 18 import org.openstreetmap.josm.Main;19 18 import org.openstreetmap.josm.data.Bounds; 20 19 import org.openstreetmap.josm.data.osm.Node; … … 24 23 import org.openstreetmap.josm.gui.MapView; 25 24 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 25 import org.openstreetmap.josm.tools.Logging; 26 26 27 27 /** … … 63 63 segmentEndPoints.add(segment.getSecondNode()); 64 64 } catch (IndexOutOfBoundsException e) { 65 Main.error(e);65 Logging.error(e); 66 66 } 67 67 } … … 91 91 // If they are, it's a bug, possibly related to tracking of DataSet deletions. 92 92 if (segment.way.getNodesCount() <= segment.lowerIndex + 1) { 93 Main.warn("Not drawing AlignWays highlighting segment: underlying nodes disappeared");93 Logging.warn("Not drawing AlignWays highlighting segment: underlying nodes disappeared"); 94 94 return; 95 95 } … … 112 112 g.draw(new Line2D.Double(mv.getPoint(n1), mv.getPoint(n2))); 113 113 } catch (IndexOutOfBoundsException e) { 114 Main.error(e);114 Logging.error(e); 115 115 } 116 116 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelAlgnState.java
r28342 r33784 4 4 package com.tilusnet.josm.plugins.alignways; 5 5 6 import org.openstreetmap.josm.Main;7 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 8 import org.openstreetmap.josm.gui.MainApplication; 8 9 9 10 /** … … 25 26 @Override 26 27 public void setHelpText() { 27 Main .map.statusLine28 MainApplication.getMap().statusLine 28 29 .setHelpText(tr("Ctrl-Click: select reference way segment; Alt-click: Clear selection")); 29 30 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelBothState.java
r28342 r33784 5 5 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 import org.openstreetmap.josm.Main; 7 8 import org.openstreetmap.josm.gui.MainApplication; 8 9 9 10 /** … … 25 26 @Override 26 27 public void setHelpText() { 27 Main .map.statusLine28 MainApplication.getMap().statusLine 28 29 .setHelpText(AlignWaysPlugin.getAwAction().getShortcut().getKeyText() + 29 30 tr(": Align segments; Alt-click: Clear selection")); -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelNoneState.java
r28342 r33784 5 5 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 import org.openstreetmap.josm.Main; 7 8 import org.openstreetmap.josm.gui.MainApplication; 8 9 9 10 /** … … 28 29 @Override 29 30 public void setHelpText() { 30 Main .map.statusLine31 MainApplication.getMap().statusLine 31 32 .setHelpText(tr("Ctrl-click: select reference way segment; Click: select way segment to be aligned")); 32 33 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelRefState.java
r28342 r33784 5 5 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 import org.openstreetmap.josm.Main; 7 8 import org.openstreetmap.josm.gui.MainApplication; 8 9 9 10 /** … … 25 26 @Override 26 27 public void setHelpText() { 27 Main .map.statusLine28 MainApplication.getMap().statusLine 28 29 .setHelpText(tr("Click: select way segment to be aligned; Alt-click: Clear selection")); 29 30 } -
applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysState.java
r28342 r33784 5 5 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 import org.openstreetmap.josm.Main; 7 8 import org.openstreetmap.josm.gui.MainApplication; 8 9 9 10 /** … … 21 22 public void altLClick(AlignWaysMode alignWaysMode) { 22 23 alignWaysMode.setCurrentState(alignWaysMode.getNoneSelected()); 23 Main .map.statusLine24 MainApplication.getMap().statusLine 24 25 .setHelpText(tr("Ctrl-Click: select reference way segment; Click: select way segment to be aligned")); 25 26 }
Note:
See TracChangeset
for help on using the changeset viewer.