OpenMS
TOPPASVertex.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, 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 <QtWidgets/QMenu>
56 
57 #include <QtCore/QProcess>
58 #include <QtCore/QStringList>
59 
60 namespace OpenMS
61 {
62  class TOPPASEdge;
63 
75  class OPENMS_GUI_DLLAPI TOPPASVertex :
76  public QObject,
77  public QGraphicsItem
78  {
79  Q_OBJECT
80  Q_INTERFACES(QGraphicsItem)
81 
82 public:
84  typedef QList<TOPPASEdge *> EdgeContainer;
86  typedef EdgeContainer::iterator EdgeIterator;
88  typedef EdgeContainer::const_iterator ConstEdgeIterator;
89 
94  {
95  public:
96  TOPPASFilenames() = default;
97  TOPPASFilenames(const QStringList& filenames);
98  int size() const;
99  const QStringList& get() const;
100  const QString& operator[](int i) const;
101 
103 
104  void set(const QStringList& filenames);
105  void set(const QString& filename, int i);
106  void push_back(const QString& filename);
107  void append(const QStringList& filenames);
109 
110  QStringList getSuffixCounts() const;
111 
112  private:
113  /*
114  @brief Check length of filename and throw Exception::FileNotWritable() if too long
115 
116  @param filename Full path to file (using relative paths will circumvent the effectiveness)
117  @throw Exception::FileNotWritable() if too long (>=255 chars)
118  */
119  void check_(const QString& filename);
120  QStringList filenames_;
121  };
122 
125  {
127  TOPPASEdge* edge = nullptr;
128  };
129 
134  typedef std::map<Int, VertexRoundPackage> RoundPackage;
135  typedef RoundPackage::const_iterator RoundPackageConstIt;
136  typedef RoundPackage::iterator RoundPackageIt;
137 
139  typedef std::vector<RoundPackage> RoundPackages;
140 
143  {
146  DFS_BLACK
147  };
148 
151  {
154  TV_UNFINISHED_INBRANCH
155  };
156 
162  ~TOPPASVertex() override = default;
166  void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/, bool round_shape = true);
167 
171  bool buildRoundPackages(RoundPackages & pkg, String & error_msg);
172 
174  bool isUpstreamFinished() const;
175 
177  QRectF boundingRect() const override = 0;
179  QPainterPath shape() const final;
181  ConstEdgeIterator outEdgesBegin() const;
183  ConstEdgeIterator outEdgesEnd() const;
185  ConstEdgeIterator inEdgesBegin() const;
187  ConstEdgeIterator inEdgesEnd() const;
189  Size incomingEdgesCount();
191  Size outgoingEdgesCount();
193  void addInEdge(TOPPASEdge * edge);
195  void addOutEdge(TOPPASEdge * edge);
197  void removeInEdge(TOPPASEdge * edge);
199  void removeOutEdge(TOPPASEdge * edge);
201  DFS_COLOR getDFSColor();
203  void setDFSColor(DFS_COLOR color);
205  TOPPASVertex::SUBSTREESTATUS getSubtreeStatus() const;
207  bool isTopoSortMarked() const;
209  void setTopoSortMarked(bool b);
211  UInt getTopoNr() const;
213  virtual void setTopoNr(UInt nr);
216  virtual void reset(bool reset_all_files = false);
218  virtual void markUnreachable();
220  bool isReachable() const;
222  bool isFinished() const;
225  virtual void run();
227  virtual bool invertRecylingMode();
229  bool isRecyclingEnabled() const;
231  void setRecycling(const bool is_enabled);
232 
233  // get the name of the vertex (to be overridden by derived classes)
234  virtual String getName() const = 0;
235 
241  QStringList getFileNames(int param_index, int round) const;
242 
244  QStringList getFileNames() const;
245 
246  // get the output structure directly
247  const RoundPackages & getOutputFiles() const;
248 
249 
251  bool allInputsReady() const;
252 
253 
254 public slots:
255 
257  virtual void inEdgeHasChanged();
259  virtual void outEdgeHasChanged();
260 
261 signals:
262 
264  void clicked();
266  void released();
268  void hoveringEdgePosChanged(const QPointF & new_pos);
270  void newHoveringEdge(const QPointF & pos);
272  void finishHoveringEdge();
274  void somethingHasChanged();
276  void itemDragged(qreal dx, qreal dy);
279  void parameterChanged(const bool invalidates_running_pipeline);
280 
281 protected:
282 
284  EdgeContainer in_edges_;
286  EdgeContainer out_edges_;
288  bool edge_being_created_{false};
290  QColor pen_color_{Qt::black};
292  QColor brush_color_{ Qt::lightGray};
294  DFS_COLOR dfs_color_{DFS_WHITE};
296  bool topo_sort_marked_{false};
302  int round_total_{-1};
304  int round_counter_{0};
306  bool finished_{false};
308  bool reachable_{true};
310  bool allow_output_recycling_{false};
311 
312 
313 #ifdef TOPPAS_DEBUG
314  // Indentation level for nicer debug output
315  static int global_debug_indent_;
316 #endif
317 
319 
320  void mouseReleaseEvent(QGraphicsSceneMouseEvent * e) override;
321  void mousePressEvent(QGraphicsSceneMouseEvent * e) override;
322  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * e) override;
323  void mouseMoveEvent(QGraphicsSceneMouseEvent * e) override;
324  void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
326 
328  virtual void moveNewEdgeTo_(const QPointF & pos);
331 
333  void debugOut_(const String &
334 #ifdef TOPPAS_DEBUG
335  message
336 #endif
337  ) const
338  {
339 #ifdef TOPPAS_DEBUG
340  for (int i = 0; i < global_debug_indent_; ++i)
341  {
342  std::cout << " ";
343  }
344  std::cout << "[" << topo_nr_ << "] " << message << std::endl;
345 #endif
346  }
347 
348  };
349 }
350 
A more convenient string class.
Definition: String.h:34
An edge representing a data flow in TOPPAS.
Definition: TOPPASEdge.h:36
Definition: TOPPASVertex.h:94
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:120
void check_(const QString &filename)
The base class of the different vertex classes.
Definition: TOPPASVertex.h:78
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:300
bool isUpstreamFinished() const
check if all upstream nodes are ready to go ( 'finished_' is true)
std::map< Int, VertexRoundPackage > RoundPackage
Definition: TOPPASVertex.h:134
~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:139
bool buildRoundPackages(RoundPackages &pkg, String &error_msg)
SUBSTREESTATUS
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:151
@ TV_ALLFINISHED
all downstream nodes are done (including the ones which are feed by a parallel subtree)
Definition: TOPPASVertex.h:152
@ TV_UNFINISHED
some direct downstream node is not done
Definition: TOPPASVertex.h:153
QList< TOPPASEdge * > EdgeContainer
The container for in/out edges.
Definition: TOPPASVertex.h:84
EdgeContainer::const_iterator ConstEdgeIterator
A const iterator for in/out edges.
Definition: TOPPASVertex.h:88
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:136
TOPPASFilenames filenames
filenames passed from upstream node in this round
Definition: TOPPASVertex.h:126
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:333
DFS_COLOR
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:143
@ DFS_GRAY
Definition: TOPPASVertex.h:145
@ DFS_WHITE
Definition: TOPPASVertex.h:144
EdgeContainer::iterator EdgeIterator
A mutable iterator for in/out edges.
Definition: TOPPASVertex.h:86
UInt topo_nr_
The number in a topological sort of the entire graph.
Definition: TOPPASVertex.h:298
void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override
void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override
RoundPackage::const_iterator RoundPackageConstIt
Definition: TOPPASVertex.h:135
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:125
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
T round(T x)
Rounds the value.
Definition: MathFunctions.h:218
static String number(double d, UInt n)
Definition: StringUtils.h:191
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19