OpenMS  2.4.0
TOPPASVertex.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2018.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Johannes Veit $
32 // $Authors: Johannes Junker, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // ------------- DEBUGGING ----------------
38 
39 // ---- Uncomment to enable debug mode ----
40 //#define TOPPAS_DEBUG
41 // ----------------------------------------
42 
43 #ifdef TOPPAS_DEBUG
44 #define __DEBUG_BEGIN_METHOD__ \
45  { \
46  for (int dbg_indnt_cntr = 0; dbg_indnt_cntr < global_debug_indent_; ++dbg_indnt_cntr) \
47  { \
48  std::cout << " "; \
49  } \
50  std::cout << "BEGIN [" << topo_nr_ << "] " << OPENMS_PRETTY_FUNCTION << std::endl; \
51  ++global_debug_indent_; \
52  }
53 
54 #define __DEBUG_END_METHOD__ \
55  { \
56  --global_debug_indent_; \
57  if (global_debug_indent_ < 0) global_debug_indent_ = 0; \
58  for (int dbg_indnt_cntr = 0; dbg_indnt_cntr < global_debug_indent_; ++dbg_indnt_cntr) \
59  { \
60  std::cout << " "; \
61  } \
62  std::cout << "END [" << topo_nr_ << "] " << OPENMS_PRETTY_FUNCTION << std::endl; \
63  }
64 #else
65 #define __DEBUG_BEGIN_METHOD__ {}
66 #define __DEBUG_END_METHOD__ {}
67 #endif
68 
69 // ----------------------------------------
70 
71 // OpenMS_GUI config
72 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
73 
76 
77 #include <QPainter>
78 #include <QPainterPath>
79 #include <QtWidgets/QGraphicsSceneMouseEvent>
80 #include <QtWidgets/QGraphicsSceneContextMenuEvent>
81 #include <QtWidgets/QGraphicsItem>
82 #include <QtCore/QProcess>
83 #include <QtWidgets/QMenu>
84 
85 namespace OpenMS
86 {
87  class TOPPASEdge;
88 
100  class OPENMS_GUI_DLLAPI TOPPASVertex :
101  public QObject,
102  public QGraphicsItem
103  {
104  Q_OBJECT
105  Q_INTERFACES(QGraphicsItem)
106 
107 public:
108 
110  typedef QList<TOPPASEdge *> EdgeContainer;
112  typedef EdgeContainer::iterator EdgeIterator;
114  typedef EdgeContainer::const_iterator ConstEdgeIterator;
119  {
120  public:
122  {
123  }
124 
125  int size() const;
126  const QStringList& get() const;
127  const QString& operator[](int i) const;
128 
130 
131  void set(const QStringList& filenames);
132  void set(const QString& filename, int i);
133  void push_back(const QString& filename);
134  void append(const QStringList& filenames);
136 
137  private:
138  /*
139  @brief Check length of filename and throw Exception::FileNotWritable() if too long
140 
141  @param filename Full path to file (using relative paths will circumvent the effectiveness)
142  @throw Exception::FileNotWritable() if too long (>=255 chars)
143  */
144  void check_(const QString& filename);
145  QStringList filenames_;
146  };
149  {
151  filenames(),
152  edge(nullptr)
153  {
154  }
155 
158  };
159 
160 
161 
162 
167  typedef std::map<Int, VertexRoundPackage> RoundPackage;
168  typedef RoundPackage::const_iterator RoundPackageConstIt;
169  typedef RoundPackage::iterator RoundPackageIt;
170 
172  typedef std::vector<RoundPackage> RoundPackages;
173 
176  {
179  DFS_BLACK
180  };
181 
184  {
185  TV_ALLFINISHED, // all downstream nodes are done (including the ones which are feed by a parallel subtree)
186  TV_UNFINISHED, // some direct downstream node is not done
187  TV_UNFINISHED_INBRANCH // a parallel subtree which merged with some downstream node A was not done (which prevented processing of the node A)
188  };
189 
191  TOPPASVertex();
193  TOPPASVertex(const TOPPASVertex & rhs);
195  ~TOPPASVertex() override;
197  TOPPASVertex & operator=(const TOPPASVertex & rhs);
198 
202  bool buildRoundPackages(RoundPackages & pkg, String & error_msg);
203 
205  bool isUpstreamFinished() const;
206 
208  QRectF boundingRect() const override = 0;
210  QPainterPath shape() const override = 0;
212  void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) override = 0;
214  ConstEdgeIterator outEdgesBegin() const;
216  ConstEdgeIterator outEdgesEnd() const;
218  ConstEdgeIterator inEdgesBegin() const;
220  ConstEdgeIterator inEdgesEnd() const;
222  Size incomingEdgesCount();
224  Size outgoingEdgesCount();
226  void addInEdge(TOPPASEdge * edge);
228  void addOutEdge(TOPPASEdge * edge);
230  void removeInEdge(TOPPASEdge * edge);
232  void removeOutEdge(TOPPASEdge * edge);
234  DFS_COLOR getDFSColor();
236  void setDFSColor(DFS_COLOR color);
238  TOPPASVertex * getDFSParent();
240  void setDFSParent(TOPPASVertex * parent);
242  TOPPASVertex::SUBSTREESTATUS getSubtreeStatus() const;
244  bool isTopoSortMarked();
246  void setTopoSortMarked(bool b);
248  UInt getTopoNr();
250  virtual void setTopoNr(UInt nr);
253  virtual void reset(bool reset_all_files = false);
255  virtual void markUnreachable();
257  bool isReachable();
259  bool isFinished() const;
262  virtual void run();
264  virtual bool invertRecylingMode();
266  bool isRecyclingEnabled() const;
268  void setRecycling(const bool is_enabled);
269 
270  // get the name of the vertex (to be overridden by derived classes)
271  virtual String getName() const = 0;
272 
278  QStringList getFileNames(int param_index, int round) const;
279 
281  QStringList getFileNames() const;
282 
283  // get the output structure directly
284  const RoundPackages & getOutputFiles() const;
285 
286 
288  bool allInputsReady();
289 
290 
291 public slots:
292 
294  virtual void inEdgeHasChanged();
296  virtual void outEdgeHasChanged();
297 
298 signals:
299 
301  void clicked();
303  void released();
305  void hoveringEdgePosChanged(const QPointF & new_pos);
307  void newHoveringEdge(const QPointF & pos);
309  void finishHoveringEdge();
311  void somethingHasChanged();
313  void itemDragged(qreal dx, qreal dy);
316  void parameterChanged(const bool invalidates_running_pipeline);
317 
318 protected:
319 
327  QColor pen_color_;
329  QColor brush_color_;
345  bool finished_;
350 
351 
352 #ifdef TOPPAS_DEBUG
353  // Indentation level for nicer debug output
354  static int global_debug_indent_;
355 #endif
356 
358 
359  void mouseReleaseEvent(QGraphicsSceneMouseEvent * e) override;
360  void mousePressEvent(QGraphicsSceneMouseEvent * e) override;
361  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * e) override;
362  void mouseMoveEvent(QGraphicsSceneMouseEvent * e) override;
363  void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
365 
367  virtual void moveNewEdgeTo_(const QPointF & pos);
369  String get3CharsNumber_(UInt number) const;
370 
372  void debugOut_(const String &
373 #ifdef TOPPAS_DEBUG
374  message
375 #endif
376  ) const
377  {
378 #ifdef TOPPAS_DEBUG
379  for (int i = 0; i < global_debug_indent_; ++i)
380  {
381  std::cout << " ";
382  }
383  std::cout << "[" << topo_nr_ << "] " << message << std::endl;
384 #endif
385  }
386 
387  };
388 }
389 
TOPPASEdge * edge
edge that connects the upstream node to the current one
Definition: TOPPASVertex.h:157
Definition: TOPPASVertex.h:118
TOPPASFilenames filenames
filenames passed from upstream node in this round
Definition: TOPPASVertex.h:156
bool edge_being_created_
Indicates whether a new out edge is currently being created.
Definition: TOPPASVertex.h:325
QColor pen_color_
The color of the pen.
Definition: TOPPASVertex.h:327
DFS_COLOR
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:175
RoundPackage::iterator RoundPackageIt
Definition: TOPPASVertex.h:169
A more convenient string class.
Definition: String.h:57
RoundPackage::const_iterator RoundPackageConstIt
Definition: TOPPASVertex.h:168
bool finished_
Stores whether this node has already been processed during the current pipeline execution.
Definition: TOPPASVertex.h:345
Definition: TOPPASVertex.h:186
void debugOut_(const String &) const
Displays the debug output message, if TOPPAS_DEBUG is defined.
Definition: TOPPASVertex.h:372
The base class of the different vertex classes.
Definition: TOPPASVertex.h:100
std::map< Int, VertexRoundPackage > RoundPackage
Definition: TOPPASVertex.h:167
Info for one edge and round, to be passed to next node.
Definition: TOPPASVertex.h:148
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
bool allow_output_recycling_
shall subsequent tools be allowed to recycle the output of this node to match the number of rounds im...
Definition: TOPPASVertex.h:349
TOPPASVertex * dfs_parent_
The DFS parent of this node.
Definition: TOPPASVertex.h:333
DFS_COLOR dfs_color_
The DFS color of this node.
Definition: TOPPASVertex.h:331
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
An edge representing a data flow in TOPPAS.
Definition: TOPPASEdge.h:59
SUBSTREESTATUS
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:183
T round(T x)
Rounds the value.
Definition: MathFunctions.h:138
EdgeContainer::iterator EdgeIterator
A mutable iterator for in/out edges.
Definition: TOPPASVertex.h:112
EdgeContainer out_edges_
The list of outgoing edges.
Definition: TOPPASVertex.h:323
int round_total_
number of rounds this node will do (&#39;Merge All&#39; nodes will pass everything, thus do only one round) ...
Definition: TOPPASVertex.h:341
Definition: TOPPASVertex.h:177
Definition: TOPPASVertex.h:185
bool reachable_
Indicates whether this node is reachable (i.e. there is an input node somewhere further upstream) ...
Definition: TOPPASVertex.h:347
std::vector< RoundPackage > RoundPackages
all information a node needs to process all rounds
Definition: TOPPASVertex.h:172
QStringList filenames_
filenames passed from upstream node in this round
Definition: TOPPASVertex.h:145
EdgeContainer in_edges_
The list of incoming edges.
Definition: TOPPASVertex.h:321
RoundPackages output_files_
Stores the current output file names for each output parameter.
Definition: TOPPASVertex.h:339
TOPPASFilenames()
Definition: TOPPASVertex.h:121
QList< TOPPASEdge * > EdgeContainer
The container for in/out edges.
Definition: TOPPASVertex.h:110
Definition: TOPPASVertex.h:178
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
VertexRoundPackage()
Definition: TOPPASVertex.h:150
QColor brush_color_
The color of the brush.
Definition: TOPPASVertex.h:329
EdgeContainer::const_iterator ConstEdgeIterator
A const iterator for in/out edges.
Definition: TOPPASVertex.h:114
bool topo_sort_marked_
"marked" flag for topological sort
Definition: TOPPASVertex.h:335
UInt topo_nr_
The number in a topological sort of the entire graph.
Definition: TOPPASVertex.h:337
int round_counter_
currently finished number of rounds (TODO: do we need that?)
Definition: TOPPASVertex.h:343