Search in sources :

Example 1 with IControlPointShape

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

the class Border method configureBindings.

@Override
protected void configureBindings() {
    addBinding(new DnD2Scale(this));
    configureMovePointBinding();
    nodeBinder(MoveCtrlPoint.class, new DnD()).on(ctrlPt1Handlers).on(ctrlPt2Handlers).first((c, i) -> {
        final IGroup group = canvas.getDrawing().getSelection();
        if (group.size() == 1 && group.getShapeAt(0) instanceof IControlPointShape) {
            c.setPoint(i.getSrcObject().map(h -> ((CtrlPointHandler) h).getPoint()).orElse(null));
            c.setShape((IControlPointShape) group.getShapeAt(0));
            c.setIsFirstCtrlPt(ctrlPt1Handlers.contains(i.getSrcObject().orElse(null)));
        }
    }).then((c, i) -> {
        final Point3D startPt = i.getSrcObject().map(n -> n.localToParent(i.getSrcLocalPoint())).orElse(new Point3D(0d, 0d, 0d));
        final Point3D endPt = i.getSrcObject().map(n -> n.localToParent(i.getEndLocalPt())).orElse(new Point3D(0d, 0d, 0d));
        final IPoint ptToMove = i.getSrcObject().map(n -> ((CtrlPointHandler) n).getPoint()).orElse(ShapeFactory.INST.createPoint());
        final double x = ptToMove.getX() + endPt.getX() - startPt.getX();
        final double y = ptToMove.getY() + endPt.getY() - startPt.getY();
        c.setNewCoord(grid.getTransformedPointToGrid(new Point3D(x, y, 0d)));
    }).exec().bind();
    nodeBinder(RotateShapes.class, new DnD()).on(rotHandler).first((c, i) -> {
        final IDrawing drawing = canvas.getDrawing();
        c.setGravityCentre(drawing.getSelection().getGravityCentre());
        c.getGc().translate(canvas.getOrigin().getX(), canvas.getOrigin().getY());
        c.setShape(drawing.getSelection().duplicateDeep(false));
    }).then((c, i) -> c.setRotationAngle(c.getGc().computeRotationAngle(ShapeFactory.INST.createPoint(canvas.sceneToLocal(i.getSrcScenePoint())), ShapeFactory.INST.createPoint(canvas.sceneToLocal(i.getEndScenePt()))))).exec().bind();
    addBinding(new DnD2ArcAngle(this));
}
Also used : Arrays(java.util.Arrays) Initializable(javafx.fxml.Initializable) Command(org.malai.command.Command) MovePtHandler(net.sf.latexdraw.handlers.MovePtHandler) Point3D(javafx.geometry.Point3D) URL(java.net.URL) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) ScaleHandler(net.sf.latexdraw.handlers.ScaleHandler) FXCollections(javafx.collections.FXCollections) MathUtils(net.sf.latexdraw.models.MathUtils) MovePointShape(net.sf.latexdraw.commands.shape.MovePointShape) JfXWidgetBinding(org.malai.javafx.binding.JfXWidgetBinding) Function(java.util.function.Function) IArc(net.sf.latexdraw.models.interfaces.shape.IArc) Position(net.sf.latexdraw.models.interfaces.shape.Position) Inject(net.sf.latexdraw.util.Inject) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) ResourceBundle(java.util.ResourceBundle) ListChangeListener(javafx.collections.ListChangeListener) IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) ScaleShapes(net.sf.latexdraw.commands.shape.ScaleShapes) DnD(org.malai.javafx.interaction.library.DnD) ArcAngleHandler(net.sf.latexdraw.handlers.ArcAngleHandler) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) Node(javafx.scene.Node) ShapeProperties(net.sf.latexdraw.commands.shape.ShapeProperties) ModifyShapeProperty(net.sf.latexdraw.commands.shape.ModifyShapeProperty) RotationHandler(net.sf.latexdraw.handlers.RotationHandler) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IBezierCurve(net.sf.latexdraw.models.interfaces.shape.IBezierCurve) Collectors(java.util.stream.Collectors) MoveCtrlPoint(net.sf.latexdraw.commands.shape.MoveCtrlPoint) Cursor(javafx.scene.Cursor) List(java.util.List) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) CtrlPointHandler(net.sf.latexdraw.handlers.CtrlPointHandler) ObservableList(javafx.collections.ObservableList) Handler(net.sf.latexdraw.handlers.Handler) RotateShapes(net.sf.latexdraw.commands.shape.RotateShapes) RotateShapes(net.sf.latexdraw.commands.shape.RotateShapes) CtrlPointHandler(net.sf.latexdraw.handlers.CtrlPointHandler) IDrawing(net.sf.latexdraw.models.interfaces.shape.IDrawing) Point3D(javafx.geometry.Point3D) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD)

Example 2 with IControlPointShape

use of net.sf.latexdraw.models.interfaces.shape.IControlPointShape 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.setOnArrowChanged(null));
    model.getPoints().forEach(pt -> {
        pt.xProperty().removeListener(updateArrow);
        pt.yProperty().removeListener(updateArrow);
    });
    if (model instanceof IControlPointShape) {
        ((IControlPointShape) model).getFirstCtrlPts().forEach(pt -> {
            pt.xProperty().removeListener(updateArrow);
            pt.yProperty().removeListener(updateArrow);
        });
    }
    super.flush();
}
Also used : IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 3 with IControlPointShape

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

the class TestIControlPointShape method testDuplicate.

@Theory
public void testDuplicate(@CtrlShapeData final IControlPointShape sh) {
    sh.translate(10d, -12d);
    final IControlPointShape dup = sh.duplicate();
    assertEquals(sh.getFirstCtrlPts(), dup.getFirstCtrlPts());
    assertEquals(sh.getSecondCtrlPts(), dup.getSecondCtrlPts());
}
Also used : IControlPointShape(net.sf.latexdraw.models.interfaces.shape.IControlPointShape) Theory(org.junit.experimental.theories.Theory)

Example 4 with IControlPointShape

use of net.sf.latexdraw.models.interfaces.shape.IControlPointShape 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)

Aggregations

IControlPointShape (net.sf.latexdraw.models.interfaces.shape.IControlPointShape)4 IPoint (net.sf.latexdraw.models.interfaces.shape.IPoint)3 Arrays (java.util.Arrays)2 Function (java.util.function.Function)2 Point3D (javafx.geometry.Point3D)2 Cursor (javafx.scene.Cursor)2 MathUtils (net.sf.latexdraw.models.MathUtils)2 ShapeFactory (net.sf.latexdraw.models.ShapeFactory)2 IBezierCurve (net.sf.latexdraw.models.interfaces.shape.IBezierCurve)2 IGroup (net.sf.latexdraw.models.interfaces.shape.IGroup)2 IModifiablePointsShape (net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape)2 IShape (net.sf.latexdraw.models.interfaces.shape.IShape)2 Inject (net.sf.latexdraw.util.Inject)2 DnD (org.malai.javafx.interaction.library.DnD)2 URL (java.net.URL)1 Collections (java.util.Collections)1 List (java.util.List)1 ResourceBundle (java.util.ResourceBundle)1 Collectors (java.util.stream.Collectors)1 Platform (javafx.application.Platform)1