LogicUI works embedded in SampleERCP again
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 29 May 2019 19:57:35 +0000 (21:57 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 29 May 2019 19:57:35 +0000 (21:57 +0200)
LogicUI/src/era/mi/gui/examples/RSLatchExample.java
SampleERCP/src/sampleercp/parts/LogicUIPart.java

index 91b2d0e..57b5b9c 100644 (file)
@@ -16,7 +16,7 @@ public class RSLatchExample
                SimpleLogicUIStandalone.executeVisualisation(RSLatchExample::createRSLatchExample);
        }
 
-       private static void createRSLatchExample(ViewModel model)
+       public static void createRSLatchExample(ViewModel model)
        {
                GUIManualSwitch rIn = new GUIManualSwitch(model);
                rIn.moveTo(100, 100);
index fa18e2d..98fb64c 100644 (file)
@@ -7,8 +7,13 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 
+import era.mi.gui.LogicExecuter;
 import era.mi.gui.LogicUICanvas;
+import era.mi.gui.examples.RSLatchExample;
 import era.mi.gui.model.ViewModel;
+import era.mi.gui.modeladapter.LogicModelParameters;
+import era.mi.gui.modeladapter.ViewLogicModelAdapter;
+import era.mi.logic.timeline.Timeline;
 import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput;
 
 public class LogicUIPart
@@ -19,41 +24,31 @@ public class LogicUIPart
        @PostConstruct
        public void create(Composite parent)
        {
-               ViewModel model = new ViewModel();
-               LogicUICanvas ui = new LogicUICanvas(parent, SWT.NONE, model);
-//             RSLatchGUIExample.addComponentsAndWires(ui, timeline);
+               // setup view model
+               ViewModel viewModel = new ViewModel();
+               RSLatchExample.createRSLatchExample(viewModel);
+
+               // convert to logic model
+               LogicModelParameters params = new LogicModelParameters();
+               params.gateProcessTime = 50;
+               params.wireTravelTime = 10;
+               Timeline timeline = ViewLogicModelAdapter.convert(viewModel, params);
+
+               // initialize UI
+               LogicUICanvas ui = new LogicUICanvas(parent, SWT.NONE, viewModel);
                ui.addTransformListener((x, y, z) -> part.setDirty(z < 1));
                ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(ui);
                userInput.buttonDrag = 3;
                userInput.buttonZoom = 2;
                userInput.enableUserInput();
-//             Thread simulationThread = new Thread(() ->
-//             {
-//                     // TODO find a better condition
-//                     while (!ui.isDisposed())
-//                     {
-//                             // always execute to keep timeline from "hanging behind" for too long
-//                             timeline.executeUpTo(System.currentTimeMillis(), System.currentTimeMillis() + 10);
-//                             long sleepTime;
-//                             if (timeline.hasNext())
-//                                     sleepTime = timeline.nextEventTime() - System.currentTimeMillis();
-//                             else
-//                                     sleepTime = 10;
-//                             try
-//                             {
-//                                     if (sleepTime > 0)
-//                                             Thread.sleep(sleepTime);
-//                             }
-//                             catch (InterruptedException e)
-//                             {
-//                             } // it is normal execution flow to be interrupted
-//                     }
-//             });
-//             simulationThread.start();
-//             timeline.addEventAddedListener(event ->
-//             {
-//                     if (event.getTiming() <= System.currentTimeMillis())
-//                             simulationThread.interrupt();
-//             });
+
+               // initialize executer
+               LogicExecuter exec = new LogicExecuter(timeline);
+
+               // run it
+               exec.startLiveExecution();
+
+               // TODO find a better condition when to stop
+               ui.addDisposeListener(e -> exec.stopLiveExecution());
        }
 }
\ No newline at end of file