Search in sources :

Example 36 with Shape

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

the class TestShapePositioner method testOneShapeBackground.

@Test
public void testOneShapeBackground() {
    Cmds.of(selectOneShape, selectOneShape).execute();
    final Shape s1 = drawing.getShapeAt(0).orElseThrow();
    final Shape s2 = drawing.getShapeAt(1).orElseThrow();
    Cmds.of(() -> clickOn("#backgroundB")).execute();
    assertEquals(s2, drawing.getShapeAt(0).orElseThrow());
    assertEquals(s1, drawing.getShapeAt(1).orElseThrow());
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Test(org.junit.Test)

Example 37 with Shape

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

the class InsertPSTCode method doCmdBody.

@Override
protected void doCmdBody() {
    final PSTLatexdrawListener listener = new PSTLatexdrawListener();
    final PSTLexer lexer = new PSTLexer(CharStreams.fromString(code));
    final PSTParser parser = new PSTParser(new CommonTokenStream(lexer));
    parser.addParseListener(listener);
    parser.pstCode(new PSTContext());
    final Group group = ShapeFactory.INST.createGroup();
    group.getShapes().addAll(listener.flatShapes());
    if (!group.isEmpty()) {
        final Shape sh = group.size() > 1 ? group : group.getShapeAt(0).orElseThrow();
        final Point tl = sh.getTopLeftPoint();
        final double tx = tl.getX() < 0d ? -tl.getX() + 50d : 0d;
        final double ty = tl.getY() < 0d ? -tl.getY() + 50d : 0d;
        shapes = Optional.of(sh);
        sh.translate(tx, ty);
        redo();
        statusBar.setText(lang.getString("codeConverted"));
    }
    parser.getInterpreter().clearDFA();
    lexer.getInterpreter().clearDFA();
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Group(net.sf.latexdraw.model.api.shape.Group) PSTLexer(net.sf.latexdraw.parser.pst.PSTLexer) Shape(net.sf.latexdraw.model.api.shape.Shape) PSTLatexdrawListener(net.sf.latexdraw.parser.pst.PSTLatexdrawListener) PSTContext(net.sf.latexdraw.parser.pst.PSTContext) Point(net.sf.latexdraw.model.api.shape.Point) PSTParser(net.sf.latexdraw.parser.pst.PSTParser)

Example 38 with Shape

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

the class MoveBackForegroundShapes method moveForeground.

/**
 * Puts the shapes in the foreground.
 */
private void moveForeground() {
    final int size = shape.size();
    prepareMove();
    for (int i = 0; i < size; i++) {
        final Shape sh = sortedSh.get(i);
        formerId[i] = drawing.getShapes().indexOf(sh);
        drawing.removeShape(sh);
        drawing.addShape(sh);
    }
    drawing.setModified(true);
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape)

Example 39 with Shape

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

the class Canvas method getIntersectedShapes.

public List<Shape> getIntersectedShapes(final Bounds selectionBorder) {
    final Rectangle selectionRec = new Rectangle(selectionBorder.getMinX() + Canvas.ORIGIN.getX(), selectionBorder.getMinY() + Canvas.ORIGIN.getY(), selectionBorder.getWidth(), selectionBorder.getHeight());
    // Transforming the selection rectangle to match the transformation of the canvas.
    selectionRec.getTransforms().setAll(getLocalToSceneTransform());
    return getViews().getChildren().stream().filter(view -> {
        Bounds bounds;
        final Transform transform = view.getLocalToParentTransform();
        if (transform.isIdentity()) {
            bounds = selectionBorder;
        } else {
            try {
                bounds = transform.createInverse().transform(selectionBorder);
            } catch (final NonInvertibleTransformException ex) {
                bounds = selectionBorder;
            }
        }
        return view.intersects(bounds) && ((ViewShape<?>) view).getActivatedShapes().stream().anyMatch(sh -> !javafx.scene.shape.Shape.intersect(sh, selectionRec).getLayoutBounds().isEmpty());
    }).map(view -> (Shape) view.getUserData()).collect(Collectors.toList());
}
Also used : Change(javafx.collections.ListChangeListener.Change) Point2D(java.awt.geom.Point2D) Flushable(net.sf.latexdraw.util.Flushable) Rectangle2D(java.awt.geom.Rectangle2D) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) Parent(javafx.scene.Parent) ShapeFactory(net.sf.latexdraw.model.ShapeFactory) Inject(net.sf.latexdraw.util.Inject) ScrollPane(javafx.scene.control.ScrollPane) Preferenciable(io.github.interacto.properties.Preferenciable) Document(org.w3c.dom.Document) Map(java.util.Map) Transform(javafx.scene.transform.Transform) Pane(javafx.scene.layout.Pane) Rectangle(javafx.scene.shape.Rectangle) Reinitialisable(io.github.interacto.properties.Reinitialisable) JavaFxScheduler(io.reactivex.rxjavafx.schedulers.JavaFxScheduler) Group(javafx.scene.Group) Point(net.sf.latexdraw.model.api.shape.Point) Collectors(java.util.stream.Collectors) Modifiable(io.github.interacto.properties.Modifiable) ViewsSynchroniserHandler(net.sf.latexdraw.view.ViewsSynchroniserHandler) Objects(java.util.Objects) Platform(javafx.application.Platform) BadaboomCollector(net.sf.latexdraw.util.BadaboomCollector) Nullable(org.jetbrains.annotations.Nullable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) StrokeLineCap(javafx.scene.shape.StrokeLineCap) ObservableList(javafx.collections.ObservableList) NotNull(org.jetbrains.annotations.NotNull) Bounds(javafx.geometry.Bounds) Drawing(net.sf.latexdraw.model.api.shape.Drawing) HashMap(java.util.HashMap) DoubleProperty(javafx.beans.property.DoubleProperty) Bindings(javafx.beans.binding.Bindings) ArrayList(java.util.ArrayList) Shape(net.sf.latexdraw.model.api.shape.Shape) LNamespace(net.sf.latexdraw.util.LNamespace) JavaFxObservable(io.reactivex.rxjavafx.observables.JavaFxObservable) Node(org.w3c.dom.Node) Zoomable(io.github.interacto.properties.Zoomable) MathUtils(net.sf.latexdraw.model.MathUtils) Redo(io.github.interacto.command.library.Redo) Modifying(net.sf.latexdraw.command.Modifying) Color(javafx.scene.paint.Color) CommandsRegistry(io.github.interacto.command.CommandsRegistry) NodeList(org.w3c.dom.NodeList) Undo(io.github.interacto.command.library.Undo) Click(io.github.interacto.jfx.interaction.library.Click) TimeUnit(java.util.concurrent.TimeUnit) PreferencesService(net.sf.latexdraw.service.PreferencesService) Element(org.w3c.dom.Element) Shape(net.sf.latexdraw.model.api.shape.Shape) Bounds(javafx.geometry.Bounds) Rectangle(javafx.scene.shape.Rectangle) Transform(javafx.scene.transform.Transform) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException)

Example 40 with Shape

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

the class TestShapePositioner method testSeveralShapesBackground.

@Test
public void testSeveralShapesBackground() {
    Cmds.of(selectThreeShapes, selectTwoShapes).execute();
    selectShapeAt.execute(Arrays.asList(1, 2));
    final Shape s2 = drawing.getShapeAt(1).orElseThrow();
    final Shape s3 = drawing.getShapeAt(2).orElseThrow();
    Cmds.of(() -> clickOn("#backgroundB")).execute();
    assertEquals(s2, drawing.getShapeAt(0).orElseThrow());
    assertEquals(s3, drawing.getShapeAt(1).orElseThrow());
}
Also used : Shape(net.sf.latexdraw.model.api.shape.Shape) Test(org.junit.Test)

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