Skip to content

Commit

Permalink
Setup for GateLibraryManager
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrKermet committed Nov 26, 2023
1 parent 8571ea9 commit 9e361dc
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// MIT License
//
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include "hal_core/netlist/gate_library/gate_library.h"

#include <QFrame>
#include <QGridLayout>
#include <QTableView>

namespace hal
{


class GateLibraryManager : public QFrame
{
Q_OBJECT

public:
/**
* Constructor.
*
* @param parent - the parent widget
*/
explicit GateLibraryManager(QWidget* parent = nullptr);

/**
* Reinitializes the appearance of the widget and its children.
*/
void repolish();

bool initialize(GateLibrary* gateLibrary = nullptr);


private:
QGridLayout* mLayout;

QTableView* mTableView;

GateLibrary* mGateLibrary;
};
}
6 changes: 4 additions & 2 deletions plugins/gui/include/gui/main_window/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QSplitter>
#include <QStackedWidget>
#include <QToolBar>
#include <gui/gatelibrary_management/gatelibrary_manager.h>

namespace hal
{
Expand Down Expand Up @@ -603,6 +604,7 @@ namespace hal
MainSettingsWidget* mSettings;
GuiPluginManager* mPluginManager;
WelcomeScreen* mWelcomeScreen;
GateLibraryManager* mGateLibraryManager;
QHBoxLayout* mToolBarLayout;
QToolBar* mLeftToolBar;
QToolBar* mRightToolBar;
Expand All @@ -613,7 +615,7 @@ namespace hal
Action* mActionImportNetlist;
Action* mActionSave;
Action* mActionSaveAs;
// Action* mActionGateLibraryManager;
Action* mActionGateLibraryManager;
Action* mActionAbout;
Action* mActionStartRecording;
Action* mActionStopRecording;
Expand Down Expand Up @@ -665,7 +667,7 @@ namespace hal
QString mUndoIconPath;
QString mUndoIconStyle;

QString mDisabledIconStyle;
QString mDisabledIconStyle;

SettingsItemKeybind* mSettingCreateFile;
SettingsItemKeybind* mSettingOpenFile;
Expand Down
67 changes: 67 additions & 0 deletions plugins/gui/src/gatelibrary_management/gatelibrary_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "gui/gatelibrary_management/gatelibrary_manager.h"

#include "gui/frames/labeled_frame.h"
#include "gui/graphics_effects/shadow_effect.h"
#include "gui/plugin_relay/gui_plugin_manager.h"
#include "gui/welcome_screen/open_file_widget.h"
#include "hal_core/netlist/gate_library/gate_library_manager.h"
#include "hal_core/plugin_system/fac_extension_interface.h"

#include <QDebug>
#include <QDir>
#include <QFileDialog>

#include <gui/gui_globals.h>

#include <QTableWidget>
namespace hal
{
GateLibraryManager::GateLibraryManager(QWidget* parent)
: QFrame(parent), mLayout(new QGridLayout()), mTableView(new QTableView())
{
//TODO create layout and widgets




repolish(); // CALL FROM PARENT
}

void GateLibraryManager::repolish()
{
QStyle* s = style();

s->unpolish(this);
s->polish(this);
}
bool GateLibraryManager::initialize(GateLibrary* gateLibrary)
{
if(!gateLibrary)
{
//TODO Check if a gate library is already in use
// if yes then open it in read-only mode
// else open file dialog and select one to parse

QString title = "Load gate library";
QString text = "HAL Gate Library (*.hgl *.lib)";
QString path = QDir::currentPath();

//TODO fileDialog throws bad window error
QString fileName = QFileDialog::getOpenFileName(nullptr, title, path, text, nullptr);
if(fileName == nullptr)
return false;

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 elem : gateLibrary->get_gate_types())
{
qInfo() << QString::fromStdString(elem.second->get_name());
}
}
mGateLibrary = gateLibrary;
return true;
}
}
37 changes: 26 additions & 11 deletions plugins/gui/src/main_window/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#include <QDesktopWidget>
#include <QDir>
#include <QFileDialog>
#include <QFuture>
#include <QInputDialog>
#include <QMessageBox>
#include <QPushButton>
Expand All @@ -53,6 +52,7 @@
#include <QStringList>
#include <QtConcurrent>


