HAL
action_delete_object.cpp
Go to the documentation of this file.
2 
8 #include "gui/gui_globals.h"
16 
17 namespace hal
18 {
20  {
21  ;
22  }
23 
25 
27  {
28  return new ActionDeleteObject;
29  }
30 
32  {
34  }
35 
37  {
38  Module* mod;
39  Gate* gat;
40  Net* net;
41  GraphContext* ctx;
42  ContextDirectory* ctxDir;
43 
44  LayoutLocker llock;
45 
46  switch (mObject.type())
47  {
50  if (mod)
51  {
53  act->setUseCreatedObject();
55  actCreate->setObject(mObject);
56  actCreate->setParentId(mod->get_parent_module()->get_id());
57  act->addAction(actCreate);
60  QSet<u32> mods, gats;
61  for (Gate* g : mod->get_gates())
62  gats.insert(g->get_id());
63  for (Module* sm : mod->get_submodules())
64  mods.insert(sm->get_id());
65  if (!mods.isEmpty() || !gats.isEmpty())
66  act->addAction(new ActionAddItemsToObject(mods, gats));
67  mUndoAction = act;
68  gNetlist->delete_module(mod);
69  }
70  else
71  return false;
72  break;
75  if (gat)
76  gNetlist->delete_gate(gat);
77  else
78  return false;
79  break;
82  if (net)
84  else
85  return false;
86  break;
89  for (int irow = 0; irow < grpModel->rowCount(); irow++)
90  {
91  const GroupingTableEntry& grpEntry = grpModel->groupingAt(irow);
92  if (grpEntry.id() == mObject.id())
93  {
95  undoCreate->setObject(mObject);
96  QSet<u32> mods, gats, nets;
97  for (u32 id : grpEntry.grouping()->get_module_ids())
98  mods.insert(id);
99  for (u32 id : grpEntry.grouping()->get_gate_ids())
100  gats.insert(id);
101  for (u32 id : grpEntry.grouping()->get_net_ids())
102  nets.insert(id);
103  ActionSetObjectColor* undoColor = new ActionSetObjectColor(grpEntry.color());
104  undoColor->setObject(mObject);
105  ActionAddItemsToObject* undoPopulate = new ActionAddItemsToObject(mods, gats, nets);
106  undoPopulate->setObject(mObject);
108  act->setUseCreatedObject();
109  act->addAction(undoCreate);
110  act->addAction(undoColor);
111  act->addAction(undoPopulate);
112  mUndoAction = act;
113  grpModel->removeRows(irow);
114  break;
115  }
116  }
117  }
118  break;
121  if (ctx)
122  {
124  act->setUseCreatedObject();
125 
128  if (ctx->isShowingModuleExclusively())
129  actCreate->setLinkedObjectId(ctx->getExclusiveModuleId());
130  actCreate->setParentId(gGraphContextManager->getParentId(ctx->id(),false));
131  act->addAction(actCreate);
132 
133  ActionAddItemsToObject* actAddItems = new ActionAddItemsToObject(ctx->modules(), ctx->gates());
134  GridPlacement plc;
135  QMap<Node, QPoint> contextNodeMap = ctx->getLayouter()->nodeToPositionMap();
136  for (auto it = contextNodeMap.begin(); it != contextNodeMap.end(); it++)
137  plc.insert(it.key(), it.value());
138  actAddItems->setPlacementHint(plc);
139  act->addAction(actAddItems);
140 
141  mUndoAction = act;
143  }
144  else
145  return false;
146  break;
149  if (ctxDir)
150  {
152  mUndoAction = nullptr;
153  } else {
155  act->setUseCreatedObject();
158  actCreate->setParentId(gGraphContextManager->getParentId(ctxDir->id(),true));
159  act->addAction(actCreate);
160  act->addAction(new ActionAddItemsToObject({gNetlist->get_top_module()->get_id()}, {}));
161 
162  mUndoAction = act;
163  }
165  }
166  else
167  return false;
168  break;
169  default:
170  return false;
171  }
172  return UserAction::exec();
173  }
174 } // namespace hal
Adds an item to a module or grouping.
void setPlacementHint(PlacementHint hint)
UserActionFactory for ActionDeleteObject.
static ActionDeleteObjectFactory * sFactory
QString tagname() const override
Assigns a new type to a module.
virtual int getChildCount() const
GroupingManagerWidget * getGroupingManagerWidget()
BaseTreeItem * getDirectory(u32 directoryId) const
Definition: gate.h:58
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
u32 getExclusiveModuleId() const
bool isShowingModuleExclusively()
const QSet< u32 > & gates() const
const QSet< u32 > & modules() const
GraphLayouter * getLayouter() const
QString name() const
void deleteContextDirectory(ContextDirectory *ctxDir)
GraphContext * getContextById(u32 id) const
ContextTreeModel * getContextTreeModel() const
u32 getParentId(u32 childId, bool isDirectory) const
void deleteGraphContext(GraphContext *ctx)
ContextDirectory * getDirectoryById(u32 id) const
const QMap< Node, QPoint > nodeToPositionMap() const
std::vector< u32 > get_gate_ids(const std::function< bool(Gate *)> &filter=nullptr) const
Definition: grouping.cpp:113
std::vector< u32 > get_module_ids(const std::function< bool(Module *)> &filter=nullptr) const
Definition: grouping.cpp:287
std::vector< u32 > get_net_ids(const std::function< bool(Net *)> &filter=nullptr) const
Definition: grouping.cpp:200
GroupingTableModel * getModel() const
An entry within a GroupingTableModel.
Grouping * grouping() const
QString name() const
QColor color() const
u32 id() const
Table that holds information about all groupings.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool removeRows(int row, int count=1, const QModelIndex &parent=QModelIndex()) override
GroupingTableEntry groupingAt(int irow) const
QColor moduleColor(u32 id) const
Module * get_parent_module() const
Definition: module.cpp:125
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
std::string get_type() const
Definition: module.cpp:106
u32 get_id() const
Definition: module.cpp:82
Definition: net.h:58
Module * get_top_module() const
Definition: netlist.cpp:608
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
bool delete_net(Net *net)
Definition: netlist.cpp:343
bool delete_module(Module *module)
Definition: netlist.cpp:603
bool delete_gate(Gate *gate)
Definition: netlist.cpp:183
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
Net * get_net_by_id(u32 net_id) const
Definition: netlist.cpp:353
ModuleColorManager * getModuleColorManager() const
void addAction(UserAction *act)
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
NetlistRelay * gNetlistRelay
Definition: plugin_gui.cpp:81
quint32 u32
Net * net
QHash::iterator insert(const Key &key, const T &value)
QMap::iterator begin()
QMap::iterator end()
QSet::iterator insert(const T &value)
bool isEmpty() const const
QString fromStdString(const std::string &str)