use of net.sf.latexdraw.models.interfaces.shape.IControlPointShape in project latexdraw by arnobl.
the class Border method configureBindings.
@Override
protected void configureBindings() {
addBinding(new DnD2Scale(this));
configureMovePointBinding();
nodeBinder(MoveCtrlPoint.class, new DnD()).on(ctrlPt1Handlers).on(ctrlPt2Handlers).first((c, i) -> {
final IGroup group = canvas.getDrawing().getSelection();
if (group.size() == 1 && group.getShapeAt(0) instanceof IControlPointShape) {
c.setPoint(i.getSrcObject().map(h -> ((CtrlPointHandler) h).getPoint()).orElse(null));
c.setShape((IControlPointShape) group.getShapeAt(0));
c.setIsFirstCtrlPt(ctrlPt1Handlers.contains(i.getSrcObject().orElse(null)));
}
}).then((c, i) -> {
final Point3D startPt = i.getSrcObject().map(n -> n.localToParent(i.getSrcLocalPoint())).orElse(new Point3D(0d, 0d, 0d));
final Point3D endPt = i.getSrcObject().map(n -> n.localToParent(i.getEndLocalPt())).orElse(new Point3D(0d, 0d, 0d));
final IPoint ptToMove = i.getSrcObject().map(n -> ((CtrlPointHandler) n).getPoint()).orElse(ShapeFactory.INST.createPoint());
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().bind();
nodeBinder(RotateShapes.class, new DnD()).on(rotHandler).first((c, i) -> {
final IDrawing drawing = canvas.getDrawing();
c.setGravityCentre(drawing.getSelection().getGravityCentre());
c.getGc().translate(canvas.getOrigin().getX(), canvas.getOrigin().getY());
c.setShape(drawing.getSelection().duplicateDeep(false));
}).then((c, i) -> c.setRotationAngle(c.getGc().computeRotationAngle(ShapeFactory.INST.createPoint(canvas.sceneToLocal(i.getSrcScenePoint())), ShapeFactory.INST.createPoint(canvas.sceneToLocal(i.getEndScenePt()))))).exec().bind();
addBinding(new DnD2ArcAngle(this));
}
use of net.sf.latexdraw.models.interfaces.shape.IControlPointShape in project latexdraw by arnobl.
the class ViewArrowableTrait method flush.
@Override
public void flush() {
final int nbPts = model.getNbPoints();
model.getPtAt(0).xProperty().removeListener(updateArrow);
model.getPtAt(0).yProperty().removeListener(updateArrow);
model.getPtAt(-1).xProperty().removeListener(updateArrow);
model.getPtAt(-1).yProperty().removeListener(updateArrow);
if (nbPts > 2) {
model.getPtAt(1).xProperty().removeListener(updateArrow);
model.getPtAt(1).yProperty().removeListener(updateArrow);
}
if (nbPts > 3) {
model.getPtAt(nbPts - 2).xProperty().removeListener(updateArrow);
model.getPtAt(nbPts - 2).yProperty().removeListener(updateArrow);
}
model.thicknessProperty().removeListener(updateArrow);
model.fillingProperty().removeListener(updateClip);
model.dbleBordProperty().removeListener(updateArrow);
model.dbleBordSepProperty().removeListener(updateArrow);
model.getArrows().forEach(arr -> arr.setOnArrowChanged(null));
model.getPoints().forEach(pt -> {
pt.xProperty().removeListener(updateArrow);
pt.yProperty().removeListener(updateArrow);
});
if (model instanceof IControlPointShape) {
((IControlPointShape) model).getFirstCtrlPts().forEach(pt -> {
pt.xProperty().removeListener(updateArrow);
pt.yProperty().removeListener(updateArrow);
});
}
super.flush();
}
use of net.sf.latexdraw.models.interfaces.shape.IControlPointShape in project latexdraw by arnobl.
the class TestIControlPointShape method testDuplicate.
@Theory
public void testDuplicate(@CtrlShapeData final IControlPointShape sh) {
sh.translate(10d, -12d);
final IControlPointShape dup = sh.duplicate();
assertEquals(sh.getFirstCtrlPts(), dup.getFirstCtrlPts());
assertEquals(sh.getSecondCtrlPts(), dup.getSecondCtrlPts());
}
use of net.sf.latexdraw.models.interfaces.shape.IControlPointShape 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));
}
Aggregations