Skip to content

Commit

Permalink
Restructured context menus more
Browse files Browse the repository at this point in the history
  • Loading branch information
Skaleee committed Aug 28, 2024
1 parent 317a4ca commit 13c84a7
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 297 deletions.
24 changes: 23 additions & 1 deletion plugins/gui/include/gui/graph_widget/graph_context_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,31 @@ namespace hal
*/
GraphContext* createNewContext(const QString& name, u32 parentId = 0);


ContextDirectory* createNewDirectory(const QString &name, u32 parentId = 0);

/**
* Opens a existing view that contains the given module, otherwise creates a new context
* and opens it.
*
* @param moduleId - The module to open.
* @param unfold - True to unfold the module upon opening.
*/
void openModuleInView(u32 moduleId, bool unfold);

/**
* Creates and opens a new view that contains the given gate.
*
* @param netId - The gate to open.
*/
void openGateInView(u32 gateId);

/**
* Creates and opens a new view that contains the sources and desinations of the given net.
*
* @param netId - The net to open.
*/
void openNetEndpointsInView(u32 netId);

/**
* Renames a GraphContext. <br>
* Emits the signal contextRenamed.
Expand Down
14 changes: 0 additions & 14 deletions plugins/gui/include/gui/module_widget/module_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@ namespace hal
*/
ModuleModel* getModuleModel() const;

/**
* Opens a existing view that contains the given module, otherwise creates a new context
* and opens it.
*
* @param moduleId - The module to open.
* @param unfold - True to unfold the module upon opening.
*/
void openModuleInView(u32 moduleId, bool unfold);

/**
* Get the widget's proxy model that represents the ModuleModel.
*
Expand Down Expand Up @@ -281,11 +272,6 @@ namespace hal

QShortcut* mShortCutDeleteItem;

// 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);

void enableDeleteAction(bool enable);

ModuleItem* getModuleItemFromIndex(const QModelIndex& index);
Expand Down
2 changes: 1 addition & 1 deletion plugins/gui/include/gui/netlist_relay/netlist_relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace hal
void changeModuleColorDialog(const u32 id);

/**
* Adds the current selection to a specific module.
* Adds the currently selected gates to a specific module.
*
* @param id - The id of the module that should be appended
*/
Expand Down
75 changes: 75 additions & 0 deletions plugins/gui/src/graph_widget/graph_context_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "gui/graph_widget/graph_context_manager.h"

#include "gui/context_manager_widget/context_manager_widget.h"
#include "gui/context_manager_widget/models/context_tree_model.h"
#include "gui/file_manager/file_manager.h"
#include "gui/graph_widget/contexts/graph_context.h"
Expand All @@ -9,6 +10,10 @@
#include "gui/graph_widget/shaders/module_shader.h"
#include "gui/gui_globals.h"
#include "gui/settings/settings_items/settings_item_checkbox.h"
#include "gui/user_action/action_add_items_to_object.h"
#include "gui/user_action/action_create_object.h"
#include "gui/user_action/action_unfold_module.h"
#include "gui/user_action/user_action_compound.h"
#include "hal_core/netlist/gate.h"
#include "hal_core/netlist/module.h"
#include "hal_core/netlist/netlist.h"
Expand Down Expand Up @@ -130,6 +135,76 @@ namespace hal
mMaxContextId = ctxId;
}

void GraphContextManager::openModuleInView(u32 moduleId, bool unfold)
{
const Module* module = gNetlist->get_module_by_id(moduleId);

if (!module)
return;

GraphContext* moduleContext =
gGraphContextManager->getContextByExclusiveModuleId(moduleId);
if (moduleContext)
{
gContentManager->getContextManagerWidget()->selectViewContext(moduleContext);
gContentManager->getContextManagerWidget()->handleOpenContextClicked();
}
else
{
UserActionCompound* act = new UserActionCompound;
act->setUseCreatedObject();
QString name = QString::fromStdString(module->get_name()) + " (ID: " + QString::number(moduleId) + ")";
act->addAction(new ActionCreateObject(UserActionObjectType::ContextView, name));
act->addAction(new ActionAddItemsToObject({module->get_id()}, {}));
if (unfold) act->addAction(new ActionUnfoldModule(module->get_id()));
act->exec();
moduleContext = gGraphContextManager->getContextById(act->object().id());
moduleContext->setDirty(false);
moduleContext->setExclusiveModuleId(module->get_id());
}
}

void GraphContextManager::openGateInView(u32 gateId)
{
QString name = gGraphContextManager->nextViewName("Isolated View");

UserActionCompound* act = new UserActionCompound;
act->setUseCreatedObject();
act->addAction(new ActionCreateObject(UserActionObjectType::ContextView, name));
act->addAction(new ActionAddItemsToObject({}, {gateId}));
act->exec();
}

void GraphContextManager::openNetEndpointsInView(u32 netId){
QSet<u32> allGates;

Net* net = gNetlist->get_net_by_id(netId);

PlacementHint plc(PlacementHint::PlacementModeType::GridPosition);
int currentY = -(int)(net->get_num_of_sources()/2);
for(auto endpoint : net->get_sources()) {
u32 id = endpoint->get_gate()->get_id();
allGates.insert(id);
plc.addGridPosition(Node(id, Node::NodeType::Gate), {0, currentY++});
}
currentY = -(int)(net->get_num_of_destinations()/2);
for(auto endpoint : net->get_destinations()) {
u32 id = endpoint->get_gate()->get_id();
allGates.insert(id);
plc.addGridPosition(Node(id, Node::NodeType::Gate), {1, currentY++});
}

QString name = gGraphContextManager->nextViewName("Isolated View");

UserActionCompound* act = new UserActionCompound;
act->setUseCreatedObject();
act->addAction(new ActionCreateObject(UserActionObjectType::ContextView, name));
auto actionAITO = new ActionAddItemsToObject({}, allGates);
actionAITO->setPlacementHint(plc);
act->addAction(actionAITO);
act->exec();
}

