OpenMS  2.5.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-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 // 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 
152  void addVertex(TOPPASVertex * tv);
154  void addEdge(TOPPASEdge * te);
156  void setActionMode(ActionMode mode);
158  ActionMode getActionMode();
160  VertexIterator verticesBegin();
162  VertexIterator verticesEnd();
164  EdgeIterator edgesBegin();
166  EdgeIterator edgesEnd();
168  void copySelected();
170  void paste(QPointF pos = QPointF());
172  void removeSelected();
174  void unselectAll();
176  void updateEdgeColors();
178  void resetDownstream(TOPPASVertex * vertex);
180  void runPipeline();
182  bool store(const String & file);
184  void load(const String & file);
186  void include(TOPPASScene * new_scene, QPointF pos = QPointF());
188  const String & getSaveFileName();
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);
200  bool saveIfChanged();
202  void setChanged(bool b);
204  bool isPipelineRunning();
206  bool askForOutputDir(bool always_ask = true);
208  void enqueueProcess(const TOPPProcess & process);
210  void runNextProcess();
212  void resetProcessesQueue();
214  void setClipboard(TOPPASScene * clipboard);
216  void connectVertexSignals(TOPPASVertex * tv);
218  void connectToolVertexSignals(TOPPASToolVertex * ttv);
220  void connectOutputVertexSignals(TOPPASOutputFileListVertex * oflv);
222  void connectMergerVertexSignals(TOPPASMergerVertex * tmv);
224  void connectEdgeSignals(TOPPASEdge * e);
226  void loadResources(const TOPPASResources & resources);
228  void createResources(TOPPASResources & resources);
230  bool wasChanged();
232  RefreshStatus refreshParameters();
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);
246  TOPPASEdge* getHoveringEdge();
248  void checkIfWeAreDone();
249 
250 
251 public slots:
252 
254  void abortPipeline();
256  void itemClicked();
258  void itemReleased();
260  void updateHoveringEdgePos(const QPointF & new_pos);
262  void addHoveringEdge(const QPointF & pos);
264  void finishHoveringEdge();
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);
277  void changedOutputFolder();
279  void processFinished();
281  void quitWithError();
282 
283 
285 
286  void logTOPPOutput(const QString & out);
289  void logToolStarted();
291  void logToolFinished();
293  void logToolFailed();
295  void logToolCrashed();
297  void logOutputFileWritten(const String & file);
299 
300 signals:
301 
303  void entirePipelineFinished();
305  void pipelineExecutionFailed();
307  void saveMe();
309  void terminateCurrentPipeline();
311  void selectionCopied(TOPPASScene * ts);
313  void requestClipboardContent();
315  void mainWindowNeedsUpdate();
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);
370  bool isEdgeAllowed_(TOPPASVertex * u, TOPPASVertex * v);
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 
OpenMS::TOPPASScene::VertexIterator
VertexContainer::iterator VertexIterator
A mutable iterator for vertices.
Definition: TOPPASScene.h:141
OpenMS::FakeProcess::start
virtual void start(const QString &program, const QStringList &arguments, OpenMode mode=ReadWrite)
QObject
OpenMS::TOPPASScene::tmp_path_
QString tmp_path_
The path for temporary files.
Definition: TOPPASScene.h:339
OpenMS::TOPPASScene::RefreshStatus
RefreshStatus
Pipeline status after refreshParameters() was called.
Definition: TOPPASScene.h:123
OpenMS::TOPPASScene::changed_
bool changed_
Flag that indicates if the pipeline has been changed since the last save.
Definition: TOPPASScene.h:345
TOPPASEdge.h
OpenMS::TOPPASScene::edges_
EdgeContainer edges_
The list of all edges.
Definition: TOPPASScene.h:331
OpenMS::TOPPASScene::threads_active_
int threads_active_
currently running processes...
Definition: TOPPASScene.h:359
OpenMS::TOPPASScene::ST_REFRESH_CHANGED
some parameters were updated, but pipeline is ok
Definition: TOPPASScene.h:126
OpenMS::TOPPASScene::topp_processes_queue_
QList< TOPPProcess > topp_processes_queue_
The queue of pending TOPP processes.
Definition: TOPPASScene.h:353
OpenMS::TOPPASScene::vertices_
VertexContainer vertices_
The list of all vertices.
Definition: TOPPASScene.h:329
OpenMS::TOPPASScene::clipboard_
TOPPASScene * clipboard_
Stores the clipboard content when requested from TOPPASBase.
Definition: TOPPASScene.h:355
OpenMS::TOPPASScene
A container for all visual items of a TOPPAS workflow.
Definition: TOPPASScene.h:85
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::TOPPASToolVertex
A vertex representing a TOPP tool.
Definition: TOPPASToolVertex.h:59
OpenMS::TOPPASScene::TOPPProcess::args
QStringList args
The arguments.
Definition: TOPPASScene.h:109
OpenMS::TOPPASScene::dry_run_
bool dry_run_
dry run mode (no tools are actually called)
Definition: TOPPASScene.h:357
OpenMS::TOPPASScene::AM_NEW_EDGE
Definition: TOPPASScene.h:117
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::TOPPASScene::TOPPProcess::TOPPProcess
TOPPProcess(QProcess *p, const QString &cmd, const QStringList &arg, TOPPASToolVertex *const tool)
Constructor.
Definition: TOPPASScene.h:96
OpenMS::TOPPASScene::running_
bool running_
Indicates if a pipeline is currently running.
Definition: TOPPASScene.h:347
OpenMS::TOPPASScene::VertexContainer
QList< TOPPASVertex * > VertexContainer
The container for vertices.
Definition: TOPPASScene.h:139
TOPPASToolVertex.h
OpenMS::TOPPASScene::ConstVertexIterator
VertexContainer::const_iterator ConstVertexIterator
A const iterator for vertices.
Definition: TOPPASScene.h:143
OpenMS::TOPPASScene::ST_REFRESH_NOCHANGE
no updates required
Definition: TOPPASScene.h:125
QProcess
OpenMS::TOPPASScene::hover_edge_
TOPPASEdge * hover_edge_
The hovering edge which is currently being created.
Definition: TOPPASScene.h:333
OpenMS::TOPPASScene::TOPPProcess::proc
QProcess * proc
The process.
Definition: TOPPASScene.h:105
OpenMS::FakeProcess
A FakeProcess class.
Definition: TOPPASScene.h:59
OpenMS::TOPPASScene::ActionMode
ActionMode
The current action mode (creation of a new edge, or panning of the widget)
Definition: TOPPASScene.h:115
OpenMS::TOPPASScene::EdgeIterator
EdgeContainer::iterator EdgeIterator
A mutable iterator for edges.
Definition: TOPPASScene.h:135
OpenMS::TOPPASResources
A dictionary mapping string keys to lists of TOPPASResource objects.
Definition: TOPPASResources.h:55
OpenMS::TOPPASScene::file_name_
String file_name_
The file name of this pipeline.
Definition: TOPPASScene.h:337
OpenMS::TOPPASScene::allowed_threads_
int allowed_threads_
maximum number of allowed threads
Definition: TOPPASScene.h:363
QGraphicsScene
OpenMS::TOPPASScene::gui_
bool gui_
Are we in a GUI or is the scene used by ExecutePipeline (at the command line)?
Definition: TOPPASScene.h:341
OpenMS::TOPPASVertex
The base class of the different vertex classes.
Definition: TOPPASVertex.h:101
OpenMS::TOPPASMergerVertex
A special vertex that allows to merge several inputs.
Definition: TOPPASMergerVertex.h:58
OpenMS::TOPPASScene::user_specified_out_dir_
bool user_specified_out_dir_
Indicates if the output directory has been specified by the user already.
Definition: TOPPASScene.h:351
OpenMS::TOPPASScene::error_occured_
bool error_occured_
true if an error occurred during pipeline execution
Definition: TOPPASScene.h:349
OpenMS::TOPPASScene::out_dir_
QString out_dir_
The directory where the output files will be written.
Definition: TOPPASScene.h:343
OpenMS::TOPPASOutputFileListVertex
A vertex representing an output file list.
Definition: TOPPASOutputFileListVertex.h:49
String.h
OpenMS::TOPPASScene::EdgeContainer
QList< TOPPASEdge * > EdgeContainer
The container for edges.
Definition: TOPPASScene.h:133
OpenMS::TOPPASScene::TOPPProcess::command
QString command
The command.
Definition: TOPPASScene.h:107
OpenMS::TOPPASEdge
An edge representing a data flow in TOPPAS.
Definition: TOPPASEdge.h:59
OpenMS::TOPPASScene::TOPPProcess
Stores the information for a TOPP process.
Definition: TOPPASScene.h:93
OpenMS::TOPPASScene::action_mode_
ActionMode action_mode_
The current action mode.
Definition: TOPPASScene.h:327
OpenMS::TOPPASScene::TOPPProcess::tv
TOPPASToolVertex * tv
The tool which is started (used to call its slots)
Definition: TOPPASScene.h:111
OpenMS::TOPPASScene::resume_source_
TOPPASToolVertex * resume_source_
last node where 'resume' was started
Definition: TOPPASScene.h:365
OpenMS::TOPPASScene::ST_REFRESH_CHANGEINVALID
updating made pipeline invalid
Definition: TOPPASScene.h:127
OpenMS::TOPPASScene::potential_target_
TOPPASVertex * potential_target_
The current potential target vertex of the hovering edge.
Definition: TOPPASScene.h:335
OpenMS::TOPPASScene::ConstEdgeIterator
EdgeContainer::const_iterator ConstEdgeIterator
A const iterator for edges.
Definition: TOPPASScene.h:137
OpenMS::TOPPASScene::description_text_
QString description_text_
description text
Definition: TOPPASScene.h:361