HAL  v4.5.0-283-g3f42a39fa
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
clock_tree_viewer.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 // Copyright (c) 2025-2026 Sascha Tommasone. All rights reserved.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 // SOFTWARE.
26 
27 #pragma once
28 
32 
33 #include <QHash>
34 #include <QPointer>
35 #include <QSet>
36 #include <QString>
37 #include <QThread>
38 #include <QVector>
39 #include <cstddef>
40 #include <optional>
41 #include <string>
42 #include <vector>
43 
44 class QAction;
45 class QColor;
46 class QLabel;
47 class QStackedWidget;
48 class QStatusBar;
49 class QTimer;
50 
51 namespace hal
52 {
53  namespace cte
54  {
55  class ClockTree;
56  }
57 
58  class ClockTreeGraphicsView;
59  class ClockTreeScene;
60  struct ClockTreeColors;
61  class Toolbar;
62 
79  {
80  Q_OBJECT
81 
82  public:
84  static constexpr auto sPluginName = "clock_tree_viewer";
85 
91  explicit ClockTreeViewer( QWidget *parent = nullptr );
92 
96  ~ClockTreeViewer() override;
97 
104  static ClockTreeViewer *instance();
105 
111  void setupToolbar( Toolbar *toolbar ) override;
112 
133  static bool setClockTree( const cte::ClockTree &tree,
134  const ctv::StyleOverrides &overrides = ctv::StyleOverrides(),
135  const std::optional<std::string> &x_key = ctv::DEFAULT_X_KEY,
136  const std::optional<std::string> &y_key = ctv::DEFAULT_Y_KEY );
137 
145  bool savePicture( const QString &filename );
146 
156  static std::size_t highlightGates( const std::vector<u32> &gateIds );
157 
163  [[nodiscard]] const QSet<u32> &highlightedGates() const
164  {
165  return mHighlightedGates;
166  }
167 
168  private Q_SLOTS:
173  void handleExtractClicked();
174 
178  void handleFileAboutToClose();
179 
183  void handleFitClicked() const;
184 
188  void handleSavePictureClicked();
189 
193  void handleZoomToHighlightClicked();
194 
198  void handleSelectionChanged();
199 
206  void handleCoordinatesChanged( double x, double y );
207 
211  void handleStyleChanged();
212 
216  void recolor();
217 
221  void scheduleRecolor();
222 
223  private:
228  bool display( const Result<ctv::Layout> &layout,
229  const ctv::StyleOverrides &overrides,
230  const std::optional<std::string> &x_key,
231  const std::optional<std::string> &y_key );
232 
236  void applyThemeColors() const;
237 
241  [[nodiscard]] QVector<int> highlightedNodes() const;
242 
248  bool showError( const QString &message );
249 
253  void showWarning( const QString &message ) const;
254 
258  void updateActions() const;
259 
263  void highlightFromSelection();
264 
270  std::size_t applyHighlight( const std::vector<u32> &gateIds );
271 
275  [[nodiscard]] ClockTreeColors currentColors() const;
276 
283  [[nodiscard]] QColor gateColor( u32 gateId, const QColor &fallback ) const;
284 
288  [[nodiscard]] QColor backgroundColor() const;
289 
290  ClockTreeScene *mScene;
291  ClockTreeGraphicsView *mView;
292  QStackedWidget *mStack;
293  QLabel *mMessageLabel;
294  QStatusBar *mStatusBar;
295  QLabel *mCoordinateLabel;
296  QLabel *mWarningLabel;
297  QLabel *mHighlightLabel;
298 
299  QAction *mExtractAction;
300  QAction *mFitAction;
301  QAction *mSavePictureAction;
302  QAction *mZoomToHighlightAction;
303 
304  QTimer *mRecolorTimer;
305 
307  ctv::Layout mLayout;
308 
310  QHash<u32, int> mNodeOfGate;
311 
313  QSet<u32> mHighlightedGates;
314 
319  ctv::StyleOverrides mOverrides;
320  std::optional<std::string> mXKey = ctv::DEFAULT_X_KEY;
321  std::optional<std::string> mYKey = ctv::DEFAULT_Y_KEY;
322 
324  bool mShowsError = false;
325 
327  QPointer<QThread> mExtraction;
328  };
329 } // namespace hal
ClockTreeViewer(QWidget *parent=nullptr)
static std::size_t highlightGates(const std::vector< u32 > &gateIds)
static constexpr auto sPluginName
bool savePicture(const QString &filename)
const QSet< u32 > & highlightedGates() const
static ClockTreeViewer * instance()
void setupToolbar(Toolbar *toolbar) override
static bool setClockTree(const cte::ClockTree &tree, const ctv::StyleOverrides &overrides=ctv::StyleOverrides(), const std::optional< std::string > &x_key=ctv::DEFAULT_X_KEY, const std::optional< std::string > &y_key=ctv::DEFAULT_Y_KEY)
Toolbar for all ContentFrames and ContentWidgets.
Definition: toolbar.h:39
uint32_t u32
Definition: defines.h:41
const std::string DEFAULT_Y_KEY
const std::string DEFAULT_X_KEY
Definition: defines.h:45
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
QLayout * layout() const const