X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Feditors%2FSimulationViewEditor.java;h=3ed2128104a28604947a372553541147b1fcdefa;hb=e2f36a0166c4843c4a5d79e23ee52cb0a6010896;hp=aece3ac43d82525d0d880474da68f09623821f33;hpb=8f54507e17429185b36515338b9ebc5c42e50d70;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java index aece3ac4..3ed21281 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/editors/SimulationViewEditor.java @@ -10,6 +10,7 @@ import org.eclipse.jface.util.SafeRunnable; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -29,8 +30,14 @@ import net.mograsim.logic.core.components.CoreClock; import net.mograsim.logic.model.LogicExecuter; import net.mograsim.logic.model.LogicUICanvas; import net.mograsim.machine.Machine; +import net.mograsim.machine.Memory.MemoryCellModifiedListener; +import net.mograsim.machine.mi.AssignableMicroInstructionMemory; import net.mograsim.plugin.nature.MachineContext; +import net.mograsim.plugin.nature.MachineContext.ActiveMachineListener; import net.mograsim.plugin.nature.ProjectMachineContext; +import net.mograsim.plugin.tables.DisplaySettings; +import net.mograsim.plugin.tables.mi.ActiveInstructionPreviewContentProvider; +import net.mograsim.plugin.tables.mi.InstructionTable; //TODO what if we open multiple editors? //TODO actually save / load register and latch states @@ -45,9 +52,35 @@ public class SimulationViewEditor extends EditorPart private Button sbseButton; private Button pauseButton; private Slider simSpeedSlider; + private Composite canvasParent; private LogicUICanvas canvas; + private InstructionTable instPreview; private Label noMachineLabel; + private ActiveMachineListener activeMNachineListener; + private MemoryCellModifiedListener memCellListener; + private LogicObserver clockObserver; + + public SimulationViewEditor() + { + activeMNachineListener = m -> recreateContextDependentControls(); + memCellListener = a -> instPreview.refresh(); + clockObserver = o -> + { + if (((CoreClock) o).isOn()) + { + exec.pauseLiveExecution(); + if (!pauseButton.isDisposed()) + Display.getDefault().asyncExec(() -> + { + if (!pauseButton.isDisposed()) + pauseButton.setSelection(false); + setPauseText(pauseButton, false); + }); + } + }; + } + @Override public void createPartControl(Composite parent) { @@ -58,6 +91,10 @@ public class SimulationViewEditor extends EditorPart noMachineLabel = new Label(parent, SWT.NONE); noMachineLabel.setText("No machine present...");// TODO internationalize? addSimulationControlWidgets(parent); + canvasParent = new Composite(parent, SWT.NONE); + canvasParent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + canvasParent.setLayout(new FillLayout()); + addInstructionPreviewControlWidgets(parent); recreateContextDependentControls(); } @@ -67,10 +104,22 @@ public class SimulationViewEditor extends EditorPart // createPartControls has not been called yet return; + double offX; + double offY; + double zoom; + stopExecAndDeregisterContextDependentListeners(); if (canvas != null) + { + offX = canvas.getOffX(); + offY = canvas.getOffY(); + zoom = canvas.getZoom(); canvas.dispose(); - if (exec != null) - exec.stopLiveExecution(); + } else + { + offX = 0; + offY = 0; + zoom = -1; + } Optional machineOptional; if (context != null && (machineOptional = context.getActiveMachine()).isPresent()) @@ -79,15 +128,24 @@ public class SimulationViewEditor extends EditorPart sbseButton.setEnabled(true); pauseButton.setEnabled(true); simSpeedSlider.setEnabled(true); + machine = machineOptional.get(); - canvas = new LogicUICanvas(parent, SWT.NONE, machine.getModel()); + canvas = new LogicUICanvas(canvasParent, SWT.NONE, machine.getModel()); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(canvas); userInput.buttonDrag = 3; userInput.buttonZoom = 2; userInput.enableUserInput(); + if (zoom > 0) + { + canvas.moveTo(offX, offY, zoom); + canvas.commitTransform(); + } + + AssignableMicroInstructionMemory mIMemory = machine.getMicroInstructionMemory(); + instPreview.bindMicroInstructionMemory(mIMemory); + mIMemory.registerCellModifiedListener(memCellListener); - GridData uiData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); - canvas.setLayoutData(uiData); + canvasParent.layout(); // initialize executer exec = new LogicExecuter(machine.getTimeline()); @@ -101,6 +159,17 @@ public class SimulationViewEditor extends EditorPart } } + private void stopExecAndDeregisterContextDependentListeners() + { + if (exec != null) + exec.stopLiveExecution(); + if (machine != null) + { + machine.getMicroInstructionMemory().deregisterCellModifiedListener(memCellListener); + machine.getClock().deregisterObserver(clockObserver); + } + } + private void addSimulationControlWidgets(Composite parent) { Composite c = new Composite(parent, SWT.NONE); @@ -108,20 +177,6 @@ public class SimulationViewEditor extends EditorPart sbseButton = new Button(c, SWT.CHECK); pauseButton = new Button(c, SWT.TOGGLE); - LogicObserver clockObserver = o -> - { - if (((CoreClock) o).isOn()) - { - exec.pauseLiveExecution(); - if (!pauseButton.isDisposed()) - Display.getDefault().asyncExec(() -> - { - if (!pauseButton.isDisposed()) - pauseButton.setSelection(false); - setPauseText(pauseButton, false); - }); - } - }; sbseButton.setText("Step by step execution"); sbseButton.addListener(SWT.Selection, e -> @@ -193,6 +248,13 @@ public class SimulationViewEditor extends EditorPart c.pack(); } + private void addInstructionPreviewControlWidgets(Composite parent) + { + instPreview = new InstructionTable(parent, new DisplaySettings()); + instPreview.getTableViewer().getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + instPreview.setContentProvider(new ActiveInstructionPreviewContentProvider(instPreview.getTableViewer())); + } + private static void setPauseText(Button pauseButton, boolean hovered) { if (hovered) @@ -213,6 +275,8 @@ public class SimulationViewEditor extends EditorPart { IFileEditorInput fileInput = (IFileEditorInput) input; context = ProjectMachineContext.getMachineContextOf(fileInput.getFile().getProject()); + context.activateMachine(); + context.addActiveMachineListener(activeMNachineListener); recreateContextDependentControls(); setPartName(fileInput.getName()); @@ -271,7 +335,8 @@ public class SimulationViewEditor extends EditorPart @Override public void dispose() { - exec.stopLiveExecution(); + stopExecAndDeregisterContextDependentListeners(); + context.removeActiveMachineListener(activeMNachineListener); super.dispose(); } } \ No newline at end of file