Search in sources :

Example 1 with Shape

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

the class Pencil method bindPressToAddShape.

/**
 * Binds a press interaction to add a shape.
 */
private void bindPressToAddShape() {
    // Add axes, grids, or dots
    nodeBinder().usingInteraction(Press::new).toProduce(i -> {
        final PositionShape sh = (PositionShape) editing.createShapeInstance();
        sh.setPosition(getAdaptedPoint(i.getSrcLocalPoint()));
        return new AddShape(sh, canvas.getDrawing());
    }).on(canvas).when(i -> i.getButton() == MouseButton.PRIMARY && (editing.getCurrentChoice() == EditionChoice.GRID || editing.getCurrentChoice() == EditionChoice.DOT || editing.getCurrentChoice() == EditionChoice.AXES)).bind();
    // When a user starts to type a text using the text setter and then he clicks somewhere else in the canvas,
    // the text typed must be added (if possible to the canvas) before starting typing a new text.
    nodeBinder().usingInteraction(Press::new).toProduce(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(textSetter.getPosition()), textSetter.getTextField().getText()), canvas.getDrawing())).on(canvas).when(i -> textSetter.isActivated() && !textSetter.getTextField().getText().isEmpty() && editing.getCurrentChoice() == EditionChoice.TEXT).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) AddShape(net.sf.latexdraw.command.shape.AddShape) PositionShape(net.sf.latexdraw.model.api.shape.PositionShape) Press(io.github.interacto.jfx.interaction.library.Press)

Example 2 with Shape

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

the class SVGGroup method toSVG.

@Override
SVGElement toSVG(@NotNull final SVGDocument doc) {
    if (shape.isEmpty()) {
        return null;
    }
    final SVGElement root = new SVGGElement(doc);
    final List<Shape> shapes = shape.getShapes();
    root.setAttribute(LNamespace.LATEXDRAW_NAMESPACE + ':' + LNamespace.XML_TYPE, LNamespace.XML_TYPE_GROUP);
    root.setAttribute(SVGAttributes.SVG_ID, getSVGID());
    shapes.stream().map(f -> shapeProducer.createSVGElement(f, doc)).forEach(newChild -> root.appendChild(newChild));
    return root;
}
Also used : Group(net.sf.latexdraw.model.api.shape.Group) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) List(java.util.List) Shape(net.sf.latexdraw.model.api.shape.Shape) NodeList(org.w3c.dom.NodeList) LNamespace(net.sf.latexdraw.util.LNamespace) SVGDocument(net.sf.latexdraw.parser.svg.SVGDocument) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) SVGAttributes(net.sf.latexdraw.parser.svg.SVGAttributes) SVGElement(net.sf.latexdraw.parser.svg.SVGElement) NotNull(org.jetbrains.annotations.NotNull) SVGGElement(net.sf.latexdraw.parser.svg.SVGGElement) Shape(net.sf.latexdraw.model.api.shape.Shape) SVGElement(net.sf.latexdraw.parser.svg.SVGElement)

Example 3 with Shape

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

the class ModifyShapePropertyTest method undoCheckers.

@Override
protected Stream<Runnable> undoCheckers() {
    return Stream.of(() -> {
        final Function<Shape, Object> valueToCheckCmd = (Function<Shape, Object>) currentData[3];
        final AtomicInteger i = new AtomicInteger(0);
        for (final Optional<Object> mem : memento) {
            mem.ifPresent(obj -> {
                if (obj instanceof Double) {
                    final double value = (Double) obj;
                    assertThat(value).isNotNaN();
                    assertThat((Double) valueToCheckCmd.apply(shapes.getShapeAt(i.get()).orElseThrow())).isCloseTo(value, within(0.0001));
                } else {
                    assertThat(obj).isEqualTo(valueToCheckCmd.apply(shapes.getShapeAt(i.get()).orElseThrow()));
                }
            });
            i.incrementAndGet();
        }
    });
}
Also used : Function(java.util.function.Function) ArrowableShape(net.sf.latexdraw.model.api.shape.ArrowableShape) Shape(net.sf.latexdraw.model.api.shape.Shape) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 4 with Shape

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

the class TestParsingPscustom method testPsCustomStarCommand.

@Test
public void testPsCustomStarCommand() {
    parser("\\pscustom*{\\moveto(1,2)\\lineto(3,4)\\lineto(4,4)}");
    final Shape sh = getShapeAt(0);
    assertTrue(sh.isFilled());
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Test(org.junit.jupiter.api.Test)

Example 5 with Shape

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

the class TestParsingShape method testStrokeOpacity.

@ParameterizedTest
@MethodSource(value = "cmds")
void testStrokeOpacity(final Tuple<String, String> cmd) {
    parser(cmd.a + "[strokeopacity = 0.2]" + cmd.b);
    final Shape sh = getShapeAt(0);
    assumeTrue(sh.isLineStylable());
    assertEquals(0.2, sh.getLineColour().getO(), 0.00001);
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Shape (net.sf.latexdraw.model.api.shape.Shape)75 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)43 MethodSource (org.junit.jupiter.params.provider.MethodSource)41 Test (org.junit.Test)12 Point (net.sf.latexdraw.model.api.shape.Point)8 PositionShape (net.sf.latexdraw.model.api.shape.PositionShape)7 HelperTest (net.sf.latexdraw.HelperTest)6 ShapeFactory (net.sf.latexdraw.model.ShapeFactory)6 Circle (net.sf.latexdraw.model.api.shape.Circle)6 RectangularShape (net.sf.latexdraw.model.api.shape.RectangularShape)6 NotNull (org.jetbrains.annotations.NotNull)6 Click (io.github.interacto.jfx.interaction.library.Click)5 ArrayList (java.util.ArrayList)5 Objects (java.util.Objects)5 MathUtils (net.sf.latexdraw.model.MathUtils)5 Rectangle (net.sf.latexdraw.model.api.shape.Rectangle)5 Inject (net.sf.latexdraw.util.Inject)5 CommandsRegistry (io.github.interacto.command.CommandsRegistry)3 Redo (io.github.interacto.command.library.Redo)3 Undo (io.github.interacto.command.library.Undo)3