Skip to content

Commit

Permalink
Initial implementaion of description label
Browse files Browse the repository at this point in the history
  • Loading branch information
KochynVolodymyr committed Aug 24, 2023
1 parent 1370d1e commit e0bd2e8
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 38 deletions.
25 changes: 25 additions & 0 deletions src/IPGenerate/IPCatalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <sys/types.h>

#include <QDebug>
#include <QFile>
#include <QProcess>
#include <chrono>
#include <ctime>
Expand All @@ -37,6 +38,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "MainWindow/Session.h"
#include "Utils/FileUtils.h"
#include "Utils/StringUtils.h"
#include "nlohmann_json/json.hpp"
using json = nlohmann::ordered_json;

extern FOEDAG::Session* GlobalSession;
using namespace FOEDAG;
Expand Down Expand Up @@ -116,3 +119,25 @@ std::filesystem::path IPCatalog::getPythonPath() {
}
return s_pythonPath;
}

IPDetails FOEDAG::readIpDetails(const std::filesystem::path& path) {
IPDetails details;
QFile file{QString::fromStdString(path.string())};
if (!file.open(QFile::ReadOnly)) return details;
QString content = file.readAll();
json object;
try {
object = json::parse(content.toStdString());
} catch (std::exception& e) {
return details;
}

if (object.contains("IP details")) {
auto ip_details = object.at("IP details");
details.name = ip_details["Name"];
details.description = ip_details["Description"];
details.interface = ip_details["Interface"];
details.version = ip_details["Version"];
}
return details;
}
18 changes: 16 additions & 2 deletions src/IPGenerate/IPCatalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,31 +261,36 @@ class IPDefinition {
const std::string& build_name,
const std::filesystem::path& filePath,
const std::vector<Connector*>& connections,
const std::vector<Value*>& parameters)
const std::vector<Value*>& parameters,
const std::filesystem::path& detailsPath)
: m_type(type),
m_name(name),
m_build_name(build_name),
m_filePath(filePath),
m_detailsPath(detailsPath),
m_connections(connections),
m_parameters(parameters){};
void apply(IPType type, const std::string& name,
const std::string& build_name,
const std::filesystem::path& filePath,
const std::vector<Connector*>& connections,
const std::vector<Value*>& parameters) {
const std::vector<Value*>& parameters,
const std::filesystem::path& detailsPath) {
m_type = type;
m_name = name;
m_build_name = build_name;
m_filePath = filePath;
m_connections = connections;
m_parameters = parameters;
m_detailsPath = detailsPath;
}
~IPDefinition() {}
IPType Type() const { return m_type; }
const std::string& Name() const { return m_name; }
const std::string& BuildName() const { return m_build_name; }
const std::vector<Connector*>& Connections() const { return m_connections; }
const std::filesystem::path FilePath() const { return m_filePath; }
const std::filesystem::path FileDetailsPath() const { return m_detailsPath; }
const std::vector<Value*> Parameters() const { return m_parameters; }
bool Valid() const { return m_valid; }
void Valid(bool valid) { m_valid = valid; }
Expand All @@ -295,6 +300,7 @@ class IPDefinition {
std::string m_name;
std::string m_build_name;
std::filesystem::path m_filePath;
std::filesystem::path m_detailsPath;
std::vector<Connector*> m_connections;
std::vector<Value*> m_parameters;
bool m_valid{true};
Expand Down Expand Up @@ -355,7 +361,15 @@ struct VLNV {
std::string version;
};

struct IPDetails {
std::string name;
std::string version;
std::string interface;
std::string description;
};

VLNV getIpInfoFromPath(std::filesystem::path path);
IPDetails readIpDetails(const std::filesystem::path& path);

} // namespace FOEDAG

