Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualizer performance #2615

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ugs-core/src/resources/MessagesBundle_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ platform.visualizer.color.rapid = Rapid Movement Color (G0)
platform.visualizer.color.arc = Arc Movement Color (G2/G3)
platform.visualizer.color.plunge = Plunge/Raise Movement Color
platform.visualizer.color.completed = Color of lines which have been completed
platform.visualizer.grid = Show coordinates and plane
platform.visualizer.grid.desc = Show coordinates and plane
platform.visualizer.grid = Toggles grid
platform.visualizer.grid.desc = Toggles the grid
platform.visualizer.plane = Toggle plane
platform.visualizer.plane.desc = Toggles the plane
platform.visualizer.color.xy-grid = Color (and opacity) of XY grid lines.
platform.visualizer.color.xy-plane = Color (and opacity) of XY plane.
platform.visualizer.color.x-axis = Color (and opacity) of X-Axis line.
Expand Down Expand Up @@ -661,7 +663,7 @@ mainWindow.status.jog = Jog
mainWindow.status.offline = Off-line
platform.window.diagnostics = UGS Diagnostics
platform.window.diagnostics.tooltip = Internal UGS diagnostics information.
platform.visualizer.popup.showFeatures = Show features
platform.visualizer.popup.showFeatures = Features
platform.visualizer.popup.viewPresets = View presets
platform.visualizer.popup.presets.reset = Reset view
platform.visualizer.popup.presets.top = Top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This file is part of Universal Gcode Sender (UGS).
*/
package com.willwinder.ugs.platform.probe.renderable;

