HAL  v4.5.0-147-gff98e36c6
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
import_netlist_dialog.cpp
Go to the documentation of this file.
2 
6 
7 #include <QCheckBox>
8 #include <QDebug>
9 #include <QDialogButtonBox>
10 #include <QFile>
11 #include <QFileDialog>
12 #include <QGridLayout>
13 #include <QJsonDocument>
14 #include <QJsonObject>
15 #include <QLabel>
16 #include <QLineEdit>
17 #include <QPushButton>
18 #include <QSpacerItem>
19 #include <QStyle>
20 
21 namespace hal
22 {
24  {
25  QStyle* s = style();
26  s->unpolish(this);
27  s->polish(this);
28  QString gatelibFromHal;
29  if (filename.endsWith(".hal"))
30  {
31  QFile halFile(filename);
32  if (halFile.open(QIODevice::ReadOnly))
33  {
34  QJsonDocument halDoc = QJsonDocument::fromJson(halFile.readAll());
35  const QJsonObject& halObj = halDoc.object();
36  if (halObj.contains("netlist") && halObj["netlist"].isObject())
37  {
38  const QJsonObject& nlObj = halObj["netlist"].toObject();
39  if (nlObj.contains("gate_library") && nlObj["gate_library"].isString())
40  gatelibFromHal = nlObj["gate_library"].toString();
41  }
42  }
43  }
44 
45  int irow = 0;
46  QGridLayout* layout = new QGridLayout(this);
47  setWindowTitle("Netlist Import");
48  layout->addWidget(new QLabel("Create new HAL project from netlist file\n'" + filename + "'.", this), irow++, 0, Qt::AlignLeft);
49  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
50  layout->setRowStretch(irow - 1, 20);
51 
52  layout->addWidget(new QLabel("Location of project directory:", this), irow++, 0, Qt::AlignLeft);
53  mProjectdir = ImportProjectDialog::suggestedProjectDir(filename);
54 
55  QFrame* frameProjectdir = new QFrame(this);
56  QHBoxLayout* layProjectdir = new QHBoxLayout(frameProjectdir);
57  mEditProjectdir = new QLineEdit(mProjectdir, frameProjectdir);
58  layProjectdir->addWidget(mEditProjectdir);
59  QPushButton* butFiledialog = new QPushButton(gui_utility::getStyledSvgIcon(mSaveIconStyle, mSaveIconPath), "", frameProjectdir);
60  connect(butFiledialog, &QPushButton::clicked, this, &ImportNetlistDialog::handleFileDialogTriggered);
61  layProjectdir->addWidget(butFiledialog);
63  layout->addWidget(frameProjectdir, irow++, 0);
64  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
65 
66  mGatelibSelection = new GateLibrarySelection(gatelibFromHal, this);
67  layout->addWidget(mGatelibSelection, irow++, 0);
68  //mGatelibSelection->setDisabled(filename.endsWith(".hal"));
69 
70  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
71  layout->setRowStretch(irow - 1, 20);
72  mCheckMoveNetlist = new QCheckBox("Move imported netlist into project directory");
73  layout->addWidget(mCheckMoveNetlist, irow++, 0, Qt::AlignLeft);
74  mCheckCopyGatelib = new QCheckBox("Copy gate library into project directory");
75  layout->addWidget(mCheckCopyGatelib, irow++, 0, Qt::AlignLeft);
76  connect(mGatelibSelection, &GateLibrarySelection::gatelibSelected, this, &ImportNetlistDialog::handleGatelibSelected);
77  handleGatelibSelected(!mGatelibSelection->gateLibraryPath().isEmpty());
78  layout->addItem(new QSpacerItem(30, 30), irow++, 0);
79  layout->setRowStretch(irow - 1, 100);
83  layout->addWidget(dbb, irow++, 0, Qt::AlignRight);
84  }
85 
87  {
88  return mEditProjectdir->text();
89  }
90 
91  void ImportNetlistDialog::handleFileDialogTriggered()
92  {
93  QString dir = QFileDialog::getSaveFileName(this, "Enter new project directory", QFileInfo(mProjectdir).path(), "", nullptr, QFileDialog::ShowDirsOnly);
94  if (dir.isEmpty())
95  return;
96  mEditProjectdir->setText(dir);
97  }
98 
99  void ImportNetlistDialog::handleGatelibSelected(bool singleFile)
100  {
101  if (singleFile)
102  {
103  mCheckCopyGatelib->setEnabled(true);
104  }
105  else
106  {
107  mCheckCopyGatelib->setCheckState(Qt::Unchecked);
108  mCheckCopyGatelib->setDisabled(true);
109  }
110  }
111 
113  {
114  return mGatelibSelection->gateLibraryPath();
115  }
116 
118  {
119  return mCheckMoveNetlist->isChecked();
120  }
121 
123  {
124  return mCheckCopyGatelib->isChecked();
125  }
126 
127 } // namespace hal
void gatelibSelected(bool singleFile)
ImportNetlistDialog(const QString &filename, QWidget *parent=nullptr)
static QString suggestedProjectDir(const QString &filename)
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
Definition: defines.h:45
bool isChecked() const const
void clicked(bool checked)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setCheckState(Qt::CheckState state)
virtual void accept()
virtual void reject()
virtual bool open(QIODevice::OpenMode mode) override
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QByteArray readAll()
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
QJsonObject object() const const
bool contains(const QString &key) const const
virtual void addItem(QLayoutItem *item)=0
void addWidget(QWidget *w)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
virtual void polish(QWidget *widget)
virtual void unpolish(QWidget *widget)
AlignLeft
Unchecked
Horizontal
void setEnabled(bool)
QLayout * layout() const const
void setDisabled(bool disable)
void setSizePolicy(QSizePolicy)
QStyle * style() const const
void setWindowTitle(const QString &)