Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

TOPPASVertex.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Johannes Junker $
00032 // $Authors: Johannes Junker, Chris Bielow $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_VISUAL_TOPPASVERTEX_H
00036 #define OPENMS_VISUAL_TOPPASVERTEX_H
00037 
00038 // ------------- DEBUGGING ----------------
00039 
00040 // ---- Uncomment to enable debug mode ----
00041 //#define TOPPAS_DEBUG
00042 // ----------------------------------------
00043 
00044 #ifdef TOPPAS_DEBUG
00045 #define __DEBUG_BEGIN_METHOD__ \
00046   {                                                                                                                                                                                   \
00047     for (int dbg_indnt_cntr = 0; dbg_indnt_cntr < global_debug_indent_; ++dbg_indnt_cntr)   \
00048     {                                                                                                                                                                           \
00049       std::cout << "  ";                                                                                                                                  \
00050     }                                                                                                                                                                           \
00051     std::cout << "BEGIN [" << topo_nr_ << "] " << __PRETTY_FUNCTION__ << std::endl;             \
00052     ++global_debug_indent_;                                                                                                                             \
00053   }
00054 
00055 #define __DEBUG_END_METHOD__ \
00056   {                                                                                                                                                                                       \
00057     --global_debug_indent_;                                                                                                                             \
00058     if (global_debug_indent_ < 0) global_debug_indent_ = 0;                                                             \
00059     for (int dbg_indnt_cntr = 0; dbg_indnt_cntr < global_debug_indent_; ++dbg_indnt_cntr)   \
00060     {                                                                                                                                                                           \
00061       std::cout << "  ";                                                                                                                                  \
00062     }                                                                                                                                                                           \
00063     std::cout << "END [" << topo_nr_ << "] " << __PRETTY_FUNCTION__ << std::endl;                   \
00064   }
00065 #else
00066 #define __DEBUG_BEGIN_METHOD__ {}
00067 #define __DEBUG_END_METHOD__ {}
00068 #endif
00069 
00070 // ----------------------------------------
00071 
00072 #include <OpenMS/DATASTRUCTURES/String.h>
00073 #include <OpenMS/DATASTRUCTURES/Map.h>
00074 
00075 #include <QtGui/QPainter>
00076 #include <QtGui/QPainterPath>
00077 #include <QtGui/QGraphicsSceneMouseEvent>
00078 #include <QtGui/QGraphicsSceneContextMenuEvent>
00079 #include <QtGui/QGraphicsItem>
00080 #include <QtCore/QProcess>
00081 #include <QtGui/QMenu>
00082 
00083 namespace OpenMS
00084 {
00085   class TOPPASEdge;
00086 
00098   class OPENMS_GUI_DLLAPI TOPPASVertex :
00099     public QObject,
00100     public QGraphicsItem
00101   {
00102     Q_OBJECT
00103     //Q_INTERFACES(QGraphicsItem)  // works only >Qt4.6
00104 
00105 public:
00106 
00108     typedef QList<TOPPASEdge *> EdgeContainer;
00110     typedef EdgeContainer::iterator EdgeIterator;
00112     typedef EdgeContainer::const_iterator ConstEdgeIterator;
00114     struct VertexRoundPackage
00115     {
00116       VertexRoundPackage() :
00117         filenames(),
00118         edge(0)
00119       {
00120       }
00121 
00122       QStringList filenames;   //< filenames passed from upstream node in this round
00123       TOPPASEdge * edge;  //< edge that connects the upstream node to the current one
00124     };
00125 
00130     typedef std::map<Int, VertexRoundPackage> RoundPackage;
00131     typedef RoundPackage::const_iterator RoundPackageConstIt;
00132     typedef RoundPackage::iterator RoundPackageIt;
00133 
00135     typedef std::vector<RoundPackage> RoundPackages;
00136 
00138     enum DFS_COLOR
00139     {
00140       DFS_WHITE,
00141       DFS_GRAY,
00142       DFS_BLACK
00143     };
00144 
00146     enum SUBSTREESTATUS
00147     {
00148       TV_ALLFINISHED,  // all downstream nodes are done (including the ones which are feed by a parallel subtree)
00149       TV_UNFINISHED,   // some direct downstream node is not done
00150       TV_UNFINISHED_INBRANCH // a parallel subtree which merged with some downstream node A was not done (which prevented processing of the node A)
00151     };
00152 
00154     TOPPASVertex();
00156     TOPPASVertex(const TOPPASVertex & rhs);
00158     virtual ~TOPPASVertex();
00160     TOPPASVertex & operator=(const TOPPASVertex & rhs);
00161 
00165     bool buildRoundPackages(RoundPackages & pkg, String & error_msg);
00166 
00168     bool isUpstreamFinished() const;
00169 
00171     virtual QRectF boundingRect() const = 0;
00173     virtual QPainterPath shape() const = 0;
00175     virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) = 0;
00177     ConstEdgeIterator outEdgesBegin() const;
00179     ConstEdgeIterator outEdgesEnd() const;
00181     ConstEdgeIterator inEdgesBegin() const;
00183     ConstEdgeIterator inEdgesEnd() const;
00185     Size incomingEdgesCount();
00187     Size outgoingEdgesCount();
00189     void addInEdge(TOPPASEdge * edge);
00191     void addOutEdge(TOPPASEdge * edge);
00193     void removeInEdge(TOPPASEdge * edge);
00195     void removeOutEdge(TOPPASEdge * edge);
00197     DFS_COLOR getDFSColor();
00199     void setDFSColor(DFS_COLOR color);
00201     TOPPASVertex * getDFSParent();
00203     void setDFSParent(TOPPASVertex * parent);
00205     TOPPASVertex::SUBSTREESTATUS getSubtreeStatus() const;
00207     bool isTopoSortMarked();
00209     void setTopoSortMarked(bool b);
00211     UInt getTopoNr();
00213     virtual void setTopoNr(UInt nr);
00215     virtual void reset(bool reset_all_files = false);
00217     virtual void markUnreachable();
00219     bool isReachable();
00221     bool isFinished() const;
00224     virtual void run();
00226     virtual bool invertRecylingMode();
00228     bool isRecyclingEnabled() const;
00230     void setRecycling(const bool is_enabled);
00231 
00232     // get the name of the vertex (to be overridden by derived classes)
00233     virtual String getName() const = 0;
00234 
00240     QStringList getFileNames(int param_index, int round) const;
00241 
00243     QStringList getFileNames() const;
00244 
00245     // get the output structure directly
00246     const RoundPackages & getOutputFiles() const;
00247 
00248 
00250     bool allInputsReady();
00251 
00252 
00253 public slots:
00254 
00256     virtual void inEdgeHasChanged();
00258     virtual void outEdgeHasChanged();
00259 
00260 signals:
00261 
00263     void clicked();
00265     void released();
00267     void hoveringEdgePosChanged(const QPointF & new_pos);
00269     void newHoveringEdge(const QPointF & pos);
00271     void finishHoveringEdge();
00273     void somethingHasChanged();
00275     void itemDragged(qreal dx, qreal dy);
00278     void parameterChanged(const bool invalidates_running_pipeline);
00279 
00280 protected:
00281 
00283     EdgeContainer in_edges_;
00285     EdgeContainer out_edges_;
00287     bool edge_being_created_;
00289     QColor pen_color_;
00291     QColor brush_color_;
00293     DFS_COLOR dfs_color_;
00295     TOPPASVertex * dfs_parent_;
00297     bool topo_sort_marked_;
00299     UInt topo_nr_;
00301     RoundPackages output_files_;
00303     int round_total_;
00305     int round_counter_;
00307     bool finished_;
00309     bool reachable_;
00311     bool allow_output_recycling_;
00312 
00313 
00314 #ifdef TOPPAS_DEBUG
00315     // Indentation level for nicer debug output
00316     static int global_debug_indent_;
00317 #endif
00318 
00320 
00321     void mouseReleaseEvent(QGraphicsSceneMouseEvent * e);
00322     void mousePressEvent(QGraphicsSceneMouseEvent * e);
00323     void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * e);
00324     void mouseMoveEvent(QGraphicsSceneMouseEvent * e);
00325     void contextMenuEvent(QGraphicsSceneContextMenuEvent * event);
00327 
00329     virtual void moveNewEdgeTo_(const QPointF & pos);
00331     String get3CharsNumber_(UInt number) const;
00332 
00334     void debugOut_(const String &
00335 #ifdef TOPPAS_DEBUG
00336                    message
00337 #endif
00338                    ) const
00339     {
00340 #ifdef TOPPAS_DEBUG
00341       for (int i = 0; i < global_debug_indent_; ++i)
00342       {
00343         std::cout << "  ";
00344       }
00345       std::cout << "[" << topo_nr_ << "] " << message << std::endl;
00346 #endif
00347     }
00348 
00349   };
00350 }
00351 
00352 #endif

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:45 using doxygen 1.7.1