Skip to content

Commit

Permalink
moved some methods and removed some old context actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Skaleee committed Aug 5, 2024
1 parent aa1535a commit c2f1fac
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "gui/module_model/module_item.h"
#include "hal_core/defines.h"

#include <QMenu>
#include <QSet>
Expand All @@ -14,19 +14,5 @@ namespace hal {
static void addGateSubmenu(QMenu* contextMenu, u32 id);
static void addNetSubmenu(QMenu* contextMenu, u32 id);
static void addMultipleElementsSubmenu(QMenu* contextMenu, const QSet<u32>& modules = QSet<u32>(), const QSet<u32>& gates = QSet<u32>(), const QSet<u32>& nets = QSet<u32>());

/**
* Changes the name of a specific netlist element by asking the user for a new name in a dialogue.
*
* @param type - The type of the element to rename
* @param id - The id of the element to rename
*/
static void changeElementNameDialog(ModuleItem::TreeItemType type, u32 id);
/**
* Changes the type of a specific module by asking the user for a new type in a dialogue.
*
* @param id - The id of the moudle to change to type of
*/
static void changeModuleTypeDialog(const u32 id);
};
}
3 changes: 1 addition & 2 deletions plugins/gui/include/gui/module_widget/module_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ namespace hal

QShortcut* mShortCutDeleteItem;

void openModuleInView(const QModelIndex& index);

// the next 2 methods and the one for modules should be moved to a better suited place.
void openGateInView(const QModelIndex& index);

void openNetEndpointsInView(const QModelIndex &index);
Expand Down
17 changes: 13 additions & 4 deletions plugins/gui/include/gui/netlist_relay/netlist_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "hal_core/netlist/gate_library/enums/pin_event.h"
#include "gui/grouping/grouping_color_serializer.h"
#include "gui/module_model/module_color_manager.h"
#include "gui/module_model/module_item.h"
#include <QMap>
#include <QObject>

Expand Down Expand Up @@ -93,19 +94,27 @@ namespace hal
*/
ModuleColorManager* getModuleColorManager() const;

/**
* Changes the name of a specific netlist element by asking the user for a new name in a dialogue.
*
* @param type - The type of the element to rename
* @param id - The id of the element to rename
*/
void changeElementNameDialog(ModuleItem::TreeItemType type, u32 id);

/**
* Changes the type of a specific module by asking the user for a new name in a 'New Type'-dialogue.
*
* @param id - The id of the module whose type is to be changed
*/
void changeModuleType(const u32 id);
void changeModuleTypeDialog(const u32 id);

/**
* Changes the type of a specific module by asking the user to select a new color in a color dialogue.
*
* @param id - The id of the module whose color is to be changed
*/
void changeModuleColor(const u32 id);
void changeModuleColorDialog(const u32 id);

/**
* Adds the current selection to a specific module.
Expand All @@ -115,11 +124,11 @@ namespace hal
void addSelectionToModule(const u32 id);

/**
* Adds an empty child module to the specified module.
* Adds an empty child module to the specified module by asking the user for a new name in a dialogue.
*
* @param id - The id of the module that becomes the parent of the empty child module
*/
void addChildModule(const u32 id);
void addChildModuleDialog(const u32 id);

