Commit 61ede76d authored by Daniel Lehmberg's avatar Daniel Lehmberg
Browse files

Merge branch 'master' into change_dataprocessing_text

parents 040b55db fbaa84dc
Pipeline #85964 passed with stages
in 101 minutes and 3 seconds
...@@ -50,8 +50,7 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang ...@@ -50,8 +50,7 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
outputFile = fileChooser.getSelectedFile().toString().endsWith(".tex") ? fileChooser.getSelectedFile() outputFile = fileChooser.getSelectedFile().toString().endsWith(".tex") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".tex"); : new File(fileChooser.getSelectedFile().toString() + ".tex");
boolean completeDocument = true; tikzGenerator.generateTikz(outputFile);
tikzGenerator.generateTikz(outputFile, completeDocument);
} }
} }
......
...@@ -67,27 +67,26 @@ public class TikzGenerator { ...@@ -67,27 +67,26 @@ public class TikzGenerator {
translationTable[SEG_CLOSE] = ""; translationTable[SEG_CLOSE] = "";
} }
public void generateTikz(final File file, final boolean generateCompleteDocument) { public void generateTikz(final File file) {
String texTemplate = "" + String tikzCodeColorDefinitions = generateTikzColorDefinitions(model);
String tikzCodeScenarioElements = convertScenarioElementsToTikz();
String tikzOutput = "" +
"\\documentclass{standalone}\n" + "\\documentclass{standalone}\n" +
"\\usepackage{tikz}\n\n" + "\\usepackage{tikz}\n\n" +
tikzCodeColorDefinitions +
"\\begin{document}\n" + "\\begin{document}\n" +
"\\begin{tikzpicture}\n" + "% Change scaling to [x=1mm,y=1mm] if TeX reports \"Dimension too large\".\n" +
"%s" + "\\begin{tikzpicture}[x=1cm,y=1cm]\n" +
tikzCodeScenarioElements +
"\\end{tikzpicture}\n" + "\\end{tikzpicture}\n" +
"\\end{document}\n"; "\\end{document}\n";
String tikzCode = "";
tikzCode += generateTikzColorDefinitions(model);
tikzCode += convertScenarioElementsToTikz();
String output = (generateCompleteDocument) ? String.format(Locale.US, texTemplate, tikzCode) : tikzCode;
// TODO: maybe uses Java's resources notation (in general, writing the file should be done by the caller not here). // TODO: maybe uses Java's resources notation (in general, writing the file should be done by the caller not here).
try { try {
file.createNewFile(); file.createNewFile();
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
out.write(output); out.write(tikzOutput);
out.flush(); out.flush();
logger.info("generate new TikZ: " + file.getAbsolutePath()); logger.info("generate new TikZ: " + file.getAbsolutePath());
} catch (IOException e1) { } catch (IOException e1) {
...@@ -116,6 +115,8 @@ public class TikzGenerator { ...@@ -116,6 +115,8 @@ public class TikzGenerator {
Color agentColor = model.getConfig().getPedestrianDefaultColor(); Color agentColor = model.getConfig().getPedestrianDefaultColor();
colorDefinitions += String.format(Locale.US, colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue()); colorDefinitions += String.format(Locale.US, colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue());
colorDefinitions += "\n";
return colorDefinitions; return colorDefinitions;
} }
...@@ -272,7 +273,7 @@ public class TikzGenerator { ...@@ -272,7 +273,7 @@ public class TikzGenerator {
cce.printStackTrace(); cce.printStackTrace();
// Fall back to default rendering of agents. // Fall back to default rendering of agents.
String agentTextPattern = "\\fill[AgentColor] (%f,%f) circle [radius=%fcm];\n"; String agentTextPattern = "\\fill[AgentColor] (%f,%f) circle [radius=%f];\n";
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius()); generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
} }
} else { } else {
...@@ -281,12 +282,12 @@ public class TikzGenerator { ...@@ -281,12 +282,12 @@ public class TikzGenerator {
String colorString = String.format(Locale.US, "{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue()); 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. // 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)); // generatedCode += String.format(Locale.US, "\\fill[AgentColor] %s\n", generatePathForScenarioElement(agent));
String agentTextPattern = "\\fill[fill=%s] (%f,%f) circle [radius=%fcm];\n"; 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()); generatedCode += String.format(Locale.US, agentTextPattern, colorString, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
} }
if (model.isElementSelected() && model.getSelectedElement().equals(agent)) { if (model.isElementSelected() && model.getSelectedElement().equals(agent)) {
String agentTextPattern = "\\draw[magenta] (%f,%f) circle [radius=%fcm];\n"; String agentTextPattern = "\\draw[magenta] (%f,%f) circle [radius=%f];\n";
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius()); generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
} }
} }
......
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