diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/lut_wizardpage.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/lut_wizardpage.h index c5102aa2d6f..52b92313a67 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/lut_wizardpage.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/lut_wizardpage.h @@ -35,6 +35,7 @@ namespace hal { class LUTWizardPage:public QWizardPage{ + friend class GateLibraryWizard; public: LUTWizardPage(QWidget* parent = nullptr); //void initializePage() override; diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_table_model.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_table_model.h index b075bc266ad..980816f1e5b 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_table_model.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_table_model.h @@ -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 true on success + */ + //bool setData(const QModelIndex &index, const QVariant &value, int role); + /** * Returns the header data fields * diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h index ca3f363fd7d..6131f1aad5d 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h @@ -48,7 +48,6 @@ namespace hal friend class RAMPortWizardPage; friend class PinsWizardPage; friend class BoolWizardPage; - //friend class InitWizardPage; public: enum PAGE { @@ -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 getPingroups(); - std::unique_ptr getComponents(); + std::unique_ptr setComponents(); + GateType* getRecentCreatedGate(); void accept() override; int nextId() const override; private: @@ -92,6 +91,7 @@ namespace hal QStringList mProperties; PinModel* mPinModel; GateLibraryTabPin* mPinTab; + GateType* mNewGateType; bool isDirty; }; diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp index 077fe589073..364ae71abef 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp @@ -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 @@ -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; rrowCount(); r++) { + if(mTableModel->getGateTypeAtIndex(r) == mWizard->getRecentCreatedGate()) + mContentWidget->mTableView->selectRow(r); + } } void GateLibraryManager::handleDeleteType(QModelIndex index) diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/lut_wizardpage.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/lut_wizardpage.cpp index cf7f5b8844d..a4b9c6ac3cd 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/lut_wizardpage.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/lut_wizardpage.cpp @@ -21,14 +21,6 @@ namespace hal } -// int LUTWizardPage::nextId() const -// { -// auto parentWizard = wizard(); -// if(!parentWizard) -// return -1; -// return static_cast(parentWizard)->getNextPageId(GateLibraryWizard::LUT); -// } - void LUTWizardPage::setData(GateType *gate){ if(gate != nullptr && gate->has_component_of_type(GateTypeComponent::ComponentType::init)) { diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp index 95a35f83d69..2a9ab5e1393 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp @@ -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 @@ -64,24 +65,8 @@ 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 properties_set; for(QString prop : generalInfoPage->getProperties()) { @@ -89,30 +74,47 @@ namespace hal properties_set.insert(enum_from_string(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 gatepins; for (auto it : pingroup->getChildren()) { PinItem* pin = static_cast(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 GateLibraryWizard::getPingroups() @@ -120,58 +122,86 @@ namespace hal return mPinModel->getPinGroups(); } - std::unique_ptr GateLibraryWizard::getComponents() + std::unique_ptr GateLibraryWizard::setComponents() { + std::unique_ptr parentComponent; for(QString prop : generalInfoPage->getProperties()) { //Set components - switch(enum_from_string(prop.toStdString())){ - case GateTypeComponent::ComponentType::lut: + if(prop == "c_lut") { - std::unique_ptr ff_comp = GateTypeComponent::create_ff_component() + std::unique_ptr 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 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 ff_comp = GateTypeComponent::create_ff_component() } - case GateTypeComponent::ComponentType::latch: + if(prop == "latch") { - std::unique_ptr latch_comp = GateTypeComponent::create_latch_component() + //must be used with state -> create state component + //create latch component + //std::unique_ptr latch_comp = GateTypeComponent::create_latch_component() break; } - case GateTypeComponent::ComponentType::ram: + if(prop == "ram") { - std::unique_ptr 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 ram_comp = GateTypeComponent::create_ram_component(); break; } - case GateTypeComponent::ComponentType::mac: + /*if(prop == "mac") { std::unique_ptr 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 identifiers; for(QString id : ids) identifiers.push_back(id.toStdString()); std::unique_ptr 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 state_comp = GateTypeComponent::create_state_component() + //std::unique_ptr 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 ram_port_comp = GateTypeComponent::create_ram_port_component() + //std::unique_ptr ram_port_comp = GateTypeComponent::create_ram_port_component() break; - } - } + }*/ } - + return parentComponent; } int GateLibraryWizard::nextId() const