Search in sources :

Example 1 with IFreehand

use of net.sf.latexdraw.models.interfaces.shape.IFreehand 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 2 with IFreehand

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

the class LShapeFactory method createFreeHandFrom.

@Override
public IFreehand createFreeHandFrom(final IFreehand 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 IFreehand copy = createFreeHand(pts);
    copy.copy(sh);
    return copy;
}
Also used : IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) ArrayList(java.util.ArrayList) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 3 with IFreehand

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

the class TestCanvasCreation method testDrawFreeHand.

@Test
public void testDrawFreeHand() {
    pencil.setCurrentChoice(EditionChoice.FREE_HAND);
    pencil.getGroupParams().setInterval(1);
    final Point2D pos = point(canvas).query();
    drag(pos, MouseButton.PRIMARY).dropBy(100d, 200d).sleep(SLEEP);
    assertEquals(1, drawing.size());
    assertTrue(drawing.getShapeAt(0) instanceof IFreehand);
    assertEquals(100d, drawing.getShapeAt(0).getWidth(), 1d);
    assertEquals(200d, drawing.getShapeAt(0).getHeight(), 1d);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getX(), drawing.getShapeAt(0).getTopLeftPoint().getX(), 1d);
    assertEquals(-Canvas.getMargins() + canvas.screenToLocal(pos).getY(), drawing.getShapeAt(0).getTopLeftPoint().getY(), 1d);
}
Also used : IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) Point2D(javafx.geometry.Point2D) Test(org.junit.Test)

Example 4 with IFreehand

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

the class TestModifyShapeProperty method configureShapes.

private void configureShapes() {
    final IGrid grid = ShapeFactory.INST.createGrid(ShapeFactory.INST.createPoint());
    final IAxes axes = ShapeFactory.INST.createAxes(ShapeFactory.INST.createPoint());
    final IDot dot = ShapeFactory.INST.createDot(ShapeFactory.INST.createPoint());
    final ICircle circle = ShapeFactory.INST.createCircle();
    final IEllipse ell = ShapeFactory.INST.createEllipse();
    final IText txt = ShapeFactory.INST.createText();
    final IBezierCurve bc = ShapeFactory.INST.createBezierCurve(Collections.emptyList());
    final IPolyline pl = ShapeFactory.INST.createPolyline(Collections.emptyList());
    final IPolygon pg = ShapeFactory.INST.createPolygon(Collections.emptyList());
    final ITriangle tr = ShapeFactory.INST.createTriangle();
    final IRhombus rh = ShapeFactory.INST.createRhombus();
    final IRectangle r1 = ShapeFactory.INST.createRectangle();
    final IPlot plot = ShapeFactory.INST.createPlot(ShapeFactory.INST.createPoint(), 0d, 1d, "x", false);
    final ICircleArc carc = ShapeFactory.INST.createCircleArc();
    final ISquare sq = ShapeFactory.INST.createSquare();
    final IFreehand fh = ShapeFactory.INST.createFreeHand(Collections.emptyList());
    r1.setLineStyle(LineStyle.DASHED);
    r1.setBordersPosition(BorderPos.INTO);
    r1.setFillingStyle(FillingStyle.PLAIN);
    r1.setThickness(2.3);
    r1.setHasDbleBord(true);
    r1.setLineArc(0.2);
    r1.setDbleBordSep(1.3);
    r1.setHatchingsAngle(0.33);
    r1.setHatchingsSep(9.1);
    r1.setHatchingsWidth(12.11);
    r1.setShadowAngle(0.1);
    r1.setGradMidPt(0.66);
    r1.setHatchingsCol(DviPsColors.CYAN);
    r1.setLineColour(DviPsColors.NAVYBLUE);
    r1.setShadowSize(87.2);
    r1.setFillingCol(DviPsColors.CARNATIONPINK);
    r1.setShadowCol(DviPsColors.CORNFLOWERBLUE);
    r1.setDashSepBlack(1.2);
    r1.setDashSepWhite(2.1);
    r1.setDotSep(23.1);
    r1.setGradAngle(1.3);
    r1.setDbleBordCol(DviPsColors.RED);
    r1.setGradColEnd(DviPsColors.BITTERSWEET);
    r1.setGradColStart(DviPsColors.FORESTGREEN);
    r1.setShowPts(true);
    final IRectangle r2 = ShapeFactory.INST.createRectangle();
    r2.setLineStyle(LineStyle.SOLID);
    r2.setBordersPosition(BorderPos.MID);
    r2.setFillingStyle(FillingStyle.HLINES);
    r2.setThickness(6.3);
    r2.setHasShadow(true);
    r2.setLineArc(0.33);
    r2.setDbleBordSep(2.3);
    r2.setHatchingsAngle(-0.53);
    r2.setHatchingsSep(1.1);
    r2.setHatchingsWidth(2.11);
    r2.setShadowAngle(-0.1);
    r2.setGradMidPt(0.31);
    r2.setHatchingsCol(DviPsColors.APRICOT);
    r2.setLineColour(DviPsColors.YELLOW);
    r2.setShadowSize(8.1);
    r2.setFillingCol(DviPsColors.CERULEAN);
    r2.setShadowCol(DviPsColors.DARKORCHID);
    r1.setDashSepBlack(11.2);
    r1.setDashSepWhite(21.1);
    r1.setDotSep(231.1);
    r1.setGradAngle(11.3);
    r1.setDbleBordCol(DviPsColors.ROYALBLUE);
    r1.setGradColEnd(DviPsColors.CADETBLUE);
    r1.setGradColStart(DviPsColors.OLIVE);
    txt.copy(r1);
    ell.copy(r1);
    circle.copy(r2);
    dot.copy(r2);
    bc.copy(r2);
    pl.copy(r1);
    pg.copy(r2);
    tr.copy(r1);
    rh.copy(r2);
    plot.copy(r1);
    carc.copy(r2);
    sq.copy(r1);
    fh.copy(r2);
    group.addShape(r1);
    group.addShape(txt);
    group.addShape(grid);
    group.addShape(pl);
    group.addShape(pg);
    group.addShape(r2);
    group.addShape(axes);
    group.addShape(ell);
    group.addShape(circle);
    group.addShape(tr);
    group.addShape(rh);
    group.addShape(dot);
    group.addShape(bc);
    group.addShape(plot);
    group.addShape(carc);
    group.addShape(sq);
    group.addShape(fh);
}
Also used : IPlot(net.sf.latexdraw.models.interfaces.shape.IPlot) ICircle(net.sf.latexdraw.models.interfaces.shape.ICircle) IDot(net.sf.latexdraw.models.interfaces.shape.IDot) IEllipse(net.sf.latexdraw.models.interfaces.shape.IEllipse) IGrid(net.sf.latexdraw.models.interfaces.shape.IGrid) IAxes(net.sf.latexdraw.models.interfaces.shape.IAxes) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon) IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) ITriangle(net.sf.latexdraw.models.interfaces.shape.ITriangle) ICircleArc(net.sf.latexdraw.models.interfaces.shape.ICircleArc) IText(net.sf.latexdraw.models.interfaces.shape.IText) ISquare(net.sf.latexdraw.models.interfaces.shape.ISquare) IRhombus(net.sf.latexdraw.models.interfaces.shape.IRhombus) IRectangle(net.sf.latexdraw.models.interfaces.shape.IRectangle)

