HAL
action_create_object.cpp
Go to the documentation of this file.
3 #include "gui/gui_globals.h"
8 
9 namespace hal
10 {
12  : UserActionFactory("CreateObject") {;}
13 
15 
17  {
18  return new ActionCreateObject;
19  }
20 
22  {
24  }
25 
27  const QString &objName)
28  : mObjectName(objName), mParentId(0), mLinkedObjectId(0)
29  {
31  }
32 
34  {
35  cryptoHash.addData(mObjectName.toUtf8());
36  cryptoHash.addData((char*)(&mParentId),sizeof(mParentId));
37  cryptoHash.addData((char*)(&mLinkedObjectId),sizeof(mLinkedObjectId));
38  }
39 
41  {
42  xmlOut.writeTextElement("objectname", mObjectName);
43  xmlOut.writeTextElement("parentid", QString::number(mParentId));
44  xmlOut.writeTextElement("linkedid", QString::number(mLinkedObjectId));
45  }
46 
48  {
49  while (xmlIn.readNextStartElement())
50  {
51  if (xmlIn.name() == "objectname")
52  mObjectName = xmlIn.readElementText();
53  if (xmlIn.name() == "parentid")
54  mParentId = xmlIn.readElementText().toInt();
55  if (xmlIn.name() == "linkedid")
56  mLinkedObjectId = xmlIn.readElementText().toInt();
57  }
58  }
59 
61  {
62  bool standardUndo = false;
63 
64  switch (mObject.type())
65  {
66  break;
67 
69  {
70  Module* parentModule = gNetlist->get_module_by_id(mParentId);
71  if (parentModule)
72  {
74  Module* m = gNetlist->create_module(modId,
75  mObjectName.toStdString(), parentModule);
76  if (!m)
77  {
78  log_warning("gui", "Failed to create module '{}' with ID={} under parent ID={}.",
79  mObjectName.toStdString(), modId, mParentId);
80  return false;
81  }
83  standardUndo = true;
84  }
85  }
86  break;
87  /*
88  case UserActionObjectType::Gate:
89  {
90  Gate* g = gNetlist->create_gate(mGroupingName.toStdString());
91  setObject(UserActionObject(g->get_id(),UserActionObjectType::Gate));
92  }
93  break;
94  */
96  {
97  Net* n = gNetlist->create_net(mObjectName.toStdString());
99  standardUndo = true;
100  }
101  break;
103  {
105  if (!grpModel) return false;
106  Grouping* grp = grpModel->addDefaultEntry();
107  if (!mObjectName.isEmpty())
108  grpModel->renameGrouping(grp->get_id(),mObjectName);
110  standardUndo = true;
111  }
112  break;
114  {
115  QString contextName = mObjectName.isEmpty()
117  : mObjectName;
118  GraphContext* ctxView = gGraphContextManager->createNewContext(contextName, mParentId);
119  if (mLinkedObjectId > 0) ctxView->setExclusiveModuleId(mLinkedObjectId);
120  if (mObject.id() > 0) gGraphContextManager->setContextId(ctxView,mObject.id());
122  standardUndo = true;
123  }
124  break;
126  {
127  QString directoryName = mObjectName.isEmpty()
129  : mObjectName;
130 
131  ContextDirectory* ctxDir = gGraphContextManager->createNewDirectory(directoryName, mParentId);
132  if (mObject.id() > 0) ctxDir->setId(mObject.id());
134  standardUndo = true;
135  }
136  break;
137  default:
138  return false; // don't know how to create
139  }
140  if (standardUndo)
141  {
144  }
145  return UserAction::exec();
146  }
147 }
UserActionFactory for ActionCreateObject.
static ActionCreateObjectFactory * sFactory
QString tagname() const override
void readFromXml(QXmlStreamReader &xmlIn) override
void addToHash(QCryptographicHash &cryptoHash) const override
void writeToXml(QXmlStreamWriter &xmlOut) const override
ActionCreateObject(UserActionObjectType::ObjectType type=UserActionObjectType::None, const QString &objName=QString())
GroupingManagerWidget * getGroupingManagerWidget()
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
void setExclusiveModuleId(u32 id, bool emitSignal=true)
GraphContext * createNewContext(const QString &name, u32 parentId=0)
void setContextId(GraphContext *ctx, u32 ctxId)
ContextDirectory * createNewDirectory(const QString &name, u32 parentId=0)
u32 get_id() const
Definition: grouping.cpp:22
GroupingTableModel * getModel() const
Table that holds information about all groupings.
QString renameGrouping(u32 id, const QString &groupingName)
u32 get_id() const
Definition: module.cpp:82
Definition: net.h:58
u32 get_unique_module_id()
Definition: netlist.cpp:574
Net * create_net(const u32 net_id, const std::string &name)
Definition: netlist.cpp:333
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
Module * create_module(const u32 module_id, const std::string &name, Module *parent, const std::vector< Gate * > &gates={})
Definition: netlist.cpp:587
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
#define log_warning(channel,...)
Definition: log.h:76
ContentManager * gContentManager
Definition: plugin_gui.cpp:78
GraphContextManager * gGraphContextManager
Definition: plugin_gui.cpp:85
Netlist * gNetlist
Definition: plugin_gui.cpp:80
n
Definition: test.py:6
quint32 u32
PinType type
void addData(const char *data, int length)
bool isEmpty() const const
QString number(int n, int base)
int toInt(bool *ok, int base) const const
std::string toStdString() const const
QByteArray toUtf8() const const
QStringRef name() const const
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void writeTextElement(const QString &qualifiedName, const QString &text)