OpenMS
TOPPASToolVertex.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 // OpenMS_GUI config
12 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
13 
17 
18 #include <QtCore/QVector>
19 
20 namespace OpenMS
21 {
22  class TOPPASScene;
23 
34  class OPENMS_GUI_DLLAPI TOPPASToolVertex :
35  public TOPPASVertex
36  {
37  Q_OBJECT
38 
39 public:
41  enum TOOLSTATUS {TOOL_READY, TOOL_SCHEDULED, TOOL_RUNNING, TOOL_SUCCESS, TOOL_CRASH, TOOLSTATUS_SIZE};
42 
44  struct IOInfo
45  {
47  IOInfo() :
48  type(IOT_FILE),
49  param_name(),
50  valid_types()
51  {
52  }
53 
55  IOInfo(const IOInfo& rhs) :
56  type(rhs.type),
57  param_name(rhs.param_name),
58  valid_types(rhs.valid_types)
59  {
60  }
61 
63  enum IOType
64  {
67  IOT_DIR
68  };
69 
71  bool operator<(const IOInfo& rhs) const
72  {
73  if (type != rhs.type)
74  {
75  return type == IOT_FILE;
76  }
77  else
78  {
79  return param_name.compare(rhs.param_name) < 0;
80  }
81  }
83  bool operator==(const IOInfo& rhs) const
84  {
85  return type == rhs.type && param_name == rhs.param_name;
86  }
87 
89  IOInfo& operator=(const IOInfo& rhs)
90  {
91  type = rhs.type;
92  param_name = rhs.param_name;
93  valid_types = rhs.valid_types;
94 
95  return *this;
96  }
97 
99  static bool isAnyList(const QVector<IOInfo>& params)
100  {
101  for (const auto& p : params)
102  {
103  if (p.type == IOT_LIST) return true;
104  }
105  return false;
106  }
107 
114  };
115 
119  TOPPASToolVertex(const String& name, const String& type = "");
123  ~TOPPASToolVertex() override = default;
126 
127  virtual std::unique_ptr<TOPPASVertex> clone() const override;
128 
130  String getName() const override;
132  const String& getType() const;
134  QVector<IOInfo> getInputParameters() const;
136  QVector<IOInfo> getOutputParameters() const;
137  // documented in base class
138  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
139  // documented in base class
140  QRectF boundingRect() const override;
141  // documented in base class
142  void setTopoNr(UInt nr) override;
143  // documented in base class
144  void reset(bool reset_all_files = false) override;
146  void setParam(const Param& param);
148  const Param& getParam();
150  void run() override;
154  bool updateCurrentOutputFileNames(const RoundPackages& pkg, String& error_message);
158  void editParam();
166  void createDirs();
168  void openContainingFolder() const;
174  bool isToolReady() const;
178  virtual void emitToolStarted();
180  bool invertRecylingMode() override;
181 
182 public slots:
183 
185  void executionFinished(int ec, QProcess::ExitStatus es);
197  virtual void toolScheduledSlot();
199  void inEdgeHasChanged() override;
201  void outEdgeHasChanged() override;
202 
203 signals:
204 
206  void toolStarted();
208  void toolFinished();
210  void toolCrashed();
212  void toolFailed(int return_code = -1, const QString& message = "");
214  void toppOutputReady(const QString& out);
215 
216 protected:
217 
219 
220  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e) override;
222 
223 
226 
232  bool initParam_(const QString& old_ini_file = "");
234  QVector<IOInfo> getParameters_(bool input_params) const;
236  void writeParam_(const Param& param, const QString& ini_file);
238  QString toolnameWithWhitespacesForFancyWordWrapping_(QPainter* painter, const QString& str);
241  void smartFileNames_(std::vector<QStringList>& filenames);
242 
252  TOOLSTATUS status_{TOOL_READY};
254  bool tool_ready_{true};
256  bool breakpoint_set_{false};
257  };
258 }
259 
Management and storage of parameters / INI files.
Definition: Param.h:44
A more convenient string class.
Definition: String.h:34
Definition: TOPPASScene.h:62
A vertex representing a TOPP tool.
Definition: TOPPASToolVertex.h:36
TOOLSTATUS getStatus() const
return if tool failed or is ready etc.
void toppOutputReady(const QString &out)
Emitted from forwardTOPPOutput() to forward the signal outside.
void setParam(const Param &param)
Sets the Param object of this tool.
void reset(bool reset_all_files=false) override
String type_
The type of the tool, or "" if it does not have a type.
Definition: TOPPASToolVertex.h:246
void toggleBreakpoint()
Toggle breakpoint.
bool renameOutput_()
renames SUFFICES of the output files created by the TOPP tool by inspecting file content
bool initParam_(const QString &old_ini_file="")
Initializes the parameters with standard values (from -write_ini), uses the parameters from the old_i...
Param param_
The parameters of the tool.
Definition: TOPPASToolVertex.h:250
bool isToolReady() const
underlying TOPP tool found and parameters fetched?! (done in C'Tor)
void inEdgeHasChanged() override
Called by an incoming edge when it has changed.
void writeParam_(const Param &param, const QString &ini_file)
Writes param to the ini_file.
virtual std::unique_ptr< TOPPASVertex > clone() const override
Make a copy of this vertex on the heap and return a pointer to it (useful for copying nodes)
String name_
The name of the tool.
Definition: TOPPASToolVertex.h:244
void toolStartedSlot()
Called when the tool is started.
String getFullOutputDirectory() const
Returns the full directory (including preceding tmp path)
QVector< IOInfo > getInputParameters() const
Returns input file/list parameters together with their valid types.
void toolFailedSlot()
Called when the tool has failed.
void toolFinished()
Emitted when the tool is finished.
TOPPASToolVertex(const TOPPASToolVertex &rhs)
Copy constructor.
void outEdgeHasChanged() override
Called by an outgoing edge when it has changed.
void openContainingFolder() const
Opens the folder where the file is contained.
bool invertRecylingMode() override
invert status of recycling (overriding base class)
void openInTOPPView()
Opens the files in TOPPView.
void toolCrashedSlot()
Called when the tool has crashed.
void toolFinishedSlot()
Called when the tool has finished.
String getOutputDir() const
Returns the directory where this tool stores its output files.
TOPPASToolVertex()
Default constructor.
virtual void toolScheduledSlot()
Called when the tool was scheduled for running.
TOPPASToolVertex & operator=(const TOPPASToolVertex &rhs)
Assignment operator.
bool updateCurrentOutputFileNames(const RoundPackages &pkg, String &error_message)
void forwardTOPPOutput()
Called when the running TOPP tool produces output.
QVector< IOInfo > getParameters_(bool input_params) const
returns input/output file/list parameters. If input_params is true, input params are returned,...
void editParam()
Lets the user edit the parameters of the tool.
int numIterations()
Returns the number of iterations this tool has to perform.
const String & getType() const
Returns the type of the tool.
String getName() const override
returns the name of the TOPP tool
void smartFileNames_(std::vector< QStringList > &filenames)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) override
QString toolnameWithWhitespacesForFancyWordWrapping_(QPainter *painter, const QString &str)
Helper method for finding good boundaries for wrapping the tool name. Returns a string with whitespac...
String tmp_path_
The temporary path.
Definition: TOPPASToolVertex.h:248
TOOLSTATUS
current status of the vertex
Definition: TOPPASToolVertex.h:41
@ TOOL_CRASH
Definition: TOPPASToolVertex.h:41
bool refreshParameters()
Refreshes the parameters of this tool, returns if their has been a change.
QRectF boundingRect() const override
Returns the bounding rectangle of this item.
virtual void emitToolStarted()
Called when the QProcess in the queue is called: emits 'toolStarted()'.
void createDirs()
Creates all necessary directories.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void setTopoNr(UInt nr) override
Sets the topological sort number (overridden in tool and output vertices)
void run() override
Checks if all parent nodes have finished the tool execution and, if so, runs the tool.
TOPPASToolVertex(const String &name, const String &type="")
Constructor.
void toolStarted()
Emitted when the tool is started.
bool doesParamChangeInvalidate_()
determines if according to current status_, a parameter change would invalidate the pipeline status (...
QVector< IOInfo > getOutputParameters() const
Returns output file/list/dir parameters together with their valid types.
~TOPPASToolVertex() override=default
Destructor.
TOPPASScene * getScene_() const
get parent Scene
void toolFailed(int return_code=-1, const QString &message="")
Emitted when the tool execution fails.
void toolCrashed()
Emitted when the tool crashes.
void executionFinished(int ec, QProcess::ExitStatus es)
Called when the execution of this tool has finished.
const Param & getParam()
Returns the Param object of this tool.
The base class of the different vertex classes.
Definition: TOPPASVertex.h:78
std::vector< RoundPackage > RoundPackages
all information a node needs to process all rounds
Definition: TOPPASVertex.h:139
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Stores the information for input/output files/lists.
Definition: TOPPASToolVertex.h:45
IOType
The type.
Definition: TOPPASToolVertex.h:64
@ IOT_LIST
Definition: TOPPASToolVertex.h:66
@ IOT_FILE
Definition: TOPPASToolVertex.h:65
String param_name
The name of the parameter.
Definition: TOPPASToolVertex.h:111
static bool isAnyList(const QVector< IOInfo > &params)
Is any of the input/output parameters a list?
Definition: TOPPASToolVertex.h:99
IOInfo & operator=(const IOInfo &rhs)
Assignment operator.
Definition: TOPPASToolVertex.h:89
StringList valid_types
The valid file types for this parameter.
Definition: TOPPASToolVertex.h:113
IOInfo()
Standard constructor.
Definition: TOPPASToolVertex.h:47
bool operator<(const IOInfo &rhs) const
Comparison operator.
Definition: TOPPASToolVertex.h:71
bool operator==(const IOInfo &rhs) const
Comparison operator.
Definition: TOPPASToolVertex.h:83
IOType type
The type of the parameter.
Definition: TOPPASToolVertex.h:109
IOInfo(const IOInfo &rhs)
Copy constructor.
Definition: TOPPASToolVertex.h:55