X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2FLogicUICanvas.java;h=3795f64fd1016d41eb268a47f076253cbb0a602d;hb=5ece0acf049bf9af2933f513fe0206565681f622;hp=4bc4f67268c619c1faf1d716ec992487ff2a0241;hpb=f2d9d6040e8573217ca7588ff56d532eea6b6df2;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java index 4bc4f672..3795f64f 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/LogicUICanvas.java @@ -23,8 +23,8 @@ import net.mograsim.logic.core.types.Bit; import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.ui.model.ViewModel; import net.mograsim.logic.ui.model.components.GUIComponent; -import net.mograsim.logic.ui.model.components.SubmodelComponent; -import net.mograsim.logic.ui.model.components.SubmodelInterface; +import net.mograsim.logic.ui.model.components.submodels.SubmodelComponent; +import net.mograsim.logic.ui.model.components.submodels.SubmodelInterface; import net.mograsim.logic.ui.model.wires.WireCrossPoint; import net.mograsim.preferences.Preferences; @@ -66,7 +66,7 @@ public class LogicUICanvas extends ZoomableCanvas if (e.button == 1) { Point click = displayToWorldCoords(e.x, e.y); - for (GUIComponent component : model.getComponents()) + for (GUIComponent component : model.getComponentsByName().values()) if (component.getBounds().contains(click) && component.clicked(click.x, click.y)) { redraw(); @@ -100,39 +100,57 @@ public class LogicUICanvas extends ZoomableCanvas radioBit.setText("Single bit"); Button radioBitVector = new Button(radioGroup, SWT.RADIO); radioBitVector.setText("Bitvector"); - new Label(debugShell, SWT.NONE).setText("Value string representation: "); + new Label(debugShell, SWT.NONE).setText("Value string representation: \n(Bit vectors: MSBit...LSBit)"); Text valueText = new Text(debugShell, SWT.SINGLE | SWT.LEAD | SWT.BORDER); valueText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); Button send = new Button(debugShell, SWT.PUSH); - Text lastError = new Text(debugShell, SWT.READ_ONLY); - lastError.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); send.setText("Send!"); + Button get = new Button(debugShell, SWT.PUSH); + get.setText("Get!"); + Text output = new Text(debugShell, SWT.READ_ONLY); + output.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); Listener sendAction = e -> { try { - if (componentSelector.getSelectionIndex() >= componentsByItemIndex.size()) - throw new RuntimeException("No valid component selected"); - GUIComponent target = componentsByItemIndex.get(componentSelector.getSelectionIndex()); + int componentIndex = componentSelector.getSelectionIndex(); + if (componentIndex < 0 || componentIndex >= componentsByItemIndex.size()) + throw new RuntimeException("No component selected"); + GUIComponent target = componentsByItemIndex.get(componentIndex); String valueString = valueText.getText(); Object value; if (radioBit.getSelection()) value = Bit.parse(valueString); else if (radioBitVector.getSelection()) - value = BitVector.parse(valueString); + value = BitVector.parseMSBFirst(valueString); else throw new RuntimeException("No value type selected"); target.setHighLevelState(stateIDText.getText(), value); - lastError.setText("Success!"); + output.setText("Success!"); } catch (Exception x) { - lastError.setText(x.getMessage()); + output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage())); + } + }; + Listener getAction = e -> + { + try + { + if (componentSelector.getSelectionIndex() >= componentsByItemIndex.size()) + throw new RuntimeException("No valid component selected"); + output.setText("Success! Value: \r\n" + + componentsByItemIndex.get(componentSelector.getSelectionIndex()).getHighLevelState(stateIDText.getText())); + } + catch (Exception x) + { + output.setText(x.getClass().getSimpleName() + (x.getMessage() == null ? "" : ": " + x.getMessage())); } }; - stateIDText.addListener(SWT.DefaultSelection, sendAction); - valueText.addListener(SWT.DefaultSelection, sendAction); send.addListener(SWT.Selection, sendAction); + valueText.addListener(SWT.DefaultSelection, sendAction); + get.addListener(SWT.Selection, getAction); + stateIDText.addListener(SWT.DefaultSelection, getAction); debugShell.open(); } @@ -145,10 +163,10 @@ public class LogicUICanvas extends ZoomableCanvas private void addComponentSelectorItems(List componentsByItemIndex, String base, Combo componentSelector, ViewModel model) { - for (GUIComponent c : model.getComponents()) + for (GUIComponent c : model.getComponentsByName().values()) if (!(c instanceof WireCrossPoint || c instanceof SubmodelInterface)) { - String item = base + c.getIdentifier(); + String item = base + c.name; componentsByItemIndex.add(c); componentSelector.add(item); if (c instanceof SubmodelComponent)