Search in sources :

Example 66 with IPoint

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

the class PSTRectView method getCode.

@Override
public String getCode(final IPoint position, final float ppc) {
    if (!MathUtils.INST.isValidPt(position) || ppc < 1)
        return "";
    final StringBuilder params = getPropertiesCode(ppc);
    final IPoint tl = shape.getTopLeftPoint();
    final IPoint br = shape.getBottomRightPoint();
    final double x1 = tl.getX() - position.getX();
    final double x2 = br.getX() - position.getX();
    final double y1 = position.getY() - tl.getY();
    final double y2 = position.getY() - br.getY();
    final StringBuilder code = new StringBuilder();
    // $NON-NLS-1$
    if (shape.isRoundCorner())
        params.append(", framearc=").append(MathUtils.INST.getCutNumberFloat(shape.getLineArc()));
    final StringBuilder rotation = getRotationHeaderCode(ppc, position);
    if (rotation != null)
        code.append(rotation);
    // $NON-NLS-1$
    code.append("\\psframe[");
    code.append(params);
    code.append(']').append('(');
    code.append(MathUtils.INST.getCutNumberFloat(x2 / ppc)).append(',');
    code.append(MathUtils.INST.getCutNumberFloat(y1 / ppc)).append(')').append('(');
    code.append(MathUtils.INST.getCutNumberFloat(x1 / ppc)).append(',');
    code.append(MathUtils.INST.getCutNumberFloat(y2 / ppc)).append(')');
    if (rotation != null)
        code.append('}');
    return code.toString();
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 67 with IPoint

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

the class Pencil method bindDnDToDrawFreeHandShape.

/**
 * Binds a DnD interaction to create shape.
 */
private void bindDnDToDrawFreeHandShape() {
    nodeBinder(AddShape.class, new DnD(false, true)).on(canvas).map(i -> {
        final IShape sh = createShapeInstance();
        final IPoint pt = getAdaptedPoint(i.getSrcLocalPoint());
        sh.getPoints().get(0).setPoint(pt.getX(), pt.getY());
        return new AddShape(sh, canvas.getDrawing());
    }).first((c, i) -> Platform.runLater(() -> canvas.requestFocus())).then((c, i) -> {
        final IPoint last = c.getShape().get().getPtAt(-1);
        final IPoint endPt = getAdaptedPoint(i.getEndLocalPt());
        if (!MathUtils.INST.equalsDouble(last.getX(), endPt.getX(), 0.0001) && !MathUtils.INST.equalsDouble(last.getY(), endPt.getY(), 0.0001)) {
            c.setShape(ShapeFactory.INST.createFreeHandFrom((IFreehand) c.getShape().get(), endPt));
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY && currentChoice.get() == EditionChoice.FREE_HAND).strictStart().bind();
}
Also used : ISquaredShape(net.sf.latexdraw.models.interfaces.shape.ISquaredShape) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) IPositionShape(net.sf.latexdraw.models.interfaces.shape.IPositionShape) Point3D(javafx.geometry.Point3D) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) IRectangularShape(net.sf.latexdraw.models.interfaces.shape.IRectangularShape) MathUtils(net.sf.latexdraw.models.MathUtils) AddShape(net.sf.latexdraw.commands.shape.AddShape) Function(java.util.function.Function) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) InsertPicture(net.sf.latexdraw.commands.shape.InsertPicture) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) ObjectProperty(javafx.beans.property.ObjectProperty) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) LangTool(net.sf.latexdraw.util.LangTool) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) InitTextSetter(net.sf.latexdraw.commands.shape.InitTextSetter) MultiClick(org.malai.javafx.interaction.library.MultiClick) Platform(javafx.application.Platform) Cursor(javafx.scene.Cursor) FileChooser(javafx.stage.FileChooser) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) Press(org.malai.javafx.interaction.library.Press) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Collections(java.util.Collections) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) AddShape(net.sf.latexdraw.commands.shape.AddShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD) IShape(net.sf.latexdraw.models.interfaces.shape.IShape)

Example 68 with IPoint

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

the class LAxes method getArrowLineY.

/**
 * @return The line of the Y-axis.
 */
private ILine getArrowLineY(final boolean topY) {
    final IPoint pos = getPosition();
    final IPoint p2 = ShapeFactory.INST.createPoint(pos.getX(), pos.getY() - getGridEndY() * IShape.PPC);
    final IPoint p1 = ShapeFactory.INST.createPoint(pos.getX(), pos.getY() - getGridStartY() * IShape.PPC);
    if (topY) {
        return ShapeFactory.INST.createLine(p2, p1);
    }
    return ShapeFactory.INST.createLine(p1, p2);
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 69 with IPoint

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

the class LAxes method getArrowLineX.

/**
 * @return The line of the X-axis.
 */
private ILine getArrowLineX(final boolean leftX) {
    final IPoint pos = getPosition();
    final IPoint p2 = ShapeFactory.INST.createPoint(pos.getX() + getGridEndX() * IShape.PPC, pos.getY());
    final IPoint p1 = ShapeFactory.INST.createPoint(pos.getX() + getGridStartX() * IShape.PPC, pos.getY());
    if (leftX) {
        return ShapeFactory.INST.createLine(p1, p2);
    }
    return ShapeFactory.INST.createLine(p2, p1);
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 70 with IPoint

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

the class LCircleArc method getArrowLine.

@Override
public ILine getArrowLine(final int index) {
    final IArrow arrow = getArrowAt(index);
    if (arrow == null) {
        return null;
    }
    // Computing the angle to use for the second point of the line:
    // the length of the arrow and the radius are used to compute the angle that separates the two points of the line.
    final double gap = Math.asin(Math.max(-1d, Math.min(1d, arrow.getArrowShapeLength() / getRadius())));
    if (index == 0) {
        final IPoint sp = getStartPoint();
        final IPoint ep = getPointOnArc(getAngleStart() < getAngleEnd() ? getAngleStart() + gap : getAngleStart() - gap);
        return ShapeFactory.INST.createLine(sp, ep);
    }
    // For sure index == 1 here.
    final IPoint sp = getEndPoint();
    final IPoint ep = getPointOnArc(getAngleEnd() < getAngleStart() ? getAngleEnd() + gap : getAngleEnd() - gap);
    return ShapeFactory.INST.createLine(sp, ep);
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IArrow(net.sf.latexdraw.models.interfaces.shape.IArrow)

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