HAL
action_add_boolean_function.cpp
Go to the documentation of this file.
1
#include "
gui/user_action/action_add_boolean_function.h
"
2
#include"
gui/gui_globals.h
"
3
4
namespace
hal
5
{
6
ActionAddBooleanFunctionFactory::ActionAddBooleanFunctionFactory
() :
UserActionFactory
(
"AddBooleanFunction"
)
7
{
8
9
}
10
11
ActionAddBooleanFunctionFactory
*
ActionAddBooleanFunctionFactory::sFactory
=
new
ActionAddBooleanFunctionFactory
;
12
13
UserAction
*
ActionAddBooleanFunctionFactory::newAction
()
const
14
{
15
return
new
ActionAddBooleanFunction
;
16
}
17
18
ActionAddBooleanFunction::ActionAddBooleanFunction
(
QString
booleanFuncName,
BooleanFunction
func,
u32
gateID)
19
: mName(booleanFuncName), mFunction(func)
20
{
21
setObject
(
UserActionObject
(gateID,
UserActionObjectType::Gate
));
22
}
23
24
bool
ActionAddBooleanFunction::exec
()
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
39
QString
ActionAddBooleanFunction::tagname
()
const
40
{
41
return
ActionAddBooleanFunctionFactory::sFactory
->
tagname
();
42
}
43
44
void
ActionAddBooleanFunction::writeToXml
(
QXmlStreamWriter
&xmlOut)
const
45
{
46
xmlOut.
writeTextElement
(
"name"
, mName);
47
xmlOut.
writeTextElement
(
"bf"
,
QString::fromStdString
(mFunction.
to_string
()));
48
}
49
50
void
ActionAddBooleanFunction::readFromXml
(
QXmlStreamReader
&xmlIn)
51
{
52
while
(xmlIn.
readNextStartElement
())
53
{
54
if
(xmlIn.
name
() ==
"name"
)
55
mName = xmlIn.
readElementText
();
56
if
(xmlIn.
name
() ==
"bf"
)
57
{
58
auto
res =
BooleanFunction::from_string
(xmlIn.
readElementText
().
toStdString
());
59
if
(res.is_ok())
60
mFunction = res.get();
61
}
62
}
63
}
64
65
void
ActionAddBooleanFunction::addToHash
(
QCryptographicHash
&cryptoHash)
const
66
{
67
cryptoHash.
addData
(mName.
toUtf8
());
68
cryptoHash.
addData
(
QString::fromStdString
(mFunction.
to_string
()).
toUtf8
());
69
}
70
71
}
action_add_boolean_function.h
hal::ActionAddBooleanFunctionFactory
The ActionAddBooleanFunctionFactory class.
Definition:
action_add_boolean_function.h:63
hal::ActionAddBooleanFunctionFactory::ActionAddBooleanFunctionFactory
ActionAddBooleanFunctionFactory()
Definition:
action_add_boolean_function.cpp:6
hal::ActionAddBooleanFunctionFactory::sFactory
static ActionAddBooleanFunctionFactory * sFactory
Definition:
action_add_boolean_function.h:67
hal::ActionAddBooleanFunctionFactory::newAction
UserAction * newAction() const override
Definition:
action_add_boolean_function.cpp:13
hal::ActionAddBooleanFunction
Either adds a new function or changes an exisiting function of a given gate.
Definition:
action_add_boolean_function.h:44
hal::ActionAddBooleanFunction::addToHash
void addToHash(QCryptographicHash &cryptoHash) const override
Definition:
action_add_boolean_function.cpp:65
hal::ActionAddBooleanFunction::readFromXml
void readFromXml(QXmlStreamReader &xmlIn) override
Definition:
action_add_boolean_function.cpp:50
hal::ActionAddBooleanFunction::exec
bool exec() override
Definition:
action_add_boolean_function.cpp:24
hal::ActionAddBooleanFunction::tagname
QString tagname() const override
Definition:
action_add_boolean_function.cpp:39
hal::ActionAddBooleanFunction::ActionAddBooleanFunction
ActionAddBooleanFunction(QString booleanFuncName=QString(), BooleanFunction func=BooleanFunction(), u32 gateID=0)
Definition:
action_add_boolean_function.cpp:18
hal::ActionAddBooleanFunction::writeToXml
void writeToXml(QXmlStreamWriter &xmlOut) const override
Definition:
action_add_boolean_function.cpp:44
hal::BooleanFunction
Definition:
boolean_function.h:55
hal::BooleanFunction::from_string
static Result< BooleanFunction > from_string(const std::string &expression)
Definition:
boolean_function.cpp:1046
hal::BooleanFunction::to_string
static std::string to_string(Value value)
Definition:
boolean_function.cpp:23
hal::Gate::get_boolean_function
BooleanFunction get_boolean_function(const std::string &name) const
Definition:
gate.cpp:209
hal::Netlist::get_gate_by_id
Gate * get_gate_by_id(const u32 gate_id) const
Definition:
netlist.cpp:193
hal::UserActionFactory
The UserActionFactory is the abstract base class for registration.
Definition:
user_action.h:225
hal::UserActionFactory::tagname
QString tagname() const
Definition:
user_action.h:242
hal::UserAction
The UserAction class is the abstract base class for user interactions.
Definition:
user_action.h:57
hal::UserAction::mUndoAction
UserAction * mUndoAction
Definition:
user_action.h:186
hal::UserAction::exec
virtual bool exec()
Definition:
user_action.cpp:23
hal::UserAction::setObject
virtual void setObject(const UserActionObject &obj)
Definition:
user_action.cpp:32
hal::UserAction::mObject
UserActionObject mObject
Definition:
user_action.h:183
hal::UserActionObject
The UserActionObject class represents a single object used in UserAction.
Definition:
user_action_object.h:79
hal::UserActionObject::id
u32 id() const
Definition:
user_action_object.h:97
hal::UserActionObjectType::Gate
@ Gate
Definition:
user_action_object.h:52
gui_globals.h
hal
Definition:
parser_liberty.cpp:10
hal::gNetlist
Netlist * gNetlist
Definition:
plugin_gui.cpp:80
u32
quint32 u32
Definition:
net_layout_point.h:40
QCryptographicHash
QCryptographicHash::addData
void addData(const char *data, int length)
QString
QString::fromStdString
QString fromStdString(const std::string &str)
QString::toStdString
std::string toStdString() const const
QString::toUtf8
QByteArray toUtf8() const const
QXmlStreamReader
QXmlStreamReader::name
QStringRef name() const const
QXmlStreamReader::readElementText
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QXmlStreamReader::readNextStartElement
bool readNextStartElement()
QXmlStreamWriter
QXmlStreamWriter::writeTextElement
void writeTextElement(const QString &qualifiedName, const QString &text)
plugins
gui
src
user_action
action_add_boolean_function.cpp
Generated on Fri Feb 14 2025 14:22:43 for HAL by
1.9.1