Simulation preview no longer can be moved / zoomed; removed old code
[Mograsim.git] / net.mograsim.plugin.core / src / net / mograsim / plugin / SimulationPreview.java
1 package net.mograsim.plugin;
2
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;
7
8 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
9 import net.mograsim.logic.core.timeline.Timeline;
10 import net.mograsim.logic.ui.LogicExecuter;
11 import net.mograsim.logic.ui.LogicUICanvas;
12 import net.mograsim.logic.ui.model.ViewModelModifiable;
13 import net.mograsim.logic.ui.model.components.GUIManualSwitch;
14 import net.mograsim.logic.ui.model.components.GUINotGate;
15 import net.mograsim.logic.ui.model.components.GUIOrGate;
16 import net.mograsim.logic.ui.model.wires.GUIWire;
17 import net.mograsim.logic.ui.model.wires.WireCrossPoint;
18 import net.mograsim.logic.ui.modeladapter.LogicModelParameters;
19 import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
20
21 public class SimulationPreview implements IThemePreview
22 {
23
24         private LogicUICanvas ui;
25         private LogicExecuter exec;
26
27         @Override
28         @SuppressWarnings("unused")
29         public void createControl(Composite parent, ITheme currentTheme)
30         {
31                 ViewModelModifiable model = new ViewModelModifiable();
32                 LogicModelParameters params = new LogicModelParameters();
33                 params.gateProcessTime = 50;
34                 params.wireTravelTime = 10;
35
36                 GUIManualSwitch rIn = new GUIManualSwitch(model);
37                 rIn.moveTo(10, 10);
38                 GUIManualSwitch sIn = new GUIManualSwitch(model);
39                 sIn.moveTo(10, 70);
40
41                 GUIOrGate or1 = new GUIOrGate(model, 1);
42                 or1.moveTo(70, 12.5);
43                 new GUIWire(model, rIn.getOutputPin(), or1.getPin("A"));
44
45                 GUIOrGate or2 = new GUIOrGate(model, 1);
46                 or2.moveTo(70, 62.5);
47                 new GUIWire(model, sIn.getOutputPin(), or2.getPin("B"));
48
49                 GUINotGate not1 = new GUINotGate(model, 1);
50                 not1.moveTo(110, 17.5);
51                 new GUIWire(model, or1.getPin("Y"), not1.getPin("A"));
52
53                 GUINotGate not2 = new GUINotGate(model, 1);
54                 not2.moveTo(110, 67.5);
55                 new GUIWire(model, or2.getPin("Y"), not2.getPin("A"));
56
57                 WireCrossPoint p1 = new WireCrossPoint(model, 1);
58                 p1.moveCenterTo(140, 22.5);
59                 new GUIWire(model, not1.getPin("Y"), p1);
60                 new GUIWire(model, p1, or2.getPin("A"), new Point(140, 35), new Point(50, 60), new Point(50, 67.5));
61
62                 WireCrossPoint p2 = new WireCrossPoint(model, 1);
63                 p2.moveCenterTo(140, 72.5);
64                 new GUIWire(model, not2.getPin("Y"), p2);
65                 new GUIWire(model, p2, or1.getPin("B"), new Point(140, 60), new Point(50, 35), new Point(50, 27.5));
66
67                 WireCrossPoint o1 = new WireCrossPoint(model, 1);
68                 o1.moveCenterTo(150, 22.5);
69                 new GUIWire(model, p1, o1);
70
71                 WireCrossPoint o2 = new WireCrossPoint(model, 1);
72                 o2.moveCenterTo(150, 72.5);
73                 new GUIWire(model, p2, o2);
74
75                 Timeline t = ViewLogicModelAdapter.convert(model, params);
76                 exec = new LogicExecuter(t);
77
78                 rIn.clicked(0, 0);
79
80                 ui = new LogicUICanvas(parent, SWT.NONE, model);
81
82                 ui.zoom(3.5, 10, 10);
83                 exec.startLiveExecution();
84         }
85
86         @Override
87         public void dispose()
88         {
89                 exec.stopLiveExecution();
90         }
91 }