Search in sources :

Example 26 with Point

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);
}
Also used : SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) IntegerProperty(javafx.beans.property.IntegerProperty) Point(net.sf.latexdraw.model.api.shape.Point) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty)

Example 27 with Point

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();
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with Point

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;
}
Also used : SVGPathSegMoveto(net.sf.latexdraw.parser.svg.path.SVGPathSegMoveto) SVGPathSegCurvetoCubic(net.sf.latexdraw.parser.svg.path.SVGPathSegCurvetoCubic) Point(net.sf.latexdraw.model.api.shape.Point) SVGPathSegList(net.sf.latexdraw.parser.svg.path.SVGPathSegList) SVGPathSegClosePath(net.sf.latexdraw.parser.svg.path.SVGPathSegClosePath) Point(net.sf.latexdraw.model.api.shape.Point)

Example 29 with Point

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();
}
Also used : Point(net.sf.latexdraw.model.api.shape.Point)

Example 30 with Point

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();
}
Also used : VerticalPosition(net.sf.latexdraw.view.latex.VerticalPosition) Drawing(net.sf.latexdraw.model.api.shape.Drawing) Set(java.util.Set) Point(net.sf.latexdraw.model.api.shape.Point) LaTeXGenerator(net.sf.latexdraw.view.latex.LaTeXGenerator) LaTeXDataService(net.sf.latexdraw.service.LaTeXDataService) ViewsSynchroniserHandler(net.sf.latexdraw.view.ViewsSynchroniserHandler) HashSet(java.util.HashSet) Objects(java.util.Objects) Inject(net.sf.latexdraw.util.Inject) SystemUtils(net.sf.latexdraw.util.SystemUtils) MathUtils(net.sf.latexdraw.model.MathUtils) NotNull(org.jetbrains.annotations.NotNull) Point(net.sf.latexdraw.model.api.shape.Point) Point(net.sf.latexdraw.model.api.shape.Point) HashSet(java.util.HashSet)

Aggregations

Point (net.sf.latexdraw.model.api.shape.Point)139 Test (org.junit.Test)52 HelperTest (net.sf.latexdraw.HelperTest)27 Theory (org.junit.experimental.theories.Theory)23 NotNull (org.jetbrains.annotations.NotNull)19 Line (net.sf.latexdraw.model.api.shape.Line)10 Shape (net.sf.latexdraw.model.api.shape.Shape)9 SVGElement (net.sf.latexdraw.parser.svg.SVGElement)9 SVGGElement (net.sf.latexdraw.parser.svg.SVGGElement)9 Test (org.junit.jupiter.api.Test)8 ArrayList (java.util.ArrayList)7 Polyline (net.sf.latexdraw.model.api.shape.Polyline)5 Color (javafx.scene.paint.Color)4 MathUtils (net.sf.latexdraw.model.MathUtils)4 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)4 BezierCurve (net.sf.latexdraw.model.api.shape.BezierCurve)4 Canvas (net.sf.latexdraw.view.jfx.Canvas)4 Point2D (java.awt.geom.Point2D)3 List (java.util.List)3 ShapeData (net.sf.latexdraw.data.ShapeData)3