Skip to content

Commit cff9464

Browse files
committed
[feature/multi-output-luts_parameter-tab] Changes in the parameter table are now also saved in the gate
1 parent 6f9a0c6 commit cff9464

4 files changed

Lines changed: 178 additions & 19 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4+
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5+
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6+
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in all
16+
// copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
// SOFTWARE.
25+
26+
#pragma once
27+
#include "user_action.h"
28+
29+
namespace hal
30+
{
31+
/**
32+
* @ingroup user_action
33+
* @brief Sets the value of an existing typed parameter on a gate.
34+
*
35+
* Unlike ActionSetObjectData, a gate's parameters are fixed by its type: they can only
36+
* be modified, never created, deleted or moved. This action therefore only carries the
37+
* parameter name and the new value; the target gate is identified by the inherited mObject.
38+
*
39+
* The inverse of "set parameter <name> to <value>" is another ActionSetParameterValue that
40+
* restores the previous value, so exec() builds its own undo action of the same type.
41+
*/
42+
class ActionSetParameterValue : public UserAction
43+
{
44+
public:
45+
/**
46+
* Constructor.
47+
*
48+
* @param parameterName - The name of the parameter to modify.
49+
* @param value - The new value, formatted as the core expects it for the parameter's type.
50+
*/
51+
ActionSetParameterValue(const QString& parameterName = QString(), const QString& value = QString());
52+
53+
bool exec() override;
54+
QString tagname() const override;
55+
void writeToXml(QXmlStreamWriter& xmlOut) const override;
56+
void readFromXml(QXmlStreamReader& xmlIn) override;
57+
void addToHash(QCryptographicHash& cryptoHash) const override;
58+
59+
private:
60+
QString mParameterName;
61+
QString mValue;
62+
};
63+
64+
/**
65+
* @brief The ActionSetParameterValueFactory class registers the action with the manager.
66+
*/
67+
class ActionSetParameterValueFactory : public UserActionFactory
68+
{
69+
public:
70+
ActionSetParameterValueFactory();
71+
UserAction* newAction() const override;
72+
static ActionSetParameterValueFactory* sFactory;
73+
};
74+
} // namespace hal

plugins/gui/src/selection_details_widget/gate_details_tab_widget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ namespace hal
140140
GateDetailsTabWidget::GateTypeCategory gateTypeCategory = getGateTypeCategory(g);
141141
setupBooleanFunctionTables(g, gateTypeCategory);
142142
mDataTable->setGate(g);
143+
mParameterTable->setGate(g);
143144
}
144145
}
145146

plugins/gui/src/selection_details_widget/gate_details_widget/parameter_table_model.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "gui/selection_details_widget/gate_details_widget/parameter_table_model.h"
22

3+
#include "gui/user_action/action_set_parameter_value.h"
34
#include "hal_core/netlist/gate.h"
45
#include "hal_core/utilities/enums.h"
56

@@ -104,25 +105,9 @@ namespace hal
104105
return false;
105106
}
106107

107-
const std::string name = mRows[index.row()].name.toStdString();
108-
109-
Result<Parameter> param = this->mGate->get_parameter_declaration(name);
110-
if (param.is_error())
111-
{
112-
return false;
113-
}
114-
115-
Result<std::monostate> result = this->mGate->set_parameter(param.get(), value.toString().toStdString());
116-
if (result.is_error())
117-
{
118-
return false;
119-
}
120-
121-
std::string norm_value = this->mGate->get_parameter_value(name).get();
122-
this->mRows[index.row()].value = QString::fromStdString(norm_value);
123-
124-
Q_EMIT dataChanged(index, index);
125-
return true;
108+
auto act = new ActionSetParameterValue(mRows[index.row()].name, value.toString());
109+
act->setObject(UserActionObject(mGate->get_id(), UserActionObjectType::Gate));
110+
return act->exec();
126111
}
127112

128113
Qt::ItemFlags ParameterTableModel::flags(const QModelIndex& index) const
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#include "gui/user_action/action_set_parameter_value.h"
2+
3+
#include "gui/gui_globals.h"
4+
#include "gui/netlist_relay/netlist_relay.h"
5+
#include "hal_core/netlist/gate.h"
6+
7+
namespace hal
8+
{
9+
ActionSetParameterValueFactory::ActionSetParameterValueFactory() : UserActionFactory("SetParameterValue")
10+
{
11+
}
12+
ActionSetParameterValueFactory* ActionSetParameterValueFactory::sFactory = new ActionSetParameterValueFactory;
13+
14+
UserAction* ActionSetParameterValueFactory::newAction() const
15+
{
16+
return new ActionSetParameterValue;
17+
}
18+
19+
ActionSetParameterValue::ActionSetParameterValue(const QString& parameterName, const QString& value) : mParameterName(parameterName), mValue(value)
20+
{
21+
}
22+
23+
bool ActionSetParameterValue::exec()
24+
{
25+
if (mObject.type() != UserActionObjectType::Gate)
26+
{
27+
return false;
28+
}
29+
30+
// Resolve the gate.
31+
Gate* gate = gNetlist->get_gate_by_id(mObject.id());
32+
if (!gate)
33+
{
34+
return false;
35+
}
36+
37+
// Capture the current value BEFORE mutating, for the undo action:
38+
Result<std::string> old = gate->get_parameter_value(mParameterName.toStdString());
39+
if (old.is_error())
40+
{
41+
return false;
42+
}
43+
44+
// Build the inverse action and store it in mUndoAction:
45+
auto* undo = new ActionSetParameterValue(mParameterName, QString::fromStdString(old.get()));
46+
undo->setObject(mObject);
47+
mUndoAction = undo;
48+
49+
// Perform the mutation
50+
Result<Parameter> decl = gate->get_parameter_declaration(mParameterName.toStdString());
51+
if (decl.is_error())
52+
{
53+
return false;
54+
}
55+
56+
auto result = gate->set_parameter(decl.get(), mValue.toStdString());
57+
if (result.is_error())
58+
{
59+
return false;
60+
}
61+
62+
Q_EMIT gNetlistRelay->gateBooleanFunctionChanged(gate);
63+
return UserAction::exec();
64+
}
65+
66+
QString ActionSetParameterValue::tagname() const
67+
{
68+
return ActionSetParameterValueFactory::sFactory->tagname();
69+
}
70+
71+
void ActionSetParameterValue::writeToXml(QXmlStreamWriter& xmlOut) const
72+
{
73+
xmlOut.writeTextElement("name", mParameterName);
74+
xmlOut.writeTextElement("value", mValue);
75+
}
76+
77+
void ActionSetParameterValue::readFromXml(QXmlStreamReader& xmlIn)
78+
{
79+
while (xmlIn.readNextStartElement())
80+
{
81+
if (xmlIn.name() == "name")
82+
{
83+
mParameterName = xmlIn.readElementText();
84+
}
85+
else if (xmlIn.name() == "value")
86+
{
87+
mValue = xmlIn.readElementText();
88+
}
89+
}
90+
}
91+
92+
void ActionSetParameterValue::addToHash(QCryptographicHash& cryptoHash) const
93+
{
94+
cryptoHash.addData("name", 4);
95+
cryptoHash.addData(mParameterName.toUtf8());
96+
cryptoHash.addData("value", 5);
97+
cryptoHash.addData(mValue.toUtf8());
98+
}
99+
} // namespace hal

0 commit comments

Comments
 (0)