0.3.1
[qanava.git] / src / qanLayout.h
blobb13b32583a84fcdbe7550b1791027172dd61e963
1 /*
2 Qanava - Graph drawing library for QT
3 Copyright (C) 2006 Benoit AUTHEMAN
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //-----------------------------------------------------------------------------
21 // This file is a part of the Qanava software.
23 // \file qanLayout.h
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2004 May 22
26 //-----------------------------------------------------------------------------
29 #ifndef qanLayout_h
30 #define qanLayout_h
33 // Qanava headers
34 #include "./qanGraph.h"
35 #include "./qanGridItem.h"
38 // STD headers
39 #include <vector>
42 // QT headers
43 #include <QRectF>
44 #include <QProgressDialog>
47 //-----------------------------------------------------------------------------
48 namespace qan { // ::qan
50 //! Abstract interface defining a graph layout algorithm (placement of node in space).
51 /*!
52 \nosubgrouping
54 class Layout
56 public:
58 /*! \name Layout Constructor/Destructor *///---------------------------
59 //@{
60 //! Layout constructor.
61 Layout( ) { }
63 //! Layout virtual destructor.
64 virtual ~Layout( ) { }
66 private:
68 Layout( const Layout& l );
69 //@}
70 //---------------------------------------------------------------------
74 /*! \name Layout Generation Management *///----------------------------
75 //@{
76 public:
78 //! Layout nodes from a given graph using r as a clipping rect, and update grid.
79 virtual void layout( Graph& graph, QGraphicsScene* scene,
80 QRectF r, QProgressDialog* progress = 0, int step = -1 ) = 0;
82 protected:
84 //! Reset all nodes positions.
85 static void resetNodesPositions( Graph& graph );
86 //@}
87 //---------------------------------------------------------------------
92 //! Randomly layout an undirected graph.
93 /*!
94 \nosubgrouping
96 class Random : public Layout
98 /*! \name Random Constructor/Destructor *///---------------------------
99 //@{
100 public:
102 //! Random constructor.
103 Random( ) : Layout( ) { }
104 //@}
105 //---------------------------------------------------------------------
109 /*! \name Random Layout Generation Management *///---------------------
110 //@{
111 public:
113 //! .
114 virtual void layout( Graph& graph, QGraphicsScene* scene,
115 QRectF r, QProgressDialog* progress = 0, int step = -1 );
116 //@}
117 //---------------------------------------------------------------------
122 //! Layout an undirected graph using a spring force algorithm.
124 \nosubgrouping
126 class UndirectedGraph : public Layout
128 /*! \name UndirectedGraph Constructor/Destructor *///------------------
129 //@{
130 public:
132 //! UndirectedGraph constructor.
133 UndirectedGraph( ) : Layout( ), _center( "" ) { }
134 //@}
135 //---------------------------------------------------------------------
139 /*! \name Force Layout Generation Management *///----------------------
140 //@{
141 public:
143 //! Layout 'graph' using a spring force algorithm.
144 virtual void layout( Graph& graph, QGraphicsScene* scene,
145 QRectF r, QProgressDialog* progress = 0, int step = -1 );
147 static void add( VectorF& a, const VectorF& b );
149 static void scale( VectorF& p, float scale );
151 static VectorF vector( VectorF a, VectorF b );
153 static float length( const VectorF& v );
155 static float length2( const VectorF& v );
157 private:
159 VectorF computeRepulseForce( Node& node, Node::Set& adjacentNodes, Node::Set& nodes, Graph& graph );
161 VectorF computeSpringForce( Node& node, Node::Set& adjacentNodes, Graph& graph );
163 Node _center;
164 //@}
165 //---------------------------------------------------------------------
167 } // ::qan
168 //-----------------------------------------------------------------------------
171 #endif // qanLayout_h