Skip to content

Commit ec21079

Browse files
committed
fix new netlist bug
1 parent 76376ba commit ec21079

File tree

12 files changed

+352
-43
lines changed

12 files changed

+352
-43
lines changed

plugins/gui/include/gui/file_manager/file_manager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ namespace hal
165165
*/
166166
void importFile(QString filename);
167167

168+
/**
169+
* Creates a new empty hal project
170+
*/
171+
void newProject();
168172

169173
/**
170174
* Opens the given project.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4+
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
24+
#pragma once
25+
26+
#include <QDialog>
27+
#include <QString>
28+
#include <QList>
29+
#include <QMap>
30+
31+
class QComboBox;
32+
class QCheckBox;
33+
class QLineEdit;
34+
35+
namespace hal {
36+
37+
class NewProjectDialog : public QDialog
38+
{
39+
Q_OBJECT
40+
Q_PROPERTY(QString saveIconPath READ saveIconPath WRITE setSaveIconPath)
41+
Q_PROPERTY(QString saveIconStyle READ saveIconStyle WRITE setSaveIconStyle)
42+
QString mProjectdir;
43+
QLineEdit* mEditProjectdir;
44+
QComboBox* mComboGatelib;
45+
QCheckBox* mCheckCopyGatelib;
46+
47+
QStringList mGateLibraryPath;
48+
QMap<QString,int> mGateLibraryMap;
49+
QString mSaveIconPath;
50+
QString mSaveIconStyle;
51+
private Q_SLOTS:
52+
void handleGateLibraryPathChanged(const QString& txt);
53+
void handleFileDialogTriggered();
54+
public:
55+
NewProjectDialog(QWidget* parent = nullptr);
56+
QString projectDirectory() const;
57+
QString gateLibraryPath() const;
58+
bool isCopyGatelibChecked() const;
59+
QString saveIconPath() const { return mSaveIconPath; }
60+
QString saveIconStyle() const { return mSaveIconStyle; }
61+
void setSaveIconPath(const QString& path) { mSaveIconPath = path; }
62+
void setSaveIconStyle(const QString& sty) { mSaveIconStyle = sty; }
63+
};
64+
}

plugins/gui/include/gui/user_action/action_open_netlist_file.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ namespace hal
3434
*/
3535
class ActionOpenNetlistFile : public UserAction
3636
{
37+
public:
38+
enum OpenMethod { Undefined, CreateNew, ImportFile, OpenProject };
39+
private:
3740
QString mFilename;
38-
bool mProject;
41+
OpenMethod mMethod;
3942
public:
4043
/**
4144
* Action constructor.
4245
*
4346
* @param filename_ - The path of the netlist file to open.
4447
*/
45-
ActionOpenNetlistFile(const QString& filename_ = QString(), bool isProj = true);
48+
ActionOpenNetlistFile(OpenMethod method = Undefined, const QString& filename_ = QString());
4649
QString tagname() const override;
4750
bool exec() override;
4851
void writeToXml(QXmlStreamWriter& xmlOut) const override;

plugins/gui/include/gui/welcome_screen/recent_file_item.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#pragma once
2525

2626
#include <QFrame>
27+
#include "gui/user_action/action_open_netlist_file.h"
2728

2829
class QHBoxLayout;
2930
class QLabel;
@@ -149,7 +150,7 @@ namespace hal
149150

150151
bool mHover;
151152
bool mMissing;
152-
bool mProject;
153+
ActionOpenNetlistFile::OpenMethod mMethod;
153154

154155
QString mIconPath;
155156
QString mIconStyle;

plugins/gui/resources/stylesheet/dark.qss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,18 @@ hal--ImportNetlistDialog QWidget:disabled
896896
background: #2a2a2a;
897897
}
898898

899+
hal--NewProjectDialog
900+
{
901+
qproperty-saveIconStyle: "all->#3192C5";
902+
qproperty-saveIconPath: ":/icons/folder-down";
903+
}
904+
905+
hal--NewProjectDialog QWidget:disabled
906+
{
907+
color: #777777;
908+
background: #2a2a2a;
909+
}
910+
899911
hal--GetInTouchWidget
900912
{
901913
background : rgb(14, 16, 18);

plugins/gui/resources/stylesheet/light.qss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,30 @@ hal--OpenFileWidget #icon-label
907907
margin-top : 220px;
908908
}
909909

