From d62d776ec8be0115c8434c9a33d5189365aedda6 Mon Sep 17 00:00:00 2001
From: Jeffrey C. Ollie <jeff@ocjtech.us>
Date: Sat, 26 Feb 2011 19:06:43 -0600
Subject: [PATCH] Add some more symbol shapes to MapCSS styles.

---
 .../josm/data/osm/visitor/paint/MapPainter.java    |   89 ++++++++++++++++----
 .../josm/gui/mappaint/NodeElemStyle.java           |   16 ++++-
 2 files changed, 88 insertions(+), 17 deletions(-)

diff --git a/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java b/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
index ff370d4..8e4db4a 100644
--- a/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
+++ b/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPainter.java
@@ -356,6 +356,21 @@ public class MapPainter {
         }
     }
 
+    private Polygon buildPolygon(Point center, int radius, int sides, double rotation) {
+        Polygon polygon = new Polygon();
+        for (int i = 0; i < sides; i++) {
+            double angle = ((2 * Math.PI / sides) * i) - rotation;
+            int x = (int) Math.round(center.x + radius * Math.cos(angle));
+            int y = (int) Math.round(center.y + radius * Math.sin(angle));
+            polygon.addPoint(x, y);
+        }
+        return polygon;
+    }
+
+    private Polygon buildPolygon(Point center, int radius, int sides) {
+        return buildPolygon(center, radius, sides, 0.0);
+    }
+
     public void drawNodeSymbol(Node n, Symbol s, Color fillColor, Color strokeColor, NodeTextElement text) {
         Point p = nc.getPoint(n);
         if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
@@ -364,28 +379,70 @@ public class MapPainter {
         if (fillColor != null) {
             g.setColor(fillColor);
             switch (s.symbol) {
-                case SQUARE:
-                    g.fillRect(p.x - radius, p.y - radius, s.size, s.size);
-                    break;
-                case CIRCLE:
-                    g.fillOval(p.x - radius, p.y - radius, s.size, s.size);
-                    break;
-                default:
-                    throw new AssertionError();
+            case SQUARE:
+                g.fillRect(p.x - radius, p.y - radius, s.size, s.size);
+                break;
+            case CIRCLE:
+                g.fillOval(p.x - radius, p.y - radius, s.size, s.size);
+                break;
+            case TRIANGLE:
+                g.fillPolygon(buildPolygon(p, radius, 3, Math.PI / 2));
+                break;
+            case PENTAGON:
+                g.fillPolygon(buildPolygon(p, radius, 5, Math.PI / 2));
+                break;
+            case HEXAGON:
+                g.fillPolygon(buildPolygon(p, radius, 6));
+                break;
+            case HEPTAGON:
+                g.fillPolygon(buildPolygon(p, radius, 7, Math.PI / 2));
+                break;
+            case OCTAGON:
+                g.fillPolygon(buildPolygon(p, radius, 8, Math.PI / 8));
+                break;
+            case NONAGON:
+                g.fillPolygon(buildPolygon(p, radius, 9, Math.PI / 2));
+                break;
+            case DECAGON:
+                g.fillPolygon(buildPolygon(p, radius, 10));
+                break;
+            default:
+                throw new AssertionError();
             }
         }
         if (s.stroke != null) {
             g.setStroke(s.stroke);
             g.setColor(strokeColor);
             switch (s.symbol) {
-                case SQUARE:
-                    g.drawRect(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
-                    break;
-                case CIRCLE:
-                    g.drawOval(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
-                    break;
-                default:
-                    throw new AssertionError();
+            case SQUARE:
+                g.drawRect(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
+                break;
+            case CIRCLE:
+                g.drawOval(p.x - radius, p.y - radius, s.size - 1, s.size - 1);
+                break;
+            case TRIANGLE:
+                g.drawPolygon(buildPolygon(p, radius, 3, Math.PI / 2));
+                break;
+            case PENTAGON:
+                g.drawPolygon(buildPolygon(p, radius, 5, Math.PI / 2));
+                break;
+            case HEXAGON:
+                g.drawPolygon(buildPolygon(p, radius, 6));
+                break;
+            case HEPTAGON:
+                g.drawPolygon(buildPolygon(p, radius, 7, Math.PI / 2));
+                break;
+            case OCTAGON:
+                g.drawPolygon(buildPolygon(p, radius, 8, Math.PI / 8));
+                break;
+            case NONAGON:
+                g.drawPolygon(buildPolygon(p, radius, 9, Math.PI / 2));
+                break;
+            case DECAGON:
+                g.drawPolygon(buildPolygon(p, radius, 10));
+                break;
+            default:
+                throw new AssertionError();
             }
             g.setStroke(new BasicStroke());
         }
diff --git a/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java b/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
index 25fcc92..b119e74 100644
--- a/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
+++ b/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
@@ -34,7 +34,7 @@ public class NodeElemStyle extends ElemStyle {
 
     private ImageIcon disabledIcon;
 
-    public enum SymbolShape { SQUARE, CIRCLE }
+    public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON }
     public enum HorizontalTextAlignment { LEFT, CENTER, RIGHT }
     public enum VerticalTextAlignment { ABOVE, TOP, CENTER, BOTTOM, BELOW }
 
@@ -207,6 +207,20 @@ public class NodeElemStyle extends ElemStyle {
             shape = SymbolShape.SQUARE;
         } else if (equal(shapeStr, "circle")) {
             shape = SymbolShape.CIRCLE;
+        } else if (equal(shapeStr, "triangle")) {
+            shape = SymbolShape.TRIANGLE;
+        } else if (equal(shapeStr, "pentagon")) {
+            shape = SymbolShape.PENTAGON;
+        } else if (equal(shapeStr, "hexagon")) {
+            shape = SymbolShape.HEXAGON;
+        } else if (equal(shapeStr, "heptagon")) {
+            shape = SymbolShape.HEPTAGON;
+        } else if (equal(shapeStr, "octagon")) {
+            shape = SymbolShape.OCTAGON;
+        } else if (equal(shapeStr, "nonagon")) {
+            shape = SymbolShape.NONAGON;
+        } else if (equal(shapeStr, "decagon")) {
+            shape = SymbolShape.DECAGON;
         } else
             return null;
         
-- 
1.7.4

