1 package net.mograsim.plugin;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.widgets.Composite;
5 import org.eclipse.ui.themes.ITheme;
6 import org.eclipse.ui.themes.IThemePreview;
8 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
9 import net.mograsim.logic.core.timeline.Timeline;
10 import net.mograsim.logic.model.LogicExecuter;
11 import net.mograsim.logic.model.LogicUICanvas;
12 import net.mograsim.logic.model.model.LogicModelModifiable;
13 import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch;
14 import net.mograsim.logic.model.model.components.atomic.ModelNotGate;
15 import net.mograsim.logic.model.model.components.atomic.ModelOrGate;
16 import net.mograsim.logic.model.model.wires.ModelWire;
17 import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
18 import net.mograsim.logic.model.modeladapter.CoreModelParameters;
19 import net.mograsim.logic.model.modeladapter.CoreModelParameters.CoreModelParametersBuilder;
20 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
21 import net.mograsim.logic.model.preferences.RenderPreferences;
22 import net.mograsim.plugin.preferences.EclipseRenderPreferences;
24 public class SimulationPreview implements IThemePreview
26 private LogicUICanvas ui;
27 private LogicExecuter exec;
30 @SuppressWarnings("unused")
31 public void createControl(Composite parent, ITheme currentTheme)
33 RenderPreferences currentThemeRenderPrefs = new EclipseRenderPreferences(currentTheme,
34 MograsimActivator.instance().getPreferenceStore());
36 LogicModelModifiable model = new LogicModelModifiable();
38 CoreModelParametersBuilder paramsBuilder = CoreModelParameters.builder();
39 paramsBuilder.gateProcessTime = 50;
40 paramsBuilder.hardcodedComponentProcessTime = paramsBuilder.gateProcessTime * 5;
41 paramsBuilder.wireTravelTime = 10;
42 CoreModelParameters params = paramsBuilder.build();
44 ModelManualSwitch rIn = new ModelManualSwitch(model, 1);
46 ModelManualSwitch sIn = new ModelManualSwitch(model, 1);
49 ModelOrGate or1 = new ModelOrGate(model, 1);
51 new ModelWire(model, rIn.getOutputPin(), or1.getPin("A"));
53 ModelOrGate or2 = new ModelOrGate(model, 1);
55 new ModelWire(model, sIn.getOutputPin(), or2.getPin("B"));
57 ModelNotGate not1 = new ModelNotGate(model, 1);
58 not1.moveTo(110, 17.5);
59 new ModelWire(model, or1.getPin("Y"), not1.getPin("A"));
61 ModelNotGate not2 = new ModelNotGate(model, 1);
62 not2.moveTo(110, 67.5);
63 new ModelWire(model, or2.getPin("Y"), not2.getPin("A"));
65 ModelWireCrossPoint p1 = new ModelWireCrossPoint(model, 1);
66 p1.moveCenterTo(140, 22.5);
67 new ModelWire(model, not1.getPin("Y"), p1);
68 new ModelWire(model, p1, or2.getPin("A"), new Point(140, 35), new Point(50, 60), new Point(50, 67.5));
70 ModelWireCrossPoint p2 = new ModelWireCrossPoint(model, 1);
71 p2.moveCenterTo(140, 72.5);
72 new ModelWire(model, not2.getPin("Y"), p2);
73 new ModelWire(model, p2, or1.getPin("B"), new Point(140, 60), new Point(50, 35), new Point(50, 27.5));
75 ModelWireCrossPoint o1 = new ModelWireCrossPoint(model, 1);
76 o1.moveCenterTo(150, 22.5);
77 new ModelWire(model, p1, o1);
79 ModelWireCrossPoint o2 = new ModelWireCrossPoint(model, 1);
80 o2.moveCenterTo(150, 72.5);
81 new ModelWire(model, p2, o2);
83 Timeline t = LogicCoreAdapter.convert(model, params);
84 exec = new LogicExecuter(t);
88 ui = new LogicUICanvas(parent, SWT.NONE, model, currentThemeRenderPrefs);
91 exec.startLiveExecution();
93 currentTheme.addPropertyChangeListener(e -> ui.redraw());
99 exec.stopLiveExecution();