HAL
action_pingroup.h
Go to the documentation of this file.
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"
29 #include <QString>
30 #include <QObject>
31 
32 namespace hal
33 {
34  class PinActionType : public QObject
35  {
36  Q_OBJECT
37  public:
41 
42  public:
43  static QString toString(Type tp);
44  static Type fromString(const QString& s);
45  static bool useExistingGroup(Type tp);
46  static bool useExistingPin(Type tp);
47  };
48 
49  int pinGroupIndex(const Module* mod, const PinGroup<ModulePin>* pgrp);
50 
51  int pinIndex2Row(const ModulePin* pin, int index);
52 
53  int pinRow2Index(const ModulePin* pin, int row);
54 
55  QString generateGroupName(const Module* mod, const ModulePin* pin);
56 
57  void dumpPingroups(Module* m = nullptr);
111  class ActionPingroup : public UserAction
112  {
113  private:
114  class AtomicAction
115  {
116  public:
117  PinActionType::Type mType;
118  int mId;
119  QString mName;
120  int mValue;
121  AtomicAction(PinActionType::Type tp, int id, const QString& name = QString(), int v=0) : mType(tp), mId(id), mName(name), mValue(v) {;}
122  };
123 
124  class GroupRestore
125  {
126  public:
127  int mId;
128  QString mName;
129  int mRow;
130  int mStartIndex;
131  PinDirection mDirection;
132  PinType mType;
133  GroupRestore(Module* m, PinGroup<ModulePin>* pgroup);
134  };
135 
136  QHash<int,PinGroup<ModulePin>*> mPinGroups;
137  QList<AtomicAction> mPinActions;
138  Module* mParentModule;
139  QMap<int,GroupRestore> mGroupRestore;
140  QSet<u32> mPinsMoved;
141  QSet<int> mGroupToRemove;
142 
143  PinGroup<ModulePin>* getGroup(ModulePin* pin) const;
144  PinGroup<ModulePin>* getGroup(int grpId) const;
145  void prepareUndoAction();
146  void finalizeUndoAction();
147  void addUndoAction(PinActionType::Type tp, int id = 0, const QString& name=QString(), int value=0);
148  static int pinGroupRow(Module* m, PinGroup<ModulePin>* pgroup);
149  public:
150  ActionPingroup(PinActionType::Type tp = PinActionType::None, int id = 0, const QString& name=QString(), int value=0);
151  ActionPingroup(const QList<AtomicAction>& aaList);
152  bool exec() override;
153  QString tagname() const override;
154  void writeToXml(QXmlStreamWriter& xmlOut) const override;
155  void readFromXml(QXmlStreamReader& xmlIn) override;
156  void addToHash(QCryptographicHash& cryptoHash) const override;
157 
158  static ActionPingroup* addPinsToExistingGroup(const Module* m, u32 grpId, QList<u32> pinIds, int pinRow = -1);
159  static ActionPingroup* addPinToExistingGroup(const Module* m, u32 grpId, u32 pinId, int pinRow = -1);
160  static ActionPingroup* addPinsToNewGroup(const Module* m, const QString& name, QList<u32> pinIds, int grpRow = -1);
161  static ActionPingroup* addPinToNewGroup(const Module* m, const QString& name, u32 pinId, int grpRow = -1);
162  static ActionPingroup* removePinsFromGroup(const Module* m, QList<u32> pinIds);
163  static ActionPingroup* deletePinGroup(const Module* m, u32 grpId);
164  };
165 
171  {
172  public:
174  UserAction* newAction() const;
176  };
177 
178  uint qHash(PinEvent pev);
179 }
UserActionFactory for ActionPingroup.
UserAction * newAction() const
static ActionPingroupFactory * sFactory
Pingroup user actions.
static ActionPingroup * addPinToNewGroup(const Module *m, const QString &name, u32 pinId, int grpRow=-1)
static ActionPingroup * deletePinGroup(const Module *m, u32 grpId)
void readFromXml(QXmlStreamReader &xmlIn) override
static ActionPingroup * addPinToExistingGroup(const Module *m, u32 grpId, u32 pinId, int pinRow=-1)
void writeToXml(QXmlStreamWriter &xmlOut) const override
static ActionPingroup * addPinsToExistingGroup(const Module *m, u32 grpId, QList< u32 > pinIds, int pinRow=-1)
ActionPingroup(PinActionType::Type tp=PinActionType::None, int id=0, const QString &name=QString(), int value=0)
void addToHash(QCryptographicHash &cryptoHash) const override
static ActionPingroup * addPinsToNewGroup(const Module *m, const QString &name, QList< u32 > pinIds, int grpRow=-1)
static ActionPingroup * removePinsFromGroup(const Module *m, QList< u32 > pinIds)
bool exec() override
QString tagname() const override
static Type fromString(const QString &s)
static QString toString(Type tp)
static bool useExistingPin(Type tp)
static bool useExistingGroup(Type tp)
The UserActionFactory is the abstract base class for registration.
Definition: user_action.h:225
The UserAction class is the abstract base class for user interactions.
Definition: user_action.h:57
PinDirection
Definition: pin_direction.h:36
int pinGroupIndex(const Module *mod, const PinGroup< ModulePin > *pgrp)
PinEvent
Definition: pin_event.h:42
int pinIndex2Row(const ModulePin *pin, int index)
int pinRow2Index(const ModulePin *pin, int row)
void dumpPingroups(Module *m=nullptr)
PinType
Definition: pin_type.h:36
QString generateGroupName(const Module *mod, const ModulePin *pin)
uint qHash(const LaneIndex &ri)
quint32 u32
std::string name
Q_OBJECTQ_OBJECT