0.3.1
[qanava.git] / src / qanSimpleLayout.cpp
bloba8e0d2978849894b8237a099eabdb7567c0b146e
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 qanSimpleLayout.cpp
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2006 January 06
26 //-----------------------------------------------------------------------------
29 // Qanava headers
30 #include "./qanSimpleLayout.h"
33 namespace qan { // ::qan
36 /* Concentric Layout Management *///-------------------------------------------
37 void Concentric::layout( Graph& graph, QGraphicsScene* scene, QRectF r, QProgressDialog* progress, int step )
39 // Configure the progress monitor
40 if ( progress != 0 )
42 progress->setMaximum( graph.getNodeCount( ) );
43 progress->setValue( 0 );
46 QPointF center = r.center( );
47 int nodesPerCircle = ( int )( 360. / _azimutDelta );
48 Node::List::iterator nodeIter = graph.getNodes( ).begin( );
49 for ( int n = 0; n < ( int )graph.getNodes( ).size( ); n++, nodeIter++ )
51 Node& node = **nodeIter;
52 double azimutIndex = ( n % nodesPerCircle );
53 double azimut = azimutIndex * _azimutDelta;
55 int circleIndex = 1 + ( n / nodesPerCircle );
56 double cx = sin( azimut * 3.14156 / 180. ) * ( circleIndex * _circleInterval );
57 double cy = cos( azimut * 3.14156 / 180. ) * ( circleIndex * _circleInterval );
59 node.getPosition( )( 0 ) = center.x( ) + cx;
60 node.getPosition( )( 1 ) = center.y( ) + cy;
61 if ( progress != 0 )
62 progress->setValue( n );
64 if ( progress != 0 )
65 progress->close( );
67 //-----------------------------------------------------------------------------
71 /* Colimacon Layout Management *///--------------------------------------------
72 void Colimacon::layout( Graph& graph, QGraphicsScene* scene, QRectF r, QProgressDialog* progress, int step )
74 // Configure the progress monitor
75 if ( progress != 0 )
77 progress->setMaximum( graph.getNodeCount( ) );
78 progress->setValue( 0 );
81 QPointF center = r.center( );
82 int nodesPerCircle = ( int )( 360. / _azimutDelta );
83 Node::List::iterator nodeIter = graph.getNodes( ).begin( );
84 for ( int n = 0; n < ( int )graph.getNodes( ).size( ); n++, nodeIter++ )
86 Node& node = **nodeIter;
87 //double azimutIndex = ( double )( n % nodesPerCircle );
88 double azimut = n * _azimutDelta;
90 //int circleIndex = 1 + ( int )( n / nodesPerCircle );
91 double cx = sin( azimut * 3.14156 / 180. ) * ( log( 1. + n ) * 10 * _circleInterval );
92 double cy = cos( azimut * 3.14156 / 180. ) * ( log( 1. + n ) * 10 * _circleInterval );
94 node.getPosition( )( 0 ) = center.x( ) + cx;
95 node.getPosition( )( 1 ) = center.y( ) + cy;
97 if ( progress != 0 )
98 progress->setValue( n );
100 if ( progress != 0 )
101 progress->close( );
103 //-----------------------------------------------------------------------------
106 } // ::qan