Search in sources :

Example 61 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class PSTBezierCurveView method getCode.

@Override
public String getCode(final IPoint origin, final float ppc) {
    if (!MathUtils.INST.isValidPt(origin) || ppc < 1)
        return "";
    int i;
    final int size = shape.getNbPoints();
    IPoint pt;
    IPoint ctrlPt1;
    IPoint ctrlPt2;
    final StringBuilder arrowsStyle = getArrowsStyleCode();
    final StringBuilder params = getPropertiesCode(ppc);
    final StringBuilder coord = new StringBuilder();
    final List<IPoint> pts = shape.getPoints();
    final List<IPoint> fCtrlPts = shape.getFirstCtrlPts();
    final List<IPoint> sCtrlPts = shape.getSecondCtrlPts();
    final double originx = origin.getX();
    final double originy = origin.getY();
    final StringBuilder cache = new StringBuilder();
    if (size < 2)
        return "";
    coord.append('(').append(MathUtils.INST.getCutNumberFloat((pts.get(0).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - pts.get(0).getY()) / ppc));
    coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((fCtrlPts.get(0).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - fCtrlPts.get(0).getY()) / ppc));
    coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((fCtrlPts.get(1).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - fCtrlPts.get(1).getY()) / ppc));
    coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((pts.get(1).getX() - originx) / ppc));
    coord.append(',').append(MathUtils.INST.getCutNumber((originy - pts.get(1).getY()) / ppc));
    coord.append(')');
    for (i = 2; i < size; i++) {
        ctrlPt1 = fCtrlPts.get(i);
        ctrlPt2 = sCtrlPts.get(i - 1);
        coord.append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt2.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt2.getY()) / ppc));
        coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt1.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt1.getY()) / ppc));
        coord.append(')').append('(');
        pt = pts.get(i);
        coord.append(MathUtils.INST.getCutNumberFloat((pt.getX() - originx) / ppc)).append(',');
        coord.append(MathUtils.INST.getCutNumberFloat((originy - pt.getY()) / ppc)).append(')');
    }
    if (!shape.isOpened()) {
        ctrlPt1 = sCtrlPts.get(0);
        ctrlPt2 = sCtrlPts.get(sCtrlPts.size() - 1);
        coord.append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt2.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt2.getY()) / ppc));
        coord.append(')').append('(').append(MathUtils.INST.getCutNumberFloat((ctrlPt1.getX() - originx) / ppc));
        coord.append(',').append(MathUtils.INST.getCutNumberFloat((originy - ctrlPt1.getY()) / ppc));
        coord.append(')').append('(');
        pt = pts.get(0);
        coord.append(MathUtils.INST.getCutNumberFloat((pt.getX() - originx) / ppc)).append(',');
        coord.append(MathUtils.INST.getCutNumberFloat((originy - pt.getY()) / ppc)).append(')');
    }
    // $NON-NLS-1$
    cache.append("\\psbezier[");
    cache.append(params);
    cache.append(']');
    if (arrowsStyle != null)
        cache.append(arrowsStyle);
    cache.append(coord);
    return cache.toString();
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 62 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class PSTCodeGenerator method getDrawingCode.