Expand Down
17 changes: 9 additions & 8 deletions src/IPGenerate/IPCatalogBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ void buildMockUpIPDef(IPCatalog* catalog) {
Port* port = new Port("clk", Port::Direction::Input, Port::Function::Clock,
Port::Polarity::High, range);
connections.push_back(port);
IPDefinition* def = new IPDefinition(IPDefinition::IPType::Other, "MOCK_IP",
"MOCK_IP_wrapper", "path_to_nowhere",
connections, parameters);
IPDefinition* def = new IPDefinition(
IPDefinition::IPType::Other, "MOCK_IP", "MOCK_IP_wrapper",
"path_to_nowhere", connections, parameters, "ip_details.json");
catalog->addIP(def);
// catalog->WriteCatalog(std::cout);
}
Expand Down Expand Up @@ -283,12 +283,13 @@ bool IPCatalogBuilder::buildLiteXIPFromJson(
auto def = catalog->Definition(IPName);
if (def) {
def->apply(IPDefinition::IPType::LiteXGenerator, IPName, build_name,
pythonConverterScript, connections, parameters);
pythonConverterScript, connections, parameters,
"ip_Details.json");
def->Valid(true);
} else {
IPDefinition* def = new IPDefinition(
IPDefinition::IPType::LiteXGenerator, IPName, build_name,
pythonConverterScript, connections, parameters);
pythonConverterScript, connections, parameters, "ip_Details.json");
catalog->addIP(def);
}
return true;
Expand All @@ -315,9 +316,9 @@ bool IPCatalogBuilder::buildLiteXIPFromGeneratorInternal(
auto info = FOEDAG::getIpInfoFromPath(pythonConverterScript);
IPName += "_" + info.version;

IPDefinition* def =
new IPDefinition(IPDefinition::IPType::LiteXGenerator, IPName,
std::string{}, pythonConverterScript, {}, {});
IPDefinition* def = new IPDefinition(
IPDefinition::IPType::LiteXGenerator, IPName, std::string{},
pythonConverterScript, {}, {}, std::string{});
def->Valid(false);
catalog->addIP(def);
return result;
Expand Down
2 changes: 2 additions & 0 deletions src/IpConfigurator/IpCatalogTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ IpCatalogTree::IpCatalogTree(QWidget* parent /*nullptr*/)
refresh();
connect(this, &QTreeWidget::itemSelectionChanged, this,
&IpCatalogTree::itemSelectionHasChanged);
connect(this, &QTreeWidget::itemDoubleClicked, this,
&IpCatalogTree::openIpSettings);
}

