Skip to content

Commit

Permalink
implemented saving gatelibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Aug 29, 2024
1 parent fdc46fa commit 68fdd78
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 23 deletions.
195 changes: 179 additions & 16 deletions plugins/gate_libraries/definitions/example_library.hgl

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

#include <QAction>
#include <QFrame>
#include <QUuid>
#include <QTableView>
#include <gui/pin_model/pin_proxy_model.h>
#include "gui/pin_model/pin_proxy_model.h"
#include "hgl_writer/include/hgl_writer/hgl_writer.h"

namespace hal
{
Expand All @@ -51,6 +53,10 @@ namespace hal
Q_PROPERTY(QString searchActiveIconStyle READ searchActiveIconStyle WRITE setSearchActiveIconStyle)
Q_PROPERTY(QString deleteIconPath READ deleteIconPath WRITE setDeleteIconPath);
Q_PROPERTY(QString deleteIconStyle READ deleteIconStyle WRITE setDeleteIconStyle);
Q_PROPERTY(QString saveIconPath READ saveIconPath WRITE setSaveIconPath);
Q_PROPERTY(QString saveIconStyle READ saveIconStyle WRITE setSaveIconStyle);
Q_PROPERTY(QString saveAsIconPath READ saveAsIconPath WRITE setSaveAsIconPath);
Q_PROPERTY(QString saveAsIconStyle READ saveAsIconStyle WRITE setSaveAsIconStyle);

friend class GateLibraryManager;

Expand All @@ -63,6 +69,9 @@ namespace hal
QAction* mSearchAction;
QAction* mDeleteAction;

QAction* mSaveAction;
QAction* mSaveAsAction;

QString mDisabledIconStyle;
QString mEnabledIconStyle;
QString mAddTypeIconPath;
Expand All @@ -72,6 +81,10 @@ namespace hal
QString mSearchActiveIconStyle;
QString mDeleteIconPath;
QString mDeleteIconStyle;
QString mSaveIconPath;
QString mSaveIconStyle;
QString mSaveAsIconPath;
QString mSaveAsIconStyle;

bool mReadOnly = false;

Expand All @@ -87,7 +100,8 @@ namespace hal
void handleDeleteAction();
void handleCurrentSelectionChanged(QModelIndex prevIndex);
void handleDoubleClicked(QModelIndex index);

void handleSaveAction();
void handleSaveAsAction();

public:
GatelibraryContentWidget(GatelibraryTableModel* model, QWidget* parent = nullptr);
Expand All @@ -100,6 +114,11 @@ namespace hal

void toggleSelection(bool selected);

void setUuid(QUuid uid);

void setGateLibrary(GateLibrary* gl);

void setGateLibraryPath(std::filesystem::path p);

QString disabledIconStyle() const;

Expand All @@ -119,6 +138,14 @@ namespace hal

QString deleteIconStyle() const;

QString saveIconPath() const;

QString saveIconStyle() const;

QString saveAsIconPath() const;

QString saveAsIconStyle() const;

void setDisabledIconStyle(const QString& s);

void setEnabledIconStyle(const QString& s);
Expand All @@ -136,6 +163,18 @@ namespace hal
void setDeleteIconPath(const QString& s);

void setDeleteIconStyle(const QString& s);
};

void setSaveIconPath(const QString& s);

void setSaveIconStyle(const QString& s);

void setSaveAsIconPath(const QString& s);

void setSaveAsIconStyle(const QString& s);

private:
QUuid mUuid;
GateLibrary* mGateLibrary;
std::filesystem::path mPath;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
#include "hal_core/netlist/gate_library/gate_library.h"
#include "hal_core/netlist/gate_library/gate_type.h"


#include <QFrame>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h>
#include <gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h>
#include "gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_truth_table.h"
#include "gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_general.h"
#include "gui/gatelibrary_management/gatelibrary_tab_widgets/gatelibrary_tab_pin.h"

class QGridLayout;
class QPushButton;
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace hal
bool initialize(GateLibrary* gateLibrary = nullptr, bool readOnly = false);
u32 getNextGateId();
void updateTabs(GateType* gateType);
QUuid getUuid();

