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();
}
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;
}
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();
}
});
}
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());
}
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);
}
Aggregations