Changeset 14404 in osm for applications/editors/josm/plugins
- Timestamp:
- 2009-04-06T12:46:43+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/routing/src/com/innovant/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routing/src/com/innovant/josm/jrt/core/RoutingGraph.java
r14287 r14404 38 38 import org.jgrapht.graph.AsUndirectedGraph; 39 39 import org.jgrapht.graph.DirectedWeightedMultigraph; 40 import org.openstreetmap.josm. Main;40 import org.openstreetmap.josm.data.osm.DataSet; 41 41 import org.openstreetmap.josm.data.osm.Node; 42 42 import org.openstreetmap.josm.data.osm.Way; … … 74 74 private RouteType routeType; 75 75 76 /** 77 * Associated Osm DataSet 78 */ 79 private DataSet data; 80 76 81 /** 77 82 * Logger. … … 101 106 * Default Constructor. 102 107 */ 103 public RoutingGraph( ) {108 public RoutingGraph(DataSet data) { 104 109 this.graphState = false; 105 110 this.graph = null; 111 this.data = data; 106 112 routeType=RouteType.SHORTEST; 107 113 routingProfile=new RoutingProfile("default"); … … 118 124 public void createGraph() { 119 125 120 logger.debug(" Init Create Graph");126 logger.debug("Creating Graph..."); 121 127 graph = new DirectedWeightedMultigraph<Node, OsmEdge>(OsmEdge.class); 122 128 123 129 // iterate all ways and segments for all nodes: 124 for (Way way : Main.ds.ways) {130 for (Way way : data.ways) { 125 131 if (way != null && !way.deleted && this.isvalidWay(way)) { 126 132 Node from = null; -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingLayer.java
r14287 r14404 37 37 import java.util.ArrayList; 38 38 import java.util.Collection; 39 import java.util.LinkedList; 39 40 import java.util.List; 41 import java.util.TreeMap; 40 42 41 43 import javax.swing.Icon; … … 47 49 import org.openstreetmap.josm.actions.RenameLayerAction; 48 50 import org.openstreetmap.josm.data.osm.Node; 51 import org.openstreetmap.josm.data.osm.Way; 52 import org.openstreetmap.josm.data.osm.WaySegment; 49 53 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 50 54 import org.openstreetmap.josm.gui.MapView; 55 import org.openstreetmap.josm.gui.NavigatableComponent; 51 56 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 52 57 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 53 58 import org.openstreetmap.josm.gui.layer.Layer; 59 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 54 60 import org.openstreetmap.josm.tools.ColorHelper; 55 61 import org.openstreetmap.josm.tools.ImageProvider; … … 82 88 83 89 /** 84 * Icon Start Middle End90 * Start, Middle and End icons 85 91 */ 86 92 private Icon startIcon,middleIcon,endIcon; 87 93 88 94 /** 89 * Flag that manager activation layer 90 */ 91 private boolean layerAdded = false; 95 * Associated OSM layer 96 */ 97 private OsmDataLayer dataLayer; 98 99 // /** 100 // * Flag that manager activation layer 101 // */ 102 // private boolean layerAdded = false; 92 103 93 104 /** … … 95 106 * @param name Layer name. 96 107 */ 97 public RoutingLayer(String name ) {108 public RoutingLayer(String name, OsmDataLayer dataLayer) { 98 109 super(name); 99 logger.debug(" Init Routing Layer");110 logger.debug("Creating Routing Layer..."); 100 111 if(startIcon == null) startIcon = ImageProvider.get("routing", "startflag"); 101 112 if(middleIcon == null) middleIcon = ImageProvider.get("routing", "middleflag"); 102 113 if(endIcon == null) endIcon = ImageProvider.get("routing", "endflag"); 103 this.routingModel = new RoutingModel(); 104 logger.debug("End init Routing Layer"); 114 this.dataLayer = dataLayer; 115 this.routingModel = new RoutingModel(dataLayer.data); 116 logger.debug("Routing Layer created."); 105 117 } 106 118 … … 114 126 115 127 /** 116 * Check if layer is load. 117 * @return <code>true</code> Layer load. 118 * <code>false</code> Layer don't load. 119 */ 120 public boolean isLayerAdded() { 121 return layerAdded; 128 * Gets associated data layer 129 * @return OsmDataLayer associated to the RoutingLayer 130 */ 131 public OsmDataLayer getDataLayer() { 132 return dataLayer; 122 133 } 123 134 124 135 /** 125 * Setter layer active. 126 */ 127 public void setLayerAdded() { 128 layerAdded = true; 129 } 136 * Gets nearest node belonging to a highway tagged way 137 * @param p Point on the screen 138 * @return The nearest highway node, in the range of the snap distance 139 */ 140 public final Node getNearestHighwayNode(Point p) { 141 Node nearest = null; 142 double minDist = 0; 143 for (Way w : dataLayer.data.ways) { 144 if (w.deleted || w.incomplete || w.get("highway")==null) continue; 145 for (Node n : w.nodes) { 146 if (n.deleted || n.incomplete) continue; 147 148 Point P = Main.map.mapView.getPoint(n.eastNorth); 149 double dist = p.distanceSq(P); 150 if (dist < NavigatableComponent.snapDistance) { 151 if ((nearest == null) || (dist < minDist)) { 152 nearest = n; 153 minDist = dist; 154 } 155 } 156 } 157 } 158 return nearest; 159 } 160 161 // /** 162 // * Check if layer is load. 163 // * @return <code>true</code> Layer load. 164 // * <code>false</code> Layer don't load. 165 // */ 166 // public boolean isLayerAdded() { 167 // return layerAdded; 168 // } 169 // 170 // /** 171 // * Setter layer active. 172 // */ 173 // public void setLayerAdded() { 174 // layerAdded = true; 175 // } 130 176 131 177 /* … … 283 329 public void destroy() { 284 330 routingModel.reset(); 285 layerAdded = false;331 // layerAdded = false; 286 332 } 287 333 -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingModel.java
r14287 r14404 32 32 33 33 import org.apache.log4j.Logger; 34 import org.openstreetmap.josm.data.osm.DataSet; 34 35 import org.openstreetmap.josm.data.osm.Node; 35 36 … … 70 71 * Default Constructor. 71 72 */ 72 public RoutingModel( ) {73 public RoutingModel(DataSet data) { 73 74 nodes = new ArrayList<Node>(); 74 routingGraph = new RoutingGraph( );75 routingGraph = new RoutingGraph(data); 75 76 } 76 77 -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/RoutingPlugin.java
r14395 r14404 33 33 34 34 import static org.openstreetmap.josm.tools.I18n.tr; 35 36 import java.lang.reflect.Array; 37 import java.util.ArrayList; 35 38 36 39 import org.apache.log4j.Logger; … … 40 43 import org.openstreetmap.josm.gui.MapFrame; 41 44 import org.openstreetmap.josm.gui.layer.Layer; 45 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 42 46 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 43 47 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 65 69 static Logger logger = Logger.getLogger(RoutingPlugin.class); 66 70 67 /** 68 * Displays the layer menu when right clicking on the layer name, and manages 69 * how to paint the layer. 70 */ 71 private RoutingLayer routingLayer; 71 /** 72 * The list of routing layers 73 */ 74 private ArrayList<RoutingLayer> layers; 72 75 73 76 /** … … 136 139 // Create side dialog 137 140 routingDialog = new RoutingDialog(); 138 // Add routing layer 139 routingLayer = new RoutingLayer(tr("Navigation"));141 // Initialize layers list 142 layers = new ArrayList<RoutingLayer>(); 140 143 // Add menu 141 144 menu = new RoutingMenu(tr("Routing")); … … 155 158 156 159 /** 157 * Get the routing layer158 * @return The instance of the routing layer159 */160 public RoutingLayer getRoutingLayer() {161 return routingLayer;162 }163 164 /**165 160 * Get the routing side dialog 166 161 * @return The instance of the routing side dialog … … 168 163 public RoutingDialog getRoutingDialog() { 169 164 return routingDialog; 165 } 166 167 public void addLayer() { 168 OsmDataLayer osmLayer = Main.main.editLayer(); 169 RoutingLayer layer = new RoutingLayer(tr("Routing") + " [" + osmLayer.name + "]", osmLayer); 170 layers.add(layer); 171 Main.main.addLayer(layer); 170 172 } 171 173 … … 181 183 removeRouteNodeAction = new RemoveRouteNodeAction(newFrame); 182 184 moveRouteNodeAction = new MoveRouteNodeAction(newFrame); 183 // Create plugin buttons and add them to the tool 185 // Create plugin buttons and add them to the toolbar 184 186 addRouteNodeButton = new IconToggleButton(addRouteNodeAction); 185 187 removeRouteNodeButton = new IconToggleButton(removeRouteNodeAction); … … 205 207 * @see org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener#activeLayerChange(org.openstreetmap.josm.gui.layer.Layer, org.openstreetmap.josm.gui.layer.Layer) 206 208 */ 207 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 209 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 210 routingDialog.refresh(); 211 } 208 212 209 213 /* … … 214 218 // Add button(s) to the tool bar when the routing layer is added 215 219 if (newLayer instanceof RoutingLayer) { 216 newLayer.name=tr("Routing")+" ["+Main.map.mapView.getActiveLayer().name+"]";217 220 addRouteNodeButton.setVisible(true); 218 221 removeRouteNodeButton.setVisible(true); 219 222 moveRouteNodeButton.setVisible(true); 220 223 menu.enableRestOfItems(); 224 // Set layer on top and select layer, also refresh toggleDialog to reflect selection 225 Main.map.mapView.moveLayer(newLayer, 0); 226 // Main.map.mapView.setActiveLayer(newLayer); 227 // Main.map.toggleDialogs.repaint(); 221 228 logger.debug("Added routing layer."); 222 229 } … … 228 235 */ 229 236 public void layerRemoved(Layer oldLayer) { 230 // Remove button(s) from the tool bar when the routing layer is removed231 if (oldLayer instanceof RoutingLayer) {237 if ((oldLayer instanceof RoutingLayer) & (layers.size()==1)) { 238 // Remove button(s) from the tool bar when the last routing layer is removed 232 239 addRouteNodeButton.setVisible(false); 233 240 removeRouteNodeButton.setVisible(false); 234 241 moveRouteNodeButton.setVisible(false); 235 242 menu.disableRestOfItems(); 243 layers.remove(oldLayer); 236 244 logger.debug("Removed routing layer."); 245 } else if (oldLayer instanceof OsmDataLayer) { 246 // Remove all associated routing layers 247 // Convert to Array to prevent ConcurrentModificationException when removing layers from ArrayList 248 // FIXME: can't remove associated routing layers without triggering exceptions in some cases 249 RoutingLayer[] layersArray = layers.toArray(new RoutingLayer[0]); 250 for (int i=0;i<layersArray.length;i++) { 251 if (layersArray[i].getDataLayer().equals(oldLayer)) { 252 // Move layer to the top 253 Main.map.mapView.moveLayer(layersArray[i], 0); 254 try { 255 // Remove layer 256 Main.map.mapView.removeLayer(layersArray[i]); 257 } catch (IllegalArgumentException e) { 258 } 259 } 260 } 237 261 } 262 // Reload RoutingDialog table model 263 routingDialog.refresh(); 238 264 } 239 265 -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/AddRouteNodeAction.java
r14287 r14404 31 31 32 32 import java.awt.event.MouseEvent; 33 import java.util.List;34 33 35 34 import org.apache.log4j.Logger; … … 37 36 import org.openstreetmap.josm.actions.mapmode.MapMode; 38 37 import org.openstreetmap.josm.data.osm.Node; 39 import org.openstreetmap.josm.data.osm.WaySegment;40 38 import org.openstreetmap.josm.gui.MapFrame; 41 39 import org.openstreetmap.josm.tools.ImageProvider; 42 40 43 41 import com.innovant.josm.plugin.routing.RoutingLayer; 44 import com.innovant.josm.plugin.routing.RoutingModel;45 42 import com.innovant.josm.plugin.routing.RoutingPlugin; 46 43 import com.innovant.josm.plugin.routing.gui.RoutingDialog; … … 62 59 */ 63 60 static Logger logger = Logger.getLogger(AddRouteNodeAction.class); 64 /**65 * Routing Model.66 */67 private RoutingModel routingModel;68 /**69 * Routing Layer.70 */71 private RoutingLayer routingLayer;72 61 /** 73 62 * Routing Dialog. … … 84 73 tr("Click to add route nodes."), 85 74 mapFrame, ImageProvider.getCursor("crosshair", null)); 86 this.routingLayer = RoutingPlugin.getInstance().getRoutingLayer();87 this.routingModel = routingLayer.getRoutingModel();88 75 this.routingDialog = RoutingPlugin.getInstance().getRoutingDialog(); 89 76 } … … 104 91 // Search for nearest highway node 105 92 Node node = null; 106 List<WaySegment> wsl = Main.map.mapView.getNearestWaySegments(e.getPoint()); 107 for (WaySegment ws:wsl) { 108 if (ws.way.get("highway")!=null) { 109 // If waysegment belongs to a highway compare the distance from 110 // both waysegment nodes to the point clicked and keep the nearest one 111 Node node0 = ws.way.nodes.get(ws.lowerIndex); 112 Node node1 = ws.way.nodes.get(ws.lowerIndex + 1); 113 double d0 = Main.map.mapView.getPoint(node0.eastNorth).distanceSq(e.getPoint()); 114 double d1 = Main.map.mapView.getPoint(node1.eastNorth).distanceSq(e.getPoint()); 115 if (d0<d1) 116 node = node0; 117 else 118 node = node1; 119 break; 120 } 93 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 94 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 95 node = layer.getNearestHighwayNode(e.getPoint()); 96 if(node == null) { 97 logger.debug("no selected node"); 98 return; 99 } 100 logger.debug("selected node " + node); 101 layer.getRoutingModel().addNode(node); 102 routingDialog.addNode(node); 121 103 } 122 logger.debug("selected node " + node);123 if(node == null) {124 logger.debug("no selected node");125 return;126 }127 routingModel.addNode(node);128 routingDialog.addNode(node.id+" ["+node.coor.toDisplayString()+"]");129 104 } 130 105 Main.map.repaint(); -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/MoveRouteNodeAction.java
r14287 r14404 38 38 import org.openstreetmap.josm.actions.mapmode.MapMode; 39 39 import org.openstreetmap.josm.data.osm.Node; 40 import org.openstreetmap.josm.data.osm.WaySegment;41 40 import org.openstreetmap.josm.gui.MapFrame; 42 41 import org.openstreetmap.josm.tools.ImageProvider; … … 71 70 72 71 /** 73 * Routing Model.74 */75 private RoutingModel routingModel;76 77 /**78 * Routing Layer.79 */80 private RoutingLayer routingLayer;81 82 /**83 72 * Routing Dialog. 84 73 */ … … 99 88 tr("Click and drag to move route nodes."), 100 89 mapFrame, ImageProvider.getCursor("normal", "move")); 101 this.routingLayer = RoutingPlugin.getInstance().getRoutingLayer();102 this.routingModel = routingLayer.getRoutingModel();103 90 this.routingDialog = RoutingPlugin.getInstance().getRoutingDialog(); 104 91 } … … 117 104 // If left button is pressed 118 105 if (e.getButton() == MouseEvent.BUTTON1) { 119 // Search for the nearest node in the list 120 List<Node> nl = routingModel.getSelectedNodes(); 121 index = -1; 122 double dmax = DRAG_SQR_RADIUS; // maximum distance, in pixels 123 for (int i=0;i<nl.size();i++) { 124 Node node = nl.get(i); 125 double d = Main.map.mapView.getPoint(node.eastNorth).distanceSq(e.getPoint()); 126 if (d < dmax) { 127 dmax = d; 128 index = i; 129 } 106 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 107 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 108 RoutingModel routingModel = layer.getRoutingModel(); 109 // Search for the nearest node in the list 110 List<Node> nl = routingModel.getSelectedNodes(); 111 index = -1; 112 double dmax = DRAG_SQR_RADIUS; // maximum distance, in pixels 113 for (int i=0;i<nl.size();i++) { 114 Node node = nl.get(i); 115 double d = Main.map.mapView.getPoint(node.eastNorth).distanceSq(e.getPoint()); 116 if (d < dmax) { 117 dmax = d; 118 index = i; 119 } 120 } 121 if (index>=0) 122 logger.debug("Moved from node " + nl.get(index)); 130 123 } 131 if (index>=0)132 logger.debug("Moved from node " + nl.get(index));133 124 } 134 125 } … … 145 136 146 137 private void searchAndReplaceNode(Point point) { 147 // Search for nearest highway node 148 Node node = null; 149 List<WaySegment> wsl = Main.map.mapView.getNearestWaySegments(point); 150 for (WaySegment ws:wsl) { 151 if (ws.way.get("highway")!=null) { 152 // If waysegment belongs to a highway compare the distance from 153 // both waysegment nodes to the point clicked and keep the nearest one 154 Node node0 = ws.way.nodes.get(ws.lowerIndex); 155 Node node1 = ws.way.nodes.get(ws.lowerIndex + 1); 156 double d0 = Main.map.mapView.getPoint(node0.eastNorth).distanceSq(point); 157 double d1 = Main.map.mapView.getPoint(node1.eastNorth).distanceSq(point); 158 if (d0<d1) 159 node = node0; 160 else 161 node = node1; 162 break; 163 } 138 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 139 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 140 RoutingModel routingModel = layer.getRoutingModel(); 141 // Search for nearest highway node 142 Node node = null; 143 node = layer.getNearestHighwayNode(point); 144 if (node == null) { 145 logger.debug("Didn't found a close node to move to."); 146 return; 147 } 148 logger.debug("Moved to node " + node); 149 routingModel.removeNode(index); 150 routingDialog.removeNode(index); 151 routingModel.insertNode(index, node); 152 routingDialog.insertNode(index, node); 153 Main.map.repaint(); 164 154 } 165 if (node == null) {166 logger.debug("Didn't found a close node to move to.");167 return;168 }169 logger.debug("Moved to node " + node);170 routingModel.removeNode(index);171 routingDialog.removeNode(index);172 routingModel.insertNode(index, node);173 routingDialog.insertNode(index,node.id+" ["+node.coor.toDisplayString()+"]");174 Main.map.repaint();175 155 } 176 156 } -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/actions/RemoveRouteNodeAction.java
r14287 r14404 67 67 */ 68 68 static Logger logger = Logger.getLogger(RoutingLayer.class); 69 /**70 * Routing Model.71 */72 private RoutingModel routingModel;73 /**74 * Routing Layer.75 */76 private RoutingLayer routingLayer;77 69 /** 78 70 * Routing Dialog. … … 85 77 tr("Remove route nodes"), 86 78 mapFrame, ImageProvider.getCursor("normal", "delete")); 87 this.routingLayer = RoutingPlugin.getInstance().getRoutingLayer();88 this.routingModel = routingLayer.getRoutingModel();89 79 this.routingDialog = RoutingPlugin.getInstance().getRoutingDialog(); 90 80 } … … 103 93 // If left button is clicked 104 94 if (e.getButton() == MouseEvent.BUTTON1) { 105 // Search for the nearest node in the list 106 List<Node> nl = routingModel.getSelectedNodes(); 107 int index = -1; 108 double dmax = REMOVE_SQR_RADIUS; // maximum distance, in pixels 109 for (int i=0;i<nl.size();i++) { 110 Node node = nl.get(i); 111 double d = Main.map.mapView.getPoint(node.eastNorth).distanceSq(e.getPoint()); 112 if (d < dmax) { 113 dmax = d; 114 index = i; 115 } 95 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 96 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 97 RoutingModel routingModel = layer.getRoutingModel(); 98 // Search for the nearest node in the list 99 List<Node> nl = routingModel.getSelectedNodes(); 100 int index = -1; 101 double dmax = REMOVE_SQR_RADIUS; // maximum distance, in pixels 102 for (int i=0;i<nl.size();i++) { 103 Node node = nl.get(i); 104 double d = Main.map.mapView.getPoint(node.eastNorth).distanceSq(e.getPoint()); 105 if (d < dmax) { 106 dmax = d; 107 index = i; 108 } 109 } 110 // If found a close node, remove it and recalculate route 111 if (index >= 0) { 112 // Remove node 113 logger.debug("Removing node " + nl.get(index)); 114 routingModel.removeNode(index); 115 routingDialog.removeNode(index); 116 Main.map.repaint(); 117 } else { 118 logger.debug("Can't find a node to remove."); 119 } 116 120 } 117 // If found a close node, remove it and recalculate route118 if (index >= 0) {119 // Remove node120 logger.debug("Removing node " + nl.get(index));121 routingModel.removeNode(index);122 routingDialog.removeNode(index);123 Main.map.repaint();124 } else {125 logger.debug("Can't find a node to remove.");126 }127 121 } 128 122 } -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingDialog.java
r14287 r14404 41 41 import javax.swing.border.EtchedBorder; 42 42 43 import org.openstreetmap.josm.Main; 44 import org.openstreetmap.josm.data.osm.Node; 43 45 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 44 46 import org.openstreetmap.josm.tools.Shortcut; 47 48 import com.innovant.josm.plugin.routing.RoutingLayer; 49 import com.innovant.josm.plugin.routing.RoutingModel; 45 50 46 51 … … 119 124 * @param obj 120 125 */ 121 public void addNode( Object txt) {122 model.addElement( txt);126 public void addNode(Node n) { 127 model.addElement(n.id+" ["+n.coor.toDisplayString()+"]"); 123 128 } 124 129 … … 128 133 * @param obj 129 134 */ 130 public void insertNode(int index, Object txt) {131 model.insertElementAt( txt, index);135 public void insertNode(int index, Node n) { 136 model.insertElementAt(n.id+" ["+n.coor.toDisplayString()+"]", index); 132 137 } 133 138 … … 139 144 } 140 145 146 public void refresh() { 147 clearNodes(); 148 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 149 RoutingLayer routingLayer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 150 RoutingModel routingModel = routingLayer.getRoutingModel(); 151 for (Node n : routingModel.getSelectedNodes()) { 152 addNode(n); 153 } 154 } 155 } 141 156 } -
applications/editors/josm/plugins/routing/src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java
r14395 r14404 70 70 public RoutingMenu(final String name) { 71 71 super(name); 72 final RoutingLayer routingLayer = RoutingPlugin.getInstance().getRoutingLayer();73 final RoutingModel routingModel = routingLayer.getRoutingModel();74 72 75 73 JMenuItem mi; 76 74 JMenu m; 77 75 78 startMI = new JMenuItem(tr(" Start routing"));76 startMI = new JMenuItem(tr("Add routing layer")); 79 77 startMI.addActionListener(new ActionListener() { 80 78 public void actionPerformed(ActionEvent e) { 81 if(!routingLayer.isLayerAdded()) { 82 routingLayer.setLayerAdded(); 83 Main.main.addLayer(routingLayer); 84 } 79 RoutingPlugin.getInstance().addLayer(); 85 80 } 86 81 }); … … 96 91 rshorter.addItemListener(new ItemListener() { 97 92 public void itemStateChanged(ItemEvent e) { 98 if (e.getStateChange()==ItemEvent.SELECTED) { 99 routingModel.routingGraph.setTypeRoute(RouteType.SHORTEST); 100 } else { 101 routingModel.routingGraph.setTypeRoute(RouteType.FASTEST); 102 } 103 routingModel.routingGraph.resetGraph(); 104 routingModel.routingGraph.createGraph(); 105 //TODO: Change this way 106 //FIXME: do not change node but recalculate routing. 107 routingModel.setNodesChanged(); 108 Main.map.repaint(); 93 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 94 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 95 RoutingModel routingModel = layer.getRoutingModel(); 96 if (e.getStateChange()==ItemEvent.SELECTED) { 97 routingModel.routingGraph.setTypeRoute(RouteType.SHORTEST); 98 } else { 99 routingModel.routingGraph.setTypeRoute(RouteType.FASTEST); 100 } 101 routingModel.routingGraph.resetGraph(); 102 routingModel.routingGraph.createGraph(); 103 //TODO: Change this way 104 //FIXME: do not change node but recalculate routing. 105 routingModel.setNodesChanged(); 106 Main.map.repaint(); 107 } 109 108 } 110 109 … … 122 121 cbmi.addItemListener(new ItemListener() { 123 122 public void itemStateChanged(ItemEvent e) { 124 if (e.getStateChange()==ItemEvent.SELECTED) 125 routingModel.routingGraph.getRoutingProfile().setOnewayUse(false); 126 else 127 routingModel.routingGraph.getRoutingProfile().setOnewayUse(true); 128 routingModel.setNodesChanged(); 129 Main.map.repaint(); 123 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 124 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 125 RoutingModel routingModel = layer.getRoutingModel(); 126 if (e.getStateChange()==ItemEvent.SELECTED) 127 routingModel.routingGraph.getRoutingProfile().setOnewayUse(false); 128 else 129 routingModel.routingGraph.getRoutingProfile().setOnewayUse(true); 130 routingModel.setNodesChanged(); 131 Main.map.repaint(); 132 } 130 133 } 131 134 }); … … 137 140 reverseMI.addActionListener(new ActionListener() { 138 141 public void actionPerformed(ActionEvent e) { 139 routingModel.reverseNodes(); 140 Main.map.repaint(); 142 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 143 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 144 RoutingModel routingModel = layer.getRoutingModel(); 145 routingModel.reverseNodes(); 146 Main.map.repaint(); 147 } 141 148 } 142 149 }); … … 146 153 clearMI.addActionListener(new ActionListener() { 147 154 public void actionPerformed(ActionEvent e) { 148 // Reset routing nodes and paths 149 routingModel.reset(); 150 RoutingPlugin.getInstance().getRoutingDialog().clearNodes(); 151 Main.map.repaint(); 155 if (Main.map.mapView.getActiveLayer() instanceof RoutingLayer) { 156 RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer(); 157 RoutingModel routingModel = layer.getRoutingModel(); 158 // Reset routing nodes and paths 159 routingModel.reset(); 160 RoutingPlugin.getInstance().getRoutingDialog().clearNodes(); 161 Main.map.repaint(); 162 } 152 163 } 153 164 });
Note:
See TracChangeset
for help on using the changeset viewer.