@Override
public String getDrawingCode() {
    if (drawing.isEmpty())
        return "";
    final StringBuilder cache = new StringBuilder();
    String pkg = LaTeXGenerator.getPackages();
    final IPoint origin = handler.getOriginDrawingPoint();
    final IPoint tl = handler.getTopRightDrawingPoint();
    final IPoint br = handler.getBottomLeftDrawingPoint();
    final int ppc = handler.getPPCDrawing();
    final Map<String, String> addedColours = new HashMap<>();
    final StringBuilder shapeCode = new StringBuilder();
    final boolean hasBeginFigure;
    if (withComments && comment != null && !comment.isEmpty())
        cache.append(getCommentWithTag());
    cache.append(PACKAGE_PSTRICKS).append("% ").append(PACKAGE_FOR_SPACE_PICTURE.replaceAll(LSystem.EOL, LSystem.EOL + "% "));
    if (!pkg.isEmpty()) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        pkg = "% User Packages:" + LSystem.EOL + "% " + pkg.replace(LSystem.EOL, LSystem.EOL + "% ");
        cache.append(pkg).append(LSystem.EOL);
    }
    cache.append(LSystem.EOL);
    if (withLatexParams && (positionVertToken != VerticalPosition.NONE || !caption.isEmpty() || !label.isEmpty())) {
        // $NON-NLS-1$
        cache.append("\\begin{figure}");
        if (positionVertToken == VerticalPosition.NONE)
            cache.append(LSystem.EOL);
        else
            cache.append('[').append(positionVertToken.getToken()).append(']').append(LSystem.EOL);
        hasBeginFigure = true;
    } else
        hasBeginFigure = false;
    // $NON-NLS-1$
    if (withLatexParams && positionHoriCentre)
        cache.append("\\begin{center}").append(LSystem.EOL);
    final float scaleF = MathUtils.INST.getCutNumberFloat(getScale());
    // $NON-NLS-1$ //$NON-NLS-2$
    cache.append("\\psscalebox{").append(scaleF).append(' ').append(scaleF).append("} % Change this value to rescale the drawing.");
    cache.append(LSystem.EOL).append('{').append(LSystem.EOL);
    // $NON-NLS-1$
    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(LSystem.EOL);
    drawing.getShapes().forEach(shape -> PSTViewsFactory.INSTANCE.createView(shape).ifPresent(pstView -> {
        shapeCode.append(pstView.getCode(origin, ppc)).append(LSystem.EOL);
        cache.append(generateColourCode(pstView, addedColours));
    }));
    // $NON-NLS-1$
    cache.append(shapeCode).append("\\end{pspicture}").append(LSystem.EOL).append('}').append(LSystem.EOL);
    if (withLatexParams) {
        // $NON-NLS-1$
        if (positionHoriCentre)
            cache.append("\\end{center}").append(LSystem.EOL);
        // $NON-NLS-1$
        if (!label.isEmpty())
            cache.append("\\label{").append(label).append('}').append(LSystem.EOL);
        // $NON-NLS-1$
        if (!caption.isEmpty())
            cache.append("\\caption{").append(caption).append('}').append(LSystem.EOL);
        // $NON-NLS-1$
        if (hasBeginFigure)
            cache.append("\\end{figure}").append(LSystem.EOL);
    }
    return cache.toString();
}
Also used : VerticalPosition(net.sf.latexdraw.view.latex.VerticalPosition) DviPsColors(net.sf.latexdraw.view.latex.DviPsColors) Map(java.util.Map) LSystem(net.sf.latexdraw.util.LSystem) HashMap(java.util.HashMap) MathUtils(net.sf.latexdraw.models.MathUtils) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) LaTeXGenerator(net.sf.latexdraw.view.latex.LaTeXGenerator) HashMap(java.util.HashMap) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 63 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class PSTCodeGenerator method getDocumentCode.