import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW;
import com.willwinder.ugs.nbm.visualizer.shared.Renderable;
import com.willwinder.ugs.platform.probe.ProbeParameters;
import com.willwinder.ugs.platform.probe.ProbeService;
Expand All @@ -28,8 +29,8 @@ public abstract class AbstractProbePreview extends Renderable {

private final ProbeService probeService;

public AbstractProbePreview(int priority, String title) {
super(priority, title);
protected AbstractProbePreview(int priority, String title) {
super(priority, title, VISUALIZER_OPTION_PROBE_PREVIEW);
probeService = Lookup.getDefault().lookup(ProbeService.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.gl2.GLUT;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import com.willwinder.ugs.platform.probe.ProbeParameters;
import com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.Side;
import com.willwinder.universalgcodesender.model.Position;

import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW;
import static com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.Side.NEGATIVE;
import static com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.Side.POSITIVE;
import static com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.drawArrow;
import static com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.drawTouchPlate;
import com.willwinder.universalgcodesender.model.Position;

/**
*
Expand Down Expand Up @@ -79,10 +76,6 @@ public boolean center() {
public void init(GLAutoDrawable drawable) {
}

@Override
public void reloadPreferences(VisualizerOptions vo) {
}

private boolean invalidSettings() {
return this.spacing.x == 0
&& this.spacing.y == 0
Expand Down Expand Up @@ -202,14 +195,4 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P
drawXYZ(gl, X, Y);
}
}

@Override
public boolean isEnabled() {
return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_PROBE_PREVIEW, true);
}

@Override
public void setEnabled(boolean enabled) {
VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_PROBE_PREVIEW, enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.gl2.GLUT;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW;
import com.willwinder.ugs.platform.probe.ProbeParameters;
import com.willwinder.ugs.platform.probe.ProbeSettings;
import com.willwinder.ugs.platform.probe.renderable.ProbeRenderableHelpers.Triangle;
Expand Down Expand Up @@ -228,16 +226,6 @@ public void updateSettings() {
updateSpacing(ProbeSettings.getHcDiameter() * scaleFactor);
}

@Override
public boolean isEnabled() {
return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_PROBE_PREVIEW, true);
}

@Override
public void setEnabled(boolean enabled) {
VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_PROBE_PREVIEW, enabled);
}

public void updateSpacing(double hcDiameter) {
this.hcDiameter = hcDiameter;
}
Expand All @@ -256,10 +244,6 @@ public boolean center() {
public void init(GLAutoDrawable drawable) {
}

@Override
public void reloadPreferences(VisualizerOptions vo) {
}

private boolean invalidSettings() {
return this.hcDiameter <= 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.gl2.GLUT;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PROBE_PREVIEW;
import com.willwinder.ugs.platform.probe.ProbeParameters;
import com.willwinder.ugs.platform.probe.ProbeSettings;
import com.willwinder.universalgcodesender.i18n.Localization;
Expand Down Expand Up @@ -76,10 +74,6 @@ public boolean center() {
public void init(GLAutoDrawable drawable) {
}

@Override
public void reloadPreferences(VisualizerOptions vo) {
}

@Override
public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, Position workCoord, Position objectMin, Position objectMax, double scaleFactor, Position mouseWorldCoordinates, Position rotation) {
if (this.probeDepth == null || this.probeOffset == null) return;
Expand Down Expand Up @@ -110,14 +104,4 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P
gl.glTranslated(0, 0, zAbs - 1);
glut.glutSolidCone(.2, 1, slices, stacks);
}

@Override
public boolean isEnabled() {
return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_PROBE_PREVIEW, true);
}

@Override
public void setEnabled(boolean enabled) {
VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_PROBE_PREVIEW, enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
@ActionReferences({
@ActionReference(
path = LocalizingService.MENU_EDIT,
position = 1900,
separatorAfter = 2000),
position = 1901,
separatorAfter = 1999),
})
public class InsertPositionAction extends AbstractAction implements UGSEventListener {
public static final String NAME = LocalizingService.InsertPositionTitle;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016-2021 Will Winder
Copyright 2016-2024 Will Winder

This file is part of Universal Gcode Sender (UGS).

Expand All @@ -23,14 +23,13 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_EDITOR_POSITION;
import com.willwinder.ugs.nbm.visualizer.renderables.GcodeModel;
import com.willwinder.ugs.nbm.visualizer.shared.Renderable;
import com.willwinder.universalgcodesender.model.Position;

import java.awt.Color;

import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_EDITOR_POSITION;

/**
* Displays a pointer on the given line number
*
Expand All @@ -43,7 +42,7 @@ public class EditorPosition extends Renderable {
private Position position;

public EditorPosition(GcodeModel model, String title) {
super(10, title);
super(10, title, VISUALIZER_OPTION_EDITOR_POSITION);
this.model = model;
}

Expand All @@ -62,10 +61,6 @@ public void init(GLAutoDrawable drawable) {
GQ = GLU.gluNewQuadric();
}

@Override
public void reloadPreferences(VisualizerOptions vo) {
}

@Override
public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, Position workCoord, Position focusMin, Position focusMax, double scaleFactor, Position mouseCoordinates, Position rotation) {
if (position == null || GQ == null) {
Expand Down Expand Up @@ -97,14 +92,4 @@ public void setLineNumber(int lineNumber) {
.findFirst()
.ifPresent(lineSegment -> position = lineSegment.getEnd());
}

@Override
public boolean isEnabled() {
return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_EDITOR_POSITION, true);
}

@Override
public void setEnabled(boolean enabled) {
VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_EDITOR_POSITION, enabled);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016-2022 Will Winder
Copyright 2016-2024 Will Winder

This file is part of Universal Gcode Sender (UGS).

Expand All @@ -22,8 +22,11 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.GL2ES3;
import com.jogamp.opengl.GLAutoDrawable;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_HIGHLIGHT;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_HIGHLIGHT_COLOR;
import com.willwinder.ugs.nbm.visualizer.renderables.GcodeModel;
import com.willwinder.ugs.nbm.visualizer.shared.Renderable;
import static com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.getAngle;
import com.willwinder.universalgcodesender.gcode.util.Plane;
import com.willwinder.universalgcodesender.gcode.util.PlaneFormatter;
import com.willwinder.universalgcodesender.model.CNCPoint;
Expand All @@ -33,13 +36,8 @@ This file is part of Universal Gcode Sender (UGS).
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_HIGHLIGHT;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_HIGHLIGHT_COLOR;
import static com.willwinder.universalgcodesender.gcode.GcodePreprocessorUtils.getAngle;

/**
* Highlights the selected lines in the editor. It will attempt to buffer the lines with quads to make them more visible
* because GL's line width is platform dependant and is also deprecated.
Expand All @@ -60,13 +58,14 @@ public class Highlight extends Renderable {
private int endLine = 0;

public Highlight(GcodeModel model, String title) {
super(9, title);
super(9, title, VISUALIZER_OPTION_HIGHLIGHT);
this.model = model;
reloadPreferences(new VisualizerOptions());
}

@Override
public final void reloadPreferences(VisualizerOptions vo) {
super.reloadPreferences(vo);
highlightColor = vo.getOptionForKey(VISUALIZER_OPTION_HIGHLIGHT_COLOR).value;
}

Expand Down Expand Up @@ -138,18 +137,8 @@ private void generateBufferedLines() {
CNCPoint dPoint = new Position(lineSegment.getStart()).add(xyOffset).add(zOffset);
return Stream.of(aPoint, bPoint, cPoint, dPoint);
})
.collect(Collectors.toList());
.toList();

points.addAll(newPoints);
}

@Override
public void setEnabled(boolean enabled) {
VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_HIGHLIGHT, enabled);
}

@Override
public boolean isEnabled() {
return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_HIGHLIGHT, true);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2017 Will Winder
Copyright 2017-2024 Will Winder

This file is part of Universal Gcode Sender (UGS).

Expand All @@ -24,18 +24,16 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.util.gl2.GLUT;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_AUTOLEVEL_PREVIEW;
import com.willwinder.ugs.nbm.visualizer.shared.Renderable;
import com.willwinder.universalgcodesender.model.CNCPoint;
import com.willwinder.universalgcodesender.model.Position;
import com.willwinder.universalgcodesender.model.UnitUtils;
import com.willwinder.universalgcodesender.model.UnitUtils.Units;

import java.util.Arrays;
import java.util.Deque;
import java.util.stream.DoubleStream;

import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_AUTOLEVEL_PREVIEW;

/**
* @author wwinder
*/
Expand All @@ -53,7 +51,7 @@ public class AutoLevelPreview extends Renderable {
private float[] low = {255, 0, 0}; // red

public AutoLevelPreview(String title) {
super(10, title);
super(10, title, VISUALIZER_OPTION_AUTOLEVEL_PREVIEW);

glut = new GLUT();

Expand All @@ -76,6 +74,7 @@ public void init(GLAutoDrawable drawable) {

@Override
public final void reloadPreferences(VisualizerOptions vo) {
super.reloadPreferences(vo);
high = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VisualizerOptions.VISUALIZER_OPTION_HIGH).value);
low = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VisualizerOptions.VISUALIZER_OPTION_LOW).value);
}
Expand Down Expand Up @@ -239,11 +238,6 @@ private DoubleStream getGridZStream() {
.filter(z -> !Double.isNaN(z));
}

@Override
public boolean isEnabled() {
return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_AUTOLEVEL_PREVIEW, true);
}

@Override
public void setEnabled(boolean enabled) {
if (VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_AUTOLEVEL_PREVIEW, true) != enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ This file is part of Universal Gcode Sender (UGS).
import com.willwinder.universalgcodesender.model.events.CommandEventType;
import com.willwinder.universalgcodesender.model.events.ControllerStatusEvent;
import com.willwinder.universalgcodesender.model.events.FileStateEvent;
import com.willwinder.universalgcodesender.model.events.SettingChangedEvent;
import com.willwinder.universalgcodesender.utils.Settings;
import com.willwinder.universalgcodesender.utils.Settings.FileStats;
import org.apache.commons.lang3.SystemUtils;
Expand Down Expand Up @@ -86,7 +85,6 @@ public RendererInputHandler(GcodeRenderer gr, AnimatorBase a, BackendAPI backend
gcodeModel = new GcodeModel(Localization.getString("platform.visualizer.renderable.gcode-model"), backend);
sizeDisplay = new SizeDisplay(Localization.getString("platform.visualizer.renderable.gcode-model-size"));
selection = new Selection(Localization.getString("platform.visualizer.renderable.selection"));
sizeDisplay.setUnits(settings.getPreferredUnits());

gr.registerRenderable(gcodeModel);
gr.registerRenderable(sizeDisplay);
Expand Down Expand Up @@ -160,8 +158,6 @@ public void UGSEvent(UGSEvent cse) {
}

animator.resume();
} else if (cse instanceof SettingChangedEvent) {
sizeDisplay.setUnits(settings.getPreferredUnits());
} else if (cse instanceof ControllerStatusEvent controllerStatusEvent) {
gcodeRenderer.setMachineCoordinate(controllerStatusEvent.getStatus().getMachineCoord());
gcodeRenderer.setWorkCoordinate(controllerStatusEvent.getStatus().getWorkCoord());
Expand Down
Loading
Loading