void IpCatalogTree::refresh() {
Expand Down
1 change: 1 addition & 0 deletions src/IpConfigurator/IpCatalogTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class IpCatalogTree : public QTreeWidget {

signals:
void ipReady();
void openIpSettings();

private slots:
void itemSelectionHasChanged();
Expand Down
64 changes: 41 additions & 23 deletions src/IpConfigurator/IpConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ IpConfigWidget::IpConfigWidget(QWidget* parent /*nullptr*/,
m_baseDirDefault{getUserProjectPath("IPs")},
m_requestedIpName(requestedIpName),
m_instanceValueArgs(instanceValueArgs) {
this->setWindowTitle("Configure IP");
this->setWindowTitle("IP Description/Details");
this->setObjectName("IpConfigWidget");

// Set the path related widgets' tooltips to whatever their text is so long
Expand Down Expand Up @@ -106,23 +106,23 @@ IpConfigWidget::IpConfigWidget(QWidget* parent /*nullptr*/,

// Fill and add Parameters box
CreateParamFields(true);
containerLayout->addWidget(paramsBox);
// containerLayout->addWidget(paramsBox);

// Add Output Box
CreateOutputFields();
containerLayout->addWidget(&outputBox);
containerLayout->addStretch();
// containerLayout->addWidget(&outputBox);
// containerLayout->addStretch();
// Update the module name if one was passed (this occurs during a
// re-configure)
if (!moduleName.isEmpty()) {
moduleEdit.setText(moduleName);
}

// Add Dialog Buttons
AddDialogControls(topLayout);
// AddDialogControls(topLayout);

// Update output path now that meta data has been loaded
updateOutputPath();
// updateOutputPath();

// run with --json --json-template parameters to get default GUI
if (!requestedIpName.isEmpty()) handleEditorChanged({}, nullptr);
Expand Down Expand Up @@ -193,6 +193,7 @@ void IpConfigWidget::CreateParamFields(bool generateMetaLabel) {
if (m_requestedIpName.toStdString() == def->Name()) {
// Store VLNV meta data for the requested IP
m_meta = FOEDAG::getIpInfoFromPath(def->FilePath());
m_details = FOEDAG::readIpDetails(def->FileDetailsPath());

if (generateMetaLabel) {
// set default module name to the BuildName provided by the generate
Expand All @@ -204,10 +205,11 @@ void IpConfigWidget::CreateParamFields(bool generateMetaLabel) {
moduleEdit.setText(QString::fromStdString(build_name));

// Update meta label now that vlnv and module info is updated
updateMetaLabel(m_meta);
updateMetaLabel(m_details);
}

// Build widget factory json for each parameter
/*
for (auto paramVal : def->Parameters()) {
if (paramVal->GetType() == Value::Type::ParamIpVal) {
IPParameter* param = static_cast<IPParameter*>(paramVal);
Expand Down Expand Up @@ -277,6 +279,7 @@ void IpConfigWidget::CreateParamFields(bool generateMetaLabel) {
QString::fromStdString(param->Name()), valNoSpaces);
}
}
*/
}
}

Expand All @@ -285,10 +288,10 @@ void IpConfigWidget::CreateParamFields(bool generateMetaLabel) {
tclArgList = m_instanceValueArgs;
}

containerLayout->removeWidget(paramsBox);
paramsBox->deleteLater();
paramsBox = new QGroupBox{"Parameters", this};
containerLayout->insertWidget(1, paramsBox);
// containerLayout->removeWidget(paramsBox);
// paramsBox->deleteLater();
// paramsBox = new QGroupBox{"Parameters", this};
// containerLayout->insertWidget(1, paramsBox);

if (parentJson.empty()) {
// Add a note if no parameters were available
Expand Down Expand Up @@ -339,19 +342,34 @@ void IpConfigWidget::CreateOutputFields() {
outputBox.setLayout(form);
}

void IpConfigWidget::updateMetaLabel(VLNV info) {
// Create a descriptive sentence that lists all the VLNV info
QString verStr = QString::fromStdString(info.version).replace("_", ".");
QString action = "Configuring";
if (!m_instanceValueArgs.empty()) {
// if params were passed then we are reconfiguring an existing instance
action = "Reconfiguring instance \"" + moduleEdit.text() + "\" for ";
}
std::string text = "<em>" + action.toStdString() + " " + info.name + " (" +
verStr.toStdString() + ")" + " from " + info.vendor +
"'s " + info.library + " library</em>";
void IpConfigWidget::updateMetaLabel(const IPDetails& details) {
QString text = R"(
<table cellspacing=10>
<tr>
<td align="left">Name:</th>
<td align="left">%1</th>
</tr>
<tr>
<td align="left">Version:</th>
<td align="left">%2</th>
</tr>
<tr>
<td align="left">Interface:</th>
<td align="left">%3</th>
</tr>
<tr>
<td align="left">Description:</th>
<td align="left">%4</th>
</tr>
</table>
)";

text = text.arg(QString::fromStdString(details.name),
QString::fromStdString(details.version),
QString::fromStdString(details.interface),
QString::fromStdString(details.description));
metaLabel.setTextFormat(Qt::RichText);
metaLabel.setText(QString::fromStdString(text));
metaLabel.setText(text);
metaLabel.setWordWrap(true);
}

Expand Down
3 changes: 2 additions & 1 deletion src/IpConfigurator/IpConfigWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class IpConfigWidget : public QWidget {
void AddIpToProject(const QString& cmd);
void CreateParamFields(bool generateMetaLabel);
void CreateOutputFields();
void updateMetaLabel(VLNV info);
void updateMetaLabel(const IPDetails& details);
std::vector<FOEDAG::IPDefinition*> getDefinitions();

QMap<QVariant, QVariant> saveProperties(bool& valid) const;
Expand All @@ -75,6 +75,7 @@ class IpConfigWidget : public QWidget {
const QString m_requestedIpName;
const QStringList m_instanceValueArgs;
VLNV m_meta;
IPDetails m_details;
QVBoxLayout* containerLayout{nullptr};
};

Expand Down
10 changes: 6 additions & 4 deletions src/MainWindow/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,8 +1599,10 @@ void MainWindow::ipConfiguratorActionTriggered() {
m_ipCatalogTree = ipsWidgets[0];

// Update the IP Config widget when the Available IPs selection changes
QObject::connect(m_ipCatalogTree, &IpCatalogTree::ipReady, this,
&MainWindow::handleIpTreeSelectionChanged);
connect(m_ipCatalogTree, &IpCatalogTree::ipReady, this,
&MainWindow::handleIpTreeSelectionChanged);
connect(m_ipCatalogTree, &IpCatalogTree::openIpSettings, this,
[]() { qDebug() << __PRETTY_FUNCTION__; });
}

// update the console for input incase the IP system printed any messages
Expand Down Expand Up @@ -1668,8 +1670,8 @@ void MainWindow::handleIpReConfigRequested(const QString& ipName,
} else { // If dock widget hasn't been created
// Create and place new dockwidget
m_ipConfigDockWidget =
PrepareTab(tr("Configure IP"), "configureIpsWidget", configWidget,
nullptr, Qt::RightDockWidgetArea);
PrepareTab(configWidget->windowTitle(), "configureIpsWidget",
configWidget, nullptr, Qt::RightDockWidgetArea);
}
}

Expand Down

0 comments on commit e0bd2e8

Please sign in to comment.