HAL
graph_context.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 
30 #include "gui/gui_def.h"
32 
33 #include <QDateTime>
34 #include <QJsonObject>
35 #include <QObject>
36 #include <QSet>
37 
38 namespace hal
39 {
40  class GraphWidget;
41 
54  class GraphContext : public QObject
55  {
56  friend class GraphContextManager;
57  friend class LayoutLockerManager;
58  Q_OBJECT
59 
60  public:
68  explicit GraphContext(u32 id_, const QString& name, QObject* parent = nullptr);
69 
74  ~GraphContext();
75 
81  void beginChange();
82 
87  void endChange();
88 
98  void add(const QSet<u32>& modules, const QSet<u32>& gates, PlacementHint placement = PlacementHint());
99 
107  void remove(const QSet<u32>& modules, const QSet<u32>& gates);
108 
112  void clear();
113 
120  bool isGateUnfolded(u32 gateId) const;
121 
127  bool isModuleUnfolded(const u32 moduleId) const;
128 
129 
130  void refreshModule(const u32 moduleId);
131 
138  void unfoldModule(const u32 id, const PlacementHint& plc);
139 
145  bool empty() const;
146 
151  bool willBeEmptied() const;
152 
159  bool isShowingModule(const u32 id) const;
160 
178  bool isShowingModule(const u32 id, const QSet<u32>& minus_modules, const QSet<u32>& minus_gates, const QSet<u32>& plus_modules, const QSet<u32>& plus_gates) const;
179 
184 
192  void getModuleChildrenRecursively(const u32 moduleId, QSet<u32>* gates, QSet<u32>* modules) const;
193 
197  void storeViewport();
198 
203  void layoutProgress(int percent) const;
204 
212  void testIfAffected(const u32 id, const u32* moduleId, const u32* gateId);
213 
220  bool isShowingNetSource(const u32 mNetId) const;
221 
228  bool isShowingNetDestination(const u32 mNetId) const;
229 
235  bool isShowingFoldedTopModule() const;
236 
243  Node getNetSource(const Net* n) const;
244 
251  Node getNetDestination(const Net* n) const;
252 
258  const QSet<u32>& modules() const;
259 
265  const QSet<u32>& gates() const;
266 
272  const QSet<u32>& nets() const;
273 
279  GraphicsScene* scene();
280 
286  QString name() const;
287 
294 
300  u32 id() const;
301 
307  void setLayouter(GraphLayouter* layouter);
308 
314  void setShader(GraphShader* shader);
315 
323  {
324  return mLayouter;
325  }
326 
331  void updatePlacement(const GridPlacement& plc);
332 
338  bool sceneUpdateInProgress() const;
339 
344  void scheduleSceneUpdate();
345 
356  Node nodeForGate(const u32 id) const;
357 
363  QDateTime getTimestamp() const;
364 
371  void writeToFile(QJsonObject& json, int parentId);
372 
379  bool readFromFile(const QJsonObject& json);
380 
386  void setDirty(bool dty);
387 
393  bool isDirty() const
394  {
395  return mDirty;
396  }
397 
401  void setSpecialUpdate(bool state);
402 
408  bool getSpecialUpdate() const
409  {
410  return mSpecialUpdate;
411  }
412 
418  {
419  mParentWidget = gw;
420  }
421 
428  {
429  return mExclusiveModuleId;
430  }
431 
435  void setExclusiveModuleId(u32 id, bool emitSignal = true);
436 
440  void exclusiveModuleCheck();
441 
446  void showComments(const Node& nd);
447 
451  void updateNets();
452 
456  void setScheduleRemove(const QSet<u32>& mods, const QSet<u32>& gats);
457 
461  bool isScheduledRemove(const Node& nd);
462 
463  Q_SIGNALS:
464  void dataChanged();
465  void exclusiveModuleLost(u32 old_id);
466 
467  public Q_SLOTS:
468  void abortLayout();
469 
470  private Q_SLOTS:
471  void handleLayouterFinished();
472  void handleStyleChanged(int istyle);
473  void handleExclusiveModuleLost(u32 old_id);
474  void handleModuleNameChanged(Module* m);
475 
476  private:
477  void evaluateChanges();
478  void update();
479  void applyChanges();
480  void requireSceneUpdate();
481  void startSceneUpdate();
482  bool testIfAffectedInternal(const u32 id, const u32* moduleId, const u32* gateId);
483  void removeModuleContents(const u32 moduleId);
484 
485  u32 mId;
486  QString mName;
487  GraphWidget* mParentWidget;
488 
489  bool mDirty;
490 
491  GraphLayouter* mLayouter;
492  GraphShader* mShader;
493 
494  QSet<u32> mModules;
495  QSet<u32> mGates;
496  QSet<u32> mNets;
497 
498  QSet<u32> mAddedModules;
499  QSet<u32> mAddedGates;
500 
501  QList<PlacementEntry> mPlacementList[4];
502 
503  QSet<u32> mRemovedModules;
504  QSet<u32> mRemovedGates;
505 
506  u32 mUserUpdateCount;
507 
508  bool mUnappliedChanges;
509  bool mSceneUpdateRequired;
510  bool mSceneUpdateInProgress;
511 
512  QDateTime mTimestamp;
513 
514  bool mSpecialUpdate;
515 
516  QSet<u32> mScheduleRemoveModules;
517  QSet<u32> mScheduleRemoveGates;
518 
519  u32 mExclusiveModuleId;
520  };
521 } // namespace hal
Logical container for modules, gates, and nets.
Definition: graph_context.h:55
bool isModuleUnfolded(const u32 moduleId) const
bool isGateUnfolded(u32 gateId) const
void remove(const QSet< u32 > &modules, const QSet< u32 > &gates)
void setSpecialUpdate(bool state)
void writeToFile(QJsonObject &json, int parentId)
u32 getExclusiveModuleId() const
void unfoldModule(const u32 id, const PlacementHint &plc)
void refreshModule(const u32 moduleId)
void showComments(const Node &nd)
GraphicsScene * scene()
bool readFromFile(const QJsonObject &json)
Node getNetSource(const Net *n) const
bool isShowingModuleExclusively()
bool isShowingFoldedTopModule() const
void setDirty(bool dty)
bool isShowingModule(const u32 id) const
void setExclusiveModuleId(u32 id, bool emitSignal=true)
void add(const QSet< u32 > &modules, const QSet< u32 > &gates, PlacementHint placement=PlacementHint())
bool empty() const
void updatePlacement(const GridPlacement &plc)
void layoutProgress(int percent) const
Node getNetDestination(const Net *n) const
const QSet< u32 > & gates() const
const QSet< u32 > & modules() const
bool getSpecialUpdate() const
void testIfAffected(const u32 id, const u32 *moduleId, const u32 *gateId)
void setParentWidget(GraphWidget *gw)
Node nodeForGate(const u32 id) const
void exclusiveModuleLost(u32 old_id)
void setScheduleRemove(const QSet< u32 > &mods, const QSet< u32 > &gats)
void setShader(GraphShader *shader)
bool isScheduledRemove(const Node &nd)
QDateTime getTimestamp() const
bool isDirty() const
GraphLayouter * getLayouter() const
GraphContext(u32 id_, const QString &name, QObject *parent=nullptr)
bool willBeEmptied() const
QString getNameWithDirtyState() const
void setLayouter(GraphLayouter *layouter)
QString name() const
const QSet< u32 > & nets() const
bool isShowingNetSource(const u32 mNetId) const
bool sceneUpdateInProgress() const
bool isShowingNetDestination(const u32 mNetId) const
void getModuleChildrenRecursively(const u32 moduleId, QSet< u32 > *gates, QSet< u32 > *modules) const
User interface to manage all GraphContexts.
Base class for all specific layouters.
Base class to store and update visual information about the graph.
Definition: graph_shader.h:47
Wraps a GraphContext and a GraphGraphicsView.
Definition: graph_widget.h:55
Container for a GraphGraphicsView containing gates, nets, and modules.
Definition: net.h:58
The Node class object represents a module or a gate.
Definition: gui_def.h:61
The PlacementHint class object provides hints for the layouter how new box objects are placed on a vi...
Definition: gui_def.h:211
n
Definition: test.py:6
quint32 u32
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const