Search in sources :

Example 11 with IPolyline

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

the class SVGAxes method createArrows.

private void createArrows(final SVGElement elt, final SVGDocument document) {
    if (shape.getAxesStyle().supportsArrows() && shape.getNbArrows() == 4) {
        final double posX = shape.getPosition().getX();
        final double posY = shape.getPosition().getY();
        final IArrow arr0 = shape.getArrowAt(1);
        final IArrow arr1 = shape.getArrowAt(3);
        final double arr0Reduction = arr0.getArrowStyle().needsLineReduction() ? arr0.getArrowShapedWidth() : 0.;
        final double arr1Reduction = arr1.getArrowStyle().needsLineReduction() ? arr1.getArrowShapedWidth() : 0.;
        final IPolyline xLine = ShapeFactory.INST.createPolyline(Arrays.asList(ShapeFactory.INST.createPoint(posX + shape.getGridStartX() * IShape.PPC + arr0Reduction, posY), ShapeFactory.INST.createPoint(posX + shape.getGridEndX() * IShape.PPC - arr1Reduction, posY)));
        final IPolyline yLine = ShapeFactory.INST.createPolyline(Arrays.asList(ShapeFactory.INST.createPoint(posX, posY - shape.getGridStartY() * IShape.PPC - arr0Reduction), ShapeFactory.INST.createPoint(posX, posY - shape.getGridEndY() * IShape.PPC + arr1Reduction)));
        xLine.getArrowAt(0).copy(arr0);
        xLine.getArrowAt(1).copy(arr1);
        yLine.getArrowAt(0).copy(shape.getArrowAt(0));
        yLine.getArrowAt(1).copy(shape.getArrowAt(2));
        final SVGElement eltX = new SVGPolylines(xLine).toSVG(document);
        final SVGElement eltY = new SVGPolylines(yLine).toSVG(document);
        final String transform = "translate(" + MathUtils.INST.format.format(-shape.getPosition().getX()) + ',' + MathUtils.INST.format.format(-shape.getPosition().getY()) + ')';
        eltX.setAttribute(SVGAttributes.SVG_TRANSFORM, transform);
        eltY.setAttribute(SVGAttributes.SVG_TRANSFORM, transform);
        elt.appendChild(eltX);
        elt.appendChild(eltY);
    }
}
Also used : SVGElement(net.sf.latexdraw.parsers.svg.SVGElement) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow)

Example 12 with IPolyline

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

the class TestCanvasCreation method testDrawPolylines.

@Test
public void testDrawPolylines() {
    pencil.setCurrentChoice(EditionChoice.LINES);
    final Point2D pos = point(canvas).query();
    moveTo(pos).clickOn(MouseButton.PRIMARY).moveBy(-20d, -100d).clickOn(MouseButton.PRIMARY).moveBy(-100d, 50d).clickOn(MouseButton.SECONDARY).sleep(SLEEP);
    assertEquals(1, drawing.size());
    assertTrue(drawing.getShapeAt(0) instanceof IPolyline);
    final IPolyline sh = (IPolyline) drawing.getShapeAt(0);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getX(), sh.getPtAt(0).getX(), 1d);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getY(), sh.getPtAt(0).getY(), 1d);
    assertEquals(3, sh.getNbPoints());
}
Also used : Point2D(javafx.geometry.Point2D) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) Test(org.junit.Test)

Example 13 with IPolyline

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

the class LShapeFactory method createPolylineFrom.

@Override
public IPolyline createPolylineFrom(final IPolyline sh, final IPoint pointToAdd) {
    if (sh == null || !MathUtils.INST.isValidPt(pointToAdd))
        return null;
    final List<IPoint> pts = new ArrayList<>(sh.getPoints());
    pts.add(pointToAdd);
    final IPolyline copy = createPolyline(pts);
    copy.copy(sh);
    return copy;
}
Also used : IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) ArrayList(java.util.ArrayList) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 14 with IPolyline

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

the class PSTLatexdrawListener method createLine.

/**
 * Creates and initialises a polyline shape.
 */
private IPolyline createLine(final boolean hasStar, final List<IPoint> points, final PSTContext ctx, final boolean qObject) {
    final IPolyline line = ShapeFactory.INST.createPolyline(points);
    setShapeParameters(line, ctx);
    setArrows(line, ctx);
    if (qObject) {
        line.setHasShadow(false);
        line.setHasDbleBord(false);
        line.setFillingStyle(FillingStyle.NONE);
        line.setArrowStyle(ArrowStyle.NONE, 0);
        line.setArrowStyle(ArrowStyle.NONE, -1);
    }
    if (hasStar) {
        setShapeForStar(line);
    }
    return line;
}
Also used : IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline)

Example 15 with IPolyline

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

the class PlotViewHelper method updateLine.

public IPolyline updateLine(final IPlot shape, final double posX, final double posY, final double minX, final double maxX, final double step) {
    final IPolyline pl = ShapeFactory.INST.createPolyline(fillPoints(shape, posX, posY, minX, maxX, step));
    pl.copy(shape);
    return pl;
}
Also used : IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline)

Aggregations

IPolyline (net.sf.latexdraw.models.interfaces.shape.IPolyline)25 Test (org.junit.Test)17 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)4 IPolygon (net.sf.latexdraw.models.interfaces.shape.IPolygon)3 HelperTest (net.sf.latexdraw.HelperTest)2 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)2 ICircle (net.sf.latexdraw.models.interfaces.shape.ICircle)2 IFreehand (net.sf.latexdraw.models.interfaces.shape.IFreehand)2 IModifiablePointsShape (net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape)2 IRectangle (net.sf.latexdraw.models.interfaces.shape.IRectangle)2 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)2 SVGElement (net.sf.latexdraw.parsers.svg.SVGElement)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Function (java.util.function.Function)1 Platform (javafx.application.Platform)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 Point2D (javafx.geometry.Point2D)1