OpenMS
TOPPASVertex.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Johannes Veit $
6 // $Authors: Johannes Junker, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 // ------------- DEBUGGING ----------------
12 
13 // ---- Uncomment to enable debug mode ----
14 //#define TOPPAS_DEBUG
15 // ----------------------------------------
16 
17 #ifdef TOPPAS_DEBUG
18 #define __DEBUG_BEGIN_METHOD__ \
19  { \
20  for (int dbg_indnt_cntr = 0; dbg_indnt_cntr < global_debug_indent_; ++dbg_indnt_cntr) \
21  { \
22  std::cout << " "; \
23  } \
24  std::cout << "BEGIN [" << topo_nr_ << "] " << OPENMS_PRETTY_FUNCTION << std::endl; \
25  ++global_debug_indent_; \
26  }
27 
28 #define __DEBUG_END_METHOD__ \
29  { \
30  --global_debug_indent_; \
31  if (global_debug_indent_ < 0) global_debug_indent_ = 0; \
32  for (int dbg_indnt_cntr = 0; dbg_indnt_cntr < global_debug_indent_; ++dbg_indnt_cntr) \
33  { \
34  std::cout << " "; \
35  } \
36  std::cout << "END [" << topo_nr_ << "] " << OPENMS_PRETTY_FUNCTION << std::endl; \
37  }
38 #else
39 #define __DEBUG_BEGIN_METHOD__ {}
40 #define __DEBUG_END_METHOD__ {}
41 #endif
42 
43 // ----------------------------------------
44 
45 // OpenMS_GUI config
46 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
47 
49 
50 #include <QPainter>
51 #include <QPainterPath>
52 #include <QtWidgets/QGraphicsSceneMouseEvent>
53 #include <QtWidgets/QGraphicsSceneContextMenuEvent>
54 #include <QtWidgets/QGraphicsItem>
55 #include <QtCore/QProcess>
56 #include <QtWidgets/QMenu>
57 #include <QStringList>
58 
59 namespace OpenMS
60 {
61  class TOPPASEdge;
62 
74  class OPENMS_GUI_DLLAPI TOPPASVertex :
75  public QObject,
76  public QGraphicsItem
77  {
78  Q_OBJECT
79  Q_INTERFACES(QGraphicsItem)
80 
81 public:
83  typedef QList<TOPPASEdge *> EdgeContainer;
85  typedef EdgeContainer::iterator EdgeIterator;
87  typedef EdgeContainer::const_iterator ConstEdgeIterator;
88 
93  {
94  public:
95  TOPPASFilenames() = default;
96  TOPPASFilenames(const QStringList& filenames);
97  int size() const;
98  const QStringList& get() const;
99  const QString& operator[](int i) const;
100 
102 
103  void set(const QStringList& filenames);
104  void set(const QString& filename, int i);
105  void push_back(const QString& filename);
106  void append(const QStringList& filenames);
108 
109  QStringList getSuffixCounts() const;
110 
111  private:
112  /*
113  @brief Check length of filename and throw Exception::FileNotWritable() if too long
114 
115  @param filename Full path to file (using relative paths will circumvent the effectiveness)
116  @throw Exception::FileNotWritable() if too long (>=255 chars)
117  */
118  void check_(const QString& filename);
119  QStringList filenames_;
120  };
121 
124  {
126  TOPPASEdge* edge = nullptr;
127  };
128 
133  typedef std::map<Int, VertexRoundPackage> RoundPackage;
134  typedef RoundPackage::const_iterator RoundPackageConstIt;
135  typedef RoundPackage::iterator RoundPackageIt;
136 
138  typedef std::vector<RoundPackage> RoundPackages;
139 
142  {
145  DFS_BLACK
146  };
147 
150  {
153  TV_UNFINISHED_INBRANCH
154  };
155 
161  ~TOPPASVertex() override = default;
165  void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/, bool round_shape = true);
166 
170  bool buildRoundPackages(RoundPackages & pkg, String & error_msg);
171 
173  bool isUpstreamFinished() const;
174 
176  QRectF boundingRect() const override = 0;
178  QPainterPath shape() const final;
180  ConstEdgeIterator outEdgesBegin() const;
182  ConstEdgeIterator outEdgesEnd() const;
184  ConstEdgeIterator inEdgesBegin() const;
186  ConstEdgeIterator inEdgesEnd() const;
188  Size incomingEdgesCount();
190  Size outgoingEdgesCount();
192  void addInEdge(TOPPASEdge * edge);
194  void addOutEdge(TOPPASEdge * edge);
196  void removeInEdge(TOPPASEdge * edge);
198  void removeOutEdge(TOPPASEdge * edge);
200  DFS_COLOR getDFSColor();
202  void setDFSColor(DFS_COLOR color);
204  TOPPASVertex::SUBSTREESTATUS getSubtreeStatus() const;
206  bool isTopoSortMarked() const;
208  void setTopoSortMarked(bool b);
210  UInt getTopoNr() const;
212  virtual void setTopoNr(UInt nr);
215  virtual void reset(bool reset_all_files = false);
217  virtual void markUnreachable();
219  bool isReachable() const;
221  bool isFinished() const;
224  virtual void run();
226  virtual bool invertRecylingMode();
228  bool isRecyclingEnabled() const;
230  void setRecycling(const bool is_enabled);
231 
232  // get the name of the vertex (to be overridden by derived classes)
233  virtual String getName() const = 0;
234 
240  QStringList getFileNames(int param_index, int round) const;
241 
243  QStringList getFileNames() const;
244 
245  // get the output structure directly
246  const RoundPackages & getOutputFiles() const;
247 
248 
250  bool allInputsReady() const;
251 
252 
253 public slots:
254 
256  virtual void inEdgeHasChanged();
258  virtual void outEdgeHasChanged();
259 
260 signals:
261 
263  void clicked();
265  void released();
267  void hoveringEdgePosChanged(const QPointF & new_pos);
269  void newHoveringEdge(const QPointF & pos);
271  void finishHoveringEdge();
273  void somethingHasChanged();
275  void itemDragged(qreal dx, qreal dy);
278  void parameterChanged(const bool invalidates_running_pipeline);
279 
280 protected:
281 
283  EdgeContainer in_edges_;
285  EdgeContainer out_edges_;
287  bool edge_being_created_{false};
289  QColor pen_color_{Qt::black};
291  QColor brush_color_{ Qt::lightGray};
293  DFS_COLOR dfs_color_{DFS_WHITE};
295  bool topo_sort_marked_{false};
301  int round_total_{-1};
303  int round_counter_{0};
305  bool finished_{false};
307  bool reachable_{true};
309  bool allow_output_recycling_{false};
310 
311 
312 #ifdef TOPPAS_DEBUG
313  // Indentation level for nicer debug output
314  static int global_debug_indent_;
315 #endif
316 
318 
319  void mouseReleaseEvent(QGraphicsSceneMouseEvent * e) override;
320  void mousePressEvent(QGraphicsSceneMouseEvent * e) override;
321  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * e) override;
322  void mouseMoveEvent(QGraphicsSceneMouseEvent * e) override;
323  void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
325 
327  virtual void moveNewEdgeTo_(const QPointF & pos);
330 
332  void debugOut_(const String &
333 #ifdef TOPPAS_DEBUG
334  message
335 #endif
336  ) const
337  {
338 #ifdef TOPPAS_DEBUG
339  for (int i = 0; i < global_debug_indent_; ++i)
340  {
341  std::cout << " ";
342  }
343  std::cout << "[" << topo_nr_ << "] " << message << std::endl;
344 #endif
345  }
346 
347  };
348 }
349 
A more convenient string class.
Definition: String.h:34
An edge representing a data flow in TOPPAS.
Definition: TOPPASEdge.h:36
Definition: TOPPASVertex.h:93
TOPPASFilenames(const QStringList &filenames)
void append(const QStringList &filenames)
void push_back(const QString &filename)
const QString & operator[](int i) const
void set(const QStringList &filenames)
const QStringList & get() const
void set(const QString &filename, int i)
QStringList filenames_
filenames passed from upstream node in this round
Definition: TOPPASVertex.h:119
void check_(const QString &filename)
The base class of the different vertex classes.
Definition: TOPPASVertex.h:77
TOPPASVertex()
Default Constructor.
QPainterPath shape() const final
Returns a more precise shape.
TOPPASVertex(const TOPPASVertex &rhs)
Copy constructor.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
RoundPackages output_files_
Stores the current output file names for each output parameter.
Definition: TOPPASVertex.h:299
bool isUpstreamFinished() const
check if all upstream nodes are ready to go ( 'finished_' is true)
std::map< Int, VertexRoundPackage > RoundPackage
Definition: TOPPASVertex.h:133
~TOPPASVertex() override=default
Destructor.
TOPPASVertex & operator=(const TOPPASVertex &rhs)
Assignment operator.
std::vector< RoundPackage > RoundPackages
all information a node needs to process all rounds
Definition: TOPPASVertex.h:138
bool buildRoundPackages(RoundPackages &pkg, String &error_msg)
SUBSTREESTATUS
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:150
@ TV_ALLFINISHED
all downstream nodes are done (including the ones which are feed by a parallel subtree)
Definition: TOPPASVertex.h:151
@ TV_UNFINISHED
some direct downstream node is not done
Definition: TOPPASVertex.h:152
QList< TOPPASEdge * > EdgeContainer
The container for in/out edges.
Definition: TOPPASVertex.h:83
EdgeContainer::const_iterator ConstEdgeIterator
A const iterator for in/out edges.
Definition: TOPPASVertex.h:87
String get3CharsNumber_(UInt number) const
Returns a three character string (i.e. 001 instead of 1) for the given number.
RoundPackage::iterator RoundPackageIt
Definition: TOPPASVertex.h:135
TOPPASFilenames filenames
filenames passed from upstream node in this round
Definition: TOPPASVertex.h:125
QRectF boundingRect() const override=0
Returns the bounding rectangle of this item.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) override
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *, bool round_shape=true)
base paint method for all derived classes. should be called first in child-class paint
void debugOut_(const String &) const
Displays the debug output message, if TOPPAS_DEBUG is defined.
Definition: TOPPASVertex.h:332
DFS_COLOR
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:142
@ DFS_GRAY
Definition: TOPPASVertex.h:144
@ DFS_WHITE
Definition: TOPPASVertex.h:143
EdgeContainer::iterator EdgeIterator
A mutable iterator for in/out edges.
Definition: TOPPASVertex.h:85
UInt topo_nr_
The number in a topological sort of the entire graph.
Definition: TOPPASVertex.h:297
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override
RoundPackage::const_iterator RoundPackageConstIt
Definition: TOPPASVertex.h:134
void mousePressEvent(QGraphicsSceneMouseEvent *e) override
virtual void moveNewEdgeTo_(const QPointF &pos)
Moves the target pos of the edge which is just being created to pos.
Info for one edge and round, to be passed to next node.
Definition: TOPPASVertex.h:124
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
T round(T x)
Rounds the value.
Definition: MathFunctions.h:184
static String number(double d, UInt n)
Definition: StringUtils.h:191
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22