OpenMS
TOPPASScene.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, 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 <QtWidgets/QGraphicsScene>
19 #include <QtCore/QProcess>
20 
21 namespace OpenMS
22 {
23  class TOPPASVertex;
24  class TOPPASToolVertex;
25  class TOPPASMergerVertex;
26  class TOPPASOutputFileListVertex;
27  class TOPPASEdge;
28  class TOPPASResources;
29 
33  class FakeProcess :
34  public QProcess
35  {
36  Q_OBJECT
37 
38 public:
39  virtual void start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite);
40  };
41 
59  class OPENMS_GUI_DLLAPI TOPPASScene :
60  public QGraphicsScene
61  {
62  Q_OBJECT
63 
64 public:
65 
67  struct TOPPProcess
68  {
70  TOPPProcess(QProcess * p, const QString & cmd, const QStringList & arg, TOPPASToolVertex * const tool) :
71  proc(p),
72  command(cmd),
73  args(arg),
74  tv(tool)
75  {
76  }
77 
81  QString command;
83  QStringList args;
86  };
87 
90  {
92  AM_MOVE
93  };
94 
95 
98  {
102  ST_REFRESH_REMAINSINVALID
103  };
104 
105 
107  typedef QList<TOPPASEdge *> EdgeContainer;
109  typedef EdgeContainer::iterator EdgeIterator;
111  typedef EdgeContainer::const_iterator ConstEdgeIterator;
113  typedef QList<TOPPASVertex *> VertexContainer;
115  typedef VertexContainer::iterator VertexIterator;
117  typedef VertexContainer::const_iterator ConstVertexIterator;
118 
120  TOPPASScene(QObject * parent, const QString & tmp_path, bool gui = true);
121 
123  ~TOPPASScene() override;
124 
128  void addEdge(TOPPASEdge * te);
142  void copySelected();
144  void paste(QPointF pos = QPointF());
148  void unselectAll();
154  void runPipeline();
156  bool store(const String & file);
158  void load(const String & file);
160  void include(TOPPASScene * new_scene, QPointF pos = QPointF());
164  void setSaveFileName(const String & name);
166  void topoSort(bool resort_all = true);
168  const QString & getOutDir() const;
170  const QString & getTempDir() const;
172  void setOutDir(const QString & dir);
176  void setChanged(bool b);
178  bool isPipelineRunning() const;
180  bool askForOutputDir(bool always_ask = true);
182  void enqueueProcess(const TOPPProcess & process);
188  void setClipboard(TOPPASScene * clipboard);
200  void loadResources(const TOPPASResources & resources);
202  void createResources(TOPPASResources & resources);
204  bool wasChanged() const;
207 
209  bool isGUIMode() const;
210 
212  bool isDryRun() const;
214  QString getDescription() const;
216  void setDescription(const QString & desc);
218  void setAllowedThreads(int num_threads);
223 
224 
225 public slots:
226 
230  void itemClicked();
232  void itemReleased();
234  void updateHoveringEdgePos(const QPointF & new_pos);
236  void addHoveringEdge(const QPointF & pos);
240  void pipelineErrorSlot(const QString& msg = "");
242  void moveSelectedItems(qreal dx, qreal dy);
244  void snapToGrid();
247  void setPipelineRunning(bool b = true);
249  void changedParameter(const bool invalidates_running_pipeline);
256 
257 
259 
260  void logTOPPOutput(const QString & out);
271  void logOutputFileWritten(const String & file);
273 
274 signals:
275 
281  void saveMe();
291  void openInTOPPView(QStringList all_files);
293  void dryRunFinished(int, QProcess::ExitStatus);
295  void messageReady(const QString & msg);
296 
297 
298 protected:
299 
313  QString tmp_path_;
315  bool gui_;
317  QString out_dir_;
319  bool changed_;
321  bool running_;
327  QList<TOPPProcess> topp_processes_queue_;
331  bool dry_run_;
340 
342  TOPPASVertex * getVertexAt_(const QPointF & pos);
346  bool dfsVisit_(TOPPASVertex * vertex);
349  bool sanityCheck_(bool allowUserOverride);
350 
352 
353  void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
355 
357  void writeToLogFile_(const QString & text);
358  };
359 
360 }
361 
A FakeProcess class.
Definition: TOPPASScene.h:35
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:34
A vertex representing an output file list.
Definition: TOPPASOutputFileListVertex.h:25
A dictionary mapping string keys to lists of TOPPASResource objects.
Definition: TOPPASResources.h:32
A container for all visual items of a TOPPAS workflow.
Definition: TOPPASScene.h:61
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:98
@ ST_REFRESH_CHANGED
some parameters were updated, but pipeline is ok
Definition: TOPPASScene.h:100
@ ST_REFRESH_CHANGEINVALID
updating made pipeline invalid
Definition: TOPPASScene.h:101
@ ST_REFRESH_NOCHANGE
no updates required
Definition: TOPPASScene.h:99
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:337
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:305
~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:307
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:323
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:327
TOPPASVertex * potential_target_
The current potential target vertex of the hovering edge.
Definition: TOPPASScene.h:309
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:325
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:301
TOPPASEdge * getHoveringEdge()
returns the hovering edge
bool dry_run_
dry run mode (no tools are actually called)
Definition: TOPPASScene.h:331
void copySelected()
Copies all currently selected edges and vertices.
VertexContainer::const_iterator ConstVertexIterator
A const iterator for vertices.
Definition: TOPPASScene.h:117
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:315
ActionMode
The current action mode (creation of a new edge, or panning of the widget)
Definition: TOPPASScene.h:90
@ AM_NEW_EDGE
Definition: TOPPASScene.h:91
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:329
QList< TOPPASEdge * > EdgeContainer
The container for edges.
Definition: TOPPASScene.h:107
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:111
void openInTOPPView(QStringList all_files)
Emitted when files are triggered for opening in TOPPView.
VertexContainer vertices_
The list of all vertices.
Definition: TOPPASScene.h:303
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:319
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:333
QString tmp_path_
The path for temporary files.
Definition: TOPPASScene.h:313
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:335
bool running_
Indicates if a pipeline is currently running.
Definition: TOPPASScene.h:321
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:311
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_.
void connectOutputVertexSignals(TOPPASOutputFileListVertex *oflv)
Connects the signals to slots.
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:115
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:317
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:109
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:339
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:113
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:77
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Stores the information for a TOPP process.
Definition: TOPPASScene.h:68
TOPPASToolVertex * tv
The tool which is started (used to call its slots)
Definition: TOPPASScene.h:85
QString command
The command.
Definition: TOPPASScene.h:81
QStringList args
The arguments.
Definition: TOPPASScene.h:83
QProcess * proc
The process.
Definition: TOPPASScene.h:79
TOPPProcess(QProcess *p, const QString &cmd, const QStringList &arg, TOPPASToolVertex *const tool)
Constructor.
Definition: TOPPASScene.h:70