File: ClusterGraphAttributes.h

package info (click to toggle)
tulip 4.8.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 179,264 kB
  • ctags: 64,517
  • sloc: cpp: 600,444; ansic: 36,311; makefile: 22,136; python: 1,304; sh: 946; yacc: 522; xml: 337; pascal: 157; php: 66; lex: 55
file content (279 lines) | stat: -rw-r--r-- 8,395 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 * $Revision: 3521 $
 *
 * last checkin:
 *   $Author: gutwenger $
 *   $Date: 2013-05-31 14:52:33 +0200 (Fri, 31 May 2013) $
 ***************************************************************/

/** \file
 * \brief Declares ClusterGraphAttributes, an extension of class
 * GraphAttributes,  to store clustergraph layout informations
 * like cluster cage positions and sizes that can be accessed
 * over the cluster/cluster ID
 *
 * \author Karsten Klein, Carsten Gutwenger
 *
 * \par License:
 * This file is part of the Open Graph Drawing Framework (OGDF).
 *
 * \par
 * Copyright (C)<br>
 * See README.txt in the root directory of the OGDF installation for details.
 *
 * \par
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * Version 2 or 3 as published by the Free Software Foundation;
 * see the file LICENSE.txt included in the packaging of this file
 * for details.
 *
 * \par
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * \par
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * \see  http://www.gnu.org/copyleft/gpl.html
 ***************************************************************/

#ifdef _MSC_VER
#pragma once
#endif

#ifndef OGDF_CLUSTER_GRAPH_ATTRIBUTES_H
#define OGDF_CLUSTER_GRAPH_ATTRIBUTES_H


#include <ogdf/basic/GraphAttributes.h>
#include <ogdf/cluster/ClusterArray.h>


namespace ogdf {

	//! Stores information associated with a cluster.
	struct OGDF_EXPORT ClusterInfo
	{
		double m_x, m_y;	//!< position of lower left corner
		double m_w, m_h;	//!< width and height

		string m_label;		//!< cluster label

		Stroke m_stroke;	//!< stroke (style of boundary)
		Fill   m_fill;		//!< fill (style of interior)

		ClusterInfo()
			: m_stroke(LayoutStandards::defaultClusterStroke()), m_fill(LayoutStandards::defaultClusterFill())
		{
			m_x = m_y = 0.0;
			m_w = m_h = 0.0;
		}
	};


	//! Stores additional attributes of a clustered graph (like layout information).
	class OGDF_EXPORT ClusterGraphAttributes : public GraphAttributes
	{
		const ClusterGraph* m_pClusterGraph;//!< Only points to existing graphs.

	private:
		ClusterArray<ClusterInfo> m_clusterInfo;     //!< cluster attributes
		ClusterArray<string>      m_clusterTemplate; //!< Name of cluster template.

	public:
		// don't hide these inherited methods by overloading
		using GraphAttributes::x;
		using GraphAttributes::y;
		using GraphAttributes::width;
		using GraphAttributes::height;

		using GraphAttributes::label;

		using GraphAttributes::strokeType;
		using GraphAttributes::setStrokeType;
		using GraphAttributes::strokeColor;
		using GraphAttributes::strokeWidth;

		using GraphAttributes::fillPattern;
		using GraphAttributes::setFillPattern;
		using GraphAttributes::fillColor;
		using GraphAttributes::fillBgColor;

		/**
		 * @name Construction and management of attributes
		 */
		//@{

		//! Constructs cluster graph attributes for no associated graph.
		ClusterGraphAttributes() : GraphAttributes(), m_pClusterGraph(0) { }

		//! Constructs cluster graph attributes for cluster graph \a cg with attributes \a initAttributes.
		/**
		 * \remark All attributes in ClusterElement are always available.
		 */
		ClusterGraphAttributes(ClusterGraph& cg, long initAttributes = 0);

		virtual ~ClusterGraphAttributes() { }

		//! Initializes the cluster graph attributes for cluster graph \a cg with attributes \a initAttributes.
		virtual void init(ClusterGraph &cg, long initAttributes = 0);

		//! Forbidden initialization, use init(ClusterGraph &cg, long initAttributes) instead!
		virtual void init(const Graph &, long) {
			OGDF_THROW(Exception); // We need a cluster graph for initialization
		}

		//! Initializes the attributes according to \a initAttributes.
		virtual void initAtt(long initAttributes = 0) {
			GraphAttributes::initAttributes(initAttributes);
		}

		//! Returns the associated cluster graph.
		const ClusterGraph& constClusterGraph() const { return *m_pClusterGraph; }


