OpenMS
TOPPASScene.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- 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 
18 
19 #include <QtWidgets/QGraphicsScene>
20 #include <QtCore/QProcess>
21 
22 namespace OpenMS
23 {
24  class TOPPASVertex;
25  class TOPPASToolVertex;
26  class TOPPASMergerVertex;
27  class TOPPASOutputFileListVertex;
28  class TOPPASEdge;
29  class TOPPASResources;
30 
34  class FakeProcess :
35  public QProcess
36  {
37  Q_OBJECT
38 
39 public:
40  virtual void start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite);
41  };
42 
60  class OPENMS_GUI_DLLAPI TOPPASScene :
61  public QGraphicsScene
62  {
63  Q_OBJECT
64 
65 public:
66 
68  struct TOPPProcess
69  {
71  TOPPProcess(QProcess * p, const QString & cmd, const QStringList & arg, TOPPASToolVertex * const tool) :
72  proc(p),
73  command(cmd),
74  args(arg),
75  tv(tool)
76  {
77  }
78 
82  QString command;
84  QStringList args;
87  };
88 
91  {
93  AM_MOVE
94  };
95 
96 
99  {
103  ST_REFRESH_REMAINSINVALID
104  };
105 
106 
108  typedef QList<TOPPASEdge *> EdgeContainer;
110  typedef EdgeContainer::iterator EdgeIterator;
112  typedef EdgeContainer::const_iterator ConstEdgeIterator;
114  typedef QList<TOPPASVertex *> VertexContainer;
116  typedef VertexContainer::iterator VertexIterator;
118  typedef VertexContainer::const_iterator ConstVertexIterator;
119 
121  TOPPASScene(QObject * parent, const QString & tmp_path, bool gui = true);
122 
124  ~TOPPASScene() override;
125 
129  void addEdge(TOPPASEdge * te);
143  void copySelected();
145  void paste(QPointF pos = QPointF());
149  void unselectAll();
155  void runPipeline();
157  bool store(const String & file);
159  void load(const String & file);
161  void include(TOPPASScene * new_scene, QPointF pos = QPointF());
165  void setSaveFileName(const String & name);
167  void topoSort(bool resort_all = true);
169  const QString & getOutDir() const;
171  const QString & getTempDir() const;
173  void setOutDir(const QString & dir);
177  void setChanged(bool b);
179  bool isPipelineRunning() const;
181  bool askForOutputDir(bool always_ask = true);
183  void enqueueProcess(const TOPPProcess & process);
189  void setClipboard(TOPPASScene * clipboard);
201  void loadResources(const TOPPASResources & resources);
203  void createResources(TOPPASResources & resources);
205  bool wasChanged() const;
208 
210  bool isGUIMode() const;
211 
213  bool isDryRun() const;
215  QString getDescription() const;
217  void setDescription(const QString & desc);
219  void setAllowedThreads(int num_threads);
224 
225 
226 public slots:
227 
231  void itemClicked();
233  void itemReleased();
235  void updateHoveringEdgePos(const QPointF & new_pos);
237  void addHoveringEdge(const QPointF & pos);
241  void pipelineErrorSlot(const QString& msg = "");
243  void moveSelectedItems(qreal dx, qreal dy);
245  void snapToGrid();
248  void setPipelineRunning(bool b = true);
250  void changedParameter(const bool invalidates_running_pipeline);
257 
258 
260 
261  void logTOPPOutput(const QString & out);
272  void logOutputFileWritten(const String & file);
274 
275 signals:
276 
282  void saveMe();
292  void openInTOPPView(QStringList all_files);
294  void dryRunFinished(int, QProcess::ExitStatus);
296  void messageReady(const QString & msg);
297 
298 
299 protected:
300 
314  QString tmp_path_;
316  bool gui_;
318  QString out_dir_;
320  bool changed_;
322  bool running_;
328  QList<TOPPProcess> topp_processes_queue_;
332  bool dry_run_;
341 
343  TOPPASVertex * getVertexAt_(const QPointF & pos);
347  bool dfsVisit_(TOPPASVertex * vertex);
350  bool sanityCheck_(bool allowUserOverride);
351 
353 
354  void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
356 
358  void writeToLogFile_(const QString & text);
359  };
360 
361 }
362 
A FakeProcess class.
Definition: TOPPASScene.h:36
virtual void start(const QString &program, const QStringList &arguments, OpenMode mode=ReadWrite)
A more convenient string class.
Definition: String.h:34
An edge representing a data flow in TOPPAS.
Definition: TOPPASEdge.h:36
A special vertex that allows to merge several inputs.
Definition: TOPPASMergerVertex.h:33
A vertex representing an output, either folder or files(s)
Definition: TOPPASOutputVertex.h:24
A dictionary mapping string keys to lists of TOPPASResource objects.
Definition: TOPPASResources.h:32
Definition: TOPPASScene.h:62
bool askForOutputDir(bool always_ask=true)
Shows a dialog that allows to specify the output directory. If always_ask == false,...
void logToolFinished()
Writes the "tool finished" message to the logfile (and to stdout if no gui available)
RefreshStatus
Pipeline status after refreshParameters() was called.
Definition: TOPPASScene.h:99
@ ST_REFRESH_CHANGED
some parameters were updated, but pipeline is ok
Definition: TOPPASScene.h:101
@ ST_REFRESH_CHANGEINVALID
updating made pipeline invalid
Definition: TOPPASScene.h:102
@ ST_REFRESH_NOCHANGE
no updates required
Definition: TOPPASScene.h:100
void logToolCrashed()
Writes the "tool crashed" message to the logfile (and to stdout if no gui available)
void setPipelineRunning(bool b=true)
void changedParameter(const bool invalidates_running_pipeline)
Invoked by TTV or other vertices if a parameter was edited.
void setOutDir(const QString &dir)
Sets the name of the directory for output files.
void itemReleased()
Called when an item is released.
void terminateCurrentPipeline()
Kills all connected TOPP processes.
void dryRunFinished(int, QProcess::ExitStatus)
Emitted when in dry run mode and asked to run a TOPP tool (to fake success)
int allowed_threads_
maximum number of allowed threads
Definition: TOPPASScene.h:338
void writeToLogFile_(const QString &text)
Writes the text to the logfile.
void setSaveFileName(const String &name)
Sets the file name.
EdgeContainer edges_
The list of all edges.
Definition: TOPPASScene.h:306
~TOPPASScene() override
Destructor.
void messageReady(const QString &msg)
Emitted when there is an important message that needs to be printed in TOPPAS.
TOPPASEdge * hover_edge_
The hovering edge which is currently being created.
Definition: TOPPASScene.h:308
TOPPASVertex * getVertexAt_(const QPointF &pos)
Returns the vertex in the foreground at position pos , if existent, otherwise 0.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
VertexIterator verticesBegin()
Returns begin() iterator of all vertices.
void logOutputFileWritten(const String &file)
Writes the "output file written" message to the logfile (and to stdout if no gui available)
void setDescription(const QString &desc)
when description is updated by user, use this to update the description for later storage in file
void snapToGrid()
Makes all vertices snap to the grid.
const QString & getOutDir() const
Returns the name of the directory for output files.
bool error_occured_
true if an error occurred during pipeline execution
Definition: TOPPASScene.h:324
const QString & getTempDir() const
Returns the name of the directory for temporary files.
bool isEdgeAllowed_(TOPPASVertex *u, TOPPASVertex *v)
Returns whether an edge between node u and v would be allowed.
QList< TOPPProcess > topp_processes_queue_
The queue of pending TOPP processes.
Definition: TOPPASScene.h:328
TOPPASVertex * potential_target_
The current potential target vertex of the hovering edge.
Definition: TOPPASScene.h:310
void processFinished()
Called by a finished QProcess to indicate that we are free to start a new one.
void setChanged(bool b)
Sets the changed flag.
bool user_specified_out_dir_
Indicates if the output directory has been specified by the user already.
Definition: TOPPASScene.h:326
bool saveIfChanged()
Saves the pipeline if it has been changed since the last save.
void moveSelectedItems(qreal dx, qreal dy)
Moves all selected items by dx, dy.
void updateHoveringEdgePos(const QPointF &new_pos)
Called when the position of the hovering edge changes.
void runPipeline()
Runs the pipeline.
void quitWithError()
dirty solution: when using ExecutePipeline this slot is called when the pipeline crashes....
void selectionCopied(TOPPASScene *ts)
Emitted when a selection is copied to the clipboard.
void setAllowedThreads(int num_threads)
sets the maximum number of jobs
void include(TOPPASScene *new_scene, QPointF pos=QPointF())
Includes the pipeline scene.
ActionMode action_mode_
The current action mode.
Definition: TOPPASScene.h:302
TOPPASEdge * getHoveringEdge()
returns the hovering edge
bool dry_run_
dry run mode (no tools are actually called)
Definition: TOPPASScene.h:332
void copySelected()
Copies all currently selected edges and vertices.
VertexContainer::const_iterator ConstVertexIterator
A const iterator for vertices.
Definition: TOPPASScene.h:118
void connectOutputVertexSignals(TOPPASOutputVertex *oflv)
Connects the signals to slots.
bool isDryRun() const
determine dry run status (are tools actually called?)
void addVertex(TOPPASVertex *tv)
Adds a vertex.
bool gui_
Are we in a GUI or is the scene used by ExecutePipeline (at the command line)?
Definition: TOPPASScene.h:316
ActionMode
The current action mode (creation of a new edge, or panning of the widget)
Definition: TOPPASScene.h:91
@ AM_NEW_EDGE
Definition: TOPPASScene.h:92
void connectMergerVertexSignals(TOPPASMergerVertex *tmv)
Connects the signals to slots.
void connectToolVertexSignals(TOPPASToolVertex *ttv)
Connects the signals to slots.
void logToolFailed()
Writes the "tool failed" message to the logfile (and to stdout if no gui available)
void setClipboard(TOPPASScene *clipboard)
Sets the clipboard content.
void topoSort(bool resort_all=true)
Performs a topological sort of all vertices.
TOPPASScene * clipboard_
Stores the clipboard content when requested from TOPPASBase.
Definition: TOPPASScene.h:330
QList< TOPPASEdge * > EdgeContainer
The container for edges.
Definition: TOPPASScene.h:108
void enqueueProcess(const TOPPProcess &process)
Enqueues the process, it will be run when the currently pending processes have finished.
EdgeContainer::const_iterator ConstEdgeIterator
A const iterator for edges.
Definition: TOPPASScene.h:112
void openInTOPPView(QStringList all_files)
Emitted when files are triggered for opening in TOPPView.
VertexContainer vertices_
The list of all vertices.
Definition: TOPPASScene.h:304
void finishHoveringEdge()
Called when the new edge is being "released".
bool changed_
Flag that indicates if the pipeline has been changed since the last save.
Definition: TOPPASScene.h:320
void mainWindowNeedsUpdate()
Emitted when the main window needs to be updated.
VertexIterator verticesEnd()
Returns end() iterator of all vertices.
bool isPipelineRunning() const
Returns if a pipeline is currently running.
int threads_active_
currently running processes...
Definition: TOPPASScene.h:334
QString tmp_path_
The path for temporary files.
Definition: TOPPASScene.h:314
void paste(QPointF pos=QPointF())
Pastes the copied items.
bool sanityCheck_(bool allowUserOverride)
void pipelineErrorSlot(const QString &msg="")
Called by vertices at which an error occurred during pipeline execution.
QString getDescription() const
workflow description (to be displayed in TOPPAS window)
bool isGUIMode() const
is TOPPASScene run in GUI or non-GUI (ExecutePipeline) mode, i.e. are MessageBoxes allowed?
QString description_text_
description text
Definition: TOPPASScene.h:336
bool running_
Indicates if a pipeline is currently running.
Definition: TOPPASScene.h:322
void resetProcessesQueue()
Resets the processes queue.
void logToolStarted()
Writes the "tool started" message to the logfile (and to stdout if no gui available)
RefreshStatus refreshParameters()
Refreshes the parameters of the TOPP tools in this workflow.
void entirePipelineFinished()
Emitted when the entire pipeline execution is finished.
void addHoveringEdge(const QPointF &pos)
Called when a new out edge is supposed to be created.
void createResources(TOPPASResources &resources)
Create resources from the current workflow.
void addEdge(TOPPASEdge *te)
Adds an edge.
void checkIfWeAreDone()
Checks whether all output vertices are finished, and if yes, emits entirePipelineFinished() (called b...
String file_name_
The file name of this pipeline.
Definition: TOPPASScene.h:312
EdgeIterator edgesEnd()
Returns end() iterator of all edges.
void runNextProcess()
Runs the next process in the queue, if any.
void resetDownstream(TOPPASVertex *vertex)
Called when user fires "Resume" action, to clear downstream nodes from previous results.
const String & getSaveFileName()
Returns the file name.
void requestClipboardContent()
Requests the clipboard content from TOPPASBase, will be stored in clipboard_.
ActionMode getActionMode()
Returns the action mode.
bool wasChanged() const
Returns whether the workflow has been changed since the latest "save".
void unselectAll()
Unselects all items.
VertexContainer::iterator VertexIterator
A mutable iterator for vertices.
Definition: TOPPASScene.h:116
void updateEdgeColors()
Updates all edge colors (color of green and yellow edges can change when edges are added/removed)
QString out_dir_
The directory where the output files will be written.
Definition: TOPPASScene.h:318
void loadResources(const TOPPASResources &resources)
Loads the resources into the input nodes of this workflow.
EdgeContainer::iterator EdgeIterator
A mutable iterator for edges.
Definition: TOPPASScene.h:110
void connectVertexSignals(TOPPASVertex *tv)
Connects the signals to slots.
void itemClicked()
Called when an item is clicked.
bool store(const String &file)
Stores the pipeline to file, returns true on success.
void load(const String &file)
Loads the pipeline from file.
TOPPASToolVertex * resume_source_
last node where 'resume' was started
Definition: TOPPASScene.h:340
void connectEdgeSignals(TOPPASEdge *e)
Connects the signals to slots.
void abortPipeline()
Terminates the currently running pipeline.
void setActionMode(ActionMode mode)
Sets the action mode.
void changedOutputFolder()
Invoked by OutfilelistVertex of user changed the folder name.
TOPPASScene(QObject *parent, const QString &tmp_path, bool gui=true)
Constructor.
EdgeIterator edgesBegin()
Returns begin() iterator of all edges.
QList< TOPPASVertex * > VertexContainer
The container for vertices.
Definition: TOPPASScene.h:114
void removeSelected()
Removes all currently selected edges and vertices.
void pipelineExecutionFailed()
Emitted when the pipeline execution has failed.
bool dfsVisit_(TOPPASVertex *vertex)
DFS helper method. Returns true, if a back edge has been discovered.
void saveMe()
Emitted when the pipeline should be saved (showing a save as file dialog and so on)
A vertex representing a TOPP tool.
Definition: TOPPASToolVertex.h:36
The base class of the different vertex classes.
Definition: TOPPASVertex.h:78
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Stores the information for a TOPP process.
Definition: TOPPASScene.h:69
TOPPASToolVertex * tv
The tool which is started (used to call its slots)
Definition: TOPPASScene.h:86
QString command
The command.
Definition: TOPPASScene.h:82
QStringList args
The arguments.
Definition: TOPPASScene.h:84
QProcess * proc
The process.
Definition: TOPPASScene.h:80
TOPPProcess(QProcess *p, const QString &cmd, const QStringList &arg, TOPPASToolVertex *const tool)
Constructor.
Definition: TOPPASScene.h:71