HAL  v4.5.0-133-g64838ea8d
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
logic_evaluator_pingroup.cpp
Go to the documentation of this file.
2 #include <QHBoxLayout>
3 #include <QVBoxLayout>
4 #include <QtGlobal>
6 #include "hal_core/netlist/net.h"
7 
8 namespace hal {
9 
11  : QSpinBox(parent)
12  {;}
13 
15  {
16  return text.toInt(nullptr,16);
17  }
18 
20  {
21  return QString::number(val,16).toUpper();
22  }
23 
25  {
26  Q_UNUSED(pos);
27  if (input.isEmpty())
29  bool ok;
30  int val = input.toInt(&ok,16);
31  if (ok && 0 <= val && val <= maximum())
33  return QValidator::Invalid;
34  }
35 
36 //-------------------------------------------------------------------
37 
39  : QWidget(parent), mLabel(nullptr), mSpinBox(nullptr)
40  {
41  QVBoxLayout* layout = new QVBoxLayout(this);
43  if (nbits > 1)
44  {
45  mSpinBox = new LogicEvaluatorHexSpinbox(this);
46  mSpinBox->setMinimum(0);
47  mSpinBox->setMaximum((1 << nbits)-1);
49  connect(mSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &LogicEvaluatorValue::handleSpinBoxValueChanged);
50  layout->addWidget(mSpinBox);
51  }
52  else
53  {
54  mLabel = new QLabel(this);
55  layout->addWidget(mLabel);
56  }
57  }
58 
59  void LogicEvaluatorValue::handleSpinBoxValueChanged(int val)
60  {
61  Q_EMIT valueChanged(val);
62  }
63 
65  {
66  if (mSpinBox)
67  return mSpinBox->value();
68  return mLabel->text().toInt();
69  }
70 
72  {
73  if (mSpinBox)
74  mSpinBox->setValue(val);
75  else
76  mLabel->setText(QString::number(val,16));
77  }
78 
79  //-------------------------------------------------------------------
80 
82  : QCheckBox(QString::fromStdString(n->get_name()),parent), mNet(n)
83  {;}
84 
86  {
87  return QPair<const Net*,BooleanFunction::Value>(mNet, isChecked()?BooleanFunction::Value::ONE:BooleanFunction::Value::ZERO);
88  }
89 
91  {
92  if (n != mNet) return;
93  setChecked(val==BooleanFunction::Value::ONE);
94  }
95  //-------------------------------------------------------------------
96 
97  LogicEvaluatorPingroup::LogicEvaluatorPingroup(const std::vector<const Net *> &nets, bool outp, const QString& grpName, QWidget* parent)
98  : QFrame(parent), mOutput(outp)
99  {
100  constructor(nets,grpName);
101  }
102 
104  : QFrame(parent), mOutput(outp)
105  {
106  std::vector<const Net*> nets;
107  nets.push_back(net);
108  constructor(nets);
109  }
110 
111  void LogicEvaluatorPingroup::constructor(const std::vector<const Net *> &nets, const QString &grpName)
112  {
113  int nbits = nets.size();
114  QHBoxLayout* topLayout = new QHBoxLayout(this);
115  topLayout->setAlignment(Qt::AlignTop);
116  topLayout->setContentsMargins(mOutput?0:8,4,mOutput?8:0,4);
117  QVBoxLayout* valLayout = new QVBoxLayout;
118  valLayout->setSpacing(4);
119  QtCompat::setMarginWidth(valLayout,0);
120 
121  if (!grpName.isEmpty())
122  {
123  QLabel* lab = new QLabel(grpName, this);
124  valLayout->addWidget(lab,0,Qt::AlignBottom|Qt::AlignHCenter);
125  }
126  mGroupValue = new LogicEvaluatorValue(mOutput?0:nbits, this);
127  connect(mGroupValue, &LogicEvaluatorValue::valueChanged, this, &LogicEvaluatorPingroup::handleGroupValueChanged);
128  valLayout->addWidget(mGroupValue,0, Qt::AlignTop|Qt::AlignHCenter);
129 
130  QVBoxLayout* pinLayout = new QVBoxLayout;
131  for (const Net* net : nets)
132  {
133  LogicEvaluatorCheckBox* lecb = new LogicEvaluatorCheckBox(net, this);
134  connect(lecb, &QCheckBox::stateChanged, this, &LogicEvaluatorPingroup::handleCheckStateChanged);
135  if (mOutput)
136  lecb->setDisabled(true);
137  else
138  {
139  lecb->setLayoutDirection(Qt::RightToLeft);
140  }
141  mPinList.prepend(lecb);
142  pinLayout->addWidget(lecb);
143  }
144 
145  if (mOutput)
146  {
147  topLayout->addLayout(pinLayout);
148  topLayout->addSpacing(20);
149  topLayout->addLayout(valLayout);
150  }
151  else
152  {
153  topLayout->addLayout(valLayout);
154  topLayout->addSpacing(20);
155  topLayout->addLayout(pinLayout);
156  }
157  mGroupValue->setValue(0);
158  }
159 
160  void LogicEvaluatorPingroup::handleCheckStateChanged(int state)
161  {
162  Q_UNUSED(state);
163 
164  int mask = 1 << (mPinList.size()-1);
165  int val = 0;
166  for (LogicEvaluatorCheckBox* cb : mPinList)
167  {
168  if (cb->isChecked()) val |= mask;
169  mask >>= 1;
170  }
171  mGroupValue->setValue(val);
172  if (mGroupValue->isLabel())
174  }
175 
176  void LogicEvaluatorPingroup::handleGroupValueChanged(int val)
177  {
178  int mask = 1 << (mPinList.size()-1);
179  for (LogicEvaluatorCheckBox* cb : mPinList)
180  {
181  cb->setChecked(val&mask);
182  mask >>= 1;
183  }
185  }
186 
188  {
189  return mPinList.at(index)->getValue();
190  }
191 
193  {
194  for (LogicEvaluatorCheckBox* cb : mPinList)
195  cb->setValue(n,val);
196  }
197 }
Value
represents the type of the node
void setValue(const Net *n, BooleanFunction::Value val)
LogicEvaluatorCheckBox(const Net *n, QWidget *parent=nullptr)
QPair< const Net *, BooleanFunction::Value > getValue() const
LogicEvaluatorHexSpinbox(QWidget *parent=nullptr)
virtual QString textFromValue(int val) const override
int valueFromText(const QString &text) const override
QValidator::State validate(QString &input, int &pos) const override
LogicEvaluatorPingroup(const std::vector< const Net * > &nets, bool outp, const QString &grpName, QWidget *parent=nullptr)
void setValue(const Net *n, BooleanFunction::Value val)
QPair< const Net *, BooleanFunction::Value > getValue(int index) const
void valueChanged(int val)
LogicEvaluatorValue(int nbits, QWidget *parent=nullptr)
Definition: net.h:58
void setMarginWidth(QLayout *layout, int marginWidth)
Definition: defines.h:45
Net * net
bool isChecked() const const
void addLayout(QLayout *layout, int stretch)
void addSpacing(int size)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setSpacing(int spacing)
void stateChanged(int state)
void addWidget(QWidget *w)
bool setAlignment(QWidget *w, Qt::Alignment alignment)
void setContentsMargins(int left, int top, int right, int bottom)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setMinimum(int min)
void valueChanged(int i)
bool isEmpty() const const
QString number(int n, int base)
QString toUpper() const const
AlignTop
RightToLeft
QLayout * layout() const const
QRegion mask() const const
void setSizePolicy(QSizePolicy)