		//@}
		/**
		 * @name Cluster attributes
		 */
		//@{

		//! Returns the x-position of cluster \a c's cage (lower left corner).
		double x(cluster c) const { return m_clusterInfo[c].m_x; }

		//! Returns the x-position of cluster \a c's cage (lower left corner).
		double& x(cluster c) { return m_clusterInfo[c].m_x; }

		//! Returns the y-position of cluster \a c's cage (lower left corner).
		double y(cluster c) const { return m_clusterInfo[c].m_y; }

		//! Returns the y-position of cluster \a c's cage (lower left corner).
		double& y(cluster c) { return m_clusterInfo[c].m_y; }

		//! Returns the width of cluster \a c.
		double width(cluster c) const { return m_clusterInfo[c].m_w; }

		//! Returns the width of cluster \a c.
		double& width(cluster c) { return m_clusterInfo[c].m_w; }

		//! Returns the height of cluster \a c.
		double height(cluster c) const { return m_clusterInfo[c].m_h; }

		//! Returns the height of cluster \a c.
		double& height(cluster c) { return m_clusterInfo[c].m_h; }

		//! Returns the stroke type of cluster \a c.
		StrokeType strokeType(cluster c) const {
			return m_clusterInfo[c].m_stroke.m_type;
		}

		//! Sets the stroke type of cluster \a c to \a st.
		void setStrokeType(cluster c, StrokeType st) {
			m_clusterInfo[c].m_stroke.m_type = st;
		}

		//! Returns the stroke color of cluster \a c.
		const Color &strokeColor(cluster c) const {
			return m_clusterInfo[c].m_stroke.m_color;
		}

		//! Returns the stroke color of cluster \a c.
		Color &strokeColor(cluster c) {
			return m_clusterInfo[c].m_stroke.m_color;
		}

		//! Returns the stroke width of cluster \a c.
		const float &strokeWidth(cluster c) const {
			return m_clusterInfo[c].m_stroke.m_width;
		}

		//! Returns the stroke width of cluster \a c.
		float &strokeWidth(cluster c) {
			return m_clusterInfo[c].m_stroke.m_width;
		}

		//! Returns the fill pattern of cluster \a c.
		FillPattern fillPattern(cluster c) const {
			return m_clusterInfo[c].m_fill.m_pattern;
		}

		//! Sets the fill pattern of cluster \a c to \a fp.
		void setFillPattern(cluster c, FillPattern fp) {
			m_clusterInfo[c].m_fill.m_pattern = fp;
		}

		//! Returns the fill color of cluster \a c.
		const Color &fillColor(cluster c) const {
			return m_clusterInfo[c].m_fill.m_color;
		}

		//! Returns the fill color of cluster \a c.
		Color &fillColor(cluster c) {
			return m_clusterInfo[c].m_fill.m_color;
		}

		//! Returns the background color of fill patterns for cluster \a c.
		const Color &fillBgColor(cluster c) const {
			return m_clusterInfo[c].m_fill.m_bgColor;
		}

		//! Returns the background color of fill patterns for cluster \a c.
		Color &fillBgColor(cluster c) {
			return m_clusterInfo[c].m_fill.m_bgColor;
		}

		//! Returns the label of cluster \a c.
		const string &label(cluster c) const {
			return m_clusterInfo[c].m_label;
		}

		//! Returns the label of cluster \a c.
		string &label(cluster c) {
			return m_clusterInfo[c].m_label;
		}

		//! Returns the template of cluster \a c.
		const string &templateCluster(cluster c) const { return m_clusterTemplate[c]; }

		//! Returns the template of cluster \a c.
		string &templateCluster(cluster c) { return m_clusterTemplate[c]; }

		//! Returns the cluster info structure of cluster \a c.
		const ClusterInfo& clusterInfo(cluster c) const { return m_clusterInfo[c]; }

		//! Returns the cluster info structure of cluster \a c.
		ClusterInfo& clusterInfo(cluster c) { return m_clusterInfo[c]; }

		//@}
		/**
		 * @name Utility functions
		 */
		//@{

		//! Returns the bounding box of the layout.
		const DRect boundingBox() const;

		//! Returns the maximum cluster index used.
		int maxClusterID() const { return m_pClusterGraph->clusterIdCount()-1; }

		//! Updates positions of cluster boundaries wrt to children and child clusters
		void updateClusterPositions(double boundaryDist = 1.0);

		//! Returns the parent cluster of node \a v.
		cluster clusterOf(node v) { return m_pClusterGraph->clusterOf(v); }

		//@}

	};


} // end namespace ogdf


#endif