HAL  v4.5.0-83-g30c8f0afc
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>
5 #include "hal_core/netlist/net.h"
6 
7 namespace hal {
8 
10  : QSpinBox(parent)
11  {;}
12 
14  {
15  return text.toInt(nullptr,16);
16  }
17 
19  {
20  return QString::number(val,16).toUpper();
21  }
22 
24  {
25  Q_UNUSED(pos);
26  if (input.isEmpty())
28  bool ok;
29  int val = input.toInt(&ok,16);
30  if (ok && 0 <= val && val <= maximum())
32  return QValidator::Invalid;
33  }
34 
35 //-------------------------------------------------------------------
36 
38  : QWidget(parent), mLabel(nullptr), mSpinBox(nullptr)
39  {
40  QVBoxLayout* layout = new QVBoxLayout(this);
41  layout->setMargin(0);
42  if (nbits > 1)
43  {
44  mSpinBox = new LogicEvaluatorHexSpinbox(this);
45  mSpinBox->setMinimum(0);
46  mSpinBox->setMaximum((1 << nbits)-1);
48  connect(mSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &LogicEvaluatorValue::handleSpinBoxValueChanged);
49  layout->addWidget(mSpinBox);
50  }
51  else
52  {
53  mLabel = new QLabel(this);
54  layout->addWidget(mLabel);
55  }
56  }
57 
58  void LogicEvaluatorValue::handleSpinBoxValueChanged(int val)
59  {
60  Q_EMIT valueChanged(val);
61  }
62 
64  {
65  if (mSpinBox)
66  return mSpinBox->value();
67  return mLabel->text().toInt();
68  }
69 
71  {
72  if (mSpinBox)
73  mSpinBox->setValue(val);
74  else
75  mLabel->setText(QString::number(val,16));
76  }
77 
78  //-------------------------------------------------------------------
79 
81  : QCheckBox(QString::fromStdString(n->get_name()),parent), mNet(n)
82  {;}
83 
85  {
86  return QPair<const Net*,BooleanFunction::Value>(mNet, isChecked()?BooleanFunction::Value::ONE:BooleanFunction::Value::ZERO);
87  }
88 
90  {
91  if (n != mNet) return;
92  setChecked(val==BooleanFunction::Value::ONE);
93  }
94  //-------------------------------------------------------------------
95 
96  LogicEvaluatorPingroup::LogicEvaluatorPingroup(const std::vector<const Net *> &nets, bool outp, const QString& grpName, QWidget* parent)
97  : QFrame(parent), mOutput(outp)
98  {
99  constructor(nets,grpName);
100  }
101 
103  : QFrame(parent), mOutput(outp)
104  {
105  std::vector<const Net*> nets;
106  nets.push_back(net);
107  constructor(nets);
108  }
109 
110  void LogicEvaluatorPingroup::constructor(const std::vector<const Net *> &nets, const QString &grpName)
111  {
112  int nbits = nets.size();
113  QHBoxLayout* topLayout = new QHBoxLayout(this);
114  topLayout->setAlignment(Qt::AlignTop);
115  topLayout->setContentsMargins(mOutput?0:8,4,mOutput?8:0,4);
116  QVBoxLayout* valLayout = new QVBoxLayout;
117  valLayout->setSpacing(4);
118  valLayout->setMargin(0);
119 
120  if (!grpName.isEmpty())
121  {
122  QLabel* lab = new QLabel(grpName, this);
123  valLayout->addWidget(lab,0,Qt::AlignBottom|Qt::AlignHCenter);
124  }
125  mGroupValue = new LogicEvaluatorValue(mOutput?0:nbits, this);
126  connect(mGroupValue, &LogicEvaluatorValue::valueChanged, this, &LogicEvaluatorPingroup::handleGroupValueChanged);
127  valLayout->addWidget(mGroupValue,0, Qt::AlignTop|Qt::AlignHCenter);
128 
129  QVBoxLayout* pinLayout = new QVBoxLayout;
130  for (const Net* net : nets)
131  {
132  LogicEvaluatorCheckBox* lecb = new LogicEvaluatorCheckBox(net, this);
133  connect(lecb, &QCheckBox::stateChanged, this, &LogicEvaluatorPingroup::handleCheckStateChanged);
134  if (mOutput)
135  lecb->setDisabled(true);
136  else
137  {
138  lecb->setLayoutDirection(Qt::RightToLeft);
139  }
140  mPinList.prepend(lecb);
141  pinLayout->addWidget(lecb);
142  }
143 
144  if (mOutput)
145  {
146  topLayout->addLayout(pinLayout);
147  topLayout->addSpacing(20);
148  topLayout->addLayout(valLayout);
149  }
150  else
151  {
152  topLayout->addLayout(valLayout);
153  topLayout->addSpacing(20);
154  topLayout->addLayout(pinLayout);
155  }
156  mGroupValue->setValue(0);
157  }
158 
159  void LogicEvaluatorPingroup::handleCheckStateChanged(int state)
160  {
161  Q_UNUSED(state);
162 
163  int mask = 1 << (mPinList.size()-1);
164  int val = 0;
165  for (LogicEvaluatorCheckBox* cb : mPinList)
166  {
167  if (cb->isChecked()) val |= mask;
168  mask >>= 1;
169  }
170  mGroupValue->setValue(val);
171  if (mGroupValue->isLabel())
173  }
174 
175  void LogicEvaluatorPingroup::handleGroupValueChanged(int val)
176  {
177  int mask = 1 << (mPinList.size()-1);
178  for (LogicEvaluatorCheckBox* cb : mPinList)
179  {
180  cb->setChecked(val&mask);
181  mask >>= 1;
182  }
184  }
185 
187  {
188  return mPinList.at(index)->getValue();
189  }
190 
192  {
193  for (LogicEvaluatorCheckBox* cb : mPinList)
194  cb->setValue(n,val);
195  }
196 }
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
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 setMargin(int margin)
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)