910+
hal--ImportNetlistDialog
911+
{
912+
qproperty-saveIconStyle: "all->#3192C5";
913+
qproperty-saveIconPath: ":/icons/folder-down";
914+
}
915+
916+
hal--ImportNetlistDialog QWidget:disabled
917+
{
918+
color: #777777;
919+
background: #2a2a2a;
920+
}
921+
922+
hal--NewProjectDialog
923+
{
924+
qproperty-saveIconStyle: "all->#3192C5";
925+
qproperty-saveIconPath: ":/icons/folder-down";
926+
}
927+
928+
hal--NewProjectDialog QWidget:disabled
929+
{
930+
color: #777777;
931+
background: #2a2a2a;
932+
}
933+
910934
hal--GetInTouchWidget
911935
{
912936
background : rgb(219, 219, 219);

plugins/gui/src/file_manager/file_manager.cpp

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#include "hal_core/netlist/netlist_factory.h"
66
#include "hal_core/netlist/persistent/netlist_serializer.h"
77
#include "hal_core/netlist/netlist_parser/netlist_parser_manager.h"
8+
#include "hal_core/netlist/gate_library/gate_library_manager.h"
89
#include "hal_core/utilities/log.h"
910
#include "hal_core/netlist/project_manager.h"
1011
#include "hal_core/utilities/project_directory.h"
11-
1212
#include "gui/settings/settings_items/settings_item_checkbox.h"
1313
#include "gui/settings/settings_items/settings_item_spinbox.h"
1414
#include "gui/file_manager/import_netlist_dialog.h"
15+
#include "gui/file_manager/new_project_dialog.h"
1516

1617
#include <QDateTime>
1718
#include <QFile>
@@ -191,6 +192,63 @@ namespace hal
191192

192193
}
193194

