diff --git a/CHANGELOG.md b/CHANGELOG.md index 4274ae1c11b..8716ee3ce96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -200,6 +200,7 @@ All notable changes to this project will be documented in this file. * added context menu entries to the GUI for `remove_buffers`, `unify_ff_outputs`, `split_luts`, and `split_shift_registers`, each applicable to the current selection or to the entire netlist * changed duplicating a view to place the modules and gates of the copy where they are in the original instead of laying the copy out anew * changed the modules widget to list the nets that belong to no module, i.e., the global inputs and outputs of the netlist and nets without any source or destination, below the top module when nets are shown, so that every net of the netlist appears in the tree + * changed the content window of a grouping to no longer block the rest of HAL, so several can be open side by side; it follows renaming, recoloring and changes to the content of its grouping, closes when the grouping is deleted, and showing the content of a grouping whose window is already open brings that window to the front * bugfixes * fixed the module trees keeping a net under its module after the net was marked as a global input or output, and leaving a net out after it was unmarked * fixed `Number of nets` in the details of a module showing the number of internal nets; it now counts every net with a source or a destination inside the module, as `Module::get_nets` returns them diff --git a/plugins/gui/include/gui/graph_widget/layout_locker.h b/plugins/gui/include/gui/graph_widget/layout_locker.h index dbaebf72b29..fc029ec39d3 100644 --- a/plugins/gui/include/gui/graph_widget/layout_locker.h +++ b/plugins/gui/include/gui/graph_widget/layout_locker.h @@ -47,6 +47,7 @@ namespace hal static LayoutLockerManager* instance(); void addLock(); void removeLock(); + bool isLocked() const; bool canUpdate(GraphContext* ctx); void removeWaitingContext(GraphContext* ctx); }; diff --git a/plugins/gui/include/gui/grouping/grouping_content_dialog.h b/plugins/gui/include/gui/grouping/grouping_content_dialog.h new file mode 100644 index 00000000000..5ee8174d0dc --- /dev/null +++ b/plugins/gui/include/gui/grouping/grouping_content_dialog.h @@ -0,0 +1,95 @@ +// 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/defines.h" + +#include + +class QLabel; +class QTimer; + +namespace hal +{ + class Grouping; + class SelectionTreeView; + + /** + * @ingroup utility_widgets-grouping + * @brief Window that shows the modules, gates and nets of a grouping. + * + * The window does not block the rest of HAL, so several of them can be open at once. It follows changes to the + * name, the color and the content of its grouping, and closes when the grouping is deleted or the netlist is closed. + */ + class GroupingContentDialog : public QDialog + { + Q_OBJECT + + public: + /** + * Shows the content window of a grouping. If the parent has a window open for this grouping already, that window + * is brought to the front instead of opening another one. + * + * @param grouping - The grouping + * @param parent - The parent widget of the window + * @returns the window + */ + static GroupingContentDialog* showGrouping(Grouping* grouping, QWidget* parent); + + /** + * Constructor. + * + * @param grouping - The grouping + * @param parent - The parent widget + */ + GroupingContentDialog(Grouping* grouping, QWidget* parent = nullptr); + + /** + * Get the grouping the window shows. + * + * @returns the grouping + */ + Grouping* grouping() const; + + private Q_SLOTS: + void handleGroupingNameChanged(Grouping* grp); + void handleGroupingColorChanged(Grouping* grp); + void handleGroupingContentChanged(Grouping* grp); + void handleGroupingRemoved(Grouping* grp); + void handleUpdateTimeout(); + + private: + void refresh(); + void updateTitle(); + void updateColor(); + + Grouping* mGrouping; + u32 mGroupingId; + QLabel* mColorLabel; + SelectionTreeView* mSelectionTreeView; + QTimer* mUpdateTimer; + }; +} diff --git a/plugins/gui/src/graph_widget/layout_locker.cpp b/plugins/gui/src/graph_widget/layout_locker.cpp index e2bf1f46bb2..5f598215d30 100644 --- a/plugins/gui/src/graph_widget/layout_locker.cpp +++ b/plugins/gui/src/graph_widget/layout_locker.cpp @@ -35,6 +35,11 @@ namespace hal { } } + bool LayoutLockerManager::isLocked() const + { + return mLockCount > 0; + } + bool LayoutLockerManager::canUpdate(GraphContext* ctx) { if (!ctx) return false; diff --git a/plugins/gui/src/grouping/grouping_content_dialog.cpp b/plugins/gui/src/grouping/grouping_content_dialog.cpp new file mode 100644 index 00000000000..9da424fc049 --- /dev/null +++ b/plugins/gui/src/grouping/grouping_content_dialog.cpp @@ -0,0 +1,151 @@ +#include "gui/grouping/grouping_content_dialog.h" + +#include "gui/file_manager/file_manager.h" +#include "gui/graph_widget/layout_locker.h" +#include "gui/grouping/grouping_table_model.h" +#include "gui/gui_globals.h" +#include "gui/module_model/module_model.h" +#include "gui/netlist_relay/netlist_relay.h" +#include "gui/selection_details_widget/tree_navigation/selection_tree_proxy.h" +#include "gui/selection_details_widget/tree_navigation/selection_tree_view.h" +#include "hal_core/netlist/grouping.h" +#include "hal_core/netlist/netlist.h" + +#include +#include +#include +#include +#include + +namespace hal +{ + GroupingContentDialog* GroupingContentDialog::showGrouping(Grouping* grouping, QWidget* parent) + { + for (GroupingContentDialog* dialog : parent->findChildren(QString(), Qt::FindDirectChildrenOnly)) + { + if (dialog->grouping() == grouping && dialog->isVisible()) + { + dialog->raise(); + dialog->activateWindow(); + return dialog; + } + } + GroupingContentDialog* dialog = new GroupingContentDialog(grouping, parent); + dialog->show(); + return dialog; + } + + GroupingContentDialog::GroupingContentDialog(Grouping* grouping, QWidget* parent) + : QDialog(parent), mGrouping(grouping), mGroupingId(grouping->get_id()), mColorLabel(new QLabel(this)), mSelectionTreeView(new SelectionTreeView(this, true)), mUpdateTimer(new QTimer(this)) + { + setAttribute(Qt::WA_DeleteOnClose); + + mColorLabel->setFixedSize(25, 25); + mColorLabel->setAutoFillBackground(true); + + SelectionTreeProxyModel* proxyModel = new SelectionTreeProxyModel(this); + proxyModel->setSourceModel(new ModuleModel(this)); + mSelectionTreeView->setModel(proxyModel); + + QPushButton* closeButton = new QPushButton("Close", this); + connect(closeButton, &QPushButton::clicked, this, &QDialog::close); + + QHBoxLayout* colorLayout = new QHBoxLayout; + colorLayout->addStretch(); + colorLayout->addWidget(mColorLabel); + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addLayout(colorLayout); + layout->addWidget(mSelectionTreeView); + layout->addWidget(closeButton); + + mUpdateTimer->setSingleShot(true); + connect(mUpdateTimer, &QTimer::timeout, this, &GroupingContentDialog::handleUpdateTimeout); + + connect(gNetlistRelay, &NetlistRelay::groupingNameChanged, this, &GroupingContentDialog::handleGroupingNameChanged); + connect(gNetlistRelay, &NetlistRelay::groupingColorChanged, this, &GroupingContentDialog::handleGroupingColorChanged); + connect(gNetlistRelay, &NetlistRelay::groupingGateAssigned, this, &GroupingContentDialog::handleGroupingContentChanged); + connect(gNetlistRelay, &NetlistRelay::groupingGateRemoved, this, &GroupingContentDialog::handleGroupingContentChanged); + connect(gNetlistRelay, &NetlistRelay::groupingNetAssigned, this, &GroupingContentDialog::handleGroupingContentChanged); + connect(gNetlistRelay, &NetlistRelay::groupingNetRemoved, this, &GroupingContentDialog::handleGroupingContentChanged); + connect(gNetlistRelay, &NetlistRelay::groupingModuleAssigned, this, &GroupingContentDialog::handleGroupingContentChanged); + connect(gNetlistRelay, &NetlistRelay::groupingModuleRemoved, this, &GroupingContentDialog::handleGroupingContentChanged); + connect(gNetlistRelay, &NetlistRelay::groupingRemoved, this, &GroupingContentDialog::handleGroupingRemoved); + connect(FileManager::get_instance(), &FileManager::fileAboutToClose, this, &QDialog::close); + + refresh(); + } + + Grouping* GroupingContentDialog::grouping() const + { + return mGrouping; + } + + void GroupingContentDialog::handleGroupingNameChanged(Grouping* grp) + { + if (grp == mGrouping) + { + updateTitle(); + } + } + + void GroupingContentDialog::handleGroupingColorChanged(Grouping* grp) + { + if (grp == mGrouping) + { + updateColor(); + } + } + + void GroupingContentDialog::handleGroupingContentChanged(Grouping* grp) + { + // rebuild the tree once after a burst of changes instead of once per change + if (grp == mGrouping && !mUpdateTimer->isActive()) + { + mUpdateTimer->start(0); + } + } + + void GroupingContentDialog::handleGroupingRemoved(Grouping* grp) + { + if (grp == mGrouping) + { + close(); + } + } + + void GroupingContentDialog::handleUpdateTimeout() + { + if (isVisible()) + { + refresh(); + } + } + + void GroupingContentDialog::refresh() + { + // the lock is held while the netlist is being changed, possibly by a Python thread, so it must not be read yet + if (LayoutLockerManager::instance()->isLocked()) + { + mUpdateTimer->start(100); + return; + } + if (!gNetlist || gNetlist->get_grouping_by_id(mGroupingId) != mGrouping) + { + return; + } + + updateTitle(); + updateColor(); + mSelectionTreeView->populate(true, mGroupingId); + } + + void GroupingContentDialog::updateTitle() + { + setWindowTitle(QString("Content of %1 (ID: %2)").arg(QString::fromStdString(mGrouping->get_name())).arg(mGroupingId)); + } + + void GroupingContentDialog::updateColor() + { + mColorLabel->setStyleSheet("background-color: " + GroupingTableEntry(mGrouping).color().name()); + } +} diff --git a/plugins/gui/src/grouping/grouping_manager_widget.cpp b/plugins/gui/src/grouping/grouping_manager_widget.cpp index ea441ea2df9..ee81a02bb0a 100644 --- a/plugins/gui/src/grouping/grouping_manager_widget.cpp +++ b/plugins/gui/src/grouping/grouping_manager_widget.cpp @@ -3,6 +3,7 @@ #include "gui/action/action.h" #include "gui/graph_tab_widget/graph_tab_widget.h" #include "gui/grouping/grouping_color_delegate.h" +#include "gui/grouping/grouping_content_dialog.h" #include "gui/grouping/grouping_proxy_model.h" #include "gui/gui_def.h" #include "gui/gui_globals.h" @@ -19,7 +20,6 @@ #include "gui/user_action/user_action_compound.h" #include "gui/user_action/action_remove_items_from_object.h" #include "hal_core/utilities/log.h" -#include "gui/selection_details_widget/tree_navigation/selection_tree_view.h" #include "gui/grouping_dialog/grouping_dialog.h" #include @@ -551,44 +551,11 @@ namespace hal if (!currentIndex.isValid()) return; - int irow = currentIndex.row(); - GroupingTableEntry gte = mGroupingTableModel->groupingAt(irow); - - QString grpName = gte.name(); - u32 grpId = gte.id(); - QColor grpColor = gte.color(); - - QDialog dialog; - dialog.setWindowTitle(QString("Content of %1 (ID: %2)").arg(grpName).arg(grpId)); - - // Create color rectangle - QLabel colorRectangle(&dialog); - colorRectangle.setText(QString()); // Empty text to visualize grouping color - colorRectangle.setStyleSheet("background-color: " + grpColor.name()); - colorRectangle.setFixedSize(25, 25); // Adapt size of grouping color - colorRectangle.setAutoFillBackground(true); - - // Replace InputDialog with SelectionTreeView - SelectionTreeView selectionTreeView(&dialog, true); - SelectionTreeProxyModel selectionTreeProxyModel(&dialog); - ModuleModel moduleModel(&dialog); // Need to fully initialise SelectionTreeView with a model - selectionTreeProxyModel.setSourceModel(&moduleModel); - selectionTreeView.setModel(&selectionTreeProxyModel); - - selectionTreeView.populate(true, grpId); - - QPushButton closeButton("Close",&dialog);// = new QPushButton("Close", &dialog); - connect(&closeButton, &QPushButton::clicked, [&dialog](){ dialog.close(); }); - - QVBoxLayout layout(&dialog); - QHBoxLayout hlay(&dialog); - hlay.addStretch(); - hlay.addWidget(&colorRectangle); - layout.addLayout(&hlay); - layout.addWidget(&selectionTreeView); - layout.addWidget(&closeButton); - - dialog.exec(); + Grouping* grouping = mGroupingTableModel->groupingAt(currentIndex.row()).grouping(); + if (grouping) + { + GroupingContentDialog::showGrouping(grouping, this); + } } void GroupingManagerWidget::handleDeleteGroupingClicked()