OpenMS  2.6.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-2020.
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 #include <QStringList>
85 
86 namespace OpenMS
87 {
88  class TOPPASEdge;
89 
101  class OPENMS_GUI_DLLAPI TOPPASVertex :
102  public QObject,
103  public QGraphicsItem
104  {
105  Q_OBJECT
106  Q_INTERFACES(QGraphicsItem)
107 
108 public:
110  typedef QList<TOPPASEdge *> EdgeContainer;
112  typedef EdgeContainer::iterator EdgeIterator;
114  typedef EdgeContainer::const_iterator ConstEdgeIterator;
115 
120  {
121  public:
122  TOPPASFilenames() = default;
123  TOPPASFilenames(const QStringList& filenames);
124  int size() const;
125  const QStringList& get() const;
126  const QString& operator[](int i) const;
127 
129 
130  void set(const QStringList& filenames);
131  void set(const QString& filename, int i);
132  void push_back(const QString& filename);
133  void append(const QStringList& filenames);
135 
136  QStringList getSuffixCounts() const;
137 
138  private:
139  /*
140  @brief Check length of filename and throw Exception::FileNotWritable() if too long
141 
142  @param filename Full path to file (using relative paths will circumvent the effectiveness)
143  @throw Exception::FileNotWritable() if too long (>=255 chars)
144  */
145  void check_(const QString& filename);
146  QStringList filenames_;
147  };
148 
151  {
153  TOPPASEdge* edge = nullptr;
154  };
155 
160  typedef std::map<Int, VertexRoundPackage> RoundPackage;
161  typedef RoundPackage::const_iterator RoundPackageConstIt;
162  typedef RoundPackage::iterator RoundPackageIt;
163 
165  typedef std::vector<RoundPackage> RoundPackages;
166 
169  {
172  DFS_BLACK
173  };
174 
177  {
180  TV_UNFINISHED_INBRANCH
181  };
182 
184  TOPPASVertex();
186  TOPPASVertex(const TOPPASVertex & rhs);
188  ~TOPPASVertex() override = default;
190  TOPPASVertex& operator=(const TOPPASVertex & rhs);
192  void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/, bool round_shape = true);
193 
197  bool buildRoundPackages(RoundPackages & pkg, String & error_msg);
198 
200  bool isUpstreamFinished() const;
201 
203  QRectF boundingRect() const override = 0;
205  QPainterPath shape() const final;
207  ConstEdgeIterator outEdgesBegin() const;
209  ConstEdgeIterator outEdgesEnd() const;
211  ConstEdgeIterator inEdgesBegin() const;
213  ConstEdgeIterator inEdgesEnd() const;
215  Size incomingEdgesCount();
217  Size outgoingEdgesCount();
219  void addInEdge(TOPPASEdge * edge);
221  void addOutEdge(TOPPASEdge * edge);
223  void removeInEdge(TOPPASEdge * edge);
225  void removeOutEdge(TOPPASEdge * edge);
227  DFS_COLOR getDFSColor();
229  void setDFSColor(DFS_COLOR color);
231  TOPPASVertex::SUBSTREESTATUS getSubtreeStatus() const;
233  bool isTopoSortMarked();
235  void setTopoSortMarked(bool b);
237  UInt getTopoNr();
239  virtual void setTopoNr(UInt nr);
242  virtual void reset(bool reset_all_files = false);
244  virtual void markUnreachable();
246  bool isReachable();
248  bool isFinished() const;
251  virtual void run();
253  virtual bool invertRecylingMode();
255  bool isRecyclingEnabled() const;
257  void setRecycling(const bool is_enabled);
258 
259  // get the name of the vertex (to be overridden by derived classes)
260  virtual String getName() const = 0;
261 
267  QStringList getFileNames(int param_index, int round) const;
268 
270  QStringList getFileNames() const;
271 
272  // get the output structure directly
273  const RoundPackages & getOutputFiles() const;
274 
275 
277  bool allInputsReady();
278 
279 
280 public slots:
281 
283  virtual void inEdgeHasChanged();
285  virtual void outEdgeHasChanged();
286 
287 signals:
288 
290  void clicked();
292  void released();
294  void hoveringEdgePosChanged(const QPointF & new_pos);
296  void newHoveringEdge(const QPointF & pos);
298  void finishHoveringEdge();
300  void somethingHasChanged();
302  void itemDragged(qreal dx, qreal dy);
305  void parameterChanged(const bool invalidates_running_pipeline);
306 
307 protected:
308 
310  EdgeContainer in_edges_;
312  EdgeContainer out_edges_;
314  bool edge_being_created_{false};
316  QColor pen_color_{Qt::black};
318  QColor brush_color_{ Qt::lightGray};
320  DFS_COLOR dfs_color_{DFS_WHITE};
322  bool topo_sort_marked_{false};
328  int round_total_{-1};
330  int round_counter_{0};
332  bool finished_{false};
334  bool reachable_{true};
336  bool allow_output_recycling_{false};
337 
338 
339 #ifdef TOPPAS_DEBUG
340  // Indentation level for nicer debug output
341  static int global_debug_indent_;
342 #endif
343 
345 
346  void mouseReleaseEvent(QGraphicsSceneMouseEvent * e) override;
347  void mousePressEvent(QGraphicsSceneMouseEvent * e) override;
348  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * e) override;
349  void mouseMoveEvent(QGraphicsSceneMouseEvent * e) override;
350  void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
352 
354  virtual void moveNewEdgeTo_(const QPointF & pos);
356  String get3CharsNumber_(UInt number) const;
357 
359  void debugOut_(const String &
360 #ifdef TOPPAS_DEBUG
361  message
362 #endif
363  ) const
364  {
365 #ifdef TOPPAS_DEBUG
366  for (int i = 0; i < global_debug_indent_; ++i)
367  {
368  std::cout << " ";
369  }
370  std::cout << "[" << topo_nr_ << "] " << message << std::endl;
371 #endif
372  }
373 
374  };
375 }
376 
QObject
OpenMS::TOPPASVertex::output_files_
RoundPackages output_files_
Stores the current output file names for each output parameter.
Definition: TOPPASVertex.h:326
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::TOPPASVertex::TV_UNFINISHED
some direct downstream node is not done
Definition: TOPPASVertex.h:179
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::TOPPASVertex::TOPPASFilenames::filenames_
QStringList filenames_
filenames passed from upstream node in this round
Definition: TOPPASVertex.h:146
OpenMS::TOPPASVertex::TV_ALLFINISHED
all downstream nodes are done (including the ones which are feed by a parallel subtree)
Definition: TOPPASVertex.h:178
OpenMS::TOPPASVertex::EdgeContainer
QList< TOPPASEdge * > EdgeContainer
The container for in/out edges.
Definition: TOPPASVertex.h:110
Map.h
QWidget
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::TOPPASVertex::VertexRoundPackage
Info for one edge and round, to be passed to next node.
Definition: TOPPASVertex.h:150
OpenMS::TOPPASVertex::ConstEdgeIterator
EdgeContainer::const_iterator ConstEdgeIterator
A const iterator for in/out edges.
Definition: TOPPASVertex.h:114
OpenMS::TOPPASVertex::DFS_WHITE
Definition: TOPPASVertex.h:170
OpenMS::TOPPASVertex::RoundPackageConstIt
RoundPackage::const_iterator RoundPackageConstIt
Definition: TOPPASVertex.h:161
OpenMS::TOPPASVertex::topo_nr_
UInt topo_nr_
The number in a topological sort of the entire graph.
Definition: TOPPASVertex.h:324
OpenMS::TOPPASVertex::RoundPackageIt
RoundPackage::iterator RoundPackageIt
Definition: TOPPASVertex.h:162
OpenMS::Math::round
T round(T x)
Rounds the value.
Definition: MathFunctions.h:138
OpenMS::TOPPASVertex::DFS_COLOR
DFS_COLOR
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:168
OpenMS::TOPPASVertex
The base class of the different vertex classes.
Definition: TOPPASVertex.h:101
OpenMS::StringConversions::append
void append(const T &i, String &target)
Definition: StringUtils.h:119
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::TOPPASVertex::TOPPASFilenames
Definition: TOPPASVertex.h:119
OpenMS::TOPPASVertex::debugOut_
void debugOut_(const String &) const
Displays the debug output message, if TOPPAS_DEBUG is defined.
Definition: TOPPASVertex.h:359
OpenMS::TOPPASVertex::RoundPackage
std::map< Int, VertexRoundPackage > RoundPackage
Definition: TOPPASVertex.h:160
OpenMS::TOPPASVertex::VertexRoundPackage::filenames
TOPPASFilenames filenames
filenames passed from upstream node in this round
Definition: TOPPASVertex.h:152
String.h
OpenMS::TOPPASEdge
An edge representing a data flow in TOPPAS.
Definition: TOPPASEdge.h:59
QGraphicsItem
OpenMS::TOPPASVertex::EdgeIterator
EdgeContainer::iterator EdgeIterator
A mutable iterator for in/out edges.
Definition: TOPPASVertex.h:112
OpenMS::TOPPASVertex::RoundPackages
std::vector< RoundPackage > RoundPackages
all information a node needs to process all rounds
Definition: TOPPASVertex.h:165
OpenMS::TOPPASVertex::SUBSTREESTATUS
SUBSTREESTATUS
The color of a vertex during depth-first search.
Definition: TOPPASVertex.h:176
OpenMS::TOPPASVertex::DFS_GRAY
Definition: TOPPASVertex.h:171