Commit 7afc88e5 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "TikzGenerator.java", allow to export whole topopraphy or current viewport only

Note: "TikzGenerator.java" is used by "ActionGenerateTikz.java".
parent c174a043
Pipeline #247655 passed with stages
in 128 minutes and 43 seconds
......@@ -257,6 +257,8 @@ ProjectView.btnSVGSnapshot.tooltip=SVG Snapshot
ProjectView.btnTikZSnapshot.tooltip=TikZ Snapshot
ProjectView.btnINETSnapshot.tooltip=INET Env
ProjectView.btnPolySnapshot.tooltip=Poly Snapshot
ProjectView.tikZSnapshot.option.exportWholeTopography.text=Click \"Yes\" to export whole topography or \"No\" to export current view only.
ProjectView.tikZSnapshot.option.exportWholeTopography.title=Select option...
PostVis.menuFile.title=File
PostVis.menuSettings.title=Setting
PostVis.menuRecentFiles.title=Recent Files
......
......@@ -253,6 +253,8 @@ ProjectView.btnSVGSnapshot.tooltip=SVG-Snapshot
ProjectView.btnTikZSnapshot.tooltip=TikZ-Snapshot
ProjectView.btnINETSnapshot.tooltip=INET Env
ProjectView.btnPolySnapshot.tooltip=Poly-Snapshot
ProjectView.tikZSnapshot.option.exportWholeTopography.text=Klicke \"Ja\" um die ganze Topographie zu exportieren oder \"Nein\" um den aktuellen Ausschnitt zu exportieren.
ProjectView.tikZSnapshot.option.exportWholeTopography.title=Wähle Exportbereich...
PostVis.menuFile.title=Datei
PostVis.menuSettings.title=Einstellungen
PostVis.menuRecentFiles.title=K\u00FCrzlich verwendete Dateien
......
package org.vadere.gui.components.control.simulation;
import org.apache.commons.configuration2.Configuration;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
......@@ -8,6 +7,7 @@ import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.view.SimulationRenderer;
import org.vadere.gui.onlinevisualization.view.IRendererChangeListener;
import org.vadere.gui.postvisualization.utils.TikzGenerator;
import org.vadere.gui.postvisualization.utils.TikzGenerator.EXPORT_OPTION;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.logging.Logger;
......@@ -34,6 +34,22 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = createFileChooserDialog();
int returnVale = fileChooser.showDialog(null, "Save");
if (returnVale == JFileChooser.APPROVE_OPTION) {
File outputFile = fileChooser.getSelectedFile().toString().endsWith(".tex") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".tex");
EXPORT_OPTION exportOption = askUserAboutExportOptions();
tikzGenerator.generateTikz(outputFile, exportOption);
VadereConfig.getConfig().setProperty("SettingsDialog.snapshotDirectory.path", outputFile.getParentFile().getAbsolutePath());
}
}
private JFileChooser createFileChooserDialog() {
Date todaysDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(CONFIG.getString("SettingsDialog.dataFormat"));
String formattedDate = formatter.format(todaysDate);
......@@ -43,18 +59,29 @@ public class ActionGenerateTikz extends AbstractAction implements IRendererChang
fileChooser.setSelectedFile(outputFile);
int returnVal = fileChooser.showDialog(null, "Save");
return fileChooser;
}
if (returnVal == JFileChooser.APPROVE_OPTION) {
private EXPORT_OPTION askUserAboutExportOptions() {
int input = JOptionPane.showConfirmDialog(null,
Messages.getString("ProjectView.tikZSnapshot.option.exportWholeTopography.text"),
Messages.getString("ProjectView.tikZSnapshot.option.exportWholeTopography.title"),
JOptionPane.YES_NO_OPTION);
outputFile = fileChooser.getSelectedFile().toString().endsWith(".tex") ? fileChooser.getSelectedFile()
: new File(fileChooser.getSelectedFile().toString() + ".tex");
EXPORT_OPTION userSelection;
tikzGenerator.generateTikz(outputFile);
VadereConfig.getConfig().setProperty("SettingsDialog.snapshotDirectory.path", outputFile.getParentFile().getAbsolutePath());
if (input == JOptionPane.YES_OPTION) {
userSelection = EXPORT_OPTION.EXPORT_WHOLE_TOPOGRAPHY;
} else if (input == JOptionPane.NO_OPTION) {
userSelection = EXPORT_OPTION.EXPORT_CURRENT_VIEWPORT;
} else {
throw new IllegalArgumentException("Illegal TikZ export option selected!");
}
return userSelection;
}
@Override
public void update(SimulationRenderer renderer) {
}
......
......@@ -19,30 +19,17 @@ import org.vadere.util.voronoi.Face;
import org.vadere.util.voronoi.HalfEdge;
import org.vadere.util.voronoi.RectangleLimits;
import org.vadere.util.voronoi.VoronoiDiagram;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.PathIterator;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import tech.tablesaw.api.Row;
import tech.tablesaw.api.Table;
import java.awt.geom.Rectangle2D;
import java.io.*;
import java.util.*;
import static java.awt.geom.PathIterator.SEG_CLOSE;
import static java.awt.geom.PathIterator.SEG_CUBICTO;
import static java.awt.geom.PathIterator.SEG_LINETO;
import static java.awt.geom.PathIterator.SEG_MOVETO;
import static java.awt.geom.PathIterator.SEG_QUADTO;
import static java.awt.geom.PathIterator.*;
/**
* Convert the (Java) scenario description into a TikZ representation.
......@@ -65,6 +52,8 @@ import static java.awt.geom.PathIterator.SEG_QUADTO;
*/
public class TikzGenerator {
public enum EXPORT_OPTION { EXPORT_WHOLE_TOPOGRAPHY, EXPORT_CURRENT_VIEWPORT };
private final static Logger logger = Logger.getLogger(TikzGenerator.class);
private final SimulationRenderer renderer;
private final SimulationModel<? extends DefaultSimulationConfig> model;
......@@ -88,9 +77,9 @@ public class TikzGenerator {
translationTable[SEG_CLOSE] = "";
}
public void generateTikz(final File file) {
public void generateTikz(final File file, EXPORT_OPTION exportOption) {
String tikzCodeColorDefinitions = generateTikzColorDefinitions(model);
String tikzCodeScenarioElements = convertScenarioElementsToTikz();
String tikzCodeScenarioElements = convertScenarioElementsToTikz(exportOption);
String tikzOutput = "" +
"\\documentclass{standalone}\n" +
......@@ -172,20 +161,42 @@ public class TikzGenerator {
return tikzStyles;
}
private String convertScenarioElementsToTikz() {
private Rectangle2D getExportBounds(EXPORT_OPTION exportOption, Topography topography) {
Rectangle2D exportBounds = new Rectangle2D.Double();
if (exportOption == EXPORT_OPTION.EXPORT_WHOLE_TOPOGRAPHY) {
exportBounds.setRect(topography.getBounds());
} else {
Rectangle2D viewportBound = model.getViewportBound();
// When exporting the current viewport only, consider that the viewport is usually cut off
// only horizontally or vertically. I.e, the dimension which is not cut off is filled up with a lot
// of gray margin. Therefore, limit this dimension to the corresponding topography dimension.
double width = Math.min(viewportBound.getWidth(), topography.getBounds().getWidth());
double height = Math.min(viewportBound.getHeight(), topography.getBounds().getHeight());
exportBounds.setRect(viewportBound.getX(), viewportBound.getY(), width, height);
}
return exportBounds;
}
private String convertScenarioElementsToTikz(EXPORT_OPTION exportOption) {
String generatedCode = "";
DefaultSimulationConfig config = model.getConfig();
Topography topography = model.getTopography();
// Clip everything outside of topography bound.
Rectangle2D exportBounds = getExportBounds(exportOption, topography);
// Clip everything outside of the user-defined bound.
generatedCode += "% Clipping\n";
String clipTextPattern = "\\clip (%f,%f) rectangle (%f,%f);\n";
generatedCode += String.format(Locale.US, clipTextPattern,
topography.getBounds().x,
topography.getBounds().y,
topography.getBounds().x + topography.getBounds().width,
topography.getBounds().y + topography.getBounds().height);
exportBounds.getX(),
exportBounds.getY(),
exportBounds.getX() + exportBounds.getWidth(),
exportBounds.getY() + exportBounds.getHeight());
// Draw background elements first, then other scenario elements.
generatedCode += "% Ground\n";
......
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