Skip to content

Commit

Permalink
Merge branch 'feature/GateLibraryManager' of github.com:emsec/hal int…
Browse files Browse the repository at this point in the history
…o feature/GateLibraryManager
  • Loading branch information
neoneela committed Sep 26, 2024
2 parents 6342539 + 0a8c520 commit 67be4ec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ namespace hal
GateLibraryTabTruthTable* mBooleanFunctionTab;
GateLibraryTabPin* mPinTab;

const GateLibrary* mNonEditableGateLibrary;
GateLibrary* mEditableGatelibrary;
GateLibrary* mGateLibrary;
std::unique_ptr<Netlist> mDemoNetlist;
std::filesystem::path mPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace hal
void GateLibraryFrameRAMPort::update(GateType* gt)
{
QLayoutItem* item;
if (!mLayout->isEmpty())
while (!mLayout->isEmpty())
{
while ((item = mLayout->takeAt(0)) != nullptr) {
if ((item = mLayout->takeAt(0)) != nullptr) {
delete item->widget();
delete item;
}
Expand Down
44 changes: 16 additions & 28 deletions plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
namespace hal
{
GateLibraryManager::GateLibraryManager(MainWindow *parent)
: QFrame(parent), mFrameWidth(0), mLayout(new QGridLayout()), mNonEditableGateLibrary(nullptr), mEditableGatelibrary(nullptr)
: QFrame(parent), mFrameWidth(0), mLayout(new QGridLayout()), mGateLibrary(nullptr)
{
//TODO: GateLibrarymanager will stay in readOnly mode even if closing project and opening a new gateLibrary
mSplitter = new QSplitter(this);
QWidget* rightWindow = new QWidget(mSplitter);
QGridLayout* rlay = new QGridLayout(rightWindow);
Expand Down Expand Up @@ -111,11 +110,9 @@ namespace hal
if(!gateLibrary)
{
if(gNetlist && gNetlist->get_gate_library()){
//TODO find better way to handle const/not const gateLibrary
mNonEditableGateLibrary = gNetlist->get_gate_library();
mDemoNetlist = netlist_factory::create_netlist(mNonEditableGateLibrary);
// readonly flag makes sure mGateLibrary does not get modified, const attribute not needed
mGateLibrary = const_cast<GateLibrary*>(gNetlist->get_gate_library());
mReadOnly = true;

}
else
{
Expand All @@ -136,8 +133,7 @@ namespace hal

auto gateLibrary = gate_library_manager::load(std::filesystem::path(fileName.toStdString()));

mEditableGatelibrary = gateLibrary;
mDemoNetlist = netlist_factory::create_netlist(mEditableGatelibrary);
mGateLibrary = gateLibrary;
mReadOnly = false;

QDir dir(QDir::home());
Expand All @@ -149,20 +145,13 @@ namespace hal
else
{
mReadOnly = readOnly;
if(mReadOnly)
{
mDemoNetlist = netlist_factory::create_netlist(mNonEditableGateLibrary);
mNonEditableGateLibrary = gateLibrary;
}
else
{
mDemoNetlist = netlist_factory::create_netlist(mEditableGatelibrary);
mEditableGatelibrary = gateLibrary;
}
mGateLibrary = gateLibrary;
}

mDemoNetlist = netlist_factory::create_netlist(mGateLibrary);
mGraphicsView->showGate(nullptr);
updateTabs(nullptr);
mTableModel->loadFile(mReadOnly ? mNonEditableGateLibrary : mEditableGatelibrary);
mTableModel->loadFile(mGateLibrary);
mContentWidget->activate(mReadOnly);

mContentWidget->toggleSelection(false);
Expand All @@ -178,7 +167,7 @@ namespace hal
connect(mWizard, &GateLibraryWizard::triggerUnsavedChanges, mContentWidget, &GatelibraryContentWidget::handleUnsavedChanges);

mWizard->exec();
initialize(mEditableGatelibrary);
initialize(mGateLibrary);

for (int r=0; r<mTableModel->rowCount(); r++) {
if(mTableModel->getGateTypeAtIndex(r) == gtEditable)
Expand All @@ -190,26 +179,25 @@ namespace hal

void GateLibraryManager::handleAddWizard()
{
mWizard = new GateLibraryWizard(mEditableGatelibrary);
mWizard = new GateLibraryWizard(mGateLibrary);
connect(mWizard, &GateLibraryWizard::triggerUnsavedChanges, mContentWidget, &GatelibraryContentWidget::handleUnsavedChanges);

mWizard->exec();

initialize(mEditableGatelibrary);
initialize(mGateLibrary);

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

void GateLibraryManager::handleDeleteType(QModelIndex index)
{
GateType* gate = mTableModel->getGateTypeAtIndex(index.row());
mEditableGatelibrary->remove_gate_type(gate->get_name());
initialize(mEditableGatelibrary);
mGateLibrary->remove_gate_type(gate->get_name());
initialize(mGateLibrary);
gFileStatusManager->gatelibChanged();
//qInfo() << "handleDeleteType " << QString::fromStdString(gate->get_name()) << ":" << gate->get_id();
}
Expand All @@ -218,7 +206,7 @@ namespace hal
{
QSet<u32>* occupiedIds = new QSet<u32>;
u32 freeId = 1;
for (auto gt : mEditableGatelibrary->get_gate_types()) {
for (auto gt : mGateLibrary->get_gate_types()) {
occupiedIds->insert(gt.second->get_id());
}
while(occupiedIds->contains(freeId))
Expand Down Expand Up @@ -299,7 +287,7 @@ namespace hal
Q_EMIT close();
break;
case QMessageBox::Discard:
gate_library_manager::remove(std::filesystem::path(mEditableGatelibrary->get_path()));
gate_library_manager::remove(std::filesystem::path(mGateLibrary->get_path()));
mDemoNetlist.reset(); //delete unique pointer
gFileStatusManager->gatelibSaved();
window()->setWindowTitle("HAL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ namespace hal
{
// Clear existing labels
QLayoutItem* item;
if (!mLayout->isEmpty())
while (!mLayout->isEmpty())
{
while ((item = mLayout->takeAt(0)) != nullptr) {
if ((item = mLayout->takeAt(0)) != nullptr) {
delete item->widget();
delete item;
}
Expand Down

0 comments on commit 67be4ec

Please sign in to comment.