X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Feditors%2FSimulationViewEditor.java;h=0420334fa260442e66e943c032f0a91a9281d144;hb=c303ab90cb0fb61acde8a1e0ddc7a5ed8855ab82;hp=e6d05eac4ede839c74b2530cb068f645a6188d7d;hpb=ea2cf52020e48cbb854410c51d779456e6eca4ae;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 e6d05eac..0420334f 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,10 +10,12 @@ 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; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Slider; import org.eclipse.ui.IEditorInput; @@ -23,11 +25,18 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; +import net.mograsim.logic.core.LogicObserver; +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.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 @@ -36,11 +45,20 @@ public class SimulationViewEditor extends EditorPart private MachineContext context; private LogicExecuter exec; + private Machine machine; private Composite parent; + private Button sbseButton; + private Button pauseButton; + private Slider simSpeedSlider; + private Composite canvasParent; private LogicUICanvas canvas; + private InstructionTable instPreview; private Label noMachineLabel; + private MemoryCellModifiedListener currentRegisteredCellListener; + private LogicObserver currentClockObserver; + @Override public void createPartControl(Composite parent) { @@ -51,6 +69,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(); } @@ -60,38 +82,101 @@ public class SimulationViewEditor extends EditorPart // createPartControls has not been called yet return; - if (canvas != null) - canvas.dispose(); + double offX; + double offY; + double zoom; if (exec != null) exec.stopLiveExecution(); + if (machine != null) + { + machine.getMicroInstructionMemory().deregisterCellModifiedListener(currentRegisteredCellListener); + machine.getClock().deregisterObserver(currentClockObserver); + } + if (canvas != null) + { + offX = canvas.getOffX(); + offY = canvas.getOffY(); + zoom = canvas.getZoom(); + canvas.dispose(); + } else + { + offX = 0; + offY = 0; + zoom = -1; + } Optional machineOptional; if (context != null && (machineOptional = context.getActiveMachine()).isPresent()) { noMachineLabel.setVisible(false); - Machine machine = machineOptional.get(); - canvas = new LogicUICanvas(parent, SWT.NONE, machine.getModel()); + sbseButton.setEnabled(true); + pauseButton.setEnabled(true); + simSpeedSlider.setEnabled(true); + + machine = machineOptional.get(); + 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); + currentRegisteredCellListener = a -> instPreview.refresh(); + mIMemory.registerCellModifiedListener(currentRegisteredCellListener); - 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()); exec.startLiveExecution(); } else + { noMachineLabel.setVisible(true); + sbseButton.setEnabled(false); + pauseButton.setEnabled(false); + simSpeedSlider.setEnabled(false); + } } private void addSimulationControlWidgets(Composite parent) { Composite c = new Composite(parent, SWT.NONE); - c.setLayout(new GridLayout(6, false)); + c.setLayout(new GridLayout(7, false)); + + sbseButton = new Button(c, SWT.CHECK); + pauseButton = new Button(c, SWT.TOGGLE); + currentClockObserver = 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 -> + { + CoreClock cl = machine.getClock(); + if (sbseButton.getSelection()) + cl.registerObserver(currentClockObserver); + else + cl.deregisterObserver(currentClockObserver); + }); + sbseButton.setSelection(false); - Button pauseButton = new Button(c, SWT.TOGGLE); pauseButton.setSelection(true); setPauseText(pauseButton, false); @@ -130,26 +215,32 @@ public class SimulationViewEditor extends EditorPart Label speedLabel = new Label(c, SWT.NONE); speedLabel.setText("Simulation Speed: "); - Slider slider = new Slider(c, SWT.NONE); - slider.setMinimum(1); - slider.setMaximum(100 + slider.getThumb()); - slider.setIncrement(1); + simSpeedSlider = new Slider(c, SWT.NONE); + simSpeedSlider.setMinimum(1); + simSpeedSlider.setMaximum(100 + simSpeedSlider.getThumb()); + simSpeedSlider.setIncrement(1); Label speedPercentageLabel = new Label(c, SWT.NONE); speedPercentageLabel.setText("100%"); - slider.addListener(SWT.Selection, e -> + simSpeedSlider.addListener(SWT.Selection, e -> { - int selection = slider.getSelection(); + int selection = simSpeedSlider.getSelection(); speedPercentageLabel.setText(selection + "%"); - exec.setSpeedPercentage(slider.getSelection()); + exec.setSpeedPercentage(simSpeedSlider.getSelection()); }); - slider.setSelection(100); + simSpeedSlider.setSelection(100); c.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL)); c.pack(); - c.setVisible(true); + } + + 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) @@ -172,6 +263,7 @@ public class SimulationViewEditor extends EditorPart { IFileEditorInput fileInput = (IFileEditorInput) input; context = ProjectMachineContext.getMachineContextOf(fileInput.getFile().getProject()); + context.registerObserver(m -> recreateContextDependentControls()); recreateContextDependentControls(); setPartName(fileInput.getName());