diff --git a/pom.xml b/pom.xml
index 4e731b5a1..8dc45d891 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.marginallyclever
Makelangelo
- 7.65.0
+ 7.66.2
Makelangelo
Makelangelo Software is a Java program that prepares art for CNC plotters. It is especially designed for the Makelangelo Robot.
It pairs really well with Marlin-polargraph, the code in the brain of the robot that receives instructions and moves the motors.
@@ -427,7 +427,7 @@ It pairs really well with Marlin-polargraph, the code in the brain of the robot
ch.qos.logback
logback-classic
- 1.5.9
+ 1.5.16
org.codehaus.janino
@@ -438,7 +438,7 @@ It pairs really well with Marlin-polargraph, the code in the brain of the robot
org.slf4j
slf4j-api
- 2.0.12
+ 2.0.16
@@ -571,7 +571,7 @@ It pairs really well with Marlin-polargraph, the code in the brain of the robot
-->
com.github.marginallyclever
nodegraphcore
- 1.1.0
+ 1.3.2
com.github.marginallyclever
donatello
- 1.4.3
+ 1.5.5
diff --git a/src/main/java/com/marginallyclever/convenience/LineSegment2D.java b/src/main/java/com/marginallyclever/convenience/LineSegment2D.java
index 0e339a3e5..ecd32e641 100644
--- a/src/main/java/com/marginallyclever/convenience/LineSegment2D.java
+++ b/src/main/java/com/marginallyclever/convenience/LineSegment2D.java
@@ -15,8 +15,8 @@ public class LineSegment2D {
public LineSegment2D(Point2D start, Point2D end, Color color) {
super();
- this.start = start;
- this.end = end;
+ this.start = new Point2D(start);
+ this.end = new Point2D(end);
this.color = color;
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/CollapsiblePanel.java b/src/main/java/com/marginallyclever/makelangelo/CollapsiblePanel.java
index f93593d89..ba9f615be 100644
--- a/src/main/java/com/marginallyclever/makelangelo/CollapsiblePanel.java
+++ b/src/main/java/com/marginallyclever/makelangelo/CollapsiblePanel.java
@@ -185,14 +185,12 @@ public static void main(String[] args) {
JFrame frame = new JFrame("Collapsible Panel");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel jPanel = new JPanel();
- jPanel.setLayout(new BorderLayout());
- SelectBoolean a = new SelectBoolean("A", "AAAAAAAAAAA", false);
- jPanel.add(a, BorderLayout.NORTH);
+ JPanel jPanel = new JPanel(new GridBagLayout());
CollapsiblePanel cpanel = new CollapsiblePanel(frame, "lot of buttons", 400, true);
jPanel.add(cpanel, BorderLayout.CENTER);
+ SelectBoolean a = new SelectBoolean("A", "AAAAAAAAAAA", false);
SelectButton b = new SelectButton("B", "B");
SelectColor c = new SelectColor("C", "CCCCCC", Color.BLACK, frame);
SelectFile d = new SelectFile("D", "D", null,cpanel);
@@ -205,15 +203,19 @@ public static void main(String[] args) {
SelectSlider i = new SelectSlider("I", "I", 200, 0, 100);
SelectTextArea j = new SelectTextArea("J", "J", ipsum);
- cpanel.add(b);
- cpanel.add(c);
- cpanel.add(d);
- cpanel.add(e);
- cpanel.add(f);
- cpanel.add(g);
- cpanel.add(h);
- cpanel.add(i);
- cpanel.add(j);
+ var inner = new JPanel(new GridBagLayout());
+ GridBagConstraints gbc = new GridBagConstraints();
+ a.attach(inner, gbc); gbc.gridy++;
+ b.attach(inner,gbc); gbc.gridy++;
+ c.attach(inner,gbc); gbc.gridy++;
+ d.attach(inner,gbc); gbc.gridy++;
+ e.attach(inner,gbc); gbc.gridy++;
+ f.attach(inner,gbc); gbc.gridy++;
+ g.attach(inner,gbc); gbc.gridy++;
+ h.attach(inner,gbc); gbc.gridy++;
+ i.attach(inner,gbc); gbc.gridy++;
+ j.attach(inner,gbc); gbc.gridy++;
+ cpanel.add(inner);
frame.setPreferredSize(new Dimension(600, 90));
frame.add(jPanel);
diff --git a/src/main/java/com/marginallyclever/makelangelo/MainFrame.java b/src/main/java/com/marginallyclever/makelangelo/MainFrame.java
index ce97f625f..ce345c81a 100644
--- a/src/main/java/com/marginallyclever/makelangelo/MainFrame.java
+++ b/src/main/java/com/marginallyclever/makelangelo/MainFrame.java
@@ -9,7 +9,6 @@
import com.marginallyclever.convenience.FileAccess;
import com.marginallyclever.donatello.Donatello;
import com.marginallyclever.donatello.NodeFactoryPanel;
-import com.marginallyclever.donatello.actions.undoable.NodeAddAction;
import com.marginallyclever.makelangelo.applicationsettings.MetricsPreferences;
import com.marginallyclever.makelangelo.donatelloimpl.DonatelloDropTarget;
import com.marginallyclever.makelangelo.makeart.io.LoadFilePanel;
@@ -85,18 +84,7 @@ public MainFrame() {
setJMenuBar(mainMenuBar);
setupDropTarget();
- connectFactoryToPreview();
- }
-
- private void connectFactoryToPreview() {
- nodeFactoryPanel.addListener(e->{
- var p = donatello.getPopupPoint();
- if(p!=null) p = donatello.getPaintArea().transformScreenToWorldPoint(p);
- else p = donatello.getPaintArea().getCameraPosition();
-
- var add = new NodeAddAction("Add",donatello,nodeFactoryPanel);
- add.commitAdd(e,p);
- });
+ donatello.connectNodeFactory(nodeFactoryPanel);
}
private void initDocking() {
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/DonatelloDropTarget.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/DonatelloDropTarget.java
index fa6dcf639..24d9a7aec 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/DonatelloDropTarget.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/DonatelloDropTarget.java
@@ -85,7 +85,7 @@ private Node loadFile(String absolutePath) {
*/
private Node loadImage(String absPath) {
LoadImage loadImage = new LoadImage();
- var first = loadImage.getVariable(0);
+ var first = loadImage.getPort(0);
if(!(first instanceof Input> inputFile)) throw new IllegalStateException("First variable is not an Input");
if(!(inputFile.getValue() instanceof Filename)) throw new IllegalStateException("Input value is not a Filename");
donatello.getGraph().add(loadImage);
@@ -101,7 +101,7 @@ private Node loadImage(String absPath) {
*/
private Node loadVector(String absPath) {
LoadTurtle loadTurtle = new LoadTurtle();
- var first = loadTurtle.getVariable(0);
+ var first = loadTurtle.getPort(0);
if(!(first instanceof InputFilename inputFile)) throw new IllegalStateException("First variable is not an Input");
if(inputFile.getValue() == null) throw new IllegalStateException("Input value is not a Filename");
donatello.getGraph().add(loadTurtle);
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/MakelangeloRegistry.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/MakelangeloRegistry.java
index 57956f407..f17f43457 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/MakelangeloRegistry.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/MakelangeloRegistry.java
@@ -1,5 +1,6 @@
package com.marginallyclever.makelangelo.donatelloimpl;
+import com.marginallyclever.makelangelo.donatelloimpl.nodes.points.PointsDAO4JSON;
import com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.TurtleDAO4JSON;
import com.marginallyclever.makelangelo.turtle.Turtle;
import com.marginallyclever.nodegraphcore.DAO4JSONFactory;
@@ -32,5 +33,6 @@ public void registerNodes() {
public void registerDAO() {
logger.info("Registering makelangelo-software DAOs");
DAO4JSONFactory.registerDAO(new TurtleDAO4JSON());
+ DAO4JSONFactory.registerDAO(new PointsDAO4JSON());
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/Canvas.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/Canvas.java
index dd93cecb3..e2027c03a 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/Canvas.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/Canvas.java
@@ -15,6 +15,7 @@ public class Canvas extends Node implements PrintWithGraphics {
private final InputInt width = new InputInt("width", 1);
private final InputInt height = new InputInt("height", 1);
private final InputColor color = new InputColor("color", Color.WHITE);
+ private final InputInt layer = new InputInt("layer",5);
private final OutputInt outx = new OutputInt("x",0);
private final OutputInt outy = new OutputInt("y",0);
private final OutputInt outw = new OutputInt("width",width.getValue());
@@ -22,31 +23,39 @@ public class Canvas extends Node implements PrintWithGraphics {
public Canvas() {
super("Canvas");
- addVariable(width);
- addVariable(height);
- addVariable(color);
- addVariable(outx);
- addVariable(outy);
- addVariable(outw);
- addVariable(outh);
+ addPort(width);
+ addPort(height);
+ addPort(color);
+ addPort(outx);
+ addPort(outy);
+ addPort(outw);
+ addPort(outh);
+ addPort(layer);
}
@Override
public void update() {
var w = Math.max(1,width.getValue());
var h = Math.max(1,height.getValue());
- outx.send(0);
- outy.send(0);
- outw.send(w);
- outh.send(h);
+ outx.setValue(-w/2);
+ outy.setValue(-h/2);
+ outw.setValue(w);
+ outh.setValue(h);
}
@Override
public void print(Graphics g) {
+ var x = outx.getValue();
+ var y = outy.getValue();
var w = Math.max(1,width.getValue());
var h = Math.max(1,height.getValue());
g.setColor(color.getValue());
- g.fillRect(0,0,w,h);
+ g.fillRect(x,y,w,h);
+ }
+
+ @Override
+ public int getLayer() {
+ return layer.getValue();
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/GridOfPoints.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/GridOfPoints.java
new file mode 100644
index 000000000..bd381e370
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/GridOfPoints.java
@@ -0,0 +1,90 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import com.marginallyclever.donatello.ports.InputDouble;
+import com.marginallyclever.donatello.ports.InputNumber;
+import com.marginallyclever.donatello.ports.InputOneOfMany;
+import com.marginallyclever.nodegraphcore.Node;
+
+import javax.vecmath.Matrix3d;
+import javax.vecmath.Point2d;
+import javax.vecmath.Point3d;
+import java.util.stream.IntStream;
+
+/**
+ * Create a grid of points controlled by the number (quantity) and spacing (distance between points).
+ */
+public class GridOfPoints extends Node {
+ private final InputNumber Xa = new InputNumber("Xa",10);
+ private final InputNumber Xb = new InputNumber("Xb",10d);
+ private final InputNumber Ya = new InputNumber("Ya",10);
+ private final InputNumber Yb = new InputNumber("Yb",10d);
+ private final InputOneOfMany style = new InputOneOfMany("style");
+ private final InputDouble angle = new InputDouble("angle");
+ private final OutputPoints output = new OutputPoints("output");
+
+ public GridOfPoints() {
+ super("GridOfPoints");
+ addPort(Xa);
+ addPort(Xb);
+ addPort(Ya);
+ addPort(Yb);
+ addPort(style);
+ addPort(angle);
+ addPort(output);
+
+ style.setOptions(new String[]{"a * b","b / (a count)","b / (a distance)"});
+ }
+
+ @Override
+ public void update() {
+ // we're going to make a grid nx,ny with margin dx,dy.
+ int nx,ny;
+ double dx, dy;
+
+ var list = new ListOfPoints();
+ switch(style.getValue()) {
+ case 2: {
+ // d = a
+ // n = total distance (b) divided by spacing (a)
+ dx = Math.max(1, Xa.getValue().doubleValue());
+ dy = Math.max(1, Ya.getValue().doubleValue());
+ nx = (int)Math.max(1, Xb.getValue().doubleValue() / dx);
+ ny = (int)Math.max(1, Yb.getValue().doubleValue() / dy);
+ break;
+ }
+ case 1: {
+ // n = a
+ // d = total distance (b) divided by number of points (a).
+ nx = Math.max(1, Xa.getValue().intValue());
+ ny = Math.max(1, Ya.getValue().intValue());
+ dx = Xb.getValue().doubleValue() / nx;
+ dy = Yb.getValue().doubleValue() / ny;
+ break;
+ }
+ default: {
+ // n = a
+ // d = b
+ nx = Math.max(1, Xa.getValue().intValue());
+ ny = Math.max(1, Ya.getValue().intValue());
+ dx = Xb.getValue().doubleValue();
+ dy = Yb.getValue().doubleValue();
+ break;
+ }
+ }
+
+ double halfX = (nx*dx) / 2;
+ double halfY = (ny*dy) / 2;
+ Matrix3d transform = new Matrix3d();
+ transform.rotZ(Math.toRadians(angle.getValue()));
+
+ // now make the grid
+ IntStream.range(0,ny).forEach(y -> {
+ IntStream.range(0,nx).forEach(x -> {
+ var p = new Point3d(x * dx - halfX, y * dy - halfY,0d);
+ transform.transform(p);
+ list.add(new Point2d(p.x, p.y));
+ });
+ });
+ output.setValue(list);
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/InputPoints.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/InputPoints.java
new file mode 100644
index 000000000..513a3948a
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/InputPoints.java
@@ -0,0 +1,12 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import com.marginallyclever.nodegraphcore.port.Input;
+
+/**
+ * {@link Input} for a {@link ListOfPoints}.
+ */
+public class InputPoints extends Input {
+ public InputPoints(String _name) throws IllegalArgumentException {
+ super(_name, ListOfPoints.class, new ListOfPoints());
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/ListOfPoints.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/ListOfPoints.java
new file mode 100644
index 000000000..78e37aaa9
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/ListOfPoints.java
@@ -0,0 +1,9 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import javax.vecmath.Point2d;
+import java.util.ArrayList;
+
+/**
+ * A list of 2D points with double precision.
+ */
+public class ListOfPoints extends ArrayList {}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/OutputPoints.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/OutputPoints.java
new file mode 100644
index 000000000..1acf011b1
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/OutputPoints.java
@@ -0,0 +1,12 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import com.marginallyclever.nodegraphcore.port.Output;
+
+/**
+ * {@link Output} for a {@link ListOfPoints}.
+ */
+public class OutputPoints extends Output {
+ public OutputPoints(String _name) throws IllegalArgumentException {
+ super(_name, ListOfPoints.class, new ListOfPoints());
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PatternAtPoints.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PatternAtPoints.java
new file mode 100644
index 000000000..58d101b5f
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PatternAtPoints.java
@@ -0,0 +1,85 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import com.marginallyclever.donatello.ports.InputDouble;
+import com.marginallyclever.donatello.ports.InputImage;
+import com.marginallyclever.makelangelo.donatelloimpl.ports.InputTurtle;
+import com.marginallyclever.makelangelo.donatelloimpl.ports.OutputTurtle;
+import com.marginallyclever.makelangelo.turtle.Turtle;
+import com.marginallyclever.nodegraphcore.Node;
+
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
+
+/**
+ * Place a pattern on a path. Modulate the pattern by the image.
+ */
+public class PatternAtPoints extends Node {
+ private final InputTurtle pattern = new InputTurtle("pattern");
+ private final InputPoints listOfPoints = new InputPoints("points");
+ private final InputImage inputImage = new InputImage("image");
+ private final InputDouble min = new InputDouble("min", 0.1);
+ private final InputDouble max = new InputDouble("max", 1.0);
+ private final OutputTurtle output = new OutputTurtle("output");
+
+ public PatternAtPoints() {
+ super("PatternAtPoints");
+ addPort(pattern);
+ addPort(listOfPoints);
+ addPort(inputImage);
+ addPort(min);
+ addPort(max);
+ addPort(output);
+ }
+
+ @Override
+ public void update() {
+ Turtle result = new Turtle();
+ Turtle myPattern = pattern.getValue();
+ ListOfPoints points = listOfPoints.getValue();
+ BufferedImage image = inputImage.getValue();
+ var w = image.getWidth();
+ var h = image.getHeight();
+
+ if(points.isEmpty()) {
+ setComplete(100);
+ output.setValue(result);
+ return;
+ }
+
+ double bottom = min.getValue();
+ double diff = max.getValue() - min.getValue();
+
+ var w2 = w/2;
+ var h2 = h/2;
+ Rectangle2D.Double rectangle = new Rectangle2D.Double(-w2,-h2,w,h);
+
+ setComplete(0);
+ try {
+ int total = points.size();
+ int i = 0;
+ for (var p : points) {
+ if (rectangle.contains(p.x, p.y)) {
+ // inside image
+ var c = new Color(image.getRGB((int) (p.x + w2), (int) (p.y + h2)));
+ // get intensity of c as a value 0....1
+ var intensity = (c.getBlue() + c.getGreen() + c.getRed()) / (3.0 * 255.0);
+ var capped = Math.max(0, Math.min(1, intensity));
+ var i2 = bottom + capped * diff;
+
+ if(capped!=0) {
+ Turtle stamp = new Turtle(myPattern);
+ stamp.scale(i2, i2);
+ stamp.translate(p.x, p.y);
+ result.add(stamp);
+ }
+ }
+ setComplete((100 * i++ / total));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ setComplete(100);
+ output.setValue(result);
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PointsDAO4JSON.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PointsDAO4JSON.java
new file mode 100644
index 000000000..fb0d1c44a
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PointsDAO4JSON.java
@@ -0,0 +1,48 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import com.marginallyclever.nodegraphcore.AbstractDAO4JSON;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import javax.vecmath.Point2d;
+import java.util.stream.IntStream;
+
+/**
+ * DAO for ListOfPoints
+ */
+public class PointsDAO4JSON extends AbstractDAO4JSON {
+ public PointsDAO4JSON() {
+ super(ListOfPoints.class);
+ }
+
+ @Override
+ public Object toJSON(Object object) throws JSONException {
+ JSONArray array = new JSONArray();
+ ListOfPoints points = (ListOfPoints)object;
+ // for a complete snapshot, capture all the instance details, too.
+ for(var p : points) {
+ JSONObject point = new JSONObject();
+ point.put("x", p.getX());
+ point.put("y", p.getY());
+ array.put(point);
+ }
+
+ return array;
+ }
+
+ @Override
+ public ListOfPoints fromJSON(Object object) throws JSONException {
+ JSONArray array = (JSONArray)object;
+ // for a complete snapshot, restore all the instance details, too.
+ var list = new ListOfPoints();
+ IntStream.range(0, array.length()).forEach(i ->{
+ JSONObject point = array.getJSONObject(i);
+ list.add(new Point2d(
+ point.getDouble("x"),
+ point.getDouble("y")
+ ));
+ });
+ return list;
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PrintPoints.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PrintPoints.java
new file mode 100644
index 000000000..cd41536eb
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/PrintPoints.java
@@ -0,0 +1,67 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import com.marginallyclever.donatello.graphview.GraphViewPanel;
+import com.marginallyclever.donatello.ports.InputColor;
+import com.marginallyclever.donatello.ports.InputInt;
+import com.marginallyclever.nodegraphcore.Node;
+import com.marginallyclever.nodegraphcore.PrintWithGraphics;
+
+import java.awt.*;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Draw a list of points.
+ */
+public class PrintPoints extends Node implements PrintWithGraphics {
+ private final InputPoints input = new InputPoints("points");
+ private final InputInt radius = new InputInt("radius",5);
+ private final InputColor color = new InputColor("color",Color.WHITE);
+ private final InputInt layer = new InputInt("layer",4);
+ private final ReentrantLock lock = new ReentrantLock();
+ private ListOfPoints list;
+
+ public PrintPoints() {
+ super("PrintPoints");
+ addPort(input);
+ addPort(radius);
+ addPort(color);
+ addPort(layer);
+ }
+
+ @Override
+ public void update() {
+ lock.lock();
+ try {
+ list = input.getValue();
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ @Override
+ public void print(Graphics g) {
+ if(list==null || list.isEmpty()) return;
+
+ Graphics2D g2 = (Graphics2D)g.create();
+ GraphViewPanel.setHints(g2);
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setStroke(new BasicStroke(radius.getValue(),BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
+ g2.setColor(color.getValue());
+
+
+ lock.lock();
+ try {
+ list.stream().parallel().forEach(p -> {
+ g2.drawLine((int)p.x, (int)p.y, (int)p.x, (int)p.y);
+ });
+ } finally {
+ lock.unlock();
+ }
+ g2.dispose();
+ }
+
+ @Override
+ public int getLayer() {
+ return layer.getValue();
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/TurtleToPoints.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/TurtleToPoints.java
new file mode 100644
index 000000000..d72704416
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/points/TurtleToPoints.java
@@ -0,0 +1,35 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.points;
+
+import com.marginallyclever.makelangelo.donatelloimpl.ports.InputTurtle;
+import com.marginallyclever.makelangelo.turtle.MovementType;
+import com.marginallyclever.nodegraphcore.Node;
+
+import javax.vecmath.Point2d;
+
+/**
+ * Converts a {@link com.marginallyclever.makelangelo.turtle.Turtle} to a {@link ListOfPoints}.
+ */
+public class TurtleToPoints extends Node {
+ private final InputTurtle turtle = new InputTurtle("Turtle");
+ private final OutputPoints points = new OutputPoints("points");
+
+ public TurtleToPoints() {
+ super("TurtleToPoints");
+ addPort(turtle);
+ addPort(points);
+ }
+
+ @Override
+ public void update() {
+ var in = turtle.getValue();
+ var out = new ListOfPoints();
+
+ for( var move : in.history ) {
+ if(move.type != MovementType.TOOL_CHANGE) {
+ out.add(new Point2d(move.x,move.y));
+ }
+ }
+
+ points.setValue(out);
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/AddTurtles.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/AddTurtles.java
index e894f97c6..2de40bd8e 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/AddTurtles.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/AddTurtles.java
@@ -15,9 +15,9 @@ public class AddTurtles extends Node {
public AddTurtles() {
super("AddTurtles");
- addVariable(turtleA);
- addVariable(turtleB);
- addVariable(output);
+ addPort(turtleA);
+ addPort(turtleB);
+ addPort(output);
}
@Override
@@ -26,6 +26,6 @@ public void update() {
Turtle b = turtleB.getValue();
Turtle sum = new Turtle(a);
sum.add(b);
- output.send(sum);
+ output.setValue(sum);
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/ColorTurtle.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/ColorTurtle.java
index 7b996d1f4..fc2225ba2 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/ColorTurtle.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/ColorTurtle.java
@@ -20,9 +20,9 @@ public class ColorTurtle extends Node {
public ColorTurtle() {
super("ColorTurtle");
- addVariable(turtle);
- addVariable(color);
- addVariable(output);
+ addPort(turtle);
+ addPort(color);
+ addPort(output);
}
@Override
@@ -38,6 +38,6 @@ public void update() {
}
}
// TODO could have redundant tool changes that should be removed.
- output.send(moved);
+ output.setValue(moved);
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/CropToRectangle.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/CropToRectangle.java
new file mode 100644
index 000000000..dc6e25097
--- /dev/null
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/CropToRectangle.java
@@ -0,0 +1,41 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle;
+
+import com.marginallyclever.donatello.ports.InputInt;
+import com.marginallyclever.makelangelo.donatelloimpl.ports.InputTurtle;
+import com.marginallyclever.makelangelo.donatelloimpl.ports.OutputTurtle;
+import com.marginallyclever.makelangelo.makeart.turtletool.CropTurtle;
+import com.marginallyclever.makelangelo.turtle.Turtle;
+import com.marginallyclever.nodegraphcore.Node;
+
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Crop a {@link Turtle} to a rectangle.
+ */
+public class CropToRectangle extends Node {
+ private final InputTurtle input = new InputTurtle("input");
+ private final InputInt w = new InputInt("width", 420); // A2 width
+ private final InputInt h = new InputInt("height", 594); // A2 height
+ private final OutputTurtle output = new OutputTurtle("output");
+
+ public CropToRectangle() {
+ super("Crop");
+ addPort(input);
+ addPort(w);
+ addPort(h);
+ addPort(output);
+ }
+
+ @Override
+ public void update() {
+ var turtle = input.getValue();
+ if (turtle == null) return;
+
+ Turtle result = new Turtle(turtle);
+ var width = w.getValue();
+ var height = h.getValue();
+ Rectangle2D.Double rectangle = new Rectangle2D.Double(0, 0, width, height);
+ CropTurtle.run(result, rectangle);
+ output.setValue(result);
+ }
+}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/DetectEdges.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/DetectEdges.java
index 150394ed9..64896d002 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/DetectEdges.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/DetectEdges.java
@@ -24,9 +24,9 @@ public class DetectEdges extends Node {
public DetectEdges() {
super("DetectEdges");
- addVariable(src);
- addVariable(cutoff);
- addVariable(output);
+ addPort(src);
+ addPort(cutoff);
+ addPort(output);
}
@Override
@@ -34,6 +34,7 @@ public void update() {
BufferedImage img = src.getValue();
var edge = cutoff.getValue();
+ setComplete(0);
FilterDesaturate desaturates = new FilterDesaturate(new TransformedImage(img));
var img2 = desaturates.filter();
@@ -44,7 +45,8 @@ public void update() {
FilterExtendedDifferenceOfGaussians dog = new FilterExtendedDifferenceOfGaussians(img3,img4,20);
var img5 = dog.filter();
- output.send(marchingSquares(img5.getSourceImage(),edge));
+ output.setValue(marchingSquares(img5.getSourceImage(),edge));
+ setComplete(100);
}
Turtle marchingSquares(BufferedImage img,int edge) {
@@ -52,11 +54,19 @@ Turtle marchingSquares(BufferedImage img,int edge) {
int height = img.getHeight();
int width = img.getWidth();
+ int size=width*height;
+ int i=0;
for(int y=0;y list, double offsetValue,Color lastColor) {
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PathImageMask.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PathImageMask.java
index fb8f238ff..d18575c76 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PathImageMask.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PathImageMask.java
@@ -33,12 +33,12 @@ public class PathImageMask extends Node {
public PathImageMask() {
super("PathImageMask");
- addVariable(image);
- addVariable(turtle);
- addVariable(stepSize);
- addVariable(threshold);
- addVariable(outputAbove);
- addVariable(outputBelow);
+ addPort(image);
+ addPort(turtle);
+ addPort(stepSize);
+ addPort(threshold);
+ addPort(outputAbove);
+ addPort(outputBelow);
}
@Override
@@ -46,6 +46,8 @@ public void update() {
Turtle myTurtle = turtle.getValue();
if(myTurtle==null || myTurtle.history.isEmpty()) return;
+ setComplete(0);
+
LineCollection lines = myTurtle.getAsLineSegments();
BufferedImage src = image.getValue();
@@ -54,19 +56,22 @@ public void update() {
double s = Math.max(1, stepSize.getValue());
double c = Math.max(0,Math.min(255, threshold.getValue()));
+ int size = lines.size();
+ int i=0;
- for(LineSegment2D line : lines) {
- scanLine(src,line,s,c);
+ for (LineSegment2D line : lines) {
+ scanLine(src, line, s, c);
+ setComplete(i++ * 99 / size);
}
Turtle resultAbove = new Turtle();
resultAbove.addLineSegments(listAbove);
- outputAbove.send(resultAbove);
+ outputAbove.setValue(resultAbove);
Turtle resultBelow = new Turtle();
resultBelow.addLineSegments(listBelow);
- outputBelow.send(resultBelow);
- this.updateBounds();
+ setComplete(100);
+ outputBelow.setValue(resultBelow);
}
/**
@@ -83,35 +88,38 @@ private void scanLine(BufferedImage img, LineSegment2D segment, double stepSize,
Point2D P0 = segment.start;
Point2D P1 = segment.end;
- LineCollection toKeep = new LineCollection();
-
// clip line to image bounds because sampling outside limits causes exception.
- Point2D rMin = new Point2D(0,0);
- Point2D rMax = new Point2D(img.getWidth(),img.getHeight());
+ int w2 = img.getWidth()/2;
+ int h2 = img.getHeight()/2;
+ Point2D rMin = new Point2D(-w2,-h2);
+ Point2D rMax = new Point2D(w2,h2);
if(!Clipper2D.clipLineToRectangle(P0, P1, rMax, rMin)) {
// entire line clipped
return;
}
+ // now we know all points in the line are inside the rectangle.
// walk the line
double dx = P1.x - P0.x;
double dy = P1.y - P0.y;
double distance = Math.sqrt(dx*dx+dy*dy);
- double total = Math.min(1,Math.ceil(distance / stepSize));
- Point2D a = P0;
+ double total = Math.max(1,Math.ceil(distance / stepSize));
+ Point2D a = new Point2D(P0);
+ Point2D b = new Point2D();
for( double i = 1; i <= total; ++i ) {
double fraction = i / total;
- Point2D b = new Point2D(dx * fraction + P0.x,dy * fraction + P0.y);
- double sampleResult = sampleImageUnderStep(img,a,b);
- if(sampleResult < channelCutoff) {
+ b.set(P0.x + dx * fraction,
+ P0.y + dy * fraction);
+ var test = sampleImageUnderStep(img,a,b);
+ if(test < channelCutoff) {
listBelow.add(new LineSegment2D(a,b, Color.BLACK));
} else {
listAbove.add(new LineSegment2D(a,b, Color.BLACK));
}
- a = b;
+ a.set(b);
}
-
+
// TODO run a mini-merge to reduce the number of new segments?
}
@@ -124,16 +132,21 @@ private void scanLine(BufferedImage img, LineSegment2D segment, double stepSize,
*/
private double sampleImageUnderStep(BufferedImage img, Point2D a, Point2D b) {
// find the top-left and bottom-right corners
- int left = (int)Math.floor(Math.min(a.x,b.x));
- int right = (int)Math.ceil(Math.max(a.x,b.x));
- int bottom = (int)Math.floor(Math.min(a.y,b.y));
- int top = (int)Math.ceil(Math.max(a.y,b.y));
- double total = Math.max(1,(right-left) * (top-bottom));
+ int left = (int)Math.min(a.x,b.x);
+ int right = (int)Math.max(a.x,b.x);
+ int bottom = (int)Math.min(a.y,b.y);
+ int top = (int)Math.max(a.y,b.y);
+ int w2 = img.getWidth()/2;
+ int h2 = img.getHeight()/2;
+
// get the average of the intensities
double sum = 0;
- for(int y=bottom; y=img.getWidth() || y<0 || y>=img.getHeight()) continue;
+ sum += intensity(img.getRGB(x, y));
+ total++;
}
}
return Math.max(0,Math.min(255, sum / total ));
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PatternOnPath.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PatternOnPath.java
index 569af68a6..3a4fe25c3 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PatternOnPath.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PatternOnPath.java
@@ -19,10 +19,10 @@ public class PatternOnPath extends Node {
public PatternOnPath() {
super("PatternOnPath");
- addVariable(pattern);
- addVariable(path);
- addVariable(count);
- addVariable(output);
+ addPort(pattern);
+ addPort(path);
+ addPort(count);
+ addPort(output);
}
@Override
@@ -44,6 +44,6 @@ public void update() {
}
}
setComplete(100);
- output.send(sum);
+ output.setValue(sum);
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Perturb.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Perturb.java
index 8c6a48842..e8f280f50 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Perturb.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Perturb.java
@@ -21,9 +21,9 @@ public class Perturb extends Node {
public Perturb() {
super("Perturb");
- addVariable(turtleIn);
- addVariable(maxDistance);
- addVariable(turtleOut);
+ addPort(turtleIn);
+ addPort(maxDistance);
+ addPort(turtleOut);
}
@Override
@@ -53,6 +53,6 @@ public void update() {
}
setComplete(100);
- turtleOut.send(out);
+ turtleOut.setValue(out);
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PointOnPath.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PointOnPath.java
index 067c28b74..92d02c83a 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PointOnPath.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PointOnPath.java
@@ -29,11 +29,11 @@ public class PointOnPath extends Node {
public PointOnPath() {
super("PointOnPath");
- addVariable(path);
- addVariable(px);
- addVariable(py);
- addVariable(nx);
- addVariable(ny);
+ addPort(path);
+ addPort(px);
+ addPort(py);
+ addPort(nx);
+ addPort(ny);
}
private static final double EPSILON=0.00001;
@@ -44,10 +44,10 @@ public void update() {
double total = myPath.getDrawDistance();
double c0 = index.getValue().doubleValue();
if(total==0 || c0 <= 0) {
- px.send(0d);
- px.send(0d);
- nx.send(1d);
- ny.send(0d);
+ px.setValue(0d);
+ px.setValue(0d);
+ nx.setValue(1d);
+ ny.setValue(0d);
return;
}
@@ -63,9 +63,9 @@ public void update() {
double dy = p1.y - p0.y;
Point2D n = new Point2D(dx,dy);
n.normalize();
- px.send(p0.x);
- py.send(p0.y);
- nx.send(n.x);
- ny.send(n.y);
+ px.setValue(p0.x);
+ py.setValue(p0.y);
+ nx.setValue(n.x);
+ ny.setValue(n.y);
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PrintTurtle.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PrintTurtle.java
index 2b659b1d0..37975e4e0 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PrintTurtle.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/PrintTurtle.java
@@ -12,6 +12,7 @@
import org.slf4j.LoggerFactory;
import java.awt.*;
+import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
@@ -29,52 +30,56 @@ public class PrintTurtle extends Node implements PrintWithGraphics {
private final InputBoolean showTravel = new InputBoolean("show travel",false);
private final InputColor travelColor = new InputColor("travel color",Color.GREEN);
private final InputInt lineThickness = new InputInt("line thickness",1);
+ private final InputInt layer = new InputInt("layer",5);
- private final List polylines = new ArrayList<>();
-
+ private BufferedImage image = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
private final Lock lock = new ReentrantLock();
public PrintTurtle() {
super("PrintTurtle");
- addVariable(turtle);
- addVariable(showTravel);
- addVariable(travelColor);
- addVariable(lineThickness);
+ addPort(turtle);
+ addPort(showTravel);
+ addPort(travelColor);
+ addPort(lineThickness);
+ addPort(layer);
}
@Override
public void update() {
lock.lock();
try {
- polylines.clear();
+ setComplete(0);
Turtle myTurtle = turtle.getValue();
- if (myTurtle == null || myTurtle.history.isEmpty()) return;
-
- generatePolylines(myTurtle);
+ image = TurtleToBufferedImage.generateImage(myTurtle,this);
+ //generatePolylines(myTurtle);
+ setComplete(100);
+ } catch(Exception e) {
+ logger.error("Failed to update", e);
} finally {
lock.unlock();
}
}
+ @Override
+ public int getLayer() {
+ return layer.getValue();
+ }
+
@Override
public void print(Graphics g) {
if(getComplete()<100) return;
Turtle myTurtle = turtle.getValue();
if(myTurtle==null || myTurtle.history.isEmpty()) return;
-
- Graphics2D g2 = (Graphics2D)g.create();
- GraphViewPanel.setHints(g2);
- g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2.setStroke(new BasicStroke(lineThickness.getValue()));
- lock.lock();
- try {
- polylines.forEach(p -> p.draw(g2));
- } finally {
- lock.unlock();
- }
+ //drawPolyglines(g);
+ g.drawImage(image,-image.getWidth()/2,-image.getHeight()/2,null);
}
+ private final List polylines = new ArrayList<>();
+
private void generatePolylines(Turtle myTurtle) {
+ polylines.clear();
+ if (myTurtle == null || myTurtle.history.isEmpty()) return;
+
int size = myTurtle.history.size();
int count = 0;
@@ -119,4 +124,20 @@ private void generatePolylines(Turtle myTurtle) {
}
setComplete(100);
}
+
+ private void drawPolylines(Graphics g) {
+ Graphics2D g2 = (Graphics2D)g.create();
+ GraphViewPanel.setHints(g2);
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setStroke(new BasicStroke(lineThickness.getValue()));
+
+ lock.lock();
+ try {
+ polylines.forEach(p -> p.draw(g2));
+ } finally {
+ lock.unlock();
+ }
+
+ g2.dispose();
+ }
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/SaveTurtle.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/SaveTurtle.java
index 79f8d313f..7af5ddd91 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/SaveTurtle.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/SaveTurtle.java
@@ -16,14 +16,14 @@
public class SaveTurtle extends Node {
private static final Logger logger = LoggerFactory.getLogger(SaveTurtle.class);
- private final InputFilename filename = new InputFilename("filename","");
+ private final InputFilename filename = new InputFilename("filename");
private final InputTurtle turtle = new InputTurtle("turtle");
public SaveTurtle() {
super("SaveTurtle");
- addVariable(filename);
- addVariable(turtle);
+ addPort(filename);
+ addPort(turtle);
filename.setFileChooser(TurtleFactory.getSaveFileChooser());
filename.setDialogType(true);
@@ -31,13 +31,14 @@ public SaveTurtle() {
@Override
public void update() {
- if(filename.getValue().get().isEmpty()) return;
+ String filenameValue = filename.getValue().get();
+ if(filenameValue==null || filenameValue.isEmpty()) return;
try {
PlotterSettings settings = PlotterSettingsManager.buildMakelangelo5();
- TurtleFactory.save(turtle.getValue(),filename.getValue().get(),settings);
+ TurtleFactory.save(turtle.getValue(),filenameValue,settings);
} catch (Exception e) {
- logger.warn("Failed to update, ignoring", e);
+ logger.warn("Failed to save", e);
}
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TransformTurtle.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TransformTurtle.java
index 49937b833..e34ae32a1 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TransformTurtle.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TransformTurtle.java
@@ -20,13 +20,13 @@ public class TransformTurtle extends Node {
public TransformTurtle() {
super("TransformTurtle");
- addVariable(turtle);
- addVariable(sx);
- addVariable(sy);
- addVariable(rotate);
- addVariable(tx);
- addVariable(ty);
- addVariable(output);
+ addPort(turtle);
+ addPort(sx);
+ addPort(sy);
+ addPort(rotate);
+ addPort(tx);
+ addPort(ty);
+ addPort(output);
}
@Override
@@ -36,6 +36,6 @@ public void update() {
moved.scale(sx.getValue(),sy.getValue());
moved.rotate(rotate.getValue());
moved.translate(tx.getValue(),ty.getValue());
- output.send(moved);
+ output.setValue(moved);
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TruchetTiles.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TruchetTiles.java
index 7aa77b062..f79a507b7 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TruchetTiles.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TruchetTiles.java
@@ -23,10 +23,10 @@ public class TruchetTiles extends Node {
public TruchetTiles() {
super("TruchetTiles");
- addVariable(source);
- addVariable(spaceBetweenLines);
- addVariable(linesPerTileCount);
- addVariable(output);
+ addPort(source);
+ addPort(spaceBetweenLines);
+ addPort(linesPerTileCount);
+ addPort(output);
}
@Override
@@ -61,7 +61,7 @@ public void update() {
}
}
- output.send(turtle);
+ output.setValue(turtle);
} catch (Exception e) {
e.printStackTrace();
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleDAO4JSON.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleDAO4JSON.java
index d18b7dd52..25b883c89 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleDAO4JSON.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleDAO4JSON.java
@@ -15,6 +15,8 @@ public Object toJSON(Object object) throws JSONException {
JSONObject json = new JSONObject();
Turtle turtle = (Turtle)object;
// for a complete snapshot, capture all the instance details, too.
+ // TODO save turtle to JSON.
+
return json;
}
@@ -22,6 +24,8 @@ public Object toJSON(Object object) throws JSONException {
public Turtle fromJSON(Object object) throws JSONException {
JSONObject json = (JSONObject)object;
// for a complete snapshot, restore all the instance details, too.
- return new Turtle();
+ Turtle turtle = new Turtle();
+ // TODO load turtle from JSON
+ return turtle;
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToBufferedImage.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToBufferedImage.java
index 77d79b548..84445fe7a 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToBufferedImage.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToBufferedImage.java
@@ -19,48 +19,62 @@ public class TurtleToBufferedImage extends Node {
public TurtleToBufferedImage() {
super("TurtleToBufferedImage");
- addVariable(turtle);
- addVariable(output);
+ addPort(turtle);
+ addPort(output);
}
@Override
public void update() {
- Turtle myTurtle = turtle.getValue();
- if(myTurtle!=null && !myTurtle.history.isEmpty()) {
- Rectangle2D r = myTurtle.getBounds();
- int h = (int)Math.ceil(r.getHeight());
- int w = (int)Math.ceil(r.getWidth());
- BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
- Graphics2D g = img.createGraphics();
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
- g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
- g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_PURE);
- g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
- g.translate(-r.getX(),-r.getY());
+ Turtle source = turtle.getValue();
+ output.setValue(generateImage(source,this));
+ }
- TurtleMove previousMove = null;
- Color downColor = Color.BLACK;
+ public static BufferedImage generateImage(Turtle source,Node node) {
+ if(source==null || source.history.isEmpty()) {
+ return new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
+ }
- for (TurtleMove m : myTurtle.history) {
- if (m == null) throw new NullPointerException();
+ int size = source.history.size();
- switch (m.type) {
- case TRAVEL -> previousMove = m;
- case DRAW_LINE -> {
- if (previousMove != null) {
- g.setColor(downColor);
- g.drawLine((int) previousMove.x, (int) previousMove.y, (int) m.x, (int) m.y);
- }
- previousMove = m;
- }
- case TOOL_CHANGE -> {
- downColor = m.getColor();
- g.setStroke(new BasicStroke((int) m.getDiameter()));
+ node.setComplete(0);
+ Rectangle2D r = source.getBounds();
+ int h = (int) Math.ceil(r.getHeight());
+ int w = (int) Math.ceil(r.getWidth());
+ BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g = img.createGraphics();
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
+ g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g.translate(-r.getX(), -r.getY());
+
+ TurtleMove previousMove = null;
+ Color downColor = Color.BLACK;
+
+ int i=0;
+ for (TurtleMove m : source.history) {
+ if (m == null) throw new NullPointerException();
+
+ switch (m.type) {
+ case TRAVEL -> previousMove = m;
+ case DRAW_LINE -> {
+ if (previousMove != null) {
+ g.setColor(downColor);
+ g.drawLine((int) previousMove.x, (int) previousMove.y, (int) m.x, (int) m.y);
}
+ previousMove = m;
+ }
+ case TOOL_CHANGE -> {
+ downColor = m.getColor();
+ g.setStroke(new BasicStroke((int) m.getDiameter()));
}
}
- output.send(img);
+ node.setComplete((int) (i++ * 100.0 / size));
}
+
+ node.setComplete(100);
+
+ return img;
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToRectangle.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToRectangle.java
index 0fce6b235..5c0749a1b 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToRectangle.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/TurtleToRectangle.java
@@ -19,15 +19,15 @@ public class TurtleToRectangle extends Node {
public TurtleToRectangle() {
super("TurtleToRectangle");
- addVariable(turtle);
- addVariable(output);
+ addPort(turtle);
+ addPort(output);
}
@Override
public void update() {
Turtle myTurtle = turtle.getValue();
if(myTurtle!=null ) {
- output.send(myTurtle.getBounds());
+ output.setValue(myTurtle.getBounds());
}
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Twist.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Twist.java
index 15c1d93fd..fb9e1030c 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Twist.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/Twist.java
@@ -19,11 +19,11 @@ public class Twist extends Node {
public Twist() {
super("Twist");
- addVariable(source);
- addVariable(r0);
- addVariable(dr);
- addVariable(stepSize);
- addVariable(output);
+ addPort(source);
+ addPort(r0);
+ addPort(dr);
+ addPort(stepSize);
+ addPort(output);
}
@Override
@@ -69,7 +69,7 @@ public void update() {
setComplete((int) (t / dist * 100));
}
setComplete(100);
- output.send(result);
+ output.setValue(result);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/Line.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/Line.java
index 43678ed6c..44adc672f 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/Line.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/Line.java
@@ -21,11 +21,12 @@ public class Line extends Node {
public Line() {
super("Line");
- addVariable(x0);
- addVariable(y0);
- addVariable(x1);
- addVariable(y1);
- addVariable(contents);
+ addPort(x0);
+ addPort(y0);
+ addPort(x1);
+ addPort(y1);
+ addPort(steps);
+ addPort(contents);
}
@Override
@@ -45,6 +46,6 @@ public void update() {
turtle.penDown();
}
turtle.moveTo(px1,py1);
- contents.send(turtle);
+ contents.setValue(turtle);
}
}
diff --git a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/NGon.java b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/NGon.java
index 9912753e4..61ade89f5 100644
--- a/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/NGon.java
+++ b/src/main/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/shapes/NGon.java
@@ -16,13 +16,15 @@ public class NGon extends Node {
private final InputDouble radius = new InputDouble("radius", 10.0);
private final InputInt steps = new InputInt("subdivisions", 4);
+ private final InputDouble angle = new InputDouble("angle", 45.0);
private final OutputTurtle contents = new OutputTurtle("contents");
public NGon() {
super("NGon");
- addVariable(radius);
- addVariable(steps);
- addVariable(contents);
+ addPort(radius);
+ addPort(steps);
+ addPort(angle);
+ addPort(contents);
}
@Override
@@ -31,15 +33,16 @@ public void update() {
Turtle t = new Turtle();
double r = radius.getValue();
double s = Math.max(3,steps.getValue());
+ double startAngle = Math.toRadians(angle.getValue());
for(int i=0;i updateCOMPortList());
- connectTo.add(refreshButton,BorderLayout.EAST);
-
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx=0;
@@ -49,19 +42,15 @@ public FirmwareUploaderPanel() {
c.weightx=1;
c.weighty=0;
+ SelectButton refreshButton = new SelectButton("refresh", "⟳");
+ refreshButton.addActionListener(e -> updateCOMPortList());
+
SelectReadOnlyText help = new SelectReadOnlyText("help", Translator.get("FirmwareUploader.help"));
- add(help,c);
- c.gridy++;
- c.gridwidth=2;
- add(connectTo,c);
- c.gridy++;
- c.gridwidth=1;
- c.weightx=1;
- c.weighty=1;
- c.anchor = GridBagConstraints.PAGE_END;
- add(startM5,c);
- c.gridx++;
- add(startHuge,c);
+ help.attach(this,c); c.gridy++;
+ port.attach(this,c); c.gridy++;
+ refreshButton.attach(this,c); c.gridy++;
+ startM5.attach(this,c); c.gridy++;
+ startHuge.attach(this,c); c.gridy++;
startM5.addActionListener(e -> run(e,"firmware-m5.hex"));
startHuge.addActionListener(e -> run(e,"firmware-huge.hex"));
diff --git a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_CMYK_Circles.java b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_CMYK_Circles.java
index 5dc3395c9..09d571a35 100644
--- a/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_CMYK_Circles.java
+++ b/src/main/java/com/marginallyclever/makelangelo/makeart/imageconverter/Converter_CMYK_Circles.java
@@ -159,7 +159,6 @@ private void circlesAlongLine(double x1, double y1, double x0, double y0, Transf
private void drawCircle(double x,double y,double r) {
double circumference = Math.ceil(Math.PI*r*2.0);
Turtle t = new Turtle();
- t.history.clear();
t.setColor(turtle.getColor());
t.jumpTo(x+r,y+0);
for(int i=0;ireset());
bottom.add(buttonReset);
} else {
- machineWidth.setReadOnly();
- machineHeight.setReadOnly();
+ machineWidth.setReadOnly(true);
+ machineHeight.setReadOnly(true);
}
machineWidth.addSelectListener((e)->updateLengthNeeded());
machineHeight.addSelectListener((e)->updateLengthNeeded());
- totalStepperNeeded.setReadOnly();
- totalBeltNeeded.setReadOnly();
- totalServoNeeded.setReadOnly();
+ totalStepperNeeded.setReadOnly(true);
+ totalBeltNeeded.setReadOnly(true);
+ totalServoNeeded.setReadOnly(true);
updateLengthNeeded();
// now assemble the dialog
diff --git a/src/main/java/com/marginallyclever/makelangelo/preview/OpenGLPanel.java b/src/main/java/com/marginallyclever/makelangelo/preview/OpenGLPanel.java
index d457758fd..047e055c6 100644
--- a/src/main/java/com/marginallyclever/makelangelo/preview/OpenGLPanel.java
+++ b/src/main/java/com/marginallyclever/makelangelo/preview/OpenGLPanel.java
@@ -129,7 +129,7 @@ public void mouseWheelMoved(MouseWheelEvent e) {
p.x -= r.getCenterX();
p.y -= r.getCenterY();
- if (notches < 0) {
+ if (notches > 0) {
if (mouseLastZoomDirection == -1) camera.zoom(-1,p);
mouseLastZoomDirection = -1;
} else {
diff --git a/src/main/java/com/marginallyclever/makelangelo/turtle/Turtle.java b/src/main/java/com/marginallyclever/makelangelo/turtle/Turtle.java
index 0b3a770b8..2cb457916 100644
--- a/src/main/java/com/marginallyclever/makelangelo/turtle/Turtle.java
+++ b/src/main/java/com/marginallyclever/makelangelo/turtle/Turtle.java
@@ -439,30 +439,35 @@ public void addLineSegments(LineCollection segments) {
*/
public void addLineSegments(LineCollection segments, double minimumJumpSize, double minDrawDistance) {
if(segments.isEmpty()) return;
-
- LineSegment2D first = segments.get(0);
- jumpTo(first.start.x,first.start.y);
- moveTo(first.end.x,first.end.y);
-
- double minJumpSquared = minimumJumpSize*minimumJumpSize;
- double minDrawSquared = minDrawDistance*minDrawDistance;
-
- for( LineSegment2D line : segments ) {
- // change color if needed
- if(line.color !=getColor()) {
- setColor(line.color);
- }
- double d = distanceSquared(line.start);
- if(d > minJumpSquared) {
- // The previous line ends too far from the start point of this line,
- // need to make a travel with the pen up to the start point of this line.
- jumpTo(line.start.x,line.start.y);
- } else if(d>minDrawSquared) {
- moveTo(line.start.x,line.start.y);
+ lock();
+ try {
+ LineSegment2D first = segments.get(0);
+ jumpTo(first.start.x, first.start.y);
+ moveTo(first.end.x, first.end.y);
+
+ double minJumpSquared = minimumJumpSize * minimumJumpSize;
+ double minDrawSquared = minDrawDistance * minDrawDistance;
+
+ for (LineSegment2D line : segments) {
+ // change color if needed
+ if (line.color != getColor()) {
+ setColor(line.color);
+ }
+
+ double d = distanceSquared(line.start);
+ if (d > minJumpSquared) {
+ // The previous line ends too far from the start point of this line,
+ // need to make a travel with the pen up to the start point of this line.
+ jumpTo(line.start.x, line.start.y);
+ } else if (d > minDrawSquared) {
+ moveTo(line.start.x, line.start.y);
+ }
+ // Make a pen down move to the end of this line
+ moveTo(line.end.x, line.end.y);
}
- // Make a pen down move to the end of this line
- moveTo(line.end.x,line.end.y);
+ } finally {
+ unlock();
}
}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index fc81122b3..5abb3b6f2 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -29,14 +29,18 @@
requires com.marginallyclever.nodegraphcore;
exports com.marginallyclever.communications;
- exports com.marginallyclever.makelangelo.makeart;
- exports com.marginallyclever.makelangelo.makeart.imagefilter;
- exports com.marginallyclever.makelangelo.makeart.turtletool;
- exports com.marginallyclever.makelangelo.paper;
exports com.marginallyclever.makelangelo.donatelloimpl to com.marginallyclever.nodegraphcore;
exports com.marginallyclever.makelangelo.donatelloimpl.nodes to com.marginallyclever.nodegraphcore;
exports com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle.shapes to com.marginallyclever.nodegraphcore;
+ exports com.marginallyclever.makelangelo.donatelloimpl.ports to com.marginallyclever.nodegraphcore;
+ exports com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle to com.marginallyclever.nodegraphcore;
+ exports com.marginallyclever.makelangelo.donatelloimpl.nodes.points to com.marginallyclever.nodegraphcore;
exports com.marginallyclever.convenience.log to ch.qos.logback.core;
+ exports com.marginallyclever.makelangelo.makeart;
+ exports com.marginallyclever.makelangelo.makeart.imagefilter;
+ exports com.marginallyclever.makelangelo.makeart.turtletool;
+ exports com.marginallyclever.makelangelo.paper;
+ exports com.marginallyclever.makelangelo.turtle;
opens com.marginallyclever.convenience;
opens com.marginallyclever.makelangelo.turtle;
@@ -47,8 +51,6 @@
opens com.marginallyclever.convenience.helpers;
opens com.marginallyclever.convenience.log to ch.qos.logback.core;
opens com.marginallyclever.makelangelo.preview;
- exports com.marginallyclever.makelangelo.donatelloimpl.ports to com.marginallyclever.nodegraphcore;
- exports com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle to com.marginallyclever.nodegraphcore;
// A Java module that wants to implement a service interface from a service interface module must:
// - Require the service interface module in its own module descriptor.
diff --git a/src/test/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/SaveTurtleTest.java b/src/test/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/SaveTurtleTest.java
new file mode 100644
index 000000000..41ec315de
--- /dev/null
+++ b/src/test/java/com/marginallyclever/makelangelo/donatelloimpl/nodes/turtle/SaveTurtleTest.java
@@ -0,0 +1,39 @@
+package com.marginallyclever.makelangelo.donatelloimpl.nodes.turtle;
+
+import com.marginallyclever.makelangelo.turtle.Turtle;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class SaveTurtleTest {
+ @Test
+ public void test() {
+ // make a simple drawing
+ Turtle turtle = new Turtle();
+ turtle.penDown();
+ turtle.forward(100);
+ turtle.turn(90);
+ turtle.forward(100);
+
+ SaveTurtle saveTurtle = new SaveTurtle();
+
+ try {
+ // create a temp file
+ File tempSvgFile = File.createTempFile("turtleTest", ".svg");
+ tempSvgFile.deleteOnExit();
+ // set it as the output path
+ saveTurtle.getPort("filename").setValue(tempSvgFile.getAbsolutePath());
+ saveTurtle.getPort("turtle").setValue(turtle);
+ saveTurtle.update();
+
+ assertTrue(Files.size(tempSvgFile.toPath()) > 0, "The SVG file should not be empty.");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/src/test/java/com/marginallyclever/makelangelo/paper/PaperSettingsPanelTest.java b/src/test/java/com/marginallyclever/makelangelo/paper/PaperSettingsPanelTest.java
index 4f946d411..8468a2c05 100644
--- a/src/test/java/com/marginallyclever/makelangelo/paper/PaperSettingsPanelTest.java
+++ b/src/test/java/com/marginallyclever/makelangelo/paper/PaperSettingsPanelTest.java
@@ -48,11 +48,11 @@ public void tearDown() {
public void testLandscapeToPortrait() {
JPanelFixture panel = window.panel(PaperSettingsPanel.class.getSimpleName());
panel.requireVisible();
- panel.panel("size").comboBox().selectItem(1);
+ panel.comboBox("size.field").selectItem(1);
assert(Double.parseDouble(panel.textBox("width.field").text()) == 1682.0);
assert(Double.parseDouble(panel.textBox("height.field").text()) == 2378.0);
- panel.panel("size").comboBox().selectItem(1);
- panel.panel("landscape").checkBox().click();
+ panel.comboBox("size.field").selectItem(1);
+ panel.checkBox("landscape.field").click();
assert(Double.parseDouble(panel.textBox("width.field").text()) == 2378.0);
assert(Double.parseDouble(panel.textBox("height.field").text()) == 1682.0);
}
diff --git a/src/test/java/com/marginallyclever/makelangelo/select/SelectDoubleTest.java b/src/test/java/com/marginallyclever/makelangelo/select/SelectDoubleTest.java
deleted file mode 100644
index 13635e5a3..000000000
--- a/src/test/java/com/marginallyclever/makelangelo/select/SelectDoubleTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.marginallyclever.makelangelo.select;
-
-import com.marginallyclever.donatello.select.SelectDouble;
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Locale;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class SelectDoubleTest {
- private static final Logger logger = LoggerFactory.getLogger(SelectDoubleTest.class);
- protected int testObservation;
-
- protected void testFloatField() throws Exception {
- // test contructor(s)
- SelectDouble b = new SelectDouble("test","test",0);
- assertEquals(0.0f,b.getValue(),1e-6);
- b = new SelectDouble("test2","test2",0.1f);
- assertEquals(0.1f,b.getValue(),1e-6);
- b.setValue(2000.34f);
- assertEquals(2000.34f,b.getValue(),1e-6);
- }
-
- @Test
- public void testAllFloatFields() throws Exception {
- logger.debug("testAllFloatFields() start");
- Locale original = Locale.getDefault();
- Locale [] list = Locale.getAvailableLocales();
-
- for( Locale loc : list ) {
- logger.debug("Locale={} {}", loc.toString(), loc.getDisplayLanguage());
- Locale.setDefault(loc);
- testFloatField();
- }
- Locale.setDefault(original);
- logger.debug("testAllFloatFields() end");
- }
-}
diff --git a/src/test/java/com/marginallyclever/makelangelo/select/SelectGUITest.java b/src/test/java/com/marginallyclever/makelangelo/select/SelectGUITest.java
deleted file mode 100644
index cceebef39..000000000
--- a/src/test/java/com/marginallyclever/makelangelo/select/SelectGUITest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package com.marginallyclever.makelangelo.select;
-
-import com.marginallyclever.donatello.select.*;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.awt.*;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-public class SelectGUITest {
- private SelectPanel panel;
- private int testObservation;
-
- @BeforeEach
- public void beforeEach() {
- panel = new SelectPanel();
- }
-
- @Test
- public void testBoolean() {
- // test contructor(s)
- SelectBoolean b = new SelectBoolean("test", "test", true);
- assertTrue(b.isSelected());
- // test constructor works
- b = new SelectBoolean("test2", "test2", false);
- assertFalse(b.isSelected());
-
- panel.add(b);
-
- // test observer fires
- testObservation = 0;
- b.addSelectListener(evt -> ++testObservation);
-
- b.setSelected(true);
- assertTrue(b.isSelected());
- assertTrue(testObservation > 0);
- testObservation = 0;
- b.setSelected(false);
- assertFalse(b.isSelected());
- assertTrue(testObservation > 0);
- }
-
- @Test
- public void testButton() {
- // test contructor(s)
- SelectButton b = new SelectButton("test", "test");
- panel.add(b);
-
- // test observer fires
- testObservation = 0;
- b.addActionListener(evt -> ++testObservation);
-
- b.doClick();
- assertTrue(testObservation > 0);
- }
-
- @Test
- public void testColor() {
- // test contructor(s)
- SelectColor b = new SelectColor("test", "test", new Color(0, 0, 0), panel);
- Color c = b.getColor();
- assertEquals(0, c.getRed());
- assertEquals(0, c.getGreen());
- assertEquals(0, c.getBlue());
-
- // test constructor sets value ok.
- b = new SelectColor("test2", "test2", new Color(1, 2, 3), panel);
- c = b.getColor();
- assertEquals(1, c.getRed());
- assertEquals(2, c.getGreen());
- assertEquals(3, c.getBlue());
-
- panel.add(b);
- // test setValue
- b.setColor(new Color(255, 128, 64));
- c = b.getColor();
- assertEquals(255, c.getRed());
- assertEquals(128, c.getGreen());
- assertEquals(64 , c.getBlue());
- }
-
- @Test
- public void testFile() {
- // test contructor(s)
- SelectFile b = new SelectFile("test", "test", null,null);
- assertTrue(b.getText().isEmpty());
- b = new SelectFile("test2", "test2", "something",null);
- assertEquals("something", b.getText());
-
- panel.add(b);
-
- // test setText
- b.setText("some path");
- }
-
- @Test
- public void testFloat() {
- // test contructor(s)
- SelectDouble b = new SelectDouble("test", "test", 0);
- assertEquals(0.0f, b.getValue(), 1e-6);
- b = new SelectDouble("test2", "test2", 0.1f);
- assertEquals(0.1f, b.getValue(), 1e-6);
-
- panel.add(b);
-
- b.setValue(0.2f);
- assertEquals(0.2f, b.getValue(), 1e-6);
- }
-
- @Test
- public void testInteger() {
- // test contructor(s)
- SelectInteger b = new SelectInteger("test", "test", 0);
- assertEquals(0, b.getValue());
- b = new SelectInteger("test2", "test2", 1);
- assertEquals(1, b.getValue());
-
- panel.add(b);
-
- b.setValue(2);
- assertEquals(2, b.getValue());
- }
-
- @Test
- public void testOneOfMany() {
- String[] list = {"a", "b", "c", "d"};
-
- // test contructor(s)
- SelectOneOfMany b = new SelectOneOfMany("test", "test", list, 0);
- assertEquals(0, b.getSelectedIndex());
- assertEquals("a", b.getSelectedItem());
- b = new SelectOneOfMany("test2", "test2", list, 1);
- assertEquals(1, b.getSelectedIndex());
- assertEquals("b", b.getSelectedItem());
-
- panel.add(b);
-
- // test observer fires
- testObservation = 0;
- b.addSelectListener(evt -> ++testObservation);
-
- b.setSelectedIndex(2);
- assertTrue(testObservation > 0);
- assertEquals(2, b.getSelectedIndex());
- assertEquals("c", b.getSelectedItem());
- }
-
- @Test
- public void testSlider() {
- // test contructor(s)
- SelectSlider b = new SelectSlider("test", "test", 100, 0, 10);
- assertEquals(10, b.getValue());
- b = new SelectSlider("test2", "test2", 100, 0, 20);
- assertEquals(20, b.getValue());
-
- panel.add(b);
-
- // test observer fires
- testObservation = 0;
- b.addSelectListener(evt -> ++testObservation);
-
- b.setValue(30);
- assertEquals(30, b.getValue());
- assertTrue(testObservation > 0);
- b.setValue(110);
- assertNotEquals(110, b.getValue());
- b.setValue(-10);
- assertNotEquals(-10, b.getValue());
- }
-
- @Test
- public void testTextArea() {
- // test contructor(s)
- SelectTextArea b = new SelectTextArea("test", "test", "first test");
- assertEquals("first test", b.getText());
- b = new SelectTextArea("test2", "test2", "second test");
- assertEquals("second test", b.getText());
-
- panel.add(b);
-
- // test observer fires
- testObservation = 0;
- b.addSelectListener(evt -> ++testObservation);
-
- b.setText("third test");
- assertEquals("third test", b.getText());
- assertTrue(testObservation > 0);
- }
-}
diff --git a/src/test/java/com/marginallyclever/makelangelo/select/SelectVisualInspection.java b/src/test/java/com/marginallyclever/makelangelo/select/SelectVisualInspection.java
deleted file mode 100644
index 4c3a51b0b..000000000
--- a/src/test/java/com/marginallyclever/makelangelo/select/SelectVisualInspection.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.marginallyclever.makelangelo.select;
-
-import com.marginallyclever.donatello.select.*;
-import com.marginallyclever.makelangelo.Translator;
-import com.marginallyclever.util.PreferencesHelper;
-
-import javax.swing.*;
-import java.awt.*;
-
-/**
- * Run this to visually examine every panel element and how they look in next to each other.
- * @author Dan Royer
- */
-public class SelectVisualInspection {
- public static void main(String[] args) {
- PreferencesHelper.start();
- Translator.start();
-
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (Exception ex) {
- System.out.println("failed to set native look and feel.");
- }
-
- JFrame frame = new JFrame("Select Look and feel");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().add(buildPanel());
- frame.pack();
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
-
- private static JPanel buildPanel() {
- SelectPanel panel = new SelectPanel();
- SelectBoolean a = new SelectBoolean("A","AAAAAAAAAAA",false);
- SelectButton b = new SelectButton("B","B");
- SelectColor c = new SelectColor("C","CCCCCC",Color.BLACK,panel);
- SelectFile d = new SelectFile("D","D",null,panel);
- SelectDouble e = new SelectDouble("E","E",0.0f);
- SelectInteger f = new SelectInteger("F","FFF",0);
- String [] list = {"cars","trains","planes","boats","rockets"};
- SelectOneOfMany g = new SelectOneOfMany("G","G",list,0);
- String ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Google Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
- SelectReadOnlyText h = new SelectReadOnlyText("H","H "+ipsum);
- SelectSlider i = new SelectSlider("I","I",200,0,100);
- SelectTextArea j = new SelectTextArea("J","J",ipsum);
- SelectSpinner k = new SelectSpinner("K", "K", 1, 10, 3);
- SelectTextField m = new SelectTextField("M", "M", "M");
- SelectRandomSeed n = new SelectRandomSeed("N", "N", 0);
-
- panel.add(a);
- panel.add(b);
- panel.add(c);
- panel.add(d);
- panel.add(e);
- panel.add(f);
- panel.add(g);
- panel.add(h);
- panel.add(i);
- panel.add(j);
- panel.add(k);
- panel.add(m);
- panel.add(n);
-
- // test finish
- panel.setPreferredSize(new Dimension(400,600));
-
- panel.addPropertyChangeListener((evt)-> {
- System.out.println("Event: "+evt.toString());
- });
- return panel;
- }
-}