From 1ed350052d283e5431f70153903f54b24404fca6 Mon Sep 17 00:00:00 2001 From: Dan Royer Date: Thu, 4 Jul 2024 14:49:04 -0700 Subject: [PATCH] fix various UX problems in plotter settings --- .../apps/PlotterSettingsPanel.java | 41 ++++++++++++++----- .../apps/previewpanel/PreviewPanel.java | 2 +- .../plotterrenderer/MakelangeloCustom.java | 2 +- .../PlotterRendererFactory.java | 25 +++++++---- .../plotterrenderer/Polargraph.java | 23 +---------- .../plotterrenderer/Zarplotter.java | 36 +++++++++++++--- .../makelangelo/select/SelectBoolean.java | 3 +- .../makelangelo/select/SelectDouble.java | 4 +- .../makelangelo/select/SelectOneOfMany.java | 12 ++++-- 9 files changed, 95 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/PlotterSettingsPanel.java b/src/main/java/com/marginallyclever/makelangelo/apps/PlotterSettingsPanel.java index 90dc50e53..bfeb7b0f9 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/PlotterSettingsPanel.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/PlotterSettingsPanel.java @@ -117,16 +117,17 @@ private void rebuildPanel() { bottom.add(buttonSave); bottom.add(buttonReset); } else { - machineWidth.setReadOnly(true); - machineHeight.setReadOnly(true); + visualStyle.setEnabled(false); + machineWidth.setEditable(false); + machineHeight.setEditable(false); } machineWidth.addSelectListener((e)->updateLengthNeeded()); machineHeight.addSelectListener((e)->updateLengthNeeded()); - totalStepperNeeded.setReadOnly(true); - totalBeltNeeded.setReadOnly(true); - totalServoNeeded.setReadOnly(true); + totalStepperNeeded.setEditable(false); + totalBeltNeeded.setEditable(false); + totalServoNeeded.setEditable(false); updateLengthNeeded(); JTabbedPane tabbedPane = new JTabbedPane(); @@ -140,16 +141,34 @@ private void rebuildPanel() { this.add(bottom,BorderLayout.SOUTH); this.repaint(); - visualStyle.addSelectListener(e->updateSizeEditable()); - updateSizeEditable(); + visualStyle.addSelectListener(e-> changeStyle()); + changeStyle(); } - private void updateSizeEditable() { + /** + * Change the visual style of the machine. + * If the style is not custom, then the width and height should become locked. + * If the style is locked and the visual style has a default value, then the width and height should be set to the default value. + */ + private void changeStyle() { + // make editable var isNotCustom = !visualStyle.getSelectedItem().equals(PlotterRendererFactory.MAKELANGELO_CUSTOM.name()); var isAncestral = settings.isMostAncestral(); var matches = isNotCustom | isAncestral; - machineWidth.setReadOnly(matches); - machineHeight.setReadOnly(matches); + + // do we have a default value? + if(matches) { + PlotterRendererFactory factory = PlotterRendererFactory.valueOf(visualStyle.getSelectedItem()); + var fixedSize = factory.getFixedSize(); + var hasFixed = (fixedSize!=null); + machineWidth.setEditable(!hasFixed); + machineHeight.setEditable(!hasFixed); + if(hasFixed) { + // update size + machineWidth.setValue(fixedSize.x); + machineHeight.setValue(fixedSize.y); + } + } } private void addToPanel(SelectPanel panel, Select element) { @@ -255,3 +274,5 @@ private void fireSettingsChangedEvent() { } } } + + diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java index b9cb6f88d..90f790593 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/PreviewPanel.java @@ -488,7 +488,7 @@ public void setTurtleRenderer(TurtleRenderer renderer) { public void updatePlotterSettings(PlotterSettings settings) { try { - myPlotter.getSettings().load(myPlotter.getSettings().getUID()); + myPlotter.getSettings().load(settings.getUID()); var style = myPlotter.getSettings().getString(PlotterSettings.STYLE); myPlotterRenderer = PlotterRendererFactory.valueOf(style).getPlotterRenderer(); } catch (Exception e) { diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java index 66e54e284..c427806c9 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/MakelangeloCustom.java @@ -41,6 +41,7 @@ public MakelangeloCustom() { @Override public void render(RenderContext context, Plotter robot) { + paintSafeArea(context,robot); paintControlBox(context,robot.getSettings()); paintMotors(context,robot); if(robot.getDidFindHome()) @@ -67,7 +68,6 @@ private void paintControlBox(RenderContext context, PlotterSettings settings) { // mounting plate for PCB context.shader.setColor(context.gl,"diffuseColor", new Color(255,204,127,255)); drawRectangle(context, top+35f, right+30f, top-35f, left-30f); - context.shader.setColor(context.gl,"diffuseColor", Color.WHITE); // wires to each motor diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRendererFactory.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRendererFactory.java index 3aa52583c..1a9ab0ca7 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRendererFactory.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/PlotterRendererFactory.java @@ -1,5 +1,6 @@ package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer; +import javax.vecmath.Vector2d; import java.util.Arrays; /** @@ -10,20 +11,21 @@ */ public enum PlotterRendererFactory { // name must match enum label for PlotterRendererFactory.valueOf() to work. - MAKELANGELO_5("MAKELANGELO_5", new Makelangelo5()), - MAKELANGELO_5_HUGE("MAKELANGELO_5_HUGE", new Makelangelo5Huge()), - MAKELANGELO_3_3("MAKELANGELO_3_3", new Makelangelo3_3()), - MAKELANGELO_CUSTOM("MAKELANGELO_CUSTOM", new MakelangeloCustom()), - CARTESIAN("CARTESIAN", new Cartesian()), - ZARPLOTTER("ZARPLOTTER", new Zarplotter()); + MAKELANGELO_5("MAKELANGELO_5", new Makelangelo5(), new Vector2d(650, 1000)), + MAKELANGELO_5_HUGE("MAKELANGELO_5_HUGE", new Makelangelo5Huge(), new Vector2d(1336,2000)), + MAKELANGELO_3_3("MAKELANGELO_3_3", new Makelangelo3_3(), null), + MAKELANGELO_CUSTOM("MAKELANGELO_CUSTOM", new MakelangeloCustom(), null), + CARTESIAN("CARTESIAN", new Cartesian(),null), + ZARPLOTTER("ZARPLOTTER", new Zarplotter(),null); private final PlotterRenderer plotterRenderer; - private final String name; + private final Vector2d fixedSize; - PlotterRendererFactory(String name, PlotterRenderer plotterRenderer) { + PlotterRendererFactory(String name, PlotterRenderer plotterRenderer,Vector2d fixedSize) { this.name = name; this.plotterRenderer = plotterRenderer; + this.fixedSize = fixedSize; } public PlotterRenderer getPlotterRenderer() { @@ -34,6 +36,13 @@ public String getName() { return name; } + /** + * @return the fixed size of the plotter renderer, or null if it is not fixed. + */ + public Vector2d getFixedSize() { + return fixedSize; + } + public static PlotterRendererFactory findByName(String name) { return Arrays.stream(values()) .filter(enumValue -> enumValue.getName().contains(name)) diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java index e62b0483e..543d63978 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Polargraph.java @@ -81,7 +81,6 @@ public void drawRectangle(RenderContext context, double top, double right, doubl m.m11 = (top-bottom)/2; m.setTranslation(new Vector3d((left+right)/2,(top+bottom)/2,0)); m.transpose(); - context.shader.setColor(context.gl,"diffuseColor", Color.WHITE); context.shader.setMatrix4d(context.gl,"modelMatrix", m); meshQuad.render(context.gl); context.shader.setMatrix4d(context.gl,"modelMatrix", MatrixHelper.createIdentityMatrix4()); @@ -98,6 +97,7 @@ public void drawRectangle(RenderContext context, double top, double right, doubl public void paintTexture(RenderContext context, TextureWithMetadata texture, double x, double y, double width, double height) { texture.use(context.gl); context.shader.set1i(context.gl,"useTexture",1); + context.shader.setColor(context.gl,"diffuseColor", Color.WHITE); drawRectangle(context, y+height/2, x+width/2, y-height/2, x-width/2); context.shader.set1i(context.gl,"useTexture",0); } @@ -149,8 +149,7 @@ public Point2d IK(Plotter plotter,double x,double y) { @Override public void render(RenderContext context, Plotter robot) { - drawPhysicalLimits(context,robot); - + paintSafeArea(context,robot); paintMotors(context, robot); paintControlBox(context, robot); if(robot.getDidFindHome()) { @@ -158,24 +157,6 @@ public void render(RenderContext context, Plotter robot) { } } - /** - * Outline the drawing limits - * @param context the rendering context - */ - private void drawPhysicalLimits(RenderContext context,Plotter robot) { -// TODO implement me -/* - mesh.addColor(0.9f, 0.9f, 0.9f,1.0f); // #color - - gl.glBegin(GL3.GL_LINE_LOOP); - var settings = robot.getSettings(); - gl.glVertex2d(settings.getDouble(PlotterSettings.LIMIT_LEFT), settings.getDouble(PlotterSettings.LIMIT_TOP)); - gl.glVertex2d(settings.getDouble(PlotterSettings.LIMIT_RIGHT), settings.getDouble(PlotterSettings.LIMIT_TOP)); - gl.glVertex2d(settings.getDouble(PlotterSettings.LIMIT_RIGHT), settings.getDouble(PlotterSettings.LIMIT_BOTTOM)); - gl.glVertex2d(settings.getDouble(PlotterSettings.LIMIT_LEFT), settings.getDouble(PlotterSettings.LIMIT_BOTTOM)); - gl.glEnd();*/ - } - public void paintMotors(RenderContext context,Plotter robot) { double top = robot.getSettings().getDouble(PlotterSettings.LIMIT_TOP); double right = robot.getSettings().getDouble(PlotterSettings.LIMIT_RIGHT); diff --git a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java index f6cc8e906..a6af6e27b 100644 --- a/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java +++ b/src/main/java/com/marginallyclever/makelangelo/apps/previewpanel/plotterrenderer/Zarplotter.java @@ -15,7 +15,7 @@ /** * @author Dan Royer */ -public class Zarplotter implements PlotterRenderer { +public class Zarplotter extends Polargraph implements PlotterRenderer { public static final int ZAR_MOTOR_MOUNT_SIZE=45; //cm public static final int ZAR_PLOTTER_SIZE=60; //cm public static final int ZAR_PLOTTER_OUTER_SIZE=70; //cm @@ -43,6 +43,7 @@ private void setupMesh() { @Override public void render(RenderContext context, Plotter robot) { + paintSafeArea(context,robot); paintMotors(context,robot); paintControlBox(context,robot); if(robot.getDidFindHome()) @@ -54,7 +55,8 @@ public void updatePlotterSettings(PlotterSettings settings) { } - private void paintPenHolderToCounterweights(RenderContext context, Plotter robot) { + @Override + public void paintPenHolderToCounterweights(RenderContext context, Plotter robot) { // TODO implement me /* PlotterSettings settings = robot.getSettings(); @@ -104,7 +106,8 @@ private void paintPenHolderToCounterweights(RenderContext context, Plotter robot gl.glEnd();*/ } - private void paintMotors(RenderContext context,Plotter plotter) { + @Override + public void paintMotors(RenderContext context,Plotter plotter) { double top = plotter.getSettings().getDouble(PlotterSettings.LIMIT_TOP); double bottom = plotter.getSettings().getDouble(PlotterSettings.LIMIT_BOTTOM); double right = plotter.getSettings().getDouble(PlotterSettings.LIMIT_RIGHT); @@ -157,8 +160,31 @@ private void paintOneMotor(RenderContext context,Matrix4d m) { context.shader.setColor(context.gl,"diffuseColor", Color.BLACK); meshQuad.render(context.gl); } - - private void paintControlBox(RenderContext context,Plotter plotter) { + + @Override + public void paintSafeArea(RenderContext context, Plotter robot) { + PlotterSettings settings = robot.getSettings(); + double top = settings.getDouble(PlotterSettings.LIMIT_TOP); + double bottom = settings.getDouble(PlotterSettings.LIMIT_BOTTOM); + double left = settings.getDouble(PlotterSettings.LIMIT_LEFT); + double right = settings.getDouble(PlotterSettings.LIMIT_RIGHT); + + Matrix4d m = new Matrix4d(); + m.setIdentity(); + m.m00 = (right-left); + m.m11 = (top-bottom); + m.setTranslation(new Vector3d(left,bottom,0)); + m.transpose(); + context.shader.setColor(context.gl,"diffuseColor", Color.WHITE); + context.shader.setMatrix4d(context.gl,"modelMatrix", m); + meshQuad.setRenderStyle(GL3.GL_LINE_LOOP); + meshQuad.render(context.gl); + meshQuad.setRenderStyle(GL3.GL_QUADS); + context.shader.setMatrix4d(context.gl,"modelMatrix", MatrixHelper.createIdentityMatrix4()); + } + + @Override + public void paintControlBox(RenderContext context,Plotter plotter) { // TODO implement me /* double cy = plotter.getSettings().getDouble(PlotterSettings.LIMIT_TOP); diff --git a/src/main/java/com/marginallyclever/makelangelo/select/SelectBoolean.java b/src/main/java/com/marginallyclever/makelangelo/select/SelectBoolean.java index 2808ea355..16d82dfd1 100644 --- a/src/main/java/com/marginallyclever/makelangelo/select/SelectBoolean.java +++ b/src/main/java/com/marginallyclever/makelangelo/select/SelectBoolean.java @@ -35,6 +35,5 @@ public boolean isSelected() { public void setSelected(boolean b) { field.setSelected(b); - } - + } } diff --git a/src/main/java/com/marginallyclever/makelangelo/select/SelectDouble.java b/src/main/java/com/marginallyclever/makelangelo/select/SelectDouble.java index 225b7a09d..1528d8320 100644 --- a/src/main/java/com/marginallyclever/makelangelo/select/SelectDouble.java +++ b/src/main/java/com/marginallyclever/makelangelo/select/SelectDouble.java @@ -98,8 +98,8 @@ protected SelectDouble(String internalName) { this(internalName,"", Locale.getDefault(), 0); } - public void setReadOnly(boolean state) { - field.setEditable(!state); + public void setEditable(boolean state) { + field.setEditable(state); } // @return last valid value typed into field diff --git a/src/main/java/com/marginallyclever/makelangelo/select/SelectOneOfMany.java b/src/main/java/com/marginallyclever/makelangelo/select/SelectOneOfMany.java index dad4f31cc..ccdf95b4d 100644 --- a/src/main/java/com/marginallyclever/makelangelo/select/SelectOneOfMany.java +++ b/src/main/java/com/marginallyclever/makelangelo/select/SelectOneOfMany.java @@ -45,10 +45,16 @@ public void removeItem(String s) { model.removeElement(s); } - public void setReadOnly() { - field.setEditable(false); + public void setEditable(boolean state) { + field.setEditable(state); } - + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + field.setEnabled(enabled); + } + public String getSelectedItem() { return (String)field.getSelectedItem(); }