Search in sources :

Example 16 with IPolyline

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

the class Pencil method bindMultiClic2AddShape.

/**
 * Binds a multi-click interaction to creates multi-point shapes.
 */
private void bindMultiClic2AddShape() {
    final Function<MultiClick, AddShape> creation = i -> new AddShape(setInitialPtsShape(createShapeInstance(), i.getPoints().get(0)), canvas.getDrawing());
    // Binding for polygons
    nodeBinder(AddShape.class, new MultiClick(3)).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolygonFrom((IPolygon) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.POLYGON).and(activatedProp));
    // Binding for polyline
    nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolylineFrom((IPolyline) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.LINES).and(activatedProp));
    // Binding for bézier curves
    nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
        final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createBezierCurveFrom((IBezierCurve) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        ((IControlPointShape) c.getShape().get()).balance();
        canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
    }).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.BEZIER_CURVE).and(activatedProp));
}
Also used : MultiClick(org.malai.javafx.interaction.library.MultiClick) 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) AddShape(net.sf.latexdraw.commands.shape.AddShape) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IPolygon(net.sf.latexdraw.models.interfaces.shape.IPolygon)

Example 17 with IPolyline

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

the class TestParsingPsline method testFloatSigns.

@Test
public void testFloatSigns() {
    parser("\\psline(+++35.5,--50.5)(--+12, -1)");
    final IPolyline line = (IPolyline) listener.getShapes().get(0);
    assertEquals(35.5 * IShape.PPC, line.getPtAt(0).getX(), 0.0001);
    assertEquals(-50.5 * IShape.PPC, line.getPtAt(0).getY(), 0.0001);
    assertEquals(12d * IShape.PPC, line.getPtAt(1).getX(), 0.0001);
    assertEquals(1d * IShape.PPC, line.getPtAt(1).getY(), 0.0001);
}
Also used : IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) Test(org.junit.Test)

Example 18 with IPolyline

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

the class TestParsingPsline method testParse1Coordinates.

@Test
public void testParse1Coordinates() {
    parser("\\psline(5,10)");
    final IPolyline line = (IPolyline) listener.getShapes().get(0);
    assertEquals(2, line.getNbPoints());
    assertEquals(0d, line.getPtAt(0).getX(), 0.0001);
    assertEquals(0d, line.getPtAt(0).getY(), 0.0001);
    assertEquals(5d * IShape.PPC, line.getPtAt(1).getX(), 0.0001);
    assertEquals(-10d * IShape.PPC, line.getPtAt(1).getY(), 0.0001);
}
Also used : IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) Test(org.junit.Test)

Example 19 with IPolyline

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

the class TestParsingPsline method testCoordinatesMm.

@Test
public void testCoordinatesMm() {
    parser("\\psline(350mm,200mm)(10mm, 30.3mm)");
    final IPolyline line = (IPolyline) listener.getShapes().get(0);
    assertEquals(2, line.getNbPoints());
    assertEquals(35d * IShape.PPC, line.getPtAt(0).getX(), 0.0001);
    assertEquals(-20d * IShape.PPC, line.getPtAt(0).getY(), 0.0001);
    assertEquals(1d * IShape.PPC, line.getPtAt(1).getX(), 0.0001);
    assertEquals(-3.03 * IShape.PPC, line.getPtAt(1).getY(), 0.0001);
}
Also used : IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) Test(org.junit.Test)

Example 20 with IPolyline

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

the class TestParsingPsline method testUnit.

@Test
public void testUnit() {
    parser("\\psset{unit=2}\\psline[linewidth=0.3,linestyle=dashed](2,3)(1cm,2cm)");
    final IPolyline sh = (IPolyline) listener.getShapes().get(0);
    assertEquals(2d * 2d * IShape.PPC, sh.getPtAt(0).getX(), 0.0001);
    assertEquals(-3d * 2d * IShape.PPC, sh.getPtAt(0).getY(), 0.0001);
    assertEquals(IShape.PPC, sh.getPtAt(1).getX(), 0.0001);
    assertEquals(-2d * IShape.PPC, sh.getPtAt(1).getY(), 0.0001);
}
Also used : IPolyline(net.sf.latexdraw.models.interfaces.shape.IPolyline) Test(org.junit.Test)

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