namespace hal
{
const char* MSG_PROJECT_ALREADY_OPEN = "You are already working on a HAL project. Close current project first.";
Expand Down Expand Up @@ -131,6 +131,9 @@ namespace hal

mWelcomeScreen = new WelcomeScreen();
mStackedWidget->addWidget(mWelcomeScreen);
mGateLibraryManager = new GateLibraryManager();
mStackedWidget->addWidget(mGateLibraryManager);

mStackedWidget->setCurrentWidget(mWelcomeScreen);

setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
Expand All @@ -142,7 +145,7 @@ namespace hal
mActionSaveAs = new Action(this);
mActionExportProject = new Action(this);
mActionImportProject = new Action(this);
// mActionGateLibraryManager = new Action(this);
mActionGateLibraryManager = new Action(this);
mActionAbout = new Action(this);

mActionStartRecording = new Action(this);
Expand Down Expand Up @@ -188,7 +191,7 @@ namespace hal
mActionSaveAs->setIcon(gui_utility::getStyledSvgIcon(mSaveAsIconStyle, mSaveAsIconPath));
mActionClose->setIcon(gui_utility::getStyledSvgIcon(mCloseIconStyle, mCloseIconPath));
mActionQuit->setIcon(gui_utility::getStyledSvgIcon(mQuitIconStyle, mQuitIconPath));
// mActionGateLibraryManager->setIcon(gui_utility::getStyledSvgIcon(mSaveAsIconStyle, mSaveAsIconPath));
mActionGateLibraryManager->setIcon(gui_utility::getStyledSvgIcon(mSaveAsIconStyle, mSaveAsIconPath));
mActionUndo->setIcon(gui_utility::getStyledSvgIcon(mUndoIconStyle, mUndoIconPath));
mActionSettings->setIcon(gui_utility::getStyledSvgIcon(mSettingsIconStyle, mSettingsIconPath));
mActionPlugins->setIcon(gui_utility::getStyledSvgIcon(mPluginsIconStyle, mPluginsIconPath));
Expand All @@ -207,7 +210,7 @@ namespace hal
mMenuFile->addAction(mActionClose);
mMenuFile->addAction(mActionSave);
mMenuFile->addAction(mActionSaveAs);
// mMenuFile->addAction(mActionGateLibraryManager);
mMenuFile->addAction(mActionGateLibraryManager);

QMenu* menuImport = new QMenu("Import …", this);
menuImport->addAction(mActionImportNetlist);
Expand Down Expand Up @@ -272,6 +275,7 @@ namespace hal
mLeftToolBar->addAction(mActionUndo);
mRightToolBar->addAction(mActionPlugins);
mRightToolBar->addAction(mActionSettings);
mRightToolBar->addAction(mActionGateLibraryManager);

mActionStartRecording->setText("Start recording");
mActionStopRecording->setText("Stop recording");
Expand All @@ -289,7 +293,7 @@ namespace hal
mActionImportNetlist->setText("Import Netlist");
mActionImportProject->setText("Import Project");
mActionExportProject->setText("Export Project");
// mActionGateLibraryManager->setText("Gate Library Manager");
mActionGateLibraryManager->setText("Gate Library Manager");
mActionUndo->setText("Undo");
mActionAbout->setText("About");
mActionSettings->setText("Settings");
Expand Down Expand Up @@ -342,7 +346,7 @@ namespace hal
connect(mActionSaveAs, &Action::triggered, this, &MainWindow::handleSaveAsTriggered);
connect(mActionExportProject, &Action::triggered, this, &MainWindow::handleExportProjectTriggered);
connect(mActionImportProject, &Action::triggered, this, &MainWindow::handleImportProjectTriggered);
// connect(mActionGateLibraryManager, &Action::triggered, this, &MainWindow::handleActionGatelibraryManager);
connect(mActionGateLibraryManager, &Action::triggered, this, &MainWindow::handleActionGatelibraryManager);
connect(mActionClose, &Action::triggered, this, &MainWindow::handleActionCloseFile);
connect(mActionQuit, &Action::triggered, this, &MainWindow::onActionQuitTriggered);

Expand Down Expand Up @@ -639,7 +643,7 @@ namespace hal
void MainWindow::openSettings()
{
if (mStackedWidget->currentWidget() == mSettings)
return; //nothing todo, already open
return; //nothing todo, already fetchGateLibrary

mSettings->activate();
mStackedWidget->setCurrentWidget(mSettings);
Expand All @@ -659,7 +663,7 @@ namespace hal
{
mPluginManager->repolish();
if (mStackedWidget->currentWidget() == mPluginManager)
return; //nothing todo, already open
return; //nothing todo, already fetchGateLibrary

if (mStackedWidget->currentWidget() == mSettings)
{
Expand Down Expand Up @@ -806,8 +810,19 @@ namespace hal

void MainWindow::handleActionGatelibraryManager()
{
GatelibraryManagementDialog dialog;
dialog.exec();
/**
* TODO
* check if netlist is already loaded
* if yes then skip file dialog and fetchGateLibrary GateLibraryManager in read-only mode
* else open file-dialog and search for suitable files and then fetchGateLibrary GateLibraryManager
*/

if(mGateLibraryManager->initialize())
mStackedWidget->setCurrentWidget(mGateLibraryManager);
/*previous reference code*/

//GatelibraryManagementDialog dialog;
//dialog.exec();
}

void MainWindow::handleImportProjectTriggered()
Expand All @@ -825,7 +840,7 @@ namespace hal
QMessageBox::warning(this,
"Import Project Failed",
"Failed to extract a HAL project from selected archive file.\n"
"You might want to uncompress the archive manually and try to open the project.");
"You might want to uncompress the archive manually and try to fetchGateLibrary the project.");
}
}

Expand Down

0 comments on commit 9e361dc

Please sign in to comment.