Changes between Version 14 and Version 15 of Help/Plugin/Scripting/Python
- Timestamp:
- 2018-09-07T18:59:55+02:00 (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Help/Plugin/Scripting/Python
v14 v15 18 18 19 19 if not(selected_ways) or len(selected_ways)>1: 20 JOptionPane.showMessageDialog(MainApplication.parent, "Please select a single way that connects to a roundabout") 20 JOptionPane.showMessageDialog(MainApplication.parent, 21 "Please select a single way that connects to a roundabout") 21 22 else: 22 23 for way in selected_ways: … … 35 36 for n in parentway.getNodes(): 36 37 if common_node: 37 # found common node between selected way and roundabout way in previous iteration 38 # found common node between selected way and 39 # roundabout way in previous iteration 38 40 node_after = n 39 41 # we are done here … … 43 45 common_node = n 44 46 if not(node_before): 45 # normally we encountered a node on the roundabout way before this one 46 # but if the common node is the first node of an unsplit roundabout 47 # we will need to take the last node of the roundabout instead 47 # normally we encountered a node on the roundabout way 48 # before this one, but if the common node is the first node 49 # of an unsplit roundabout, we will need to take the last 50 # node of the roundabout instead 48 51 node_before = parentway.getNodes()[-2] 49 52 node_after = parentway.getNodes()[1] 50 53 break 51 # if not we go through the loop one more time to put the next node in node_after 54 # if not we go through the loop one more time to put the next 55 # node in node_after 52 56 continue 53 57 node_before = n 54 58 if common_node: 55 # if common_node is already defined at this point, it means it was the first node of the selected way 59 # if common_node is already defined at this point, it means it was 60 # the first node of the selected way, 56 61 # so it will have to be replaced with node_before in the selected way 57 62 common_node_becomes_node_before = True … … 62 67 adjacent_node_to_split_on = way.getNodes()[-1] 63 68 if not(common_node) or common_node_becomes_node_before==None: 64 JOptionPane.showMessageDialog(MainApplication.parent, "Please select a way that connects to a roundabout") 69 JOptionPane.showMessageDialog(MainApplication.parent, 70 "Please select a way that connects to a roundabout") 65 71 else: 66 72 print common_node.get('name') … … 70 76 commandsList = [] 71 77 if len(way.getNodes())>2: 72 commandsList.append(Command.SplitWayCommand.split(way, [adjacent_node_to_split_on], [])) 73 MainApplication.undoRedo.add(Command.SequenceCommand("Split selected way", commandsList)) 78 # split off last segment before roundabout if needed 79 commandsList.append(Command.SplitWayCommand.split( 80 way, [adjacent_node_to_split_on], [])) 81 MainApplication.undoRedo.add(Command.SequenceCommand( 82 "Split selected way", commandsList)) 74 83 commandsList = [] 84 # After splitting find the segment that connects to the roundabout again 75 85 for waypartconnectedtoroundabout in adjacent_node_to_split_on.getParentWays(): 76 86 if common_node in waypartconnectedtoroundabout.getNodes(): … … 86 96 # replace its nodes, so it becomes a fork 87 97 modified_way.setNodes([node_before, adjacent_node_to_split_on, node_after]) 88 # 98 # add oneway tag 89 99 modified_way.put('oneway', 'yes') 90 # 91 commandsList.append(Command.ChangeCommand(waypartconnectedtoroundabout, modified_way)) 92 MainApplication.undoRedo.add(Command.SequenceCommand("Add oneway tag and create forked way", commandsList)) 100 # apply the changes 101 commandsList.append(Command.ChangeCommand( 102 waypartconnectedtoroundabout, modified_way)) 103 MainApplication.undoRedo.add(Command.SequenceCommand( 104 "Add oneway tag and create forked way", commandsList)) 93 105 commandsList = [] 94 commandsList.append(Command.SplitWayCommand.split(waypartconnectedtoroundabout, [adjacent_node_to_split_on], [])) 95 MainApplication.undoRedo.add(Command.SequenceCommand("Split fork into 2 ways", commandsList)) 106 # split this way where it forks 107 commandsList.append(Command.SplitWayCommand.split( 108 waypartconnectedtoroundabout, [adjacent_node_to_split_on], [])) 109 MainApplication.undoRedo.add(Command.SequenceCommand( 110 "Split fork into 2 ways", commandsList)) 96 111 commandsList = [] 97 112