Example 5 with IFreehand

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

the class TestParsingPscustom method testPsCustomFreeHandOpen.

@Test
public void testPsCustomFreeHandOpen() {
    parser("\\pscustom{\\moveto(0.0,2.64)\\lineto(0.19,2.82)\\curveto(0.285,2.91)(1.49,3.16)(2.6,3.32)" + "\\curveto(3.71,3.48)(5.625,3.205)(6.43,2.77)\\curveto(7.235,2.335)(8.07,1.135)(8.1,0.37)" + "\\curveto(8.13,-0.395)(7.64,-1.63)(7.12,-2.1)\\curveto(6.6,-2.57)(5.45,-3.18)(4.82,-3.32)}");
    assertEquals(1, listener.getShapes().size());
    IFreehand fh = getShapeAt(0);
    assertEquals(7, fh.getNbPoints());
    assertEquals(0d, fh.getPtAt(0).getX(), 0.001);
    assertEquals(-2.64 * IShape.PPC, fh.getPtAt(0).getY(), 0.001);
    assertEquals(0.19 * IShape.PPC, fh.getPtAt(1).getX(), 0.001);
    assertEquals(-2.82 * IShape.PPC, fh.getPtAt(1).getY(), 0.001);
    assertEquals(2.6 * IShape.PPC, fh.getPtAt(2).getX(), 0.001);
    assertEquals(-3.32 * IShape.PPC, fh.getPtAt(2).getY(), 0.001);
    assertEquals(6.43 * IShape.PPC, fh.getPtAt(3).getX(), 0.001);
    assertEquals(-2.77 * IShape.PPC, fh.getPtAt(3).getY(), 0.001);
    assertEquals(8.1 * IShape.PPC, fh.getPtAt(4).getX(), 0.001);
    assertEquals(-0.37 * IShape.PPC, fh.getPtAt(4).getY(), 0.001);
    assertTrue(fh.isOpened());
    assertEquals(FreeHandStyle.CURVES, fh.getType());
}
Also used : IFreehand(net.sf.latexdraw.models.interfaces.shape.IFreehand) Test(org.junit.Test)

Aggregations

IFreehand (net.sf.latexdraw.models.interfaces.shape.IFreehand)14 Test (org.junit.Test)7 Point2D (javafx.geometry.Point2D)3 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)2 IGroup (net.sf.latexdraw.models.interfaces.shape.IGroup)2 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)2 IPolygon (net.sf.latexdraw.models.interfaces.shape.IPolygon)2 IPolyline (net.sf.latexdraw.models.interfaces.shape.IPolyline)2 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)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 Point3D (javafx.geometry.Point3D)1 Cursor (javafx.scene.Cursor)1 MouseButton (javafx.scene.input.MouseButton)1 FileChooser (javafx.stage.FileChooser)1