void GraphContextManager::renameGraphContextAction(GraphContext* ctx, const QString& newName)
{
ctx->mName = newName;
Expand Down
73 changes: 22 additions & 51 deletions plugins/gui/src/graph_widget/graph_graphics_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,6 @@ namespace hal
gSelectionRelay->setFocus(SelectionRelay::ItemType::Gate,mItem->id());
gSelectionRelay->relaySelectionChanged(this);
}

//context_menu.addAction("This gate:")->setEnabled(false);

action = context_menu.addAction("Fold parent module");
QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleFoldParentSingle);
}
else if (isModule)
{
Expand All @@ -596,17 +591,6 @@ namespace hal
gSelectionRelay->setFocus(SelectionRelay::ItemType::Module,mItem->id());
gSelectionRelay->relaySelectionChanged(this);
}

//context_menu.addAction("This module:")->setEnabled(false);

if (gNetlist->get_module_by_id(mItem->id())->get_parent_module())
{
action = context_menu.addAction("Fold parent module");
QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleFoldParentSingle);
}

action = context_menu.addAction("Unfold module");
QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleUnfoldSingleAction);
}
else if (isNet)
{
Expand All @@ -617,10 +601,19 @@ namespace hal
gSelectionRelay->setFocus(SelectionRelay::ItemType::Net,mItem->id());
gSelectionRelay->relaySelectionChanged(this);
}
}

//context_menu.addAction("This net:")->setEnabled(false);
if(isGate || isModule)
{
action = context_menu.addAction("Fold parent module");
QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleFoldParentSingle);
}
if(isModule)
{
action = context_menu.addAction("Unfold module");
QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleUnfoldSingleAction);
}

if (isGate || isModule)
{
QMenu* preSucMenu = context_menu.addMenu("Successor/Predecessor …");
Expand Down Expand Up @@ -662,22 +655,20 @@ namespace hal
}
}

if (gSelectionRelay->numberSelectedItems() > 1)
{
context_menu.addSeparator();
context_menu.addAction("Entire selection:")->setEnabled(false);
}

if (isGate || isModule)
{
if (gSelectionRelay->numberSelectedNodes() > 1)
{
action = context_menu.addAction("Fold all parent modules");
QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleFoldParentAll);
}
action = context_menu.addAction("Fold all parent modules");
connect(action, &QAction::triggered, this, &GraphGraphicsView::handleFoldParentAll);
if(gSelectionRelay->numberSelectedItems() <= 1) action->setEnabled(false);

action = context_menu.addAction("Isolate all in new view");
connect(action, &QAction::triggered, this, &GraphGraphicsView::handleIsolationViewAction);
if(gSelectionRelay->numberSelectedItems() <= 1) action->setEnabled(false);


action = context_menu.addAction("Unfold all selected modules");
connect(action, &QAction::triggered, this, &GraphGraphicsView::handleUnfoldAllAction);
if(gSelectionRelay->numberSelectedModules() <= 1) action->setEnabled(false);

action = context_menu.addAction("Remove item from view");
connect(action, &QAction::triggered, this, &GraphGraphicsView::handleRemoveFromView);
Expand Down Expand Up @@ -705,32 +696,12 @@ namespace hal
}
}
}

if (gSelectionRelay->numberSelectedNodes() > 1)
{
/* there is currently no action that works on gates only
if (gSelectionRelay->numberSelectedGates())
{
context_menu.addSeparator();
context_menu.addAction("All selected gates:")->setEnabled(false);
}
*/
if (gSelectionRelay->numberSelectedModules())
{
context_menu.addSeparator();
context_menu.addAction("All selected modules:")->setEnabled(false);

action = context_menu.addAction(" Unfold all");
QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleUnfoldAllAction);
}
}
}
else
{
context_menu.addAction("This view:")->setEnabled(false);

action = context_menu.addAction("Add module to view");
action = context_menu.addAction(" Add module to view");

int selectable_modules_count = 0;
QSet<u32> not_selectable_modules = getNotSelectableModules();
Expand All @@ -749,7 +720,7 @@ namespace hal

QObject::connect(action, &QAction::triggered, this, &GraphGraphicsView::handleAddModuleToView);

action = context_menu.addAction("Add gate to view");
action = context_menu.addAction(" Add gate to view");

if (getSelectableGates().empty())
action->setDisabled(true);
Expand Down
2 changes: 1 addition & 1 deletion plugins/gui/src/graph_widget/graph_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ namespace hal
act->exec();
}
else
gContentManager->getModuleWidget()->openModuleInView(id, true);
gGraphContextManager->openModuleInView(id, true);
}

void GraphWidget::ensureItemsVisible(const QSet<u32>& gates, const QSet<u32>& modules)
Expand Down
Loading

0 comments on commit 13c84a7

Please sign in to comment.