Skip to content

Commit

Permalink
Added 'isolate in new view' and 'focus item' options in some context …
Browse files Browse the repository at this point in the history
…menus
  • Loading branch information
joern274 committed May 10, 2023
1 parent d99c947 commit 29f4c0d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "gui/selection_details_widget/module_details_widget/module_elements_tree.h"
#include "gui/selection_details_widget/module_details_widget/netlist_elements_tree_model.h"
#include "gui/selection_details_widget/module_details_widget/module_tree_model.h"
#include "gui/selection_details_widget/tree_navigation/selection_tree_view.h"
#include "gui/graph_tab_widget/graph_tab_widget.h"
#include "gui/python/py_code_provider.h"
#include "gui/gui_globals.h"
#include <QMenu>
Expand All @@ -16,7 +18,8 @@ namespace hal
{
setContextMenuPolicy(Qt::CustomContextMenu);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setSelectionMode(QAbstractItemView::NoSelection);
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setFocusPolicy(Qt::NoFocus);
header()->setStretchLastSection(true);
//setModel(mNetlistElementsModel);
Expand Down Expand Up @@ -113,6 +116,30 @@ namespace hal
}
);

menu.addAction("Isolate in new view",
[id, type]()
{
Node nd;
switch(type)
{
case ModuleTreeModel::itemType::module: nd = Node(id, Node::Module); break;
case ModuleTreeModel::itemType::gate: nd = Node(id, Node::Gate); break;
}
SelectionTreeView::isolateInNewViewAction(nd);
}
);

menu.addAction("Focus item in Graph View",
[id, type]()
{
switch(type)
{
case ModuleTreeModel::itemType::module: gContentManager->getGraphTabWidget()->handleModuleFocus(id); break;
case ModuleTreeModel::itemType::gate: gContentManager->getGraphTabWidget()->handleGateFocus(id); break;
}
}
);

menu.addSection("Python Code");

QString pythonGetObject = (type == ModuleTreeModel::itemType::module) ? PyCodeProvider::pyCodeModule(id) : PyCodeProvider::pyCodeGate(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "gui/python/py_code_provider.h"
#include "gui/selection_details_widget/net_details_widget/endpoint_table_model.h"
#include "gui/selection_details_widget/tree_navigation/selection_tree_view.h"
#include "gui/graph_tab_widget/graph_tab_widget.h"
#include "hal_core/netlist/gate.h"

#include <QApplication>
Expand Down Expand Up @@ -93,17 +94,20 @@ namespace hal
});

menu.addSeparator();
menu.addAction("Isolate gate in new view", [gateID](){
Node nd(gateID,Node::Gate);
SelectionTreeView::isolateInNewViewAction(nd);
});
if (!gSelectionRelay->selectedGates().contains(gateID))
{
menu.addAction("Add gate to selection", [gateID,this](){
gSelectionRelay->addGate(gateID);
gSelectionRelay->relaySelectionChanged(this);
});
}
menu.addAction("Isolate gate in new view", [gateID](){
Node nd(gateID,Node::Gate);
SelectionTreeView::isolateInNewViewAction(nd);
});
menu.addAction("Focus gate in Graph View", [gateID](){
gContentManager->getGraphTabWidget()->handleGateFocus(gateID);
});
menu.addSection("Python");
QString pythonCommand ="netlist.get_gate_by_id(" + gateIDStr + ").%1(\"" + pin + "\")";
pythonCommand = (mEndpointModel->getType() == EndpointTableModel::Type::source) ? pythonCommand.arg("get_fan_out_endpoint") : pythonCommand.arg("get_fan_in_endpoint");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "gui/graph_widget/contexts/graph_context.h"
#include "gui/gui_globals.h"
#include "gui/selection_details_widget/tree_navigation/selection_tree_model.h"
#include "gui/context_manager_widget/context_manager_widget.h"
#include "gui/user_action/action_create_object.h"
#include "gui/user_action/action_add_items_to_object.h"
#include "gui/user_action/user_action_compound.h"
Expand Down Expand Up @@ -148,34 +148,46 @@ namespace hal

if (nd.type() == Node::Gate)
{
name = "Isolated Gate(ID: " + QString::number(nd.id()) + ")";
u32 cnt = 0;
for (;;)
{
++cnt;
name = "Isolated View " + QString::number(cnt);
if (!gGraphContextManager->contextWithNameExists(name))
break;
}
gateId.insert(nd.id());
}
else if (nd.type() == Node::Module)
{
name = "Isolated Module(ID: " + QString::number(nd.id()) + ")";
GraphContext* moduleContext =
gGraphContextManager->getContextByExclusiveModuleId(nd.id());
if (moduleContext)
{
// open existing view
gContentManager->getContextManagerWidget()->selectViewContext(moduleContext);
gContentManager->getContextManagerWidget()->handleOpenContextClicked();
return;
}

name = QString::fromStdString(gNetlist->get_module_by_id(nd.id())->get_name()) + " (ID: " + QString::number(nd.id()) + ")";
moduleId.insert(nd.id());
}
else
{
return;
}

u32 cnt = 0;
while (true)
UserActionCompound* act = new UserActionCompound;
act->setUseCreatedObject();
act->addAction(new ActionCreateObject(UserActionObjectType::Context, name));
act->addAction(new ActionAddItemsToObject(moduleId, gateId));
act->exec();
if (nd.type() == Node::Module)
{
++cnt;
QString contextName = name + " " + QString::number(cnt);
if (!gGraphContextManager->contextWithNameExists(contextName))
{
UserActionCompound* act = new UserActionCompound;
act->setUseCreatedObject();
act->addAction(new ActionCreateObject(UserActionObjectType::Context,
contextName));
act->addAction(new ActionAddItemsToObject(moduleId, gateId));
act->exec();
return;
}
GraphContext* moduleContext = gGraphContextManager->getContextById(act->object().id());
moduleContext->setDirty(false);
moduleContext->setExclusiveModuleId(nd.id());
}
}

Expand Down

0 comments on commit 29f4c0d

Please sign in to comment.