Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Load the gcode model when opening the visualizer #2575

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,8 @@ public void keyPressed(KeyEvent ke) {
public void keyReleased(KeyEvent ke) {
setFPS(LOW_FPS);
}

public void dispose() {
gcodeRenderer.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected void componentClosed() {

if (rih != null) {
backend.removeUGSEventListener(rih);
rih.dispose();
}

logger.log(Level.INFO, "Component closed, panel = " + panel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ This file is part of Universal Gcode Sender (UGS).
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLEventListener;
import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW;
import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION;
import com.jogamp.opengl.glu.GLU;
import com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions;
import com.willwinder.ugs.nbm.visualizer.renderables.*;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BG;
import com.willwinder.ugs.nbm.visualizer.renderables.Grid;
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.Tool;
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup;
import com.willwinder.universalgcodesender.i18n.Localization;
import com.willwinder.universalgcodesender.model.BackendAPI;
Expand All @@ -39,18 +46,15 @@ This file is part of Universal Gcode Sender (UGS).
import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;

import java.awt.*;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.InputEvent;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_MODELVIEW;
import static com.jogamp.opengl.fixedfunc.GLMatrixFunc.GL_PROJECTION;
import static com.willwinder.ugs.nbm.visualizer.options.VisualizerOptions.VISUALIZER_OPTION_BG;

/**
* 3D Canvas for GCode Visualizer
*
Expand Down Expand Up @@ -134,12 +138,7 @@ public GcodeRenderer() {
setHorizontalTranslationVector();

objects = new CopyOnWriteArrayList<>();
objects.add(new MachineBoundries(Localization.getString("platform.visualizer.renderable.machine-boundries")));
objects.add(new Tool(Localization.getString("platform.visualizer.renderable.tool-location")));
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")));
Collections.sort(objects);
initRenderables();

reloadPreferences();
listenForSettingsEvents();
Expand Down Expand Up @@ -199,7 +198,7 @@ public void setMachineCoordinate(Position p) {
}
}

final public void reloadPreferences() {
public final void reloadPreferences() {
VisualizerOptions vo = new VisualizerOptions();

clearColor = vo.getOptionForKey(VISUALIZER_OPTION_BG).value;
Expand Down Expand Up @@ -476,7 +475,24 @@ private void update() {
*/
@Override
synchronized public void dispose(GLAutoDrawable drawable) {
dispose();
}

public void dispose() {
logger.log(Level.INFO, "Disposing OpenGL context.");
getRenderables()
.forEach(this::removeRenderable);
initRenderables();
}

private void initRenderables() {
objects.clear();
objects.add(new MachineBoundries(Localization.getString("platform.visualizer.renderable.machine-boundries")));
objects.add(new Tool(Localization.getString("platform.visualizer.renderable.tool-location")));
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")));
Collections.sort(objects);
}

private void setHorizontalTranslationVector() {
Expand Down
Loading