OpenMS  2.7.0
TOPPASScene.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-2021.
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 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
39 
43 
44 #include <QtWidgets/QGraphicsScene>
45 #include <QtCore/QProcess>
46 
47 namespace OpenMS
48 {
49  class TOPPASVertex;
50  class TOPPASToolVertex;
51  class TOPPASMergerVertex;
52  class TOPPASOutputFileListVertex;
53  class TOPPASEdge;
54  class TOPPASResources;
55 
59  class FakeProcess :
60  public QProcess
61  {
62  Q_OBJECT
63 
64 public:
65  virtual void start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite);
66  };
67 
85  class OPENMS_GUI_DLLAPI TOPPASScene :
86  public QGraphicsScene
87  {
88  Q_OBJECT
89 
90 public:
91 
93  struct TOPPProcess
94  {
96  TOPPProcess(QProcess * p, const QString & cmd, const QStringList & arg, TOPPASToolVertex * const tool) :
97  proc(p),
98  command(cmd),
99  args(arg),
100  tv(tool)
101  {
102  }
103 
107  QString command;
109  QStringList args;
112  };
113 
116  {
118  AM_MOVE
119  };
120 
121 
124  {
128  ST_REFRESH_REMAINSINVALID
129  };
130 
131 
133  typedef QList<TOPPASEdge *> EdgeContainer;
135  typedef EdgeContainer::iterator EdgeIterator;
137  typedef EdgeContainer::const_iterator ConstEdgeIterator;
139  typedef QList<TOPPASVertex *> VertexContainer;
141  typedef VertexContainer::iterator VertexIterator;
143  typedef VertexContainer::const_iterator ConstVertexIterator;
144 
146  TOPPASScene(QObject * parent, const QString & tmp_path, bool gui = true);
147 
149  ~TOPPASScene() override;
150 
154  void addEdge(TOPPASEdge * te);
168  void copySelected();
170  void paste(QPointF pos = QPointF());
174  void unselectAll();
180  void runPipeline();
182  bool store(const String & file);
184  void load(const String & file);
186  void include(TOPPASScene * new_scene, QPointF pos = QPointF());
190  void setSaveFileName(const String & name);
192  void topoSort(bool resort_all = true);
194  const QString & getOutDir() const;
196  const QString & getTempDir() const;
198  void setOutDir(const QString & dir);
202  void setChanged(bool b);
206  bool askForOutputDir(bool always_ask = true);
208  void enqueueProcess(const TOPPProcess & process);
214  void setClipboard(TOPPASScene * clipboard);
226  void loadResources(const TOPPASResources & resources);
228  void createResources(TOPPASResources & resources);
230  bool wasChanged();
233 
235  bool isGUIMode() const;
236 
238  bool isDryRun() const;
240  QString getDescription() const;
242  void setDescription(const QString & desc);
244  void setAllowedThreads(int num_threads);
249 
250 
251 public slots:
252 
256  void itemClicked();
258  void itemReleased();
260  void updateHoveringEdgePos(const QPointF & new_pos);
262  void addHoveringEdge(const QPointF & pos);
266  void pipelineErrorSlot(const QString msg = "");
268  void moveSelectedItems(qreal dx, qreal dy);
270  void snapToGrid();
273  void setPipelineRunning(bool b = true);
275  void changedParameter(const bool invalidates_running_pipeline);
282 
283 
285 
286  void logTOPPOutput(const QString & out);
297  void logOutputFileWritten(const String & file);
299 
300 signals:
301 
307  void saveMe();
317  void openInTOPPView(QStringList all_files);
319  void dryRunFinished(int, QProcess::ExitStatus);
321  void messageReady(const QString & msg);
322 
323 
324 protected:
325 
339  QString tmp_path_;
341  bool gui_;
343  QString out_dir_;
345  bool changed_;
347  bool running_;
353  QList<TOPPProcess> topp_processes_queue_;
357  bool dry_run_;
366 
368  TOPPASVertex * getVertexAt_(const QPointF & pos);
372  bool dfsVisit_(TOPPASVertex * vertex);
375  bool sanityCheck_(bool allowUserOverride);
376 
378 
379  void contextMenuEvent(QGraphicsSceneContextMenuEvent * event) override;
381 
383  void writeToLogFile_(const QString & text);
384  };
385 
386 }
387 
A FakeProcess class.
Definition: TOPPASScene.h:61
virtual void start(const QString &program, const QStringList &arguments, OpenMode mode=ReadWrite)
A more convenient string class.
Definition: String.h:61
An edge representing a data flow in TOPPAS.
Definition: TOPPASEdge.h:62
A special vertex that allows to merge several inputs.
Definition: TOPPASMergerVertex.h:60
A vertex representing an output file list.
Definition: TOPPASOutputFileListVertex.h:51
A dictionary mapping string keys to lists of TOPPASResource objects.
Definition: TOPPASResources.h:57
A container for all visual items of a TOPPAS workflow.
Definition: TOPPASScene.h:87
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:124
@ ST_REFRESH_CHANGED
some parameters were updated, but pipeline is ok
Definition: TOPPASScene.h:126
@ ST_REFRESH_CHANGEINVALID
updating made pipeline invalid
Definition: TOPPASScene.h:127
@ ST_REFRESH_NOCHANGE
no updates required
Definition: TOPPASScene.h:125
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:363
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:331
~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:333
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:349
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:353
TOPPASVertex * potential_target_
The current potential target vertex of the hovering edge.
Definition: TOPPASScene.h:335
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:351
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:327
bool wasChanged()
Returns whether the workflow has been changed since the latest "save".
TOPPASEdge * getHoveringEdge()
returns the hovering edge
bool dry_run_
dry run mode (no tools are actually called)
Definition: TOPPASScene.h:357
void copySelected()
Copies all currently selected edges and vertices.
VertexContainer::const_iterator ConstVertexIterator
A const iterator for vertices.
Definition: TOPPASScene.h:143
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:341
ActionMode
The current action mode (creation of a new edge, or panning of the widget)
Definition: TOPPASScene.h:116
@ AM_NEW_EDGE
Definition: TOPPASScene.h:117
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:355
QList< TOPPASEdge * > EdgeContainer
The container for edges.
Definition: TOPPASScene.h:133
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:137
void openInTOPPView(QStringList all_files)
Emitted when files are triggered for opening in TOPPView.
VertexContainer vertices_
The list of all vertices.
Definition: TOPPASScene.h:329
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:345
void mainWindowNeedsUpdate()
Emitted when the main window needs to be updated.
VertexIterator verticesEnd()
Returns end() iterator of all vertices.
int threads_active_
currently running processes...
Definition: TOPPASScene.h:359
QString tmp_path_
The path for temporary files.
Definition: TOPPASScene.h:339
void paste(QPointF pos=QPointF())
Pastes the copied items.
bool sanityCheck_(bool allowUserOverride)
bool isPipelineRunning()
Returns if a pipeline is currently running.
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:361
bool running_
Indicates if a pipeline is currently running.
Definition: TOPPASScene.h:347
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:337
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 pipelineErrorSlot(const QString msg="")
Called by vertices at which an error occurred during pipeline execution.
void connectOutputVertexSignals(TOPPASOutputFileListVertex *oflv)
Connects the signals to slots.
ActionMode getActionMode()
Returns the action mode.
void unselectAll()
Unselects all items.
VertexContainer::iterator VertexIterator
A mutable iterator for vertices.
Definition: TOPPASScene.h:141
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:343
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:135
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:365
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:139
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:62
The base class of the different vertex classes.
Definition: TOPPASVertex.h:104
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Stores the information for a TOPP process.
Definition: TOPPASScene.h:94
TOPPASToolVertex * tv
The tool which is started (used to call its slots)
Definition: TOPPASScene.h:111
QString command
The command.
Definition: TOPPASScene.h:107
QStringList args
The arguments.
Definition: TOPPASScene.h:109
QProcess * proc
The process.
Definition: TOPPASScene.h:105
TOPPProcess(QProcess *p, const QString &cmd, const QStringList &arg, TOPPASToolVertex *const tool)
Constructor.
Definition: TOPPASScene.h:96