use of net.sf.latexdraw.models.interfaces.shape.IPolyline 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.IPolyline in project latexdraw by arnobl.
the class TestParsingPsline method testFloatSigns.
@Test
public void testFloatSigns() {
parser("\\psline(+++35.5,--50.5)(--+12, -1)");
final IPolyline line = (IPolyline) listener.getShapes().get(0);
assertEquals(35.5 * IShape.PPC, line.getPtAt(0).getX(), 0.0001);
assertEquals(-50.5 * IShape.PPC, line.getPtAt(0).getY(), 0.0001);
assertEquals(12d * IShape.PPC, line.getPtAt(1).getX(), 0.0001);
assertEquals(1d * IShape.PPC, line.getPtAt(1).getY(), 0.0001);
}
use of net.sf.latexdraw.models.interfaces.shape.IPolyline in project latexdraw by arnobl.
the class TestParsingPsline method testParse1Coordinates.
@Test
public void testParse1Coordinates() {
parser("\\psline(5,10)");
final IPolyline line = (IPolyline) listener.getShapes().get(0);
assertEquals(2, line.getNbPoints());
assertEquals(0d, line.getPtAt(0).getX(), 0.0001);
assertEquals(0d, line.getPtAt(0).getY(), 0.0001);
assertEquals(5d * IShape.PPC, line.getPtAt(1).getX(), 0.0001);
assertEquals(-10d * IShape.PPC, line.getPtAt(1).getY(), 0.0001);
}
use of net.sf.latexdraw.models.interfaces.shape.IPolyline in project latexdraw by arnobl.
the class TestParsingPsline method testCoordinatesMm.
@Test
public void testCoordinatesMm() {
parser("\\psline(350mm,200mm)(10mm, 30.3mm)");
final IPolyline line = (IPolyline) listener.getShapes().get(0);
assertEquals(2, line.getNbPoints());
assertEquals(35d * IShape.PPC, line.getPtAt(0).getX(), 0.0001);
assertEquals(-20d * IShape.PPC, line.getPtAt(0).getY(), 0.0001);
assertEquals(1d * IShape.PPC, line.getPtAt(1).getX(), 0.0001);
assertEquals(-3.03 * IShape.PPC, line.getPtAt(1).getY(), 0.0001);
}
use of net.sf.latexdraw.models.interfaces.shape.IPolyline in project latexdraw by arnobl.
the class TestParsingPsline method testUnit.
@Test
public void testUnit() {
parser("\\psset{unit=2}\\psline[linewidth=0.3,linestyle=dashed](2,3)(1cm,2cm)");
final IPolyline sh = (IPolyline) listener.getShapes().get(0);
assertEquals(2d * 2d * IShape.PPC, sh.getPtAt(0).getX(), 0.0001);
assertEquals(-3d * 2d * IShape.PPC, sh.getPtAt(0).getY(), 0.0001);
assertEquals(IShape.PPC, sh.getPtAt(1).getX(), 0.0001);
assertEquals(-2d * IShape.PPC, sh.getPtAt(1).getY(), 0.0001);
}
Aggregations