25 mDisclaimer =
new QLabel(
this);
35 void GateLibraryTabTruthTable::setTableSize()
44 for (
const std::string& inputPinName : inputs)
46 for (
const std::string& outputPinName : outputs)
51 bool GateLibraryTabTruthTable::updateFlipFlop()
66 if (!scomp)
return false;
68 if (!ffcomp)
return false;
71 for (
const std::string& var : bf.get_variable_names())
74 auto resNextState = ffcomp->get_next_state_function().compute_truth_table();
76 for (
const std::string& nsi : ffcomp->get_next_state_function().get_variable_names())
79 if (!resNextState.is_ok() || resNextState.get().size() != 1)
return false;
86 switch (pin->get_type()) {
88 icolClock = columnNumber;
91 icolSet = columnNumber;
95 icolReset = columnNumber;
101 inputColHash[pinName] = columnNumber++;
104 if (rsRows == 2) rsRows = 3;
109 for (
int i=0; i<2; i++)
112 : scomp->get_state_identifier());
117 for (
const QString& qx : tempQ)
119 header <<
"last\n" + qx;
120 stateHash[qx] =
QPair<int,int>(columnNumber,columnNumber+tempQ.size());
121 inputColHash[qx] = columnNumber++;
123 for (
const QString& qx : tempQ)
125 header <<
"next\n" + qx;
129 Q_ASSERT(!stateHash.
isEmpty());
136 outputColHash[pinName] = columnNumber++;
140 auto tabNextState = resNextState.get().at(0);
141 mTableWidget->
setRowCount(tabNextState.size()+2+rsRows);
148 for (
int icol = 0; icol < inputColHash.
size(); icol++)
152 else if (icol == icolReset)
161 for (
int icol : outputColHash.
values())
169 for (
int icol = 0; icol < inputColHash.
size(); icol++)
173 else if (icol == icolReset)
182 for (
int icol : outputColHash.
values())
187 if (icolSet >= 0 && icolReset >= 0)
189 for (
int icol = 0; icol < inputColHash.
size(); icol++)
193 else if (icol == icolReset)
202 for (
int icol : outputColHash.
values())
210 for (
int nsiCol = 0; nsiCol < nextStateInputs.
size(); nsiCol++)
212 int icol = inputColHash.
value(nextStateInputs.
at(nsiCol),-1);
214 QString cellVal(irow & (1<<nsiCol) ?
"H" :
"L");
217 setCellValue(irow,stateHash.
begin()->second,bfVal);
224 for (
int icol : outputColHash.
values())
225 setCellValue(irow,icol,bfVal);
229 for (
int ihold = 0; ihold < 2; ihold++)
231 for (
int nsiCol = 0; nsiCol < nextStateInputs.
size(); nsiCol++)
233 int icol = inputColHash.
value(nextStateInputs.
at(nsiCol),-1);
244 QString qx = ihold ?
"H" :
"L";
247 for (
int icol : outputColHash.
values())
255 void GateLibraryTabTruthTable::updateLookupTable()
258 mLutInit->
update(mGateType);
269 mTableWidget->
show();
278 if (updateFlipFlop())
280 mTableWidget->
show();
288 if (getColumnNumber()-1 > 8)
290 mTableWidget->
hide();
291 mDisclaimer->
setText(
QString(
"Cannot calculate truth table\nfor gate with %1 input pins\nand %2 output pins")
298 bool undefinedResult =
false;
306 for (uint irow = 0; irow < truthTable.size(); irow++)
311 u8 inputBit =
u8((irow >> icol) & 1);
313 mTableWidget->
setItem(irow, icol, item);
319 if (!setCellValue(irow,icol,truthTable[irow]))
320 undefinedResult =
true;
327 mTableWidget->
hide();
332 mTableWidget->
show();
338 mDisclaimer->
setText(
"No gate type selected");
340 mTableWidget->
hide();
347 if (bfval == BooleanFunction::Value::ZERO)
350 mTableWidget->
setItem(irow, icol, item);
352 else if (bfval == BooleanFunction::Value::ONE)
355 mTableWidget->
setItem(irow, icol, item);
357 else if (bfval == BooleanFunction::Value::Z)
360 mTableWidget->
setItem(irow, icol, item);
365 mTableWidget->
setItem(irow, icol, item);
372 void GateLibraryTabTruthTable::handleLutInitValueChanged(
u64 initValue)
376 for (
int irow = 0; irow < mTableWidget->
rowCount(); irow++)
381 u8 inputBit =
u8((irow >> icol) & 1);
383 mTableWidget->
setItem(irow, icol, item);
391 if (initValue &
mask)
394 mTableWidget->
setItem(irow, icol, item);
399 mTableWidget->
setItem(irow, icol, item);
404 mTableWidget->
show();
407 int GateLibraryTabTruthTable::getRowNumber()
const
412 int GateLibraryTabTruthTable::getColumnNumber()
const
430 void GatelibraryLutInit::handleTextChanged(
const QString& txt)
Result< std::vector< std::vector< Value > > > compute_truth_table(const std::vector< std::string > &ordered_variables={}, bool remove_unknown_variables=false) const
Value
represents the type of the node
static bool is_class_of(const GateTypeComponent *component)
GateLibraryTabTruthTable(QWidget *parent=nullptr)
std::vector< std::string > get_input_pin_names() const
std::vector< GatePin * > get_output_pins() const
const std::string & get_name() const
std::vector< std::string > get_output_pin_names() const
bool has_component_of_type(const GateTypeComponent::ComponentType type) const
std::vector< GatePin * > get_input_pins() const
T * get_component_as(const std::function< bool(const GateTypeComponent *)> &filter=nullptr) const
BooleanFunction get_boolean_function(const std::string &name) const
const std::unordered_map< std::string, BooleanFunction > & get_boolean_functions() const
GatelibraryLutInit(QWidget *parent=nullptr)
void initValueChanged(u64 initValue)
void update(GateType *gt) override
static bool is_class_of(const GateTypeComponent *component)
static bool is_class_of(const GateTypeComponent *component)
bool isEmpty() const const
const T value(const Key &key) const const
QList< T > values() const const
void setAlignment(Qt::Alignment)
void setText(const QString &)
void setText(const QString &)
void textChanged(const QString &text)
const T & at(int i) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool contains(const T &value) const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromStdString(const std::string &str)
qulonglong toULongLong(bool *ok, int base) const const