use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class AlignDistribCmd method undo.
@Override
public void undo() {
final IntegerProperty pos = new SimpleIntegerProperty(0);
shape.getShapes().forEach(sh -> {
// Reusing the old position.
final Point pt = sh.getTopLeftPoint();
final Point oldPt = oldPositions.get(pos.get());
if (!pt.equals(oldPt)) {
sh.translate(oldPt.getX() - pt.getX(), oldPt.getY() - pt.getY());
}
pos.set(pos.get() + 1);
});
shape.setModified(true);
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class PSTTriangleView method getCode.
@Override
@NotNull
public String getCode(@NotNull final Point origin, final float ppc) {
final Point tl = shape.getTopLeftPoint();
final Point br = shape.getBottomRightPoint();
final double tlx = tl.getX();
final double brx = br.getX();
final double bry = br.getY();
final StringBuilder rot = getRotationHeaderCode(ppc, origin);
final StringBuilder code = new StringBuilder();
if (rot != null) {
code.append(rot);
}
// NON-NLS
code.append("\\pstriangle[");
code.append(getPropertiesCode(ppc)).append(']').append('(');
code.append(MathUtils.INST.getCutNumberFloat(((tlx + brx) / 2. - origin.getX()) / ppc)).append(',');
code.append(MathUtils.INST.getCutNumberFloat((origin.getY() - bry) / ppc)).append(')').append('(');
code.append(MathUtils.INST.getCutNumberFloat((brx - tlx) / ppc)).append(',');
code.append(MathUtils.INST.getCutNumberFloat((bry - tl.getY()) / ppc)).append(')');
if (rot != null) {
code.append('}');
}
return code.toString();
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class SVGBezierCurve method getPathSegList.
/**
* @return The SVG segment path list of the current Bézier curve.
*/
SVGPathSegList getPathSegList() {
if (shape.getNbPoints() < 2) {
return null;
}
final int size = shape.getNbPoints();
int i;
final SVGPathSegList path = new SVGPathSegList();
path.add(new SVGPathSegMoveto(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), false));
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(1).getX(), shape.getPtAt(1).getY(), shape.getFirstCtrlPtAt(0).getX(), shape.getFirstCtrlPtAt(0).getY(), shape.getFirstCtrlPtAt(1).getX(), shape.getFirstCtrlPtAt(1).getY(), false));
for (i = 2; i < size; i++) {
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(i).getX(), shape.getPtAt(i).getY(), shape.getSecondCtrlPtAt(i - 1).getX(), shape.getSecondCtrlPtAt(i - 1).getY(), shape.getFirstCtrlPtAt(i).getX(), shape.getFirstCtrlPtAt(i).getY(), false));
}
if (!shape.isOpened()) {
final Point ctrl1b = shape.getFirstCtrlPtAt(0).centralSymmetry(shape.getPtAt(0));
final Point ctrl2b = shape.getFirstCtrlPtAt(-1).centralSymmetry(shape.getPtAt(-1));
path.add(new SVGPathSegCurvetoCubic(shape.getPtAt(0).getX(), shape.getPtAt(0).getY(), ctrl2b.getX(), ctrl2b.getY(), ctrl1b.getX(), ctrl1b.getY(), false));
path.add(new SVGPathSegClosePath());
}
return path;
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class PSTCodeGenerator method getDocumentCode.
@Override
public String getDocumentCode() {
final StringBuilder doc = new StringBuilder();
final Point bl = handler.getBottomLeftDrawingPoint();
final Point tr = handler.getTopRightDrawingPoint();
final float ppc = handler.getPPCDrawing();
final String eol = SystemUtils.getInstance().eol;
if (tr.getY() < 0d) {
bl.setY(bl.getY() - tr.getY());
tr.setY(0d);
}
// NON-NLS
doc.append("\\documentclass{article}").append(eol).append(// NON-NLS
"\\pagestyle{empty}").append(eol).append(// NON-NLS
latexdata.getPackages()).append(eol).append(// NON-NLS
"\\usepackage[left=0cm,top=0cm,right=0cm,bottom=0cm,nohead,nofoot,paperwidth=").append((tr.getX() - bl.getX()) / ppc * latexdata.getScale() + 0.2).append(// NON-NLS
"cm,paperheight=").append(// NON-NLS
(bl.getY() - tr.getY()) / ppc * latexdata.getScale() + 0.2).append(// NON-NLS
"cm]{geometry}").append(eol).append(// NON-NLS
"\\usepackage[usenames,dvipsnames]{pstricks}").append(eol).append(// NON-NLS
"\\usepackage{epsfig}").append(eol).append(// NON-NLS
"\\usepackage{pst-grad}").append(eol).append(// NON-NLS
"\\usepackage{pst-plot}").append(eol).append(packageForSpacePicture).append(// NON-NLS
"\\begin{document}").append(eol).append(eol).append(getDrawingCode()).append(eol).append(// NON-NLS
"\\end{document}");
return doc.toString();
}
use of net.sf.latexdraw.model.api.shape.Point in project latexdraw by arnobl.
the class PSTCodeGenerator method getDrawingCode.
@Override
public String getDrawingCode() {
if (drawing.isEmpty()) {
return "";
}
final StringBuilder cache = new StringBuilder();
final Point origin = handler.getOriginDrawingPoint();
final Point tl = handler.getTopRightDrawingPoint();
final Point br = handler.getBottomLeftDrawingPoint();
final int ppc = handler.getPPCDrawing();
final Set<String> addedColours = new HashSet<>();
final StringBuilder shapeCode = new StringBuilder();
final String eol = SystemUtils.getInstance().eol;
commentCode(cache);
cache.append(packagePstricks).append("% ").append(packageForSpacePicture.replaceAll(eol, eol + "% "));
addPkgs(cache);
cache.append(eol);
final boolean hasBegan = startlatexParams(cache);
if (withLatexParams && latexdata.isPositionHoriCentre()) {
// NON-NLS
cache.append("\\begin{center}").append(eol);
}
final float scaleF = MathUtils.INST.getCutNumberFloat(latexdata.getScale());
// NON-NLS
cache.append("\\psscalebox{").append(scaleF).append(' ').append(scaleF).append("} % Change this value to rescale the drawing.");
cache.append(eol).append('{').append(eol);
// NON-NLS
cache.append("\\begin{pspicture}(");
cache.append(0).append(',').append(MathUtils.INST.getCutNumberFloat((origin.getY() - br.getY()) / ppc)).append(')').append('(');
cache.append(MathUtils.INST.getCutNumberFloat((tl.getX() - origin.getX()) / ppc)).append(',').append(MathUtils.INST.getCutNumberFloat((origin.getY() - tl.getY()) / ppc));
cache.append(')').append(eol);
drawing.getShapes().forEach(shape -> viewsFactory.createView(shape).ifPresent(pstView -> {
shapeCode.append(pstView.getCode(origin, ppc)).append(eol);
final String generateColourCode = pstView.generateColourCode(addedColours);
if (!generateColourCode.isEmpty()) {
cache.append(generateColourCode).append(eol);
}
}));
cache.append(shapeCode).append(// NON-NLS
"\\end{pspicture}").append(eol).append('}').append(eol);
endlatexParams(cache, hasBegan);
return cache.toString();
}
Aggregations