12 :
QTableWidget(parent), mMaxTime(0), mDisableCellParser(false), mDisplayHexValues(true), mCurrentTime(0), mCurrentRow(0)
19 mInputColumnHeader.clear();
24 if (omitClock && ich.is_clock)
continue;
25 mInputColumnHeader.append(ich);
31 int n = mInputColumnHeader.size()+1;
32 for (
int i=0; i<n; i++) setValueCell(0,i,0);
39 void WavedataTableEditor::setupHeader()
45 if (ich.nets.size() > 1) colName +=
QString(
"[%1:0]").
arg(ich.nets.size()-1);
46 headerLabel << colName;
48 int n = mInputColumnHeader.
size()+1;
54 void WavedataTableEditor::setValueCell(
int irow,
int icol,
int val)
65 mDisableCellParser =
true;
72 mCurrentValue =
new int[ncols];
73 memset(mCurrentValue,0,ncols*
sizeof(
int));
75 for (
int icol = 0; icol < ncols; icol++)
79 int nBits = ich.
nets.size();
81 for (
int i=0; i<nBits; i++)
88 if (t != mCurrentTime)
91 if (mCurrentRow+1 >= rowCount()) setRowCount(mCurrentRow+2);
92 QTableWidgetItem* tItem = new QTableWidgetItem(QString::number(t));
93 tItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
94 setItem(mCurrentRow,0,tItem);
96 for (int i=0; i<ncols; i++)
97 setValueCell(mCurrentRow-1, i+1, mCurrentValue[i]);
101 mCurrentValue[icol] |=
mask;
103 mCurrentValue[icol] &= (~
mask);
114 setItem(0,0,zeroItem);
116 while (parser.next_event()) {;}
118 for (
int i=0; i<ncols; i++)
119 setValueCell(mCurrentRow, i+1, mCurrentValue[i]);
121 delete [] mCurrentValue;
123 mDisableCellParser =
false;
128 if (mDisableCellParser)
return;
130 mDisableCellParser =
true;
131 int cur = rowCount() - 1;
132 if (cur > 0 && !changedItem->
column() && changedItem->
row() == cur)
135 for (
int icol=1; icol < columnCount(); icol++)
139 if ((!testItem || testItem->
text().
isEmpty()) && lastItem)
143 setItem(cur, icol, twi);
147 if (!changedItem->
column())
150 int irow = changedItem->
row();
151 if (cur > 0 && irow == cur)
154 for (
int icol=1; icol < columnCount(); icol++)
158 if ((!testItem || testItem->
text().
isEmpty()) && lastItem)
162 setItem(cur,icol, twi);
167 bool numericOk =
false;
169 qlonglong prevVal = irow ? item(irow-1,0)->text().toLongLong() : 0;
170 qlonglong nextVal = 0;
171 if (rowCount() > irow+1 && item(irow+1,0))
173 qlonglong tempNextVal = item(irow+1,0)->text().toLongLong(&numericOk);
174 if (numericOk && tempNextVal >= prevVal+2) nextVal = tempNextVal;
179 if (!numericOk || thisVal <= prevVal || thisVal >= nextVal)
185 if (!numericOk || thisVal <= prevVal)
192 int val = intCellValue(changedItem->
row(),changedItem->
column());
193 if (val == sIllegalValue)
197 if (val > 9 && mDisplayHexValues)
204 mDisableCellParser =
false;
207 int WavedataTableEditor::validLines()
const
210 qlonglong tlast = -1;
211 bool numericOk =
false;
212 for (
int irow = 0; irow < rowCount(); irow++)
215 if (!timeCell)
continue;
217 if (!numericOk)
continue;
218 if (t <= tlast)
continue;
219 bool incomplete =
false;
220 for (
int icol=1; icol<columnCount(); icol++)
229 if (incomplete)
continue;
236 int WavedataTableEditor::intCellValue(
int irow,
int icol)
const
239 int nBits = mInputColumnHeader.
at(icol-1).nets.size();
240 int upperLimit = 1 << nBits;
243 txt = item(irow,icol)->text();
245 return sIllegalValue;
247 bool numberOk =
true;
261 tempValue = txt.
toInt(&numberOk);
262 if (!numberOk || tempValue >= upperLimit)
return sIllegalValue;
268 if (txt.
at(0) ==
'"')
278 if (txt.
at(0) ==
'0')
283 tempValue = txt.
mid(2).
toInt(&numberOk, 16);
286 tempValue = txt.
mid(2).
toInt(&numberOk, 8);
289 tempValue = txt.
mid(2).
toInt(&numberOk, 2);
292 tempValue = txt.
toInt(&numberOk, 10);
297 tempValue = txt.
toInt(&numberOk, 10);
301 if (apos + 2 >= txt.
size())
302 return sIllegalValue;
306 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 16);
309 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 8);
312 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 2);
315 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 10);
318 return sIllegalValue;
323 if (!numberOk || tempValue >= upperLimit)
324 return sIllegalValue;
329 void WavedataTableEditor::generateSimulationInput(
const QString& workdir)
339 for (
auto it = mInputColumnHeader.constBegin(); it != mInputColumnHeader.constEnd(); ++it)
340 maxIndex += it->nets.size();
345 valArray =
new int[maxIndex];
347 for (
auto it = mInputColumnHeader.constBegin(); it != mInputColumnHeader.constEnd(); ++it)
349 int tableVal = intCellValue(0,iTableCol);
350 if (tableVal == WavedataTableEditor::sIllegalValue)
354 for (
const Net* n : it->nets)
357 int netVal = tableVal & mask;
359 sofArray[sofIndex + iBit] = sof;
360 valArray[sofIndex + iBit] = netVal;
365 sofIndex += it->nets.size();
368 for (
int irow = 1; irow < rowCount(); irow++)
371 timeCell = item(irow,0);
372 if (!timeCell)
continue;
374 if (tval <= mMaxTime)
continue;
377 for (
auto it = mInputColumnHeader.constBegin(); it != mInputColumnHeader.constEnd(); ++it)
379 int tableVal = intCellValue(irow,iTableCol);
380 if (tableVal == WavedataTableEditor::sIllegalValue)
384 for (
int iBit = 0; iBit < it->nets.size(); ++iBit)
386 int netVal = tableVal & mask;
387 if (netVal != valArray[sofIndex+iBit])
392 valArray[sofIndex + iBit] = netVal;
397 sofIndex += it->nets.size();
406 void WavedataTableEditor::setDisplayHexValues(
bool hex)
408 if (hex == mDisplayHexValues)
return;
410 mDisableCellParser =
true;
411 mDisplayHexValues = hex;
413 for (
int icol = 1; icol < columnCount(); icol++)
414 for (
int irow = 0; irow < rowCount(); irow++)
418 int val = intCellValue(irow,icol);
420 if (mDisplayHexValues && val > 9) txt.
prepend(
"0x");
424 mDisableCellParser =
false;
const std::string & get_name() const
void writeTimeValue(uint64_t t, int32_t val)
Write single data tuple to disk.
The SaleaeParser class is an engine which allows to parse any number of SALEAE files into a sequence ...
bool register_callback(const std::string &name, uint32_t id, std::function< void(void *, uint64_t, int)> callback, void *obj)
Registers callback which gets executed upon next_event()
The SaleaeWriter class is a helper class which provides utility methods when importing data to SALEAE...
SaleaeOutputFile * add_or_replace_waveform(const std::string &name, uint32_t id)
Create new empty output file. Will delete existing binary file if directory links already a data file...
WavedataTableEditor(QWidget *parent=nullptr)
void loadWaveData(const QString &saleaDirectoryFile)
void setup(const std::vector< NetlistSimulatorController::InputColumnHeader > &inpColHeads, bool omitClock)
QChar toUpper() const const
ushort unicode() const const
QString absoluteFilePath(const QString &fileName) const const
void prepend(const T &value)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
const QChar at(int position) const const
QString fromStdString(const std::string &str)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString mid(int position, int n) const const
QString number(int n, int base)
QString & prepend(QChar ch)
int toInt(bool *ok, int base) const const
qlonglong toLongLong(bool *ok, int base) const const
std::string toStdString() const const
qulonglong toULongLong(bool *ok, int base) const const
void setText(const QString &text)
void setTextAlignment(int alignment)
QString text() const const