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

Restructure app routine.

parent d886f81e
Branches
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;
SvgExporter<? extends AbstractCanvas> svgExporter;
switch (mode) { // Decide on correct rendering mode to apply
case NORMALPRINTER:
RasterCanvas rasterCanvas = renderer.rasterize(diagram);
svgExporter = new BoolMatrixDataSvgExporter(rasterCanvas);
outputPages = rasterCanvas.getPageIterator();
break;
case INDEX_EVEREST_D_V4_FLOATINGDOT_PRINTER:
PlotCanvas plotCanvas = new PlotCanvas(printer, representationParameters, format); // TODO: call renderer.plot()
svgExporter = new BoolFloatingPointDataSvgExporter(plotCanvas);
outputPages = plotCanvas.getPageIterator();
break;
default: throw new UnsupportedOperationException("Mode not supported: " + mode);
}
// Action switches
boolean doPrint = !settingsReader.isTrue(SettingType.INHIBIT_PRINT).orElse(false);
boolean doSvgExport = settingsReader.isPresent(SettingType.SVG_EXPORT);
boolean doByteDump = settingsReader.isPresent(SettingType.BYTE_DUMP);
// SVG exporting // SVG exporting
SvgExporter<RasterCanvas> svgExporter = new BoolMatrixDataSvgExporter(canvas); if (doSvgExport) {
File svgBaseFile = new File(settingsReader.getSetting(SettingType.SVG_EXPORT).get());
svgExporter.render(); svgExporter.render();
svgExporter.dump("boolMat"); svgExporter.dump(svgBaseFile.getAbsolutePath());
}
// FloatingPointData SVG exporting example
PlotCanvas floatCanvas = new PlotCanvas(printer, representationParameters, format);
FloatingPointData<Boolean> points = floatCanvas.getNewPage();
final int blockX = 230; // Printing and Byte Dumping
final int blockY = 400; PrintDirector printD = new PrintDirector(mode, printer);
for (int y = 0; y < blockY; y += 2) { if (doPrint && !PrintDirector.isPrintServiceOn()) { // Check for running spooler or print service
for (int x = 0; x < blockX; x += 2) { throw new Exception("Can't find any running print services on this system.");
Point2DValued<Quantity<Length>, Boolean> point = new Point2DValued<>(Quantities.getQuantity(x, MetricPrefix.MILLI(METRE)), Quantities.getQuantity(y, MetricPrefix.MILLI(METRE)), true);
points.addPoint(point);
} }
File dumpBaseFile = null; // Setup dump base file if required
if (doByteDump) {
dumpBaseFile = new File(settingsReader.getSetting(SettingType.BYTE_DUMP).get());
} }
int pageNumber = 0;
SvgExporter<PlotCanvas> floatSvgExporter = new BoolFloatingPointDataSvgExporter(floatCanvas); while (outputPages.hasNext()) { // Iterate pages
floatSvgExporter.render(); PrintableData page = outputPages.next();
floatSvgExporter.dump("floatingPointData"); if (doByteDump) { // Byte dump
LiblouisBrailleTextRasterizer textRasterizer = new LiblouisBrailleTextRasterizer(printer); try (FileOutputStream outputStream = new FileOutputStream(dumpBaseFile.getAbsolutePath() + String.format("_%03d.bin", pageNumber))) {
renderer.getRenderingBase().registerRasterizer(new FunctionalRasterizer<BrailleText>(BrailleText.class, textRasterizer)); outputStream.write(printD.byteDump(page));
RasterCanvas refCanvas = renderer.rasterize(new BrailleText(" ", new Rectangle(0, 0, 0, 0))); } catch (IOException ex) {
// RasterCanvas m2canvas = renderer.rasterize(new BrailleText(text2, textArea)); // Inform user, but do not stop execution
SimpleMatrixDataImpl<Boolean> mat = (SimpleMatrixDataImpl<Boolean>) canvas.getCurrentPage(); mLogger.error("An error occured while creating byte dump", ex);
mLogger.debug("Render preview:\n" + mat.toBoolString()); throw new RuntimeException();
// Check if some SpoolerService/Printservice exists
if (!PrintDirector.isPrintServiceOn()) {
throw new Exception("Can't find any Printservices on this System.");
} }
/*
We do not want to actually print on each run.
Until CLI parsing is fully integrated, you will have to disable this check by hand if you actually do
want to print.
Please do not commit changes to this.
*/
if (true) {
return EXIT_SUCCESS;
} }
if (doPrint) { // Print page
// Last Step: Printing printD.print(page);
@SuppressWarnings("checkstyle:MagicNumber") }
String printerConfigUpperCase = printer.getProperty("mode").toString().toUpperCase(); pageNumber++;
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.
Please to comment