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  void dumpPingroups(Module* m = nullptr);
102  class ActionPingroup : public UserAction
103  {
104  private:
105  class AtomicAction
106  {
107  public:
108  PinActionType::Type mType;
109  int mId;
110  QString mName;
111  int mValue;
112  AtomicAction(PinActionType::Type tp, int id, const QString& name = QString(), int v=0) : mType(tp), mId(id), mName(name), mValue(v) {;}
113  };
114 
115  class GroupRestore
116  {
117  public:
118  int mId;
119  QString mName;
120  int mRow;
121  int mStartIndex;
122  PinDirection mDirection;
123  PinType mType;
124  GroupRestore(Module* m, PinGroup<ModulePin>* pgroup);
125  };
126 
127  QHash<int,PinGroup<ModulePin>*> mPinGroups;
128  QList<AtomicAction> mPinActions;
129  QList<QList<AtomicAction> > mTempUndoActions;
130  Module* mParentModule;
131  QMap<int,GroupRestore> mGroupRestore;
132  QSet<u32> mPinsMoved;
133  QSet<int> mGroupToRemove;
134 
135  PinGroup<ModulePin>* getGroup(ModulePin* pin) const;
136  PinGroup<ModulePin>* getGroup(int grpId) const;
137  void prepareUndoAction();
138  void finalizeUndoAction();
139  static int pinGroupRow(const Module *m, PinGroup<ModulePin>* pgroup);
140  public:
141  ActionPingroup(PinActionType::Type tp = PinActionType::None, int id = 0, const QString& name=QString(), int value=0);
142  ActionPingroup(const QList<AtomicAction>& aaList);
143  bool exec() override;
144  QString tagname() const override;
145  void writeToXml(QXmlStreamWriter& xmlOut) const override;
146  void readFromXml(QXmlStreamReader& xmlIn) override;
147  void addToHash(QCryptographicHash& cryptoHash) const override;
148 
149  static ActionPingroup* addPinsToExistingGroup(const Module* m, u32 grpId, QList<u32> pinIds, int pinRow = -1);
150  static ActionPingroup* addPinToExistingGroup(const Module* m, u32 grpId, u32 pinId, int pinRow = -1);
151  static ActionPingroup* addPinsToNewGroup(const Module* m, const QString& name, QList<u32> pinIds, int grpRow = -1);
152  static ActionPingroup* addPinToNewGroup(const Module* m, const QString& name, u32 pinId, int grpRow = -1);
153  static ActionPingroup* removePinsFromGroup(const Module* m, QList<u32> pinIds);
154  static ActionPingroup* deletePinGroup(const Module* m, u32 grpId);
155  static ActionPingroup* toggleAscendingGroup(const Module* m, u32 grpId);
156  static ActionPingroup* changePinGroupType(const Module* m, u32 grpId, int ptype);
157 
158  static int pinGroupIndex(const Module* mod, const PinGroup<ModulePin>* pgrp);
159  static int pinIndex2Row(const ModulePin* pin, int index);
160  static int pinRow2Index(const ModulePin* pin, int row);
161  static QString generateGroupName(const Module* mod, const ModulePin* pin);
162  };
163 
169  {
170  public:
172  UserAction* newAction() const;
174  };
175 
176  uint qHash(PinEvent pev);
177 }
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 QString generateGroupName(const Module *mod, const ModulePin *pin)
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)
static int pinGroupIndex(const Module *mod, const PinGroup< ModulePin > *pgrp)
static int pinIndex2Row(const ModulePin *pin, int index)
static ActionPingroup * toggleAscendingGroup(const Module *m, u32 grpId)
void addToHash(QCryptographicHash &cryptoHash) const override
static ActionPingroup * addPinsToNewGroup(const Module *m, const QString &name, QList< u32 > pinIds, int grpRow=-1)
static int pinRow2Index(const ModulePin *pin, int row)
static ActionPingroup * removePinsFromGroup(const Module *m, QList< u32 > pinIds)
bool exec() override
QString tagname() const override
static ActionPingroup * changePinGroupType(const Module *m, u32 grpId, int ptype)
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
PinEvent
Definition: pin_event.h:42
void dumpPingroups(Module *m=nullptr)
PinType
Definition: pin_type.h:36
uint qHash(const LaneIndex &ri)
quint32 u32
std::string name
Q_OBJECTQ_OBJECT