HAL
flipflop_wizardpage.cpp
Go to the documentation of this file.
2 
3 #include <QDebug>
6 
7 namespace hal
8 {
10  {
11  setTitle("Flip Flop");
12  setSubTitle("Enter parameters for flip flop component");
13  mLayout = new QGridLayout(this);
14  mTabWidget = new QTabWidget(this);
15 
16  mClock = new BooleanFunctionEdit(mLegVars, this);
17  mNextState = new BooleanFunctionEdit(mLegVars, this);
18  mAReset = new BooleanFunctionEdit(mLegVars, this);
19  mASet = new BooleanFunctionEdit(mLegVars, this);
20  mIntState = new QLineEdit(this);
21  mNegIntState = new QLineEdit(this);
22 
23  mLabClock = new QLabel("Clock: ", this);
24  mLabNextState = new QLabel("Next state: ", this);
25  mLabAReset = new QLabel("Asynchronous reset: ", this);
26  mLabASet = new QLabel("Asynchronous set: ", this);
27  mLabIntState = new QLabel("Set+Reset -> internal state: ", this);
28  mLabNegIntState = new QLabel("Set+Reset -> neg. int. state:", this);
29 
30  mLayout->addWidget(mLabClock, 0, 0);
31  mLayout->addWidget(mClock, 0, 1);
32  mLayout->addWidget(mLabNextState, 1, 0);
33  mLayout->addWidget(mNextState, 1, 1);
34  mLayout->addWidget(mLabAReset, 2, 0);
35  mLayout->addWidget(mAReset, 2, 1);
36  mLayout->addWidget(mLabASet, 3, 0);
37  mLayout->addWidget(mASet, 3, 1);
38  mLayout->addWidget(mLabIntState, 4, 0);
39  mLayout->addWidget(mIntState, 4, 1);
40  mLayout->addWidget(mLabNegIntState, 5, 0);
41  mLayout->addWidget(mNegIntState, 5, 1);
42 
43  //TODO:
44  //mTabWidget->addTab(mStateTableTab, "State Table");
45 
46  setLayout(mLayout);
47 
54  }
55 
57  {
58  mWizard = static_cast<GateLibraryWizard*>(wizard());
59  QList<PinItem*> inputPins = mWizard->mPinModel->getInputPins();
60 
61  mLegVars.clear();
62  for (PinItem* pi : inputPins)
63  mLegVars.insert(pi->getName().toStdString());
64 
65  mClock->setLegalVariables(mLegVars);
66  mNextState->setLegalVariables(mLegVars);
67  mAReset->setLegalVariables(mLegVars);
68  mASet->setLegalVariables(mLegVars);
69 
70  if(mWizard->statePage->mNegStateIdentifier->text().isEmpty())
71  {
72  mNegIntState->clear();
73  mNegIntState->setDisabled(true);
74  }
75  else mNegIntState->setDisabled(false);
76 
77  bool clock = false;
78  bool set = false;
79  bool reset = false;
80 
81  QList<PinItem*> pingroups = mWizard->getPingroups();
82  for (PinItem* pg : pingroups) {
83  for(BaseTreeItem* it: pg->getChildren())
84  {
85  PinItem* p = static_cast<PinItem*>(it);
86  if(!clock && p->getPinType() == PinType::clock) {
87  mClock->setText(p->getName()); //name of first pin with type clock
88  clock = true;
89  }
90  if(!reset && p->getPinType() == PinType::reset) {
91  mAReset->setText(p->getName()); //name of first pin with type reset
92  reset = true;
93  }
94  if(!set && p->getPinType() == PinType::set) {
95  mASet->setText(p->getName()); //name of first pin with type set
96  set = true;
97  }
98  }
99  }
100 
101  if(!clock) mClock->clear();
102  if(!reset) mAReset->clear();
103  if(!set) mASet->clear();
104 
105  if(mASet->text().isEmpty() || mAReset->text().isEmpty())
106  {
107  mIntState->clear();
108  mNegIntState->clear();
109  mIntState->setDisabled(true);
110  mNegIntState->setDisabled(true);
111  }
112  else
113  {
114  mIntState->setDisabled(false);
115  mNegIntState->setDisabled(false);
116  }
117 
119 
120  mWizard->mEditMode = true;
121  }
122 
124  Q_UNUSED(text);
125  mWizard = static_cast<GateLibraryWizard*>(wizard());
126 
127  if(mASet->text().isEmpty() || mAReset->text().isEmpty())
128  {
129  mIntState->clear();
130  mNegIntState->clear();
131  mIntState->setDisabled(true);
132  mNegIntState->setDisabled(true);
133  }
134  else
135  {
136  mIntState->setDisabled(false);
137  mNegIntState->setDisabled(false);
138  }
140 
141  if(mWizard->mEditMode) Q_EMIT hasChanged();
142  }
143 
145  if (gate != nullptr && gate->has_component_of_type(GateTypeComponent::ComponentType::ff))
146  {
147  auto ff = gate->get_component_as<FFComponent>([](const GateTypeComponent* c) { return FFComponent::is_class_of(c); });
148 
149  if (ff != nullptr)
150  {
151  mClock->setText(QString::fromStdString(ff->get_clock_function().to_string()));
152  mNextState->setText(QString::fromStdString(ff->get_next_state_function().to_string()));
153 
154  if (ff->get_async_reset_function().is_empty()) mAReset->setText("N/A");
155  else {
156  mAReset->setDisabled(false);
157  mAReset->setText(QString::fromStdString(ff->get_async_reset_function().to_string()));
158  }
159 
160  if (ff->get_async_set_function().is_empty()) mASet->setText("N/A");
161  else {
162  mASet->setDisabled(false);
163  mASet->setText(QString::fromStdString(ff->get_async_set_function().to_string()));
164  }
165 
166  auto [stateBeh,negStateBeh] = ff->get_async_set_reset_behavior();
167  if (stateBeh == AsyncSetResetBehavior::undef) mIntState->setText("undefined");
168  else mIntState->setText(QString::fromStdString(enum_to_string<AsyncSetResetBehavior>(stateBeh)));
169 
170  if (negStateBeh == AsyncSetResetBehavior::undef) mNegIntState->setText("undefined");
171  else mNegIntState->setText(QString::fromStdString(enum_to_string<AsyncSetResetBehavior>(negStateBeh)));
172  }
173  }
174  }
175 
176 
178  if(mClock->text().isEmpty() || mNextState->text().isEmpty()) return false;
179  if(!mClock->isValid() || !mNextState->isValid() || mAReset->state() == "Invalid" || mASet->state() == "Invalid") return false;
180  if(!mASet->text().isEmpty() && !mAReset->text().isEmpty())
181  {
182  if(mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::H) &&
183  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::L) &&
184  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::N) &&
185  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::T) &&
186  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::X))
187  return false;
188  if(mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::H) &&
189  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::L) &&
190  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::N) &&
191  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::T) &&
192  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::X))
193  return false;
194  }
195  mWizard->mEditMode = false;
196  return true;
197  }
198 }
(Future) Base class for all tree models related to the details widget.
virtual QList< BaseTreeItem * > getChildren() const
void setLegalVariables(std::set< std::string > &legalVar)
static bool is_class_of(const GateTypeComponent *component)
bool isComplete() const override
FlipFlopWizardPage(QWidget *parent=nullptr)
void handleTextChanged(const QString &txt)
void setData(GateType *gate)
QList< PinItem * > getPingroups()
bool has_component_of_type(const GateTypeComponent::ComponentType type) const
Definition: gate_type.cpp:54
T * get_component_as(const std::function< bool(const GateTypeComponent *)> &filter=nullptr) const
Definition: gate_type.h:89
An item in the PinModel.
Definition: pin_item.h:48
QString getName() const
Definition: pin_item.cpp:81
PinType getPinType() const
Definition: pin_item.cpp:86
QList< PinItem * > getInputPins()
Definition: pin_model.cpp:729
std::string enum_to_string(T e)
Definition: enums.h:52
include set(SRCROOT ${CMAKE_CURRENT_SOURCE_DIR}/src) set(UIROOT $
Definition: CMakeLists.txt:45
void addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment)
void clear()
void textChanged(const QString &text)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString fromStdString(const std::string &str)
void setDisabled(bool disable)
void setLayout(QLayout *layout)
void completeChanged()
void setSubTitle(const QString &subTitle)
void setTitle(const QString &title)
QWizard * wizard() const const