use of net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape 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();
}
use of net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape 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<MultiClick, AddShape> creation = i -> new AddShape(setInitialPtsShape(createShapeInstance(), i.getPoints().get(0)), canvas.getDrawing());
// Binding for polygons
nodeBinder(AddShape.class, new MultiClick(3)).on(canvas).map(creation).then((c, i) -> {
final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolygonFrom((IPolygon) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.POLYGON).and(activatedProp));
// Binding for polyline
nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolylineFrom((IPolyline) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.LINES).and(activatedProp));
// Binding for bézier curves
nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createBezierCurveFrom((IBezierCurve) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
((IControlPointShape) c.getShape().get()).balance();
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.BEZIER_CURVE).and(activatedProp));
}
use of net.sf.latexdraw.models.interfaces.shape.IModifiablePointsShape 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 IShape setInitialPtsShape(final IShape sh, final Point3D firstPt) {
if (sh instanceof IModifiablePointsShape) {
final IModifiablePointsShape modShape = (IModifiablePointsShape) sh;
final IPoint 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.models.interfaces.shape.IModifiablePointsShape in project latexdraw by arnobl.
the class TestIModifiablePointsShape method testDuplicate.
@Theory
public void testDuplicate(@ModifPtShapeData(x = { 1.1d, 3d }, y = { -21d, 1d }) final IModifiablePointsShape shape) {
final IModifiablePointsShape 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