X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fviews%2FSimulationView.java;h=210e9de7783318a94fa596220b9acbd68b075025;hb=5799704ea3af4cce1cd89189c11f2727046009e8;hp=4d118a9f20d0815730c3286d07cd643465e77df3;hpb=9ab92f6f3ac3dacda4b9dcf2d80b08c263905682;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java index 4d118a9f..210e9de7 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java @@ -1,18 +1,18 @@ package net.mograsim.plugin.views; +import static net.mograsim.logic.model.preferences.RenderPreferences.DRAG_BUTTON; +import static net.mograsim.logic.model.preferences.RenderPreferences.ZOOM_BUTTON; +import static net.mograsim.plugin.preferences.PluginPreferences.SIMULATION_SPEED_PRECISION; + import java.util.HashSet; +import java.util.Optional; import java.util.Set; import java.util.function.Consumer; import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.debug.core.ILaunch; -import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.debug.ui.contexts.IDebugContextManager; import org.eclipse.debug.ui.contexts.IDebugContextService; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; @@ -30,15 +30,17 @@ import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInpu import net.mograsim.logic.core.LogicObserver; import net.mograsim.logic.core.components.CoreClock; import net.mograsim.logic.model.LogicUICanvas; +import net.mograsim.logic.model.preferences.RenderPreferences; import net.mograsim.machine.Machine; import net.mograsim.machine.Memory.MemoryCellModifiedListener; import net.mograsim.machine.mi.AssignableMicroInstructionMemory; +import net.mograsim.plugin.MograsimActivator; +import net.mograsim.plugin.launch.MachineDebugContextListener; import net.mograsim.plugin.launch.MachineDebugTarget; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.mi.ActiveInstructionPreviewContentProvider; import net.mograsim.plugin.tables.mi.InstructionTable; import net.mograsim.plugin.util.OverlappingFillLayout; -import net.mograsim.preferences.Preferences; public class SimulationView extends ViewPart { @@ -47,6 +49,7 @@ public class SimulationView extends ViewPart private static final double SIM_SPEED_SCALE_STEP_FACTOR_LOG = Math.log(SIM_SPEED_SCALE_STEP_FACTOR); private final Set controlsToDisableWhenNoMachinePresent; + private Button sbseButton; private Scale simSpeedScale; private DoubleInput simSpeedInput; private Composite contextDependentControlsParent; @@ -60,20 +63,27 @@ public class SimulationView extends ViewPart private final MemoryCellModifiedListener memCellListener; private final LogicObserver clockObserver; - private final IDebugContextListener debugContextListener; + private final MachineDebugContextListener debugContextListener; private final Consumer executionSpeedListener; public SimulationView() { controlsToDisableWhenNoMachinePresent = new HashSet<>(); memCellListener = a -> instPreview.refresh(); - // TODO could this be a breakpoint? + // TODO use Step Over instead clockObserver = o -> { if (((CoreClock) o).isOn()) SafeRunner.run(() -> debugTarget.suspend()); }; - debugContextListener = e -> debugContextChanged(e.getContext()); + debugContextListener = new MachineDebugContextListener() + { + @Override + public void machineDebugContextChanged(Optional oldTarget, Optional newTarget) + { + SimulationView.this.debugContextChanged(newTarget); + } + }; executionSpeedListener = this::speedFactorChanged; } @@ -107,7 +117,7 @@ public class SimulationView extends ViewPart IDebugContextManager debugCManager = DebugUITools.getDebugContextManager(); IDebugContextService contextService = debugCManager.getContextService(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); contextService.addDebugContextListener(debugContextListener); - debugContextChanged(contextService.getActiveContext()); + debugContextListener.debugContextChanged(contextService.getActiveContext()); } private void addSimulationControlWidgets(Composite parent) @@ -116,7 +126,7 @@ public class SimulationView extends ViewPart c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); c.setLayout(new GridLayout(7, false)); - Button sbseButton = new Button(c, SWT.CHECK); + sbseButton = new Button(c, SWT.CHECK); controlsToDisableWhenNoMachinePresent.add(sbseButton); sbseButton.setText("Step by step execution"); @@ -148,7 +158,8 @@ public class SimulationView extends ViewPart simSpeedInput = new DoubleInput(c, SWT.NONE); controlsToDisableWhenNoMachinePresent.add(simSpeedInput); - simSpeedInput.setPrecision(Preferences.current().getInt("net.mograsim.plugin.core.simspeedprecision")); + // TODO add a listener + simSpeedInput.setPrecision(MograsimActivator.instance().getPluginPrefs().getInt(SIMULATION_SPEED_PRECISION)); simSpeedInput.addChangeListener(speed -> { if (speed != 0) @@ -169,48 +180,22 @@ public class SimulationView extends ViewPart private void addInstructionPreviewControlWidgets(Composite parent) { - instPreview = new InstructionTable(parent, new DisplaySettings(), getSite().getWorkbenchWindow().getWorkbench().getThemeManager()); + instPreview = new InstructionTable(parent, new DisplaySettings(), getSite().getWorkbenchWindow().getWorkbench().getThemeManager(), + false); instPreview.getTableViewer().getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); contentProvider = new ActiveInstructionPreviewContentProvider(instPreview.getTableViewer()); instPreview.setContentProvider(contentProvider); } - private void debugContextChanged(ISelection selection) + private void debugContextChanged(Optional newTarget) { - if (selection != null && selection instanceof TreeSelection) - { - TreeSelection treeSelection = (TreeSelection) selection; - Object[] selectedElements = treeSelection.toArray(); - for (Object selectedElement : selectedElements) - { - MachineDebugTarget debugTarget; - if (selectedElement instanceof MachineDebugTarget) - debugTarget = (MachineDebugTarget) selectedElement; - else if (selectedElement instanceof ILaunch) - { - ILaunch launch = (ILaunch) selectedElement; - IDebugTarget genericDebugTarget = launch.getDebugTarget(); - if (genericDebugTarget instanceof MachineDebugTarget) - debugTarget = (MachineDebugTarget) genericDebugTarget; - else - continue; - } else - continue; - if (debugTarget.isTerminated()) - continue; - // we found a selected MachineDebugTarget - if (this.debugTarget != debugTarget) - bindToDebugTarget(debugTarget); - return; - } - } - // we didn't find a selected MachineDebugTarget - // call binToDebugTarget even if this.debugTarget==null - bindToDebugTarget(null); + // call binToDebugTarget even if we didn't find a selected MachineDebugTarget + bindToDebugTarget(newTarget.orElse(null)); } private void bindToDebugTarget(MachineDebugTarget debugTarget) { + deregisterMachineDependentListeners(); this.debugTarget = debugTarget; if (canvasParent == null) @@ -220,7 +205,6 @@ public class SimulationView extends ViewPart double offX; double offY; double zoom; - deregisterMachineDependentListeners(); if (canvas != null) { offX = canvas.getOffX(); @@ -242,11 +226,14 @@ public class SimulationView extends ViewPart Machine machine = debugTarget.getMachine(); - canvas = new LogicUICanvas(canvasParent, SWT.NONE, machine.getModel()); + RenderPreferences renderPrefs = MograsimActivator.instance().getRenderPrefs(); + canvas = new LogicUICanvas(canvasParent, SWT.NONE, machine.getModel(), renderPrefs); canvas.addListener(SWT.MouseDown, e -> canvas.setFocus()); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(canvas); - userInput.buttonDrag = Preferences.current().getInt("net.mograsim.logic.model.button.drag"); - userInput.buttonZoom = Preferences.current().getInt("net.mograsim.logic.model.button.zoom"); + // TODO add a listener + userInput.buttonDrag = renderPrefs.getInt(DRAG_BUTTON); + // TODO add a listener + userInput.buttonZoom = renderPrefs.getInt(ZOOM_BUTTON); userInput.enableUserInput(); if (zoom > 0) { @@ -282,6 +269,8 @@ public class SimulationView extends ViewPart debugTarget.removeExecutionSpeedListener(executionSpeedListener); debugTarget.getMachine().getMicroInstructionMemory().deregisterCellModifiedListener(memCellListener); debugTarget.getMachine().getClock().deregisterObserver(clockObserver); + if (sbseButton != null && !sbseButton.isDisposed()) + sbseButton.setSelection(false); } } @@ -296,6 +285,7 @@ public class SimulationView extends ViewPart public void dispose() { deregisterMachineDependentListeners(); + contentProvider.setMachine(null); DebugUITools.getDebugContextManager().removeDebugContextListener(debugContextListener); super.dispose(); }