Changeset 19456 in osm for applications/editors/josm
- Timestamp:
- 2010-01-13T14:53:35+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/multipoly
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/multipoly/build.xml
r18962 r19456 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- 3 ** This is the build file for the multipoly plugin. 4 ** 5 ** Maintaining versions 6 ** ==================== 7 ** see README.template 8 ** 9 ** Usage 10 ** ===== 11 ** To build it run 12 ** 13 ** > ant dist 14 ** 15 ** To install the generated plugin locally (in you default plugin directory) run 16 ** 17 ** > ant install 18 ** 19 ** The generated plugin jar is not automatically available in JOSMs plugin configuration 20 ** dialog. You have to check it in first. 21 ** 22 ** Use the ant target 'publish' to check in the plugin and make it available to other 23 ** JOSM users: 24 ** set the properties commit.message and plugin.main.version 25 ** and run 26 ** > ant publish 27 ** 28 ** 29 --> 1 30 <project name="multipoly" default="dist" basedir="."> 2 31 3 <!-- compilation properties --> 4 <property name="josm.build.dir" value="../../core"/> 5 <property name="josm.home.dir" value="${user.home}/.josm"/> 6 <property name="josm" location="../../core/dist/josm-custom.jar" /> 7 <property name="plugin.build.dir" value="build"/> 8 <property name="plugin.dist.dir" value="../../dist"/> 9 <property name="plugin.name" value="${ant.project.name}"/> 10 <property name="plugin.jar" value="${plugin.dist.dir}/${plugin.name}.jar"/> 11 12 <!-- There's no josm.jar in the svn, so point "josm" to a local copy of your JOSM binary --> 13 <property name="josm" location="../../core/dist/josm-custom.jar" /> 14 15 <property name="ant.build.javac.target" value="1.5"/> 16 17 <target name="init"> 18 <mkdir dir="${plugin.build.dir}"></mkdir> 19 <mkdir dir="${plugin.dist.dir}"></mkdir> 20 </target> 21 22 <target name="compile" depends="init"> 23 <echo message="creating ${plugin.jar}"/> 24 <javac srcdir="src" target="1.5" classpath="${josm}" destdir="build" debug="true"> 25 <include name="**/*.java" /> 26 </javac> 27 </target> 28 29 <target name="revision"> 30 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 31 <env key="LANG" value="C"/> 32 <arg value="info"/> 33 <arg value="--xml"/> 34 <arg value="."/> 35 </exec> 36 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/> 37 <delete file="REVISION"/> 38 </target> 39 40 <target name="dist" depends="compile,revision"> 41 <copy todir="${plugin.build.dir}/images"> 42 <fileset dir="images"/> 43 </copy> 44 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 45 <manifest> 46 <attribute name="Author" value="Bilbo"/> 47 <attribute name="Plugin-Class" value="multipoly.MultipolyPlugin" /> 48 <attribute name="Plugin-Description" value="Create multipolygons by one click, much easier than standard way with relation editor." /> 49 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 50 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/> 51 <attribute name="Plugin-Link" value="http://svn.openstreetmap.org/applications/editors/josm/plugins/multipoly/"/> 52 <attribute name="Plugin-Mainversion" value="2578"/> 53 </manifest> 54 </jar> 55 </target> 56 57 <target name="clean"> 58 <delete dir="${plugin.build.dir}" /> 59 <delete file="${plugin.jar}" /> 60 </target> 61 62 <target name="clean_install"> 63 <delete file="${plugins}/multipoly.jar" /> 64 </target> 65 66 <target name="install" depends="dist"> 67 <property environment="env"/> 68 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 69 <and> 70 <os family="windows"/> 71 </and> 72 </condition> 73 <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/> 74 </target> 32 33 <!-- enter the SVN commit message --> 34 <property name="commit.message" value="Changed the constructor signature of the plugin main class" /> 35 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 36 <property name="plugin.main.version" value="2830" /> 37 38 39 <!-- compilation properties --> 40 <property name="josm.build.dir" value="../../core" /> 41 <property name="josm.home.dir" value="${user.home}/.josm" /> 42 <property name="josm" location="../../core/dist/josm-custom.jar" /> 43 <property name="plugin.build.dir" value="build" /> 44 <property name="plugin.dist.dir" value="../../dist" /> 45 <property name="plugin.name" value="${ant.project.name}" /> 46 <property name="plugin.jar" value="${plugin.dist.dir}/${plugin.name}.jar" /> 47 48 <!-- There's no josm.jar in the svn, so point "josm" to a local copy of your JOSM binary --> 49 <property name="josm" location="../../core/dist/josm-custom.jar" /> 50 51 <property name="ant.build.javac.target" value="1.5" /> 52 53 <target name="init"> 54 <mkdir dir="${plugin.build.dir}"> 55 </mkdir> 56 <mkdir dir="${plugin.dist.dir}"> 57 </mkdir> 58 </target> 59 60 <target name="compile" depends="init"> 61 <echo message="creating ${plugin.jar}" /> 62 <javac srcdir="src" target="1.5" classpath="${josm}" destdir="build" debug="true"> 63 <include name="**/*.java" /> 64 </javac> 65 </target> 66 67 <target name="revision"> 68 <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false"> 69 <env key="LANG" value="C" /> 70 <arg value="info" /> 71 <arg value="--xml" /> 72 <arg value="." /> 73 </exec> 74 <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true" /> 75 <delete file="REVISION" /> 76 </target> 77 78 <target name="dist" depends="compile,revision"> 79 <copy todir="${plugin.build.dir}/images"> 80 <fileset dir="images" /> 81 </copy> 82 <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}"> 83 <manifest> 84 <attribute name="Author" value="Bilbo" /> 85 <attribute name="Plugin-Class" value="multipoly.MultipolyPlugin" /> 86 <attribute name="Plugin-Description" value="Create multipolygons by one click, much easier than standard way with relation editor." /> 87 <attribute name="Plugin-Version" value="${version.entry.commit.revision}" /> 88 <attribute name="Plugin-Date" value="${version.entry.commit.date}" /> 89 <attribute name="Plugin-Link" value="http://svn.openstreetmap.org/applications/editors/josm/plugins/multipoly/" /> 90 <attribute name="Plugin-Mainversion" value="${plugin.main.version}" /> 91 </manifest> 92 </jar> 93 </target> 94 95 <target name="clean"> 96 <delete dir="${plugin.build.dir}" /> 97 <delete file="${plugin.jar}" /> 98 </target> 99 100 <target name="clean_install"> 101 <delete file="${plugins}/multipoly.jar" /> 102 </target> 103 104 <target name="install" depends="dist"> 105 <property environment="env" /> 106 <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins"> 107 <and> 108 <os family="windows" /> 109 </and> 110 </condition> 111 <copy file="${plugin.jar}" todir="${josm.plugins.dir}" /> 112 </target> 113 114 <!-- 115 ************************** Publishing the plugin *********************************** 116 --> 117 <!-- 118 ** extracts the JOSM release for the JOSM version in ../core and saves it in the 119 ** property ${coreversion.info.entry.revision} 120 ** 121 --> 122 <target name="core-info"> 123 <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false"> 124 <env key="LANG" value="C" /> 125 <arg value="info" /> 126 <arg value="--xml" /> 127 <arg value="../../core" /> 128 </exec> 129 <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true" /> 130 <echo>Building against core revision ${coreversion.info.entry.revision}.</echo> 131 <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo> 132 <delete file="core.info.xml" /> 133 </target> 134 135 <!-- 136 ** commits the source tree for this plugin 137 --> 138 <target name="commit-current"> 139 <echo>Commiting the plugin source with message '${commit.message}' ...</echo> 140 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 141 <env key="LANG" value="C" /> 142 <arg value="commit" /> 143 <arg value="-m '${commit.message}'" /> 144 <arg value="." /> 145 </exec> 146 </target> 147 148 <!-- 149 ** updates (svn up) the source tree for this plugin 150 --> 151 <target name="update-current"> 152 <echo>Updating plugin source ...</echo> 153 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 154 <env key="LANG" value="C" /> 155 <arg value="up" /> 156 <arg value="." /> 157 </exec> 158 <echo>Updating ${plugin.jar} ...</echo> 159 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 160 <env key="LANG" value="C" /> 161 <arg value="up" /> 162 <arg value="../dist/${plugin.jar}" /> 163 </exec> 164 </target> 165 166 <!-- 167 ** commits the plugin.jar 168 --> 169 <target name="commit-dist"> 170 <echo> 171 ***** Properties of published ${plugin.jar} ***** 172 Commit message : '${commit.message}' 173 Plugin-Mainversion: ${plugin.main.version} 174 JOSM build version: ${coreversion.info.entry.revision} 175 Plugin-Version : ${version.entry.commit.revision} 176 ***** / Properties of published ${plugin.jar} ***** 177 178 Now commiting ${plugin.jar} ... 179 </echo> 180 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false"> 181 <env key="LANG" value="C" /> 182 <arg value="-m '${commit.message}'" /> 183 <arg value="commit" /> 184 <arg value="${plugin.jar}" /> 185 </exec> 186 </target> 187 188 <!-- ** make sure svn is present as a command line tool ** --> 189 <target name="ensure-svn-present"> 190 <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code"> 191 <env key="LANG" value="C" /> 192 <arg value="--version" /> 193 </exec> 194 <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system."> 195 <!-- return code not set at all? Most likely svn isn't installed --> 196 <condition> 197 <not> 198 <isset property="svn.exit.code" /> 199 </not> 200 </condition> 201 </fail> 202 <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system."> 203 <!-- error code from SVN? Most likely svn is not what we are looking on this system --> 204 <condition> 205 <isfailure code="${svn.exit.code}" /> 206 </condition> 207 </fail> 208 </target> 209 210 <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist"> 211 </target> 75 212 76 213 </project> -
applications/editors/josm/plugins/multipoly/src/multipoly/MultipolyAction.java
r19138 r19456 30 30 /** 31 31 * Create multipolygon from selected ways automatically. 32 * 32 * 33 33 * New relation with type=multipolygon is created 34 * 35 * If one or more of ways is already in relation with type=multipolygon or the way is not closed,36 * then error is reported and no relation is created37 * 38 * The "inner" and "outer" roles are guessed automatically. 39 * First, bbox is calculated for each way. then the largest area is assumed to be outside40 * and the rest inside41 * In cases with one "outside" area and several cut-ins, the guess should be always good ...42 * In more complex (multiple outer areas) or buggy (inner and outer ways intersect) scenarios43 * the result is likely to bewrong.34 * 35 * If one or more of ways is already in relation with type=multipolygon or the 36 * way is not closed, then error is reported and no relation is created 37 * 38 * The "inner" and "outer" roles are guessed automatically. First, bbox is 39 * calculated for each way. then the largest area is assumed to be outside and 40 * the rest inside In cases with one "outside" area and several cut-ins, the 41 * guess should be always good ... In more complex (multiple outer areas) or 42 * buggy (inner and outer ways intersect) scenarios the result is likely to be 43 * wrong. 44 44 */ 45 45 public class MultipolyAction extends JosmAction { 46 46 47 public MultipolyAction() { 48 super(tr("Create multipolygon"), "multipoly_create", tr("Create multipolygon."), 49 Shortcut.registerShortcut("tools:multipoly", tr("Tool: {0}", tr("Create multipolygon")), 50 KeyEvent.VK_M, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 51 } 47 public MultipolyAction() { 48 super(tr("Create multipolygon"), "multipoly_create", 49 tr("Create multipolygon."), Shortcut.registerShortcut( 50 "tools:multipoly", tr("Tool: {0}", 51 tr("Create multipolygon")), KeyEvent.VK_M, 52 Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 53 } 52 54 53 /** 54 * The action button has been clicked 55 * @param e Action Event 56 */ 57 public void actionPerformed(ActionEvent e) { 55 /** 56 * The action button has been clicked 57 * 58 * @param e 59 * Action Event 60 */ 61 public void actionPerformed(ActionEvent e) { 58 62 59 // Get all ways in some type=multipolygon relation 60 HashSet<OsmPrimitive> relationsInMulti = new HashSet<OsmPrimitive>(); 61 for (Relation r : Main.main.getCurrentDataSet().getRelations()) { 62 if (!r.isUsable()) continue; 63 if (r.get("type")!="multipolygon") continue; 64 for (RelationMember rm : r.getMembers()) { 65 OsmPrimitive m=rm.getMember(); 66 if (m instanceof Way) { 67 relationsInMulti.add(m); 68 } 69 } 70 } 63 // Get all ways in some type=multipolygon relation 64 HashSet<OsmPrimitive> relationsInMulti = new HashSet<OsmPrimitive>(); 65 for (Relation r : Main.main.getCurrentDataSet().getRelations()) { 66 if (!r.isUsable()) 67 continue; 68 if (r.get("type") != "multipolygon") 69 continue; 70 for (RelationMember rm : r.getMembers()) { 71 OsmPrimitive m = rm.getMember(); 72 if (m instanceof Way) { 73 relationsInMulti.add(m); 74 } 75 } 76 } 71 77 72 //List of selected ways73 74 //Area of largest way (in square degrees)75 double maxarea=0;76 //Which way is the largest one (outer)77 Way maxWay=null;78 // List of selected ways 79 List<Way> selectedWays = new ArrayList<Way>(); 80 // Area of largest way (in square degrees) 81 double maxarea = 0; 82 // Which way is the largest one (outer) 83 Way maxWay = null; 78 84 79 // For every selected way 80 for (OsmPrimitive osm : Main.main.getCurrentDataSet().getSelected()) { 81 if (osm instanceof Way) { 82 Way way = (Way)osm; 83 //Check if way is already in another multipolygon 84 if (relationsInMulti.contains(osm)) { 85 JOptionPane.showMessageDialog(Main.parent,tr("One of the selected ways is already part of another multipolygon.")); 86 return; 87 } 88 EastNorth first=null,last=null; 89 //Boundingbox of way 90 double minx=9999,miny=9999,maxx=-9999,maxy=-9999; 91 for (Pair<Node,Node> seg : way.getNodePairs(false)) { 92 if (first==null) first=seg.a.getEastNorth(); 93 last=seg.b.getEastNorth(); 94 double x=seg.a.getEastNorth().east(); 95 double y=seg.a.getEastNorth().north(); 96 if (x<minx) minx=x; 97 if (y<miny) miny=y; 98 if (x>maxx) maxx=x; 99 if (y>maxy) maxy=y; 100 } 101 //Check if first and last node are the same 102 if (!first.equals(last)) { 103 JOptionPane.showMessageDialog(Main.parent,tr("Multipolygon must consist only of closed ways.")); 104 return; 105 } 106 //Determine area 107 double area=(maxx-minx)*(maxy-miny); 108 selectedWays.add(way); 109 if (area>maxarea) { 110 maxarea=area; 111 maxWay=way; 112 } 113 } 114 } 85 // For every selected way 86 for (OsmPrimitive osm : Main.main.getCurrentDataSet().getSelected()) { 87 if (osm instanceof Way) { 88 Way way = (Way) osm; 89 // Check if way is already in another multipolygon 90 if (relationsInMulti.contains(osm)) { 91 JOptionPane 92 .showMessageDialog( 93 Main.parent, 94 tr("One of the selected ways is already part of another multipolygon.")); 95 return; 96 } 97 EastNorth first = null, last = null; 98 // Boundingbox of way 99 double minx = 9999, miny = 9999, maxx = -9999, maxy = -9999; 100 for (Pair<Node, Node> seg : way.getNodePairs(false)) { 101 if (first == null) 102 first = seg.a.getEastNorth(); 103 last = seg.b.getEastNorth(); 104 double x = seg.a.getEastNorth().east(); 105 double y = seg.a.getEastNorth().north(); 106 if (x < minx) 107 minx = x; 108 if (y < miny) 109 miny = y; 110 if (x > maxx) 111 maxx = x; 112 if (y > maxy) 113 maxy = y; 114 } 115 // Check if first and last node are the same 116 if (!first.equals(last)) { 117 JOptionPane 118 .showMessageDialog( 119 Main.parent, 120 tr("Multipolygon must consist only of closed ways.")); 121 return; 122 } 123 // Determine area 124 double area = (maxx - minx) * (maxy - miny); 125 selectedWays.add(way); 126 if (area > maxarea) { 127 maxarea = area; 128 maxWay = way; 129 } 130 } 131 } 115 132 116 117 118 119 133 if (Main.map == null) { 134 JOptionPane.showMessageDialog(Main.parent, tr("No data loaded.")); 135 return; 136 } 120 137 121 if (selectedWays.size()<2) { 122 JOptionPane.showMessageDialog(Main.parent, tr("You must select at least two ways.")); 123 return; 124 } 138 if (selectedWays.size() < 2) { 139 JOptionPane.showMessageDialog(Main.parent, 140 tr("You must select at least two ways.")); 141 return; 142 } 125 143 126 Collection<Command> cmds = new LinkedList<Command>(); 127 //Create new relation 128 Relation rel=new Relation(); 129 rel.put("type","multipolygon"); 130 //Add ways to it 131 for (int i=0;i<selectedWays.size();i++) { 132 Way s=selectedWays.get(i); 133 String xrole="inner"; 134 if (s==maxWay) xrole="outer"; 135 RelationMember rm=new RelationMember(xrole,s); 136 rel.addMember(rm); 137 } 138 //Add relation 139 cmds.add(new AddCommand(rel)); 140 //Commit 141 Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), cmds)); 142 Main.map.repaint(); 143 } 144 Collection<Command> cmds = new LinkedList<Command>(); 145 // Create new relation 146 Relation rel = new Relation(); 147 rel.put("type", "multipolygon"); 148 // Add ways to it 149 for (int i = 0; i < selectedWays.size(); i++) { 150 Way s = selectedWays.get(i); 151 String xrole = "inner"; 152 if (s == maxWay) 153 xrole = "outer"; 154 RelationMember rm = new RelationMember(xrole, s); 155 rel.addMember(rm); 156 } 157 // Add relation 158 cmds.add(new AddCommand(rel)); 159 // Commit 160 Main.main.undoRedo.add(new SequenceCommand(tr("Create multipolygon"), 161 cmds)); 162 Main.map.repaint(); 163 } 144 164 145 /** Enable this action only if something is selected */ 146 @Override protected void updateEnabledState() { 147 if (getCurrentDataSet()==null) { 148 setEnabled(false); 149 } else { 150 updateEnabledState(getCurrentDataSet().getSelected()); 151 } 152 } 165 /** Enable this action only if something is selected */ 166 @Override 167 protected void updateEnabledState() { 168 if (getCurrentDataSet() == null) { 169 setEnabled(false); 170 } else { 171 updateEnabledState(getCurrentDataSet().getSelected()); 172 } 173 } 153 174 154 /** Enable this action only if something is selected */ 155 @Override protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 156 setEnabled(selection != null && !selection.isEmpty()); 157 } 158 175 /** Enable this action only if something is selected */ 176 @Override 177 protected void updateEnabledState( 178 Collection<? extends OsmPrimitive> selection) { 179 setEnabled(selection != null && !selection.isEmpty()); 180 } 159 181 } -
applications/editors/josm/plugins/multipoly/src/multipoly/MultipolyPlugin.java
r19138 r19456 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.plugins.Plugin; 10 import org.openstreetmap.josm.plugins.PluginInformation; 10 11 11 12 /** … … 14 15 public class MultipolyPlugin extends Plugin { 15 16 16 17 protected String name; 17 18 18 public MultipolyPlugin() { 19 name = tr("Create multipolygon"); 20 JMenu toolsMenu = null; 21 for (int i = 0; i < Main.main.menu.getMenuCount() && toolsMenu == null; i++) { 22 JMenu menu = Main.main.menu.getMenu(i); 23 String name = menu.getText(); 24 if (name != null && name.equals(tr("Tools"))) { 25 toolsMenu = menu; 26 } 27 } 19 public MultipolyPlugin(PluginInformation info) { 20 super(info); 21 name = tr("Create multipolygon"); 22 JMenu toolsMenu = null; 23 for (int i = 0; i < Main.main.menu.getMenuCount() && toolsMenu == null; i++) { 24 JMenu menu = Main.main.menu.getMenu(i); 25 String name = menu.getText(); 26 if (name != null && name.equals(tr("Tools"))) { 27 toolsMenu = menu; 28 } 29 } 28 30 29 if (toolsMenu == null) { 30 toolsMenu = new JMenu(name); 31 toolsMenu.add(new JMenuItem(new MultipolyAction())); 32 Main.main.menu.add(toolsMenu, 2); 33 } else { 34 toolsMenu.addSeparator(); 35 toolsMenu.add(new JMenuItem(new MultipolyAction())); 36 } 37 38 } 39 31 if (toolsMenu == null) { 32 toolsMenu = new JMenu(name); 33 toolsMenu.add(new JMenuItem(new MultipolyAction())); 34 Main.main.menu.add(toolsMenu, 2); 35 } else { 36 toolsMenu.addSeparator(); 37 toolsMenu.add(new JMenuItem(new MultipolyAction())); 38 } 39 } 40 40 }
Note:
See TracChangeset
for help on using the changeset viewer.