X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fviews%2FLogicUIPart.java;h=00b1956668aeea308dced630f1bd1705598c5267;hb=6345e8d7c88792fb1f92eb490e43b0decc15bf0f;hp=aab85c8c516c0e9b97717798b06a4e6b61a27ee5;hpb=19b9fa6c1cfcd7036c5b0c44c892f029cd04879b;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 aab85c8c..00b19566 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,5 +1,9 @@ package net.mograsim.plugin.views; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + import javax.inject.Inject; import org.eclipse.e4.ui.model.application.ui.basic.MPart; @@ -7,20 +11,22 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; -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.logic.model.LogicExecuter; +import net.mograsim.logic.model.LogicUICanvas; +import net.mograsim.logic.model.model.ViewModelModifiable; +import net.mograsim.logic.model.model.components.GUIComponent; +import net.mograsim.logic.model.model.components.atomic.GUIBitDisplay; +import net.mograsim.logic.model.model.components.atomic.GUIManualSwitch; +import net.mograsim.logic.model.model.wires.GUIWire; +import net.mograsim.logic.model.model.wires.Pin; +import net.mograsim.logic.model.modeladapter.LogicModelParameters; +import net.mograsim.logic.model.modeladapter.ViewLogicModelAdapter; +import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; +import net.mograsim.plugin.ThemePreferences; +import net.mograsim.preferences.Preferences; public class LogicUIPart extends ViewPart { @@ -40,6 +46,9 @@ public class LogicUIPart extends ViewPart @Override public void createPartControl(Composite parent) { + // set preferences + Preferences.setPreferences(new ThemePreferences(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme())); + // setup view model ViewModelModifiable viewModel = new ViewModelModifiable(); createTestbench(viewModel); @@ -58,10 +67,6 @@ public class LogicUIPart extends ViewPart 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); @@ -69,12 +74,6 @@ public class LogicUIPart extends ViewPart 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() { @@ -84,20 +83,32 @@ public class LogicUIPart extends ViewPart @SuppressWarnings("unused") // for GUIWires being created public static void createTestbench(ViewModelModifiable model) { - SimpleRectangularSubmodelComponent comp = new GUIAm2901(model); + GUIComponent comp = IndirectGUIComponentCreator.createComponent(model, "GUIAm2901"); + + // TODO this code exists four times... but it seems too "hacky" to put it in a helper class + List inputPinNames = new ArrayList<>(); + List outputPinNames = new ArrayList<>(); + for (Pin p : comp.getPins().values()) + if (p.getRelX() == 0) + inputPinNames.add(p.name); + else + outputPinNames.add(p.name); + + inputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); + outputPinNames.sort(Comparator.comparing(comp::getPin, Comparator.comparing(Pin::getRelY))); comp.moveTo(100, 0); - for (int i = 0; i < comp.getInputPinNames().size(); i++) + for (int i = 0; i < inputPinNames.size(); i++) { - GUIManualSwitch sw = new GUIManualSwitch(model); + GUIManualSwitch sw = new GUIManualSwitch(model, 1); sw.moveTo(0, 20 * i); - new GUIWire(model, comp.getPin(comp.getInputPinNames().get(i)), sw.getOutputPin()); + new GUIWire(model, comp.getPin(inputPinNames.get(i)), sw.getOutputPin()); } - for (int i = 0; i < comp.getOutputPinNames().size(); i++) + for (int i = 0; i < outputPinNames.size(); i++) { - GUIBitDisplay bd = new GUIBitDisplay(model); + GUIBitDisplay bd = new GUIBitDisplay(model, 1); bd.moveTo(200, 20 * i); - new GUIWire(model, comp.getPin(comp.getOutputPinNames().get(i)), bd.getInputPin()); + new GUIWire(model, comp.getPin(outputPinNames.get(i)), bd.getInputPin()); } } } \ No newline at end of file