From 434753930508de6e3b6bb6044e0bdf16ae25b9eb Mon Sep 17 00:00:00 2001 From: tarapn79 Date: Thu, 27 Jun 2024 11:39:17 +0200 Subject: [PATCH] implemented saving the changes to the gate made with the wizard --- .../generalinfo_wizardpage.h | 1 + .../gatelibrary_wizard.h | 2 +- .../gatelibrary_manager.cpp | 6 -- .../generalinfo_wizardpage.cpp | 9 +- .../gatelibrary_wizard.cpp | 85 +++++++++++++------ 5 files changed, 64 insertions(+), 39 deletions(-) diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h index 38fe0d4b916..6366d539459 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.h @@ -45,6 +45,7 @@ namespace hal { QString getName(); QStringList getProperties(); void setMode(bool edit); + bool isEdit(); bool validatePage() override; public Q_SLOTS: void addProperty(); diff --git a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h index 6131f1aad5d..2f9f07955b4 100644 --- a/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h +++ b/plugins/gui/include/gui/gatelibrary_management/gatelibrary_wizard.h @@ -65,7 +65,7 @@ namespace hal GateLibraryWizard(GateLibrary* gateLibrary, GateType* gateType = nullptr, QWidget* parent = nullptr); - void editGate(GateType* gt); + void editGate(); GateType* addGate(); void setData(GateLibrary* gateLibrary, GateType* gateType); QList getPingroups(); diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp index 77fe17b22ca..2df32c58b96 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp @@ -126,15 +126,9 @@ namespace hal if (gPluginRelay->mGuiPluginTable) gPluginRelay->mGuiPluginTable->loadFeature(FacExtensionInterface::FacGatelibParser); - //qInfo() << "selected file: " << fileName; auto gateLibrary = gate_library_manager::load(std::filesystem::path(fileName.toStdString())); - /*for (auto const elem : gateLibrary->get_gate_types()) - { - qInfo() << QString::fromStdString(elem.second->get_name()); - }*/ - mEditableGatelibrary = gateLibrary; mDemoNetlist = netlist_factory::create_netlist(mEditableGatelibrary); mReadOnly = false; diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp index f0862022358..091ea67bfd5 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_pages/generalinfo_wizardpage.cpp @@ -33,9 +33,6 @@ namespace hal setLayout(mLayout); - registerField("name*", mName); - registerField("properties", mProperties); - //TODO: fetch data from enum GateTypeProperty mAddProperty->addItems(QStringList{ "combinational", @@ -77,6 +74,11 @@ namespace hal mIsEdit = edit; } + bool GeneralInfoWizardPage::isEdit() + { + return mIsEdit; + } + void GeneralInfoWizardPage::setData(QString name, QStringList properties) { mName->setText(name); @@ -93,7 +95,6 @@ namespace hal { QStringList res; for (int i = 0; i < mProperties->count(); i++) { - //qInfo()<item(i)->text(); res.append(mProperties->item(i)->text()); } return res; diff --git a/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp b/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp index 3e06fd265c7..695e1be9628 100644 --- a/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp +++ b/plugins/gui/src/gatelibrary_management/gatelibrary_wizard.cpp @@ -62,38 +62,15 @@ namespace hal } } - void GateLibraryWizard::editGate(GateType* gt) + void GateLibraryWizard::editGate() { } GateType* GateLibraryWizard::addGate() { - //Convert QStringList to std::set - std::set properties_set; - for(QString prop : generalInfoPage->getProperties()) - properties_set.insert(enum_from_string(prop.toStdString())); - //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); - 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()); - } - } - if(pingroup->getItemType() != PinItem::TreeItemType::GroupCreator) - mNewGateType->create_pin_group(pingroup->getName().toStdString(), gatepins, pingroup->getDirection(), pingroup->getPinType()); - } - //Set boolean functions - mNewGateType->add_boolean_functions(boolPage->getBoolFunctions()); - return mNewGateType; + } void GateLibraryWizard::setData(GateLibrary *gateLibrary, GateType* gateType) @@ -104,10 +81,61 @@ namespace hal void GateLibraryWizard::accept() { - //TODO: get all the data after user finishes + /*if(generalInfoPage->isEdit()) editGate(); + else addGate();*/ + + //Convert QStringList to std::set + std::set properties_set; + for(QString prop : generalInfoPage->getProperties()) + properties_set.insert(enum_from_string(prop.toStdString())); + + if(generalInfoPage->isEdit()) + { + mGateType = mGateLibrary->replace_gate_type(mGateType->get_id(), 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); + if(pin->getItemType() != PinItem::TreeItemType::PinCreator) + { + auto res = mGateType->create_pin(pin->getName().toStdString(), pin->getDirection(), pin->getPinType()); + if(res.is_ok()) gatepins.push_back(res.get()); + } + } + if(pingroup->getItemType() != PinItem::TreeItemType::GroupCreator) + mGateType->create_pin_group(pingroup->getName().toStdString(), gatepins, pingroup->getDirection(), pingroup->getPinType()); + } + + //TODO: Set boolean functions without adding the same double + //also: boolean functions may be removed + mGateType->add_boolean_functions(boolPage->getBoolFunctions()); + } + else + { + //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); + 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()); + } + } + if(pingroup->getItemType() != PinItem::TreeItemType::GroupCreator) + mNewGateType->create_pin_group(pingroup->getName().toStdString(), gatepins, pingroup->getDirection(), pingroup->getPinType()); + } + + //Set boolean functions + mNewGateType->add_boolean_functions(boolPage->getBoolFunctions()); + } - if(!mGateLibrary->contains_gate_type_by_name(generalInfoPage->getName().toStdString())) addGate(); - else editGate(mGateLibrary->get_gate_type_by_name(generalInfoPage->getName().toStdString())); this->close(); } @@ -251,6 +279,7 @@ namespace hal else if(properties.contains("latch")) return Latch; else if(properties.contains("c_lut")) return LUT; else if(properties.contains("ram")) return RAM; + else return BoolFunc; case FlipFlop: if(properties.contains("latch")) return Latch; else if(properties.contains("c_lut")) return LUT;