12 :
QTableWidget(parent), mMaxTime(0), mDisableCellParser(false), mDisplayHexValues(true), mCurrentTime(0), mCurrentRow(0)
19 if (omitClock && ich.is_clock)
continue;
20 mInputColumnHeader.append(ich);
26 int n = mInputColumnHeader.size()+1;
27 for (
int i=0; i<n; i++) setValueCell(0,i,0);
34 void WavedataTableEditor::setupHeader()
40 if (ich.nets.size() > 1) colName +=
QString(
"[%1:0]").
arg(ich.nets.size()-1);
41 headerLabel << colName;
43 int n = mInputColumnHeader.
size()+1;
49 void WavedataTableEditor::setValueCell(
int irow,
int icol,
int val)
60 mDisableCellParser =
true;
67 mCurrentValue =
new int[ncols];
68 memset(mCurrentValue,0,ncols*
sizeof(
int));
70 for (
int icol = 0; icol < ncols; icol++)
74 int nBits = ich.
nets.size();
76 for (
int i=0; i<nBits; i++)
83 if (t != mCurrentTime)
86 if (mCurrentRow+1 >= rowCount()) setRowCount(mCurrentRow+2);
87 QTableWidgetItem* tItem = new QTableWidgetItem(QString::number(t));
88 tItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
89 setItem(mCurrentRow,0,tItem);
91 for (int i=0; i<ncols; i++)
92 setValueCell(mCurrentRow-1, i+1, mCurrentValue[i]);
96 mCurrentValue[icol] |=
mask;
98 mCurrentValue[icol] &= (~
mask);
109 setItem(0,0,zeroItem);
111 while (parser.next_event()) {;}
113 for (
int i=0; i<ncols; i++)
114 setValueCell(mCurrentRow, i+1, mCurrentValue[i]);
116 delete [] mCurrentValue;
118 mDisableCellParser =
false;
123 if (mDisableCellParser)
return;
125 mDisableCellParser =
true;
126 int cur = rowCount() - 1;
127 if (cur > 0 && !changedItem->
column() && changedItem->
row() == cur)
130 for (
int icol=1; icol < columnCount(); icol++)
134 if ((!testItem || testItem->
text().
isEmpty()) && lastItem)
138 setItem(cur, icol, twi);
142 if (!changedItem->
column())
145 int irow = changedItem->
row();
146 if (cur > 0 && irow == cur)
149 for (
int icol=1; icol < columnCount(); icol++)
153 if ((!testItem || testItem->
text().
isEmpty()) && lastItem)
157 setItem(cur,icol, twi);
162 bool numericOk =
false;
164 qlonglong prevVal = irow ? item(irow-1,0)->text().toLongLong() : 0;
165 qlonglong nextVal = 0;
166 if (rowCount() > irow+1 && item(irow+1,0))
168 qlonglong tempNextVal = item(irow+1,0)->text().toLongLong(&numericOk);
169 if (numericOk && tempNextVal >= prevVal+2) nextVal = tempNextVal;
174 if (!numericOk || thisVal <= prevVal || thisVal >= nextVal)
180 if (!numericOk || thisVal <= prevVal)
187 int val = intCellValue(changedItem->
row(),changedItem->
column());
188 if (val == sIllegalValue)
192 if (val > 9 && mDisplayHexValues)
199 mDisableCellParser =
false;
202 int WavedataTableEditor::validLines()
const
205 qlonglong tlast = -1;
206 bool numericOk =
false;
207 for (
int irow = 0; irow < rowCount(); irow++)
210 if (!timeCell)
continue;
212 if (!numericOk)
continue;
213 if (t <= tlast)
continue;
214 bool incomplete =
false;
215 for (
int icol=1; icol<columnCount(); icol++)
224 if (incomplete)
continue;
231 int WavedataTableEditor::intCellValue(
int irow,
int icol)
const
234 int nBits = mInputColumnHeader.
at(icol-1).nets.size();
235 int upperLimit = 1 << nBits;
238 txt = item(irow,icol)->text();
240 return sIllegalValue;
242 bool numberOk =
true;
256 tempValue = txt.
toInt(&numberOk);
257 if (!numberOk || tempValue >= upperLimit)
return sIllegalValue;
263 if (txt.
at(0) ==
'"')
273 if (txt.
at(0) ==
'0')
278 tempValue = txt.
mid(2).
toInt(&numberOk, 16);
281 tempValue = txt.
mid(2).
toInt(&numberOk, 8);
284 tempValue = txt.
mid(2).
toInt(&numberOk, 2);
287 tempValue = txt.
toInt(&numberOk, 10);
292 tempValue = txt.
toInt(&numberOk, 10);
296 if (apos + 2 >= txt.
size())
297 return sIllegalValue;
301 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 16);
304 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 8);
307 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 2);
310 tempValue = txt.
mid(apos+2).
toInt(&numberOk, 10);
313 return sIllegalValue;
318 if (!numberOk || tempValue >= upperLimit)
319 return sIllegalValue;
324 void WavedataTableEditor::generateSimulationInput(
const QString& workdir)
334 for (
auto it = mInputColumnHeader.constBegin(); it != mInputColumnHeader.constEnd(); ++it)
335 maxIndex += it->nets.size();
340 valArray =
new int[maxIndex];
342 for (
auto it = mInputColumnHeader.constBegin(); it != mInputColumnHeader.constEnd(); ++it)
344 int tableVal = intCellValue(0,iTableCol);
345 if (tableVal == WavedataTableEditor::sIllegalValue)
349 for (
const Net* n : it->nets)
352 int netVal = tableVal & mask;
354 sofArray[sofIndex + iBit] = sof;
355 valArray[sofIndex + iBit] = netVal;
360 sofIndex += it->nets.size();
363 for (
int irow = 1; irow < rowCount(); irow++)
366 timeCell = item(irow,0);
367 if (!timeCell)
continue;
369 if (tval <= mMaxTime)
continue;
372 for (
auto it = mInputColumnHeader.constBegin(); it != mInputColumnHeader.constEnd(); ++it)
374 int tableVal = intCellValue(irow,iTableCol);
375 if (tableVal == WavedataTableEditor::sIllegalValue)
379 for (
int iBit = 0; iBit < it->nets.size(); ++iBit)
381 int netVal = tableVal & mask;
382 if (netVal != valArray[sofIndex+iBit])
387 valArray[sofIndex + iBit] = netVal;
392 sofIndex += it->nets.size();
401 void WavedataTableEditor::setDisplayHexValues(
bool hex)
403 if (hex == mDisplayHexValues)
return;
405 mDisableCellParser =
true;
406 mDisplayHexValues = hex;
408 for (
int icol = 1; icol < columnCount(); icol++)
409 for (
int irow = 0; irow < rowCount(); irow++)
413 int val = intCellValue(irow,icol);
415 if (mDisplayHexValues && val > 9) txt.
prepend(
"0x");
419 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)
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