Search in sources :

Example 1 with ControlPointShape

use of net.sf.latexdraw.model.api.shape.ControlPointShape 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<PointsData, AddShape> creation = i -> new AddShape(setInitialPtsShape(editing.createShapeInstance(), i.getPointsData().get(0).getSrcLocalPoint()), canvas.getDrawing());
    // Binding for polygons
    nodeBinder().usingInteraction(() -> new MultiClick(3)).toProduce(creation).on(canvas).then((i, c) -> {
        final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolygonFrom((Polygon) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
    }).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.POLYGON).bind();
    // Binding for polyline
    nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
        final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createPolylineFrom((Polyline) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
    }).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.LINES).bind();
    // Binding for bézier curves
    nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
        final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
        if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
            c.setShape(ShapeFactory.INST.createBezierCurveFrom((BezierCurve) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
        } else {
            ((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
        }
        ((ControlPointShape) c.getShape()).balance();
        canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
    }).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.BEZIER_CURVE).bind();
}
Also used : EditingService(net.sf.latexdraw.service.EditingService) Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) Freehand(net.sf.latexdraw.model.api.shape.Freehand) Point3D(javafx.geometry.Point3D) BorderPos(net.sf.latexdraw.model.api.shape.BorderPos) InsertPicture(net.sf.latexdraw.command.shape.InsertPicture) Function(java.util.function.Function) Polyline(net.sf.latexdraw.model.api.shape.Polyline) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Shape(net.sf.latexdraw.model.api.shape.Shape) Inject(net.sf.latexdraw.util.Inject) PointsData(io.github.interacto.jfx.interaction.library.PointsData) MathUtils(net.sf.latexdraw.model.MathUtils) AddShape(net.sf.latexdraw.command.shape.AddShape) Canvas(net.sf.latexdraw.view.jfx.Canvas) ViewFactory(net.sf.latexdraw.view.jfx.ViewFactory) Click(io.github.interacto.jfx.interaction.library.Click) InitTextSetter(net.sf.latexdraw.command.shape.InitTextSetter) MultiClick(io.github.interacto.jfx.interaction.library.MultiClick) ModifiablePointsShape(net.sf.latexdraw.model.api.shape.ModifiablePointsShape) Polygon(net.sf.latexdraw.model.api.shape.Polygon) Press(io.github.interacto.jfx.interaction.library.Press) PositionShape(net.sf.latexdraw.model.api.shape.PositionShape) Point(net.sf.latexdraw.model.api.shape.Point) MagneticGrid(net.sf.latexdraw.view.jfx.MagneticGrid) Objects(java.util.Objects) FileChooser(javafx.stage.FileChooser) SquaredShape(net.sf.latexdraw.model.api.shape.SquaredShape) RectangularShape(net.sf.latexdraw.model.api.shape.RectangularShape) NotNull(org.jetbrains.annotations.NotNull) DnD(io.github.interacto.jfx.interaction.library.DnD) MultiClick(io.github.interacto.jfx.interaction.library.MultiClick) PointsData(io.github.interacto.jfx.interaction.library.PointsData) AddShape(net.sf.latexdraw.command.shape.AddShape) Polyline(net.sf.latexdraw.model.api.shape.Polyline) ModifiablePointsShape(net.sf.latexdraw.model.api.shape.ModifiablePointsShape) Point(net.sf.latexdraw.model.api.shape.Point) Polygon(net.sf.latexdraw.model.api.shape.Polygon) BezierCurve(net.sf.latexdraw.model.api.shape.BezierCurve) ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape)

Example 2 with ControlPointShape

use of net.sf.latexdraw.model.api.shape.ControlPointShape in project latexdraw by arnobl.

the class ViewArrowableTrait method flush.

