Skip to content

Commit

Permalink
implemented adding new gate to the gate library
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Jun 21, 2024
1 parent 8020e98 commit 6d34860
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

namespace hal {
class LUTWizardPage:public QWizardPage{
friend class GateLibraryWizard;
public:
LUTWizardPage(QWidget* parent = nullptr);
//void initializePage() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ class GatelibraryTableModel : public QAbstractTableModel
*/
QVariant data(const QModelIndex& index, int role) const override;

/**
* Sets the role data for the item at index to value.
*
* @param index - The model index
* @param value - The value to set
* @param role - The access role
* @returns <b>true</b> on success
*/
//bool setData(const QModelIndex &index, const QVariant &value, int role);

/**
* Returns the header data fields
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace hal
friend class RAMPortWizardPage;
friend class PinsWizardPage;
friend class BoolWizardPage;
//friend class InitWizardPage;
public:
enum PAGE
{
Expand All @@ -67,11 +66,11 @@ namespace hal
GateLibraryWizard(GateLibrary* gateLibrary, GateType* gateType = nullptr, QWidget* parent = nullptr);

void editGate(GateType* gt);
void addGate();
GateType* addGate();
void setData(GateLibrary* gateLibrary, GateType* gateType);
QStringList getProperties();
QList<PinItem*> getPingroups();
std::unique_ptr<GateTypeComponent> getComponents();
std::unique_ptr<GateTypeComponent> setComponents();
GateType* getRecentCreatedGate();
void accept() override;
int nextId() const override;
private:
Expand All @@ -92,6 +91,7 @@ namespace hal
QStringList mProperties;
PinModel* mPinModel;
GateLibraryTabPin* mPinTab;
GateType* mNewGateType;

bool isDirty;
};
Expand Down
16 changes: 9 additions & 7 deletions plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace hal
connect(mContentWidget, &GatelibraryContentWidget::triggerDeleteType, this, &GateLibraryManager::handleDeleteType);
connect(mContentWidget, &GatelibraryContentWidget::triggerDoubleClicked, this, &GateLibraryManager::handleEditWizard);

//connect(mWizard, &GateLibraryWizard::accepted, mTableModel, &GatelibraryTableModel::dataChanged);
//connect(mWizard, &QDialog::accepted, this, &GateLibraryManager::handleSelectionChanged);

setLayout(mLayout);GateLibraryTabGeneral
repolish(); // CALL FROM PARENT
Expand Down Expand Up @@ -170,18 +170,20 @@ namespace hal
return;
mWizard = new GateLibraryWizard(mEditableGatelibrary, mTableModel->getGateTypeAtIndex(index.row()));
mWizard->exec();
QModelIndex start = mTableModel->index(0,0);
QModelIndex end = mTableModel->index(mTableModel->rowCount(), mTableModel->columnCount());
Q_EMIT mTableModel->dataChanged(start, end);
initialize(mEditableGatelibrary);
}

void GateLibraryManager::handleAddWizard()
{
mWizard = new GateLibraryWizard(mEditableGatelibrary);
mWizard->exec();
QModelIndex start = mTableModel->index(0,0);
QModelIndex end = mTableModel->index(mTableModel->rowCount(), mTableModel->columnCount());
Q_EMIT mTableModel->dataChanged(start, end);

initialize(mEditableGatelibrary);

for (int r=0; r<mTableModel->rowCount(); r++) {
if(mTableModel->getGateTypeAtIndex(r) == mWizard->getRecentCreatedGate())
mContentWidget->mTableView->selectRow(r);
}
}

void GateLibraryManager::handleDeleteType(QModelIndex index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ namespace hal

}

// int LUTWizardPage::nextId() const
// {
// auto parentWizard = wizard();
// if(!parentWizard)
// return -1;
// return static_cast<GateLibraryWizard*>(parentWizard)->getNextPageId(GateLibraryWizard::LUT);
// }

void LUTWizardPage::setData(GateType *gate){
if(gate != nullptr && gate->has_component_of_type(GateTypeComponent::ComponentType::init))
{
Expand Down
126 changes: 78 additions & 48 deletions plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "hal_core/netlist/gate_library/gate_type_component/gate_type_component.h"
#include "hal_core/utilities/enums.h"
#include "hal_core/netlist/boolean_function.h"
#include "hal_core/netlist/gate_library/gate_type_component/lut_component.h"


#include <QGridLayout>
Expand Down Expand Up @@ -64,114 +65,143 @@ namespace hal

}

void GateLibraryWizard::addGate()
GateType* GateLibraryWizard::addGate()
{

}

void GateLibraryWizard::setData(GateLibrary *gateLibrary, GateType* gateType)
{
mGateLibrary = gateLibrary;
mGateType = gateType;
}

void GateLibraryWizard::accept()
{
//TODO: get all the data after user finishes

mName = generalInfoPage->getName();
mProperties = generalInfoPage->getProperties();
//mPingroups = pinsPage->getPingroups();
std::set<GateTypeProperty> properties_set;
for(QString prop : generalInfoPage->getProperties())
{
//Convert QStringList to std::set
properties_set.insert(enum_from_string<GateTypeProperty>(prop.toStdString()));

}
//Set name and properties
GateType* newGateType = mGateLibrary->create_gate_type(generalInfoPage->getName().toStdString(), properties_set);

//Set name, properties and the parent component
mNewGateType = mGateLibrary->create_gate_type(generalInfoPage->getName().toStdString(), properties_set, setComponents());
//Set pingroups and pins
for(PinItem* pingroup : getPingroups())
{
std::vector<GatePin*> gatepins;
for (auto it : pingroup->getChildren()) {
PinItem* pin = static_cast<PinItem*>(it);
gatepins.push_back(new GatePin(pin->getId(), pin->getName().toStdString(), pin->getDirection(), pin->getPinType()));
if(pin->getItemType() != PinItem::TreeItemType::PinCreator)
{
auto res = mNewGateType->create_pin(pin->getName().toStdString(), pin->getDirection(), pin->getPinType());
if(res.is_ok()) gatepins.push_back(res.get());
}
}
newGateType->create_pin_group(pingroup->getName().toStdString(), gatepins, pingroup->getDirection(), pingroup->getPinType());
if(pingroup->getItemType() != PinItem::TreeItemType::GroupCreator)
mNewGateType->create_pin_group(pingroup->getName().toStdString(), gatepins, pingroup->getDirection(), pingroup->getPinType());
}


//Set boolean functions
newGateType->add_boolean_functions(boolPage->getBoolFunctions());
mNewGateType->add_boolean_functions(boolPage->getBoolFunctions());
return mNewGateType;
}

this->close();
void GateLibraryWizard::setData(GateLibrary *gateLibrary, GateType* gateType)
{
mGateLibrary = gateLibrary;
mGateType = gateType;
}

QStringList GateLibraryWizard::getProperties()
void GateLibraryWizard::accept()
{
return mProperties;
//TODO: get all the data after user finishes

if(!mGateLibrary->contains_gate_type_by_name(generalInfoPage->getName().toStdString())) addGate();
else editGate(mGateLibrary->get_gate_type_by_name(generalInfoPage->getName().toStdString()));

this->close();
}

GateType* GateLibraryWizard::getRecentCreatedGate(){
return mNewGateType;
}

QList<PinItem*> GateLibraryWizard::getPingroups()
{
return mPinModel->getPinGroups();
}

std::unique_ptr<GateTypeComponent> GateLibraryWizard::getComponents()
std::unique_ptr<GateTypeComponent> GateLibraryWizard::setComponents()
{
std::unique_ptr<GateTypeComponent> parentComponent;
for(QString prop : generalInfoPage->getProperties())
{
//Set components
switch(enum_from_string<GateTypeComponent::ComponentType>(prop.toStdString())){
case GateTypeComponent::ComponentType::lut:
if(prop == "c_lut")
{
std::unique_ptr<GateTypeComponent> ff_comp = GateTypeComponent::create_ff_component()
std::unique_ptr<GateTypeComponent> init_comp(mGateType->get_component([](const GateTypeComponent* c) { return LUTComponent::is_class_of(c); }));
if(init_comp == nullptr) //must be used with init -> create init component
{
std::string category = initPage->mCategory->text().toStdString();
QStringList ids = initPage->mIdentifiers->toPlainText().split('\n', Qt::SkipEmptyParts);
std::vector<std::string> identifiers;
for(QString id : ids) identifiers.push_back(id.toStdString());
init_comp = parentComponent->create_init_component(category, identifiers);

}
//create lut component
parentComponent->create_lut_component(std::move(init_comp), lutPage->mAscending->text()=="Ascending");
break;
}
case GateTypeComponent::ComponentType::ff:
if(prop == "ff")
{
//must be used with state -> create state component
//can be used with init -> create init if not empty
//create ff component


//std::unique_ptr<GateTypeComponent> ff_comp = GateTypeComponent::create_ff_component()
}
case GateTypeComponent::ComponentType::latch:
if(prop == "latch")
{
std::unique_ptr<GateTypeComponent> latch_comp = GateTypeComponent::create_latch_component()
//must be used with state -> create state component
//create latch component
//std::unique_ptr<GateTypeComponent> latch_comp = GateTypeComponent::create_latch_component()
break;
}
case GateTypeComponent::ComponentType::ram:
if(prop == "ram")
{
std::unique_ptr<GateTypeComponent> ram_comp = GateTypeComponent::create_ram_component();
//must be used with at least one ram_port -> create ram_port component
//can be used with init -> create init if not empty
//create ram component

//std::unique_ptr<GateTypeComponent> ram_comp = GateTypeComponent::create_ram_component();
break;
}
case GateTypeComponent::ComponentType::mac:
/*if(prop == "mac")
{
std::unique_ptr<GateTypeComponent> mac_comp = GateTypeComponent::create_mac_component();
break;
}
case GateTypeComponent::ComponentType::init:
}*/

//INIT is NOT in enum GateTypeProperty!
/*if(prop == "init")
{
std::string category = initPage->mCategory->text().toStdString();
QStringList ids = initPage->mIdentifiers->toPlainText().split('\n', Qt::SkipEmptyParts);
std::vector<std::string> identifiers;
for(QString id : ids) identifiers.push_back(id.toStdString());
std::unique_ptr<GateTypeComponent> init_comp = GateTypeComponent::create_init_component(category, identifiers);
return init_comp;
break;
}
case GateTypeComponent::ComponentType::state:
}*/

//STATE is NOT in enum GateTypeProperty!
/*if(prop == "state")
{
std::unique_ptr<GateTypeComponent> state_comp = GateTypeComponent::create_state_component()
//std::unique_ptr<GateTypeComponent> state_comp = GateTypeComponent::create_state_component()
break;
}
case GateTypeComponent::ComponentType::ram_port:
}*/

//RAM_PORT is NOT in enum GateTypeProperty!
/*if(prop == "ram_port")
{
std::unique_ptr<GateTypeComponent> ram_port_comp = GateTypeComponent::create_ram_port_component()
//std::unique_ptr<GateTypeComponent> ram_port_comp = GateTypeComponent::create_ram_port_component()
break;
}
}
}*/
}

return parentComponent;
}

int GateLibraryWizard::nextId() const
Expand Down

0 comments on commit 6d34860

Please sign in to comment.