Skip to content
Snippets Groups Projects
Commit 02b19cc5 authored by Leonard Kupper's avatar Leonard Kupper
Browse files

Restructure app routine.

parent d886f81e
No related branches found
No related tags found
1 merge request!39App restructuring
...@@ -10,16 +10,13 @@ import de.tudresden.inf.mci.brailleplot.datacontainers.PointListContainer; ...@@ -10,16 +10,13 @@ import de.tudresden.inf.mci.brailleplot.datacontainers.PointListContainer;
import de.tudresden.inf.mci.brailleplot.datacontainers.SimpleCategoricalPointListContainerImpl; import de.tudresden.inf.mci.brailleplot.datacontainers.SimpleCategoricalPointListContainerImpl;
import de.tudresden.inf.mci.brailleplot.diagrams.CategoricalBarChart; import de.tudresden.inf.mci.brailleplot.diagrams.CategoricalBarChart;
import de.tudresden.inf.mci.brailleplot.diagrams.Diagram; import de.tudresden.inf.mci.brailleplot.diagrams.Diagram;
import de.tudresden.inf.mci.brailleplot.layout.AbstractCanvas;
import de.tudresden.inf.mci.brailleplot.layout.PlotCanvas; import de.tudresden.inf.mci.brailleplot.layout.PlotCanvas;
import de.tudresden.inf.mci.brailleplot.layout.RasterCanvas; import de.tudresden.inf.mci.brailleplot.layout.RasterCanvas;
import de.tudresden.inf.mci.brailleplot.layout.Rectangle;
import de.tudresden.inf.mci.brailleplot.point.Point2DValued;
import de.tudresden.inf.mci.brailleplot.printabledata.FloatingPointData;
import de.tudresden.inf.mci.brailleplot.printabledata.PrintableData; import de.tudresden.inf.mci.brailleplot.printabledata.PrintableData;
import de.tudresden.inf.mci.brailleplot.printerbackend.PrintDirector; import de.tudresden.inf.mci.brailleplot.printerbackend.PrintDirector;
import de.tudresden.inf.mci.brailleplot.printerbackend.PrinterCapability; import de.tudresden.inf.mci.brailleplot.printerbackend.PrinterCapability;
import de.tudresden.inf.mci.brailleplot.printabledata.SimpleMatrixDataImpl;
import de.tudresden.inf.mci.brailleplot.commandline.CommandLineParser; import de.tudresden.inf.mci.brailleplot.commandline.CommandLineParser;
import de.tudresden.inf.mci.brailleplot.commandline.SettingType; import de.tudresden.inf.mci.brailleplot.commandline.SettingType;
...@@ -32,34 +29,28 @@ import de.tudresden.inf.mci.brailleplot.csvparser.CsvType; ...@@ -32,34 +29,28 @@ import de.tudresden.inf.mci.brailleplot.csvparser.CsvType;
import de.tudresden.inf.mci.brailleplot.datacontainers.CategoricalPointListContainer; import de.tudresden.inf.mci.brailleplot.datacontainers.CategoricalPointListContainer;
import de.tudresden.inf.mci.brailleplot.datacontainers.PointList; import de.tudresden.inf.mci.brailleplot.datacontainers.PointList;
import de.tudresden.inf.mci.brailleplot.rendering.BrailleText;
import de.tudresden.inf.mci.brailleplot.rendering.FunctionalRasterizer;
import de.tudresden.inf.mci.brailleplot.rendering.LiblouisBrailleTextRasterizer; import de.tudresden.inf.mci.brailleplot.rendering.LiblouisBrailleTextRasterizer;
import de.tudresden.inf.mci.brailleplot.rendering.MasterRenderer; import de.tudresden.inf.mci.brailleplot.rendering.MasterRenderer;
import de.tudresden.inf.mci.brailleplot.svgexporter.BoolFloatingPointDataSvgExporter; import de.tudresden.inf.mci.brailleplot.svgexporter.BoolFloatingPointDataSvgExporter;
import de.tudresden.inf.mci.brailleplot.svgexporter.BoolMatrixDataSvgExporter; import de.tudresden.inf.mci.brailleplot.svgexporter.BoolMatrixDataSvgExporter;
import de.tudresden.inf.mci.brailleplot.svgexporter.SvgExporter; import de.tudresden.inf.mci.brailleplot.svgexporter.SvgExporter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import tec.units.ri.quantity.Quantities;
import tec.units.ri.unit.MetricPrefix;
import javax.measure.Quantity;
import javax.measure.quantity.Length;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.net.URL; import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Iterator;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
import static tec.units.ri.unit.Units.METRE;
/** /**
* Main class. * Main class.
* Set up the application and run it. * Set up the application and run it.
...@@ -187,7 +178,7 @@ public final class App { ...@@ -187,7 +178,7 @@ public final class App {
Representation representationParameters = configParser.getRepresentation(); Representation representationParameters = configParser.getRepresentation();
Format format; Format format;
if (!settingsReader.isPresent(SettingType.FORMAT)) { if (!settingsReader.isPresent(SettingType.FORMAT)) {
format = configParser.getFormat("A4"); // Default behaviour is A4 portrait format = configParser.getFormat("default"); // Default behaviour from default config (A4 portrait)
} else { } else {
format = configParser.getFormat(settingsReader.getSetting(SettingType.FORMAT).get()); format = configParser.getFormat(settingsReader.getSetting(SettingType.FORMAT).get());
} }
...@@ -213,10 +204,10 @@ public final class App { ...@@ -213,10 +204,10 @@ public final class App {
switch (settingsReader.getSetting(SettingType.DIAGRAM_TYPE).orElse("")) { switch (settingsReader.getSetting(SettingType.DIAGRAM_TYPE).orElse("")) {
case "ScatterPlot": case "ScatterPlot":
PointListContainer<PointList> scatterPlotContainer = csvParser.parse(CsvType.DOTS, csvOrientation); PointListContainer<PointList> scatterPlotContainer = csvParser.parse(CsvType.DOTS, csvOrientation);
throw new UnsupportedOperationException("Scatter Plots coming soon."); throw new UnsupportedOperationException("Scatter Plots coming soon."); // TODO: integrate scatter plots
case "LineChart": case "LineChart":
PointListContainer<PointList> lineChartContainer = csvParser.parse(CsvType.DOTS, csvOrientation); PointListContainer<PointList> lineChartContainer = csvParser.parse(CsvType.DOTS, csvOrientation);
throw new UnsupportedOperationException("Line Charts coming soon."); throw new UnsupportedOperationException("Line Charts coming soon."); // TODO: integrate line charts
case "BarChart": case "BarChart":
CategoricalPointListContainer<PointList> barChartContainer; CategoricalPointListContainer<PointList> barChartContainer;
try { // first try to parse as regular bar chart and convert to single category bar cart. try { // first try to parse as regular bar chart and convert to single category bar cart.
...@@ -235,61 +226,61 @@ public final class App { ...@@ -235,61 +226,61 @@ public final class App {
// Render diagram // Render diagram
LiblouisBrailleTextRasterizer.initModule(); LiblouisBrailleTextRasterizer.initModule();
MasterRenderer renderer = new MasterRenderer(printer, representationParameters, format); MasterRenderer renderer = new MasterRenderer(printer, representationParameters, format);
RasterCanvas canvas = renderer.rasterize(diagram); PrinterCapability mode = PrinterCapability.valueOf(printer.getProperty("mode").toString().toUpperCase());
Iterator<? extends PrintableData> outputPages;
// SVG exporting SvgExporter<? extends AbstractCanvas> svgExporter;
SvgExporter<RasterCanvas> svgExporter = new BoolMatrixDataSvgExporter(canvas); switch (mode) { // Decide on correct rendering mode to apply
svgExporter.render(); case NORMALPRINTER:
svgExporter.dump("boolMat"); RasterCanvas rasterCanvas = renderer.rasterize(diagram);
svgExporter = new BoolMatrixDataSvgExporter(rasterCanvas);
// FloatingPointData SVG exporting example outputPages = rasterCanvas.getPageIterator();
PlotCanvas floatCanvas = new PlotCanvas(printer, representationParameters, format); break;
FloatingPointData<Boolean> points = floatCanvas.getNewPage(); case INDEX_EVEREST_D_V4_FLOATINGDOT_PRINTER:
PlotCanvas plotCanvas = new PlotCanvas(printer, representationParameters, format); // TODO: call renderer.plot()
final int blockX = 230; svgExporter = new BoolFloatingPointDataSvgExporter(plotCanvas);
final int blockY = 400; outputPages = plotCanvas.getPageIterator();
for (int y = 0; y < blockY; y += 2) { break;
for (int x = 0; x < blockX; x += 2) { default: throw new UnsupportedOperationException("Mode not supported: " + mode);
Point2DValued<Quantity<Length>, Boolean> point = new Point2DValued<>(Quantities.getQuantity(x, MetricPrefix.MILLI(METRE)), Quantities.getQuantity(y, MetricPrefix.MILLI(METRE)), true);
points.addPoint(point);
}
} }
SvgExporter<PlotCanvas> floatSvgExporter = new BoolFloatingPointDataSvgExporter(floatCanvas); // Action switches
floatSvgExporter.render(); boolean doPrint = !settingsReader.isTrue(SettingType.INHIBIT_PRINT).orElse(false);
floatSvgExporter.dump("floatingPointData"); boolean doSvgExport = settingsReader.isPresent(SettingType.SVG_EXPORT);
LiblouisBrailleTextRasterizer textRasterizer = new LiblouisBrailleTextRasterizer(printer); boolean doByteDump = settingsReader.isPresent(SettingType.BYTE_DUMP);
renderer.getRenderingBase().registerRasterizer(new FunctionalRasterizer<BrailleText>(BrailleText.class, textRasterizer));
RasterCanvas refCanvas = renderer.rasterize(new BrailleText(" ", new Rectangle(0, 0, 0, 0)));
// RasterCanvas m2canvas = renderer.rasterize(new BrailleText(text2, textArea));
SimpleMatrixDataImpl<Boolean> mat = (SimpleMatrixDataImpl<Boolean>) canvas.getCurrentPage();
mLogger.debug("Render preview:\n" + mat.toBoolString());
// SVG exporting
// Check if some SpoolerService/Printservice exists if (doSvgExport) {
if (!PrintDirector.isPrintServiceOn()) { File svgBaseFile = new File(settingsReader.getSetting(SettingType.SVG_EXPORT).get());
throw new Exception("Can't find any Printservices on this System."); svgExporter.render();
svgExporter.dump(svgBaseFile.getAbsolutePath());
} }
/* // Printing and Byte Dumping
We do not want to actually print on each run. PrintDirector printD = new PrintDirector(mode, printer);
Until CLI parsing is fully integrated, you will have to disable this check by hand if you actually do if (doPrint && !PrintDirector.isPrintServiceOn()) { // Check for running spooler or print service
want to print. throw new Exception("Can't find any running print services on this system.");
Please do not commit changes to this. }
*/ File dumpBaseFile = null; // Setup dump base file if required
if (true) { if (doByteDump) {
return EXIT_SUCCESS; dumpBaseFile = new File(settingsReader.getSetting(SettingType.BYTE_DUMP).get());
}
int pageNumber = 0;
while (outputPages.hasNext()) { // Iterate pages
PrintableData page = outputPages.next();
if (doByteDump) { // Byte dump
try (FileOutputStream outputStream = new FileOutputStream(dumpBaseFile.getAbsolutePath() + String.format("_%03d.bin", pageNumber))) {
outputStream.write(printD.byteDump(page));
} catch (IOException ex) {
// Inform user, but do not stop execution
mLogger.error("An error occured while creating byte dump", ex);
throw new RuntimeException();
}
}
if (doPrint) { // Print page
printD.print(page);
}
pageNumber++;
} }
// Last Step: Printing
@SuppressWarnings("checkstyle:MagicNumber")
String printerConfigUpperCase = printer.getProperty("mode").toString().toUpperCase();
PrintDirector printD = new PrintDirector(PrinterCapability.valueOf(printerConfigUpperCase), printer);
printD.print(mat);
FileOutputStream textDumpOutput = new FileOutputStream("dump.txt");
textDumpOutput.write(printD.byteDump(mat));
} catch (final Exception e) { } catch (final Exception e) {
terminateWithException(e); terminateWithException(e);
} }
......
...@@ -36,14 +36,14 @@ public class CommandLineParser { ...@@ -36,14 +36,14 @@ public class CommandLineParser {
.addRequiredOption("c", SettingType.CSV_LOCATION.toString(), true, "Path to CSV") .addRequiredOption("c", SettingType.CSV_LOCATION.toString(), true, "Path to CSV")
.addRequiredOption("p", SettingType.PRINTER_CONFIG_PATH.toString(), true, "Path to printer configuration file") .addRequiredOption("p", SettingType.PRINTER_CONFIG_PATH.toString(), true, "Path to printer configuration file")
.addRequiredOption("t", SettingType.DIAGRAM_TITLE.toString(), true, "Title of the diagram") .addRequiredOption("t", SettingType.DIAGRAM_TITLE.toString(), true, "Title of the diagram")
.addRequiredOption("x", SettingType.X_AXIS_LABEL.toString(), true, "Label of X-axis including unit")
.addRequiredOption("y", SettingType.Y_AXIS_LABEL.toString(), true, "Label of Y-axis including unit")
.addRequiredOption("d", SettingType.DIAGRAM_TYPE.toString(), true, "Type of the diagram. Possible Values: [ScatterPlot, LineChart, BarChart]") .addRequiredOption("d", SettingType.DIAGRAM_TYPE.toString(), true, "Type of the diagram. Possible Values: [ScatterPlot, LineChart, BarChart]")
.addOption("f", SettingType.FORMAT.toString(), true, "Name of predefined format from configuration") .addOption("x", SettingType.X_AXIS_LABEL.toString(), true, "Label of X-axis including unit")
.addOption("y", SettingType.Y_AXIS_LABEL.toString(), true, "Label of Y-axis including unit")
.addOption("f", SettingType.FORMAT.toString(), true, "Name of predefined format from configuration (A4 portrait if not specified)")
.addOption("v", SettingType.VERTICAL_CSV.toString(), false, "Parse CSV in vertical instead of horizontal orientation (Only applicable for BarChart)") .addOption("v", SettingType.VERTICAL_CSV.toString(), false, "Parse CSV in vertical instead of horizontal orientation (Only applicable for BarChart)")
.addOption("i", SettingType.INHIBIT_PRINT.toString(), false, "Inhibit the printing process") .addOption("i", SettingType.INHIBIT_PRINT.toString(), false, "Inhibit the printing process")
.addOption("s", SettingType.SVG_EXPORT.toString(), true, "File path for the generated svg") .addOption("s", SettingType.SVG_EXPORT.toString(), true, "Base file path for export of svg file(s) (Omit '.svg' suffix)")
.addOption("b", SettingType.BYTE_DUMP.toString(), true, "File path for the generated printing byte dump file"); .addOption("b", SettingType.BYTE_DUMP.toString(), true, "Base file path for print data byte dump file(s) (Omit '.bin' suffix)");
} }
/** /**
......
...@@ -51,6 +51,8 @@ public enum SettingType { ...@@ -51,6 +51,8 @@ public enum SettingType {
return INHIBIT_PRINT; return INHIBIT_PRINT;
case "svg-export": case "svg-export":
return SVG_EXPORT; return SVG_EXPORT;
case "byte-dump":
return BYTE_DUMP;
default: default:
throw new IllegalArgumentException("Setting not available"); throw new IllegalArgumentException("Setting not available");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment