X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fviews%2FLogicUIPart.java;h=83b3e2f5566e210870f034514dab4d155dc09817;hb=aacd9de307f43bd19065ace45688a49af064f5a5;hp=d40f5a3569b914ea632d33dc858bd4662a4ac8dc;hpb=193667ac7c2900324c2de9996590a4cde5ac2c70;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 d40f5a35..83b3e2f5 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 @@ -1,32 +1,22 @@ package net.mograsim.plugin.views; +import java.util.Optional; + 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 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.logic.model.LogicExecuter; +import net.mograsim.logic.model.LogicUICanvas; +import net.mograsim.machine.Machine; +import net.mograsim.machine.MachineDefinition; +import net.mograsim.machine.MachineRegistry; +import net.mograsim.plugin.ThemePreferences; import net.mograsim.preferences.Preferences; public class LogicUIPart extends ViewPart @@ -48,44 +38,15 @@ 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 null; - } - return new ColorDefinition(rgb.red, rgb.green, rgb.blue); - } - - @Override - public Color getColor(String name) - { - return getColorRegistry().get(name); - } + Preferences.setPreferences(new ThemePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme())); - private ColorRegistry getColorRegistry() - { - return PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); - } - }); + Optional mdo = MachineRegistry.getinstalledMachines().stream().findFirst(); - // 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); + MachineDefinition md = mdo.orElseThrow(IllegalStateException::new); + Machine m = md.createNew(); // 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; @@ -93,7 +54,7 @@ public class LogicUIPart extends ViewPart userInput.enableUserInput(); // initialize executer - exec = new LogicExecuter(timeline); + exec = new LogicExecuter(m.getTimeline()); // run it exec.startLiveExecution(); @@ -104,24 +65,4 @@ public class LogicUIPart extends ViewPart { 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