X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fviews%2FLogicUIPart.java;h=212f777cdd4b30d833e2a64798d4d21f6ae3909e;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=61e0b3849637a8cbac448bca8b38a88463e2e9c9;hpb=1852c81ce3a63e6847fc5404f91607b553fcd882;p=Mograsim.git diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java index 61e0b384..212f777c 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/views/LogicUIPart.java @@ -2,33 +2,18 @@ package net.mograsim.plugin.views; import javax.inject.Inject; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.statushandlers.StatusManager; -import org.eclipse.ui.themes.ITheme; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; -import net.mograsim.logic.core.timeline.Timeline; -import net.mograsim.logic.ui.LogicExecuter; -import net.mograsim.logic.ui.LogicUICanvas; -import net.mograsim.logic.ui.model.ViewModelModifiable; -import net.mograsim.logic.ui.model.components.GUIBitDisplay; -import net.mograsim.logic.ui.model.components.GUIManualSwitch; -import net.mograsim.logic.ui.model.components.SimpleRectangularSubmodelComponent; -import net.mograsim.logic.ui.model.components.mi.nandbased.am2901.GUIAm2901; -import net.mograsim.logic.ui.model.wires.GUIWire; -import net.mograsim.logic.ui.modeladapter.LogicModelParameters; -import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter; -import net.mograsim.preferences.ColorDefinition; -import net.mograsim.preferences.ColorDefinition.BuiltInColor; +import net.mograsim.logic.model.LogicExecuter; +import net.mograsim.logic.model.LogicUICanvas; +import net.mograsim.machine.Machine; +import net.mograsim.plugin.MachineContext; +import net.mograsim.plugin.ThemePreferences; import net.mograsim.preferences.Preferences; public class LogicUIPart extends ViewPart @@ -50,90 +35,28 @@ public class LogicUIPart extends ViewPart public void createPartControl(Composite parent) { // set preferences - Preferences.setPreferences(new Preferences() - { - @Override - public ColorDefinition getColorDefinition(String name) - { - RGB rgb = getColorRegistry().getRGB(name); - if (rgb == null) - { - StatusManager.getManager().handle(new Status(IStatus.ERROR, "net.mograsim.plugin.core", "No color for name " + name)); - return new ColorDefinition(BuiltInColor.COLOR_BLACK); - } - return new ColorDefinition(rgb.red, rgb.green, rgb.blue); - } + Preferences.setPreferences(new ThemePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme())); - @Override - public Color getColor(String name) - { - return getColorRegistry().get(name); - } - - private ColorRegistry getColorRegistry() - { - return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); - } - }); - - // setup view model - ViewModelModifiable viewModel = new ViewModelModifiable(); - createTestbench(viewModel); - - // convert to logic model - LogicModelParameters params = new LogicModelParameters(); - params.gateProcessTime = 50; - params.wireTravelTime = 10; - Timeline timeline = ViewLogicModelAdapter.convert(viewModel, params); + Machine m = MachineContext.getInstance().getMachine(); // initialize UI - ui = new LogicUICanvas(parent, SWT.NONE, viewModel); + ui = new LogicUICanvas(parent, SWT.NONE, m.getModel()); ui.addTransformListener((x, y, z) -> part.setDirty(z < 1)); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui); userInput.buttonDrag = 3; userInput.buttonZoom = 2; userInput.enableUserInput(); - ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(); - update(currentTheme); - currentTheme.getColorRegistry().addListener(e -> update(currentTheme)); - // initialize executer - exec = new LogicExecuter(timeline); + exec = new LogicExecuter(m.getTimeline()); // run it exec.startLiveExecution(); } - private void update(ITheme currentTheme) - { - ui.setBackground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_backgound")); - ui.setForeground(currentTheme.getColorRegistry().get("net.mograsim.plugin.sim_text_color")); - } - @Override public void setFocus() { ui.setFocus(); } - - @SuppressWarnings("unused") // for GUIWires being created - public static void createTestbench(ViewModelModifiable model) - { - SimpleRectangularSubmodelComponent comp = new GUIAm2901(model); - - comp.moveTo(100, 0); - for (int i = 0; i < comp.getInputPinNames().size(); i++) - { - GUIManualSwitch sw = new GUIManualSwitch(model); - sw.moveTo(0, 20 * i); - new GUIWire(model, comp.getPin(comp.getInputPinNames().get(i)), sw.getOutputPin()); - } - for (int i = 0; i < comp.getOutputPinNames().size(); i++) - { - GUIBitDisplay bd = new GUIBitDisplay(model); - bd.moveTo(200, 20 * i); - new GUIWire(model, comp.getPin(comp.getOutputPinNames().get(i)), bd.getInputPin()); - } - } } \ No newline at end of file