HAL
selection_relay.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_def.h"
29 #include "hal_config.h"
30 #include "hal_core/defines.h"
31 
32 #include <QList>
33 #include <QObject>
34 #include <QPair>
35 #include <QSet>
36 #include <QVector>
37 #include <vector>
38 
39 namespace hal
40 {
41  class Gate;
42  class Module;
43  class Net;
44 
45  class ActionSetSelectionFocus;
46  class UserActionObject;
47 
59  class SelectionRelay : public QObject
60  {
61  Q_OBJECT
62 
63  public:
68  enum class ItemType
69  {
70  None = 0,
71  Gate = 1,
72  Net = 2,
73  Module = 3
74  };
75 
82  enum class Subfocus
83  {
84  None = 0,
85  Left = 1,
86  Right = 2
87  };
88 
94  explicit SelectionRelay(QObject* parent = nullptr);
95 
100  void clear();
101 
106  void clearAndUpdate();
107 
114  void registerSender(void* sender, QString name);
115 
121  void removeSender(void* sender);
122 
123  // TEST METHOD
124  // USE RELAY METHODS OR ACCESS SIGNALS DIRECTLY ???
137  void relaySelectionChanged(void* sender);
138 
146  void relaySubfocusChanged(void* sender);
147 
152  void navigateUp();
153 
158  void navigateDown();
159 
166  void handleModuleRemoved(const u32 id);
167 
174  void handleGateRemoved(const u32 id);
175 
182  void handleNetRemoved(const u32 id);
183 
192  bool isModuleSelected(u32 id) const;
193 
202  bool isGateSelected(u32 id) const;
203 
212  bool isNetSelected(u32 id) const;
213 
224  //void suppressedByFilter(const QList<u32>& modIds = QList<u32>(), const QList<u32>& gatIds = QList<u32>(), const QList<u32>& netIds = QList<u32>());
225 
232  {
233  return mSelectedGates.values();
234  }
235 
242  {
243  return mSelectedNets.values();
244  }
245 
252  {
253  return mSelectedModules.values();
254  }
255 
262 
268  std::vector<u32> selectedGatesVector() const
269  {
270  return std::vector<u32>(mSelectedGates.begin(), mSelectedGates.end());
271  }
272 
278  std::vector<u32> selectedNetsVector() const
279  {
280  return std::vector<u32>(mSelectedNets.begin(), mSelectedNets.end());
281  }
282 
288  std::vector<u32> selectedModulesVector() const
289  {
290  return std::vector<u32>(mSelectedModules.begin(), mSelectedModules.end());
291  }
292 
298  const QSet<u32>& selectedGates() const
299  {
300  return mSelectedGates;
301  }
302 
308  const QSet<u32>& selectedNets() const
309  {
310  return mSelectedNets;
311  }
312 
318  const QSet<u32>& selectedModules() const
319  {
320  return mSelectedModules;
321  }
322 
329  {
330  return mSelectedGates.size();
331  }
332 
338  int numberSelectedNets() const
339  {
340  return mSelectedNets.size();
341  }
342 
349  {
350  return mSelectedModules.size();
351  }
352 
359  {
360  return mSelectedGates.size() + mSelectedModules.size();
361  }
362 
369  {
370  return mSelectedGates.size() + mSelectedModules.size() + mSelectedNets.size();
371  }
372 
379  bool containsGate(u32 id) const
380  {
381  return mSelectedGates.contains(id);
382  }
383 
390  bool containsNet(u32 id) const
391  {
392  return mSelectedNets.contains(id);
393  }
394 
401  bool containsModule(u32 id) const
402  {
403  return mSelectedModules.contains(id);
404  }
405 
411  void addGate(u32 id);
412 
418  void addNet(u32 id);
419 
425  void addModule(u32 id);
426 
433  void setSelectedGates(const QSet<u32>& ids);
434 
441  void setSelectedNets(const QSet<u32>& ids);
442 
449  void setSelectedModules(const QSet<u32>& ids);
450 
467  void actionSetSelected(const QSet<u32>& mods, const QSet<u32>& gats, const QSet<u32>& nets);
468 
474  void removeGate(u32 id);
475 
481  void removeNet(u32 id);
482 
488  void removeModule(u32 id);
489  Q_SIGNALS:
490  // TEST SIGNAL
491  // ADD ADDITIONAL INFORMATION (LIKE PREVIOUS FOCUS) OR LEAVE THAT TO SUBSCRIBERS ???
492  // USE SEPARATE OR COMBINED SIGNALS ??? MEANING DOES A SELECTION CAHNGE FIRE A SUBSELECTION CHANGED SIGNAL OR IS THAT IMPLICIT
501  //void focus_changed(void* sender); // UNCERTAIN
502 
510  void subfocusChanged(void* sender);
511 
512  public:
519  {
520  return mFocusType;
521  }
522 
528  u32 focusId() const
529  {
530  return mFocusId;
531  }
532 
539  {
540  return mSubfocus;
541  }
542 
549  {
550  return mSubfocusIndex;
551  }
552 
562  void setFocus(ItemType ftype, u32 fid, Subfocus sfoc = Subfocus::None, u32 sfinx = 0);
563 
574  void setFocusDirect(ItemType ftype, u32 fid, Subfocus sfoc = Subfocus::None, u32 sfinx = 0);
575 
582 
583  private:
584  void initializeAction();
585  void executeAction();
586 
587  ActionSetSelectionFocus* mAction;
588  bool mDisableExecution;
589 
590  // USE ARRAY[0] INSTEAD OF MEMBER ???
595  ItemType mFocusType;
596 
601  u32 mFocusId;
602 
607  Subfocus mSubfocus;
608 
615  u32 mSubfocusIndex; // HANDLE VIA INT OR STRING ?? INDEX HAS TO BE KNOWN ANYWAY TO FIND NEXT / PREVIOUS BOTH OPTIONS KIND OF BAD
616 
617  QSet<u32> mSelectedGates;
618  QSet<u32> mSelectedNets;
619  QSet<u32> mSelectedModules;
620 
621  QSet<u32> mModulesSuppressedByFilter;
622  QSet<u32> mGatesSuppressedByFilter;
623  QSet<u32> mNetsSuppressedByFilter;
624 
625  static bool sNavigationSkipsEnabled; // DOES THIS HAVE ANY USE ???
626 
627  // RENAME THESE METHODS ???
628  void followModuleInputPin(Module* m, u32 input_pin_index);
629  void followModuleOutputPin(Module* m, u32 output_pin_index);
630 
631 #ifdef HAL_STUDY
632  void evaluateSelectionChanged(void* sender);
633 #endif
634  void subfocusNone();
635  void subfocusLeft();
636  void subfocusRight();
637 
638  // bool try_subfocus_left();
639  // bool try_subfocus_right();
640  // bool try_subfocus_up();
641  // bool try_subfocus_down();
642 
643  QVector<QPair<void*, QString>> mSenderRegister;
644  };
645 } // namespace hal
Set the selection and focus.
Definition: gate.h:58
Definition: net.h:58
Stores and manages the gui's selection state.
int numberSelectedGates() const
ItemType focusType() const
QList< UserActionObject > toUserActionObject() const
int numberSelectedItems() const
bool containsGate(u32 id) const
void setFocus(ItemType ftype, u32 fid, Subfocus sfoc=Subfocus::None, u32 sfinx=0)
void selectionChanged(void *sender)
const QSet< u32 > & selectedNets() const
bool isNetSelected(u32 id) const
void relaySelectionChanged(void *sender)
int numberSelectedNets() const
void removeSender(void *sender)
void relaySubfocusChanged(void *sender)
QList< Node > selectedNodesList() const
QList< u32 > selectedModulesList() const
const QSet< u32 > & selectedGates() const
void setFocusDirect(ItemType ftype, u32 fid, Subfocus sfoc=Subfocus::None, u32 sfinx=0)
QList< u32 > selectedNetsList() const
const QSet< u32 > & selectedModules() const
Subfocus subfocus() const
std::vector< u32 > selectedGatesVector() const
int numberSelectedModules() const
void handleNetRemoved(const u32 id)
bool containsModule(u32 id) const
u32 subfocusIndex() const
std::vector< u32 > selectedNetsVector() const
void actionSetSelected(const QSet< u32 > &mods, const QSet< u32 > &gats, const QSet< u32 > &nets)
bool containsNet(u32 id) const
QList< u32 > selectedGatesList() const
void handleGateRemoved(const u32 id)
void handleModuleRemoved(const u32 id)
void setSelectedGates(const QSet< u32 > &ids)
SelectionRelay(QObject *parent=nullptr)
bool isModuleSelected(u32 id) const
std::vector< u32 > selectedModulesVector() const
void setSelectedNets(const QSet< u32 > &ids)
void subfocusChanged(void *sender)
int numberSelectedNodes() const
void registerSender(void *sender, QString name)
bool isGateSelected(u32 id) const
void setSelectedModules(const QSet< u32 > &ids)
ItemType
The ItemType enum provides the enum type to classify graphic items into Modules, Gates or Nets....
Definition: gui_def.h:45
quint32 u32
std::string name
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
QObject * sender() const const
QSet::iterator begin()
bool contains(const T &value) const const
QSet::iterator end()
int size() const const
QList< T > values() const const