Commit eb78c5ff authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "TikzGenerator.java", added method "generateTikzDrawSettings()" to define...

In "TikzGenerator.java", added method "generateTikzDrawSettings()" to define TeX variables to quickly adapt TikZ figure.
parent 4138f774
Pipeline #87602 failed with stages
in 100 minutes and 12 seconds
......@@ -69,12 +69,14 @@ public class TikzGenerator {
public void generateTikz(final File file) {
String tikzCodeColorDefinitions = generateTikzColorDefinitions(model);
String tikzCodeDrawSettings = generateTikzDrawSettings(model);
String tikzCodeScenarioElements = convertScenarioElementsToTikz();
String tikzOutput = "" +
"\\documentclass{standalone}\n" +
"\\usepackage{tikz}\n\n" +
tikzCodeColorDefinitions +
tikzCodeDrawSettings +
"\\begin{document}\n" +
"% Change scaling to [x=1mm,y=1mm] if TeX reports \"Dimension too large\".\n" +
"\\begin{tikzpicture}[x=1cm,y=1cm]\n" +
......@@ -120,7 +122,23 @@ public class TikzGenerator {
return colorDefinitions;
}
private String convertScenarioElementsToTikz() {
private String generateTikzDrawSettings(SimulationModel<? extends DefaultSimulationConfig> model) {
// Generate TeX variables for common draw settings like agent radius and
// use them later on when generating TikZ code. These settins can be used
// by TikZ users to adapt the drawing quickly.
String drawSettings = "% Draw Settings\n";
double agentRadius = model.getConfig().getPedestrianTorso() / 2.0;
drawSettings += String.format(Locale.US,"\\newcommand{\\AgentRadius}{%f}\n", agentRadius);
drawSettings += String.format(Locale.US,"\\newcommand{\\LineWidth}{%d}\n", 1);
drawSettings += "\n";
return drawSettings;
}
private String convertScenarioElementsToTikz() {
String generatedCode = "";
DefaultSimulationConfig config = model.getConfig();
......@@ -273,8 +291,8 @@ public class TikzGenerator {
cce.printStackTrace();
// Fall back to default rendering of agents.
String agentTextPattern = "\\fill[AgentColor] (%f,%f) circle [radius=%f];\n";
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
String agentTextPattern = "\\fill[AgentColor] (%f,%f) circle [radius=\\AgentRadius];\n";
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y);
}
} else {
Pedestrian pedestrian = (Pedestrian) agent;
......@@ -282,13 +300,13 @@ public class TikzGenerator {
String colorString = String.format(Locale.US, "{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
// Do not draw agents as path for performance reasons. Usually, agents have a circular shape.
// generatedCode += String.format(Locale.US, "\\fill[AgentColor] %s\n", generatePathForScenarioElement(agent));
String agentTextPattern = "\\fill[fill=%s] (%f,%f) circle [radius=%f];\n";
generatedCode += String.format(Locale.US, agentTextPattern, colorString, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
String agentTextPattern = "\\fill[fill=%s] (%f,%f) circle [radius=\\AgentRadius];\n";
generatedCode += String.format(Locale.US, agentTextPattern, colorString, agent.getPosition().x, agent.getPosition().y);
}
if (model.isElementSelected() && model.getSelectedElement().equals(agent)) {
String agentTextPattern = "\\draw[magenta] (%f,%f) circle [radius=%f];\n";
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
String agentTextPattern = "\\draw[magenta] (%f,%f) circle [radius=\\AgentRadius];\n";
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y);
}
}
}
......
Supports Markdown
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