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.
24 // \author Benoit Autheman (benoit@libqanava.org)
26 //-----------------------------------------------------------------------------
34 #include "./qanGraph.h"
35 #include "./qanGridItem.h"
44 #include <QProgressDialog>
47 //-----------------------------------------------------------------------------
48 namespace qan
{ // ::qan
50 //! Abstract interface defining a graph layout algorithm (placement of node in space).
58 /*! \name Layout Constructor/Destructor *///---------------------------
60 //! Layout constructor.
63 //! Layout virtual destructor.
64 virtual ~Layout( ) { }
68 Layout( const Layout
& l
);
70 //---------------------------------------------------------------------
74 /*! \name Layout Generation Management *///----------------------------
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;
84 //! Reset all nodes positions.
85 static void resetNodesPositions( Graph
& graph
);
87 //---------------------------------------------------------------------
92 //! Randomly layout an undirected graph.
96 class Random
: public Layout
98 /*! \name Random Constructor/Destructor *///---------------------------
102 //! Random constructor.
103 Random( ) : Layout( ) { }
105 //---------------------------------------------------------------------
109 /*! \name Random Layout Generation Management *///---------------------
114 virtual void layout( Graph
& graph
, QGraphicsScene
* scene
,
115 QRectF r
, QProgressDialog
* progress
= 0, int step
= -1 );
117 //---------------------------------------------------------------------
122 //! Layout an undirected graph using a spring force algorithm.
126 class UndirectedGraph
: public Layout
128 /*! \name UndirectedGraph Constructor/Destructor *///------------------
132 //! UndirectedGraph constructor.
133 UndirectedGraph( ) : Layout( ), _center( "" ) { }
135 //---------------------------------------------------------------------
139 /*! \name Force Layout Generation Management *///----------------------
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
);
159 VectorF
computeRepulseForce( Node
& node
, Node::Set
& adjacentNodes
, Node::Set
& nodes
, Graph
& graph
);
161 VectorF
computeSpringForce( Node
& node
, Node::Set
& adjacentNodes
, Graph
& graph
);
165 //---------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
171 #endif // qanLayout_h