Skip to content

Commit

Permalink
Implemented validation rules for FlipFlop wizard page
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Aug 16, 2024
1 parent d62cdb0 commit 44ef25a
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ namespace hal {
static const char* STATE_INVALID;
Q_SIGNALS:
void stateChanged(QString s);
void legalVariablesChanged(std::set<std::string> legalVar);
private Q_SLOTS:
void handleEditingFinished();
public:
BooleanFunctionEdit(std::set<std::string>& legalVar, QWidget* parent = nullptr);
QString state() const { return mState; }
void setState(const QString& s);
void setLegalVariables(std::set<std::string>& legalVar);
bool isValid() const { return mState == STATE_VALID; }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
// SOFTWARE.

#pragma once
//#include "gui/src/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_flip_flop.cpp"
#include "gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h"
#include "gui/gatelibrary_management/gatelibrary_pages/bool_wizardpage.h"


#include <QWizardPage>
Expand All @@ -35,21 +35,26 @@
#include <QLabel>

namespace hal {
class GateLibraryWizard;
class FlipFlopWizardPage:public QWizardPage{
Q_OBJECT
friend class GateLibraryWizard;
public:
FlipFlopWizardPage(QWidget* parent = nullptr);
void initializePage() override;
void setData(GateType* gate);
bool isComplete() const override;

public Q_SLOTS:
void handleTextChanged(const QString& txt);
private:
QGridLayout* mLayout;
QTabWidget* mTabWidget;

QLineEdit* mClock;
QLineEdit* mNextState;
QLineEdit* mAReset;
QLineEdit* mASet;
BooleanFunctionEdit* mClock;
BooleanFunctionEdit* mNextState;
BooleanFunctionEdit* mAReset;
BooleanFunctionEdit* mASet;
QLineEdit* mIntState;
QLineEdit* mNegIntState;

Expand All @@ -59,5 +64,8 @@ namespace hal {
QLabel* mLabASet;
QLabel* mLabIntState;
QLabel* mLabNegIntState;

GateLibraryWizard* mWizard;
std::set<std::string> mLegVars;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace hal {
class GateLibraryWizard;
class StateWizardPage:public QWizardPage{
friend class GateLibraryWizard;
friend class FlipFlopWizardPage;
friend class BoolWizardPage;
public:
Q_OBJECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace hal
{
friend class RAMPortWizardPage;
friend class PinsWizardPage;
friend class FlipFlopWizardPage;
friend class StateWizardPage;
friend class BoolWizardPage;
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace hal
: QLineEdit(parent), mState(STATE_VALID), mLegalVariables(legalVar)
{
connect(this, &QLineEdit::textChanged, this, &BooleanFunctionEdit::handleEditingFinished);
connect(this, &BooleanFunctionEdit::legalVariablesChanged, this, &BooleanFunctionEdit::handleEditingFinished);

setState(STATE_EMPTY); // do an active transition to enforce style
}
Expand All @@ -27,6 +28,12 @@ namespace hal
sty->polish(this);
}

void BooleanFunctionEdit::setLegalVariables(std::set<std::string> &legalVar)
{
mLegalVariables = legalVar;
Q_EMIT legalVariablesChanged(legalVar);
}

void BooleanFunctionEdit::handleEditingFinished()
{
if (text().isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace hal
mLayout = new QGridLayout(this);
mTabWidget = new QTabWidget(this);

mClock = new QLineEdit(this);
mNextState = new QLineEdit(this);
mAReset = new QLineEdit(this);
mASet = new QLineEdit(this);
mClock = new BooleanFunctionEdit(mLegVars, this);
mNextState = new BooleanFunctionEdit(mLegVars, this);
mAReset = new BooleanFunctionEdit(mLegVars, this);
mASet = new BooleanFunctionEdit(mLegVars, this);
mIntState = new QLineEdit(this);
mNegIntState = new QLineEdit(this);

Expand All @@ -43,17 +43,67 @@ namespace hal
//TODO:
//mTabWidget->addTab(mStateTableTab, "State Table");

//mAReset->setDisabled(true);
//mASet->setDisabled(true);

setLayout(mLayout);

connect(mClock, &QLineEdit::textChanged, this, &FlipFlopWizardPage::handleTextChanged);
connect(mNextState, &QLineEdit::textChanged, this, &FlipFlopWizardPage::handleTextChanged);
connect(mAReset, &QLineEdit::textChanged, this, &FlipFlopWizardPage::handleTextChanged);
connect(mASet, &QLineEdit::textChanged, this, &FlipFlopWizardPage::handleTextChanged);
connect(mIntState, &QLineEdit::textChanged, this, &FlipFlopWizardPage::handleTextChanged);
connect(mNegIntState, &QLineEdit::textChanged, this, &FlipFlopWizardPage::handleTextChanged);
}

void FlipFlopWizardPage::initializePage()
{
//qInfo() << field("name").toString();
//qInfo() << field("properties").toInt();
mWizard = static_cast<GateLibraryWizard*>(wizard());
QList<PinItem*> inputPins = mWizard->mPinModel->getInputPins();
for (PinItem* pi : inputPins)
mLegVars.insert(pi->getName().toStdString());

mClock->setLegalVariables(mLegVars);
mNextState->setLegalVariables(mLegVars);
mAReset->setLegalVariables(mLegVars);
mASet->setLegalVariables(mLegVars);

if(mWizard->statePage->mNegStateIdentifier->text().isEmpty())
{
mNegIntState->clear();
mNegIntState->setDisabled(true);
}
else mNegIntState->setDisabled(false);

QList<PinItem*> pingroups = mWizard->getPingroups();
for (PinItem* pg : pingroups) {
if(pg->getPinType() == PinType::clock) { //assuming pins have the same type as the pingroup
PinItem* p = static_cast<PinItem*>(pg->getChild(0));
mClock->setText(p->getName()); //name of first pin with type clock
}
if(pg->getPinType() == PinType::reset) {
PinItem* p = static_cast<PinItem*>(pg->getChild(0));
mAReset->setText(p->getName()); //name of first pin with type reset
}
if(pg->getPinType() == PinType::set) {
PinItem* p = static_cast<PinItem*>(pg->getChild(0));
mASet->setText(p->getName()); //name of first pin with type set
}
}
}

void FlipFlopWizardPage::handleTextChanged(const QString& text){
Q_UNUSED(text);
if(mASet->text().isEmpty() || mAReset->text().isEmpty())
{
mIntState->clear();
mNegIntState->clear();
mIntState->setDisabled(true);
mNegIntState->setDisabled(true);
}
else
{
mIntState->setDisabled(false);
mNegIntState->setDisabled(false);
}
Q_EMIT completeChanged();
}

void FlipFlopWizardPage::setData(GateType *gate){
Expand Down Expand Up @@ -87,4 +137,26 @@ namespace hal
}
}
}


bool FlipFlopWizardPage::isComplete() const{
if(mClock->text().isEmpty() || mNextState->text().isEmpty()) return false;
if(!mClock->isValid() || !mNextState->isValid() || !mAReset->isValid() || !mASet->isValid()) return false;
if(!mASet->text().isEmpty() && !mAReset->text().isEmpty())
{
if(mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::H) &&
mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::L) &&
mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::N) &&
mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::T) &&
mIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::X))
return false;
if(mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::H) &&
mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::L) &&
mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::N) &&
mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::T) &&
mNegIntState->text().toStdString() != enum_to_string(AsyncSetResetBehavior::X))
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace hal

bool StateWizardPage::isComplete() const
{
if(mStateIdentifier->text().isEmpty() || mNegStateIdentifier->text().isEmpty()) return false;
if(mStateIdentifier->text().isEmpty()) return false;
for (auto pingroup : mPinGroups) { //check if pins name is used as a state identifier name
QString groupName = pingroup->getName();
if(mStateIdentifier->text() == groupName || mNegStateIdentifier->text() == groupName) return false;
Expand Down

0 comments on commit 44ef25a

Please sign in to comment.