Skip to content

Commit

Permalink
Load the gcode model when opening the visualizer (#2575)
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler authored Jul 26, 2024
1 parent d7b0749 commit c0c906c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
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

0 comments on commit c0c906c

Please sign in to comment.