HAL
action_add_boolean_function.cpp
Go to the documentation of this file.
2 #include"gui/gui_globals.h"
3 
4 namespace hal
5 {
7  {
8 
9  }
10 
12 
14  {
15  return new ActionAddBooleanFunction;
16  }
17 
19  : mName(booleanFuncName), mFunction(func)
20  {
22  }
23 
25  {
26  auto gate = gNetlist->get_gate_by_id(mObject.id());
27  if(!gate)
28  return false;
29 
30  auto bf = gate->get_boolean_function(mName.toStdString());
31  mUndoAction = !bf.is_empty() ? new ActionAddBooleanFunction(mName, bf, mObject.id()) : nullptr;
32 
33  if(!gate->add_boolean_function(mName.toStdString(), mFunction))
34  return false;
35 
36  return UserAction::exec();
37  }
38 
40  {
42  }
43 
45  {
46  xmlOut.writeTextElement("name", mName);
47  xmlOut.writeTextElement("bf", QString::fromStdString(mFunction.to_string()));
48  }
49 
51  {
52  while(xmlIn.readNextStartElement())
53  {
54  if(xmlIn.name() == "name")
55  mName = xmlIn.readElementText();
56  if(xmlIn.name() == "bf")
57  {
59  if(res.is_ok())
60  mFunction = res.get();
61  }
62  }
63  }
64 
66  {
67  cryptoHash.addData(mName.toUtf8());
68  cryptoHash.addData(QString::fromStdString(mFunction.to_string()).toUtf8());
69  }
70 
71 }
The ActionAddBooleanFunctionFactory class.
static ActionAddBooleanFunctionFactory * sFactory
Either adds a new function or changes an exisiting function of a given gate.
void addToHash(QCryptographicHash &cryptoHash) const override
void readFromXml(QXmlStreamReader &xmlIn) override
ActionAddBooleanFunction(QString booleanFuncName=QString(), BooleanFunction func=BooleanFunction(), u32 gateID=0)
void writeToXml(QXmlStreamWriter &xmlOut) const override
static Result< BooleanFunction > from_string(const std::string &expression)
static std::string to_string(Value value)
BooleanFunction get_boolean_function(const std::string &name) const
Definition: gate.cpp:209
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
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.
Netlist * gNetlist
Definition: plugin_gui.cpp:80
quint32 u32
void addData(const char *data, int length)
QString fromStdString(const std::string &str)
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)