Search in sources :

Example 1 with IPoint

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

the class Border method configureMovePointBinding.

private void configureMovePointBinding() {
    nodeBinder(MovePointShape.class, new DnD()).on(mvPtHandlers).first((c, i) -> i.getSrcObject().filter(o -> o instanceof MovePtHandler).map(o -> (MovePtHandler) o).ifPresent(handler -> {
        final IGroup group = canvas.getDrawing().getSelection();
        if (group.size() == 1 && group.getShapeAt(0) instanceof IModifiablePointsShape) {
            c.setPoint(handler.getPoint());
            c.setShape((IModifiablePointsShape) group.getShapeAt(0));
        }
    })).then((c, i) -> i.getSrcObject().ifPresent(node -> {
        final Point3D startPt = node.localToParent(i.getSrcLocalPoint());
        final Point3D endPt = node.localToParent(i.getEndLocalPt());
        final IPoint ptToMove = ((MovePtHandler) node).getPoint();
        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().when(i -> i.getSrcLocalPoint() != null && i.getEndLocalPt() != null && i.getSrcObject().orElse(null) instanceof MovePtHandler).bind();
}
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) IModifiablePointsShape(net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape) Point3D(javafx.geometry.Point3D) MovePtHandler(net.sf.latexdraw.handlers.MovePtHandler) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) DnD(org.malai.javafx.interaction.library.DnD)

Example 2 with IPoint

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

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

the class MoveCtrlPoint method move.

private void move(final IPoint firstPt, final IPoint sndPt) {
    final int indexPt = getIndexCtrlPt();
    shape.setXFirstCtrlPt(firstPt.getX(), indexPt);
    shape.setYFirstCtrlPt(firstPt.getY(), indexPt);
    shape.setXSecondCtrlPt(sndPt.getX(), indexPt);
    shape.setYSecondCtrlPt(sndPt.getY(), indexPt);
    shape.setModified(true);
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint)

Example 4 with IPoint

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

the class TestIGroup method testGetAxesDistLabelsOk.

@Test
public void testGetAxesDistLabelsOk() {
    IPoint pt = ShapeFactory.INST.createPoint(10d, 11d);
    init4getAxes().setDistLabels(pt);
    assertEquals(pt, shape.getDistLabels());
}
Also used : IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) HelperTest(net.sf.latexdraw.HelperTest) Test(org.junit.Test)

Example 5 with IPoint

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

the class TestIGroup method testSetAxesIncrement.

@Test
public void testSetAxesIncrement() {
    init4setAxes();
    IPoint pt = ShapeFactory.INST.createPoint(13d, 14d);
    shape.setIncrement(pt);
    shape.getShapes().stream().filter(sh -> sh instanceof IAxes).map(sh -> (IAxes) sh).forEach(sh -> assertEquals(pt, sh.getIncrement()));
}
Also used : ShapeData(net.sf.latexdraw.data.ShapeData) ShapeFactory(net.sf.latexdraw.models.ShapeFactory) RunWith(org.junit.runner.RunWith) BorderPos(net.sf.latexdraw.models.interfaces.shape.BorderPos) HelperTest(net.sf.latexdraw.HelperTest) IShape(net.sf.latexdraw.models.interfaces.shape.IShape) Matchers.closeTo(org.hamcrest.Matchers.closeTo) LineStyle(net.sf.latexdraw.models.interfaces.shape.LineStyle) DviPsColors(net.sf.latexdraw.view.latex.DviPsColors) Theories(org.junit.experimental.theories.Theories) TicksStyle(net.sf.latexdraw.models.interfaces.shape.TicksStyle) AxesStyle(net.sf.latexdraw.models.interfaces.shape.AxesStyle) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) Theory(org.junit.experimental.theories.Theory) PSTricksConstants(net.sf.latexdraw.view.pst.PSTricksConstants) Matchers.empty(org.hamcrest.Matchers.empty) PlottingStyle(net.sf.latexdraw.models.interfaces.shape.PlottingStyle) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IGroup(net.sf.latexdraw.models.interfaces.shape.IGroup) Test(org.junit.Test) DotStyle(net.sf.latexdraw.models.interfaces.shape.DotStyle) ArrowStyle(net.sf.latexdraw.models.interfaces.shape.ArrowStyle) Assert.assertNull(org.junit.Assert.assertNull) FillingStyle(net.sf.latexdraw.models.interfaces.shape.FillingStyle) Assert.assertFalse(org.junit.Assert.assertFalse) IAxes(net.sf.latexdraw.models.interfaces.shape.IAxes) IRectangle(net.sf.latexdraw.models.interfaces.shape.IRectangle) IDot(net.sf.latexdraw.models.interfaces.shape.IDot) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IPoint(net.sf.latexdraw.models.interfaces.shape.IPoint) IAxes(net.sf.latexdraw.models.interfaces.shape.IAxes) HelperTest(net.sf.latexdraw.HelperTest) Test(org.junit.Test)

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