@Override
public void flush() {
    final int nbPts = model.getNbPoints();
    model.getPtAt(0).xProperty().removeListener(updateArrow);
    model.getPtAt(0).yProperty().removeListener(updateArrow);
    model.getPtAt(-1).xProperty().removeListener(updateArrow);
    model.getPtAt(-1).yProperty().removeListener(updateArrow);
    if (nbPts > 2) {
        model.getPtAt(1).xProperty().removeListener(updateArrow);
        model.getPtAt(1).yProperty().removeListener(updateArrow);
    }
    if (nbPts > 3) {
        model.getPtAt(nbPts - 2).xProperty().removeListener(updateArrow);
        model.getPtAt(nbPts - 2).yProperty().removeListener(updateArrow);
    }
    model.thicknessProperty().removeListener(updateArrow);
    model.fillingProperty().removeListener(updateClip);
    model.dbleBordProperty().removeListener(updateArrow);
    model.dbleBordSepProperty().removeListener(updateArrow);
    model.getArrows().forEach(arr -> arr.onChanges(null));
    model.getPoints().forEach(pt -> {
        pt.xProperty().removeListener(updateArrow);
        pt.yProperty().removeListener(updateArrow);
    });
    if (model instanceof ControlPointShape) {
        ((ControlPointShape) model).getFirstCtrlPts().forEach(pt -> {
            pt.xProperty().removeListener(updateArrow);
            pt.yProperty().removeListener(updateArrow);
        });
    }
    super.flush();
}
Also used : ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) Point(net.sf.latexdraw.model.api.shape.Point)

Example 3 with ControlPointShape

use of net.sf.latexdraw.model.api.shape.ControlPointShape in project latexdraw by arnobl.

the class PolymorphCtlPtShapeTest method testCtrlPt2.

@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#createDiversifiedCtrlPtShape")
default void testCtrlPt2(final ControlPointShape sh) {
    final ControlPointShape s2 = produceOutputShapeFrom(sh);
    assertThat(sh.getSecondCtrlPts()).isEqualTo(s2.getSecondCtrlPts());
}
Also used : ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with ControlPointShape

use of net.sf.latexdraw.model.api.shape.ControlPointShape in project latexdraw by arnobl.

the class PolymorphCtlPtShapeTest method testCtrlPt1.

@ParameterizedTest
@MethodSource("net.sf.latexdraw.data.ShapeSupplier#createDiversifiedCtrlPtShape")
default void testCtrlPt1(final ControlPointShape sh) {
    final ControlPointShape s2 = produceOutputShapeFrom(sh);
    assertThat(sh.getFirstCtrlPts()).isEqualTo(s2.getFirstCtrlPts());
}
Also used : ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with ControlPointShape

use of net.sf.latexdraw.model.api.shape.ControlPointShape in project latexdraw by arnobl.

the class TestControlPointShapeBase method testDuplicateDoNotShareCtrlPoints.

@Theory
public void testDuplicateDoNotShareCtrlPoints(@CtrlShapeData final ControlPointShape shape) {
    final List<Point> ctrlPts = cloneList(shape.getFirstCtrlPts(), pt -> ShapeFactory.INST.createPoint(pt));
    final Shape sh = shape.duplicate();
    sh.translate(11d, 12d);
    assertEquals(ctrlPts, shape.getFirstCtrlPts());
}
Also used : ControlPointShape(net.sf.latexdraw.model.api.shape.ControlPointShape) Shape(net.sf.latexdraw.model.api.shape.Shape) Point(net.sf.latexdraw.model.api.shape.Point) Theory(org.junit.experimental.theories.Theory)

Aggregations

ControlPointShape (net.sf.latexdraw.model.api.shape.ControlPointShape)6 Point (net.sf.latexdraw.model.api.shape.Point)3 Shape (net.sf.latexdraw.model.api.shape.Shape)2 Theory (org.junit.experimental.theories.Theory)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Click (io.github.interacto.jfx.interaction.library.Click)1 DnD (io.github.interacto.jfx.interaction.library.DnD)1 MultiClick (io.github.interacto.jfx.interaction.library.MultiClick)1 PointsData (io.github.interacto.jfx.interaction.library.PointsData)1 Press (io.github.interacto.jfx.interaction.library.Press)1 Arrays (java.util.Arrays)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Point3D (javafx.geometry.Point3D)1 MouseButton (javafx.scene.input.MouseButton)1 FileChooser (javafx.stage.FileChooser)1 AddShape (net.sf.latexdraw.command.shape.AddShape)1 InitTextSetter (net.sf.latexdraw.command.shape.InitTextSetter)1 InsertPicture (net.sf.latexdraw.command.shape.InsertPicture)1