Commit a5855370 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add tread lines to TopographyCreatorRenderer and refactor to use same code as simulation rendering

parent 24cdffeb
......@@ -129,40 +129,51 @@ public abstract class DefaultRenderer {
protected void renderStairs(final Iterable<Stairs> stairs, final Graphics2D g,
final Color color){
final Color tmpColor = g.getColor();
for (Stairs s : stairs) {
g.setColor(Color.black);
g.fill(s.getShape());
Area hatchArea = new Area(s.getShape());
double stroke = s.getTreadDepth() * 0.05;
double halfTreadDepth = s.getTreadDepth()/2;
for (Stairs.Tread tread : s.getTreads()) {
VLine tLine = tread.treadline;
Vector2D vec = tLine.asVector();
vec = vec.normalize(stroke);
vec = vec.rotate(rotNeg90);
Vector2D trans = vec.normalize(halfTreadDepth);
Path2D p = new Path2D.Double();
p.moveTo(tLine.x1, tLine.y1);
p.lineTo(tLine.x2, tLine.y2);
p.lineTo(tLine.x2 + vec.x, tLine.y2 + vec.y);
p.lineTo(tLine.x1 + vec.x, tLine.y1 + vec.y);
p.closePath();
p.transform(AffineTransform.getTranslateInstance(trans.x, trans.y));
hatchArea.subtract(new Area(p));
}
renderStair(s, g, color);
}
}
g.setColor(color);
g.fill(hatchArea);
protected void renderStair(ScenarioElement element, final Graphics2D graphics, Color color){
Stairs stairs = (Stairs) element;
final Color tmpColor = graphics.getColor();
graphics.setColor(Color.black);
graphics.fill(stairs.getShape());
Area hatchArea = new Area(stairs.getShape());
double stroke = stairs.getTreadDepth() * 0.05;
double halfTreadDepth = stairs.getTreadDepth()/2;
for (Stairs.Tread tread : stairs.getTreads()) {
VLine tLine = tread.treadline;
Vector2D vec = tLine.asVector();
vec = vec.normalize(stroke);
vec = vec.rotate(rotNeg90);
Vector2D trans = vec.normalize(halfTreadDepth);
Path2D p = new Path2D.Double();
p.moveTo(tLine.x1, tLine.y1);
p.lineTo(tLine.x2, tLine.y2);
p.lineTo(tLine.x2 + vec.x, tLine.y2 + vec.y);
p.lineTo(tLine.x1 + vec.x, tLine.y1 + vec.y);
p.closePath();
p.transform(AffineTransform.getTranslateInstance(trans.x, trans.y));
hatchArea.subtract(new Area(p));
}
g.setColor(tmpColor);
graphics.setColor(color);
graphics.fill(hatchArea);
graphics.setColor(tmpColor);
}
protected void renderFilledShape(ScenarioElement element, final Graphics2D graphics, Color color){
final Color tmpColor = graphics.getColor();
graphics.setColor(color);
graphics.fill(element.getShape());
graphics.setColor(tmpColor);
}
protected void renderSelectionShape(final Graphics2D graphics) {
graphics.setColor(defaultModel.getMouseSelectionMode().getSelectionColor());
......
......@@ -5,6 +5,7 @@ import org.apache.log4j.Logger;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.util.geometry.shapes.VShape;
import java.awt.*;
......@@ -28,19 +29,20 @@ public class AgentRender implements Renderer {
}
@Override
public void render(Agent a, Graphics2D g) {
public void render(final ScenarioElement element, Graphics2D g) {
if (model.config.isShowGroups()) {
try {
Pedestrian ped = (Pedestrian) a;
Pedestrian ped = (Pedestrian) element;
renderGroup(ped, g);
} catch (ClassCastException cce) {
logger.error("Error casting to Pedestrian");
cce.printStackTrace();
model.config.setShowGroups(false);
renderDefault(a, g, defaultColor);
renderDefault(element, g, defaultColor);
}
} else {
renderDefault(a, g, defaultColor);
renderDefault(element, g, defaultColor);
}
}
......@@ -49,9 +51,9 @@ public class AgentRender implements Renderer {
g.fill(getShape(ped));
}
private void renderDefault(Agent a, Graphics2D g, Color c) {
private void renderDefault(final ScenarioElement element, Graphics2D g, Color c) {
g.setColor(c);
g.fill(a.getShape());
g.fill(element.getShape());
}
private Color getHSBColor(int groupId) {
......
package org.vadere.gui.renderer.agent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.ScenarioElement;
import java.awt.*;
public interface Renderer {
void render(final Agent a, final Graphics2D g);
void render(final ScenarioElement element, final Graphics2D g);
}
package org.vadere.gui.topographycreator.view;
import org.vadere.state.scenario.ScenarioElement;
import java.awt.*;
@FunctionalInterface
public interface ScenarioElementRenderer {
void render(ScenarioElement element, final Graphics2D graphics, Color color);
}
package org.vadere.gui.topographycreator.view;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Line2D;
import org.vadere.gui.components.model.DefaultConfig;
import org.vadere.gui.components.view.DefaultRenderer;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.util.geometry.shapes.VPoint;
public class TopographyCreatorRenderer extends DefaultRenderer {
import java.awt.*;
import java.awt.geom.Line2D;
public class TopographyCreatorRenderer extends DefaultRenderer{
private final IDrawPanelModel<DefaultConfig> panelModel;
......@@ -25,15 +22,24 @@ public class TopographyCreatorRenderer extends DefaultRenderer {
private final static long REPAINT_SLEEP_TIME = 25; // 25 => 40 FPS
private int boundId = -1;
private ScenarioElementRenderer[] renderers;
/**
* Creates a new DrawPanel and start the repaint thead.
*
* @param panelModel the panelModel of the panel
*/
public TopographyCreatorRenderer(final IDrawPanelModel panelModel) {
public TopographyCreatorRenderer(final IDrawPanelModel panelModel){
super(panelModel);
this.panelModel = panelModel;
this.renderers = new ScenarioElementRenderer[ScenarioElementType.values().length];
renderers[ScenarioElementType.OBSTACLE.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.PEDESTRIAN.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.SOURCE.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.TARGET.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.STAIRS.ordinal()] = this::renderStair;
renderers[ScenarioElementType.TELEPORTER.ordinal()] = this::renderFilledShape;
renderers[ScenarioElementType.CAR.ordinal()] = this::renderFilledShape;
}
@Override
......@@ -48,8 +54,8 @@ public class TopographyCreatorRenderer extends DefaultRenderer {
}
for (ScenarioElement element : panelModel) {
graphics.setColor(panelModel.getScenarioElementColor(element.getType()));
graphics.fill(element.getShape());
Color color = panelModel.getScenarioElementColor(element.getType());
renderers[element.getType().ordinal()].render(element, graphics, color);
}
if (panelModel.isPrototypeVisble()) {
......@@ -84,10 +90,6 @@ public class TopographyCreatorRenderer extends DefaultRenderer {
+ resolution * 0.2));
}
/**
* Draws a grid with the given resolution and line width to graphics.
* Recalculate the grid only if needed. Otherwise use the old image. This improves performance!
*/
/*
* private void paintGrid(Graphics2D graphics, double width, double height, double resolution,
* float lineWidth) {
......
......@@ -77,7 +77,7 @@
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : 1,
"simulationSeed" : 0
"simulationSeed" : 1
},
"topography" : {
"attributes" : {
......
......@@ -77,7 +77,7 @@
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : 1,
"simulationSeed" : 0
"simulationSeed" : 1
},
"topography" : {
"attributes" : {
......
......@@ -77,7 +77,7 @@
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : 1,
"simulationSeed" : 0
"simulationSeed" : 1
},
"topography" : {
"attributes" : {
......
......@@ -77,7 +77,7 @@
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : 1,
"simulationSeed" : 0
"simulationSeed" : 1
},
"topography" : {
"attributes" : {
......
......@@ -77,7 +77,7 @@
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : 1,
"simulationSeed" : 0
"simulationSeed" : 1
},
"topography" : {
"attributes" : {
......
......@@ -77,7 +77,7 @@
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : 1,
"simulationSeed" : 0
"simulationSeed" : 1
},
"topography" : {
"attributes" : {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment