Project

General

Profile

Statistics
| Branch: | Revision:

root / src / layout / graphlayouter.h @ 8aeaaccc

History | View | Annotate | Download (4.4 KB)

1
//==========================================================================
2
//  GRAPHLAYOUTER.H - 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
#ifndef __GRAPHLAYOUTER_H
18
#define __GRAPHLAYOUTER_H
19

    
20
#include "layoutdefs.h"
21
#include "lcgrandom.h"
22

    
23
NAMESPACE_BEGIN
24

    
25
class cModule;
26

    
27
/**
28
 * Allows drawing during layouting for debug purposes, and makes it possible to
29
 * stop the layouter if it's taking too long.
30
 */
31
class LAYOUT_API GraphLayouterEnvironment
32
{
33
    public:
34
        virtual ~GraphLayouterEnvironment() {}
35
        virtual bool inspected() = 0;
36
        virtual bool okToProceed() = 0;  // should return false if layouting is taking too long
37

    
38
        virtual bool getBoolParameter(const char *tagName, int index, bool defaultValue) = 0;
39
        virtual long getLongParameter(const char *tagName, int index, long defaultValue) = 0;
40
        virtual double getDoubleParameter(const char *tagName, int index, double defaultValue) = 0;
41

    
42
        virtual void clearGraphics() = 0;
43
        virtual void showGraphics(const char *text) = 0;
44
        virtual void drawText(double x, double y, const char *text, const char *tags, const char *color) = 0;
45
        virtual void drawLine(double x1, double y1, double x2, double y2, const char *tags, const char *color) = 0;
46
        virtual void drawRectangle(double x1, double y1, double x2, double y2, const char *tags, const char *color) = 0;
47
};
48

    
49
/**
50
 * Abstract base class for graph layouting algorithms.
51
 */
52
class LAYOUT_API GraphLayouter
53
{
54
  protected:
55
    LCGRandom lcgRandom;
56

    
57
    GraphLayouterEnvironment *environment;
58

    
59
    int width, height;  // ==0 means unspecified
60
    int border;
61

    
62
    double privRand01() { return lcgRandom.next01(); }
63
    double privUniform(double a, double b) { return a + privRand01() * (b - a); }
64

    
65
  public:
66
    /**
67
     * Ctor, dtor
68
     */
69
    //@{
70
    GraphLayouter();
71
    virtual ~GraphLayouter() {}
72
    //@}
73

    
74
    /**
75
     * Add node that can be moved.
76
     */
77
    virtual void addMovableNode(cModule *mod, int width, int height) = 0;
78

    
79
    /**
80
     * Add fixed node. (x,y) denotes the center of the node.
81
     */
82
    virtual void addFixedNode(cModule *mod, int x, int y, int width, int height) = 0;
83

    
84
    /**
85
     * Add node that is anchored to a freely movable anchor point. Nodes anchored
86
     * to the same anchor point can only move together. Anchor points are
87
     * identified by name, and they need not be predeclared (they are registered
88
     * on demand.) Usage: module vectors in ring, matrix, etc. layout.
89
     *
90
     * offx, offy: offset of the node center to the anchor point
91
     */
92
    virtual void addAnchoredNode(cModule *mod, const char *anchorname, int offx, int offy, int width, int height) = 0;
93

    
94
    /**
95
     * Add connection (graph edge). len is the preferred length (0==unspecified)
96
     */
97
    virtual void addEdge(cModule *from, cModule *to, int len=0) = 0;
98

    
99
    /**
100
     * Add connection (graph edge) to enclosing (parent) module. len is the
101
     * preferred length (0==unspecified)
102
     */
103
    virtual void addEdgeToBorder(cModule *from, int len=0) = 0;
104

    
105
    /**
106
     * Set parameters
107
     */
108
    //@{
109
    virtual void setEnvironment(GraphLayouterEnvironment *environment) {this->environment = environment;}
110

    
111
    /**
112
     * Set the random number seed used by the algorithm. The layouter has its
113
     * own RNG, i.e. does not use the simulation kernel's RNGs. The same seed
114
     * and same input results in the same layout.
115
     */
116
    void setSeed(int32 seed) { lcgRandom.setSeed(seed);}
117

    
118
    /**
119
     * Return the seed value
120
     */
121
    int32 getSeed() { return lcgRandom.getSeed(); }
122

    
123
    /**
124
     * Sets the size of the enclosing module. A zero width or height means
125
     * unspecified value.
126
     */
127
    void setSize(int width, int height, int border);
128
    //@}
129

    
130
    /**
131
     * The layouting algorithm.
132
     */
133
    virtual void execute() = 0;
134

    
135
    /**
136
     * Extracting the results. The returned position is the center of the module.
137
     */
138
    virtual void getNodePosition(cModule *mod, int& x, int& y) = 0;
139
};
140

    
141
NAMESPACE_END
142

    
143

    
144
#endif
145

    
146

    
147