Skip to content

Commit

Permalink
fix various UX problems in plotter settings
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Jul 4, 2024
1 parent da3048e commit 1ed3500
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -255,3 +274,5 @@ private void fireSettingsChangedEvent() {
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer;

import javax.vecmath.Vector2d;
import java.util.Arrays;

/**
Expand All @@ -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() {
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
Expand Down Expand Up @@ -149,33 +149,14 @@ 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()) {
paintPenHolderToCounterweights(context, 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ public boolean isSelected() {

public void setSelected(boolean b) {
field.setSelected(b);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 1ed3500

Please sign in to comment.