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 
135  void unfoldModule(const u32 id, const PlacementHint& plc);
136 
142  bool empty() const;
143 
148  bool willBeEmptied() const;
149 
156  bool isShowingModule(const u32 id) const;
157 
175  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;
176 
181 
189  void getModuleChildrenRecursively(const u32 moduleId, QSet<u32>* gates, QSet<u32>* modules) const;
190 
194  void storeViewport();
195 
200  void layoutProgress(int percent) const;
201 
209  void testIfAffected(const u32 id, const u32* moduleId, const u32* gateId);
210 
217  bool isShowingNetSource(const u32 mNetId) const;
218 
225  bool isShowingNetDestination(const u32 mNetId) const;
226 
232  bool isShowingFoldedTopModule() const;
233 
240  Node getNetSource(const Net* n) const;
241 
248  Node getNetDestination(const Net* n) const;
249 
255  const QSet<u32>& modules() const;
256 
262  const QSet<u32>& gates() const;
263 
269  const QSet<u32>& nets() const;
270 
276  GraphicsScene* scene();
277 
283  QString name() const;
284 
291 
297  u32 id() const;
298 
304  void setLayouter(GraphLayouter* layouter);
305 
311  void setShader(GraphShader* shader);
312 
320  {
321  return mLayouter;
322  }
323 
327  void moveNodeAction(const QPoint& from, const QPoint& to);
328 
334  bool sceneUpdateInProgress() const;
335 
340  void scheduleSceneUpdate();
341 
352  Node nodeForGate(const u32 id) const;
353 
359  QDateTime getTimestamp() const;
360 
367  void writeToFile(QJsonObject& json, int parentId);
368 
375  bool readFromFile(const QJsonObject& json);
376 
382  void setDirty(bool dty);
383 
389  bool isDirty() const
390  {
391  return mDirty;
392  }
393 
397  void setSpecialUpdate(bool state);
398 
404  bool getSpecialUpdate() const
405  {
406  return mSpecialUpdate;
407  }
408 
414  {
415  mParentWidget = gw;
416  }
417 
424  {
425  return mExclusiveModuleId;
426  }
427 
431  void setExclusiveModuleId(u32 id, bool emitSignal = true);
432 
436  void exclusiveModuleCheck();
437 
442  void showComments(const Node& nd);
443 
447  void updateNets();
448 
452  void setScheduleRemove(const QSet<u32>& mods, const QSet<u32>& gats);
453 
457  bool isScheduledRemove(const Node& nd);
458 
459  Q_SIGNALS:
460  void dataChanged();
461  void exclusiveModuleLost(u32 old_id);
462 
463  public Q_SLOTS:
464  void abortLayout();
465 
466  private Q_SLOTS:
467  void handleLayouterFinished();
468  void handleStyleChanged(int istyle);
469  void handleExclusiveModuleLost(u32 old_id);
470  void handleModuleNameChanged(Module* m);
471 
472  private:
473  void evaluateChanges();
474  void update();
475  void applyChanges();
476  void requireSceneUpdate();
477  void startSceneUpdate();
478  bool testIfAffectedInternal(const u32 id, const u32* moduleId, const u32* gateId);
479  void removeModuleContents(const u32 moduleId);
480 
481  u32 mId;
482  QString mName;
483  GraphWidget* mParentWidget;
484 
485  bool mDirty;
486 
487  GraphLayouter* mLayouter;
488  GraphShader* mShader;
489 
490  QSet<u32> mModules;
491  QSet<u32> mGates;
492  QSet<u32> mNets;
493 
494  QSet<u32> mAddedModules;
495  QSet<u32> mAddedGates;
496 
497  QList<PlacementEntry> mPlacementList[4];
498 
499  QSet<u32> mRemovedModules;
500  QSet<u32> mRemovedGates;
501 
502  u32 mUserUpdateCount;
503 
504  bool mUnappliedChanges;
505  bool mSceneUpdateRequired;
506  bool mSceneUpdateInProgress;
507 
508  QDateTime mTimestamp;
509 
510  bool mSpecialUpdate;
511 
512  QSet<u32> mScheduleRemoveModules;
513  QSet<u32> mScheduleRemoveGates;
514 
515  u32 mExclusiveModuleId;
516  };
517 } // namespace hal
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
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 showComments(const Node &nd)
GraphicsScene * scene()
bool readFromFile(const QJsonObject &json)
Node getNetSource(const Net *n) const
bool isShowingModuleExclusively()
void moveNodeAction(const QPoint &from, const QPoint &to)
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 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:196
S to(const T &str)
n
Definition: test.py:6
quint32 u32
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const