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  mLegVars.insert(mWizard->statePage->mStateIdentifier->text().toStdString());
66  mLegVars.insert(mWizard->statePage->mNegStateIdentifier->text().toStdString());
67  mClock->setLegalVariables(mLegVars);
68  mNextState->setLegalVariables(mLegVars);
69  mAReset->setLegalVariables(mLegVars);
70  mASet->setLegalVariables(mLegVars);
71 
72  if(mWizard->statePage->mNegStateIdentifier->text().isEmpty())
73  {
74  mNegIntState->clear();
75  mNegIntState->setDisabled(true);
76  }
77  else mNegIntState->setDisabled(false);
78 
79  bool clock = false;
80  bool set = false;
81  bool reset = false;
82 
83  QList<PinItem*> pingroups = mWizard->getPingroups();
84  for (PinItem* pg : pingroups) {
85  for(BaseTreeItem* it: pg->getChildren())
86  {
87  PinItem* p = static_cast<PinItem*>(it);
88  if(!clock && p->getPinType() == PinType::clock) {
89  mClock->setText(p->getName()); //name of first pin with type clock
90  clock = true;
91  }
92  if(!reset && p->getPinType() == PinType::reset) {
93  mAReset->setText(p->getName()); //name of first pin with type reset
94  reset = true;
95  }
96  if(!set && p->getPinType() == PinType::set) {
97  mASet->setText(p->getName()); //name of first pin with type set
98  set = true;
99  }
100  }
101  }
102 
103  if(!clock) mClock->clear();
104  if(!reset) mAReset->clear();
105  if(!set) mASet->clear();
106 
107  if(mASet->text().isEmpty() || mAReset->text().isEmpty())
108  {
109  mIntState->clear();
110  mNegIntState->clear();
111  mIntState->setDisabled(true);
112  mNegIntState->setDisabled(true);
113  }
114  else
115  {
116  mIntState->setDisabled(false);
117  mNegIntState->setDisabled(false);
118  }
119 
121 
122  mWizard->mEditMode = true;
123  }
124 
126  Q_UNUSED(text);
127  mWizard = static_cast<GateLibraryWizard*>(wizard());
128 
129  if(mASet->text().isEmpty() || mAReset->text().isEmpty())
130  {
131  mIntState->clear();
132  mNegIntState->clear();
133  mIntState->setDisabled(true);
134  mNegIntState->setDisabled(true);
135  }
136  else
137  {
138  mIntState->setDisabled(false);
139  mNegIntState->setDisabled(false);
140  }
142 
143  if(mWizard->mEditMode) Q_EMIT hasChanged();
144  }
145 
147  if (gate != nullptr && gate->has_component_of_type(GateTypeComponent::ComponentType::ff))
148  {
149  auto ff = gate->get_component_as<FFComponent>([](const GateTypeComponent* c) { return FFComponent::is_class_of(c); });
150 
151  if (ff != nullptr)
152  {
153  mClock->setText(QString::fromStdString(ff->get_clock_function().to_string()));
154  mNextState->setText(QString::fromStdString(ff->get_next_state_function().to_string()));
155 
156  if (ff->get_async_reset_function().is_empty()) mAReset->setText("N/A");
157  else {
158  mAReset->setDisabled(false);
159  mAReset->setText(QString::fromStdString(ff->get_async_reset_function().to_string()));
160  }
161 
162  if (ff->get_async_set_function().is_empty()) mASet->setText("N/A");
163  else {
164  mASet->setDisabled(false);
165  mASet->setText(QString::fromStdString(ff->get_async_set_function().to_string()));
166  }
167 
168  auto [stateBeh,negStateBeh] = ff->get_async_set_reset_behavior();
169  if (stateBeh == AsyncSetResetBehavior::undef) mIntState->setText("undefined");
170  else mIntState->setText(QString::fromStdString(enum_to_string<AsyncSetResetBehavior>(stateBeh)));
171 
172  if (negStateBeh == AsyncSetResetBehavior::undef) mNegIntState->setText("undefined");
173  else mNegIntState->setText(QString::fromStdString(enum_to_string<AsyncSetResetBehavior>(negStateBeh)));
174  }
175  }
176  }
177 
178 
180  if(mClock->text().isEmpty() || mNextState->text().isEmpty()) return false;
181  if(!mClock->isValid() || !mNextState->isValid() || mAReset->state() == "Invalid" || mASet->state() == "Invalid") return false;
182  if(!mASet->text().isEmpty() && !mAReset->text().isEmpty())
183  {
184  if(mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::H) &&
185  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::L) &&
186  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::N) &&
187  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::T) &&
188  mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::X))
189  return false;
190  if(mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::H) &&
191  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::L) &&
192  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::N) &&
193  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::T) &&
194  mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::X))
195  return false;
196  }
197  mWizard->mEditMode = false;
198  return true;
199  }
200 }
(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:746
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