public Q_SLOTS:
/**
Expand Down Expand Up @@ -115,6 +117,7 @@ namespace hal
const GateLibrary* mNonEditableGateLibrary;
GateLibrary* mEditableGatelibrary;
std::unique_ptr<Netlist> mDemoNetlist;
std::filesystem::path mPath;

bool mReadOnly = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace hal
GateType* getRecentCreatedGate();
void accept() override;
int nextId() const override;
QUuid getUuid();
private:
GateLibrary* mGateLibrary;
GateType* mGateType;
Expand All @@ -90,5 +91,7 @@ namespace hal
PinModel* mPinModel;
GateLibraryTabPin* mPinTab;
GateType* mNewGateType;

QUuid mUuid;
};
}
4 changes: 4 additions & 0 deletions plugins/gui/resources/stylesheet/dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ hal--GatelibraryContentWidget
qproperty-searchActiveIconStyle: "all->#30ac4f";
qproperty-deleteIconStyle: "all->#e8e8e8";
qproperty-deleteIconPath: ":/icons/trashcan";
qproperty-saveIconPath: ":/icons/folder-down";
qproperty-saveIconStyle: "all->#e8e8e8";
qproperty-saveAsIconPath: ":/icons/save-as";
qproperty-saveAsIconStyle: "all->#e8e8e8";
}

hal--GeneralInfoWizardPage
Expand Down
4 changes: 4 additions & 0 deletions plugins/gui/resources/stylesheet/light.qss
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,10 @@ hal--GatelibraryContentWidget
qproperty-searchActiveIconStyle: "all->#30ac4f";
qproperty-deleteIconStyle: "all->#FFFFFF";
qproperty-deleteIconPath: ":/icons/trashcan";
qproperty-saveIconStyle: "all->#3192C5";
qproperty-saveIconPath: ":/icons/folder-down";
qproperty-saveAsIconStyle: "all->#FFFFFF";
qproperty-saveAsIconPath: ":/icons/save-as";
}

hal--ImportNetlistDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,28 @@ namespace hal
mDeleteAction = new QAction("Delete gate type", this);
mSearchAction = new QAction("Search", this);

mSaveAction = new QAction("Save", this);
mSaveAsAction = new QAction("Save as...", this);

//connections
connect(mTableView, &QTableView::customContextMenuRequested, this, &GatelibraryContentWidget::handleContextMenuRequested);
connect(mTableView, &QTableView::doubleClicked, this, &GatelibraryContentWidget::handleDoubleClicked);
connect(mTableView->selectionModel(), &QItemSelectionModel::currentChanged, this, &GatelibraryContentWidget::handleCurrentSelectionChanged);
connect(mSearchAction, &QAction::triggered, this, &GatelibraryContentWidget::toggleSearchbar);
connect(mEditAction, &QAction::triggered, this, &GatelibraryContentWidget::handleEditAction);
connect(mDeleteAction, &QAction::triggered, this, &GatelibraryContentWidget::handleDeleteAction);
connect(mSaveAction, &QAction::triggered, this, &GatelibraryContentWidget::handleSaveAction);
connect(mSaveAsAction, &QAction::triggered, this, &GatelibraryContentWidget::handleSaveAsAction);
connect(mSearchbar, &Searchbar::triggerNewSearch, mPinProxyModel, &SearchProxyModel::startSearch);

mToolbar->addAction(mAddAction);
mToolbar->addAction(mEditAction);
mToolbar->addAction(mDeleteAction);
mToolbar->addAction(mSearchAction);

mToolbar->addAction(mSaveAction);
mToolbar->addAction(mSaveAsAction);


layout->addWidget(mToolbar);
layout->addWidget(mTableView);
Expand All @@ -86,6 +94,21 @@ namespace hal
menu.exec();
}

void GatelibraryContentWidget::setUuid(QUuid uid)
{
mUuid = uid;
}

void GatelibraryContentWidget::setGateLibrary(GateLibrary *gl)
{
mGateLibrary = gl;
}

void GatelibraryContentWidget::setGateLibraryPath(std::filesystem::path p)
{
mPath = p;
}

void GatelibraryContentWidget::handleEditAction()
{
QModelIndex inx = mPinProxyModel->mapToSource(mTableView->currentIndex());
Expand Down Expand Up @@ -114,6 +137,22 @@ namespace hal
Q_EMIT triggerDoubleClicked(inx);
}

void GatelibraryContentWidget::handleSaveAction()
{
//TODO

gFileStatusManager->fileSaved(mUuid);
HGLWriter* writer = new HGLWriter();
writer->write(mGateLibrary, mPath);
}

void GatelibraryContentWidget::handleSaveAsAction()
{
//TODO
gFileStatusManager->fileSaved(mUuid);
HGLWriter* writer = new HGLWriter();
writer->write(mGateLibrary, mPath);
}

void GatelibraryContentWidget::toggleSearchbar()
{
Expand Down Expand Up @@ -143,6 +182,8 @@ namespace hal
toggleReadOnlyMode(readOnly);

mSearchAction->setIcon(gui_utility::getStyledSvgIcon(mEnabledIconStyle,mSearchIconPath));
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveIconPath));
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(mDisabledIconStyle,mSaveAsIconPath));

}

Expand All @@ -156,6 +197,12 @@ namespace hal

mAddAction->setEnabled(!readOnly);
mAddAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mAddTypeIconPath));

mSaveAction->setEnabled(!readOnly);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveIconPath));

mSaveAsAction->setEnabled(!readOnly);
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(readOnly ? mDisabledIconStyle : mEnabledIconStyle,mSaveAsIconPath));
}

void GatelibraryContentWidget::toggleSelection(bool selected)
Expand All @@ -164,6 +211,12 @@ namespace hal
mDeleteAction->setIcon(gui_utility::getStyledSvgIcon(selected ? mEnabledIconStyle : mDisabledIconStyle, mDeleteIconPath));
mEditAction->setEnabled(selected);
mEditAction->setIcon(gui_utility::getStyledSvgIcon(selected ? mEnabledIconStyle : mDisabledIconStyle,mEditTypeIconPath));

mSaveAction->setEnabled(selected);
mSaveAction->setIcon(gui_utility::getStyledSvgIcon(selected ? mEnabledIconStyle : mDisabledIconStyle,mSaveIconPath));
mSaveAsAction->setEnabled(selected);
mSaveAsAction->setIcon(gui_utility::getStyledSvgIcon(selected ? mEnabledIconStyle : mDisabledIconStyle,mSaveAsIconPath));

}

QString GatelibraryContentWidget::disabledIconStyle() const
Expand Down Expand Up @@ -211,6 +264,26 @@ namespace hal
return mDeleteIconStyle;
}

QString GatelibraryContentWidget::saveIconPath() const
{
return mSaveIconPath;
}

QString GatelibraryContentWidget::saveIconStyle() const
{
return mSaveIconStyle;
}

QString GatelibraryContentWidget::saveAsIconPath() const
{
return mSaveAsIconPath;
}

QString GatelibraryContentWidget::saveAsIconStyle() const
{
return mSaveAsIconStyle;
}

void GatelibraryContentWidget::setDisabledIconStyle(const QString& s)
{
mDisabledIconStyle = s;
Expand Down Expand Up @@ -256,5 +329,23 @@ namespace hal
mDeleteIconStyle = s;
}

void GatelibraryContentWidget::setSaveIconPath(const QString& s)
{
mSaveIconPath = s;
}

void GatelibraryContentWidget::setSaveIconStyle(const QString& s)
{
mSaveIconStyle = s;
}

void GatelibraryContentWidget::setSaveAsIconPath(const QString& s)
{
mSaveAsIconPath = s;
}

void GatelibraryContentWidget::setSaveAsIconStyle(const QString& s)
{
mSaveAsIconStyle = s;
}
}
12 changes: 12 additions & 0 deletions plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ namespace hal

QDir dir(QDir::home());
window()->setWindowTitle(QString("GateLibrary %1").arg(dir.relativeFilePath(fileName)));
mPath = fileName.toStdString();
}

}
Expand All @@ -161,6 +162,11 @@ namespace hal
return true;
}

QUuid GateLibraryManager::getUuid()
{
return mWizard->getUuid();
}

void GateLibraryManager::handleEditWizard(const QModelIndex& index)
{
if(mReadOnly)
Expand All @@ -170,6 +176,9 @@ namespace hal
initialize(mEditableGatelibrary);

mContentWidget->mTableView->selectRow(index.row());
mContentWidget->setUuid(mWizard->getUuid());
mContentWidget->setGateLibrary(mEditableGatelibrary);
mContentWidget->setGateLibraryPath(mPath);
}

void GateLibraryManager::handleAddWizard()
Expand All @@ -183,6 +192,9 @@ namespace hal
if(mTableModel->getGateTypeAtIndex(r) == mWizard->getRecentCreatedGate())
mContentWidget->mTableView->selectRow(r);
}
mContentWidget->setUuid(mWizard->getUuid());
mContentWidget->setGateLibrary(mEditableGatelibrary);
mContentWidget->setGateLibraryPath(mPath);
}

void GateLibraryManager::handleDeleteType(QModelIndex index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ namespace hal
//Set boolean functions
mNewGateType->add_boolean_functions(boolPage->getBoolFunctions());
}
this->close();

mUuid = QUuid::createUuid();
gFileStatusManager->fileChanged(mUuid, QString("GateLibrary %1 modified").arg(QString::fromStdString(mGateLibrary->get_name())));
}

this->close();
QUuid GateLibraryWizard::getUuid(){
return mUuid;
}

GateType* GateLibraryWizard::getRecentCreatedGate(){
Expand Down

0 comments on commit 68fdd78

Please sign in to comment.