HAL
pin_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 "gui/gui_globals.h"
29 #include "gui/gui_utils/sort.h"
30 #include "gui/pin_model/pin_item.h"
32 #include "hal_core/defines.h"
33 #include "hal_core/netlist/gate.h"
34 #include "hal_core/netlist/net.h"
35 
36 #include <QAbstractItemModel>
37 #include <QModelIndex>
38 #include <QVariant>
39 #include <QMessageBox>
40 #include <QPushButton>
41 #include <QComboBox>
42 #include <array>
43 #include <set>
44 
45 namespace hal
46 {
47 
48 
49  class PinModel : public BaseTreeModel
50  {
51  Q_OBJECT
52 
53  Q_SIGNALS:
55 
56  public:
57 
58  explicit PinModel(QObject* parent = nullptr);
59  explicit PinModel(QObject* parent, bool editable);
60 
61  ~PinModel();
62 
69  Qt::ItemFlags flags(const QModelIndex& index) const override;
70 
75  void setGate(GateType* gate);
76 
82  void handleEditName(QModelIndex index, const QString& input);
83 
89  void handleEditDirection(QModelIndex index, const QString& directionString);
90 
96  void handleEditType(QModelIndex index, const QString& typeString);
97 
99 
105 
108 
109  private:
110  QList<PinItem*> mInvalidPins = QList<PinItem*>();
111  QList<PinItem*> mInvalidGroups = QList<PinItem*>();
112 
121  bool isNameAvailable(const QString& newName, PinItem* treeItem);
122  void handleInvalidPinUpdate(PinItem* pinItem);
123  void handleInvalidGroupUpdate(PinItem* groupItem);
124  bool renamePin(PinItem* pinItem, const QString& newName);
125  bool renamePinGroup(PinItem* groupItem, const QString& newName);
126  void addPinToPinGroup(PinItem* pinItem, PinItem* groupItem);
127  void handleGroupDirectionUpdate(PinItem* groupItem ,PinDirection direction = PinDirection::none);
128  u32 getNextId(PinItem::TreeItemType type);
129  void handleItemRemoved(PinItem* item);
130  //TODO delete - only for testing
131  void printGateMember();
132 
133 
134  QSet<QString> mAssignedNames;
135  QSet<QString> mAssignedPinNames;
136  QSet<QString> mAssignedGroupNames;
137  bool mEditable;
138 
139  };
140 } // 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 PinModel.
Definition: pin_item.h:48
QList< PinItem * > getInputPins()
Definition: pin_model.cpp:729
PinModel(QObject *parent=nullptr)
Definition: pin_model.cpp:7
QList< PinItem * > getOutputPins()
Definition: pin_model.cpp:744
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition: pin_model.cpp:32
void handleEditDirection(QModelIndex index, const QString &directionString)
Definition: pin_model.cpp:252
QList< PinItem * > getPinGroups() const
Definition: pin_model.cpp:632
void setGate(GateType *gate)
Definition: pin_model.cpp:41
void handleEditName(QModelIndex index, const QString &input)
Definition: pin_model.cpp:148
void editNewDone(QModelIndex index)
void handleDeleteItem(QModelIndex index)
Definition: pin_model.cpp:644
void handleEditType(QModelIndex index, const QString &typeString)
Definition: pin_model.cpp:308
PinDirection
Definition: pin_direction.h:36
quint32 u32
PinType type
PinDirection direction
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
typedef ItemFlags