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 updateModuleType(const u32 id);
267 
273  void updateGateName(const u32 id);
274 
280  void updateNetName(const u32 id);
281 
289  bool isModifying();
290 
291  private Q_SLOTS:
292  void handleModuleNameChanged(Module* mod);
293 
294  void handleModuleTypeChanged(Module* mod);
295 
296  void handleModuleRemoved(Module* mod);
297 
298  void handleModuleCreated(Module* mod);
299 
307  void handleModuleParentChanged(const Module* mod);
308 
309  void handleModuleSubmoduleAdded(Module* mod, u32 submodId);
310 
311  void handleModuleSubmoduleRemoved(Module* mod, u32 submodId);
312 
313  void handleModuleGateAssigned(Module* mod, u32 gateId);
314 
315  void handleModuleGateRemoved(Module* mod, u32 gateId);
316 
317  void handleModuleGatesAssignBegin(Module* mod, u32 numberGates);
318 
319  void handleModuleGatesAssignEnd(Module* mod, u32 numberGates);
320 
321  void handleGateCreated(Gate* gat);
322 
323  void handleGateNameChanged(Gate* gat);
324 
325  void handleGateRemoved(Gate* gat);
326 
327  void handleNetCreated(Net* net);
328 
329  void handleNetNameChanged(Net* net);
330 
331  void handleNetRemoved(Net* net);
332 
333  void handleNetUpdated(Net* net, u32 data);
334 
335  protected:
343  ModuleItem* createChildItem(u32 id, ModuleItem::TreeItemType itemType, BaseTreeItem* parentItem = nullptr);
344 
351  void removeChildItem(ModuleItem* itemToRemove, BaseTreeItem* parentItem);
352 
356  void setIsModifying(bool pIsModifying);
357 
358  private:
368  Module* findNetParent(const Net* net) const;
369 
376  void findNetParentRecursion(BaseTreeItem* parent, QHash<const Net*,ModuleItem*>& parentAssignment, std::unordered_set<Net*>& assignedNets) const;
377 
378  QMultiMap<u32, ModuleItem*> mModuleMap;
381  QMultiMap<u32, ModuleItem*>* mModuleItemMaps[3] = {&mModuleMap, &mGateMap, &mNetMap};;
382 
383  bool mIsModifying;
384  TempGateAssignment mTempGateAssignment;
385  };
386 } // 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 updateModuleType(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