| 1 |
2 |
peteralieb |
package edu.byu.cc.plieber.fpgaenet.examples;
|
| 2 |
|
|
|
| 3 |
|
|
import java.io.IOException;
|
| 4 |
|
|
import java.net.InetAddress;
|
| 5 |
|
|
|
| 6 |
|
|
import com.trolltech.qt.core.QModelIndex;
|
| 7 |
|
|
import com.trolltech.qt.core.Qt.DockWidgetArea;
|
| 8 |
|
|
//import com.trolltech.qt.gui.*;
|
| 9 |
|
|
import com.trolltech.qt.gui.QAbstractItemView.SelectionMode;
|
| 10 |
|
|
import com.trolltech.qt.gui.QAction;
|
| 11 |
|
|
import com.trolltech.qt.gui.QApplication;
|
| 12 |
|
|
import com.trolltech.qt.gui.QBoxLayout;
|
| 13 |
|
|
import com.trolltech.qt.gui.QBoxLayout.Direction;
|
| 14 |
|
|
import com.trolltech.qt.gui.QDockWidget;
|
| 15 |
|
|
import com.trolltech.qt.gui.QFileDialog;
|
| 16 |
|
|
import com.trolltech.qt.gui.QFrame;
|
| 17 |
|
|
import com.trolltech.qt.gui.QHBoxLayout;
|
| 18 |
|
|
import com.trolltech.qt.gui.QItemSelection;
|
| 19 |
|
|
import com.trolltech.qt.gui.QLabel;
|
| 20 |
|
|
import com.trolltech.qt.gui.QLayout;
|
| 21 |
|
|
import com.trolltech.qt.gui.QLineEdit;
|
| 22 |
|
|
import com.trolltech.qt.gui.QListView;
|
| 23 |
|
|
import com.trolltech.qt.gui.QMainWindow;
|
| 24 |
|
|
import com.trolltech.qt.gui.QMenu;
|
| 25 |
|
|
import com.trolltech.qt.gui.QMessageBox;
|
| 26 |
|
|
import com.trolltech.qt.gui.QPushButton;
|
| 27 |
|
|
import com.trolltech.qt.gui.QSortFilterProxyModel;
|
| 28 |
|
|
import com.trolltech.qt.gui.QTableView;
|
| 29 |
|
|
import com.trolltech.qt.gui.QVBoxLayout;
|
| 30 |
|
|
import com.trolltech.qt.gui.QWidget;
|
| 31 |
|
|
|
| 32 |
|
|
import edu.byu.cc.plieber.fpgaenet.debug.IcapReadback;
|
| 33 |
|
|
import edu.byu.cc.plieber.fpgaenet.debug.LogicalMapping;
|
| 34 |
|
|
import edu.byu.cc.plieber.fpgaenet.debug.llparse.LatchRBEntry;
|
| 35 |
|
|
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
|
| 36 |
|
|
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
|
| 37 |
|
|
import edu.byu.cc.plieber.fpgaenet.icapif.IcapInterface;
|
| 38 |
|
|
import edu.byu.cc.plieber.fpgaenet.icapif.IcapTools;
|
| 39 |
|
|
|
| 40 |
|
|
public class IcapToolGui extends QMainWindow {
|
| 41 |
|
|
|
| 42 |
|
|
private QMenu fileMenu;
|
| 43 |
|
|
private QMenu helpMenu;
|
| 44 |
|
|
|
| 45 |
|
|
private QAction openLL;
|
| 46 |
|
|
private QAction exitAct;
|
| 47 |
|
|
private QAction aboutAct;
|
| 48 |
|
|
private QAction aboutQtJambiAct;
|
| 49 |
|
|
|
| 50 |
|
|
// Widgets
|
| 51 |
|
|
private QLabel netLabel;
|
| 52 |
|
|
private QLineEdit netValue;
|
| 53 |
|
|
private QPushButton buttonGetValue;
|
| 54 |
|
|
|
| 55 |
|
|
// Model/Views
|
| 56 |
|
|
private QListView netListView;
|
| 57 |
|
|
private QTableView netTableView;
|
| 58 |
|
|
private NetListModel netListModel;
|
| 59 |
|
|
QSortFilterProxyModel tableProxyModel;
|
| 60 |
|
|
QSortFilterProxyModel listProxyModel;
|
| 61 |
|
|
|
| 62 |
|
|
// Connections
|
| 63 |
|
|
FCPProtocol fcpProtocol;
|
| 64 |
|
|
IcapInterface icapif;
|
| 65 |
|
|
IcapTools icapTools;
|
| 66 |
|
|
IcapReadback icapReadback;
|
| 67 |
|
|
LatchRBEntry currentEntry;
|
| 68 |
|
|
|
| 69 |
|
|
public static void main(String[] args) {
|
| 70 |
|
|
QApplication.initialize(args);
|
| 71 |
|
|
|
| 72 |
|
|
IcapToolGui testIcapToolGui = new IcapToolGui(null);
|
| 73 |
|
|
testIcapToolGui.show();
|
| 74 |
|
|
|
| 75 |
|
|
QApplication.exec();
|
| 76 |
|
|
|
| 77 |
|
|
testIcapToolGui.tearDown();
|
| 78 |
|
|
}
|
| 79 |
|
|
|
| 80 |
|
|
public void tearDown() {
|
| 81 |
|
|
fcpProtocol.disconnect();
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
public IcapToolGui(QWidget parent) {
|
| 85 |
|
|
super(parent);
|
| 86 |
|
|
setWindowTitle("ICAP Tool GUI");
|
| 87 |
|
|
createActions();
|
| 88 |
|
|
createMenus();
|
| 89 |
|
|
createWidgets();
|
| 90 |
|
|
setupConnections();
|
| 91 |
|
|
connectSignals();
|
| 92 |
|
|
}
|
| 93 |
|
|
|
| 94 |
|
|
private void setupConnections() {
|
| 95 |
|
|
try {
|
| 96 |
|
|
fcpProtocol = new FCPProtocol();
|
| 97 |
|
|
fcpProtocol.connect(InetAddress.getByName("192.168.1.222"), 0x3001);
|
| 98 |
|
|
} catch (IOException e) {
|
| 99 |
|
|
return;
|
| 100 |
|
|
}
|
| 101 |
|
|
icapif = new IcapInterface(fcpProtocol);
|
| 102 |
|
|
icapTools = new IcapTools(icapif);
|
| 103 |
|
|
icapReadback = new IcapReadback(icapTools);
|
| 104 |
|
|
while(!fcpProtocol.isConnected());
|
| 105 |
|
|
icapTools.synchIcap();
|
| 106 |
|
|
}
|
| 107 |
|
|
|
| 108 |
|
|
private void createActions() {
|
| 109 |
|
|
openLL = new QAction(tr("&Open LL File"), this);
|
| 110 |
|
|
openLL.setShortcut(tr("Ctrl+O"));
|
| 111 |
|
|
openLL.setStatusTip(tr("Open new LL file"));
|
| 112 |
|
|
openLL.triggered.connect(this, "openLL()");
|
| 113 |
|
|
|
| 114 |
|
|
exitAct = new QAction(tr("E&xit"), this);
|
| 115 |
|
|
exitAct.setShortcut(tr("Ctrl+Q"));
|
| 116 |
|
|
exitAct.setStatusTip(tr("Exit the application"));
|
| 117 |
|
|
exitAct.triggered.connect(this, "close()");
|
| 118 |
|
|
|
| 119 |
|
|
aboutAct = new QAction(tr("&About"), this);
|
| 120 |
|
|
aboutAct.setStatusTip(tr("Show the application's About box"));
|
| 121 |
|
|
aboutAct.triggered.connect(this, "about()");
|
| 122 |
|
|
|
| 123 |
|
|
aboutQtJambiAct = new QAction(tr("About &Qt Jambi"), this);
|
| 124 |
|
|
aboutQtJambiAct.setStatusTip(tr("Show the Qt Jambi's About box"));
|
| 125 |
|
|
aboutQtJambiAct.triggered.connect(QApplication.instance(), "aboutQtJambi()");
|
| 126 |
|
|
}
|
| 127 |
|
|
|
| 128 |
|
|
private void createMenus() {
|
| 129 |
|
|
fileMenu = menuBar().addMenu(tr("&File"));
|
| 130 |
|
|
fileMenu.addAction(openLL);
|
| 131 |
|
|
fileMenu.addAction(exitAct);
|
| 132 |
|
|
|
| 133 |
|
|
helpMenu = menuBar().addMenu(tr("&Help"));
|
| 134 |
|
|
helpMenu.addAction(aboutAct);
|
| 135 |
|
|
helpMenu.addAction(aboutQtJambiAct);
|
| 136 |
|
|
}
|
| 137 |
|
|
|
| 138 |
|
|
private void createWidgets() {
|
| 139 |
|
|
// Left Dock Net List
|
| 140 |
|
|
netListView = new QListView(this);
|
| 141 |
|
|
netListView.setSelectionMode(SelectionMode.ExtendedSelection);
|
| 142 |
|
|
QDockWidget dockWidget = new QDockWidget(tr("Net List"), this);
|
| 143 |
|
|
dockWidget.setAllowedAreas(DockWidgetArea.LeftDockWidgetArea);
|
| 144 |
|
|
dockWidget.setWidget(netListView);
|
| 145 |
|
|
addDockWidget(DockWidgetArea.LeftDockWidgetArea, dockWidget);
|
| 146 |
|
|
|
| 147 |
|
|
// Main area Frame -------------------------------------------------
|
| 148 |
|
|
QFrame mainFrame = new QFrame(this);
|
| 149 |
|
|
setCentralWidget(mainFrame);
|
| 150 |
|
|
netTableView = new QTableView(mainFrame);
|
| 151 |
|
|
QVBoxLayout mainLayout = new QVBoxLayout(mainFrame);
|
| 152 |
|
|
mainLayout.addWidget(netTableView);
|
| 153 |
|
|
QHBoxLayout netValueLayout = new QHBoxLayout();
|
| 154 |
|
|
netLabel = new QLabel(tr("Net Value"));
|
| 155 |
|
|
netValue = new QLineEdit(tr("<net value>"));
|
| 156 |
|
|
buttonGetValue = new QPushButton(tr("Get Value"));
|
| 157 |
|
|
buttonGetValue.clicked.connect(this, "getNetValue()");
|
| 158 |
|
|
netValueLayout.addWidget(netLabel);
|
| 159 |
|
|
netValueLayout.addWidget(netValue);
|
| 160 |
|
|
netValueLayout.addWidget(buttonGetValue);
|
| 161 |
|
|
mainLayout.addLayout(netValueLayout);
|
| 162 |
|
|
mainFrame.setLayout(mainLayout);
|
| 163 |
|
|
}
|
| 164 |
|
|
|
| 165 |
|
|
private void connectSignals() {
|
| 166 |
|
|
netListView.doubleClicked.connect(this, "openStatusWidget(QModelIndex)");
|
| 167 |
|
|
}
|
| 168 |
|
|
|
| 169 |
|
|
protected void openLL() {
|
| 170 |
|
|
String fName = QFileDialog.getOpenFileName(this, tr("Open LL File"), "", new QFileDialog.Filter(
|
| 171 |
|
|
tr("LL Files (*.ll *.LL)")));
|
| 172 |
|
|
LogicalMapping llMapping = new LogicalMapping(fName);
|
| 173 |
|
|
netListModel = new NetListModel(llMapping);
|
| 174 |
|
|
listProxyModel = new QSortFilterProxyModel(this);
|
| 175 |
|
|
listProxyModel.setSourceModel(netListModel);
|
| 176 |
|
|
listProxyModel.sort(0);
|
| 177 |
|
|
netListView.setModel(listProxyModel);
|
| 178 |
|
|
tableProxyModel = new QSortFilterProxyModel(this);
|
| 179 |
|
|
tableProxyModel.setSourceModel(netListModel);
|
| 180 |
|
|
tableProxyModel.setFilterFixedString("");
|
| 181 |
|
|
netTableView.setModel(tableProxyModel);
|
| 182 |
|
|
netTableView.setSelectionMode(SelectionMode.SingleSelection);
|
| 183 |
|
|
netListView.selectionModel().selectionChanged.connect(this,
|
| 184 |
|
|
"netSelectionChanged(QItemSelection,QItemSelection)");
|
| 185 |
|
|
netTableView.clicked.connect(this, "netDetailClicked(QModelIndex)");
|
| 186 |
|
|
}
|
| 187 |
|
|
|
| 188 |
|
|
protected void about() {
|
| 189 |
|
|
QMessageBox.information(this, "Info", "It's your turn now :-)");
|
| 190 |
|
|
}
|
| 191 |
|
|
|
| 192 |
|
|
protected void openStatusWidget(QModelIndex index) {
|
| 193 |
|
|
QWidget statusWidget = new QWidget();
|
| 194 |
|
|
QLayout layout = new QBoxLayout(Direction.LeftToRight);
|
| 195 |
|
|
layout.addWidget(new QLabel(tr(listProxyModel.data(index).toString()), statusWidget));
|
| 196 |
|
|
statusWidget.setLayout(layout);
|
| 197 |
|
|
statusWidget.setWindowTitle(tr("Net Status"));
|
| 198 |
|
|
statusWidget.show();
|
| 199 |
|
|
}
|
| 200 |
|
|
|
| 201 |
|
|
protected void filterTableView(QModelIndex index) {
|
| 202 |
|
|
//tableProxyModel.setFilterFixedString(listProxyModel.data(index).toString());
|
| 203 |
|
|
}
|
| 204 |
|
|
|
| 205 |
|
|
protected void netSelectionChanged(QItemSelection deselected, QItemSelection selected) {
|
| 206 |
|
|
String regexStr = "^(";
|
| 207 |
|
|
for (QModelIndex index : netListView.selectionModel().selection().indexes()) {
|
| 208 |
|
|
regexStr += listProxyModel.data(index).toString() + "|";
|
| 209 |
|
|
}
|
| 210 |
|
|
regexStr = regexStr.substring(0, regexStr.length()-1);
|
| 211 |
|
|
regexStr += ")$";
|
| 212 |
|
|
tableProxyModel.setFilterRegExp(regexStr);
|
| 213 |
|
|
tableProxyModel.sort(0);
|
| 214 |
|
|
}
|
| 215 |
|
|
|
| 216 |
|
|
protected void netDetailClicked(QModelIndex index) {
|
| 217 |
|
|
currentEntry = netListModel.getEntry(tableProxyModel.mapToSource(index));
|
| 218 |
|
|
netLabel.setText(currentEntry.getFullName());
|
| 219 |
|
|
netValue.setText("<Invalid>");
|
| 220 |
|
|
}
|
| 221 |
|
|
|
| 222 |
|
|
protected void getNetValue() {
|
| 223 |
|
|
try {
|
| 224 |
|
|
if (currentEntry != null) {
|
| 225 |
|
|
netValue.setText(String.valueOf(icapReadback.readState(currentEntry)));
|
| 226 |
|
|
}
|
| 227 |
|
|
} catch (FCPException e) {
|
| 228 |
|
|
QMessageBox.critical(this, "FCP Error", "Error during FCP communication, connection closed");
|
| 229 |
|
|
this.fcpProtocol.disconnect();
|
| 230 |
|
|
this.close();
|
| 231 |
|
|
}
|
| 232 |
|
|
}
|
| 233 |
|
|
}
|