Project

General

Profile

Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (5.89 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  FORCEDIRECTEDGRAPHLAYOUTER.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 __FORCEDIRECTEDGRAPHLAYOUTER_H
18
#define __FORCEDIRECTEDGRAPHLAYOUTER_H
19
20
#include <vector>
21
#include <map>
22
23
#include "graphlayouter.h"
24
#include "forcedirectedembedding.h"
25
#include "forcedirectedparameters.h"
26
#include "graphcomponent.h"
27
28
NAMESPACE_BEGIN
29
30
31
/**
32
 * XXX
33
 */
34
class LAYOUT_API ForceDirectedGraphLayouter : public GraphLayouter
35
{
36
  protected:
37
    /**
38
     * Time to wait after drawing the actual state of the layouting process.
39
     */
40
    double debugWaitTime;
41
42
    /**
43
     * True means all forces will be shown in debug window.
44
     */
45
    bool showForces;
46
47
    /**
48
     * True means summa force will be shown in debug window.
49
     */
50
    bool showSummaForce;
51
52
    /**
53
     * True means there is at least one movable node.
54
     */
55
    bool hasMovableNode;
56
57
    /**
58
     * True means there is at least one fixed node.
59
     */
60
    bool hasFixedNode;
61
62
    /**
63
     * True means there is at least one anchored node.
64
     */
65
    bool hasAnchoredNode;
66
67
    /**
68
     * True means there is at least one edge to the border.
69
     */
70
    bool hasEdgeToBorder;
71
72
    /**
73
     * Use pre embedding to create an initial layout before calling the force directed embedding.
74
     */
75
    bool preEmbedding;
76
77
    /**
78
     * Use force directed embedding.
79
     */
80
    bool forceDirectedEmbedding;
81
82
    /**
83
     * Use 3d coordinates and return the base plane projection coordinates.
84
     * Add springs connected to the base plane.
85
     * 0 means do not use 3d coordinates. Higher value means bigger initial 3d coordinates.
86
     */
87
    double threeDFactor;
88
    double threeDCoefficient;
89
90
    /**
91
     * Various measures calculated before the actual layout.
92
     */
93
    double expectedEmbeddingWidth;
94
    double expectedEmbeddingHeight;
95
    double expectedEdgeLength;
96
    bool slippery;
97
    bool pointLikeDistance;
98
99
    // border bodies will be added if there are either
100
    // fixed nodes or edges connected to the border
101
    // or the width or the height of the bounding box is specified
102
    WallBody *topBorder;
103
    WallBody *bottomBorder;
104
    WallBody *leftBorder;
105
    WallBody *rightBorder;
106
107
    GraphComponent graphComponent;
108
    ForceDirectedEmbedding embedding;
109
110
    std::map<std::string, Variable *> anchorNameToVariableMap;
111
    std::map<cModule *, IBody *> moduleToBodyMap;
112
113
  public:
114
    /**
115
     * Ctor, dtor
116
     */
117
    //@{
118
    ForceDirectedGraphLayouter();
119
    virtual ~ForceDirectedGraphLayouter() {}
120
    //@}
121
122
    void setParameters();
123
124
    /**
125
     * Add node that can be moved.
126
     */
127
    virtual void addMovableNode(cModule *mod, int width, int height);
128
129
    /**
130
     * Add fixed node
131
     */
132
    virtual void addFixedNode(cModule *mod, int x, int y, int width, int height);
133
134
    /**
135
     * Add node that is anchored to a freely movable anchor point. Nodes anchored
136
     * to the same anchor point can only move together. Anchor points are
137
     * identified by name, and they need not be predeclared (they are registered
138
     * on demand.) Usage: module vectors in ring, matrix, etc. layout.
139
     *
140
     * offx, offy: offset to anchor point
141
     */
142
    virtual void addAnchoredNode(cModule *mod, const char *anchorname, int offx, int offy, int width, int height);
143
144
    /**
145
     * Add connection (graph edge)
146
     */
147
    virtual void addEdge(cModule *from, cModule *to, int len=0);
148
149
    /**
150
     * Add connection (graph edge) to enclosing (parent) module
151
     */
152
    virtual void addEdgeToBorder(cModule *from, int len=0);
153
154
    /**
155
     * The layouting algorithm.
156
     */
157
    virtual void execute();
158
159
    /**
160
     * Extracting the results
161
     */
162
    virtual void getNodePosition(cModule *mod, int& x, int& y);
163
164
  protected:
165
    void addBody(cModule *mod, IBody *body);
166
    IBody *findBody(cModule *mod);
167
    Variable *ensureAnchorVariable(const char *anchorname);
168
169
    /**
170
     * Adds electric repulsions between bodies. Bodies being part of different connected
171
     * subcomponents will have a finite repulsion range determined by default spring repose length.
172
     */
173
    void addElectricRepulsions();
174
175
    /**
176
     * Adds springs generating attraction forces.
177
     */
178
    void addBasePlaneSprings();
179
180
    /**
181
     * Calculate various expected embedding measures such as width, height, edge length.
182
     */
183
    void calculateExpectedMeasures();
184
185
    /**
186
     * Assigns positions to coordinates not yet assigned by some other means.
187
     * The size of the random range is determined by the total size of the bodies
188
     * and the default spring repose length.
189
     */
190
    void setRandomPositions();
191
192
    /**
193
     * Executes pre embedding, it always takes into consideration the bounding box.
194
     */
195
    void executePreEmbedding();
196
197
    /**
198
     * Adds border bodies to the force directed embedding.
199
     * Adds springs between left-right and top-bottom walls and electric repulsions to other bodies.
200
     */
201
    void ensureBorders();
202
    void addBorderForceProviders();
203
204
    /**
205
     * Assigns positions to border bodies so that all other bodies are within.
206
     */
207
    void setBorderPositions();
208
209
    /**
210
     * Returns the bounding box of the embedding and the size of bigest right and bottom vertex.
211
     */
212
    Rc getBoundingBox(Rs &rs);
213
214
    /**
215
     * Scale coordinates.
216
     */
217
    void scale(Pt pt);
218
219
    /**
220
     * Translates coordinates.
221
     */
222
    void translate(Pt pt);
223
224
    /**
225
     * Draws the current state of the layout to a window.
226
     */
227
    void debugDraw();
228
};
229
230
NAMESPACE_END
231
232
233
#endif
234