HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
wave_tree_model.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 "hal_core/defines.h"
30 #include <QAbstractItemModel>
31 #include <QList>
32 #include <QDir>
33 #include <QThread>
34 #include <QObject>
35 #include <QMetaObject>
36 
37 namespace hal {
38  class WaveData;
39  class WaveDataList;
40  class WaveDataGroup;
41  class WaveGraphicsCanvas;
42 
46  class WaveDataRoot : public WaveDataGroup
47  {
48  public:
50  : WaveDataGroup(wdList,0,"root") {;}
51  void recalcData() override {;}
52  bool moveGroupPosition(int sourceRow, int targetRow);
53  void clearAll() { mGroupList.clear(); }
54  void dump() const;
55  };
56 
60  class WaveValueThread : public QThread
61  {
62  Q_OBJECT
63  WaveItem* mItem;
64  QDir mWorkDir;
65  u64 mTpos;
66  int mXpos;
67  int mValue;
68  bool mAbort;
69  Q_SIGNALS:
71  private Q_SLOTS:
72  void handleValueThreadFinished();
73  public:
74  WaveValueThread(WaveItem* item, const QString& workdir, u64 tpos, int xpos, QObject* parent = nullptr);
75  void run() override;
76  void abort() { mAbort = true; }
77  bool wasAborted() const { return mAbort; }
78  };
79 
84  {
85  Q_OBJECT
86 
87  public:
88  enum DragCommand { None, Move, Copy };
89 
94  {
95  WaveTreeModel* mParent;
96  public:
97  ReorderRequest(WaveTreeModel* p) : mParent(p) { mParent->mReorderRequestWaiting++; }
99  if (--mParent->mReorderRequestWaiting <= 0) mParent->emitReorder();
100  }
101  };
102 
103  private:
104  WaveDataList* mWaveDataList;
105  WaveItemHash* mWaveItemHash;
106  WaveGraphicsCanvas* mGraphicsCanvas;
107  WaveDataRoot* mRoot;
108  QModelIndexList mDragIndexList;
109  DragCommand mDragCommand;
110  bool mDragIsGroup;
111  u64 mCursorTime;
112  int mCursorXpos;
113  int mReorderRequestWaiting;
114  int mNumberEntriesChangedEvents;
115  QMap<WaveItem*,WaveValueThread*> mValueThreads;
116 
117  bool dropGroup(const QModelIndex& parentTo, int row);
118  void dropRow(const QModelIndex& parentTo, int row);
119  void invalidateParent(const QModelIndex& parentRow);
120  void updateGroup(WaveDataGroup* grp);
121  void emitReorder();
122  void addOrReplaceItem(WaveData* wd, WaveItemIndex::IndexType tp, int iwave, int parentId);
123  int valueAtCursor(const QModelIndex& index) const;
124  Q_SIGNALS:
127  void numberEntriesChanged(int count);
129 
130  public Q_SLOTS:
132  void handleWaveAdded(int iwave);
133  void handleWaveRenamed(int iwave);
134  void handleGroupRenamed(int grpId);
135  void handleWaveAddedToGroup(const QVector<u32>& netIds, int grpId);
136  void handleWaveRemovedFromGroup(int iwave, int grpId);
137  void handleBooleanAdded(int boolId);
138  void handleTriggerAdded(int trigId);
139  void handleGroupAdded(int grpId);
141  void handleGroupUpdated(int grpId);
142  void handleCursorMoved(u64 tCursor, int xpos);
143  void forwardBeginResetModel();
144  void forwardEndResetModel();
145  //void handleValueLoaderFinished();
148 
149  public:
150  WaveTreeModel(WaveDataList* wdlist, WaveItemHash* wHash, WaveGraphicsCanvas* wgc, QObject* obj=nullptr);
151  bool isLeaveItem(const QModelIndex &index) const;
152  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
153  QModelIndexList indexes(const WaveData* wd) const;
154  QModelIndexList indexes(const QSet<u32>& netIds) const;
155  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
156  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
157  QString netName(const QModelIndex& index) const;
158  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
159  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
160  QModelIndex parent(const QModelIndex &child) const override;
161  Qt::ItemFlags flags(const QModelIndex &index) const override;
162  Qt::DropActions supportedDragActions() const override;
163  bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &dropParent) override;
164  bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
165  void setDragIndexes(const QModelIndexList& indexList);
166 
167  bool insertItem(int row, const QModelIndex &parent, WaveData* wd);
168  void insertExisting(int row, const QModelIndex& parent, WaveItem* wi);
169  WaveItem* removeItemFromHash(int row, const QModelIndex &parent);
170  void removeGroup(const QModelIndex& groupIndex);
171  void insertBoolean(const QModelIndex& boolIndex, const QString& boolExpression, WaveDataBoolean* wdBool=nullptr);
172  void insertBoolean(const QModelIndex& boolIndex, const QList<WaveData*>& boolWaves, const QList<int>& acceptMask);
173  void insertTrigger(const QModelIndex& trigIndex, const QList<WaveData*>& trigWaves, const QList<int>& toVal,
174  WaveData* wdFilter=nullptr, WaveDataTrigger *wdTrig=nullptr);
175  void insertGroup(const QModelIndex& groupIndex, WaveDataGroup *grp=nullptr);
176  int waveIndex(const QModelIndex& index) const;
177  int groupId(const QModelIndex& grpIndex) const;
178  int booleanId(const QModelIndex& boolIndex) const;
179  int triggerId(const QModelIndex& trigIndex) const;
180  WaveData* item(const QModelIndex& index) const;
182 
183  void setGroupPosition(int ypos, const QModelIndex& index);
184  void addWaves(const QVector<WaveData*>& wds);
185  bool onlyRootItemsSelected(const QModelIndexList& selectList) const;
186 
187  u64 cursorTime() const { return mCursorTime; }
188  int cursorXpos() const { return mCursorXpos; }
189 
190  QSet<int> waveDataIndexSet() const;
191 
192  static const char* sStateColor[3];
193  bool persist() const;
194  void restore();
196  };
197 }
QList< WaveData * > mGroupList
Definition: wave_data.h:330
WaveDataRoot(WaveDataList *wdList)
bool moveGroupPosition(int sourceRow, int targetRow)
void recalcData() override
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
void addWaves(const QVector< WaveData * > &wds)
Qt::DropActions supportedDragActions() const override
WaveItem * removeItemFromHash(int row, const QModelIndex &parent)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
void handleWaveAddedToGroup(const QVector< u32 > &netIds, int grpId)
void handleWaveRemovedFromGroup(int iwave, int grpId)
int triggerId(const QModelIndex &trigIndex) const
QModelIndexList indexes(const WaveData *wd) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
void handleWaveAdded(int iwave)
u64 cursorTime() const
void numberEntriesChanged(int count)
void handleGroupRenamed(int grpId)
void handleEndValueThread(WaveItem *item)
void insertTrigger(const QModelIndex &trigIndex, const QList< WaveData * > &trigWaves, const QList< int > &toVal, WaveData *wdFilter=nullptr, WaveDataTrigger *wdTrig=nullptr)
QString netName(const QModelIndex &index) const
static const char * sStateColor[3]
WaveData * item(const QModelIndex &index) const
void inserted(QModelIndex index)
int decreaseNumberEntriesChangedEvents()
void insertExisting(int row, const QModelIndex &parent, WaveItem *wi)
void handleTriggerAdded(int trigId)
int cursorXpos() const
Qt::ItemFlags flags(const QModelIndex &index) const override
void setDragIndexes(const QModelIndexList &indexList)
void handleGroupAboutToBeRemoved(WaveDataGroup *grp)
void handleCursorMoved(u64 tCursor, int xpos)
int waveIndex(const QModelIndex &index) const
void triggerStartValueThread(WaveItem *item) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void removeGroup(const QModelIndex &groupIndex)
void handleWaveRenamed(int iwave)
void handleGroupAdded(int grpId)
WaveTreeModel(WaveDataList *wdlist, WaveItemHash *wHash, WaveGraphicsCanvas *wgc, QObject *obj=nullptr)
bool onlyRootItemsSelected(const QModelIndexList &selectList) const
int groupId(const QModelIndex &grpIndex) const
bool insertItem(int row, const QModelIndex &parent, WaveData *wd)
void handleStartValueThread(WaveItem *item)
int booleanId(const QModelIndex &boolIndex) const
bool isLeaveItem(const QModelIndex &index) const
QSet< int > waveDataIndexSet() const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void handleGroupUpdated(int grpId)
void setGroupPosition(int ypos, const QModelIndex &index)
void insertGroup(const QModelIndex &groupIndex, WaveDataGroup *grp=nullptr)
bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &dropParent) override
void insertBoolean(const QModelIndex &boolIndex, const QString &boolExpression, WaveDataBoolean *wdBool=nullptr)
WaveItemIndex hashIndex(const QModelIndex &index) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void handleBooleanAdded(int boolId)
void valueThreadEnds(hal::WaveItem *item)
WaveValueThread(WaveItem *item, const QString &workdir, u64 tpos, int xpos, QObject *parent=nullptr)
bool wasAborted() const
uint64_t u64
Definition: defines.h:42
Definition: defines.h:45
virtual QMimeData * mimeData(const QModelIndexList &indexes) const const
void clear()
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
typedef DropActions
DisplayRole
typedef ItemFlags
Orientation