1 | #
|
---|
2 | # Adds command queue listener that will perform utilsplugin2's AddNodesAtIntersections command after encountering Extrude command
|
---|
3 | #
|
---|
4 | # Usage: Run once per JOSM session
|
---|
5 | #
|
---|
6 |
|
---|
7 | print
|
---|
8 | print "[AutoAddIntersections] Startup"
|
---|
9 |
|
---|
10 | from javax.swing import JOptionPane
|
---|
11 | from org.openstreetmap.josm import Main
|
---|
12 | from org.openstreetmap.josm.gui.layer.OsmDataLayer import CommandQueueListener
|
---|
13 | from org.openstreetmap.josm.tools.I18n import tr
|
---|
14 | try:
|
---|
15 | from org.openstreetmap.josm.plugins.utilsplugin2.actions import AddIntersectionsAction
|
---|
16 | except ImportError:
|
---|
17 | JOptionPane.showMessageDialog(Main.parent, "utilsplugin2 not found.")
|
---|
18 |
|
---|
19 | extrudeCommandText = tr("Extrude Way")
|
---|
20 |
|
---|
21 | def getAction():
|
---|
22 | """Finds utilsplugin2's AddIntersectionsAction in the menu"""
|
---|
23 | if not Main.main or not Main.main.menu:
|
---|
24 | return None
|
---|
25 | menubar = Main.main.menu
|
---|
26 | # try directly first item of fourth menu
|
---|
27 | i, j = 4, 1
|
---|
28 | menu = menubar.getMenu(i)
|
---|
29 | if menu:
|
---|
30 | menuitem = menu.getItem(j)
|
---|
31 | if menuitem:
|
---|
32 | action = menuitem.getAction()
|
---|
33 | if action and isinstance(action, AddIntersectionsAction):
|
---|
34 | print "[AutoAddIntersections] Action found directly at %d/%d (%s/%s)" % (i, j, menu.getText(), menuitem.getText())
|
---|
35 | return action
|
---|
36 | # search all menus
|
---|
37 | for i in range(0, menubar.getMenuCount()):
|
---|
38 | menu = menubar.getMenu(i)
|
---|
39 | if menu:
|
---|
40 | for j in range(0, menu.getItemCount()):
|
---|
41 | menuitem = menu.getItem(j)
|
---|
42 | if menuitem:
|
---|
43 | action = menuitem.getAction()
|
---|
44 | if action and isinstance(action, AddIntersectionsAction):
|
---|
45 | print "[AutoAddIntersections] Action found at %d/%d (%s/%s)" % (i, j, menu.getText(), menuitem.getText())
|
---|
46 | return action
|
---|
47 | JOptionPane.showMessageDialog(Main.parent, "Add nodes at intersections command not found.")
|
---|
48 | return None
|
---|
49 |
|
---|
50 | undoRedo = Main.main.undoRedo
|
---|
51 | cmds = undoRedo.commands
|
---|
52 | action = getAction()
|
---|
53 |
|
---|
54 | class myCommandQueueListener(CommandQueueListener):
|
---|
55 | def commandChanged(self, queueSize, redoSize):
|
---|
56 | if queueSize > 0 and redoSize == 0:
|
---|
57 | cmdDesc = cmds.getLast().getDescriptionText()
|
---|
58 | if extrudeCommandText in cmdDesc:
|
---|
59 | print "[AutoAddIntersections] Extrude command detected, performing action"
|
---|
60 | action.actionPerformed(None);
|
---|
61 |
|
---|
62 | mcql = myCommandQueueListener()
|
---|
63 | undoRedo.addCommandQueueListener(mcql)
|
---|
64 |
|
---|
65 | print "[AutoAddIntersections] Done"
|
---|