diff --git a/ugs-core/src/resources/MessagesBundle_en_US.properties b/ugs-core/src/resources/MessagesBundle_en_US.properties index b2bc3d75bd..501187bb03 100644 --- a/ugs-core/src/resources/MessagesBundle_en_US.properties +++ b/ugs-core/src/resources/MessagesBundle_en_US.properties @@ -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. @@ -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 diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java index 0cb32c082f..26afe116dd 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/AbstractProbePreview.java @@ -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; @@ -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); } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java index e466d07bb8..3abea23855 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/CornerProbePathPreview.java @@ -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; /** * @@ -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 @@ -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); - } } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java index 8c1bd6539f..6ea8671706 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/HoleCenterPathPreview.java @@ -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; @@ -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; } @@ -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; } diff --git a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java index d6ddec0f18..3b2410b6a7 100644 --- a/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java +++ b/ugs-platform/ProbeModule/src/main/java/com/willwinder/ugs/platform/probe/renderable/ZProbePathPreview.java @@ -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; @@ -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; @@ -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); - } } diff --git a/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/actions/InsertPositionAction.java b/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/actions/InsertPositionAction.java index b19163108d..370f2d6090 100644 --- a/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/actions/InsertPositionAction.java +++ b/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/actions/InsertPositionAction.java @@ -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; diff --git a/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/EditorPosition.java b/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/EditorPosition.java index 86e14dbb0a..23d11b1383 100644 --- a/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/EditorPosition.java +++ b/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/EditorPosition.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2021 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -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 * @@ -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; } @@ -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) { @@ -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); - } } diff --git a/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/Highlight.java b/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/Highlight.java index 9cbfffa7eb..aa1fb9a4b6 100644 --- a/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/Highlight.java +++ b/ugs-platform/ugs-platform-gcode-editor/src/main/java/com/willwinder/ugs/nbp/editor/renderer/Highlight.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2022 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -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; @@ -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. @@ -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; } @@ -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); - } } diff --git a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/renderable/AutoLevelPreview.java b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/renderable/AutoLevelPreview.java index 3fa432c1cd..b09b48b340 100644 --- a/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/renderable/AutoLevelPreview.java +++ b/ugs-platform/ugs-platform-surfacescanner/src/main/java/com/willwinder/ugs/platform/surfacescanner/renderable/AutoLevelPreview.java @@ -1,5 +1,5 @@ /* - Copyright 2017 Will Winder + Copyright 2017-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -24,6 +24,7 @@ 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; @@ -31,11 +32,8 @@ This file is part of Universal Gcode Sender (UGS). 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 */ @@ -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(); @@ -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); } @@ -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) { diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java index 7e309abccc..aee1d98acd 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/RendererInputHandler.java @@ -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; @@ -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); @@ -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()); diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/VisualizerToolBar.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/VisualizerToolBar.java index d622c4f60b..ca6f56a910 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/VisualizerToolBar.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/VisualizerToolBar.java @@ -1,5 +1,5 @@ /* - Copyright 2022 Will Winder + Copyright 2022-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -22,11 +22,29 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.nbm.visualizer.actions.CameraXPreset; import com.willwinder.ugs.nbm.visualizer.actions.CameraYPreset; import com.willwinder.ugs.nbm.visualizer.actions.CameraZPreset; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleBoundaryFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleGridFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleModelFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleMouseFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleOrientationFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.TogglePlaneFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleSelectFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleSizeFeatureAction; +import com.willwinder.ugs.nbm.visualizer.actions.ToggleToolFeatureAction; import com.willwinder.ugs.nbp.core.actions.OutlineAction; import com.willwinder.ugs.nbp.core.actions.ToggleUnitAction; import com.willwinder.ugs.nbp.core.ui.ToolBar; +import org.openide.awt.DropDownButtonFactory; +import org.openide.util.ImageUtilities; -import javax.swing.*; +import javax.swing.Action; +import javax.swing.Box; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.JToggleButton; +import java.awt.event.ActionListener; /** * A toolbar for visualizer actions @@ -34,28 +52,76 @@ This file is part of Universal Gcode Sender (UGS). * @author Joacim Breiler */ public class VisualizerToolBar extends ToolBar { + private JButton cameraPresetButton = null; + public VisualizerToolBar() { setFloatable(false); initComponents(); } private void initComponents() { - createAndAddButton(new CameraResetPreset()); - createAndAddButton(new CameraXPreset()); - createAndAddButton(new CameraYPreset()); - createAndAddButton(new CameraZPreset()); + add(createCameraPresetDropDownButton()); + addSeparator(); + createAndAddToggleButton(new TogglePlaneFeatureAction()); + createAndAddToggleButton(new ToggleGridFeatureAction()); + createAndAddToggleButton(new ToggleSizeFeatureAction()); + createAndAddToggleButton(new ToggleToolFeatureAction()); + createAndAddToggleButton(new ToggleBoundaryFeatureAction()); + createAndAddToggleButton(new ToggleSelectFeatureAction()); + createAndAddToggleButton(new ToggleOrientationFeatureAction()); + createAndAddToggleButton(new ToggleModelFeatureAction()); + createAndAddToggleButton(new ToggleMouseFeatureAction()); addSeparator(); createAndAddButton(new OutlineAction()); add(Box.createGlue()); createAndAddButton(new ToggleUnitAction()); } + private void createAndAddToggleButton(Action action) { + JToggleButton resetPresetButton = new JToggleButton(action); + resetPresetButton.setText(""); + resetPresetButton.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); + this.add(resetPresetButton); + } + private void createAndAddButton(Action action) { JButton resetPresetButton = new JButton(action); resetPresetButton.setText(""); resetPresetButton.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); - resetPresetButton.setContentAreaFilled(false); - resetPresetButton.setBorderPainted(false); this.add(resetPresetButton); } + + + private JButton createCameraPresetDropDownButton() { + // An action listener that listens to the popup menu items and changes the current action + ActionListener toolMenuListener = e -> { + if (cameraPresetButton == null) { + return; + } + + JMenuItem source = (JMenuItem) e.getSource(); + cameraPresetButton.setIcon((Icon) source.getAction().getValue(Action.LARGE_ICON_KEY)); + cameraPresetButton.setSelected(false); + cameraPresetButton.setAction(source.getAction()); + }; + + CameraResetPreset cameraResetPreset = new CameraResetPreset(); + JPopupMenu popupMenu = new JPopupMenu(); + addDropDownAction(popupMenu, cameraResetPreset, toolMenuListener); + addDropDownAction(popupMenu, new CameraXPreset(), toolMenuListener); + addDropDownAction(popupMenu, new CameraYPreset(), toolMenuListener); + addDropDownAction(popupMenu, new CameraZPreset(), toolMenuListener); + cameraPresetButton = DropDownButtonFactory.createDropDownButton(ImageUtilities.loadImageIcon(CameraResetPreset.LARGE_ICON_PATH, false), popupMenu); + cameraPresetButton.setAction(cameraResetPreset); + return cameraPresetButton; + } + + private void addDropDownAction(JPopupMenu popupMenu, Action action, ActionListener actionListener) { + JMenuItem menuItem = new JMenuItem(action); + if (actionListener != null) { + menuItem.addActionListener(actionListener); + } + popupMenu.add(menuItem); + } + } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/MoveCameraAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/MoveCameraAction.java index 72211eee4b..9981d63e90 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/MoveCameraAction.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/MoveCameraAction.java @@ -1,5 +1,5 @@ /* - Copyright 2017-2018 Will Winder + Copyright 2017-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -31,7 +31,7 @@ This file is part of Universal Gcode Sender (UGS). */ public class MoveCameraAction extends AbstractAction { - public static final Position CAMERA_POSITION = new Position(0, 0, 1.5); + public static final Position CAMERA_POSITION = new Position(0, 0, 3); public static final Position ROTATION_TOP = new Position(0, 0, 0); public static final Position ROTATION_LEFT = new Position(90, -90, 0); public static final Position ROTATION_FRONT = new Position(0, -90, 0); diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleBoundaryFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleBoundaryFeatureAction.java new file mode 100644 index 0000000000..ac4ba56e3c --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleBoundaryFeatureAction.java @@ -0,0 +1,58 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleBoundaryFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleBoundaryFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle boundary", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1090) +}) +public class ToggleBoundaryFeatureAction extends ToggleFeatureAction { + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleBoundaryFeatureAction"; + public static final String SMALL_ICON_PATH = "icons/boundary.svg"; + public static final String LARGE_ICON_PATH = "icons/boundary24.svg"; + + public ToggleBoundaryFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_BOUNDRY, VisualizerOptions.VISUALIZER_OPTION_BOUNDRY_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleFeatureAction.java new file mode 100644 index 0000000000..b01bb6d11b --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleFeatureAction.java @@ -0,0 +1,73 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.universalgcodesender.i18n.Localization; +import org.openide.awt.Actions; +import org.openide.util.ImageUtilities; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import java.awt.event.ActionEvent; + +/** + * A action base class for toggling a feature in the visualizer + * + * @author Joacim Breiler + */ +public class ToggleFeatureAction extends AbstractAction { + public static final String SMALL_ICON_PATH = "icons/grid.svg"; + public static final String LARGE_ICON_PATH = "icons/grid24.svg"; + + private final String toggleKey; + + protected ToggleFeatureAction(String toggleKey, String descriptionKey) { + this.toggleKey = toggleKey; + + String title = Localization.getString(toggleKey); + putValue(NAME, title); + putValue("menuText", title); + putValue(SHORT_DESCRIPTION, Localization.getString(descriptionKey)); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + + updateState(); + VisualizerOptions.addListener(this::updateState); + } + + @Override + public void actionPerformed(ActionEvent e) { + boolean newValue = !VisualizerOptions.getBooleanOption(toggleKey, true); + VisualizerOptions.setBooleanOption(toggleKey, newValue); + + updateState(); + } + + private void updateState() { + boolean value = VisualizerOptions.getBooleanOption(toggleKey, true); + putValue(Action.SELECTED_KEY, value); + putValue(Actions.ACTION_VALUE_TOGGLE, value); + setEnabled(true); + VisualizerOptions.setBooleanOption(toggleKey, value); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleGridFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleGridFeatureAction.java new file mode 100644 index 0000000000..0d480bbf6a --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleGridFeatureAction.java @@ -0,0 +1,58 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleGridFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleGridFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle grid", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1075) +}) +public class ToggleGridFeatureAction extends ToggleFeatureAction { + public static final String SMALL_ICON_PATH = "icons/grid.svg"; + public static final String LARGE_ICON_PATH = "icons/grid24.svg"; + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleGridFeatureAction"; + + + public ToggleGridFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_GRID, VisualizerOptions.VISUALIZER_OPTION_GRID_DESC); + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleModelFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleModelFeatureAction.java new file mode 100644 index 0000000000..f22cf9f199 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleModelFeatureAction.java @@ -0,0 +1,58 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleModelFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleModelFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle tool path", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1110) +}) +public class ToggleModelFeatureAction extends ToggleFeatureAction { + public static final String SMALL_ICON_PATH = "icons/model.svg"; + public static final String LARGE_ICON_PATH = "icons/model24.svg"; + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleModelFeatureAction"; + + public ToggleModelFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_MODEL, VisualizerOptions.VISUALIZER_OPTION_MODEL_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleMouseFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleMouseFeatureAction.java new file mode 100644 index 0000000000..313a27e0a1 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleMouseFeatureAction.java @@ -0,0 +1,58 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleMouseFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleMouseFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle mouse", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1120) +}) +public class ToggleMouseFeatureAction extends ToggleFeatureAction { + public static final String SMALL_ICON_PATH = "icons/mouse.svg"; + public static final String LARGE_ICON_PATH = "icons/mouse24.svg"; + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleMouseFeatureAction"; + + public ToggleMouseFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_MOUSE_OVER, VisualizerOptions.VISUALIZER_OPTION_MOUSE_OVER_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleOrientationFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleOrientationFeatureAction.java new file mode 100644 index 0000000000..19937a5aeb --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleOrientationFeatureAction.java @@ -0,0 +1,58 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleOrientationFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleOrientationFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle orientation cube", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1100) +}) +public class ToggleOrientationFeatureAction extends ToggleFeatureAction { + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleOrientationFeatureAction"; + public static final String SMALL_ICON_PATH = "icons/cube.svg"; + public static final String LARGE_ICON_PATH = "icons/cube24.svg"; + + public ToggleOrientationFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_ORIENTATION_CUBE, VisualizerOptions.VISUALIZER_OPTION_ORIENTATION_CUBE_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/TogglePlaneFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/TogglePlaneFeatureAction.java new file mode 100644 index 0000000000..b016cd3de2 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/TogglePlaneFeatureAction.java @@ -0,0 +1,57 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = TogglePlaneFeatureAction.ID +) +@ActionRegistration( + iconBase = TogglePlaneFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle plane", + lazy = false +) +@ActionReferences({ + @ActionReference( + separatorBefore = 1069, + path = LocalizingService.MENU_VISUALIZER, + position = 1070) +}) +public class TogglePlaneFeatureAction extends ToggleFeatureAction { + public static final String SMALL_ICON_PATH = "icons/plane.svg"; + public static final String LARGE_ICON_PATH = "icons/plane24.svg"; + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.TogglePlaneFeatureAction"; + + public TogglePlaneFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_PLANE, VisualizerOptions.VISUALIZER_OPTION_PLANE_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleSelectFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleSelectFeatureAction.java new file mode 100644 index 0000000000..2ad1f4398a --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleSelectFeatureAction.java @@ -0,0 +1,59 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleSelectFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleSelectFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle selected lines", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1095) +}) +public class ToggleSelectFeatureAction extends ToggleFeatureAction { + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleSelectFeatureAction"; + public static final String SMALL_ICON_PATH = "icons/select.svg"; + public static final String LARGE_ICON_PATH = "icons/select24.svg"; + + public ToggleSelectFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_SELECTION, VisualizerOptions.VISUALIZER_OPTION_SELECTION_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleSizeFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleSizeFeatureAction.java new file mode 100644 index 0000000000..cf97180f76 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleSizeFeatureAction.java @@ -0,0 +1,58 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleSizeFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleSizeFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle size", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1080) +}) +public class ToggleSizeFeatureAction extends ToggleFeatureAction { + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleSizeFeatureAction"; + public static final String SMALL_ICON_PATH = "icons/size.svg"; + public static final String LARGE_ICON_PATH = "icons/size24.svg"; + + public ToggleSizeFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_SIZE_DISPLAY, VisualizerOptions.VISUALIZER_OPTION_SIZE_DISPLAY_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleToolFeatureAction.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleToolFeatureAction.java new file mode 100644 index 0000000000..cc5d7ba812 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/actions/ToggleToolFeatureAction.java @@ -0,0 +1,58 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.actions; + +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbp.lib.services.LocalizingService; +import com.willwinder.universalgcodesender.model.BackendAPI; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.ActionState; +import org.openide.util.ImageUtilities; + +@ActionID( + category = LocalizingService.CATEGORY_VISUALIZER, + id = ToggleToolFeatureAction.ID +) +@ActionRegistration( + iconBase = ToggleToolFeatureAction.SMALL_ICON_PATH, + displayName = "Toggle tool", + checkedOn = @ActionState(type = BackendAPI.class, useActionInstance = true) +) +@ActionReferences({ + @ActionReference( + path = LocalizingService.MENU_VISUALIZER, + position = 1085) +}) +public class ToggleToolFeatureAction extends ToggleFeatureAction { + public static final String ID = "com.willwinder.ugs.nbm.visualizer.actions.ToggleToolFeatureAction"; + public static final String SMALL_ICON_PATH = "icons/tool.svg"; + public static final String LARGE_ICON_PATH = "icons/tool24.svg"; + + public ToggleToolFeatureAction() { + super(VisualizerOptions.VISUALIZER_OPTION_TOOL, VisualizerOptions.VISUALIZER_OPTION_TOOL_DESC); + + putValue("iconBase", SMALL_ICON_PATH); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); + putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/options/VisualizerOptions.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/options/VisualizerOptions.java index 8ac0a31212..3ece686cf8 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/options/VisualizerOptions.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/options/VisualizerOptions.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2022 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -65,11 +65,14 @@ public class VisualizerOptions extends ArrayList> { public static String VISUALIZER_OPTION_GRID = "platform.visualizer.grid"; public static String VISUALIZER_OPTION_GRID_DESC = "platform.visualizer.grid.desc"; public static String VISUALIZER_OPTION_XY_GRID = "platform.visualizer.color.xy-grid"; - public static String VISUALIZER_OPTION_XY_PLANE = "platform.visualizer.color.xy-plane"; public static String VISUALIZER_OPTION_X = "platform.visualizer.color.x-axis"; public static String VISUALIZER_OPTION_Y = "platform.visualizer.color.y-axis"; public static String VISUALIZER_OPTION_Z = "platform.visualizer.color.z-axis"; + public static final String VISUALIZER_OPTION_PLANE = "platform.visualizer.plane"; + public static final String VISUALIZER_OPTION_PLANE_DESC = "platform.visualizer.plane.desc"; + public static final String VISUALIZER_OPTION_PLANE_COLOR = "platform.visualizer.color.xy-plane"; + // SizeDisplay renderable public static String VISUALIZER_OPTION_SIZE = "platform.visualizer.color.sizedisplay"; @@ -140,11 +143,13 @@ public VisualizerOptions() { // Grid renderable add(getOption(VISUALIZER_OPTION_GRID, Localization.getString(VISUALIZER_OPTION_GRID_DESC), true)); add(getOption(VISUALIZER_OPTION_XY_GRID, "", new Color(179,179,179, 29))); - add(getOption(VISUALIZER_OPTION_XY_PLANE, "", new Color(77,77,77,29))); add(getOption(VISUALIZER_OPTION_X, "", new Color(230,0,0))); add(getOption(VISUALIZER_OPTION_Y, "", new Color(0,230,0))); add(getOption(VISUALIZER_OPTION_Z, "", new Color(0,0,230))); + add(getOption(VISUALIZER_OPTION_PLANE, Localization.getString(VISUALIZER_OPTION_PLANE_DESC), true)); + add(getOption(VISUALIZER_OPTION_PLANE_COLOR, "", new Color(77,77,77,29))); + // SizeDisplay renderable add(getOption(VISUALIZER_OPTION_SIZE_DISPLAY, Localization.getString(VISUALIZER_OPTION_SIZE_DISPLAY_DESC), true)); add(getOption(VISUALIZER_OPTION_SIZE, "", new Color(128,128,128))); @@ -170,6 +175,10 @@ public VisualizerOptions() { add(getOption(VISUALIZER_OPTION_DOWEL_PREVIEW, Localization.getString(VISUALIZER_OPTION_DOWEL_PREVIEW_DESC), true)); } + public static void addListener(Runnable runnable) { + NbPreferences.forModule(VisualizerOptions.class).addPreferenceChangeListener(l -> runnable.run()); + } + private Option getOption(String op, String desc, int defaultValue) { return new Option<>(op, Localization.getString(op), desc, getIntegerOption(op, defaultValue)); } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/GcodeModel.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/GcodeModel.java index ba5dd3f908..046aa5e623 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/GcodeModel.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/GcodeModel.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2023 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -85,7 +85,7 @@ public class GcodeModel extends Renderable implements UGSEventListener { private Position objectSize; public GcodeModel(String title, BackendAPI backend) { - super(10, title); + super(10, title, VISUALIZER_OPTION_MODEL); objectSize = new Position(0, 0, 0); reloadPreferences(new VisualizerOptions()); this.backend = backend; @@ -94,6 +94,7 @@ public GcodeModel(String title, BackendAPI backend) { @Override public final void reloadPreferences(VisualizerOptions vo) { + super.reloadPreferences(vo); colorizer.reloadPreferences(vo); vertexBufferDirty = true; } @@ -384,16 +385,6 @@ private void updateGLColorArray() { } - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_MODEL, true); - } - - @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_MODEL, enabled); - } - @Override public void UGSEvent(UGSEvent evt) { if (evt instanceof ControllerStateEvent stateEvent) { diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Grid.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Grid.java index 0099834380..55675adbc3 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Grid.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Grid.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2022 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -18,183 +18,80 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.nbm.visualizer.renderables; -import static com.jogamp.opengl.GL.GL_LINES; +import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2; -import com.jogamp.opengl.GLAutoDrawable; import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; - import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_GRID; import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_X; import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_XY_GRID; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_XY_PLANE; import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_Y; import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_Z; -import com.willwinder.ugs.nbm.visualizer.shared.Renderable; +import com.willwinder.ugs.nbm.visualizer.shared.VertexObjectRenderable; import com.willwinder.universalgcodesender.model.Position; -import com.willwinder.universalgcodesender.visualizer.VisualizerUtils; /** - * * @author wwinder */ -public class Grid extends Renderable { +public class Grid extends VertexObjectRenderable { private float[] gridLineColor; - private float[] gridPlaneColor; private float[] xAxisColor; private float[] yAxisColor; private float[] zAxisColor; public Grid(String title) { - super(5, title); + super(6, title, VISUALIZER_OPTION_GRID); reloadPreferences(new VisualizerOptions()); } @Override - final public void reloadPreferences(VisualizerOptions vo) { + public final void reloadPreferences(VisualizerOptions vo) { + super.reloadPreferences(vo); gridLineColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_XY_GRID).value); - gridPlaneColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_XY_PLANE).value); xAxisColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_X).value); yAxisColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_Y).value); zAxisColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_Z).value); } @Override - public boolean enableLighting() { - return false; - } - - @Override - public boolean rotate() { - return true; - } - - @Override - public boolean center() { - return true; + public void render(GL2 gl) { + gl.glLineWidth(1.2f); + gl.glDisable(GL.GL_DEPTH_TEST); + gl.glDrawArrays(GL.GL_LINES, 0, getVertexCount()); } @Override - public void init(GLAutoDrawable drawable) { - } - - private double getBestStepSize(double maxSide) { - return maxSide/20; - } - - private double getDistFromZeroForStepSize(double stepSize, double point, boolean min) { - if (stepSize < 0.01) return min ? -1 : 1; - - // Get remainder. - double remainder = Math.abs(point); - while (remainder >= stepSize/2) { - remainder -= stepSize; - } - - if (point <= 0) { - if (min) { - return point - (stepSize - remainder); - } else { - return point + remainder; - } - } - else { - if (min) { - return point - remainder; - } else { - return point + (stepSize - remainder); + public void reloadModel(GL2 gl, Position bottomLeft, Position topRight, double scaleFactor) { + for (double x = bottomLeft.x; x <= topRight.x; x += getStepSize()) { + for (double y = bottomLeft.y; y <= topRight.y; y += getStepSize()) { + if (x == 0) continue; + addVertex(x, bottomLeft.y, 0); + addColor(gridLineColor); + + addVertex(x, topRight.y, 0); + addColor(gridLineColor); + + if (y == 0) continue; + addVertex(bottomLeft.x, y, 0); + addColor(gridLineColor); + + addVertex(topRight.x, y, 0); + addColor(gridLineColor); } } - } - @Override - public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, Position workCoord, Position focusMin, Position focusMax, double scaleFactor, Position mouseCoordinates, Position rotation) { - double maxSide = VisualizerUtils.findMaxSide(focusMin, focusMax); - if (maxSide == 0) { - maxSide = 1; - } - Position bottomLeft = new Position(focusMin); - Position topRight = new Position(focusMax); - - // Setup the stepSize and min/max edges so that the lines look right. - double stepSize = getBestStepSize(maxSide); - bottomLeft.x = getDistFromZeroForStepSize(stepSize, bottomLeft.x, true); - bottomLeft.y = getDistFromZeroForStepSize(stepSize, bottomLeft.y, true); - topRight.x = getDistFromZeroForStepSize(stepSize, topRight.x, false); - topRight.y = getDistFromZeroForStepSize(stepSize, topRight.y, false); - - GL2 gl = drawable.getGL().getGL2(); - gl.glPushMatrix(); - double offset = 0.001; - - gl.glLineWidth(1.5f); - // grid - gl.glBegin(GL_LINES); - for(double x=bottomLeft.x;x<=topRight.x;x+=stepSize) { - for (double y=bottomLeft.y; y<=topRight.y; y+=stepSize) { - if (x==0) continue; - gl.glColor4fv(gridLineColor, 0); - - gl.glVertex3d(x, bottomLeft.y, offset); - gl.glVertex3d(x, topRight.y , offset); - - gl.glVertex3d(x, bottomLeft.y, -offset); - gl.glVertex3d(x, topRight.y , -offset); - - if (y==0) continue; - gl.glColor4fv(gridLineColor, 0); - gl.glVertex3d(bottomLeft.x, y, offset); - gl.glVertex3d(topRight.x , y, offset); - - gl.glVertex3d(bottomLeft.x, y, -offset); - gl.glVertex3d(topRight.x , y, -offset); - } - } - gl.glEnd(); - - gl.glLineWidth(5f); - gl.glBegin(GL_LINES); - // X Axis Line - gl.glColor4fv(yAxisColor, 0); - gl.glVertex3d(0, bottomLeft.y, offset); - gl.glVertex3d(0, topRight.y , offset); - - gl.glVertex3d(0, bottomLeft.y, -offset); - gl.glVertex3d(0, topRight.y , -offset); - - // Y Axis Line - gl.glColor4fv(xAxisColor, 0); - gl.glVertex3d(bottomLeft.x, 0, offset); - gl.glVertex3d(topRight.x , 0, offset); - - gl.glVertex3d(bottomLeft.x, 0, -offset); - gl.glVertex3d(topRight.x , 0, -offset); - - // Z Axis Line - gl.glColor4fv(zAxisColor, 0); - gl.glVertex3d(0, 0, bottomLeft.z); - gl.glVertex3d(0, 0, Math.max(topRight.z, -bottomLeft.z)); - gl.glEnd(); - - //gl.glColor4f(.3f,.3f,.3f, .09f); - gl.glColor4fv(gridPlaneColor, 0); - - // floor - cover entire model and a little extra. - gl.glBegin(GL2.GL_QUADS); - gl.glVertex3d(bottomLeft.x, bottomLeft.y, 0); - gl.glVertex3d(bottomLeft.x, topRight.y , 0); - gl.glVertex3d(topRight.x , topRight.y , 0); - gl.glVertex3d(topRight.x , bottomLeft.y, 0); - gl.glEnd(); - gl.glPopMatrix(); - } + addVertex(0, bottomLeft.y, 0); + addColor(yAxisColor); + addVertex(0, topRight.y, 0); + addColor(yAxisColor); - @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_GRID, enabled); - } + addVertex(bottomLeft.x, 0, 0); + addColor(xAxisColor); + addVertex(topRight.x, 0, 0); + addColor(xAxisColor); - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_GRID, true); + addVertex(0, 0, bottomLeft.z); + addColor(zAxisColor); + addVertex(0, 0, Math.max(topRight.z, -bottomLeft.z)); + addColor(zAxisColor); } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java index cf235075d1..f143b5197d 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MachineBoundries.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2023 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -54,7 +54,7 @@ public class MachineBoundries extends Renderable { * to lowest priority. */ public MachineBoundries(String title) { - super(Integer.MIN_VALUE, title); + super(Integer.MIN_VALUE, title, VISUALIZER_OPTION_BOUNDRY); reloadPreferences(new VisualizerOptions()); backendAPI = CentralLookup.getDefault().lookup(BackendAPI.class); backendAPI.addUGSEventListener(this::onUGSEvent); @@ -112,6 +112,7 @@ public void init(GLAutoDrawable drawable) { @Override public void reloadPreferences(VisualizerOptions vo) { + super.reloadPreferences(vo); machineBoundryBottomColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VisualizerOptions.VISUALIZER_OPTION_BOUNDRY_BASE).value); machineBoundryLineColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VisualizerOptions.VISUALIZER_OPTION_BOUNDRY_SIDES).value); xAxisColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_X).value); @@ -216,14 +217,4 @@ private void drawSides(GL2 gl, Position bottomLeft, Position topRight) { gl.glVertex3d(topRight.x, topRight.y, topRight.getZ()); gl.glEnd(); } - - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_BOUNDRY, true); - } - - @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_BOUNDRY, enabled); - } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MouseOver.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MouseOver.java index 6604ed3b8e..2778524614 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MouseOver.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/MouseOver.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2022 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -18,17 +18,17 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.nbm.visualizer.renderables; +import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; 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_MOUSE_OVER; import com.willwinder.ugs.nbm.visualizer.shared.Renderable; import com.willwinder.universalgcodesender.model.Position; -import java.awt.Color; -import java.util.logging.Logger; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_MOUSE_OVER; +import java.awt.Color; /** * Draws a vertical line along the Z axis at the (X,Y) coordinate where the @@ -38,13 +38,12 @@ This file is part of Universal Gcode Sender (UGS). * @author wwinder */ public class MouseOver extends Renderable { - private static final Logger logger = Logger.getLogger(MouseOver.class.getName()); private static final GLU GLU = new GLU(); private static GLUquadric GQ; public MouseOver(String title) { - super(8, title); + super(5, title, VISUALIZER_OPTION_MOUSE_OVER); } @Override @@ -62,10 +61,6 @@ public void init(GLAutoDrawable drawable) { GQ = GLU.gluNewQuadric(); } - @Override - public void reloadPreferences(VisualizerOptions vo) { - } - static private boolean inBounds(Position point, Position bottomLeft, Position topRight) { if (point.x > topRight.x || point.x < bottomLeft.x) return false; if (point.y > topRight.y || point.y < bottomLeft.y) return false; @@ -82,6 +77,8 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P double scale = 1. / (scaleFactor * 2); gl.glPushMatrix(); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glTranslated(mouseWorldCoordinates.x, mouseWorldCoordinates.y, 0.); gl.glScaled(scale, scale, scale); @@ -93,14 +90,4 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P gl.glPopMatrix(); } } - - @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_MOUSE_OVER, enabled); - } - - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_MOUSE_OVER, true); - } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/OrientationCube.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/OrientationCube.java index d81f169b27..b01539d830 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/OrientationCube.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/OrientationCube.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2022 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -23,14 +23,13 @@ This file is part of Universal Gcode Sender (UGS). import static com.jogamp.opengl.GL.GL_DEPTH_TEST; import com.jogamp.opengl.GL2; import static com.jogamp.opengl.GL2ES3.GL_QUADS; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_ORIENTATION_CUBE; - import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.fixedfunc.GLMatrixFunc; import com.jogamp.opengl.util.awt.TextRenderer; -import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_ORIENTATION_CUBE; import com.willwinder.ugs.nbm.visualizer.shared.Renderable; import com.willwinder.universalgcodesender.model.Position; + import java.awt.Font; import java.awt.geom.Rectangle2D; @@ -48,15 +47,10 @@ public class OrientationCube extends Renderable { private float textScaleFactor; public OrientationCube(float s, String title) { - super(Integer.MIN_VALUE, title); + super(Integer.MIN_VALUE, title, VISUALIZER_OPTION_ORIENTATION_CUBE); size = s; } - @Override - public void reloadPreferences(VisualizerOptions vo) { - - } - @Override public boolean rotate() { return true; @@ -196,14 +190,4 @@ private void drawFace(GL2 gl, gl.glDisable(GL_CULL_FACE); gl.glEnable(GL_DEPTH_TEST); } - - @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_ORIENTATION_CUBE, enabled); - } - - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_ORIENTATION_CUBE, true); - } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Plane.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Plane.java new file mode 100644 index 0000000000..28446c3e96 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Plane.java @@ -0,0 +1,68 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.renderables; + +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_PLANE_COLOR; +import com.willwinder.ugs.nbm.visualizer.shared.VertexObjectRenderable; +import com.willwinder.universalgcodesender.model.Position; + +public class Plane extends VertexObjectRenderable { + + private float[] gridPlaneColor; + + public Plane(String title) { + super(7, title, VisualizerOptions.VISUALIZER_OPTION_PLANE); + } + + @Override + public void reloadPreferences(VisualizerOptions vo) { + super.reloadPreferences(vo); + gridPlaneColor = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_PLANE_COLOR).value); + } + + @Override + public void render(GL2 gl) { + gl.glDisable(GL.GL_DEPTH_TEST); + gl.glDrawArrays(GL.GL_TRIANGLES, 0, getVertexCount()); + } + + @Override + public void reloadModel(GL2 gl, Position bottomLeft, Position topRight, double scaleFactor) { + addVertex(bottomLeft.x, bottomLeft.y, -0.01); + addColor(gridPlaneColor); + + addVertex(bottomLeft.x, topRight.y, -0.01); + addColor(gridPlaneColor); + + addVertex(topRight.x, topRight.y, -0.01); + addColor(gridPlaneColor); + + addVertex(topRight.x, topRight.y, -0.01); + addColor(gridPlaneColor); + + addVertex(topRight.x, bottomLeft.y, -0.01); + addColor(gridPlaneColor); + + addVertex(bottomLeft.x, bottomLeft.y, -0.01); + addColor(gridPlaneColor); + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Selection.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Selection.java index 28b4d2c4b2..f0dd9768a1 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Selection.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Selection.java @@ -21,7 +21,6 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.nbm.visualizer.shared.Renderable; import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; -import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; import com.willwinder.universalgcodesender.model.Position; import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_SELECTION; @@ -35,7 +34,7 @@ public class Selection extends Renderable { private Position end = null; public Selection(String title) { - super(8, title); + super(8, title, VISUALIZER_OPTION_SELECTION); } public void clear() { @@ -65,10 +64,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 (start == null || end == null) return; @@ -85,14 +80,4 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P gl.glVertex3d(end.x , start.y, 0); gl.glEnd(); } - - @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_SELECTION, enabled); - } - - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_SELECTION, true); - } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/SizeDisplay.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/SizeDisplay.java index bfb05536fa..c892c5437a 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/SizeDisplay.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/SizeDisplay.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2022 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -22,26 +22,31 @@ This file is part of Universal Gcode Sender (UGS). import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.util.awt.TextRenderer; import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_SIZE; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_SIZE_DISPLAY; import com.willwinder.ugs.nbm.visualizer.shared.Renderable; +import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; +import com.willwinder.universalgcodesender.listeners.UGSEventListener; +import com.willwinder.universalgcodesender.model.BackendAPI; import com.willwinder.universalgcodesender.model.Position; +import com.willwinder.universalgcodesender.model.UGSEvent; import com.willwinder.universalgcodesender.model.UnitUtils.Units; +import com.willwinder.universalgcodesender.model.events.SettingChangedEvent; import com.willwinder.universalgcodesender.visualizer.VisualizerUtils; import java.awt.Font; import java.awt.geom.Rectangle2D; import java.text.DecimalFormat; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_SIZE; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_SIZE_DISPLAY; - /** * Display some lines and measurements for the current objects size. * * @author wwinder */ -public class SizeDisplay extends Renderable { +public class SizeDisplay extends Renderable implements UGSEventListener { private static final DecimalFormat FORMATTER = new DecimalFormat("#.##"); + private final BackendAPI backend; private Units units = Units.MM; private TextRenderer renderer; @@ -49,16 +54,29 @@ public class SizeDisplay extends Renderable { private boolean textRendererDirty = true; public SizeDisplay(String title) { - super(3, title); + super(3, title, VISUALIZER_OPTION_SIZE_DISPLAY); reloadPreferences(new VisualizerOptions()); + backend = CentralLookup.getDefault().lookup(BackendAPI.class); + units = backend.getSettings().getPreferredUnits(); + backend.addUGSEventListener(this); + } + + private static String getTextForMM(double mm, Units goal) { + Position p = new Position(mm, 0, 0, Units.MM); + double converted = p.getPositionIn(goal).x; + return FORMATTER.format(converted) + " " + goal.abbreviation; } - public void setUnits(Units units) { - this.units = units; + protected void setUnits(Units units) { + if (units != this.units) { + this.units = units; + textRendererDirty = true; + } } @Override - final public void reloadPreferences(VisualizerOptions vo) { + public final void reloadPreferences(VisualizerOptions vo) { + super.reloadPreferences(vo); color = VisualizerOptions.colorToFloatArray(vo.getOptionForKey(VISUALIZER_OPTION_SIZE).value); textRendererDirty = true; } @@ -80,12 +98,6 @@ public void init(GLAutoDrawable drawable) { textRendererDirty = false; } - private static String getTextForMM(double mm, Units goal) { - Position p = new Position(mm, 0, 0, Units.MM); - double converted = p.getPositionIn(goal).x; - return FORMATTER.format(converted) + " " + goal.abbreviation; - } - @Override public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, Position workCoord, Position focusMin, Position focusMax, double scaleFactor, Position mouseCoordinates, Position rotation) { if (idle) return; @@ -94,127 +106,120 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P double maxSide = VisualizerUtils.findMaxSide(focusMin, focusMax); double buffer = maxSide * 0.03; - double offset = buffer*2; + double offset = buffer * 2; GL2 gl = drawable.getGL().getGL2(); // X gl.glPushMatrix(); - gl.glTranslated(0, -offset, 0); - gl.glColor4fv(color, 0); - gl.glLineWidth(2f); - gl.glBegin(GL2.GL_LINES); - gl.glVertex3d(focusMin.x, focusMin.y, 0); - gl.glVertex3d(focusMin.x, focusMin.y-offset, 0); - gl.glVertex3d(focusMin.x, focusMin.y-buffer, 0); - gl.glVertex3d(focusMax.x, focusMin.y-buffer, 0); - gl.glVertex3d(focusMax.x, focusMin.y-offset, 0); - gl.glVertex3d(focusMax.x, focusMin.y, 0); - gl.glEnd(); - - { + gl.glTranslated(0, -offset, 0); + gl.glColor4fv(color, 0); + gl.glLineWidth(2f); + gl.glBegin(GL2.GL_LINES); + gl.glVertex3d(focusMin.x, focusMin.y, 0); + gl.glVertex3d(focusMin.x, focusMin.y - offset, 0); + gl.glVertex3d(focusMin.x, focusMin.y - buffer, 0); + gl.glVertex3d(focusMax.x, focusMin.y - buffer, 0); + gl.glVertex3d(focusMax.x, focusMin.y - offset, 0); + gl.glVertex3d(focusMax.x, focusMin.y, 0); + gl.glEnd(); + + { renderer.begin3DRendering(); - double xSize = focusMax.x-focusMin.x; + double xSize = focusMax.x - focusMin.x; String text = this.getTextForMM(xSize, units); Rectangle2D bounds = renderer.getBounds(text); float w = (float) bounds.getWidth(); float h = (float) bounds.getHeight(); - float textScaleFactor = (float)(buffer/h); + float textScaleFactor = (float) (buffer / h); // Center text and move to line. - gl.glTranslated((focusMin.x+focusMax.x)/2-(w*textScaleFactor/2), - focusMin.y-offset, 0); - //gl.glRotated(-rotation.y, 1.0, 0.0, 0.0); - //gl.glRotated(-rotation.x, 0.0, 1.0, 0.0); + gl.glTranslated((focusMin.x + focusMax.x) / 2 - (w * textScaleFactor / 2), + focusMin.y - offset, 0); renderer.draw3D(text, 0f, 0f, 0f, textScaleFactor); renderer.end3DRendering(); - } + } gl.glPopMatrix(); // Y gl.glPushMatrix(); - gl.glTranslated(-offset, 0, 0); - gl.glColor4fv(color, 0); - gl.glLineWidth(2f); - gl.glBegin(GL2.GL_LINES); - gl.glVertex3d(focusMin.x , focusMin.y, 0); - gl.glVertex3d(focusMin.x-offset, focusMin.y, 0); - gl.glVertex3d(focusMin.x-buffer, focusMin.y, 0); - gl.glVertex3d(focusMin.x-buffer, focusMax.y, 0); - gl.glVertex3d(focusMin.x-offset, focusMax.y, 0); - gl.glVertex3d(focusMin.x , focusMax.y, 0); - gl.glEnd(); - - { + gl.glTranslated(-offset, 0, 0); + gl.glColor4fv(color, 0); + gl.glLineWidth(2f); + gl.glBegin(GL2.GL_LINES); + gl.glVertex3d(focusMin.x, focusMin.y, 0); + gl.glVertex3d(focusMin.x - offset, focusMin.y, 0); + gl.glVertex3d(focusMin.x - buffer, focusMin.y, 0); + gl.glVertex3d(focusMin.x - buffer, focusMax.y, 0); + gl.glVertex3d(focusMin.x - offset, focusMax.y, 0); + gl.glVertex3d(focusMin.x, focusMax.y, 0); + gl.glEnd(); + + { renderer.begin3DRendering(); - double ySize = focusMax.y-focusMin.y; + double ySize = focusMax.y - focusMin.y; String text = this.getTextForMM(ySize, units); Rectangle2D bounds = renderer.getBounds(text); float w = (float) bounds.getWidth(); float h = (float) bounds.getHeight(); - float textScaleFactor = (float)(buffer/h); + float textScaleFactor = (float) (buffer / h); // Center text and move to line. - gl.glRotated(90,0,0,1); - gl.glTranslated((focusMin.y+focusMax.y)/2-(w*textScaleFactor/2), - -focusMin.x+buffer*1.1, 0); - //gl.glRotated(rotation.y, 0.0, 1.0, 0.0); - //gl.glRotated(-rotation.x, 1.0, 0.0, 0.0); + gl.glRotated(90, 0, 0, 1); + gl.glTranslated((focusMin.y + focusMax.y) / 2 - (w * textScaleFactor / 2), + -focusMin.x + buffer * 1.1, 0); renderer.draw3D(text, 0f, 0f, 0f, textScaleFactor); renderer.end3DRendering(); - } + } gl.glPopMatrix(); // Z gl.glPushMatrix(); - gl.glTranslated(offset, 0, 0); - gl.glColor4fv(color, 0); - gl.glLineWidth(2f); - gl.glBegin(GL2.GL_LINES); - gl.glVertex3d(focusMax.x , focusMin.y, focusMin.z); - gl.glVertex3d(focusMax.x+offset, focusMin.y, focusMin.z); - gl.glVertex3d(focusMax.x+buffer, focusMin.y, focusMin.z); - gl.glVertex3d(focusMax.x+buffer, focusMin.y, focusMax.z); - gl.glVertex3d(focusMax.x+offset, focusMin.y, focusMax.z); - gl.glVertex3d(focusMax.x , focusMin.y, focusMax.z); - gl.glEnd(); - - { + gl.glTranslated(offset, 0, 0); + gl.glColor4fv(color, 0); + gl.glLineWidth(2f); + gl.glBegin(GL2.GL_LINES); + gl.glVertex3d(focusMax.x, focusMin.y, focusMin.z); + gl.glVertex3d(focusMax.x + offset, focusMin.y, focusMin.z); + gl.glVertex3d(focusMax.x + buffer, focusMin.y, focusMin.z); + gl.glVertex3d(focusMax.x + buffer, focusMin.y, focusMax.z); + gl.glVertex3d(focusMax.x + offset, focusMin.y, focusMax.z); + gl.glVertex3d(focusMax.x, focusMin.y, focusMax.z); + gl.glEnd(); + + { renderer.begin3DRendering(); - double zSize = focusMax.z-focusMin.z; + double zSize = focusMax.z - focusMin.z; String text = this.getTextForMM(zSize, units); Rectangle2D bounds = renderer.getBounds(text); float w = (float) bounds.getWidth(); float h = (float) bounds.getHeight(); - float textScaleFactor = (float)(buffer/h); + float textScaleFactor = (float) (buffer / h); // Center text and move to line. - gl.glRotated(90,1,0,0); - gl.glTranslated(focusMax.x + buffer*1.1, - (focusMin.z+focusMax.z)/2-(h*textScaleFactor/2), + gl.glRotated(90, 1, 0, 0); + gl.glTranslated(focusMax.x + buffer * 1.1, + (focusMin.z + focusMax.z) / 2 - (h * textScaleFactor / 2), //focusMin.y-offset, -focusMin.y); - gl.glRotated(-rotation.y-90, 1.0, 0.0, 0.0); + gl.glRotated(-rotation.y - 90, 1.0, 0.0, 0.0); gl.glRotated(-rotation.x, 0.0, 1.0, 0.0); renderer.draw3D(text, 0f, 0f, 0f, textScaleFactor); renderer.end3DRendering(); - } + } gl.glPopMatrix(); } @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_SIZE_DISPLAY, enabled); - } - - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_SIZE_DISPLAY, true); + public void UGSEvent(UGSEvent evt) { + if (evt instanceof SettingChangedEvent) { + setUnits(backend.getSettings().getPreferredUnits()); + } } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Tool.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Tool.java index cc6e7836fa..740f0da798 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Tool.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/renderables/Tool.java @@ -1,5 +1,5 @@ /* - Copyright 2016-2022 Will Winder + Copyright 2016-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -18,20 +18,20 @@ This file is part of Universal Gcode Sender (UGS). */ package com.willwinder.ugs.nbm.visualizer.renderables; +import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2; import com.jogamp.opengl.GLAutoDrawable; 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_TOOL; +import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_TOOL_COLOR; import com.willwinder.ugs.nbm.visualizer.shared.Renderable; import com.willwinder.universalgcodesender.model.Position; import com.willwinder.universalgcodesender.visualizer.VisualizerUtils; import java.awt.Color; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_TOOL; -import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_TOOL_COLOR; - /** * * @author wwinder @@ -42,12 +42,13 @@ public final class Tool extends Renderable { Color toolColor; public Tool(String title) { - super(9, title); + super(4, title, VISUALIZER_OPTION_TOOL); reloadPreferences(new VisualizerOptions()); } @Override public void reloadPreferences(VisualizerOptions vo) { + super.reloadPreferences(vo); toolColor = vo.getOptionForKey(VISUALIZER_OPTION_TOOL_COLOR).value; } @@ -75,6 +76,8 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P double scale = 1. / scaleFactor; gl.glPushMatrix(); + gl.glEnable(GL.GL_DEPTH_TEST); + gl.glTranslated(position.x, position.y, position.z); gl.glScaled(scale, scale, scale); @@ -95,14 +98,4 @@ public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, P glu.gluCylinder(gq, 0.03f, .0f, .01, 16, 1); gl.glPopMatrix(); } - - @Override - public void setEnabled(boolean enabled) { - VisualizerOptions.setBooleanOption(VISUALIZER_OPTION_TOOL, enabled); - } - - @Override - public boolean isEnabled() { - return VisualizerOptions.getBooleanOption(VISUALIZER_OPTION_TOOL, true); - } } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shader/PlainShader.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shader/PlainShader.java new file mode 100644 index 0000000000..446296def0 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shader/PlainShader.java @@ -0,0 +1,79 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.shader; + +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GLException; +import com.willwinder.ugs.nbm.visualizer.utils.ShaderLoader; +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +/** + * A simple shader program that will render each vertex with the given color + * + * @author Joacim Breiler + */ +public class PlainShader implements Shader { + private int shaderProgramId; + private int shaderVertexIndex; + private int shaderColorIndex; + + public void init(GL2 gl) { + try { + InputStream vertexShaderInputStream = getClass().getResourceAsStream("/shaders/plain.vert.glsl"); + if (vertexShaderInputStream == null) { + throw new IOException("Could not find vertex shader file"); + } + + InputStream fragmentShaderInputStream = getClass().getResourceAsStream("/shaders/plain.frag.glsl"); + if (fragmentShaderInputStream == null) { + throw new IOException("Could not find fragment shader file"); + } + + shaderProgramId = ShaderLoader.loadProgram(gl, IOUtils.toString(vertexShaderInputStream, StandardCharsets.UTF_8), IOUtils.toString(fragmentShaderInputStream, StandardCharsets.UTF_8)); + shaderVertexIndex = gl.glGetAttribLocation(shaderProgramId, "inPosition"); + shaderColorIndex = gl.glGetAttribLocation(shaderProgramId, "inColor"); + } catch (IOException e) { + throw new GLException(e); + } + } + + public int getShaderVertexIndex() { + return shaderVertexIndex; + } + + public int getShaderColorIndex() { + return shaderColorIndex; + } + + public void dispose(GL2 gl) { + if (shaderProgramId <= 0) { + return; + } + + gl.glDeleteShader(shaderProgramId); + } + + public int getProgramId() { + return shaderProgramId; + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shader/Shader.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shader/Shader.java new file mode 100644 index 0000000000..2b2c5af795 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shader/Shader.java @@ -0,0 +1,48 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.shader; + +import com.jogamp.opengl.GL2; + +/** + * An interface for describing a shader program + * + * @author Joacim Breiler + */ +public interface Shader { + /** + * Initializes the shader program + * + * @param gl the current OpenGL context + */ + void init(GL2 gl); + + /** + * Disposes the shader program + * + * @param gl the current OpenGL context + */ + void dispose(GL2 gl); + + /** + * Returns the ID of the loaded shader program to be referenced in OpenGL + * @return the id of the shader program + */ + int getProgramId(); +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java index 52e52d32ad..13cd04b6ac 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/GcodeRenderer.java @@ -1,5 +1,5 @@ /* - Copyright 2013-2022 Will Winder + Copyright 2013-2024 Will Winder This file is part of Universal Gcode Sender (UGS). @@ -32,6 +32,7 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.nbm.visualizer.renderables.MachineBoundries; import com.willwinder.ugs.nbm.visualizer.renderables.MouseOver; import com.willwinder.ugs.nbm.visualizer.renderables.OrientationCube; +import com.willwinder.ugs.nbm.visualizer.renderables.Plane; import com.willwinder.ugs.nbm.visualizer.renderables.Tool; import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; import com.willwinder.universalgcodesender.i18n.Localization; @@ -60,7 +61,6 @@ This file is part of Universal Gcode Sender (UGS). * * @author wwinder */ -@SuppressWarnings("serial") @ServiceProviders(value = { @ServiceProvider(service = IRenderableRegistrationService.class), @ServiceProvider(service = GcodeRenderer.class)}) @@ -471,6 +471,7 @@ private void initRenderables() { objects.add(new MouseOver(Localization.getString("platform.visualizer.renderable.mouse-indicator"))); objects.add(new OrientationCube(0.5f, Localization.getString("platform.visualizer.renderable.orientation-cube"))); objects.add(new Grid(Localization.getString("platform.visualizer.renderable.grid"))); + objects.add(new Plane(Localization.getString("platform.visualizer.renderable.grid"))); Collections.sort(objects); } diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/Renderable.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/Renderable.java index 395cadd75a..c327e4b4dc 100644 --- a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/Renderable.java +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/Renderable.java @@ -22,7 +22,8 @@ This file is part of Universal Gcode Sender (UGS). import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; import com.willwinder.universalgcodesender.model.Position; -import java.util.*; +import java.util.Objects; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** @@ -31,19 +32,21 @@ This file is part of Universal Gcode Sender (UGS). */ public abstract class Renderable implements Comparable { Integer priority; - Boolean enabled; String title; + boolean isEnabled; private final Set listeners = ConcurrentHashMap.newKeySet(); + private final String enabledOptionKey; /** * Construct with a priority number. Objects should be rendered from highest * to lowest priority; */ - public Renderable(int priority, String title) { + protected Renderable(int priority, String title, String enabledOptionKey) { this.title = title; this.priority = priority; - this.enabled = true; + this.isEnabled = true; + this.enabledOptionKey = enabledOptionKey; } @Override @@ -53,7 +56,7 @@ public boolean equals(Object obj) { Renderable that = (Renderable)obj; return Objects.equals(this.title, that.title) && - Objects.equals(this.enabled, that.enabled) && + Objects.equals(this.isEnabled, that.isEnabled) && Objects.equals(this.priority, that.priority); } @@ -72,14 +75,18 @@ public int compareTo(Renderable o) { * * @param enabled set to true for enabling it in the configuration */ - public abstract void setEnabled(boolean enabled); + public void setEnabled(boolean enabled) { + VisualizerOptions.setBooleanOption(enabledOptionKey, enabled); + } /** * Returns true if the setting for the renderable is enabled * * @return true if enabled in the configuration */ - public abstract boolean isEnabled(); + public boolean isEnabled() { + return isEnabled; + } public String getTitle() { return this.title; @@ -95,16 +102,19 @@ public boolean enableLighting() { /** * Indicates whether the object should be rotated prior to calling draw. */ - abstract public boolean rotate(); + public abstract boolean rotate(); /** * Indicates whether the object should be centered prior to calling draw. */ - abstract public boolean center(); + public abstract boolean center(); + + public abstract void init(GLAutoDrawable drawable); + public void reloadPreferences(VisualizerOptions vo) { + isEnabled = VisualizerOptions.getBooleanOption(enabledOptionKey, true); + } - abstract public void init(GLAutoDrawable drawable); - abstract public void reloadPreferences(VisualizerOptions vo); - abstract public void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, Position workCoord, Position objectMin, Position objectMax, double scaleFactor, Position mouseWorldCoordinates, Position rotation); + public abstract void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, Position workCoord, Position objectMin, Position objectMax, double scaleFactor, Position mouseWorldCoordinates, Position rotation); public void addListener(RenderableListener listener) { listeners.add(listener); diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/VertexObjectRenderable.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/VertexObjectRenderable.java new file mode 100644 index 0000000000..3d3f34166c --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/shared/VertexObjectRenderable.java @@ -0,0 +1,153 @@ +package com.willwinder.ugs.nbm.visualizer.shared; + +import com.jogamp.opengl.GL2; +import com.jogamp.opengl.GLAutoDrawable; +import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions; +import com.willwinder.ugs.nbm.visualizer.shader.PlainShader; +import com.willwinder.ugs.nbm.visualizer.utils.RenderableUtils; +import static com.willwinder.ugs.nbm.visualizer.utils.RenderableUtils.bindColorBuffer; +import static com.willwinder.ugs.nbm.visualizer.utils.RenderableUtils.bindVertexBuffer; +import static com.willwinder.ugs.nbm.visualizer.utils.RenderableUtils.bindVertexObject; +import com.willwinder.universalgcodesender.model.Position; + +import java.util.ArrayList; +import java.util.List; + +/** + * A base class for rendering a vertex buffer object using a shader + */ +public abstract class VertexObjectRenderable extends Renderable { + private double stepSize; + private final List vertexList = new ArrayList<>(); + private final List colorList = new ArrayList<>(); + + private Position objectMin = Position.ZERO; + private Position objectMax = Position.ZERO; + private PlainShader shader; + + private boolean reloadModel; + private int vertexObjectId; + private int vertexBufferId; + private int colorBufferId; + + + protected double getStepSize() { + return stepSize; + } + + protected VertexObjectRenderable(int priority, String title, String enabledOptionKey) { + super(priority, title, enabledOptionKey); + reloadPreferences(new VisualizerOptions()); + } + + private void clear() { + vertexList.clear(); + colorList.clear(); + } + + @Override + public boolean rotate() { + return true; + } + + @Override + public boolean center() { + return true; + } + + protected void addVertex(double x, double y, double z) { + RenderableUtils.addVertex(vertexList, x, y, z); + } + + protected void addColor(float[] color) { + RenderableUtils.addColor(colorList, color); + } + + protected int getVertexCount() { + return vertexList.size(); + } + + @Override + public void reloadPreferences(VisualizerOptions vo) { + super.reloadPreferences(vo); + + // Need to reload model the next time to load new colors and settings + reloadModel = true; + } + + @Override + public void init(GLAutoDrawable drawable) { + shader = new PlainShader(); + shader.init(drawable.getGL().getGL2()); + } + + private double padMinMaxPoint(double stepSize, double point, boolean negativeDirection) { + if (stepSize < 0.01) return negativeDirection ? -1 : 1; + + int step = negativeDirection ? -1 : 1; + long numberOfFullSteps = Math.round(point / stepSize); + return (numberOfFullSteps + step) * stepSize; + } + + @Override + public final void draw(GLAutoDrawable drawable, boolean idle, Position machineCoord, Position workCoord, Position objectMin, Position objectMax, double scaleFactor, Position mouseWorldCoordinates, Position rotation) { + GL2 gl = (GL2) drawable.getGL(); + + double newStepSize = RenderableUtils.getStepSize(scaleFactor); + if (!this.objectMin.equals(objectMin) || !this.objectMax.equals(objectMax) || reloadModel || this.stepSize != newStepSize) { + this.objectMin = new Position(objectMin); + this.objectMax = new Position(objectMax); + this.reloadModel = false; + this.stepSize = newStepSize; + + Position bottomLeft = new Position(objectMin); + Position topRight = new Position(objectMax); + + bottomLeft.x = padMinMaxPoint(newStepSize, bottomLeft.x, true); + bottomLeft.y = padMinMaxPoint(newStepSize, bottomLeft.y, true); + topRight.x = padMinMaxPoint(newStepSize, topRight.x, false); + topRight.y = padMinMaxPoint(newStepSize, topRight.y, false); + clear(); + reloadModel(gl, bottomLeft, topRight, scaleFactor); + updateBuffers(gl); + } + + // Use the shader program + gl.glUseProgram(shader.getProgramId()); + + // Bind the VAO containing the vertex data + gl.glBindVertexArray(vertexObjectId); + + render(gl); + + // Unbind the VAO + gl.glBindVertexArray(0); + gl.glUseProgram(0); + } + + + private void updateBuffers(GL2 gl) { + gl.glDeleteBuffers(2, new int[]{vertexBufferId, colorBufferId}, 0); + vertexObjectId = bindVertexObject(gl); + vertexBufferId = bindVertexBuffer(gl, vertexList, shader.getShaderVertexIndex()); + colorBufferId = bindColorBuffer(gl, colorList, shader.getShaderColorIndex()); + } + + /** + * A method to be used for rendering the vertex buffer. + * + * @param gl the current gl context + */ + public abstract void render(GL2 gl); + + + /** + * Reload the model + * + * @param gl the current gl context + * @param bottomLeft the loaded model bottom right corner + * @param topRight the loaded model top right corner + * @param scaleFactor the scale factor being used + */ + public abstract void reloadModel(GL2 gl, Position bottomLeft, Position topRight, double scaleFactor); +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/utils/RenderableUtils.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/utils/RenderableUtils.java new file mode 100644 index 0000000000..ab86d52a19 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/utils/RenderableUtils.java @@ -0,0 +1,111 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.utils; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.GL; +import com.jogamp.opengl.GL2; +import org.apache.commons.lang3.ArrayUtils; + +import java.nio.FloatBuffer; +import java.util.List; + +public class RenderableUtils { + /** + * Generates and binds a color buffer + * + * @param gl the GL context to use + * @param colorList a list of float values containing the color RGBA values + * @param vertexBufferIndex the parameter index of the shader to bind to + * @return the id of the color buffer to be reference to when rendering + */ + public static int bindColorBuffer(GL2 gl, List colorList, int vertexBufferIndex) { + // Create and upload the Color Buffer Object (CBO) for colors + int[] cbo = new int[1]; + gl.glGenBuffers(1, cbo, 0); + + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, cbo[0]); + + // Upload vertex colors to the GPU + FloatBuffer colorBuffer = Buffers.newDirectFloatBuffer(ArrayUtils.toPrimitive(colorList.toArray(new Float[0]))); + gl.glBufferData(GL.GL_ARRAY_BUFFER, colorBuffer.capacity() * Float.BYTES, colorBuffer, GL.GL_STATIC_DRAW); + + // Specify vertex attribute layout (index 1 for color) + gl.glEnableVertexAttribArray(vertexBufferIndex); + gl.glVertexAttribPointer(vertexBufferIndex, 4, GL.GL_FLOAT, false, 4 * Float.BYTES, 0); + + return cbo[0]; + } + + public static int bindVertexBuffer(GL2 gl, List vertexList, int positionIndex) { + // Create a Vertex Buffer Object (VBO) + int[] vbo = new int[1]; + gl.glGenBuffers(1, vbo, 0); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[0]); + + // Send vertex data to the GPU + FloatBuffer vertexBuffer = Buffers.newDirectFloatBuffer(ArrayUtils.toPrimitive(vertexList.toArray(new Float[0]))); + gl.glBufferData(GL.GL_ARRAY_BUFFER, vertexBuffer.limit() * Float.BYTES, vertexBuffer, GL.GL_STATIC_DRAW); + + // Specify the layout of the vertex data + gl.glEnableVertexAttribArray(positionIndex); + gl.glVertexAttribPointer(positionIndex, 3, GL.GL_FLOAT, false, 3 * Float.BYTES, 0); + + return vbo[0]; + } + + public static int bindVertexObject(GL2 gl) { + int[] vao = new int[1]; + gl.glGenVertexArrays(1, vao, 0); + gl.glBindVertexArray(vao[0]); + return vao[0]; + } + + public static void addColor(List colorList, float[] color) { + colorList.add(color[0]); + colorList.add(color[1]); + colorList.add(color[2]); + + if (color.length > 3) { + colorList.add(color[3]); + } else { + colorList.add(1f); + } + } + + public static void addVertex(List vertexList, double x, double y, double z) { + vertexList.add((float) x); + vertexList.add((float) y); + vertexList.add((float) z); + } + + + public static double getStepSize(double scaleFactor) { + if (scaleFactor < 0.001) { + return 50; + } else if (scaleFactor < 0.01) { + return 10; + } else if (scaleFactor < 0.04) { + return 5; + } else if (scaleFactor < 0.1) { + return 1; + } + return 0.5; + } +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/utils/ShaderLoader.java b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/utils/ShaderLoader.java new file mode 100644 index 0000000000..474066e2b7 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/java/com/willwinder/ugs/nbm/visualizer/utils/ShaderLoader.java @@ -0,0 +1,141 @@ +/* + Copyright 2024 Will Winder + + This file is part of Universal Gcode Sender (UGS). + + UGS is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UGS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UGS. If not, see . + */ +package com.willwinder.ugs.nbm.visualizer.utils; + +import com.jogamp.opengl.GL2ES2; +import com.jogamp.opengl.GLException; +import com.jogamp.opengl.util.glsl.ShaderUtil; + +/** + * Utility to load shaders from files, URLs, and strings. + * + *

+ * {@code ShaderLoader} is a simple utility for loading shaders. It takes shaders directly as + * strings. It will create and compile the shaders, and link them together into a program. Both + * compiling and linking are verified. If a problem occurs a {@link GLException} is thrown with + * the appropriate log attached. + * + *

+ * Note it is highly recommended that if the developer passes the strings directly to {@code + * ShaderLoader} that they contain newlines. That way if any errors do occur their line numbers + * will be reported correctly. This means that if the shader is to be embedded in Java code, a + * "\n" should be appended to every line. + */ +public final class ShaderLoader { + + /** + * Prevents instantiation. + */ + private ShaderLoader() { + // empty + } + + /** + * Checks that a shader was compiled correctly. + * + * @param gl OpenGL context, assumed not null + * @param shader OpenGL handle to a shader + * @return true if shader was compiled without errors + */ + public static boolean isShaderCompiled(final GL2ES2 gl, final int shader) { + return ShaderUtil.isShaderStatusValid(gl, shader, GL2ES2.GL_COMPILE_STATUS, null); + } + + /** + * Checks that a shader program was linked successfully. + * + * @param gl OpenGL context, assumed not null + * @param program OpenGL handle to a shader program + * @return true if program was linked successfully + */ + public static boolean isProgramLinked(final GL2ES2 gl, final int program) { + return ShaderUtil.isProgramStatusValid(gl, program, GL2ES2.GL_LINK_STATUS); + } + + /** + * Checks that a shader program was validated successfully. + * + * @param gl OpenGL context, assumed not null + * @param program OpenGL handle to a shader program + * @return true if program was validated successfully + */ + public static boolean isProgramValidated(final GL2ES2 gl, final int program) { + return ShaderUtil.isProgramStatusValid(gl, program, GL2ES2.GL_VALIDATE_STATUS); + } + + /** + * Loads a shader program from a pair of strings. + * + * @param gl Current OpenGL context + * @param vertexShaderSource Vertex shader source + * @param fragmentShaderSource Fragment shader source + * @return OpenGL handle to the shader program, not negative + * @throws NullPointerException if context or either source is null + * @throws IllegalArgumentException if either source is empty + * @throws GLException if program did not compile, link, or validate successfully + */ + /*@Nonnegative*/ + public static int loadProgram(final GL2ES2 gl, final String vertexShaderSource, final String fragmentShaderSource) { + // Create the shaders + final int vertexShaderId = loadShader(gl, vertexShaderSource, GL2ES2.GL_VERTEX_SHADER); + final int fragmentShaderId = loadShader(gl, fragmentShaderSource, GL2ES2.GL_FRAGMENT_SHADER); + + // Create a program and attach the shaders + final int program = gl.glCreateProgram(); + gl.glAttachShader(program, vertexShaderId); + gl.glAttachShader(program, fragmentShaderId); + + // Link the program + gl.glLinkProgram(program); + if (!isProgramLinked(gl, program)) { + final String log = ShaderUtil.getProgramInfoLog(gl, program); + throw new GLException(log); + } + + // Clean up the shaders + gl.glDeleteShader(vertexShaderId); + gl.glDeleteShader(fragmentShaderId); + return program; + } + + /** + * Loads a shader from a string. + * + * @param gl Current OpenGL context, assumed not null + * @param source Source code of the shader as one long string, assumed not null or empty + * @param type Type of shader, assumed valid + * @return OpenGL handle to the shader, not negative + * @throws GLException if a GLSL-capable context is not active or could not compile shader + */ + private static int loadShader(final GL2ES2 gl, final String source, final int type) { + final int shader = gl.glCreateShader(type); + gl.glShaderSource(shader, + 1, + new String[]{source}, + null); + + gl.glCompileShader(shader); + if (!isShaderCompiled(gl, shader)) { + final String log = ShaderUtil.getShaderInfoLog(gl, shader); + throw new GLException(log); + } + + return shader; + } +} \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary.svg new file mode 100644 index 0000000000..2ce3029513 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24.svg new file mode 100644 index 0000000000..63a0340846 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24_dark.svg new file mode 100644 index 0000000000..a301f85f31 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24_disabled_dark.svg new file mode 100644 index 0000000000..639b385c55 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary24_disabled_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary_dark.svg new file mode 100644 index 0000000000..6056107f47 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary_disabled_dark.svg new file mode 100644 index 0000000000..0dea4548c5 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/boundary_disabled_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube.svg new file mode 100644 index 0000000000..ef9da62adb --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24.svg new file mode 100644 index 0000000000..51c5a4db43 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24_dark.svg new file mode 100644 index 0000000000..5b863878d0 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24_dark.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24_disabled_dark.svg new file mode 100644 index 0000000000..970b1ba9e6 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube24_disabled_dark.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube_dark.svg new file mode 100644 index 0000000000..0be80f60bb --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube_dark.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube_disabled_dark.svg new file mode 100644 index 0000000000..a32204dc42 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/cube_disabled_dark.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid.svg new file mode 100644 index 0000000000..0fea76987e --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24.svg new file mode 100644 index 0000000000..520b7dd101 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24_dark.svg new file mode 100644 index 0000000000..5ce47c6086 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24_dark.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24_disabled_dark.svg new file mode 100644 index 0000000000..d1e35ce1ea --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid24_disabled_dark.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid_dark.svg new file mode 100644 index 0000000000..8e02505081 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid_dark.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid_disabled_dark.svg new file mode 100644 index 0000000000..e4e62f3eab --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/grid_disabled_dark.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model.svg new file mode 100644 index 0000000000..773fc8aecb --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model.svg @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24.svg new file mode 100644 index 0000000000..553568dcdc --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24.svg @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24_dark.svg new file mode 100644 index 0000000000..e4717168c0 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24_dark.svg @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24_disabled_dark.svg new file mode 100644 index 0000000000..2655da682d --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model24_disabled_dark.svg @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model_dark.svg new file mode 100644 index 0000000000..8ab228a137 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model_dark.svg @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model_disabled_dark.svg new file mode 100644 index 0000000000..8701638e60 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/model_disabled_dark.svg @@ -0,0 +1,51 @@ + + + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse.svg new file mode 100644 index 0000000000..c4fd0023b1 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24.svg new file mode 100644 index 0000000000..ff326b3448 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24_dark.svg new file mode 100644 index 0000000000..8a9cfb3692 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24_disabled_dark.svg new file mode 100644 index 0000000000..6348439df6 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse24_disabled_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse_dark.svg new file mode 100644 index 0000000000..b389d89d2d --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse_disabled_dark.svg new file mode 100644 index 0000000000..1ff34357eb --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/mouse_disabled_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane.svg new file mode 100644 index 0000000000..683fd28d05 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24.svg new file mode 100644 index 0000000000..fc6721da0b --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24_dark.svg new file mode 100644 index 0000000000..03535974a4 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24_disabled_dark.svg new file mode 100644 index 0000000000..2a3cd39fcc --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane24_disabled_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane_dark.svg new file mode 100644 index 0000000000..cd642093a9 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane_disabled_dark.svg new file mode 100644 index 0000000000..873559b220 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/plane_disabled_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select.svg new file mode 100644 index 0000000000..2e5845bff0 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24.svg new file mode 100644 index 0000000000..a7e0d56c31 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24_dark.svg new file mode 100644 index 0000000000..c6fb1f736a --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24_disabled_dark.svg new file mode 100644 index 0000000000..6cc866a234 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select24_disabled_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select_dark.svg new file mode 100644 index 0000000000..a126452623 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select_disabled_dark.svg new file mode 100644 index 0000000000..5249a64583 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/select_disabled_dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size.svg new file mode 100644 index 0000000000..1c410d3436 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24.svg new file mode 100644 index 0000000000..66bda3ec3d --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24_dark.svg new file mode 100644 index 0000000000..bef596a0c7 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24_dark.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24_disabled_dark.svg new file mode 100644 index 0000000000..9695ecd37f --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size24_disabled_dark.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size_dark.svg new file mode 100644 index 0000000000..406e9dcab3 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size_dark.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size_disabled_dark.svg new file mode 100644 index 0000000000..10a7f11a8d --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/size_disabled_dark.svg @@ -0,0 +1,40 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool.svg new file mode 100644 index 0000000000..6319daca7e --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24.svg new file mode 100644 index 0000000000..9fa876e52a --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24_dark.svg new file mode 100644 index 0000000000..704e21fa7a --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24_disabled_dark.svg new file mode 100644 index 0000000000..b0f87f7393 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool24_disabled_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool_dark.svg new file mode 100644 index 0000000000..94857628c6 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool_disabled_dark.svg b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool_disabled_dark.svg new file mode 100644 index 0000000000..a830ef9180 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/icons/tool_disabled_dark.svg @@ -0,0 +1,41 @@ + + + + + + diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/shaders/plain.frag.glsl b/ugs-platform/ugs-platform-visualizer/src/main/resources/shaders/plain.frag.glsl new file mode 100644 index 0000000000..4c777b3acc --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/shaders/plain.frag.glsl @@ -0,0 +1,9 @@ +#version 110 + +// Input color from the vertex shader +varying vec4 fragColor; + +void main() { + // Set the fragment color to the input color + gl_FragColor = fragColor; +} diff --git a/ugs-platform/ugs-platform-visualizer/src/main/resources/shaders/plain.vert.glsl b/ugs-platform/ugs-platform-visualizer/src/main/resources/shaders/plain.vert.glsl new file mode 100644 index 0000000000..3cf4459146 --- /dev/null +++ b/ugs-platform/ugs-platform-visualizer/src/main/resources/shaders/plain.vert.glsl @@ -0,0 +1,16 @@ +#version 110 + +// Input vertex position and color +attribute vec3 inPosition; +attribute vec4 inColor; + +// Output color to the fragment shader +varying vec4 fragColor; + +void main() { + // Set the vertex position + gl_Position = gl_ModelViewProjectionMatrix * vec4(inPosition, 1.0); + + // Pass the vertex color to the fragment shader + fragColor = inColor; +} \ No newline at end of file