2 Qanava - Graph drawing library for QT
3 Copyright (C) 2005 Benoit AUTHEMAN
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; 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 (authem_b@epita.fr)
25 // \date 2004 February 15
26 //-----------------------------------------------------------------------------
41 #include "boost/date_time/posix_time/posix_time.hpp"
45 namespace qan
{ // ::qan
46 namespace la
{ // ::qan::la
49 /* Node Constructor/Destructor *///--------------------------------------------
50 Node::Node( const std::string
& label
) :
58 setPosition( -1.f
, -1.f
);
59 setDimension( -1.f
, -1.f
);
62 Node::Node( const std::string
& label
, int type
) :
70 setPosition( -1.f
, -1.f
);
71 setDimension( -1.f
, -1.f
);
73 //-----------------------------------------------------------------------------
77 /* Node Edges Management *///--------------------------------------------------
78 const Node::Nodes
& Node::getOutNodes( ) const
83 Node::NodesSet
* Node::getOutNodesSet( )
85 NodesSet
* outNodeSet
= new NodesSet( );
87 // Add all edge destination to the out nodes set
88 Edge::Edges
& edges
= getOutEdges( );
89 Edge::Edges::iterator edgeIter
= edges
.begin( );
90 for ( ; edgeIter
!= edges
.end( ); edgeIter
++ )
92 Edge
* edge
= *edgeIter
;
93 outNodeSet
->insert( &( edge
->getDst( ) ) );
99 Node::NodesSet
* Node::getInNodesSet( )
101 NodesSet
* inNodeSet
= new NodesSet( );
103 // Add all edge destination to the out nodes set
104 Edge::Edges
& edges
= getInEdges( );
105 Edge::Edges::iterator edgeIter
= edges
.begin( );
106 for ( ; edgeIter
!= edges
.end( ); edgeIter
++ )
108 Edge
* edge
= *edgeIter
;
109 inNodeSet
->insert( &( edge
->getSrc( ) ) );
115 Node::NodesSet
* Node::getAdjacentNodesSet( )
117 NodesSet
* outNodes
= getOutNodesSet( );
118 NodesSet
* inNodes
= getInNodesSet( );
120 NodesSet
& adjacentNodes
= *new NodesSet( );
121 std::set_union( outNodes
->begin( ), outNodes
->end( ),
122 inNodes
->begin( ), inNodes
->end( ),
123 std::insert_iterator
< NodesSet
>( adjacentNodes
, adjacentNodes
.begin( ) ) );
128 return &adjacentNodes
;
131 Node::NodesSet
* Node::getNonAdjacentNodesSet( la::Graph
& graph
)
133 NodesSet
* adjacentNodes
= getAdjacentNodesSet( );
134 NodesSet
* graphNodes
= graph
.getNodesSet( );
136 NodesSet
& nonAdjacentNodes
= *new NodesSet( );
137 std::set_difference( graphNodes
->begin( ), graphNodes
->end( ),
138 adjacentNodes
->begin( ), adjacentNodes
->end( ),
139 std::insert_iterator
< NodesSet
>( nonAdjacentNodes
, nonAdjacentNodes
.begin( ) ) );
141 // Remove the node idself from to non adjacent nodes list
142 nonAdjacentNodes
.erase( this );
144 delete adjacentNodes
;
147 return &nonAdjacentNodes
;
149 //-----------------------------------------------------------------------------
153 /* Node Attributes Management *///---------------------------------------------
154 void Node::setDate( const std::string
& date
)
158 _date
= new boost::posix_time::ptime( boost::posix_time::time_from_string( date
) );
159 } catch( std::exception
& e
)
166 //-----------------------------------------------------------------------------