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)
25 // \date 2004 February 15
26 //-----------------------------------------------------------------------------
34 #include "./qanEdge.h"
35 #include "./qanVectorf.h"
48 //-----------------------------------------------------------------------------
49 //! Root qanava namespace
50 namespace qan
{ // ::qan
52 //! Model a node in a standard weighted and directed graph.
56 class Node
: public AttrFunc
58 /*! \name Node Constructor/Destructor *///-------------------------
62 //! Node constructor with label initialisation.
63 Node( const QString
& label
);
65 //! Node constructor with label and type initialisation.
66 Node( const QString
& label
, int type
);
73 Node( const Node
& n
);
75 //-----------------------------------------------------------------
79 /*! \name Node Edges Management *///-------------------------------
83 //! Typedef for a QT list of pointer on Node.
84 typedef QList
< Node
* > List
;
86 //! Typedef for a QT set of pointer on Node.
87 typedef QSet
< Node
* > Set
;
89 //! Get a list of all nodes pointing to this node.
90 const Edge::List
& getInEdges( ) const { return _inEdges
; }
92 //! Get a list of all nodes pointing to this node.
93 Edge::List
& getInEdges( ) { return _inEdges
; }
95 //! Get a list of all node pointed by this node.
96 const Edge::List
& getOutEdges( ) const { return _outEdges
; }
98 //! Get a list of all node pointed by this node.
99 Edge::List
& getOutEdges( ) { return _outEdges
; }
101 //! Collect a list of this node sub nodes.
102 void collectOutNodes( Node::List
& outNodes
);
104 //! Collect a list of this node in nodes.
105 void collectInNodes( Node::List
& outNodes
);
107 //! Collect a set of unique nodes pointed by this node.
108 void collectOutNodesSet( Node::Set
& outNodes
) const;
110 //! Collect a set of unique nodes referencing this node.
111 void collectInNodesSet( Node::Set
& nodes
) const;
114 void addInEdge( Edge
& edge
) { _inEdges
<< &edge
; }
117 void addOutEdge( Edge
& edge
) { _outEdges
<< &edge
; }
119 //! Get node in degree.
120 unsigned int getInDegree( ) const { return _inEdges
.size( ); }
122 //! Get node out degree.
123 unsigned int getOutDegree( ) const { return _outEdges
.size( ); }
125 //! Get a list of nodes adjacent to this (all in and out nodes, without this).
126 void getAdjacentNodesSet( Node::Set
& nodes
) const;
128 //! Get a list of nodes non adjacent to this (all nodes minus the adjacent node set collected with getAdjacentNodesSet()).
129 void getNonAdjacentNodesSet( Node::Set
& nonAdjacentNodes
, const Node::Set
& graphNodes
) const;
131 //! Return true if this node is a "leaf" (ie has no out edges).
132 bool isLeaf( ) const { return _outEdges
.size( ) == 0; }
140 Edge::List _outEdges
;
142 //-----------------------------------------------------------------
146 /*! \name Node Property Management *///----------------------------
161 enum { StdAttributeCount
= 5 };
163 //! Get this node label.
164 const QString
& getLabel( ) const { return *getAttribute
< QString
>( Node::LABEL
); }
166 //! Set this node label.
167 void setLabel( const QString
& label
) { setAttribute
< QString
>( Node::LABEL
, label
); }
169 //! Set this node's user defined type.
170 void setType( int type
) { setAttribute
< int >( Node::TYPE
, type
); }
172 //! Get this node's user defined type.
173 int getType( ) const { return *getAttribute
< int >( Node::TYPE
); }
176 VectorF
& getPosition( ) { return *getAttribute
< VectorF
>( Node::POSITION
); }
179 const VectorF
& getPosition( ) const { return *getAttribute
< VectorF
>( Node::POSITION
); }
182 void setPosition( VectorF
& position
) { setAttribute
< VectorF
>( Node::POSITION
, position
); }
185 void setPosition( float x
, float y
)
187 VectorF
& position
= getPosition( );
188 position( 0 ) = x
; position( 1 ) = y
;
191 const VectorF
& getDimension( ) const { return *getAttribute
< VectorF
>( Node::DIMENSION
); }
193 void setDimension( const VectorF
& dimension
) { setAttribute
< VectorF
>( Node::DIMENSION
, dimension
); }
195 void setDimension( float x
, float y
)
197 VectorF
& dimension
= *getAttribute
< VectorF
>( Node::DIMENSION
);
198 dimension( 0 ) = x
; dimension( 1 ) = y
;
201 //! Set the node date from a text string with the Posix Time format (ex: 2002-Jan-01 10:00:01).
202 void setDate( const QString
& date
);
204 //! Return the node date under Posix Time format (0 if the date is undefined).
205 const QDateTime
* getDate( ) const { return getAttribute
< QDateTime
>( Node::DATE
); }
207 //-----------------------------------------------------------------
210 //-----------------------------------------------------------------------------