Project

General

Profile

Statistics
| Branch: | Revision:

root / src / layout / concentrictreeembedding.cc @ 8aeaaccc

History | View | Annotate | Download (1.55 KB)

1
//=========================================================================
2
//  CONCENTRICTREEEMBEDDING.CC - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Levente Meszaros
7
//
8
//=========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#include "concentrictreeembedding.h"
18

    
19
USING_NAMESPACE
20

    
21
ConcentricTreeEmbedding::ConcentricTreeEmbedding(GraphComponent *graphComponent, double vertexSpacing)
22
{
23
    this->graphComponent = graphComponent;
24
    this->vertexSpacing = vertexSpacing;
25
}
26

    
27
void ConcentricTreeEmbedding::embed()
28
{
29
    calculateCenterRecursive(graphComponent->spanningTreeRoot, 0);
30
}
31

    
32
void ConcentricTreeEmbedding::calculateCenterRecursive(Vertex *vertex, int level)
33
{
34
    // TODO: finish this quick hack and really embed in concentric circles
35
    if (levelPositions.size() == level)
36
        levelPositions.insert(levelPositions.end(), 0);
37
    double levelPosition = levelPositions[level];
38
    vertex->rc.pt.x = levelPosition;
39
    vertex->rc.pt.y = level * 100;
40
    levelPositions[level] += vertex->rc.rs.width + vertexSpacing;
41
    for (std::vector<Vertex *>::iterator it = vertex->spanningTreeChildren.begin(); it != vertex->spanningTreeChildren.end(); it++)
42
        calculateCenterRecursive(*it, level + 1);
43
}