HAL
action_unfold_module.cpp
Go to the documentation of this file.
2 #include "gui/gui_globals.h"
8 #include <QDebug>
9 
10 namespace hal
11 {
13  : UserActionFactory("UnfoldModule") {;}
14 
16 
18  {
19  return new ActionUnfoldModule;
20  }
21 
23  {
25  }
26 
28  : mContextId(0), mPlacementHint(PlacementHint::Standard)
29  {
30  if (moduleId)
32  }
33 
35  {
36  switch (obj.type())
37  {
41  break;
43  mContextId = obj.id();
44  break;
45  default:
46  qDebug() << "ActionUnfoldModule warning: invalid object type" << obj.type();
47  break;
48  }
49  }
50 
52  {
53  if (mObject.type() != UserActionObjectType::Module) return false;
54 
56  if (m->get_gates().empty() && m->get_submodules().empty())
57  return false;
58 
59  GraphContext* ctx = mContextId
62  if (!ctx) return false;
63 
65  undo->setContextId(mContextId);
68  NetLayoutPoint pos = ctx->getLayouter()->positonForNode(nd);
69  if (!pos.isUndefined())
70  {
71  plc.addGridPosition(nd,pos);
72  undo->setPlacementHint(plc);
73  }
74  mUndoAction = undo;
75  execInternal(m,ctx);
76  return UserAction::exec();
77  }
78 
79  void ActionUnfoldModule::execInternal(Module *m, GraphContext* currentContext)
80  {
81  // only module shown in context
82  if (currentContext->gates().isEmpty() &&
83  currentContext->modules() == QSet<u32>({mObject.id()}))
84  {
85  currentContext->unfoldModule(mObject.id(),mPlacementHint);
86  return;
87  }
88 
89  // module to unfold and other boxes shown
90  if (currentContext->modules().contains(mObject.id()))
91  {
92  currentContext->unfoldModule(mObject.id(),mPlacementHint);
93  return;
94  }
95 
96  QSet<u32> gats;
97  QSet<u32> mods;
98  for (const Gate* g : m->get_gates())
99  {
100  gats.insert(g->get_id());
101  }
102  for (const Module* sm : m->get_submodules())
103  {
104  mods.insert(sm->get_id());
105  }
106 
107  for (const auto& ctx : gGraphContextManager->getContexts())
108  {
109  if ((ctx->gates().isEmpty() && ctx->modules() == QSet<u32>({mObject.id()})) ||
110  (ctx->modules() == mods && ctx->gates() == gats))
111  {
113  return;
114  }
115  }
116 
118  ctx->add(mods, gats, mPlacementHint);
119  }
120 }
void setPlacementHint(PlacementHint hint)
UserActionFactory for ActionUnfoldModule.
static ActionUnfoldModuleFactory * sFactory
void setObject(const UserActionObject &obj) override
QString tagname() const override
GraphTabWidget * getGraphTabWidget()
Get hal's graph tab widget.
ContextManagerWidget * getContextManagerWidget()
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
void unfoldModule(const u32 id, const PlacementHint &plc)
void add(const QSet< u32 > &modules, const QSet< u32 > &gates, PlacementHint placement=PlacementHint())
const QSet< u32 > & gates() const
const QSet< u32 > & modules() const
GraphLayouter * getLayouter() const
GraphContext * createNewContext(const QString &name, u32 parentId=0)
GraphContext * getContextById(u32 id) const
QVector< GraphContext * > getContexts() const
NetLayoutPoint positonForNode(const Node &nd) const
void showContext(GraphContext *context)
const std::vector< Gate * > & get_gates() const
Definition: module.cpp:391
std::string get_name() const
Definition: module.cpp:87
std::vector< Module * > get_submodules(const std::function< bool(Module *)> &filter=nullptr, bool recursive=false) const
Definition: module.cpp:259
bool isUndefined() const
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
The Node class object represents a module or a gate.
Definition: gui_def.h:61
@ Module
Definition: gui_def.h:63
The PlacementHint class object provides hints for the layouter how new box objects are placed on a vi...
Definition: gui_def.h:196
void addGridPosition(const Node &nd, const QPoint &p)
Definition: gui_def.h:263
The UserActionFactory is the abstract base class for registration.
Definition: user_action.h:225
QString tagname() const
Definition: user_action.h:242
The UserAction class is the abstract base class for user interactions.
Definition: user_action.h:57
UserAction * mUndoAction
Definition: user_action.h:186
virtual bool exec()
Definition: user_action.cpp:23
virtual void setObject(const UserActionObject &obj)
Definition: user_action.cpp:32
UserActionObject mObject
Definition: user_action.h:183
The UserActionObject class represents a single object used in UserAction.
UserActionObjectType::ObjectType type() const
ContentManager * gContentManager
Definition: plugin_gui.cpp:78
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
Netlist * gNetlist
Definition: plugin_gui.cpp:80
quint32 u32
bool contains(const T &value) const const
QSet::iterator insert(const T &value)
bool isEmpty() const const
QString fromStdString(const std::string &str)