195+
void FileManager::newProject()
196+
{
197+
NewProjectDialog npr(qApp->activeWindow());
198+
if (npr.exec() != QDialog::Accepted) return;
199+
200+
QString projdir = npr.projectDirectory();
201+
if (projdir.isEmpty()) return;
202+
203+
QString gatelib = npr.gateLibraryPath();
204+
if (gatelib.isEmpty())
205+
{
206+
QMessageBox::warning(qApp->activeWindow(),"Aborted", "Cannot create project <" + projdir + ">, no gate library selected");
207+
return;
208+
}
209+
GateLibrary* glib = gate_library_manager::load(gatelib.toStdString());
210+
if (!glib)
211+
{
212+
QMessageBox::warning(qApp->activeWindow(),"Aborted", "Cannot create project <" + projdir + ">, cannot load gate library <" + gatelib + ">");
213+
return;
214+
}
215+
216+
ProjectManager* pm = ProjectManager::instance();
217+
if (!pm->create_project_directory(projdir.toStdString()))
218+
{
219+
QMessageBox::warning(qApp->activeWindow(),"Aborted", "Error creating project directory <" + projdir + ">");
220+
return;
221+
}
222+
223+
QDir projectDir(projdir);
224+
QString netlistFilename = QString::fromStdString(pm->get_netlist_filename());
225+
if (npr.isCopyGatelibChecked())
226+
{
227+
QFileInfo glInfo(gatelib);
228+
QString targetGateLib = projectDir.absoluteFilePath(glInfo.fileName());
229+
if (QFile::copy(gatelib,targetGateLib))
230+
gatelib = targetGateLib;
231+
}
232+
233+
std::filesystem::path lpath = pm->get_project_directory().get_default_filename(".log");
234+
LogManager::get_instance()->set_file_name(lpath);
235+
236+
gNetlistOwner = netlist_factory::create_netlist(glib);
237+
gNetlist = gNetlistOwner.get();
238+
239+
if (!gNetlist)
240+
{
241+
QMessageBox::warning(qApp->activeWindow(),"Aborted", "Failed to create <" + projdir + "> with gate library <" + gatelib + ">");
242+
return;
243+
}
244+
gNetlistRelay->registerNetlistCallbacks();
245+
gFileStatusManager->netlistChanged();
246+
if (pm->serialize_project(gNetlist))
247+
gFileStatusManager->netlistSaved();
248+
projectSuccessfullyLoaded(projdir,netlistFilename);
249+
log_info("gui", "Created empty project '{}' with gate library '{}'.", projdir.toStdString(), gatelib.toStdString());
250+
}
251+
194252
void FileManager::importFile(QString filename)
195253
{
196254
// check whether there is already a project with the same name as file-to-be-imported

plugins/gui/src/file_manager/import_netlist_dialog.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
#include <QRegularExpression>
2121
#include <QSpacerItem>
2222

23-
QLineEdit* mEditProjectdir;
24-
QComboBox* mComboGatelib;
25-
QCheckBox* mCheckMoveNetlist;
26-
2723
namespace hal
2824
{
2925
ImportNetlistDialog::ImportNetlistDialog(const QString& filename, QWidget* parent) : QDialog(parent)
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#include "gui/file_manager/new_project_dialog.h"
2+
3+
#include "gui/gui_utils/graphics.h"
4+
#include "hal_core/netlist/gate_library/gate_library.h"
5+
#include "hal_core/netlist/gate_library/gate_library_manager.h"
6+
7+
#include <QCheckBox>
8+
#include <QComboBox>
9+
#include <QDebug>
10+
#include <QDialogButtonBox>
11+
#include <QFile>
12+
#include <QFileDialog>
13+
#include <QFileInfo>
14+
#include <QGridLayout>
15+
#include <QJsonDocument>
16+
#include <QJsonObject>
17+
#include <QLabel>
18+
#include <QLineEdit>
19+
#include <QPushButton>
20+
#include <QRegularExpression>
21+
#include <QSpacerItem>
22+
#include <QDir>
23+
24+
QLineEdit* mEditProjectdir;
25+
QComboBox* mComboGatelib;
26+
27+
namespace hal
28+
{
29+
NewProjectDialog::NewProjectDialog(QWidget* parent) : QDialog(parent)
30+
{
31+
QStyle* s = style();
32+
s->unpolish(this);
33+
s->polish(this);
34+
QString suggestedGateLibraryPath;
35+
QString suggestedGateLibraryName;
36+
37+
int suggestedProjectCount = 0;
38+
do {
39+
++ suggestedProjectCount;
40+
mProjectdir = QDir::current().absoluteFilePath(QString("hal_project_%1").arg(suggestedProjectCount));
41+
} while (QFileInfo(mProjectdir).exists());
42+
43+
int irow = 0;
44+
QGridLayout* layout = new QGridLayout(this);
45+
setWindowTitle("Netlist Import");
46+
layout->addWidget(new QLabel("Create new empty HAL project:", this), irow++, 0, Qt::AlignLeft);
47+
layout->addItem(new QSpacerItem(30, 30), irow++, 0);
48+
layout->setRowStretch(irow - 1, 20);
49+
50+
layout->addWidget(new QLabel("Location of project directory:", this), irow++, 0, Qt::AlignLeft);
51+
QFrame* frameProjectdir = new QFrame(this);
52+
QHBoxLayout* layProjectdir = new QHBoxLayout(frameProjectdir);
53+
mEditProjectdir = new QLineEdit(mProjectdir, frameProjectdir);
54+
layProjectdir->addWidget(mEditProjectdir);
55+
QPushButton* butFiledialog = new QPushButton(gui_utility::getStyledSvgIcon(mSaveIconStyle, mSaveIconPath), "", frameProjectdir);
56+
connect(butFiledialog, &QPushButton::clicked, this, &NewProjectDialog::handleFileDialogTriggered);
57+
layProjectdir->addWidget(butFiledialog);
58+
mEditProjectdir->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
59+
layout->addWidget(frameProjectdir, irow++, 0);
60+
layout->addItem(new QSpacerItem(30, 30), irow++, 0);
61+
62+
QLabel* labGatelib = new QLabel("Gate library:", this);
63+
layout->addWidget(labGatelib, irow++, 0, Qt::AlignLeft);
64+
mComboGatelib = new QComboBox(this);
65+
mComboGatelib->addItem(QString());
66+
for (const std::filesystem::path path : gate_library_manager::get_all_path())
67+
{
68+
int n = mGateLibraryPath.size();
69+
QString qName = QString::fromStdString(path.filename());
70+
mGateLibraryMap.insert(qName, n);
71+
QString qPath = QString::fromStdString(path.string());
72+
mGateLibraryPath.append(qPath);
73+
if (qPath == suggestedGateLibraryPath)
74+
suggestedGateLibraryName = qName;
75+
}
76+
if (suggestedGateLibraryName.isEmpty() && !suggestedGateLibraryPath.isEmpty())
77+
{
78+
// suggested gate library not found in default path
79+
QFileInfo info(suggestedGateLibraryPath);
80+
suggestedGateLibraryName = info.fileName();
81+
int n = mGateLibraryPath.size();
82+
mGateLibraryMap.insert(suggestedGateLibraryName, n);
83+
mGateLibraryPath.append(suggestedGateLibraryPath);
84+
}
85+
mComboGatelib->addItems(mGateLibraryMap.keys());
86+
if (!suggestedGateLibraryName.isEmpty())
87+
mComboGatelib->setCurrentText(suggestedGateLibraryName);
88+
89+
mComboGatelib->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
90+
layout->addWidget(mComboGatelib, irow++, 0);
91+
92+
layout->addItem(new QSpacerItem(30, 30), irow++, 0);
93+
layout->setRowStretch(irow - 1, 20);
94+
mCheckCopyGatelib = new QCheckBox("Copy gate library into project directory");
95+
layout->addWidget(mCheckCopyGatelib, irow++, 0, Qt::AlignLeft);
96+
layout->addItem(new QSpacerItem(30, 30), irow++, 0);
97+
layout->setRowStretch(irow - 1, 100);
98+
QDialogButtonBox* dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
99+
connect(dbb, &QDialogButtonBox::accepted, this, &QDialog::accept);
100+
connect(dbb, &QDialogButtonBox::rejected, this, &QDialog::reject);
101+
layout->addWidget(dbb, irow++, 0, Qt::AlignRight);
102+
connect(mComboGatelib, &QComboBox::currentTextChanged, this, &NewProjectDialog::handleGateLibraryPathChanged);
103+
handleGateLibraryPathChanged(mComboGatelib->currentText());
104+
}
105+
106+
QString NewProjectDialog::projectDirectory() const
107+
{
108+
return mEditProjectdir->text();
109+
}
110+
111+
void NewProjectDialog::handleFileDialogTriggered()
112+
{
113+
QString dir = QFileDialog::getSaveFileName(this, "Enter new project directory", QFileInfo(mProjectdir).path(), "", nullptr, QFileDialog::ShowDirsOnly);
114+
if (dir.isEmpty())
115+
return;
116+
mEditProjectdir->setText(dir);
117+
}
118+
119+
void NewProjectDialog::handleGateLibraryPathChanged(const QString& txt)
120+
{
121+
if (mGateLibraryMap.value(txt, -1) < 0)
122+
{
123+
mCheckCopyGatelib->setCheckState(Qt::Unchecked);
124+
mCheckCopyGatelib->setDisabled(true);
125+
}
126+
else
127+
mCheckCopyGatelib->setEnabled(true);
128+
}
129+
130+
QString NewProjectDialog::gateLibraryPath() const
131+
{
132+
QString seltxt = mComboGatelib->currentText();
133+
int inx = mGateLibraryMap.value(seltxt, -1);
134+
if (inx < 0)
135+
return QString();
136+
return mGateLibraryPath.at(inx);
137+
}
138+
139+
bool NewProjectDialog::isCopyGatelibChecked() const
140+
{
141+
return mCheckCopyGatelib->isChecked();
142+
}
143+
} // namespace hal

0 commit comments

Comments
 (0)