mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -04:00
added exporter for SVG-LaTeX
This commit is contained in:
parent
edd00f1e68
commit
953c3b9edf
@ -30,7 +30,7 @@
|
|||||||
<elementAttributes>
|
<elementAttributes>
|
||||||
<entry>
|
<entry>
|
||||||
<string>Label</string>
|
<string>Label</string>
|
||||||
<string>C_i-1</string>
|
<string>C0</string>
|
||||||
</entry>
|
</entry>
|
||||||
</elementAttributes>
|
</elementAttributes>
|
||||||
<pos x="-130" y="240"/>
|
<pos x="-130" y="240"/>
|
||||||
@ -242,7 +242,7 @@
|
|||||||
<elementAttributes>
|
<elementAttributes>
|
||||||
<entry>
|
<entry>
|
||||||
<string>Label</string>
|
<string>Label</string>
|
||||||
<string>C_i</string>
|
<string>C3</string>
|
||||||
</entry>
|
</entry>
|
||||||
</elementAttributes>
|
</elementAttributes>
|
||||||
<pos x="60" y="-300"/>
|
<pos x="60" y="-300"/>
|
||||||
@ -346,7 +346,7 @@
|
|||||||
<elementAttributes>
|
<elementAttributes>
|
||||||
<entry>
|
<entry>
|
||||||
<string>Label</string>
|
<string>Label</string>
|
||||||
<string>C_i-1</string>
|
<string>C0</string>
|
||||||
</entry>
|
</entry>
|
||||||
</elementAttributes>
|
</elementAttributes>
|
||||||
<pos x="220" y="240"/>
|
<pos x="220" y="240"/>
|
||||||
@ -638,10 +638,6 @@
|
|||||||
<string>Inputs</string>
|
<string>Inputs</string>
|
||||||
<int>5</int>
|
<int>5</int>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
|
||||||
<string>Inputs</string>
|
|
||||||
<int>5</int>
|
|
||||||
</entry>
|
|
||||||
</elementAttributes>
|
</elementAttributes>
|
||||||
<pos x="450" y="-340"/>
|
<pos x="450" y="-340"/>
|
||||||
<rotate>0</rotate>
|
<rotate>0</rotate>
|
||||||
@ -651,7 +647,7 @@
|
|||||||
<elementAttributes>
|
<elementAttributes>
|
||||||
<entry>
|
<entry>
|
||||||
<string>Label</string>
|
<string>Label</string>
|
||||||
<string>C_i</string>
|
<string>C3</string>
|
||||||
</entry>
|
</entry>
|
||||||
</elementAttributes>
|
</elementAttributes>
|
||||||
<pos x="530" y="-320"/>
|
<pos x="530" y="-320"/>
|
||||||
|
@ -7,8 +7,7 @@ import java.util.Date;
|
|||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class GraphicSVG implements Graphic, Closeable {
|
public class GraphicSVG implements Graphic, Closeable {
|
||||||
private static final int TEXTSIZE = 20;
|
private static final int DEF_SCALE = 30;
|
||||||
private static final int DEF_SCALE = 100;
|
|
||||||
private final BufferedWriter w;
|
private final BufferedWriter w;
|
||||||
|
|
||||||
public GraphicSVG(File file, Vector min, Vector max) throws IOException {
|
public GraphicSVG(File file, Vector min, Vector max) throws IOException {
|
||||||
@ -22,7 +21,7 @@ public class GraphicSVG implements Graphic, Closeable {
|
|||||||
public GraphicSVG(File file, Vector min, Vector max, File source, int svgScale) throws IOException {
|
public GraphicSVG(File file, Vector min, Vector max, File source, int svgScale) throws IOException {
|
||||||
w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
|
w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
|
||||||
w.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
|
w.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
|
||||||
"<!-- Created with Digital by H.Neemann -->\n");
|
"<!-- Created with Digital by H.Neemann -->\n");
|
||||||
w.write("<!-- created: " + new Date() + " -->\n");
|
w.write("<!-- created: " + new Date() + " -->\n");
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
w.write("<!-- source: " + source.getPath() + " -->\n");
|
w.write("<!-- source: " + source.getPath() + " -->\n");
|
||||||
@ -32,8 +31,8 @@ public class GraphicSVG implements Graphic, Closeable {
|
|||||||
" xmlns:svg=\"http://www.w3.org/2000/svg\"\n" +
|
" xmlns:svg=\"http://www.w3.org/2000/svg\"\n" +
|
||||||
" xmlns=\"http://www.w3.org/2000/svg\"\n");
|
" xmlns=\"http://www.w3.org/2000/svg\"\n");
|
||||||
|
|
||||||
double width = (max.x - min.x) * svgScale / 900;
|
double width = (max.x - min.x) * svgScale / 100;
|
||||||
double height = (max.y - min.y) * svgScale / 900;
|
double height = (max.y - min.y) * svgScale / 100;
|
||||||
|
|
||||||
w.write(" width=\"" + width + "mm\"\n" +
|
w.write(" width=\"" + width + "mm\"\n" +
|
||||||
" height=\"" + height + "mm\"\n" +
|
" height=\"" + height + "mm\"\n" +
|
||||||
@ -142,7 +141,7 @@ public class GraphicSVG implements Graphic, Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getColor(Style style) {
|
public String getColor(Style style) {
|
||||||
return "#" + Integer.toHexString(style.getColor().getRGB()).substring(2);
|
return "#" + Integer.toHexString(style.getColor().getRGB()).substring(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package de.neemann.digital.draw.graphics;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
public class GraphicSVGLaTeX extends GraphicSVG {
|
||||||
|
public GraphicSVGLaTeX(File file, Vector min, Vector max) throws IOException {
|
||||||
|
super(file, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawText(Vector p1, Vector p2, String text, Orientation orientation, Style style) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < text.length(); i++) {
|
||||||
|
char c = text.charAt(i);
|
||||||
|
switch (c) {
|
||||||
|
case '~':
|
||||||
|
case '\u00AC':
|
||||||
|
sb.append("$\\neg$");
|
||||||
|
break;
|
||||||
|
case '\u2265':
|
||||||
|
sb.append("$\\geq$");
|
||||||
|
break;
|
||||||
|
case '&':
|
||||||
|
sb.append("\\&");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.drawText(p1, p2, sb.toString(), orientation, style);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawCircle(Vector p1, Vector p2, Style style) {
|
||||||
|
if ((style != Style.WIRE && style != Style.WIRE_OUT) || Math.abs(p1.x - p2.x) > 2)
|
||||||
|
super.drawCircle(p1, p2, style);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColor(Style style) {
|
||||||
|
if (style == Style.WIRE) return super.getColor(Style.NORMAL);
|
||||||
|
if (style == Style.WIRE_OUT) return super.getColor(Style.NORMAL);
|
||||||
|
return super.getColor(style);
|
||||||
|
}
|
||||||
|
}
|
@ -46,7 +46,7 @@ public class ClockShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, boolean heighLight) {
|
public void drawTo(Graphic graphic, boolean heighLight) {
|
||||||
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 2, -SIZE).add(-2, -SIZE).add(-2, SIZE).add(-SIZE * 2 - 2, SIZE), Style.NORMAL);
|
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 1, -SIZE).add(-1, -SIZE).add(-1, SIZE).add(-SIZE * 2 - 1, SIZE), Style.NORMAL);
|
||||||
|
|
||||||
Vector textPos = new Vector(-SIZE * 3, 0);
|
Vector textPos = new Vector(-SIZE * 3, 0);
|
||||||
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.RIGHTCENTER, Style.NORMAL);
|
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.RIGHTCENTER, Style.NORMAL);
|
||||||
|
@ -51,10 +51,10 @@ public class DemuxerShape implements Shape {
|
|||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, boolean highLight) {
|
public void drawTo(Graphic graphic, boolean highLight) {
|
||||||
graphic.drawPolygon(new Polygon(true)
|
graphic.drawPolygon(new Polygon(true)
|
||||||
.add(2, 3)
|
.add(1, 3)
|
||||||
.add(SIZE * 2 - 2, -2)
|
.add(SIZE * 2 - 1, -2)
|
||||||
.add(SIZE * 2 - 2, height + 2)
|
.add(SIZE * 2 - 1, height + 2)
|
||||||
.add(2, height - 3), Style.NORMAL);
|
.add(1, height - 3), Style.NORMAL);
|
||||||
graphic.drawText(new Vector(SIZE * 2 - 2, 0), new Vector(SIZE * 2, 0), "0", Orientation.RIGHTTOP, Style.SHAPE_PIN);
|
graphic.drawText(new Vector(SIZE * 2 - 2, 0), new Vector(SIZE * 2, 0), "0", Orientation.RIGHTTOP, Style.SHAPE_PIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,9 @@ public class InputShape implements Shape {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector center = new Vector(-2 - SIZE, 0);
|
Vector center = new Vector(-1 - SIZE, 0);
|
||||||
graphic.drawCircle(center.sub(RAD), center.add(RAD), style);
|
graphic.drawCircle(center.sub(RAD), center.add(RAD), style);
|
||||||
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 2, -SIZE).add(-2, -SIZE).add(-2, SIZE).add(-SIZE * 2 - 2, SIZE), Style.NORMAL);
|
graphic.drawPolygon(new Polygon(true).add(-SIZE * 2 - 1, -SIZE).add(-1, -SIZE).add(-1, SIZE).add(-SIZE * 2 - 1, SIZE), Style.NORMAL);
|
||||||
|
|
||||||
Vector textPos = new Vector(-SIZE * 3, 0);
|
Vector textPos = new Vector(-SIZE * 3, 0);
|
||||||
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.RIGHTCENTER, Style.NORMAL);
|
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.RIGHTCENTER, Style.NORMAL);
|
||||||
|
@ -46,10 +46,10 @@ public class MuxerShape implements Shape {
|
|||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphic graphic, boolean heighLight) {
|
public void drawTo(Graphic graphic, boolean heighLight) {
|
||||||
graphic.drawPolygon(new Polygon(true)
|
graphic.drawPolygon(new Polygon(true)
|
||||||
.add(2, -2)
|
.add(1, -2)
|
||||||
.add(SIZE * 2 - 2, 3)
|
.add(SIZE * 2 - 1, 3)
|
||||||
.add(SIZE * 2 - 2, inputCount * SIZE - 3)
|
.add(SIZE * 2 - 1, inputCount * SIZE - 3)
|
||||||
.add(2, inputCount * SIZE + 2), Style.NORMAL);
|
.add(1, inputCount * SIZE + 2), Style.NORMAL);
|
||||||
graphic.drawText(new Vector(3, 0), new Vector(4, 0), "0", Orientation.LEFTTOP, Style.SHAPE_PIN);
|
graphic.drawText(new Vector(3, 0), new Vector(4, 0), "0", Orientation.LEFTTOP, Style.SHAPE_PIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,7 @@ import de.neemann.digital.core.wiring.Clock;
|
|||||||
import de.neemann.digital.draw.elements.Circuit;
|
import de.neemann.digital.draw.elements.Circuit;
|
||||||
import de.neemann.digital.draw.elements.PinException;
|
import de.neemann.digital.draw.elements.PinException;
|
||||||
import de.neemann.digital.draw.elements.PinOrder;
|
import de.neemann.digital.draw.elements.PinOrder;
|
||||||
import de.neemann.digital.draw.graphics.Exporter;
|
import de.neemann.digital.draw.graphics.*;
|
||||||
import de.neemann.digital.draw.graphics.Graphic;
|
|
||||||
import de.neemann.digital.draw.graphics.GraphicMinMax;
|
|
||||||
import de.neemann.digital.draw.graphics.GraphicSVG;
|
|
||||||
import de.neemann.digital.draw.library.ElementLibrary;
|
import de.neemann.digital.draw.library.ElementLibrary;
|
||||||
import de.neemann.digital.draw.model.ModelDescription;
|
import de.neemann.digital.draw.model.ModelDescription;
|
||||||
import de.neemann.digital.draw.model.RealTimeClock;
|
import de.neemann.digital.draw.model.RealTimeClock;
|
||||||
@ -164,6 +161,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
|
|
||||||
JMenu export = new JMenu(Lang.get("menu_export"));
|
JMenu export = new JMenu(Lang.get("menu_export"));
|
||||||
export.add(new ExportAction(Lang.get("menu_exportSVG"), "svg", GraphicSVG::new));
|
export.add(new ExportAction(Lang.get("menu_exportSVG"), "svg", GraphicSVG::new));
|
||||||
|
export.add(new ExportAction(Lang.get("menu_exportSVGLaTex"), "svg", GraphicSVGLaTeX::new));
|
||||||
|
|
||||||
|
|
||||||
JMenu file = new JMenu(Lang.get("menu_file"));
|
JMenu file = new JMenu(Lang.get("menu_file"));
|
||||||
|
@ -133,6 +133,7 @@ menu_fast=Run Fast
|
|||||||
menu_fast_tt=Runs the model until a break is detected by the BRK element.
|
menu_fast_tt=Runs the model until a break is detected by the BRK element.
|
||||||
menu_export=Export
|
menu_export=Export
|
||||||
menu_exportSVG=Export SVG
|
menu_exportSVG=Export SVG
|
||||||
|
menu_exportSVGLaTex=Export SVG+LaTeX
|
||||||
menu_delete=Delete elements
|
menu_delete=Delete elements
|
||||||
menu_delete_tt=Delete selected single element or group of elements
|
menu_delete_tt=Delete selected single element or group of elements
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user