Changeset 32479 in osm for applications/editors/josm/plugins/indoor_sweepline
- Timestamp:
- 2016-07-01T09:34:44+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/indoor_sweepline
- Files:
-
- 5 added
- 12 edited
-
.classpath (added)
-
.project (added)
-
.settings (added)
-
.settings/org.eclipse.jdt.core.prefs (added)
-
.settings/org.eclipse.jdt.ui.prefs (added)
-
build.xml (modified) (1 diff)
-
src/indoor_sweepline/Beam.java (modified) (2 diffs)
-
src/indoor_sweepline/BeamGeography.java (modified) (3 diffs)
-
src/indoor_sweepline/CorridorGeography.java (modified) (2 diffs)
-
src/indoor_sweepline/CorridorPart.java (modified) (1 diff)
-
src/indoor_sweepline/IndoorSweepline.java (modified) (1 diff)
-
src/indoor_sweepline/IndoorSweeplineController.java (modified) (2 diffs)
-
src/indoor_sweepline/IndoorSweeplineModel.java (modified) (5 diffs)
-
src/indoor_sweepline/IndoorSweeplineWizardAction.java (modified) (2 diffs)
-
src/indoor_sweepline/IndoorSweeplineWizardDialog.java (modified) (4 diffs)
-
src/indoor_sweepline/ModelGeography.java (modified) (2 diffs)
-
src/indoor_sweepline/Strip.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoor_sweepline/build.xml
r32103 r32479 5 5 <property name="commit.message" value="Commit message"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value=" 7817"/>7 <property name="plugin.main.version" value="10279"/> 8 8 9 9 <property name="plugin.author" value="Roland M. Olbricht"/> -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/Beam.java
r32109 r32479 8 8 public Beam(Vector<Double> blueprint, double blueprintOffset, CorridorPart.ReachableSide defaultSide) 9 9 { 10 offset = blueprintOffset;11 parts = new Vector<CorridorPart>();12 13 setDefaultSide_(defaultSide);14 if (defaultSide == CorridorPart.ReachableSide.RIGHT)15 {16 for (int i = 1; i < blueprint.size(); i += 2)17 {18 addCorridorPart_(true, CorridorPart.Type.WALL,19 blueprint.elementAt(i).doubleValue() - blueprint.elementAt(i-1).doubleValue());20 if (i+1 < blueprint.size())21 addCorridorPart_(true, CorridorPart.Type.VOID,22 blueprint.elementAt(i+1).doubleValue() - blueprint.elementAt(i).doubleValue());23 }24 }25 else26 {27 for (int i = 1; i < blueprint.size(); i += 2)28 {29 addCorridorPart_(true, CorridorPart.Type.PASSAGE,30 blueprint.elementAt(i).doubleValue() - blueprint.elementAt(i-1).doubleValue());31 if (i+1 < blueprint.size())32 addCorridorPart_(true, CorridorPart.Type.VOID,33 blueprint.elementAt(i+1).doubleValue() - blueprint.elementAt(i).doubleValue());34 }35 }36 adjustStripCache();37 } 38 39 10 offset = blueprintOffset; 11 parts = new Vector<>(); 12 13 setDefaultSide_(defaultSide); 14 if (defaultSide == CorridorPart.ReachableSide.RIGHT) 15 { 16 for (int i = 1; i < blueprint.size(); i += 2) 17 { 18 addCorridorPart_(true, CorridorPart.Type.WALL, 19 blueprint.elementAt(i).doubleValue() - blueprint.elementAt(i-1).doubleValue()); 20 if (i+1 < blueprint.size()) 21 addCorridorPart_(true, CorridorPart.Type.VOID, 22 blueprint.elementAt(i+1).doubleValue() - blueprint.elementAt(i).doubleValue()); 23 } 24 } 25 else 26 { 27 for (int i = 1; i < blueprint.size(); i += 2) 28 { 29 addCorridorPart_(true, CorridorPart.Type.PASSAGE, 30 blueprint.elementAt(i).doubleValue() - blueprint.elementAt(i-1).doubleValue()); 31 if (i+1 < blueprint.size()) 32 addCorridorPart_(true, CorridorPart.Type.VOID, 33 blueprint.elementAt(i+1).doubleValue() - blueprint.elementAt(i).doubleValue()); 34 } 35 } 36 adjustStripCache(); 37 } 38 39 40 40 private void setDefaultSide_(CorridorPart.ReachableSide defaultSide) 41 41 { 42 this.defaultSide = defaultSide;43 } 44 42 this.defaultSide = defaultSide; 43 } 44 45 45 public void setDefaultSide(CorridorPart.ReachableSide defaultSide) 46 46 { 47 setDefaultSide_(defaultSide);48 adjustStripCache();49 } 50 51 47 setDefaultSide_(defaultSide); 48 adjustStripCache(); 49 } 50 51 52 52 public Vector<CorridorPart> getBeamParts() 53 53 { 54 return parts;55 } 56 57 54 return parts; 55 } 56 57 58 58 public double getBeamOffset() 59 59 { 60 return offset;61 } 62 60 return offset; 61 } 62 63 63 public void setBeamOffset(double beamOffset) 64 64 { 65 offset = beamOffset;66 } 67 68 65 offset = beamOffset; 66 } 67 68 69 69 private void addCorridorPart_(boolean append, CorridorPart.Type type, double width) 70 70 { 71 CorridorPart.ReachableSide side = defaultSide == CorridorPart.ReachableSide.RIGHT ?72 defaultSide : CorridorPart.ReachableSide.ALL;73 74 if (append)75 parts.add(new CorridorPart(width, type, side));76 else77 parts.add(0, new CorridorPart(width, type, side));71 CorridorPart.ReachableSide side = defaultSide == CorridorPart.ReachableSide.RIGHT ? 72 defaultSide : CorridorPart.ReachableSide.ALL; 73 74 if (append) 75 parts.add(new CorridorPart(width, type, side)); 76 else 77 parts.add(0, new CorridorPart(width, type, side)); 78 78 } 79 79 80 80 public void addCorridorPart(boolean append, double width) 81 81 { 82 addCorridorPart_(append,83 defaultSide == CorridorPart.ReachableSide.RIGHT ? CorridorPart.Type.WALL : CorridorPart.Type.PASSAGE,84 width);85 adjustStripCache();86 } 87 88 82 addCorridorPart_(append, 83 defaultSide == CorridorPart.ReachableSide.RIGHT ? CorridorPart.Type.WALL : CorridorPart.Type.PASSAGE, 84 width); 85 adjustStripCache(); 86 } 87 88 89 89 public void setCorridorPartWidth(int partIndex, double value) 90 90 { 91 parts.elementAt(partIndex).width = value;92 adjustStripCache();93 } 94 95 91 parts.elementAt(partIndex).width = value; 92 adjustStripCache(); 93 } 94 95 96 96 public void setCorridorPartType(int partIndex, CorridorPart.Type type) 97 97 { 98 parts.elementAt(partIndex).setType(type, defaultSide);99 enforceSideCoherence();100 adjustStripCache();101 } 102 103 98 parts.elementAt(partIndex).setType(type, defaultSide); 99 enforceSideCoherence(); 100 adjustStripCache(); 101 } 102 103 104 104 public void setCorridorPartSide(int partIndex, CorridorPart.ReachableSide side) 105 105 { 106 parts.elementAt(partIndex).setSide(side, defaultSide);107 enforceSideCoherence();108 adjustStripCache();109 } 110 111 106 parts.elementAt(partIndex).setSide(side, defaultSide); 107 enforceSideCoherence(); 108 adjustStripCache(); 109 } 110 111 112 112 private void enforceSideCoherence() 113 113 { 114 for (int i = 1; i < parts.size(); ++i)115 {116 if (parts.elementAt(i).getSide() != CorridorPart.ReachableSide.ALL117 && parts.elementAt(i-1).getSide() != CorridorPart.ReachableSide.ALL)118 parts.elementAt(i).setSide(parts.elementAt(i-1).getSide(), defaultSide);119 }120 } 121 122 114 for (int i = 1; i < parts.size(); ++i) 115 { 116 if (parts.elementAt(i).getSide() != CorridorPart.ReachableSide.ALL 117 && parts.elementAt(i-1).getSide() != CorridorPart.ReachableSide.ALL) 118 parts.elementAt(i).setSide(parts.elementAt(i-1).getSide(), defaultSide); 119 } 120 } 121 122 123 123 private boolean isVoidAbove(int i) 124 124 { 125 return i == 0 || parts.elementAt(i-1).getType() == CorridorPart.Type.VOID126 || (parts.elementAt(i-1).getSide() == CorridorPart.ReachableSide.RIGHT127 && defaultSide == CorridorPart.ReachableSide.LEFT)128 || (parts.elementAt(i-1).getSide() == CorridorPart.ReachableSide.LEFT129 && defaultSide == CorridorPart.ReachableSide.RIGHT);130 } 131 125 return i == 0 || parts.elementAt(i-1).getType() == CorridorPart.Type.VOID 126 || (parts.elementAt(i-1).getSide() == CorridorPart.ReachableSide.RIGHT 127 && defaultSide == CorridorPart.ReachableSide.LEFT) 128 || (parts.elementAt(i-1).getSide() == CorridorPart.ReachableSide.LEFT 129 && defaultSide == CorridorPart.ReachableSide.RIGHT); 130 } 131 132 132 private boolean isVoidBelow(int i) 133 133 { 134 return i == parts.size() || parts.elementAt(i).getType() == CorridorPart.Type.VOID135 || (parts.elementAt(i).getSide() == CorridorPart.ReachableSide.RIGHT136 && defaultSide == CorridorPart.ReachableSide.LEFT)137 || (parts.elementAt(i).getSide() == CorridorPart.ReachableSide.LEFT138 && defaultSide == CorridorPart.ReachableSide.RIGHT);139 } 140 134 return i == parts.size() || parts.elementAt(i).getType() == CorridorPart.Type.VOID 135 || (parts.elementAt(i).getSide() == CorridorPart.ReachableSide.RIGHT 136 && defaultSide == CorridorPart.ReachableSide.LEFT) 137 || (parts.elementAt(i).getSide() == CorridorPart.ReachableSide.LEFT 138 && defaultSide == CorridorPart.ReachableSide.RIGHT); 139 } 140 141 141 private boolean isPassageAbove(int i) 142 142 { 143 return i > 0144 && parts.elementAt(i-1).getType() == CorridorPart.Type.PASSAGE145 && defaultSide == CorridorPart.ReachableSide.ALL;146 } 147 143 return i > 0 144 && parts.elementAt(i-1).getType() == CorridorPart.Type.PASSAGE 145 && defaultSide == CorridorPart.ReachableSide.ALL; 146 } 147 148 148 private boolean isPassageBelow(int i) 149 149 { 150 return i < parts.size()151 && parts.elementAt(i).getType() == CorridorPart.Type.PASSAGE152 && defaultSide == CorridorPart.ReachableSide.ALL;153 } 154 150 return i < parts.size() 151 && parts.elementAt(i).getType() == CorridorPart.Type.PASSAGE 152 && defaultSide == CorridorPart.ReachableSide.ALL; 153 } 154 155 155 private boolean isReachableLeft(int i) 156 156 { 157 if (defaultSide == CorridorPart.ReachableSide.RIGHT)158 return false;159 if (parts.elementAt(i).getSide() == CorridorPart.ReachableSide.LEFT)160 return true;161 return defaultSide == CorridorPart.ReachableSide.LEFT;162 } 163 164 157 if (defaultSide == CorridorPart.ReachableSide.RIGHT) 158 return false; 159 if (parts.elementAt(i).getSide() == CorridorPart.ReachableSide.LEFT) 160 return true; 161 return defaultSide == CorridorPart.ReachableSide.LEFT; 162 } 163 164 165 165 private void connectTwoPos(StripPosition newPos, boolean toLeft) 166 166 { 167 StripPosition other = null;168 if (rhsStrips.size() > 0 && rhsStrips.elementAt(rhsStrips.size()-1).connectedTo == -1)169 {170 newPos.connectedToSameSide = !toLeft;171 newPos.connectedTo = rhsStrips.size()-1;172 other = rhsStrips.elementAt(rhsStrips.size()-1);173 }174 else175 {176 newPos.connectedToSameSide = toLeft;177 newPos.connectedTo = lhsStrips.size()-1;178 other = lhsStrips.elementAt(lhsStrips.size()-1);179 }180 181 other.connectedToSameSide = newPos.connectedToSameSide;182 if (toLeft)183 {184 other.connectedTo = lhsStrips.size();185 lhsStrips.add(newPos);186 }187 else188 {189 other.connectedTo = rhsStrips.size();190 rhsStrips.add(newPos);191 }192 } 193 194 167 StripPosition other = null; 168 if (rhsStrips.size() > 0 && rhsStrips.elementAt(rhsStrips.size()-1).connectedTo == -1) 169 { 170 newPos.connectedToSameSide = !toLeft; 171 newPos.connectedTo = rhsStrips.size()-1; 172 other = rhsStrips.elementAt(rhsStrips.size()-1); 173 } 174 else 175 { 176 newPos.connectedToSameSide = toLeft; 177 newPos.connectedTo = lhsStrips.size()-1; 178 other = lhsStrips.elementAt(lhsStrips.size()-1); 179 } 180 181 other.connectedToSameSide = newPos.connectedToSameSide; 182 if (toLeft) 183 { 184 other.connectedTo = lhsStrips.size(); 185 lhsStrips.add(newPos); 186 } 187 else 188 { 189 other.connectedTo = rhsStrips.size(); 190 rhsStrips.add(newPos); 191 } 192 } 193 194 195 195 private class StripPosition 196 196 { 197 StripPosition(int nodeIndex, double offset)198 {199 this.nodeIndex = nodeIndex;200 this.offset = offset;201 connectedTo = -1;202 connectedToSameSide = false;203 }204 205 public int nodeIndex;206 public double offset;207 public int connectedTo;208 public boolean connectedToSameSide;209 } 210 211 197 StripPosition(int nodeIndex, double offset) 198 { 199 this.nodeIndex = nodeIndex; 200 this.offset = offset; 201 connectedTo = -1; 202 connectedToSameSide = false; 203 } 204 205 public int nodeIndex; 206 public double offset; 207 public int connectedTo; 208 public boolean connectedToSameSide; 209 } 210 211 212 212 private double offset; 213 213 private Vector<CorridorPart> parts; … … 215 215 private Vector<StripPosition> rhsStrips; 216 216 217 217 218 218 private void adjustStripCache() 219 219 { 220 lhsStrips = new Vector<StripPosition>();221 rhsStrips = new Vector<StripPosition>();222 223 double offset = 0;224 225 for (int i = 0; i <= parts.size(); ++i)226 {227 if (isVoidBelow(i))228 {229 if (isPassageAbove(i))230 {231 StripPosition lhs = new StripPosition(i, offset);232 StripPosition rhs = new StripPosition(i, offset);233 234 lhs.connectedToSameSide = false;235 lhs.connectedTo = rhsStrips.size();236 rhs.connectedToSameSide = false;237 rhs.connectedTo = lhsStrips.size();238 239 lhsStrips.add(lhs);240 rhsStrips.add(rhs);241 }242 else if (!isVoidAbove(i))243 connectTwoPos(new StripPosition(i, offset), isReachableLeft(i-1));244 }245 else if (isPassageBelow(i))246 {247 if (isVoidAbove(i))248 {249 StripPosition lhs = new StripPosition(i, offset);250 StripPosition rhs = new StripPosition(i, offset);251 252 lhs.connectedToSameSide = false;253 lhs.connectedTo = rhsStrips.size();254 rhs.connectedToSameSide = false;255 rhs.connectedTo = lhsStrips.size();256 257 lhsStrips.add(lhs);258 rhsStrips.add(rhs);259 }260 else if (!isPassageAbove(i))261 connectTwoPos(new StripPosition(i, offset), !isReachableLeft(i-1));262 }263 else264 {265 if (isVoidAbove(i))266 {267 if (isReachableLeft(i))268 lhsStrips.add(new StripPosition(i, offset));269 else270 rhsStrips.add(new StripPosition(i, offset));271 }272 else if (isPassageAbove(i))273 {274 if (isReachableLeft(i))275 rhsStrips.add(new StripPosition(i, offset));276 else277 lhsStrips.add(new StripPosition(i, offset));278 }279 }280 281 if (i < parts.size())282 offset += parts.elementAt(i).width;283 }284 } 285 286 220 lhsStrips = new Vector<>(); 221 rhsStrips = new Vector<>(); 222 223 double offset = 0; 224 225 for (int i = 0; i <= parts.size(); ++i) 226 { 227 if (isVoidBelow(i)) 228 { 229 if (isPassageAbove(i)) 230 { 231 StripPosition lhs = new StripPosition(i, offset); 232 StripPosition rhs = new StripPosition(i, offset); 233 234 lhs.connectedToSameSide = false; 235 lhs.connectedTo = rhsStrips.size(); 236 rhs.connectedToSameSide = false; 237 rhs.connectedTo = lhsStrips.size(); 238 239 lhsStrips.add(lhs); 240 rhsStrips.add(rhs); 241 } 242 else if (!isVoidAbove(i)) 243 connectTwoPos(new StripPosition(i, offset), isReachableLeft(i-1)); 244 } 245 else if (isPassageBelow(i)) 246 { 247 if (isVoidAbove(i)) 248 { 249 StripPosition lhs = new StripPosition(i, offset); 250 StripPosition rhs = new StripPosition(i, offset); 251 252 lhs.connectedToSameSide = false; 253 lhs.connectedTo = rhsStrips.size(); 254 rhs.connectedToSameSide = false; 255 rhs.connectedTo = lhsStrips.size(); 256 257 lhsStrips.add(lhs); 258 rhsStrips.add(rhs); 259 } 260 else if (!isPassageAbove(i)) 261 connectTwoPos(new StripPosition(i, offset), !isReachableLeft(i-1)); 262 } 263 else 264 { 265 if (isVoidAbove(i)) 266 { 267 if (isReachableLeft(i)) 268 lhsStrips.add(new StripPosition(i, offset)); 269 else 270 rhsStrips.add(new StripPosition(i, offset)); 271 } 272 else if (isPassageAbove(i)) 273 { 274 if (isReachableLeft(i)) 275 rhsStrips.add(new StripPosition(i, offset)); 276 else 277 lhsStrips.add(new StripPosition(i, offset)); 278 } 279 } 280 281 if (i < parts.size()) 282 offset += parts.elementAt(i).width; 283 } 284 } 285 286 287 287 public Vector<Double> leftHandSideStrips() 288 288 { 289 Vector<Double> offsets = new Vector<Double>();290 for (StripPosition pos : lhsStrips)291 offsets.add(pos.offset);292 293 return offsets;294 } 295 296 289 Vector<Double> offsets = new Vector<>(); 290 for (StripPosition pos : lhsStrips) 291 offsets.add(pos.offset); 292 293 return offsets; 294 } 295 296 297 297 public Vector<Double> rightHandSideStrips() 298 298 { 299 Vector<Double> offsets = new Vector<Double>();300 for (StripPosition pos : rhsStrips)301 offsets.add(pos.offset);302 303 return offsets;304 } 305 306 299 Vector<Double> offsets = new Vector<>(); 300 for (StripPosition pos : rhsStrips) 301 offsets.add(pos.offset); 302 303 return offsets; 304 } 305 306 307 307 public int getBeamPartIndex(boolean toTheLeft, int i) 308 308 { 309 if (toTheLeft)310 return lhsStrips.elementAt(i).nodeIndex;311 else312 return rhsStrips.elementAt(i).nodeIndex;313 } 314 309 if (toTheLeft) 310 return lhsStrips.elementAt(i).nodeIndex; 311 else 312 return rhsStrips.elementAt(i).nodeIndex; 313 } 314 315 315 316 316 public boolean appendNodes(IndoorSweeplineModel.SweepPolygonCursor cursor, boolean fromRight, 317 BeamGeography geography, String level)318 { 319 if (fromRight)320 {321 StripPosition pos = rhsStrips.elementAt(cursor.partIndex);322 StripPosition to = pos.connectedToSameSide ?323 rhsStrips.elementAt(pos.connectedTo) : lhsStrips.elementAt(pos.connectedTo);324 325 geography.appendNodes(pos.nodeIndex, to.nodeIndex, level);326 327 if (!pos.connectedToSameSide)328 --cursor.stripIndex;329 cursor.partIndex = pos.connectedTo;330 331 return !pos.connectedToSameSide;332 }333 else334 {335 StripPosition pos = lhsStrips.elementAt(cursor.partIndex);336 StripPosition to = pos.connectedToSameSide ?337 lhsStrips.elementAt(pos.connectedTo) : rhsStrips.elementAt(pos.connectedTo);338 339 geography.appendNodes(pos.nodeIndex, to.nodeIndex, level);340 341 if (!pos.connectedToSameSide)342 ++cursor.stripIndex;343 cursor.partIndex = pos.connectedTo;344 345 return pos.connectedToSameSide;346 }347 } 348 349 317 BeamGeography geography, String level) 318 { 319 if (fromRight) 320 { 321 StripPosition pos = rhsStrips.elementAt(cursor.partIndex); 322 StripPosition to = pos.connectedToSameSide ? 323 rhsStrips.elementAt(pos.connectedTo) : lhsStrips.elementAt(pos.connectedTo); 324 325 geography.appendNodes(pos.nodeIndex, to.nodeIndex, level); 326 327 if (!pos.connectedToSameSide) 328 --cursor.stripIndex; 329 cursor.partIndex = pos.connectedTo; 330 331 return !pos.connectedToSameSide; 332 } 333 else 334 { 335 StripPosition pos = lhsStrips.elementAt(cursor.partIndex); 336 StripPosition to = pos.connectedToSameSide ? 337 lhsStrips.elementAt(pos.connectedTo) : rhsStrips.elementAt(pos.connectedTo); 338 339 geography.appendNodes(pos.nodeIndex, to.nodeIndex, level); 340 341 if (!pos.connectedToSameSide) 342 ++cursor.stripIndex; 343 cursor.partIndex = pos.connectedTo; 344 345 return pos.connectedToSameSide; 346 } 347 } 348 349 350 350 private CorridorPart.ReachableSide defaultSide; 351 351 } -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/BeamGeography.java
r32109 r32479 1 1 package indoor_sweepline; 2 2 3 import java.util.List;4 3 import java.util.Vector; 4 5 5 import org.openstreetmap.josm.data.coor.LatLon; 6 6 import org.openstreetmap.josm.data.osm.DataSet; … … 12 12 public BeamGeography(DataSet dataSet, ModelGeography target) 13 13 { 14 partsGeography = new Vector<CorridorGeography>();15 nodes = new Vector<Node>();16 this.dataSet = dataSet;17 this.target = target;14 partsGeography = new Vector<>(); 15 nodes = new Vector<>(); 16 this.dataSet = dataSet; 17 this.target = target; 18 18 } 19 19 20 20 21 21 public void appendNodes(int from, int to, String level) 22 22 { 23 if (from <= to)24 {25 for (int i = from; i < to; ++i)26 {27 target.appendNode(nodes.elementAt(i));28 CorridorPart part = parts.elementAt(i);29 partsGeography.elementAt(i).appendNodes(part.getType(), part.getSide(), level,30 nodes.elementAt(i).getCoor(), nodes.elementAt(i+1).getCoor(), target);31 }32 target.appendNode(nodes.elementAt(to));33 }34 else35 {36 for (int i = from; i > to; --i)37 {38 target.appendNode(nodes.elementAt(i));39 CorridorPart part = parts.elementAt(i-1);40 partsGeography.elementAt(i-1).appendNodes(part.getType(), part.getSide(), level,41 nodes.elementAt(i).getCoor(), nodes.elementAt(i-1).getCoor(), target);42 }43 target.appendNode(nodes.elementAt(to));44 }23 if (from <= to) 24 { 25 for (int i = from; i < to; ++i) 26 { 27 target.appendNode(nodes.elementAt(i)); 28 CorridorPart part = parts.elementAt(i); 29 partsGeography.elementAt(i).appendNodes(part.getType(), part.getSide(), level, 30 nodes.elementAt(i).getCoor(), nodes.elementAt(i+1).getCoor(), target); 31 } 32 target.appendNode(nodes.elementAt(to)); 33 } 34 else 35 { 36 for (int i = from; i > to; --i) 37 { 38 target.appendNode(nodes.elementAt(i)); 39 CorridorPart part = parts.elementAt(i-1); 40 partsGeography.elementAt(i-1).appendNodes(part.getType(), part.getSide(), level, 41 nodes.elementAt(i).getCoor(), nodes.elementAt(i-1).getCoor(), target); 42 } 43 target.appendNode(nodes.elementAt(to)); 44 } 45 45 } 46 46 47 47 48 48 public void adjustNodes(LatLon pivot, Vector<CorridorPart> parts, double beamOffset) 49 49 { 50 double offset = -beamOffset;51 this.parts = parts;52 53 adjustNode(0, new LatLon(addMetersToLat(pivot, offset), pivot.lon()));54 55 for (int i = 0; i < parts.size(); ++i)56 {57 adjustPartGeography(i);58 offset += parts.elementAt(i).width;59 adjustNode(i+1, new LatLon(addMetersToLat(pivot, offset), pivot.lon()));60 }61 62 // Size reduction not implemented50 double offset = -beamOffset; 51 this.parts = parts; 52 53 adjustNode(0, new LatLon(addMetersToLat(pivot, offset), pivot.lon())); 54 55 for (int i = 0; i < parts.size(); ++i) 56 { 57 adjustPartGeography(i); 58 offset += parts.elementAt(i).width; 59 adjustNode(i+1, new LatLon(addMetersToLat(pivot, offset), pivot.lon())); 60 } 61 62 // Size reduction not implemented 63 63 } 64 65 64 65 66 66 private void adjustNode(int i, LatLon coor) 67 67 { 68 if (nodes.size() <= i)69 nodes.setSize(i+1);70 Node node = nodes.elementAt(i);71 if (node == null)72 {73 node = new Node(coor);74 dataSet.addPrimitive(node);75 nodes.setElementAt(node, i);76 }77 else78 node.setCoor(coor);68 if (nodes.size() <= i) 69 nodes.setSize(i+1); 70 Node node = nodes.elementAt(i); 71 if (node == null) 72 { 73 node = new Node(coor); 74 dataSet.addPrimitive(node); 75 nodes.setElementAt(node, i); 76 } 77 else 78 node.setCoor(coor); 79 79 } 80 81 80 81 82 82 private void adjustPartGeography(int i) 83 83 { 84 if (partsGeography.size() <= i)85 partsGeography.setSize(i+1);86 CorridorGeography partGeography = partsGeography.elementAt(i);87 if (partGeography == null)88 {89 partGeography = new CorridorGeography(dataSet);90 partsGeography.setElementAt(partGeography, i);91 }84 if (partsGeography.size() <= i) 85 partsGeography.setSize(i+1); 86 CorridorGeography partGeography = partsGeography.elementAt(i); 87 if (partGeography == null) 88 { 89 partGeography = new CorridorGeography(dataSet); 90 partsGeography.setElementAt(partGeography, i); 91 } 92 92 } 93 94 93 94 95 95 public LatLon coorAt(int i) 96 96 { 97 return nodes.elementAt(i).getCoor();97 return nodes.elementAt(i).getCoor(); 98 98 } 99 100 99 100 101 101 private Vector<CorridorPart> parts; 102 102 private Vector<CorridorGeography> partsGeography; … … 105 105 private Vector<Node> nodes; 106 106 107 107 108 108 private static double addMetersToLat(LatLon latLon, double south) 109 109 { 110 return latLon.lat() - south *(360./4e7);110 return latLon.lat() - south *(360./4e7); 111 111 } 112 112 } -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/CorridorGeography.java
r32107 r32479 1 1 package indoor_sweepline; 2 2 3 import java.util.List;4 3 import java.util.Vector; 4 5 5 import org.openstreetmap.josm.data.coor.LatLon; 6 6 import org.openstreetmap.josm.data.osm.DataSet; … … 13 13 public CorridorGeography(DataSet dataSet) 14 14 { 15 this.dataSet = dataSet;15 this.dataSet = dataSet; 16 16 } 17 18 17 18 19 19 private static final double MIN_LENGTH = 10.; 20 21 20 21 22 22 private void setExtraElements(CorridorPart.ReachableSide side, LatLon from, LatLon to, 23 boolean extraWayUp, double minLength)23 boolean extraWayUp, double minLength) 24 24 { 25 LatLon middleCoor = new LatLon((from.lat() + to.lat())/2.,26 (from.lon() + to.lon())/2.);27 if (middleNode == null)28 {29 middleNode = new Node(middleCoor);30 dataSet.addPrimitive(middleNode);31 }32 else33 middleNode.setCoor(middleCoor);34 35 LatLon start = from;36 if (side == CorridorPart.ReachableSide.LEFT)37 {38 if (middleCoor.lat() < start.lat())39 start = to;40 }41 else if (side == CorridorPart.ReachableSide.RIGHT)42 {43 if (start.lat() < middleCoor.lat())44 start = to;45 }46 else if (side == CorridorPart.ReachableSide.FRONT)47 {48 if (start.lon() < middleCoor.lon())49 start = to;50 }51 else if (side == CorridorPart.ReachableSide.BACK)52 {53 if (middleCoor.lon() < start.lon())54 start = to;55 }56 57 double scale = Math.cos(middleCoor.lat() * (Math.PI/180.));58 double length = Math.sqrt((start.lat() - middleCoor.lat()) * (start.lat() - middleCoor.lat()) +59 (start.lon() - middleCoor.lon()) * (start.lon() - middleCoor.lon()) * scale * scale) / 180. * 20000000.;60 double lengthFactor = length < minLength ? minLength / length : 1.;61 LatLon detachedCoor = new LatLon(middleCoor.lat() + (start.lon() - middleCoor.lon()) * scale * lengthFactor,62 middleCoor.lon() - (start.lat() - middleCoor.lat()) / scale * lengthFactor);63 if (detachedNode == null)64 {65 detachedNode = new Node(detachedCoor);66 dataSet.addPrimitive(detachedNode);67 }68 else69 detachedNode.setCoor(detachedCoor);70 71 Vector<Node> extraWayNodes = new Vector<Node>();72 if (extraWayUp)73 {74 extraWayNodes.add(middleNode);75 extraWayNodes.add(detachedNode);76 }77 else78 {79 extraWayNodes.add(detachedNode);80 extraWayNodes.add(middleNode);81 }82 if (extraWay == null)83 {84 extraWay = new Way();85 extraWay.setNodes(extraWayNodes);86 dataSet.addPrimitive(extraWay);87 }88 else89 extraWay.setNodes(extraWayNodes);25 LatLon middleCoor = new LatLon((from.lat() + to.lat())/2., 26 (from.lon() + to.lon())/2.); 27 if (middleNode == null) 28 { 29 middleNode = new Node(middleCoor); 30 dataSet.addPrimitive(middleNode); 31 } 32 else 33 middleNode.setCoor(middleCoor); 34 35 LatLon start = from; 36 if (side == CorridorPart.ReachableSide.LEFT) 37 { 38 if (middleCoor.lat() < start.lat()) 39 start = to; 40 } 41 else if (side == CorridorPart.ReachableSide.RIGHT) 42 { 43 if (start.lat() < middleCoor.lat()) 44 start = to; 45 } 46 else if (side == CorridorPart.ReachableSide.FRONT) 47 { 48 if (start.lon() < middleCoor.lon()) 49 start = to; 50 } 51 else if (side == CorridorPart.ReachableSide.BACK) 52 { 53 if (middleCoor.lon() < start.lon()) 54 start = to; 55 } 56 57 double scale = Math.cos(middleCoor.lat() * (Math.PI/180.)); 58 double length = Math.sqrt((start.lat() - middleCoor.lat()) * (start.lat() - middleCoor.lat()) + 59 (start.lon() - middleCoor.lon()) * (start.lon() - middleCoor.lon()) * scale * scale) / 180. * 20000000.; 60 double lengthFactor = length < minLength ? minLength / length : 1.; 61 LatLon detachedCoor = new LatLon(middleCoor.lat() + (start.lon() - middleCoor.lon()) * scale * lengthFactor, 62 middleCoor.lon() - (start.lat() - middleCoor.lat()) / scale * lengthFactor); 63 if (detachedNode == null) 64 { 65 detachedNode = new Node(detachedCoor); 66 dataSet.addPrimitive(detachedNode); 67 } 68 else 69 detachedNode.setCoor(detachedCoor); 70 71 Vector<Node> extraWayNodes = new Vector<>(); 72 if (extraWayUp) 73 { 74 extraWayNodes.add(middleNode); 75 extraWayNodes.add(detachedNode); 76 } 77 else 78 { 79 extraWayNodes.add(detachedNode); 80 extraWayNodes.add(middleNode); 81 } 82 if (extraWay == null) 83 { 84 extraWay = new Way(); 85 extraWay.setNodes(extraWayNodes); 86 dataSet.addPrimitive(extraWay); 87 } 88 else 89 extraWay.setNodes(extraWayNodes); 90 90 } 91 92 91 92 93 93 public void appendNodes(CorridorPart.Type type, CorridorPart.ReachableSide side, String level, 94 LatLon from, LatLon to, ModelGeography target)94 LatLon from, LatLon to, ModelGeography target) 95 95 { 96 if (type == CorridorPart.Type.STAIRS_UP || type == CorridorPart.Type.STAIRS_DOWN)97 {98 setExtraElements(side, from, to, type == CorridorPart.Type.STAIRS_UP, MIN_LENGTH);99 target.appendNode(middleNode);96 if (type == CorridorPart.Type.STAIRS_UP || type == CorridorPart.Type.STAIRS_DOWN) 97 { 98 setExtraElements(side, from, to, type == CorridorPart.Type.STAIRS_UP, MIN_LENGTH); 99 target.appendNode(middleNode); 100 100 101 detachedNode.removeAll();101 detachedNode.removeAll(); 102 102 103 extraWay.removeAll();104 extraWay.put("highway", "steps");105 extraWay.put("incline", "up");106 extraWay.put("level", level);107 }108 else if (type == CorridorPart.Type.ESCALATOR_UP_LEAVING109 || type == CorridorPart.Type.ESCALATOR_UP_ARRIVING110 || type == CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL111 || type == CorridorPart.Type.ESCALATOR_DOWN_LEAVING112 || type == CorridorPart.Type.ESCALATOR_DOWN_ARRIVING113 || type == CorridorPart.Type.ESCALATOR_DOWN_BIDIRECTIONAL)114 {115 setExtraElements(side, from, to,116 type == CorridorPart.Type.ESCALATOR_UP_LEAVING117 || type == CorridorPart.Type.ESCALATOR_UP_ARRIVING118 || type == CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL, MIN_LENGTH);119 target.appendNode(middleNode);103 extraWay.removeAll(); 104 extraWay.put("highway", "steps"); 105 extraWay.put("incline", "up"); 106 extraWay.put("level", level); 107 } 108 else if (type == CorridorPart.Type.ESCALATOR_UP_LEAVING 109 || type == CorridorPart.Type.ESCALATOR_UP_ARRIVING 110 || type == CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL 111 || type == CorridorPart.Type.ESCALATOR_DOWN_LEAVING 112 || type == CorridorPart.Type.ESCALATOR_DOWN_ARRIVING 113 || type == CorridorPart.Type.ESCALATOR_DOWN_BIDIRECTIONAL) 114 { 115 setExtraElements(side, from, to, 116 type == CorridorPart.Type.ESCALATOR_UP_LEAVING 117 || type == CorridorPart.Type.ESCALATOR_UP_ARRIVING 118 || type == CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL, MIN_LENGTH); 119 target.appendNode(middleNode); 120 120 121 detachedNode.removeAll();121 detachedNode.removeAll(); 122 122 123 extraWay.removeAll();124 extraWay.put("highway", "steps");125 extraWay.put("incline", "up");126 if (type == CorridorPart.Type.ESCALATOR_UP_LEAVING127 || type == CorridorPart.Type.ESCALATOR_DOWN_ARRIVING)128 extraWay.put("conveying", "forward");129 else if (type == CorridorPart.Type.ESCALATOR_UP_ARRIVING130 || type == CorridorPart.Type.ESCALATOR_DOWN_LEAVING)131 extraWay.put("conveying", "backward");132 else133 extraWay.put("conveying", "reversible");134 extraWay.put("level", level);135 }136 else if (type == CorridorPart.Type.ELEVATOR)137 {138 setExtraElements(side, from, to, true, 0.);139 target.appendNode(middleNode);123 extraWay.removeAll(); 124 extraWay.put("highway", "steps"); 125 extraWay.put("incline", "up"); 126 if (type == CorridorPart.Type.ESCALATOR_UP_LEAVING 127 || type == CorridorPart.Type.ESCALATOR_DOWN_ARRIVING) 128 extraWay.put("conveying", "forward"); 129 else if (type == CorridorPart.Type.ESCALATOR_UP_ARRIVING 130 || type == CorridorPart.Type.ESCALATOR_DOWN_LEAVING) 131 extraWay.put("conveying", "backward"); 132 else 133 extraWay.put("conveying", "reversible"); 134 extraWay.put("level", level); 135 } 136 else if (type == CorridorPart.Type.ELEVATOR) 137 { 138 setExtraElements(side, from, to, true, 0.); 139 target.appendNode(middleNode); 140 140 141 detachedNode.removeAll();142 detachedNode.put("highway", "elevator");143 144 extraWay.removeAll();145 extraWay.put("highway", "footway");146 extraWay.put("level", level);147 }148 else149 {150 if (extraWay != null)151 {152 extraWay.setDeleted(true);153 extraWay = null;154 }155 if (middleNode != null)156 {157 middleNode.setDeleted(true);158 middleNode = null;159 }160 if (detachedNode != null)161 {162 detachedNode.setDeleted(true);163 detachedNode = null;164 }165 }141 detachedNode.removeAll(); 142 detachedNode.put("highway", "elevator"); 143 144 extraWay.removeAll(); 145 extraWay.put("highway", "footway"); 146 extraWay.put("level", level); 147 } 148 else 149 { 150 if (extraWay != null) 151 { 152 extraWay.setDeleted(true); 153 extraWay = null; 154 } 155 if (middleNode != null) 156 { 157 middleNode.setDeleted(true); 158 middleNode = null; 159 } 160 if (detachedNode != null) 161 { 162 detachedNode.setDeleted(true); 163 detachedNode = null; 164 } 165 } 166 166 } 167 168 167 168 169 169 private DataSet dataSet; 170 170 private Node middleNode; -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/CorridorPart.java
r32103 r32479 1 1 package indoor_sweepline; 2 3 import java.util.List;4 import java.util.Vector;5 6 2 7 3 public class CorridorPart -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/IndoorSweepline.java
r32107 r32479 3 3 import javax.swing.JMenu; 4 4 import javax.swing.JMenuItem; 5 5 6 import org.openstreetmap.josm.Main; 6 import org.openstreetmap.josm.gui.MainMenu;7 7 import org.openstreetmap.josm.plugins.Plugin; 8 8 import org.openstreetmap.josm.plugins.PluginInformation; -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/IndoorSweeplineController.java
r32109 r32479 2 2 3 3 import java.util.List; 4 4 5 import javax.swing.DefaultComboBoxModel; 6 7 import org.openstreetmap.josm.Main; 5 8 import org.openstreetmap.josm.data.coor.LatLon; 6 import org.openstreetmap.josm.gui.layer.Layer; 9 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 10 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 11 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 12 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 7 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 8 import org.openstreetmap.josm.gui.MapView;9 14 10 15 11 public class IndoorSweeplineController implements MapView.LayerChangeListener16 public class IndoorSweeplineController implements LayerChangeListener 12 17 { 13 18 public IndoorSweeplineController(OsmDataLayer activeLayer, LatLon center) 14 19 { 15 MapView.addLayerChangeListener(this);16 layer = activeLayer;17 model = new IndoorSweeplineModel(activeLayer, center);18 dialog = new IndoorSweeplineWizardDialog(this);19 dialog.setVisible(true);20 Main.getLayerManager().addLayerChangeListener(this); 21 layer = activeLayer; 22 model = new IndoorSweeplineModel(activeLayer, center); 23 dialog = new IndoorSweeplineWizardDialog(this); 24 dialog.setVisible(true); 20 25 } 21 26 … … 23 28 public IndoorSweeplineWizardDialog view() 24 29 { 25 return dialog;30 return dialog; 26 31 } 27 32 28 29 33 @Override 30 public void activeLayerChange(Layer oldLayer, Layer newLayer)34 public void layerOrderChanged(LayerOrderChangeEvent e) 31 35 { 32 36 } 33 37 34 38 @Override 35 public void layerAdded(Layer newLayer)39 public void layerAdded(LayerAddEvent e) 36 40 { 37 41 } 38 42 39 43 @Override 40 public void layerRemov ed(Layer oldLayer)44 public void layerRemoving(LayerRemoveEvent e) 41 45 { 42 if (oldLayer== layer)43 dialog.setVisible(false);46 if (e.getRemovedLayer() == layer) 47 dialog.setVisible(false); 44 48 } 45 46 49 47 50 public int leftRightCount() 48 51 { 49 return model.leftRightCount();52 return model.leftRightCount(); 50 53 } 51 54 52 55 public void addRightStructure() 53 56 { 54 if (model.leftRightCount() % 2 == 0)55 model.addBeam();56 else57 model.addStrip();57 if (model.leftRightCount() % 2 == 0) 58 model.addBeam(); 59 else 60 model.addStrip(); 58 61 } 59 62 60 63 public DefaultComboBoxModel<String> structures() 61 64 { 62 return model.structures();65 return model.structures(); 63 66 } 64 67 65 68 public double getStripWidth(int index) 66 69 { 67 return model.getStripWidth(index);70 return model.getStripWidth(index); 68 71 } 69 72 70 73 public void setStripWidth(int index, double value) 71 74 { 72 model.setStripWidth(index, value);75 model.setStripWidth(index, value); 73 76 } 74 77 75 78 public double getBeamOffset(int index) 76 79 { 77 return model.getBeamOffset(index);80 return model.getBeamOffset(index); 78 81 } 79 82 80 83 public void setBeamOffset(int index, double beamOffset) 81 84 { 82 model.setBeamOffset(index, beamOffset);85 model.setBeamOffset(index, beamOffset); 83 86 } 84 87 85 88 public List<CorridorPart> getBeamParts(int index) 86 89 { 87 return model.getBeamParts(index);90 return model.getBeamParts(index); 88 91 } 89 92 90 93 public void addCorridorPart(int beamIndex, boolean append, double value) 91 94 { 92 model.addCorridorPart(beamIndex, append, value);95 model.addCorridorPart(beamIndex, append, value); 93 96 } 94 97 95 98 public void setCorridorPartWidth(int beamIndex, int partIndex, double value) 96 99 { 97 model.setCorridorPartWidth(beamIndex, partIndex, value);100 model.setCorridorPartWidth(beamIndex, partIndex, value); 98 101 } 99 102 100 103 public void setCorridorPartType(int beamIndex, int partIndex, CorridorPart.Type type) 101 104 { 102 model.setCorridorPartType(beamIndex, partIndex, type);105 model.setCorridorPartType(beamIndex, partIndex, type); 103 106 } 104 107 105 108 public void setCorridorPartSide(int beamIndex, int partIndex, CorridorPart.ReachableSide side) 106 109 { 107 model.setCorridorPartSide(beamIndex, partIndex, side);110 model.setCorridorPartSide(beamIndex, partIndex, side); 108 111 } 109 112 110 113 public Strip getStrip(int beamIndex) 111 114 { 112 return model.getStrip(beamIndex);115 return model.getStrip(beamIndex); 113 116 } 114 117 115 118 public IndoorSweeplineModel.Type getType() 116 119 { 117 return model.getType();120 return model.getType(); 118 121 } 119 122 120 123 public void setType(IndoorSweeplineModel.Type type) 121 124 { 122 model.setType(type);125 model.setType(type); 123 126 } 124 127 125 128 public String getLevel() 126 129 { 127 return model.getLevel();130 return model.getLevel(); 128 131 } 129 132 130 133 public void setLevel(String level) 131 134 { 132 model.setLevel(level);135 model.setLevel(level); 133 136 } 134 137 135 138 private OsmDataLayer layer; 136 139 private IndoorSweeplineModel model; -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/IndoorSweeplineModel.java
r32109 r32479 3 3 import java.util.List; 4 4 import java.util.Vector; 5 5 6 import javax.swing.DefaultComboBoxModel; 7 6 8 import org.openstreetmap.josm.Main; 7 9 import org.openstreetmap.josm.data.coor.LatLon; 8 import org.openstreetmap.josm.data.osm.DataSet;9 10 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 10 11 … … 13 14 - focus to useful table entry after cell edit 14 15 - keyboard shortcuts 15 */ 16 */ 16 17 17 18 … … 20 21 public enum Type 21 22 { 22 CORRIDOR,23 PLATFORM23 CORRIDOR, 24 PLATFORM 24 25 }; 25 26 … … 27 28 public IndoorSweeplineModel(OsmDataLayer activeLayer, LatLon center) 28 29 { 29 target = new ModelGeography(activeLayer.data, center);30 31 beams = new Vector<Beam>();32 strips = new Vector<Strip>();33 type = Type.CORRIDOR;34 level = "-1";35 addBeam();36 addStrip();37 addBeam();38 39 structureBox = new DefaultComboBoxModel<String>();40 } 41 42 30 target = new ModelGeography(activeLayer.data, center); 31 32 beams = new Vector<>(); 33 strips = new Vector<>(); 34 type = Type.CORRIDOR; 35 level = "-1"; 36 addBeam(); 37 addStrip(); 38 addBeam(); 39 40 structureBox = new DefaultComboBoxModel<>(); 41 } 42 43 43 44 private ModelGeography target; 44 45 45 46 46 47 public void addBeam() 47 48 { 48 CorridorPart.ReachableSide side = CorridorPart.ReachableSide.LEFT;49 if (beams.size() == 0)50 side = CorridorPart.ReachableSide.RIGHT;51 52 double width = 10.;49 CorridorPart.ReachableSide side = CorridorPart.ReachableSide.LEFT; 50 if (beams.size() == 0) 51 side = CorridorPart.ReachableSide.RIGHT; 52 53 /*double width = 10.; 53 54 if (beams.size() > 0) 54 55 { … … 57 58 width += part.width; 58 59 } 59 60 60 61 double offset = 0; 61 62 for (int i = 0; i < strips.size(); ++i) 62 offset += strips.elementAt(i).width; 63 64 if (strips.size() == 0)65 {66 Vector<Double> blueprint = new Vector<Double>();67 blueprint.addElement(0.);68 blueprint.addElement(10.);69 beams.add(new Beam(blueprint, 0., side));70 }71 else72 beams.add(new Beam(strips.elementAt(strips.size()-1).lhs,73 beams.elementAt(beams.size()-1).getBeamOffset(), side));74 75 if (strips.size() > 0)76 strips.elementAt(beams.size()-2).rhs = beams.elementAt(beams.size()-1).leftHandSideStrips();77 78 updateOsmModel();79 } 80 81 63 offset += strips.elementAt(i).width;*/ 64 65 if (strips.size() == 0) 66 { 67 Vector<Double> blueprint = new Vector<>(); 68 blueprint.addElement(0.); 69 blueprint.addElement(10.); 70 beams.add(new Beam(blueprint, 0., side)); 71 } 72 else 73 beams.add(new Beam(strips.elementAt(strips.size()-1).lhs, 74 beams.elementAt(beams.size()-1).getBeamOffset(), side)); 75 76 if (strips.size() > 0) 77 strips.elementAt(beams.size()-2).rhs = beams.elementAt(beams.size()-1).leftHandSideStrips(); 78 79 updateOsmModel(); 80 } 81 82 82 83 public void addStrip() 83 84 { 84 strips.add(new Strip(target.getDataSet()));85 if (beams.size() > 1)86 {87 beams.elementAt(beams.size()-1).setDefaultSide(CorridorPart.ReachableSide.ALL);88 strips.elementAt(strips.size()-2).rhs = beams.elementAt(strips.size()-1).leftHandSideStrips();89 }90 strips.elementAt(strips.size()-1).lhs = beams.elementAt(strips.size()-1).rightHandSideStrips();91 92 updateOsmModel();93 } 94 95 85 strips.add(new Strip(target.getDataSet())); 86 if (beams.size() > 1) 87 { 88 beams.elementAt(beams.size()-1).setDefaultSide(CorridorPart.ReachableSide.ALL); 89 strips.elementAt(strips.size()-2).rhs = beams.elementAt(strips.size()-1).leftHandSideStrips(); 90 } 91 strips.elementAt(strips.size()-1).lhs = beams.elementAt(strips.size()-1).rightHandSideStrips(); 92 93 updateOsmModel(); 94 } 95 96 96 97 public int leftRightCount() 97 98 { 98 return beams.size() + strips.size();99 } 100 101 99 return beams.size() + strips.size(); 100 } 101 102 102 103 public DefaultComboBoxModel<String> structures() 103 104 { 104 structureBox.removeAllElements();105 double offset = 0;106 for (int i = 0; i < strips.size(); ++i)107 {108 if (i < beams.size())109 structureBox.addElement(Double.toString(offset));110 structureBox.addElement(Double.toString(offset) + " - "111 + Double.toString(offset + strips.elementAt(i).width));112 offset += strips.elementAt(i).width;113 }114 if (strips.size() < beams.size())115 structureBox.addElement(Double.toString(offset));116 117 return structureBox;118 } 119 120 105 structureBox.removeAllElements(); 106 double offset = 0; 107 for (int i = 0; i < strips.size(); ++i) 108 { 109 if (i < beams.size()) 110 structureBox.addElement(Double.toString(offset)); 111 structureBox.addElement(Double.toString(offset) + " - " 112 + Double.toString(offset + strips.elementAt(i).width)); 113 offset += strips.elementAt(i).width; 114 } 115 if (strips.size() < beams.size()) 116 structureBox.addElement(Double.toString(offset)); 117 118 return structureBox; 119 } 120 121 121 122 public Strip getStrip(int index) 122 123 { 123 return strips.elementAt(index / 2);124 } 125 126 124 return strips.elementAt(index / 2); 125 } 126 127 127 128 public double getStripWidth(int index) 128 129 { 129 return strips.elementAt(index / 2).width;130 } 131 132 130 return strips.elementAt(index / 2).width; 131 } 132 133 133 134 public void setStripWidth(int index, double value) 134 135 { 135 strips.elementAt(index / 2).width = value;136 137 updateOsmModel();138 } 139 140 136 strips.elementAt(index / 2).width = value; 137 138 updateOsmModel(); 139 } 140 141 141 142 public double getBeamOffset(int index) 142 143 { 143 return beams.elementAt(index / 2).getBeamOffset();144 } 145 144 return beams.elementAt(index / 2).getBeamOffset(); 145 } 146 146 147 public void setBeamOffset(int index, double beamOffset) 147 148 { 148 beams.elementAt(index / 2).setBeamOffset(beamOffset);149 updateOsmModel();150 } 151 152 149 beams.elementAt(index / 2).setBeamOffset(beamOffset); 150 updateOsmModel(); 151 } 152 153 153 154 public List<CorridorPart> getBeamParts(int index) 154 155 { 155 return beams.elementAt(index / 2).getBeamParts();156 } 157 158 156 return beams.elementAt(index / 2).getBeamParts(); 157 } 158 159 159 160 public void addCorridorPart(int beamIndex, boolean append, double value) 160 161 { 161 beams.elementAt(beamIndex / 2).addCorridorPart(append, value);162 if (beamIndex / 2 > 0)163 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips();164 if (beamIndex / 2 < strips.size())165 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips();166 167 updateOsmModel();168 } 169 170 162 beams.elementAt(beamIndex / 2).addCorridorPart(append, value); 163 if (beamIndex / 2 > 0) 164 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips(); 165 if (beamIndex / 2 < strips.size()) 166 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips(); 167 168 updateOsmModel(); 169 } 170 171 171 172 public void setCorridorPartWidth(int beamIndex, int partIndex, double value) 172 173 { 173 beams.elementAt(beamIndex / 2).setCorridorPartWidth(partIndex, value);174 if (beamIndex / 2 > 0)175 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips();176 if (beamIndex / 2 < strips.size())177 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips();178 179 updateOsmModel();180 } 181 182 174 beams.elementAt(beamIndex / 2).setCorridorPartWidth(partIndex, value); 175 if (beamIndex / 2 > 0) 176 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips(); 177 if (beamIndex / 2 < strips.size()) 178 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips(); 179 180 updateOsmModel(); 181 } 182 183 183 184 public void setCorridorPartType(int beamIndex, int partIndex, CorridorPart.Type type) 184 185 { 185 if (beamIndex % 2 == 0)186 {187 beams.elementAt(beamIndex / 2).setCorridorPartType(partIndex, type);188 if (beamIndex / 2 > 0)189 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips();190 if (beamIndex / 2 < strips.size())191 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips();192 }193 else194 {195 if (type != CorridorPart.Type.PASSAGE && type != CorridorPart.Type.VOID)196 strips.elementAt(beamIndex / 2).setCorridorPartType(partIndex, type);197 }198 199 updateOsmModel();200 } 201 202 186 if (beamIndex % 2 == 0) 187 { 188 beams.elementAt(beamIndex / 2).setCorridorPartType(partIndex, type); 189 if (beamIndex / 2 > 0) 190 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips(); 191 if (beamIndex / 2 < strips.size()) 192 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips(); 193 } 194 else 195 { 196 if (type != CorridorPart.Type.PASSAGE && type != CorridorPart.Type.VOID) 197 strips.elementAt(beamIndex / 2).setCorridorPartType(partIndex, type); 198 } 199 200 updateOsmModel(); 201 } 202 203 203 204 public void setCorridorPartSide(int beamIndex, int partIndex, CorridorPart.ReachableSide side) 204 205 { 205 beams.elementAt(beamIndex / 2).setCorridorPartSide(partIndex, side);206 if (beamIndex / 2 > 0)207 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips();208 if (beamIndex / 2 < strips.size())209 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips();210 211 updateOsmModel();212 } 213 214 206 beams.elementAt(beamIndex / 2).setCorridorPartSide(partIndex, side); 207 if (beamIndex / 2 > 0) 208 strips.elementAt(beamIndex / 2 - 1).rhs = beams.elementAt(beamIndex / 2).leftHandSideStrips(); 209 if (beamIndex / 2 < strips.size()) 210 strips.elementAt(beamIndex / 2).lhs = beams.elementAt(beamIndex / 2).rightHandSideStrips(); 211 212 updateOsmModel(); 213 } 214 215 215 216 public Type getType() 216 217 { 217 return type;218 } 219 218 return type; 219 } 220 220 221 public void setType(Type type) 221 222 { 222 this.type = type;223 updateOsmModel();224 } 225 226 223 this.type = type; 224 updateOsmModel(); 225 } 226 227 227 228 public String getLevel() 228 229 { 229 return level;230 } 231 230 return level; 231 } 232 232 233 public void setLevel(String level) 233 234 { 234 this.level = level;235 updateOsmModel();236 } 237 238 235 this.level = level; 236 updateOsmModel(); 237 } 238 239 239 240 private Vector<Beam> beams; 240 241 private Vector<Strip> strips; 241 242 private Type type; 242 243 private String level; 243 244 244 245 DefaultComboBoxModel<String> structureBox; 245 246 246 247 247 248 private void updateOsmModel() 248 249 { 249 distributeWays();250 Main.map.mapView.repaint();251 } 252 253 250 distributeWays(); 251 Main.map.mapView.repaint(); 252 } 253 254 254 255 public class SweepPolygonCursor 255 256 { 256 public SweepPolygonCursor(int stripIndex, int partIndex)257 {258 this.stripIndex = stripIndex;259 this.partIndex = partIndex;260 }261 262 public boolean equals(SweepPolygonCursor rhs)263 {264 return rhs != null265 && stripIndex == rhs.stripIndex && partIndex == rhs.partIndex;266 }267 268 public int stripIndex;269 public int partIndex;270 } 271 272 257 public SweepPolygonCursor(int stripIndex, int partIndex) 258 { 259 this.stripIndex = stripIndex; 260 this.partIndex = partIndex; 261 } 262 263 public boolean equals(SweepPolygonCursor rhs) 264 { 265 return rhs != null 266 && stripIndex == rhs.stripIndex && partIndex == rhs.partIndex; 267 } 268 269 public int stripIndex; 270 public int partIndex; 271 } 272 273 273 274 private void distributeWays() 274 275 { 275 target.startGeographyBuild(beams, strips);276 277 Vector<Vector<Boolean>> stripRefs = new Vector<Vector<Boolean>>();278 for (Strip strip : strips)279 {280 Vector<Boolean> refs = new Vector<Boolean>();281 if (strip.lhs.size() < strip.rhs.size())282 refs.setSize(strip.rhs.size());283 else284 refs.setSize(strip.lhs.size());285 stripRefs.add(refs);286 }287 288 Boolean truePtr = new Boolean(true);289 for (int i = 0; i < stripRefs.size(); ++i)290 {291 Vector<Boolean> refs = stripRefs.elementAt(i);292 for (int j = 0; j < refs.size(); ++j)293 {294 if (refs.elementAt(j) == null)295 {296 target.startWay();297 298 SweepPolygonCursor cursor = new SweepPolygonCursor(i, j);299 300 boolean toTheLeft = true;301 while (stripRefs.elementAt(cursor.stripIndex).elementAt(cursor.partIndex) == null)302 {303 stripRefs.elementAt(cursor.stripIndex).setElementAt(truePtr, cursor.partIndex);304 if (toTheLeft && cursor.partIndex < strips.elementAt(cursor.stripIndex).lhs.size())305 {306 target.appendCorridorPart(307 strips.elementAt(cursor.stripIndex).partAt(cursor.partIndex),308 strips.elementAt(cursor.stripIndex).geographyAt(cursor.partIndex),309 cursor.stripIndex,310 beams.elementAt(cursor.stripIndex).getBeamPartIndex(!toTheLeft, cursor.partIndex),311 level);312 toTheLeft = beams.elementAt(cursor.stripIndex).appendNodes(313 cursor, toTheLeft, target.beamAt(cursor.stripIndex), level);314 }315 else if (!toTheLeft && cursor.partIndex < strips.elementAt(cursor.stripIndex).rhs.size())316 {317 target.appendCorridorPart(318 strips.elementAt(cursor.stripIndex).partAt(cursor.partIndex),319 strips.elementAt(cursor.stripIndex).geographyAt(cursor.partIndex),320 cursor.stripIndex + 1,321 beams.elementAt(cursor.stripIndex + 1).getBeamPartIndex(!toTheLeft, cursor.partIndex),322 level);323 toTheLeft = beams.elementAt(cursor.stripIndex + 1).appendNodes(324 cursor, toTheLeft, target.beamAt(cursor.stripIndex + 1), level);325 }326 else327 toTheLeft = appendUturn(cursor, toTheLeft);328 }329 330 target.finishWay(strips.elementAt(cursor.stripIndex), cursor.partIndex, j % 2 == 0, level);331 }332 }333 }334 335 target.finishGeographyBuild(type, level);336 } 337 338 276 target.startGeographyBuild(beams, strips); 277 278 Vector<Vector<Boolean>> stripRefs = new Vector<>(); 279 for (Strip strip : strips) 280 { 281 Vector<Boolean> refs = new Vector<>(); 282 if (strip.lhs.size() < strip.rhs.size()) 283 refs.setSize(strip.rhs.size()); 284 else 285 refs.setSize(strip.lhs.size()); 286 stripRefs.add(refs); 287 } 288 289 Boolean truePtr = new Boolean(true); 290 for (int i = 0; i < stripRefs.size(); ++i) 291 { 292 Vector<Boolean> refs = stripRefs.elementAt(i); 293 for (int j = 0; j < refs.size(); ++j) 294 { 295 if (refs.elementAt(j) == null) 296 { 297 target.startWay(); 298 299 SweepPolygonCursor cursor = new SweepPolygonCursor(i, j); 300 301 boolean toTheLeft = true; 302 while (stripRefs.elementAt(cursor.stripIndex).elementAt(cursor.partIndex) == null) 303 { 304 stripRefs.elementAt(cursor.stripIndex).setElementAt(truePtr, cursor.partIndex); 305 if (toTheLeft && cursor.partIndex < strips.elementAt(cursor.stripIndex).lhs.size()) 306 { 307 target.appendCorridorPart( 308 strips.elementAt(cursor.stripIndex).partAt(cursor.partIndex), 309 strips.elementAt(cursor.stripIndex).geographyAt(cursor.partIndex), 310 cursor.stripIndex, 311 beams.elementAt(cursor.stripIndex).getBeamPartIndex(!toTheLeft, cursor.partIndex), 312 level); 313 toTheLeft = beams.elementAt(cursor.stripIndex).appendNodes( 314 cursor, toTheLeft, target.beamAt(cursor.stripIndex), level); 315 } 316 else if (!toTheLeft && cursor.partIndex < strips.elementAt(cursor.stripIndex).rhs.size()) 317 { 318 target.appendCorridorPart( 319 strips.elementAt(cursor.stripIndex).partAt(cursor.partIndex), 320 strips.elementAt(cursor.stripIndex).geographyAt(cursor.partIndex), 321 cursor.stripIndex + 1, 322 beams.elementAt(cursor.stripIndex + 1).getBeamPartIndex(!toTheLeft, cursor.partIndex), 323 level); 324 toTheLeft = beams.elementAt(cursor.stripIndex + 1).appendNodes( 325 cursor, toTheLeft, target.beamAt(cursor.stripIndex + 1), level); 326 } 327 else 328 toTheLeft = appendUturn(cursor, toTheLeft); 329 } 330 331 target.finishWay(strips.elementAt(cursor.stripIndex), cursor.partIndex, j % 2 == 0, level); 332 } 333 } 334 } 335 336 target.finishGeographyBuild(type, level); 337 } 338 339 339 340 private boolean appendUturn(SweepPolygonCursor cursor, boolean toTheLeft) 340 341 { 341 Strip strip = strips.elementAt(cursor.stripIndex);342 target.appendUturnNode(strip, cursor.partIndex, cursor.stripIndex,343 beams.elementAt(toTheLeft ? cursor.stripIndex + 1 : cursor.stripIndex).344 getBeamPartIndex(toTheLeft, cursor.partIndex),345 toTheLeft, level);346 347 if (cursor.partIndex % 2 == 0)348 ++cursor.partIndex;349 else350 --cursor.partIndex;351 return !toTheLeft;342 Strip strip = strips.elementAt(cursor.stripIndex); 343 target.appendUturnNode(strip, cursor.partIndex, cursor.stripIndex, 344 beams.elementAt(toTheLeft ? cursor.stripIndex + 1 : cursor.stripIndex). 345 getBeamPartIndex(toTheLeft, cursor.partIndex), 346 toTheLeft, level); 347 348 if (cursor.partIndex % 2 == 0) 349 ++cursor.partIndex; 350 else 351 --cursor.partIndex; 352 return !toTheLeft; 352 353 } 353 354 } -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/IndoorSweeplineWizardAction.java
r32103 r32479 4 4 5 5 import java.awt.event.ActionEvent; 6 6 7 import javax.swing.JOptionPane; 8 7 9 import org.openstreetmap.josm.Main; 8 10 import org.openstreetmap.josm.actions.JosmAction; 9 11 import org.openstreetmap.josm.data.projection.Projections; 10 12 import org.openstreetmap.josm.gui.layer.Layer; 13 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 14 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 17 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 18 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 11 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 12 import org.openstreetmap.josm.gui.MapView;13 20 14 21 15 public class IndoorSweeplineWizardAction extends JosmAction implements MapView.LayerChangeListener22 public class IndoorSweeplineWizardAction extends JosmAction implements LayerChangeListener, ActiveLayerChangeListener 16 23 { 17 24 public IndoorSweeplineWizardAction() 18 25 { 19 super(tr("Concourse wizard ..."), null,20 tr("Opens up a wizard to create a concourse"), null, false);21 MapView.addLayerChangeListener(this);26 super(tr("Concourse wizard ..."), null, 27 tr("Opens up a wizard to create a concourse"), null, false); 28 Main.getLayerManager().addLayerChangeListener(this); 22 29 } 23 30 … … 25 32 public void actionPerformed(ActionEvent event) 26 33 { 27 if (layer == null) 28 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 29 "No default layer found."); 30 else if (!(layer instanceof OsmDataLayer)) 31 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 32 "The default layer is not an OSM layer."); 33 else if (Main.map == null) 34 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 35 "No map found."); 36 else if (Main.map.mapView == null) 37 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 38 "No map view found."); 39 else 40 new IndoorSweeplineController((OsmDataLayer)layer, 41 Projections.inverseProject(Main.map.mapView.getCenter())); 42 } 43 44 45 @Override 46 public void activeLayerChange(Layer oldLayer, Layer newLayer) 47 { 48 layer = newLayer; 34 if (layer == null) 35 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 36 "No default layer found."); 37 else if (!(layer instanceof OsmDataLayer)) 38 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 39 "The default layer is not an OSM layer."); 40 else if (Main.map == null) 41 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 42 "No map found."); 43 else if (Main.map.mapView == null) 44 JOptionPane.showMessageDialog(JOptionPane.getFrameForComponent(Main.parent), 45 "No map view found."); 46 else 47 new IndoorSweeplineController((OsmDataLayer)layer, 48 Projections.inverseProject(Main.map.mapView.getCenter())); 49 49 } 50 50 51 51 @Override 52 public void layerAdded(Layer newLayer) 52 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) 53 { 54 layer = Main.getLayerManager().getActiveLayer(); 55 } 56 57 @Override 58 public void layerOrderChanged(LayerOrderChangeEvent e) 53 59 { 54 60 } 55 61 56 62 @Override 57 public void layer Removed(LayeroldLayer)63 public void layerAdded(LayerAddEvent e) 58 64 { 59 if (layer == oldLayer)60 layer = null;61 65 } 62 66 67 @Override 68 public void layerRemoving(LayerRemoveEvent e) 69 { 70 if (layer == e.getRemovedLayer()) 71 layer = null; 72 } 73 63 74 private Layer layer; 64 75 } -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/IndoorSweeplineWizardDialog.java
r32109 r32479 10 10 import java.util.List; 11 11 import java.util.Vector; 12 12 13 import javax.swing.AbstractAction; 13 14 import javax.swing.DefaultCellEditor; … … 29 30 import javax.swing.table.TableColumn; 30 31 import javax.swing.table.TableModel; 32 31 33 import org.openstreetmap.josm.Main; 32 34 … … 36 38 public IndoorSweeplineWizardDialog(IndoorSweeplineController controller) 37 39 { 38 super(JOptionPane.getFrameForComponent(Main.parent), "Indoor Sweepline Wizard", false); 39 40 this.controller = controller; 41 beamIndex = 0; 42 prev = new PrevAction(); 43 next = new NextAction(); 44 45 GridbagPanel panel = new GridbagPanel(); 46 47 panel.add(new JLabel(tr("Vertical layer:")), 0, 0, 3, 1); 48 panel.add(makeLevelField(), 3, 0, 1, 1); 49 panel.add(new JLabel(tr("Structure type:")), 0, 1, 3, 1); 50 panel.add(typeBox(), 3, 1, 1, 1); 51 52 panel.add(new JButton(prev), 0, 2, 1, 1); 53 panel.add(structureBox(), 1, 2, 1, 1); 54 panel.add(new JButton(next), 2, 2, 2, 1); 55 56 panel.add(makeWidthLabel(), 0, 3, 3, 1); 57 panel.add(makeWidthField(), 3, 3, 1, 1); 58 59 panel.add(makeStructureTable(), 0, 4, 4, 1); 60 61 add(panel); 62 pack(); 63 refresh(); 64 } 65 66 40 super(JOptionPane.getFrameForComponent(Main.parent), "Indoor Sweepline Wizard", false); 41 42 this.controller = controller; 43 beamIndex = 0; 44 prev = new PrevAction(); 45 next = new NextAction(); 46 47 GridbagPanel panel = new GridbagPanel(); 48 49 panel.add(new JLabel(tr("Vertical layer:")), 0, 0, 3, 1); 50 panel.add(makeLevelField(), 3, 0, 1, 1); 51 panel.add(new JLabel(tr("Structure type:")), 0, 1, 3, 1); 52 panel.add(typeBox(), 3, 1, 1, 1); 53 54 panel.add(new JButton(prev), 0, 2, 1, 1); 55 panel.add(structureBox(), 1, 2, 1, 1); 56 panel.add(new JButton(next), 2, 2, 2, 1); 57 58 panel.add(makeWidthLabel(), 0, 3, 3, 1); 59 panel.add(makeWidthField(), 3, 3, 1, 1); 60 61 panel.add(makeStructureTable(), 0, 4, 4, 1); 62 63 add(panel); 64 pack(); 65 refresh(); 66 } 67 68 69 @Override 67 70 public void setVisible(boolean visible) 68 { 69 if (visible)70 setLocationRelativeTo(JOptionPane.getFrameForComponent(Main.parent));71 super.setVisible(visible);72 } 73 74 71 { 72 if (visible) 73 setLocationRelativeTo(JOptionPane.getFrameForComponent(Main.parent)); 74 super.setVisible(visible); 75 } 76 77 75 78 private void refresh() 76 79 { 77 inRefresh = true;78 79 leftRightCount = controller.leftRightCount();80 prev.setEnabled(beamIndex > 0);81 82 DefaultComboBoxModel<String> structureBoxModel = controller.structures();83 structureBoxModel.setSelectedItem(structureBoxModel.getElementAt(beamIndex));84 85 try86 {87 if (beamIndex % 2 == 0)88 {89 widthOffsetLabel.setText("Offset into background:");90 stripWidth.setText(Double.toString(controller.getBeamOffset(beamIndex)));91 }92 else93 {94 widthOffsetLabel.setText("Strip width:");95 stripWidth.setText(Double.toString(controller.getStripWidth(beamIndex)));96 }97 }98 catch (IllegalStateException ex)99 {100 }101 102 try103 {104 level.setText(controller.getLevel());105 }106 catch (IllegalStateException ex)107 {108 }109 110 typeBoxModel.setSelectedItem(structureTypeToString(controller.getType()));111 112 113 structureTableModel.setRowCount(0);114 if (beamIndex % 2 == 0)115 {116 Vector<Object> row = new Vector<Object>();117 row.addElement("");118 row.addElement("");119 row.addElement("");120 structureTableModel.addRow(row);121 122 List<CorridorPart> parts = controller.getBeamParts(beamIndex);123 for (CorridorPart part : parts)124 {125 row = new Vector<Object>();126 row.addElement(Double.toString(part.width));127 row.addElement(corridorPartTypeToString(part.getType()));128 row.addElement(corridorPartSideToString(part.getSide()));129 structureTableModel.addRow(row);130 }131 row = new Vector<Object>();132 row.addElement("");133 row.addElement("");134 row.addElement("");135 structureTableModel.addRow(row);136 structureTableModel.isBeam = true;137 }138 else139 {140 Strip strip = controller.getStrip(beamIndex);141 for (int i = 0; i < strip.lhs.size() || i < strip.rhs.size(); ++i)142 {143 Vector<Object> row = new Vector<Object>();144 String position = i < strip.lhs.size() ? strip.lhs.elementAt(i).toString() : "X";145 position += " - " + (i < strip.rhs.size() ? strip.rhs.elementAt(i).toString() : "X");146 row.addElement(position);147 row.addElement(i < strip.parts.size() ?148 corridorPartTypeToString(strip.parts.elementAt(i).getType()) : "wall");149 row.addElement(i < strip.parts.size() ?150 corridorPartSideToString(strip.parts.elementAt(i).getSide()) : "all");151 structureTableModel.addRow(row);152 }153 structureTableModel.isBeam = false;154 }155 156 inRefresh = false;157 } 158 159 80 inRefresh = true; 81 82 leftRightCount = controller.leftRightCount(); 83 prev.setEnabled(beamIndex > 0); 84 85 DefaultComboBoxModel<String> structureBoxModel = controller.structures(); 86 structureBoxModel.setSelectedItem(structureBoxModel.getElementAt(beamIndex)); 87 88 try 89 { 90 if (beamIndex % 2 == 0) 91 { 92 widthOffsetLabel.setText("Offset into background:"); 93 stripWidth.setText(Double.toString(controller.getBeamOffset(beamIndex))); 94 } 95 else 96 { 97 widthOffsetLabel.setText("Strip width:"); 98 stripWidth.setText(Double.toString(controller.getStripWidth(beamIndex))); 99 } 100 } 101 catch (IllegalStateException ex) 102 { 103 } 104 105 try 106 { 107 level.setText(controller.getLevel()); 108 } 109 catch (IllegalStateException ex) 110 { 111 } 112 113 typeBoxModel.setSelectedItem(structureTypeToString(controller.getType())); 114 115 116 structureTableModel.setRowCount(0); 117 if (beamIndex % 2 == 0) 118 { 119 Vector<Object> row = new Vector<>(); 120 row.addElement(""); 121 row.addElement(""); 122 row.addElement(""); 123 structureTableModel.addRow(row); 124 125 List<CorridorPart> parts = controller.getBeamParts(beamIndex); 126 for (CorridorPart part : parts) 127 { 128 row = new Vector<>(); 129 row.addElement(Double.toString(part.width)); 130 row.addElement(corridorPartTypeToString(part.getType())); 131 row.addElement(corridorPartSideToString(part.getSide())); 132 structureTableModel.addRow(row); 133 } 134 row = new Vector<>(); 135 row.addElement(""); 136 row.addElement(""); 137 row.addElement(""); 138 structureTableModel.addRow(row); 139 structureTableModel.isBeam = true; 140 } 141 else 142 { 143 Strip strip = controller.getStrip(beamIndex); 144 for (int i = 0; i < strip.lhs.size() || i < strip.rhs.size(); ++i) 145 { 146 Vector<Object> row = new Vector<>(); 147 String position = i < strip.lhs.size() ? strip.lhs.elementAt(i).toString() : "X"; 148 position += " - " + (i < strip.rhs.size() ? strip.rhs.elementAt(i).toString() : "X"); 149 row.addElement(position); 150 row.addElement(i < strip.parts.size() ? 151 corridorPartTypeToString(strip.parts.elementAt(i).getType()) : "wall"); 152 row.addElement(i < strip.parts.size() ? 153 corridorPartSideToString(strip.parts.elementAt(i).getSide()) : "all"); 154 structureTableModel.addRow(row); 155 } 156 structureTableModel.isBeam = false; 157 } 158 159 inRefresh = false; 160 } 161 162 160 163 private String corridorPartTypeToString(CorridorPart.Type type) 161 164 { 162 if (type == CorridorPart.Type.VOID)163 return "void";164 else if (type == CorridorPart.Type.PASSAGE)165 return "passage";166 else if (type == CorridorPart.Type.WALL)167 return "wall";168 else if (type == CorridorPart.Type.STAIRS_UP)169 return "stairs to upper level";170 else if (type == CorridorPart.Type.STAIRS_DOWN)171 return "stairs to lower level";172 else if (type == CorridorPart.Type.ESCALATOR_UP_LEAVING)173 return "escalator leaving to upper level";174 else if (type == CorridorPart.Type.ESCALATOR_UP_ARRIVING)175 return "escalator arriving from upper level";176 else if (type == CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL)177 return "escalator (reversible) to upper level";178 else if (type == CorridorPart.Type.ESCALATOR_DOWN_LEAVING)179 return "escalator leaving to lower level";180 else if (type == CorridorPart.Type.ESCALATOR_DOWN_ARRIVING)181 return "escalator arriving from lower level";182 else if (type == CorridorPart.Type.ESCALATOR_DOWN_BIDIRECTIONAL)183 return "escalator (reversible) to lower level";184 else if (type == CorridorPart.Type.ELEVATOR)185 return "elevator";186 return "";187 } 188 189 165 if (type == CorridorPart.Type.VOID) 166 return "void"; 167 else if (type == CorridorPart.Type.PASSAGE) 168 return "passage"; 169 else if (type == CorridorPart.Type.WALL) 170 return "wall"; 171 else if (type == CorridorPart.Type.STAIRS_UP) 172 return "stairs to upper level"; 173 else if (type == CorridorPart.Type.STAIRS_DOWN) 174 return "stairs to lower level"; 175 else if (type == CorridorPart.Type.ESCALATOR_UP_LEAVING) 176 return "escalator leaving to upper level"; 177 else if (type == CorridorPart.Type.ESCALATOR_UP_ARRIVING) 178 return "escalator arriving from upper level"; 179 else if (type == CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL) 180 return "escalator (reversible) to upper level"; 181 else if (type == CorridorPart.Type.ESCALATOR_DOWN_LEAVING) 182 return "escalator leaving to lower level"; 183 else if (type == CorridorPart.Type.ESCALATOR_DOWN_ARRIVING) 184 return "escalator arriving from lower level"; 185 else if (type == CorridorPart.Type.ESCALATOR_DOWN_BIDIRECTIONAL) 186 return "escalator (reversible) to lower level"; 187 else if (type == CorridorPart.Type.ELEVATOR) 188 return "elevator"; 189 return ""; 190 } 191 192 190 193 private CorridorPart.Type parseCorridorPartType(String val) 191 194 { 192 if (val == "void")193 return CorridorPart.Type.VOID;194 else if (val == "passage")195 return CorridorPart.Type.PASSAGE;196 else if (val == "wall")197 return CorridorPart.Type.WALL;198 else if (val == "stairs to upper level")199 return CorridorPart.Type.STAIRS_UP;200 else if (val == "stairs to lower level")201 return CorridorPart.Type.STAIRS_DOWN;202 else if (val == "escalator leaving to upper level")203 return CorridorPart.Type.ESCALATOR_UP_LEAVING;204 else if (val == "escalator arriving from upper level")205 return CorridorPart.Type.ESCALATOR_UP_ARRIVING;206 else if (val == "escalator (reversible) to upper level")207 return CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL;208 else if (val == "escalator leaving to lower level")209 return CorridorPart.Type.ESCALATOR_DOWN_LEAVING;210 else if (val == "escalator arriving from lower level")211 return CorridorPart.Type.ESCALATOR_DOWN_ARRIVING;212 else if (val == "escalator (reversible) to lower level")213 return CorridorPart.Type.ESCALATOR_DOWN_BIDIRECTIONAL;214 else if (val == "elevator")215 return CorridorPart.Type.ELEVATOR;216 return CorridorPart.Type.VOID;217 } 218 219 195 if (val == "void") 196 return CorridorPart.Type.VOID; 197 else if (val == "passage") 198 return CorridorPart.Type.PASSAGE; 199 else if (val == "wall") 200 return CorridorPart.Type.WALL; 201 else if (val == "stairs to upper level") 202 return CorridorPart.Type.STAIRS_UP; 203 else if (val == "stairs to lower level") 204 return CorridorPart.Type.STAIRS_DOWN; 205 else if (val == "escalator leaving to upper level") 206 return CorridorPart.Type.ESCALATOR_UP_LEAVING; 207 else if (val == "escalator arriving from upper level") 208 return CorridorPart.Type.ESCALATOR_UP_ARRIVING; 209 else if (val == "escalator (reversible) to upper level") 210 return CorridorPart.Type.ESCALATOR_UP_BIDIRECTIONAL; 211 else if (val == "escalator leaving to lower level") 212 return CorridorPart.Type.ESCALATOR_DOWN_LEAVING; 213 else if (val == "escalator arriving from lower level") 214 return CorridorPart.Type.ESCALATOR_DOWN_ARRIVING; 215 else if (val == "escalator (reversible) to lower level") 216 return CorridorPart.Type.ESCALATOR_DOWN_BIDIRECTIONAL; 217 else if (val == "elevator") 218 return CorridorPart.Type.ELEVATOR; 219 return CorridorPart.Type.VOID; 220 } 221 222 220 223 private String corridorPartSideToString(CorridorPart.ReachableSide side) 221 224 { 222 if (side == CorridorPart.ReachableSide.ALL)223 return "all";224 else if (side == CorridorPart.ReachableSide.FRONT)225 return "front";226 else if (side == CorridorPart.ReachableSide.BACK)227 return "back";228 else if (side == CorridorPart.ReachableSide.LEFT)229 return "left";230 else if (side == CorridorPart.ReachableSide.RIGHT)231 return "right";232 return "";233 } 234 235 225 if (side == CorridorPart.ReachableSide.ALL) 226 return "all"; 227 else if (side == CorridorPart.ReachableSide.FRONT) 228 return "front"; 229 else if (side == CorridorPart.ReachableSide.BACK) 230 return "back"; 231 else if (side == CorridorPart.ReachableSide.LEFT) 232 return "left"; 233 else if (side == CorridorPart.ReachableSide.RIGHT) 234 return "right"; 235 return ""; 236 } 237 238 236 239 private CorridorPart.ReachableSide parseCorridorPartSide(String val) 237 240 { 238 if (val == "all")239 return CorridorPart.ReachableSide.ALL;240 else if (val == "front")241 return CorridorPart.ReachableSide.FRONT;242 else if (val == "back")243 return CorridorPart.ReachableSide.BACK;244 else if (val == "left")245 return CorridorPart.ReachableSide.LEFT;246 else if (val == "right")247 return CorridorPart.ReachableSide.RIGHT;248 return CorridorPart.ReachableSide.ALL;249 } 250 251 241 if (val == "all") 242 return CorridorPart.ReachableSide.ALL; 243 else if (val == "front") 244 return CorridorPart.ReachableSide.FRONT; 245 else if (val == "back") 246 return CorridorPart.ReachableSide.BACK; 247 else if (val == "left") 248 return CorridorPart.ReachableSide.LEFT; 249 else if (val == "right") 250 return CorridorPart.ReachableSide.RIGHT; 251 return CorridorPart.ReachableSide.ALL; 252 } 253 254 252 255 private String structureTypeToString(IndoorSweeplineModel.Type type) 253 256 { 254 if (type == IndoorSweeplineModel.Type.CORRIDOR)255 return "corridor";256 else if (type == IndoorSweeplineModel.Type.PLATFORM)257 return "platform";258 return "";259 } 260 261 262 private JComboBox structureBox() 263 { 264 JComboBox structureBox = new JComboBox<String>(controller.structures());265 structureBox.addActionListener(new StructureBoxListener());266 return structureBox;267 } 268 269 257 if (type == IndoorSweeplineModel.Type.CORRIDOR) 258 return "corridor"; 259 else if (type == IndoorSweeplineModel.Type.PLATFORM) 260 return "platform"; 261 return ""; 262 } 263 264 265 private JComboBox<String> structureBox() 266 { 267 JComboBox<String> structureBox = new JComboBox<>(controller.structures()); 268 structureBox.addActionListener(new StructureBoxListener()); 269 return structureBox; 270 } 271 272 270 273 private IndoorSweeplineController controller; 271 274 272 275 private int beamIndex; 273 276 private int leftRightCount; … … 275 278 private NextAction next; 276 279 boolean inRefresh; 277 278 279 private JComboBox typeBox() 280 { 281 if (typeBoxModel == null)282 {283 typeBoxModel = new DefaultComboBoxModel<String>();284 typeBoxModel.addElement("corridor");285 typeBoxModel.addElement("platform");286 }287 JComboBox typeBox = new JComboBox<String>(typeBoxModel);288 typeBox.addActionListener(new TypeBoxListener());289 return typeBox;290 } 291 280 281 282 private JComboBox<String> typeBox() 283 { 284 if (typeBoxModel == null) 285 { 286 typeBoxModel = new DefaultComboBoxModel<>(); 287 typeBoxModel.addElement("corridor"); 288 typeBoxModel.addElement("platform"); 289 } 290 JComboBox<String> typeBox = new JComboBox<>(typeBoxModel); 291 typeBox.addActionListener(new TypeBoxListener()); 292 return typeBox; 293 } 294 292 295 private DefaultComboBoxModel<String> typeBoxModel; 293 294 296 297 295 298 private class TypeBoxListener implements ActionListener 296 299 { 297 public void actionPerformed(ActionEvent e) 298 { 299 if (inRefresh) 300 return; 301 302 String entry = (String)((JComboBox)e.getSource()).getSelectedItem(); 303 if (entry == "corridor") 304 controller.setType(IndoorSweeplineModel.Type.CORRIDOR); 305 else 306 controller.setType(IndoorSweeplineModel.Type.PLATFORM); 307 308 refresh(); 309 } 310 } 311 312 300 @Override 301 public void actionPerformed(ActionEvent e) 302 { 303 if (inRefresh) 304 return; 305 306 @SuppressWarnings("unchecked") 307 String entry = (String)((JComboBox<String>)e.getSource()).getSelectedItem(); 308 if (entry == "corridor") 309 controller.setType(IndoorSweeplineModel.Type.CORRIDOR); 310 else 311 controller.setType(IndoorSweeplineModel.Type.PLATFORM); 312 313 refresh(); 314 } 315 } 316 317 313 318 private class PrevAction extends AbstractAction 314 319 { 315 public PrevAction() 316 { 317 super("Prev"); 318 } 319 320 public void actionPerformed(ActionEvent e) 321 { 322 if (inRefresh) 323 return; 324 325 if (beamIndex > 0) 326 --beamIndex; 327 refresh(); 328 } 329 } 330 331 320 public PrevAction() 321 { 322 super("Prev"); 323 } 324 325 @Override 326 public void actionPerformed(ActionEvent e) 327 { 328 if (inRefresh) 329 return; 330 331 if (beamIndex > 0) 332 --beamIndex; 333 refresh(); 334 } 335 } 336 337 332 338 private class NextAction extends AbstractAction 333 339 { 334 public NextAction() 335 { 336 super("Next"); 337 } 338 339 public void actionPerformed(ActionEvent e) 340 { 341 if (inRefresh) 342 return; 343 344 ++beamIndex; 345 if (beamIndex >= leftRightCount) 346 controller.addRightStructure(); 347 refresh(); 348 } 349 } 350 351 340 public NextAction() 341 { 342 super("Next"); 343 } 344 345 @Override 346 public void actionPerformed(ActionEvent e) 347 { 348 if (inRefresh) 349 return; 350 351 ++beamIndex; 352 if (beamIndex >= leftRightCount) 353 controller.addRightStructure(); 354 refresh(); 355 } 356 } 357 358 352 359 private class StructureBoxListener implements ActionListener 353 360 { 354 public void actionPerformed(ActionEvent e) 355 { 356 if (inRefresh) 357 return; 358 359 String entry = (String)((JComboBox)e.getSource()).getSelectedItem(); 360 DefaultComboBoxModel<String> structureBoxModel = controller.structures(); 361 for (int i = 0; i < structureBoxModel.getSize(); ++i) 362 { 363 if (structureBoxModel.getElementAt(i).equals(entry)) 364 beamIndex = i; 365 } 366 refresh(); 367 } 368 } 369 370 361 @Override 362 public void actionPerformed(ActionEvent e) 363 { 364 if (inRefresh) 365 return; 366 367 @SuppressWarnings("unchecked") 368 String entry = (String)((JComboBox<String>)e.getSource()).getSelectedItem(); 369 DefaultComboBoxModel<String> structureBoxModel = controller.structures(); 370 for (int i = 0; i < structureBoxModel.getSize(); ++i) 371 { 372 if (structureBoxModel.getElementAt(i).equals(entry)) 373 beamIndex = i; 374 } 375 refresh(); 376 } 377 } 378 379 371 380 private JLabel widthOffsetLabel; 372 381 373 382 private JLabel makeWidthLabel() 374 383 { 375 widthOffsetLabel = new JLabel(tr("Offset into background:"));376 return widthOffsetLabel;377 } 378 379 384 widthOffsetLabel = new JLabel(tr("Offset into background:")); 385 return widthOffsetLabel; 386 } 387 388 380 389 private JTextField stripWidth; 381 390 382 391 private JTextField makeWidthField() 383 392 { 384 stripWidth = new JTextField(5);385 stripWidth.getDocument().addDocumentListener(new StripWidthListener());386 return stripWidth;387 } 388 389 393 stripWidth = new JTextField(5); 394 stripWidth.getDocument().addDocumentListener(new StripWidthListener()); 395 return stripWidth; 396 } 397 398 390 399 private class StripWidthListener implements DocumentListener 391 400 { 392 public void changedUpdate(DocumentEvent e) 393 { 394 update(e); 395 } 396 397 public void insertUpdate(DocumentEvent e) 398 { 399 update(e); 400 } 401 402 public void removeUpdate(DocumentEvent e) 403 { 404 update(e); 405 } 406 407 408 private void update(DocumentEvent e) 409 { 410 if (inRefresh) 411 return; 412 413 try 414 { 415 if (beamIndex % 2 == 0) 416 controller.setBeamOffset(beamIndex, Double.parseDouble(stripWidth.getText())); 417 else 418 controller.setStripWidth(beamIndex, Double.parseDouble(stripWidth.getText())); 419 } 420 catch (NumberFormatException ex) 421 { 422 } 423 424 refresh(); 425 } 426 } 427 428 401 @Override 402 public void changedUpdate(DocumentEvent e) 403 { 404 update(e); 405 } 406 407 @Override 408 public void insertUpdate(DocumentEvent e) 409 { 410 update(e); 411 } 412 413 @Override 414 public void removeUpdate(DocumentEvent e) 415 { 416 update(e); 417 } 418 419 420 private void update(DocumentEvent e) 421 { 422 if (inRefresh) 423 return; 424 425 try 426 { 427 if (beamIndex % 2 == 0) 428 controller.setBeamOffset(beamIndex, Double.parseDouble(stripWidth.getText())); 429 else 430 controller.setStripWidth(beamIndex, Double.parseDouble(stripWidth.getText())); 431 } 432 catch (NumberFormatException ex) 433 { 434 } 435 436 refresh(); 437 } 438 } 439 440 429 441 private JTextField level; 430 442 431 443 private JTextField makeLevelField() 432 444 { 433 level = new JTextField(5);434 level.getDocument().addDocumentListener(new LevelFieldListener());435 return level;436 } 437 438 445 level = new JTextField(5); 446 level.getDocument().addDocumentListener(new LevelFieldListener()); 447 return level; 448 } 449 450 439 451 private class LevelFieldListener implements DocumentListener 440 452 { 441 public void changedUpdate(DocumentEvent e) 442 { 443 update(e); 444 } 445 446 public void insertUpdate(DocumentEvent e) 447 { 448 update(e); 449 } 450 451 public void removeUpdate(DocumentEvent e) 452 { 453 update(e); 454 } 455 456 457 private void update(DocumentEvent e) 458 { 459 if (inRefresh) 460 return; 461 462 controller.setLevel(level.getText()); 463 464 refresh(); 465 } 466 } 467 468 453 @Override 454 public void changedUpdate(DocumentEvent e) 455 { 456 update(e); 457 } 458 459 @Override 460 public void insertUpdate(DocumentEvent e) 461 { 462 update(e); 463 } 464 465 @Override 466 public void removeUpdate(DocumentEvent e) 467 { 468 update(e); 469 } 470 471 472 private void update(DocumentEvent e) 473 { 474 if (inRefresh) 475 return; 476 477 controller.setLevel(level.getText()); 478 479 refresh(); 480 } 481 } 482 483 469 484 private class StructureTableModel extends DefaultTableModel 470 485 { 471 @Override472 public boolean isCellEditable(int row, int column)473 {474 return isBeam || column == 1;475 }476 477 public boolean isBeam;478 } 479 486 @Override 487 public boolean isCellEditable(int row, int column) 488 { 489 return isBeam || column == 1; 490 } 491 492 public boolean isBeam; 493 } 494 480 495 private StructureTableModel structureTableModel; 481 496 482 497 private JScrollPane makeStructureTable() 483 498 { 484 structureTableModel = new StructureTableModel();485 structureTableModel.addColumn("Width");486 structureTableModel.addColumn("Type");487 structureTableModel.addColumn("Reachable Side");488 structureTableModel.addTableModelListener(new StructureTableListener());489 490 JTable table = new JTable(structureTableModel);491 492 TableColumn column = table.getColumnModel().getColumn(1);493 JComboBox<String> comboBox = new JComboBox<String>();494 comboBox.addItem("void");495 comboBox.addItem("passage");496 comboBox.addItem("wall");497 comboBox.addItem("stairs to upper level");498 comboBox.addItem("stairs to lower level");499 comboBox.addItem("escalator leaving to upper level");500 comboBox.addItem("escalator arriving from upper level");501 comboBox.addItem("escalator (reversible) to upper level");502 comboBox.addItem("escalator leaving to lower level");503 comboBox.addItem("escalator arriving from lower level");504 comboBox.addItem("escalator (reversible) to lower level");505 comboBox.addItem("elevator");506 column.setCellEditor(new DefaultCellEditor(comboBox));507 508 column = table.getColumnModel().getColumn(2);509 comboBox = new JComboBox<String>();510 comboBox.addItem("all");511 comboBox.addItem("left");512 comboBox.addItem("right");513 column.setCellEditor(new DefaultCellEditor(comboBox));514 515 return new JScrollPane(table);516 } 517 499 structureTableModel = new StructureTableModel(); 500 structureTableModel.addColumn("Width"); 501 structureTableModel.addColumn("Type"); 502 structureTableModel.addColumn("Reachable Side"); 503 structureTableModel.addTableModelListener(new StructureTableListener()); 504 505 JTable table = new JTable(structureTableModel); 506 507 TableColumn column = table.getColumnModel().getColumn(1); 508 JComboBox<String> comboBox = new JComboBox<>(); 509 comboBox.addItem("void"); 510 comboBox.addItem("passage"); 511 comboBox.addItem("wall"); 512 comboBox.addItem("stairs to upper level"); 513 comboBox.addItem("stairs to lower level"); 514 comboBox.addItem("escalator leaving to upper level"); 515 comboBox.addItem("escalator arriving from upper level"); 516 comboBox.addItem("escalator (reversible) to upper level"); 517 comboBox.addItem("escalator leaving to lower level"); 518 comboBox.addItem("escalator arriving from lower level"); 519 comboBox.addItem("escalator (reversible) to lower level"); 520 comboBox.addItem("elevator"); 521 column.setCellEditor(new DefaultCellEditor(comboBox)); 522 523 column = table.getColumnModel().getColumn(2); 524 comboBox = new JComboBox<>(); 525 comboBox.addItem("all"); 526 comboBox.addItem("left"); 527 comboBox.addItem("right"); 528 column.setCellEditor(new DefaultCellEditor(comboBox)); 529 530 return new JScrollPane(table); 531 } 532 518 533 private class StructureTableListener implements TableModelListener 519 534 { 520 public void tableChanged(TableModelEvent e) 521 { 522 if (inRefresh) 523 return; 524 525 int column = e.getColumn(); 526 int row = e.getFirstRow(); 527 if (column == 0 && beamIndex % 2 == 0) 528 { 529 try 530 { 531 if (row == 0 || row == structureTableModel.getRowCount() - 1) 532 controller.addCorridorPart(beamIndex, row != 0, 533 Double.parseDouble(((TableModel)e.getSource()).getValueAt(row, column).toString())); 534 else 535 controller.setCorridorPartWidth(beamIndex, row - 1, 536 Double.parseDouble(((TableModel)e.getSource()).getValueAt(row, column).toString())); 537 } 538 catch (NumberFormatException ex) 539 { 540 } 541 } 542 else if (column == 1 && beamIndex % 2 == 0) 543 { 544 if (row > 0 && row < structureTableModel.getRowCount() - 1) 545 controller.setCorridorPartType(beamIndex, row - 1, 546 parseCorridorPartType(((TableModel)e.getSource()).getValueAt(row, column).toString())); 547 } 548 else if (column == 1 && beamIndex % 2 == 1) 549 { 550 controller.setCorridorPartType(beamIndex, row, 551 parseCorridorPartType(((TableModel)e.getSource()).getValueAt(row, column).toString())); 552 } 553 else if (column == 2 && beamIndex % 2 == 0) 554 { 555 if (row > 0 && row < structureTableModel.getRowCount() - 1) 556 controller.setCorridorPartSide(beamIndex, row - 1, 557 parseCorridorPartSide(((TableModel)e.getSource()).getValueAt(row, column).toString())); 558 } 559 560 refresh(); 561 } 562 } 563 564 535 @Override 536 public void tableChanged(TableModelEvent e) 537 { 538 if (inRefresh) 539 return; 540 541 int column = e.getColumn(); 542 int row = e.getFirstRow(); 543 if (column == 0 && beamIndex % 2 == 0) 544 { 545 try 546 { 547 if (row == 0 || row == structureTableModel.getRowCount() - 1) 548 controller.addCorridorPart(beamIndex, row != 0, 549 Double.parseDouble(((TableModel)e.getSource()).getValueAt(row, column).toString())); 550 else 551 controller.setCorridorPartWidth(beamIndex, row - 1, 552 Double.parseDouble(((TableModel)e.getSource()).getValueAt(row, column).toString())); 553 } 554 catch (NumberFormatException ex) 555 { 556 } 557 } 558 else if (column == 1 && beamIndex % 2 == 0) 559 { 560 if (row > 0 && row < structureTableModel.getRowCount() - 1) 561 controller.setCorridorPartType(beamIndex, row - 1, 562 parseCorridorPartType(((TableModel)e.getSource()).getValueAt(row, column).toString())); 563 } 564 else if (column == 1 && beamIndex % 2 == 1) 565 { 566 controller.setCorridorPartType(beamIndex, row, 567 parseCorridorPartType(((TableModel)e.getSource()).getValueAt(row, column).toString())); 568 } 569 else if (column == 2 && beamIndex % 2 == 0) 570 { 571 if (row > 0 && row < structureTableModel.getRowCount() - 1) 572 controller.setCorridorPartSide(beamIndex, row - 1, 573 parseCorridorPartSide(((TableModel)e.getSource()).getValueAt(row, column).toString())); 574 } 575 576 refresh(); 577 } 578 } 579 580 565 581 private class GridbagPanel extends JPanel 566 582 { 567 public GridbagPanel()568 {569 gridbag = new GridBagLayout();570 layoutCons = new GridBagConstraints();571 setLayout(gridbag);572 }573 574 public void add(Component comp, int gridx, int gridy, int gridwidth, int gridheight)575 {576 layoutCons.gridx = gridx;577 layoutCons.gridy = gridy;578 layoutCons.gridwidth = gridwidth;579 layoutCons.gridheight = gridheight;580 layoutCons.weightx = 0.0;581 layoutCons.weighty = 0.0;582 layoutCons.fill = GridBagConstraints.BOTH;583 584 gridbag.setConstraints(comp, layoutCons);585 add(comp);586 }587 588 private GridBagLayout gridbag;589 private GridBagConstraints layoutCons;583 public GridbagPanel() 584 { 585 gridbag = new GridBagLayout(); 586 layoutCons = new GridBagConstraints(); 587 setLayout(gridbag); 588 } 589 590 public void add(Component comp, int gridx, int gridy, int gridwidth, int gridheight) 591 { 592 layoutCons.gridx = gridx; 593 layoutCons.gridy = gridy; 594 layoutCons.gridwidth = gridwidth; 595 layoutCons.gridheight = gridheight; 596 layoutCons.weightx = 0.0; 597 layoutCons.weighty = 0.0; 598 layoutCons.fill = GridBagConstraints.BOTH; 599 600 gridbag.setConstraints(comp, layoutCons); 601 add(comp); 602 } 603 604 private GridBagLayout gridbag; 605 private GridBagConstraints layoutCons; 590 606 } 591 607 } -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/ModelGeography.java
r32109 r32479 3 3 import java.util.List; 4 4 import java.util.Vector; 5 5 6 import org.openstreetmap.josm.data.coor.LatLon; 6 7 import org.openstreetmap.josm.data.osm.DataSet; … … 16 17 public ModelGeography(DataSet dataSet, LatLon center) 17 18 { 18 beamsGeography = new Vector<BeamGeography>();19 20 this.dataSet = dataSet;21 this.center = center;22 23 wayPool = new Vector<Way>();24 wayPoolCount = 0;25 nodePool = new Vector<Node>();26 nodePoolCount = 0;27 28 nodes = null;29 multipolygon = null;30 members = null;31 } 32 19 beamsGeography = new Vector<>(); 20 21 this.dataSet = dataSet; 22 this.center = center; 23 24 wayPool = new Vector<>(); 25 wayPoolCount = 0; 26 nodePool = new Vector<>(); 27 nodePoolCount = 0; 28 29 nodes = null; 30 multipolygon = null; 31 members = null; 32 } 33 33 34 34 35 private Vector<BeamGeography> beamsGeography; 35 36 36 37 private DataSet dataSet; 37 38 private LatLon center; 38 39 39 40 private Vector<Way> wayPool; 40 41 private int wayPoolCount; 41 42 private Vector<Node> nodePool; 42 43 private int nodePoolCount; 43 44 44 45 private Vector<Node> nodes; 45 46 private Relation multipolygon; 46 47 private Vector<RelationMember> members; 47 48 48 49 49 50 public void appendNode(Node node) 50 51 { 51 nodes.add(node);52 } 53 54 52 nodes.add(node); 53 } 54 55 55 56 public DataSet getDataSet() 56 57 { 57 return dataSet;58 } 59 60 58 return dataSet; 59 } 60 61 61 62 public BeamGeography beamAt(int i) 62 63 { 63 return beamsGeography.elementAt(i);64 } 65 66 64 return beamsGeography.elementAt(i); 65 } 66 67 67 68 public void startGeographyBuild(Vector<Beam> beams, Vector<Strip> strips) 68 69 { 69 if (beamsGeography.size() < beams.size())70 beamsGeography.setSize(beams.size());71 72 double offset = 0;73 for (int i = 0; i < beams.size(); ++i)74 {75 if (beamsGeography.elementAt(i) == null)76 beamsGeography.setElementAt(new BeamGeography(dataSet, this), i);77 beamsGeography.elementAt(i).adjustNodes(new LatLon(center.lat(), addMetersToLon(center, offset)),78 beams.elementAt(i).getBeamParts(), beams.elementAt(i).getBeamOffset());79 80 if (i < strips.size())81 offset += strips.elementAt(i).width;82 }83 84 nodePoolCount = 0;85 wayPoolCount = 0;86 87 members = new Vector<RelationMember>();88 if (multipolygon != null)89 multipolygon.setMembers(members);90 } 91 92 70 if (beamsGeography.size() < beams.size()) 71 beamsGeography.setSize(beams.size()); 72 73 double offset = 0; 74 for (int i = 0; i < beams.size(); ++i) 75 { 76 if (beamsGeography.elementAt(i) == null) 77 beamsGeography.setElementAt(new BeamGeography(dataSet, this), i); 78 beamsGeography.elementAt(i).adjustNodes(new LatLon(center.lat(), addMetersToLon(center, offset)), 79 beams.elementAt(i).getBeamParts(), beams.elementAt(i).getBeamOffset()); 80 81 if (i < strips.size()) 82 offset += strips.elementAt(i).width; 83 } 84 85 nodePoolCount = 0; 86 wayPoolCount = 0; 87 88 members = new Vector<>(); 89 if (multipolygon != null) 90 multipolygon.setMembers(members); 91 } 92 93 93 94 public void startWay() 94 95 { 95 nodes = new Vector<Node>();96 } 97 98 96 nodes = new Vector<>(); 97 } 98 99 99 100 public void finishWay(Strip strip, int partIndex, boolean isOuter, String level) 100 101 { 101 if (nodes.size() > 0)102 {103 CorridorPart part = strip.partAt(partIndex);104 strip.geographyAt(partIndex).appendNodes(part.getType(), part.getSide(), level,105 nodes.elementAt(nodes.size()-1).getCoor(), nodes.elementAt(0).getCoor(), this);106 nodes.add(nodes.elementAt(0));107 }108 assignNds(nodes);109 members.add(new RelationMember(isOuter ? "outer" : "inner", wayPool.elementAt(wayPoolCount)));110 ++wayPoolCount;111 } 112 113 102 if (nodes.size() > 0) 103 { 104 CorridorPart part = strip.partAt(partIndex); 105 strip.geographyAt(partIndex).appendNodes(part.getType(), part.getSide(), level, 106 nodes.elementAt(nodes.size()-1).getCoor(), nodes.elementAt(0).getCoor(), this); 107 nodes.add(nodes.elementAt(0)); 108 } 109 assignNds(nodes); 110 members.add(new RelationMember(isOuter ? "outer" : "inner", wayPool.elementAt(wayPoolCount))); 111 ++wayPoolCount; 112 } 113 114 114 115 public void appendCorridorPart(CorridorPart part, CorridorGeography partGeography, int beamIndex, int partIndex, 115 String level)116 { 117 if (nodes.size() > 0)118 partGeography.appendNodes(part.getType(), part.getSide(), level,119 nodes.elementAt(nodes.size()-1).getCoor(),120 beamsGeography.elementAt(beamIndex).coorAt(partIndex), this);121 } 122 123 116 String level) 117 { 118 if (nodes.size() > 0) 119 partGeography.appendNodes(part.getType(), part.getSide(), level, 120 nodes.elementAt(nodes.size()-1).getCoor(), 121 beamsGeography.elementAt(beamIndex).coorAt(partIndex), this); 122 } 123 124 124 125 public void appendUturnNode(Strip strip, int partIndex, int stripIndex, int beamNodeIndex, boolean toTheLeft, 125 String level)126 { 127 if (toTheLeft)128 assignCoor(addMeterOffset(beamsGeography.elementAt(stripIndex + 1).coorAt(beamNodeIndex),129 0, -strip.width / 2.));130 else131 assignCoor(addMeterOffset(beamsGeography.elementAt(stripIndex).coorAt(beamNodeIndex),132 0, strip.width / 2.));133 134 if (nodes.size() > 0)135 {136 CorridorPart part = strip.partAt(partIndex);137 strip.geographyAt(partIndex).appendNodes(part.getType(), part.getSide(), level,138 nodes.elementAt(nodes.size()-1).getCoor(), nodePool.elementAt(nodePoolCount).getCoor(), this);139 }140 nodes.add(nodePool.elementAt(nodePoolCount));141 ++nodePoolCount;142 } 143 144 126 String level) 127 { 128 if (toTheLeft) 129 assignCoor(addMeterOffset(beamsGeography.elementAt(stripIndex + 1).coorAt(beamNodeIndex), 130 0, -strip.width / 2.)); 131 else 132 assignCoor(addMeterOffset(beamsGeography.elementAt(stripIndex).coorAt(beamNodeIndex), 133 0, strip.width / 2.)); 134 135 if (nodes.size() > 0) 136 { 137 CorridorPart part = strip.partAt(partIndex); 138 strip.geographyAt(partIndex).appendNodes(part.getType(), part.getSide(), level, 139 nodes.elementAt(nodes.size()-1).getCoor(), nodePool.elementAt(nodePoolCount).getCoor(), this); 140 } 141 nodes.add(nodePool.elementAt(nodePoolCount)); 142 ++nodePoolCount; 143 } 144 145 145 146 public void finishGeographyBuild(IndoorSweeplineModel.Type type, String level) 146 147 { 147 for (int i = nodePoolCount; i < nodePool.size(); ++i)148 nodePool.elementAt(i).setDeleted(true);149 nodePool.setSize(nodePoolCount);150 151 for (int i = wayPoolCount; i < wayPool.size(); ++i)152 wayPool.elementAt(i).setDeleted(true);153 wayPool.setSize(wayPoolCount);154 155 adjustMultipolygonRelation(type, level);156 } 157 158 148 for (int i = nodePoolCount; i < nodePool.size(); ++i) 149 nodePool.elementAt(i).setDeleted(true); 150 nodePool.setSize(nodePoolCount); 151 152 for (int i = wayPoolCount; i < wayPool.size(); ++i) 153 wayPool.elementAt(i).setDeleted(true); 154 wayPool.setSize(wayPoolCount); 155 156 adjustMultipolygonRelation(type, level); 157 } 158 159 159 160 private static LatLon addMeterOffset(LatLon latLon, double south, double east) 160 161 { 161 double scale = Math.cos(latLon.lat() * (Math.PI/180.));162 return new LatLon(latLon.lat() - south *(360./4e7), latLon.lon() + east / scale *(360./4e7));163 } 164 165 162 double scale = Math.cos(latLon.lat() * (Math.PI/180.)); 163 return new LatLon(latLon.lat() - south *(360./4e7), latLon.lon() + east / scale *(360./4e7)); 164 } 165 166 166 167 private static double addMetersToLon(LatLon latLon, double east) 167 168 { 168 double scale = Math.cos(latLon.lat() * (Math.PI/180.));169 return latLon.lon() + east / scale *(360./4e7);170 } 171 172 169 double scale = Math.cos(latLon.lat() * (Math.PI/180.)); 170 return latLon.lon() + east / scale *(360./4e7); 171 } 172 173 173 174 private void assignCoor(LatLon latLon) 174 175 { 175 if (nodePoolCount < nodePool.size())176 nodePool.elementAt(nodePoolCount).setCoor(latLon);177 else178 {179 Node node = new Node(latLon);180 dataSet.addPrimitive(node);181 nodePool.add(node);182 }183 } 184 185 176 if (nodePoolCount < nodePool.size()) 177 nodePool.elementAt(nodePoolCount).setCoor(latLon); 178 else 179 { 180 Node node = new Node(latLon); 181 dataSet.addPrimitive(node); 182 nodePool.add(node); 183 } 184 } 185 186 186 187 private void assignNds(List<Node> nodes) 187 188 { 188 if (wayPoolCount < wayPool.size())189 wayPool.elementAt(wayPoolCount).setNodes(nodes);190 else191 {192 Way way = new Way();193 way.setNodes(nodes);194 dataSet.addPrimitive(way);195 wayPool.add(way);196 }197 } 198 199 189 if (wayPoolCount < wayPool.size()) 190 wayPool.elementAt(wayPoolCount).setNodes(nodes); 191 else 192 { 193 Way way = new Way(); 194 way.setNodes(nodes); 195 dataSet.addPrimitive(way); 196 wayPool.add(way); 197 } 198 } 199 200 200 201 private static void addPolygonTags(IndoorSweeplineModel.Type type, String level, OsmPrimitive obj) 201 202 { 202 if (type == IndoorSweeplineModel.Type.PLATFORM)203 {204 obj.put("railway", "platform");205 obj.put("public_transport", "platform");206 obj.put("area", "yes");207 obj.put("level", level);208 }209 else210 {211 obj.put("highway", "pedestrian");212 obj.put("indoor", "corridor");213 obj.put("area", "yes");214 obj.put("level", level);215 }216 } 217 218 203 if (type == IndoorSweeplineModel.Type.PLATFORM) 204 { 205 obj.put("railway", "platform"); 206 obj.put("public_transport", "platform"); 207 obj.put("area", "yes"); 208 obj.put("level", level); 209 } 210 else 211 { 212 obj.put("highway", "pedestrian"); 213 obj.put("indoor", "corridor"); 214 obj.put("area", "yes"); 215 obj.put("level", level); 216 } 217 } 218 219 219 220 private void adjustMultipolygonRelation(IndoorSweeplineModel.Type type, String level) 220 221 { 221 if (members.size() > 1)222 {223 if (wayPool.size() > 0)224 wayPool.elementAt(0).removeAll();225 226 if (multipolygon == null)227 {228 multipolygon = new Relation();229 dataSet.addPrimitive(multipolygon);230 }231 232 multipolygon.removeAll();233 multipolygon.put("type", "multipolygon");234 addPolygonTags(type, level, multipolygon);235 236 multipolygon.setMembers(members);237 }238 else239 {240 if (multipolygon != null)241 {242 multipolygon.setDeleted(true);243 multipolygon = null;244 }245 246 if (wayPool.size() == 1)247 {248 wayPool.elementAt(0).removeAll();249 addPolygonTags(type, level, wayPool.elementAt(0));250 }251 }222 if (members.size() > 1) 223 { 224 if (wayPool.size() > 0) 225 wayPool.elementAt(0).removeAll(); 226 227 if (multipolygon == null) 228 { 229 multipolygon = new Relation(); 230 dataSet.addPrimitive(multipolygon); 231 } 232 233 multipolygon.removeAll(); 234 multipolygon.put("type", "multipolygon"); 235 addPolygonTags(type, level, multipolygon); 236 237 multipolygon.setMembers(members); 238 } 239 else 240 { 241 if (multipolygon != null) 242 { 243 multipolygon.setDeleted(true); 244 multipolygon = null; 245 } 246 247 if (wayPool.size() == 1) 248 { 249 wayPool.elementAt(0).removeAll(); 250 addPolygonTags(type, level, wayPool.elementAt(0)); 251 } 252 } 252 253 } 253 254 } -
applications/editors/josm/plugins/indoor_sweepline/src/indoor_sweepline/Strip.java
r32103 r32479 3 3 4 4 import java.util.Vector; 5 5 6 import org.openstreetmap.josm.data.osm.DataSet; 6 7 … … 10 11 public Strip(DataSet dataSet) 11 12 { 12 width = 10.;13 parts = new Vector<CorridorPart>();14 partsGeography = new Vector<CorridorGeography>();15 lhs = new Vector<Double>();16 rhs = new Vector<Double>();17 18 this.dataSet = dataSet;13 width = 10.; 14 parts = new Vector<>(); 15 partsGeography = new Vector<>(); 16 lhs = new Vector<>(); 17 rhs = new Vector<>(); 18 19 this.dataSet = dataSet; 19 20 } 20 21 21 22 22 23 public void setCorridorPartType(int partIndex, CorridorPart.Type type) 23 24 { 24 while (parts.size() <= partIndex)25 {26 parts.add(new CorridorPart(0., CorridorPart.Type.WALL,27 parts.size() % 2 == 0 ? CorridorPart.ReachableSide.FRONT :28 CorridorPart.ReachableSide.BACK));29 partsGeography.add(new CorridorGeography(dataSet));30 }31 parts.elementAt(partIndex).setType(type, CorridorPart.ReachableSide.ALL);25 while (parts.size() <= partIndex) 26 { 27 parts.add(new CorridorPart(0., CorridorPart.Type.WALL, 28 parts.size() % 2 == 0 ? CorridorPart.ReachableSide.FRONT : 29 CorridorPart.ReachableSide.BACK)); 30 partsGeography.add(new CorridorGeography(dataSet)); 31 } 32 parts.elementAt(partIndex).setType(type, CorridorPart.ReachableSide.ALL); 32 33 } 33 34 34 35 35 36 public CorridorPart partAt(int i) 36 37 { 37 while (parts.size() <= i)38 {39 parts.add(new CorridorPart(0., CorridorPart.Type.WALL,40 parts.size() % 2 == 0 ? CorridorPart.ReachableSide.FRONT :41 CorridorPart.ReachableSide.BACK));42 partsGeography.add(new CorridorGeography(dataSet));43 }44 return parts.elementAt(i);38 while (parts.size() <= i) 39 { 40 parts.add(new CorridorPart(0., CorridorPart.Type.WALL, 41 parts.size() % 2 == 0 ? CorridorPart.ReachableSide.FRONT : 42 CorridorPart.ReachableSide.BACK)); 43 partsGeography.add(new CorridorGeography(dataSet)); 44 } 45 return parts.elementAt(i); 45 46 } 46 47 47 48 48 49 public CorridorGeography geographyAt(int i) 49 50 { 50 while (parts.size() <= i)51 {52 parts.add(new CorridorPart(0., CorridorPart.Type.WALL,53 parts.size() % 2 == 0 ? CorridorPart.ReachableSide.FRONT :54 CorridorPart.ReachableSide.BACK));55 partsGeography.add(new CorridorGeography(dataSet));56 }57 return partsGeography.elementAt(i);51 while (parts.size() <= i) 52 { 53 parts.add(new CorridorPart(0., CorridorPart.Type.WALL, 54 parts.size() % 2 == 0 ? CorridorPart.ReachableSide.FRONT : 55 CorridorPart.ReachableSide.BACK)); 56 partsGeography.add(new CorridorGeography(dataSet)); 57 } 58 return partsGeography.elementAt(i); 58 59 } 59 60 60 61 61 62 public double width; 62 63 public Vector<CorridorPart> parts; … … 64 65 public Vector<Double> lhs; 65 66 public Vector<Double> rhs; 66 67 67 68 private DataSet dataSet; 68 69 }
Note:
See TracChangeset
for help on using the changeset viewer.