/**
* Deletes the specified module from the netlist.
Expand Down
90 changes: 23 additions & 67 deletions plugins/gui/src/module_context_menu/module_context_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "hal_core/defines.h"
#include "gui/gui_globals.h"
#include "gui/user_action/action_rename_object.h"
#include "gui/user_action/action_set_object_type.h"
#include "gui/grouping_dialog/grouping_dialog.h"
#include "gui/content_manager/content_manager.h"
#include "gui/grouping/grouping_manager_widget.h"
Expand Down Expand Up @@ -69,7 +67,19 @@ namespace hal {
menu->addAction("Change name",
[id]()
{
ModuleContextMenu::changeElementNameDialog(ModuleItem::TreeItemType::Module, id);
gNetlistRelay->changeElementNameDialog(ModuleItem::TreeItemType::Module, id);
}
);
menu->addAction("Change type",
[id]()
{
gNetlistRelay->changeModuleTypeDialog(id);
}
);
menu->addAction("Change color",
[id]()
{
gNetlistRelay->changeModuleColorDialog(id);
}
);
menu->addAction("Assign to grouping",
Expand All @@ -90,6 +100,14 @@ namespace hal {
gContentManager->getGraphTabWidget()->handleModuleFocus(id);
}
);
QAction* delAction = menu->addAction("Delete module",
[id]()
{
gNetlistRelay->deleteModule(id);
}
);
if(gNetlist->get_module_by_id(id) == gNetlist->get_top_module())
delAction->setEnabled(false);
}

void ModuleContextMenu::addGateSubmenu(QMenu* contextMenu, u32 id)
Expand Down Expand Up @@ -123,7 +141,7 @@ namespace hal {
menu->addAction("Change name",
[id]()
{
ModuleContextMenu::changeElementNameDialog(ModuleItem::TreeItemType::Gate, id);
gNetlistRelay->changeElementNameDialog(ModuleItem::TreeItemType::Gate, id);
}
);
menu->addAction("Assign to grouping",
Expand Down Expand Up @@ -171,7 +189,7 @@ namespace hal {
menu->addAction("Change name",
[id]()
{
ModuleContextMenu::changeElementNameDialog(ModuleItem::TreeItemType::Net, id);
gNetlistRelay->changeElementNameDialog(ModuleItem::TreeItemType::Net, id);
}
);
menu->addAction("Assign to grouping",
Expand Down Expand Up @@ -210,66 +228,4 @@ namespace hal {
}
);
}

void ModuleContextMenu::changeElementNameDialog(ModuleItem::TreeItemType type, u32 id)
{
QString oldName;
QString prompt;
UserActionObject uao;

if (type == ModuleItem::TreeItemType::Module)
{
Module* m = gNetlist->get_module_by_id(id);
assert(m);
oldName = QString::fromStdString(m->get_name());
prompt = "Change module name";
uao = UserActionObject(id, UserActionObjectType::Module);
}
else if (type == ModuleItem::TreeItemType::Gate)
{
Gate* g = gNetlist->get_gate_by_id(id);
assert(g);
oldName = QString::fromStdString(g->get_name());
prompt = "Change gate name";
uao = UserActionObject(id, UserActionObjectType::Gate);
}
else if (type == ModuleItem::TreeItemType::Net)
{
Net* n = gNetlist->get_net_by_id(id);
assert(n);
oldName = QString::fromStdString(n->get_name());
prompt = "Change net name";
uao = UserActionObject(id, UserActionObjectType::Net);
}
else return;

bool confirm;
QString newName =
QInputDialog::getText(nullptr, prompt, "New name:", QLineEdit::Normal,
oldName, &confirm);
if (confirm)
{
ActionRenameObject* act = new ActionRenameObject(newName);
act->setObject(uao);
act->exec();
}
}

void ModuleContextMenu::changeModuleTypeDialog(const u32 id)
{
// NOT THREADSAFE

Module* m = gNetlist->get_module_by_id(id);
assert(m);

bool ok;
QString type = QInputDialog::getText(nullptr, "Change Module Type", "New Type", QLineEdit::Normal, QString::fromStdString(m->get_type()), &ok);

if (ok)
{
ActionSetObjectType* act = new ActionSetObjectType(type);
act->setObject(UserActionObject(m->get_id(),UserActionObjectType::Module));
act->exec();
}
}
}
92 changes: 17 additions & 75 deletions plugins/gui/src/module_widget/module_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "gui/module_model/module_model.h"
#include "gui/graph_tab_widget/graph_tab_widget.h"
#include "gui/module_context_menu/module_context_menu.h"
#include "gui/plugin_relay/gui_plugin_manager.h"

#include <QApplication>
#include <QHeaderView>
Expand All @@ -31,7 +32,6 @@
#include <QVBoxLayout>
#include <QInputDialog>
#include <QClipboard>
#include "gui/plugin_relay/gui_plugin_manager.h"

namespace hal
{
Expand Down Expand Up @@ -167,7 +167,7 @@ namespace hal
void ModuleWidget::handleRenameClicked()
{
ModuleItem* item = getModuleItemFromIndex(mTreeView->currentIndex());
ModuleContextMenu::changeElementNameDialog(item->getType(), item->id());
gNetlistRelay->changeElementNameDialog(item->getType(), item->id());
}

void ModuleWidget::setupToolbar(Toolbar* toolbar)
Expand Down Expand Up @@ -223,103 +223,50 @@ namespace hal
void ModuleWidget::handleTreeViewContextMenuRequested(const QPoint& point)
{
QModelIndex index = mTreeView->indexAt(point);

if (!index.isValid())
return;

ModuleItem* item = getModuleItemFromIndex(index);
ModuleItem::TreeItemType type = getModuleItemFromIndex(index)->getType();
ModuleItem::TreeItemType type = item->getType();
u32 id = item->id();

QMenu context_menu;

switch(type) {
case ModuleItem::TreeItemType::Module:{
QAction* act = context_menu.addAction(QIcon(":/icons/python"),
"Extract Module as python code (copy to clipboard)",
[item](){
QApplication::clipboard()->setText("netlist.get_module_by_id(" + QString::number(item->id()) + ")");
});

act = context_menu.addAction("Isolate in new view", [this,index](){openModuleInView(index);});
QAction* act = context_menu.addAction("Isolate in new view", [this,id](){openModuleInView(id, false);});

act = context_menu.addAction("Add selected gates to module",
[this,index](){gNetlistRelay->addSelectionToModule(getModuleItemFromIndex(index)->id());});
[this,id](){gNetlistRelay->addSelectionToModule(id);});

act = context_menu.addAction("Add child module",
[this,index](){
gNetlistRelay->addChildModule(getModuleItemFromIndex(index)->id());
[this,id,index](){
gNetlistRelay->addChildModuleDialog(id);
mTreeView->setExpanded(index, true);
});

act = context_menu.addAction("Change module name",
[item,type](){ModuleContextMenu::changeElementNameDialog(type, item->id());});

act = context_menu.addAction("Change module type",
[item](){gNetlistRelay->changeModuleType(item->id());});

act = context_menu.addAction("Change module color",
[this,item](){gNetlistRelay->changeModuleColor(item->id());});

if(gNetlist->get_module_by_id(item->id()) != gNetlist->get_top_module())
{
act = context_menu.addAction("Delete module",
[item](){gNetlistRelay->deleteModule(item->id());});
}

act = context_menu.addAction("Focus module in Graph View",
[item](){
gContentManager->getGraphTabWidget()->handleModuleFocus(item->id());
});
break;
}
case ModuleItem::TreeItemType::Gate: {
QAction* act = context_menu.addAction(QIcon(":/icons/python"),
"Extract Gate as python code (copy to clipboard)",
[item](){QApplication::clipboard()->setText("netlist.get_gate_by_id(" + QString::number(item->id()) + ")");});

act = context_menu.addAction("Isolate in new view", [this,index](){openGateInView(index);});

act = context_menu.addAction("Change gate name",
[this,index,type](){ModuleContextMenu::changeElementNameDialog(type, getModuleItemFromIndex(index)->id());});

act = context_menu.addAction("Focus gate in Graph View",
[item](){
gContentManager->getGraphTabWidget()->handleGateFocus(item->id());
});
QAction* act = context_menu.addAction("Isolate in new view", [this,index](){openGateInView(index);});
break;
}
case ModuleItem::TreeItemType::Net: {
QAction* act = context_menu.addAction(QIcon(":/icons/python"),
"Extract Net as python code (copy to clipboard)",
[item](){QApplication::clipboard()->setText("netlist.get_net_by_id(" + QString::number(item->id()) + ")");});

act = context_menu.addAction("Isolate in new view", [this,index](){openNetEndpointsInView(index);});

act = context_menu.addAction("Change net name",
[this,index,type](){ModuleContextMenu::changeElementNameDialog(type, getModuleItemFromIndex(index)->id());});

act = context_menu.addAction("Focus net in Graph View",
[item](){
gContentManager->getGraphTabWidget()->handleNetFocus(item->id());
});
QAction* act = context_menu.addAction("Isolate in new view", [this,index](){openNetEndpointsInView(index);});
break;
}
}

u32 module_id = getModuleItemFromIndex(index)->id();
auto module = gNetlist->get_module_by_id(module_id);

if(type == ModuleItem::TreeItemType::Module)
ModuleContextMenu::addModuleSubmenu(&context_menu, getModuleItemFromIndex(index)->id());
ModuleContextMenu::addModuleSubmenu(&context_menu, id);
else if(type == ModuleItem::TreeItemType::Gate)
ModuleContextMenu::addGateSubmenu(&context_menu, getModuleItemFromIndex(index)->id());
ModuleContextMenu::addGateSubmenu(&context_menu, id);
else if(type == ModuleItem::TreeItemType::Net)
ModuleContextMenu::addNetSubmenu(&context_menu, getModuleItemFromIndex(index)->id());
ModuleContextMenu::addNetSubmenu(&context_menu, id);

GuiPluginManager::addPluginSubmenus(&context_menu, gNetlist,
type==ModuleItem::TreeItemType::Module?std::vector<u32>({module_id}):std::vector<u32>(),
type==ModuleItem::TreeItemType::Gate?std::vector<u32>({module_id}):std::vector<u32>(),
type==ModuleItem::TreeItemType::Net?std::vector<u32>({module_id}):std::vector<u32>());
type==ModuleItem::TreeItemType::Module?std::vector<u32>({id}):std::vector<u32>(),
type==ModuleItem::TreeItemType::Gate?std::vector<u32>({id}):std::vector<u32>(),
type==ModuleItem::TreeItemType::Net?std::vector<u32>({id}):std::vector<u32>());

context_menu.exec(mTreeView->viewport()->mapToGlobal(point));
}
Expand Down Expand Up @@ -399,17 +346,12 @@ namespace hal
{
ModuleItem* mi = getModuleItemFromIndex(index);
switch(mi->getType()){
case ModuleItem::TreeItemType::Module: openModuleInView(index); break;
case ModuleItem::TreeItemType::Module: openModuleInView(getModuleItemFromIndex(index)->id(), false); break;
case ModuleItem::TreeItemType::Gate: openGateInView(index); break;
case ModuleItem::TreeItemType::Net: openNetEndpointsInView(index); break;
}
}

void ModuleWidget::openModuleInView(const QModelIndex& index)
{
openModuleInView(getModuleItemFromIndex(index)->id(), false);
}

void ModuleWidget::openGateInView(const QModelIndex &index)
{
QSet<u32> gateId;
Expand Down
Loading

0 comments on commit c2f1fac

Please sign in to comment.