HAL
module_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 
28 #include "hal_core/defines.h"
29 #include "gui/gui_utils/sort.h"
32 
33 
34 #include <QAbstractItemModel>
35 #include <QModelIndex>
36 #include <QVariant>
37 #include <set>
38 #include <array>
39 #include <vector>
40 #include <QTextStream>
41 
42 namespace hal
43 {
44 
53  class ModuleModel : public BaseTreeModel
54  {
55  friend class ModuleItem;
56  Q_OBJECT
57 
61  class TempGateAssignment
62  {
63  int mAccumulate;
64  public:
65  QHash<u32, Module*> mGateRemove;
66  QHash<u32, Module*> mGateAssign;
67 
68  TempGateAssignment() : mAccumulate(0) {;}
69  void removeGateFromModule(u32 gateId, Module* m)
70  {
71  if (!mGateRemove.contains(gateId))
72  mGateRemove[gateId] = m;
73  }
74  void assignGateToModule(u32 gateId, Module* m)
75  {
76  mGateAssign[gateId] = m;
77  }
78  bool isAccumulate() const { return mAccumulate > 0; }
79  void beginAccumulate() { mAccumulate++; }
80  void endAccumulate() { mAccumulate--; }
81  };
82 
83  public:
90  explicit ModuleModel(QObject* parent = nullptr);
91 
92  // === Pure Virtual ===
93 
101  QVariant data(const QModelIndex& index, int role) const override;
102 
103  // === Virtual ===
110  Qt::ItemFlags flags(const QModelIndex& index) const override;
111 
112  // === Others ===
113 
120  ModuleItem* getItem(const QModelIndex& index) const;
121 
130 
139 
143  void clear() override;
144 
145  QMimeData* mimeData(const QModelIndexList &indexes) const override;
146 
158  void populateTree(const QVector<u32>& modIds = {}, const QVector<u32>& gatIds = {}, const QVector<u32>& netIds = {});
159 
167  void populateFromGatelist(const std::vector<Gate*>& gates);
168 
175  void addModule(const u32 id, const u32 parentId);
176 
183  void addGate(const u32 id, const u32 parentId);
184 
191  void addNet(const u32 id, const u32 parentId);
192 
201  void addRecursively(const Module* module, BaseTreeItem* parentItem = nullptr);
202 
208  void removeModule(const u32 id);
209 
215  void removeGate(const u32 id);
216 
222  void removeNet(const u32 id);
223 
228  void moduleAssignGate(const u32 moduleId, const u32 gateId);
229 
234  void moduleAssignNets(const QList<u32>& gateIds = QList<u32>());
235 
244  void updateNetParent(const Net* net, const QHash<const Net*,ModuleItem*>* parentAssignment = nullptr);
245 
252  void updateModuleParent(const Module* module);
253 
259  void updateModuleName(const u32 id);
260 
266  void updateGateName(const u32 id);
267 
273  void updateNetName(const u32 id);
274 
282  bool isModifying();
283 
284  private Q_SLOTS:
285  void handleModuleNameChanged(Module* mod);
286 
287  void handleModuleRemoved(Module* mod);
288 
289  void handleModuleCreated(Module* mod);
290 
298  void handleModuleParentChanged(const Module* mod);
299 
300  void handleModuleSubmoduleAdded(Module* mod, u32 submodId);
301 
302  void handleModuleSubmoduleRemoved(Module* mod, u32 submodId);
303 
304  void handleModuleGateAssigned(Module* mod, u32 gateId);
305 
306  void handleModuleGateRemoved(Module* mod, u32 gateId);
307 
308  void handleModuleGatesAssignBegin(Module* mod, u32 numberGates);
309 
310  void handleModuleGatesAssignEnd(Module* mod, u32 numberGates);
311 
312  void handleGateCreated(Gate* gat);
313 
314  void handleGateNameChanged(Gate* gat);
315 
316  void handleGateRemoved(Gate* gat);
317 
318  void handleNetCreated(Net* net);
319 
320  void handleNetNameChanged(Net* net);
321 
322  void handleNetRemoved(Net* net);
323 
324  void handleNetUpdated(Net* net, u32 data);
325 
326  protected:
334  ModuleItem* createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem* parentItem = nullptr);
335 
342  void removeChildItem(ModuleItem* itemToRemove, BaseTreeItem* parentItem);
343 
347  void setIsModifying(bool pIsModifying);
348 
349  private:
359  Module* findNetParent(const Net* net) const;
360 
367  void findNetParentRecursion(BaseTreeItem* parent, QHash<const Net*,ModuleItem*>& parentAssignment, std::unordered_set<Net*>& assignedNets) const;
368 
369  QMultiMap<u32, ModuleItem*> mModuleMap;
372  QMultiMap<u32, ModuleItem*>* mModuleItemMaps[3] = {&mModuleMap, &mGateMap, &mNetMap};;
373 
374  bool mIsModifying;
375  TempGateAssignment mTempGateAssignment;
376  };
377 } // namespace hal
The BaseTreeModel implements generic standard functions of a tree model.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
An item in the ModuleModel.
Definition: module_item.h:48
A model for displaying multiple netlist elements.
Definition: module_model.h:54
void updateModuleParent(const Module *module)
Qt::ItemFlags flags(const QModelIndex &index) const override
void updateNetName(const u32 id)
void addRecursively(const Module *module, BaseTreeItem *parentItem=nullptr)
void addNet(const u32 id, const u32 parentId)
void removeGate(const u32 id)
void moduleAssignNets(const QList< u32 > &gateIds=QList< u32 >())
void removeModule(const u32 id)
QList< ModuleItem * > getItems(const u32 id, ModuleItem::TreeItemType type=ModuleItem::TreeItemType::Module) const
void addGate(const u32 id, const u32 parentId)
ModuleItem * getItem(const QModelIndex &index) const
void populateFromGatelist(const std::vector< Gate * > &gates)
ModuleItem * createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem *parentItem=nullptr)
void updateGateName(const u32 id)
void addModule(const u32 id, const u32 parentId)
QVariant data(const QModelIndex &index, int role) const override
void updateNetParent(const Net *net, const QHash< const Net *, ModuleItem * > *parentAssignment=nullptr)
void setIsModifying(bool pIsModifying)
ModuleModel(QObject *parent=nullptr)
void removeNet(const u32 id)
QMimeData * mimeData(const QModelIndexList &indexes) const override
void updateModuleName(const u32 id)
void clear() override
void removeChildItem(ModuleItem *itemToRemove, BaseTreeItem *parentItem)
void populateTree(const QVector< u32 > &modIds={}, const QVector< u32 > &gatIds={}, const QVector< u32 > &netIds={})
friend class ModuleItem
Definition: module_model.h:55
void moduleAssignGate(const u32 moduleId, const u32 gateId)
const Module * module(const Gate *g, const NodeBoxes &boxes)
quint32 u32
PinType type
Net * net
bool contains(const Key &key) const const
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
typedef ItemFlags