@Override
public String getDocumentCode() {
    final StringBuilder doc = new StringBuilder();
    final IPoint bl = handler.getBottomLeftDrawingPoint();
    final IPoint tr = handler.getTopRightDrawingPoint();
    final float ppc = handler.getPPCDrawing();
    if (tr.getY() < 0) {
        bl.setY(bl.getY() - tr.getY());
        tr.setY(0.0);
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    doc.append("\\documentclass{article}").append(LSystem.EOL).append("\\pagestyle{empty}").append(LSystem.EOL).append(getPackages()).append(LSystem.EOL).append(// $NON-NLS-1$
    "\\usepackage[left=0cm,top=0.1cm,right=0cm,bottom=0cm,nohead,nofoot,paperwidth=").append(tr.getX() / ppc * scale).append(// $NON-NLS-1$
    "cm,paperheight=").append(bl.getY() / ppc * scale + 0.2).append(// $NON-NLS-1$
    "cm]{geometry}").append(LSystem.EOL).append(// $NON-NLS-1$
    "\\usepackage[usenames,dvipsnames]{pstricks}").append(LSystem.EOL).append(// $NON-NLS-1$
    "\\usepackage{epsfig}").append(LSystem.EOL).append("\\usepackage{pst-grad}").append(LSystem.EOL).append("\\usepackage{pst-plot}").append(// $NON-NLS-1$//$NON-NLS-2$
    LSystem.EOL).append(PSTCodeGenerator.PACKAGE_FOR_SPACE_PICTURE).append("\\begin{document}").append(// $NON-NLS-1$
    LSystem.EOL).append("\\addtolength{\\oddsidemargin}{-0.2in}").append(LSystem.EOL).append(// $NON-NLS-1$ //$NON-NLS-2$
    "\\addtolength{\\evensidemargin}{-0.2in}").append(LSystem.EOL).append(getDrawingCode()).append(LSystem.EOL).append(// $NON-NLS-1$
    "\\end{document}");
    return doc.toString();
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 64 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class PSTGridView method getCode.

@Override
public String getCode(final IPoint pt, final float ppc) {
    if (!MathUtils.INST.isValidPt(pt) || ppc < 1)
        return "";
    final int startX;
    final int startY;
    final int endX;
    final int endY;
    final boolean isXLabelSouth = shape.isXLabelSouth();
    final boolean isYLabelWest = shape.isYLabelWest();
    final IPoint position = shape.getPosition();
    final StringBuilder start = new StringBuilder();
    final StringBuilder end = new StringBuilder();
    final StringBuilder rot = getRotationHeaderCode(ppc, position);
    final StringBuilder coord = new StringBuilder();
    final double unit = shape.getUnit();
    final double gridStartx = shape.getGridStartX();
    final double gridStarty = shape.getGridStartY();
    final double gridEndx = shape.getGridEndX();
    final double gridEndy = shape.getGridEndY();
    final StringBuilder code = new StringBuilder();
    if (isXLabelSouth) {
        startY = (int) gridStarty;
        endY = (int) gridEndy;
    } else {
        startY = (int) gridEndy;
        endY = (int) gridStarty;
    }
    if (isYLabelWest) {
        startX = (int) gridStartx;
        endX = (int) gridEndx;
    } else {
        startX = (int) gridEndx;
        endX = (int) gridStartx;
    }
    coord.append('(').append((int) shape.getOriginX()).append(',').append((int) shape.getOriginY()).append(')');
    coord.append('(').append(startX).append(',').append(startY).append(')');
    coord.append('(').append(endX).append(',').append(endY).append(')');
    if (!MathUtils.INST.equalsDouble(unit, PSTricksConstants.DEFAULT_UNIT))
        // $NON-NLS-1$
        end.append("\n\\psset{unit=").append(PSTricksConstants.DEFAULT_UNIT).append(PSTricksConstants.TOKEN_CM).append('}');
    if (!MathUtils.INST.equalsDouble(position.getX(), 0.0) || !MathUtils.INST.equalsDouble(position.getY(), 0.0)) {
        final float posX = MathUtils.INST.getCutNumberFloat((position.getX() - pt.getX()) / ppc);
        final float posY = MathUtils.INST.getCutNumberFloat((pt.getY() - position.getY()) / ppc);
        end.append('}');
        // $NON-NLS-1$
        start.append("\\rput(").append(posX).append(',').append(posY).append(')').append('{');
    }
    if (rot != null) {
        start.append(rot);
        end.insert(0, '}');
    }
    code.append(start);
    // $NON-NLS-1$
    code.append("\\psgrid[");
    code.append(getParamsCode(ppc, unit));
    code.append(']');
    code.append(coord);
    code.append(end);
    return code.toString();
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 65 with IPoint

use of net.sf.latexdraw.models.interfaces.shape.IPoint in project latexdraw by arnobl.

the class PSTPolygonView method getPointsCode.

/**
 * @param position The reference point of the PSTricks drawing.
 * @param ppc The number of pixels per centimetre.
 * @return The PSTricks code of the polygon coordinates.
 * @since 3.0
 */
protected StringBuilder getPointsCode(final IPoint position, final float ppc) {
    if (!MathUtils.INST.isValidPt(position) || ppc < 1)
        return null;
    IPoint p;
    int i;
    final int size = shape.getNbPoints();
    final StringBuilder points = new StringBuilder();
    for (i = 0; i < size; i++) {
        p = shape.getPtAt(i);
        points.append('(').append(MathUtils.INST.getCutNumberFloat((p.getX() - position.getX()) / ppc));
        points.append(',').append(MathUtils.INST.getCutNumberFloat((position.getY() - p.getY()) / ppc)).append(')');
    }
    return points;
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Aggregations

IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)191 Test (org.junit.Test)45 HelperTest (net.sf.latexdraw.HelperTest)25 Theory (org.junit.experimental.theories.Theory)21 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)15 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)11 SVGGElement (net.sf.latexdraw.parsers.svg.SVGGElement)11 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)10 ILine (net.sf.latexdraw.models.interfaces.shape.ILine)10 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)9 IGroup (net.sf.latexdraw.models.interfaces.shape.IGroup)9 ArrayList (java.util.ArrayList)8 MathUtils (net.sf.latexdraw.models.MathUtils)8 Collections (java.util.Collections)7 IPolygon (net.sf.latexdraw.models.interfaces.shape.IPolygon)7 Arrays (java.util.Arrays)6 Cursor (javafx.scene.Cursor)6 BorderPos (net.sf.latexdraw.models.interfaces.shape.BorderPos)6 IModifiablePointsShape (net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape)6 Inject (net.sf.latexdraw.util.Inject)6