Changeset 11914 in josm for trunk/src/org/openstreetmap/josm/data/osm
- Timestamp:
- 2017-04-15T02:00:43+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r11893 r11914 35 35 import java.util.Optional; 36 36 import java.util.concurrent.ForkJoinPool; 37 import java.util.concurrent.ForkJoinTask;38 import java.util.concurrent.RecursiveTask;39 37 import java.util.function.BiConsumer; 40 38 import java.util.function.Consumer; … … 48 46 import org.openstreetmap.josm.data.coor.EastNorth; 49 47 import org.openstreetmap.josm.data.osm.BBox; 50 import org.openstreetmap.josm.data.osm.Changeset;51 48 import org.openstreetmap.josm.data.osm.DataSet; 52 49 import org.openstreetmap.josm.data.osm.Node; … … 57 54 import org.openstreetmap.josm.data.osm.Way; 58 55 import org.openstreetmap.josm.data.osm.WaySegment; 59 import org.openstreetmap.josm.data.osm.visitor.Visitor;60 56 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 61 57 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData; … … 69 65 import org.openstreetmap.josm.gui.draw.MapViewPath; 70 66 import org.openstreetmap.josm.gui.draw.MapViewPositionAndRotation; 71 import org.openstreetmap.josm.gui.mappaint.ElemStyles;72 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;73 import org.openstreetmap.josm.gui.mappaint.StyleElementList;74 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;75 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement;76 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaIconElement;77 67 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement; 78 68 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.HorizontalTextAlignment; … … 83 73 import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement; 84 74 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol; 85 import org.openstreetmap.josm.gui.mappaint.styleelement.TextElement;86 75 import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel; 87 76 import org.openstreetmap.josm.gui.mappaint.styleelement.placement.PositionForAreaStrategy; … … 247 236 * Not used in any public interfaces. 248 237 */ 249 privatestatic final int FLAG_NORMAL = 0;238 static final int FLAG_NORMAL = 0; 250 239 /** 251 240 * A primitive with {@link OsmPrimitive#isDisabled()} 252 241 */ 253 privatestatic final int FLAG_DISABLED = 1;242 static final int FLAG_DISABLED = 1; 254 243 /** 255 244 * A primitive with {@link OsmPrimitive#isMemberOfSelected()} 256 245 */ 257 privatestatic final int FLAG_MEMBER_OF_SELECTED = 2;246 static final int FLAG_MEMBER_OF_SELECTED = 2; 258 247 /** 259 248 * A primitive with {@link OsmPrimitive#isSelected()} 260 249 */ 261 privatestatic final int FLAG_SELECTED = 4;250 static final int FLAG_SELECTED = 4; 262 251 /** 263 252 * A primitive with {@link OsmPrimitive#isOuterMemberOfSelected()} 264 253 */ 265 privatestatic final int FLAG_OUTERMEMBER_OF_SELECTED = 8;254 static final int FLAG_OUTERMEMBER_OF_SELECTED = 8; 266 255 267 256 private static final double PHI = Math.toRadians(20); … … 1495 1484 } 1496 1485 1497 private static class ComputeStyleListWorker extends RecursiveTask<List<StyleRecord>> implements Visitor {1498 private final transient List<? extends OsmPrimitive> input;1499 private final transient List<StyleRecord> output;1500 1501 private final transient ElemStyles styles = MapPaintStyles.getStyles();1502 private final int directExecutionTaskSize;1503 private final double circum;1504 private final NavigatableComponent nc;1505 1506 private final boolean drawArea;1507 private final boolean drawMultipolygon;1508 private final boolean drawRestriction;1509 1510 /**1511 * Constructs a new {@code ComputeStyleListWorker}.1512 * @param circum distance on the map in meters that 100 screen pixels represent1513 * @param nc navigatable component1514 * @param input the primitives to process1515 * @param output the list of styles to which styles will be added1516 * @param directExecutionTaskSize the threshold deciding whether to subdivide the tasks1517 */1518 ComputeStyleListWorker(double circum, NavigatableComponent nc,1519 final List<? extends OsmPrimitive> input, List<StyleRecord> output, int directExecutionTaskSize) {1520 this.circum = circum;1521 this.nc = nc;1522 this.input = input;1523 this.output = output;1524 this.directExecutionTaskSize = directExecutionTaskSize;1525 this.drawArea = circum <= Main.pref.getInteger("mappaint.fillareas", 10_000_000);1526 this.drawMultipolygon = drawArea && Main.pref.getBoolean("mappaint.multipolygon", true);1527 this.drawRestriction = Main.pref.getBoolean("mappaint.restriction", true);1528 this.styles.setDrawMultipolygon(drawMultipolygon);1529 }1530 1531 @Override1532 protected List<StyleRecord> compute() {1533 if (input.size() <= directExecutionTaskSize) {1534 return computeDirectly();1535 } else {1536 final Collection<ForkJoinTask<List<StyleRecord>>> tasks = new ArrayList<>();1537 for (int fromIndex = 0; fromIndex < input.size(); fromIndex += directExecutionTaskSize) {1538 final int toIndex = Math.min(fromIndex + directExecutionTaskSize, input.size());1539 final List<StyleRecord> output = new ArrayList<>(directExecutionTaskSize);1540 tasks.add(new ComputeStyleListWorker(circum, nc, input.subList(fromIndex, toIndex), output, directExecutionTaskSize).fork());1541 }1542 for (ForkJoinTask<List<StyleRecord>> task : tasks) {1543 output.addAll(task.join());1544 }1545 return output;1546 }1547 }1548 1549 public List<StyleRecord> computeDirectly() {1550 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();1551 try {1552 for (final OsmPrimitive osm : input) {1553 acceptDrawable(osm);1554 }1555 return output;1556 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {1557 throw BugReport.intercept(e).put("input-size", input.size()).put("output-size", output.size());1558 } finally {1559 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().unlock();1560 }1561 }1562 1563 private void acceptDrawable(final OsmPrimitive osm) {1564 try {1565 if (osm.isDrawable()) {1566 osm.accept(this);1567 }1568 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {1569 throw BugReport.intercept(e).put("osm", osm);1570 }1571 }1572 1573 @Override1574 public void visit(Node n) {1575 add(n, computeFlags(n, false));1576 }1577 1578 @Override1579 public void visit(Way w) {1580 add(w, computeFlags(w, true));1581 }1582 1583 @Override1584 public void visit(Relation r) {1585 add(r, computeFlags(r, true));1586 }1587 1588 @Override1589 public void visit(Changeset cs) {1590 throw new UnsupportedOperationException();1591 }1592 1593 public void add(Node osm, int flags) {1594 StyleElementList sl = styles.get(osm, circum, nc);1595 for (StyleElement s : sl) {1596 output.add(new StyleRecord(s, osm, flags));1597 }1598 }1599 1600 public void add(Relation osm, int flags) {1601 StyleElementList sl = styles.get(osm, circum, nc);1602 for (StyleElement s : sl) {1603 if (drawMultipolygon && drawArea && (s instanceof AreaElement || s instanceof AreaIconElement) && (flags & FLAG_DISABLED) == 0) {1604 output.add(new StyleRecord(s, osm, flags));1605 } else if (drawMultipolygon && drawArea && s instanceof TextElement) {1606 output.add(new StyleRecord(s, osm, flags));1607 } else if (drawRestriction && s instanceof NodeElement) {1608 output.add(new StyleRecord(s, osm, flags));1609 }1610 }1611 }1612 1613 public void add(Way osm, int flags) {1614 StyleElementList sl = styles.get(osm, circum, nc);1615 for (StyleElement s : sl) {1616 if ((drawArea && (flags & FLAG_DISABLED) == 0) || !(s instanceof AreaElement)) {1617 output.add(new StyleRecord(s, osm, flags));1618 }1619 }1620 }1621 }1622 1623 1486 /** 1624 1487 * Sets the factory that creates the benchmark data receivers.
Note:
See TracChangeset
for help on using the changeset viewer.