use of net.sf.latexdraw.model.api.shape.ModifiablePointsShape in project latexdraw by arnobl.
the class Pencil method setInitialPtsShape.
/**
* Companion function to the bindMultiClic2AddShape binding.
* It initialises the first two points of the given shape.
*/
private Shape setInitialPtsShape(final Shape sh, final Point3D firstPt) {
if (sh instanceof ModifiablePointsShape) {
final ModifiablePointsShape modShape = (ModifiablePointsShape) sh;
final Point pt = getAdaptedPoint(firstPt);
modShape.setPoint(pt.getX(), pt.getY(), 0);
modShape.setPoint(pt.getX() + 1d, pt.getY() + 1d, 1);
}
return sh;
}
use of net.sf.latexdraw.model.api.shape.ModifiablePointsShape 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<PointsData, AddShape> creation = i -> new AddShape(setInitialPtsShape(editing.createShapeInstance(), i.getPointsData().get(0).getSrcLocalPoint()), canvas.getDrawing());
// Binding for polygons
nodeBinder().usingInteraction(() -> new MultiClick(3)).toProduce(creation).on(canvas).then((i, c) -> {
final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolygonFrom((Polygon) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
}).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.POLYGON).bind();
// Binding for polyline
nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolylineFrom((Polyline) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
}).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.LINES).bind();
// Binding for bézier curves
nodeBinder().usingInteraction(MultiClick::new).toProduce(creation).on(canvas).then((i, c) -> {
final Point currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().getNbPoints() == i.getPointsData().size() && i.getLastButton().orElse(MouseButton.NONE) == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createBezierCurveFrom((BezierCurve) c.getShape(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((ModifiablePointsShape) c.getShape()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
((ControlPointShape) c.getShape()).balance();
canvas.setTempView(viewFactory.createView(c.getShape()).orElse(null));
}).strictStart().endOrCancel(i -> canvas.setTempView(null)).when(() -> editing.getCurrentChoice() == EditionChoice.BEZIER_CURVE).bind();
}
use of net.sf.latexdraw.model.api.shape.ModifiablePointsShape in project latexdraw by arnobl.
the class TestModifiablePointsShapeBase method testDuplicate.
@Theory
public void testDuplicate(@ModifPtShapeData(x = { 1.1d, 3d }, y = { -21d, 1d }) final ModifiablePointsShape shape) {
final ModifiablePointsShape dup = shape.duplicate();
assertEqualsDouble(1.1d, dup.getPtAt(0).getX());
assertEqualsDouble(3d, dup.getPtAt(1).getX());
assertEqualsDouble(-21d, dup.getPtAt(0).getY());
assertEqualsDouble(1d, dup.getPtAt(1).getY());
}
Aggregations