File: HypergraphAttributes.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 (396 lines) | stat: -rw-r--r-- 9,189 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/*
 * $Revision: 3505 $
 *
 * last checkin:
 *   $Author: beyer $
 *   $Date: 2013-05-16 14:49:47 +0200 (Thu, 16 May 2013) $
 ***************************************************************/

/** \file
 * \brief Declares HypergraphAttributes storing specific attributes
 *        related to hypergraph layout drawings.
 *
 * \author Ondrej Moris
 *
 * \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_HYPERGRAPH_ATTRIBUTES_H
#define OGDF_HYPERGRAPH_ATTRIBUTES_H

#include <ogdf/hypergraph/HypergraphArray.h>
#include <ogdf/hypergraph/EdgeStandardRep.h>
#include <ogdf/basic/GraphAttributes.h>

namespace ogdf {

/**
 * \brief Stores additional attributes of a hypergraph.
 *
 * Because of different representation standards of hypergraphs (edge or
 * subset) there are two different classes for hypergraph attributes. The
 * main reason is that some edge standard atrributes are pointless in t
 * subset standard representation and vice-versa. Common attributes, currently
 * various hypernode attributes only, are pushed to the superclass
 * HypergraphAttributes.
 *
 * Similarly to GraphAttributes, attributes are simply stored in hypernode
 * or hyperedge arrays.
 */
class OGDF_EXPORT HypergraphAttributes
{
protected:

	//!< Only points to an existing hypergraph.
	const Hypergraph * m_hypergraph;

	//!< Label of a hypernode.
	HypernodeArray<string> m_label;

	//!< Coordinate x of a hypernod.e
	HypernodeArray<double> m_x;

	//!< Coordinate y of a hypernode.
	HypernodeArray<double> m_y;

	//!< Width of a hypernode bounding box.
	HypernodeArray<double> m_width;

	//!< Height of a hypernodes bounding box.
	HypernodeArray<double> m_height;

	//!< Shape of a hypernode.
	HypernodeArray<int>    m_shape;

public:

	//! Initializes new instance of class HypergraphAttributes.
	HypergraphAttributes()
	  : m_hypergraph(0)
	{
	}

	//! Initializes new instance of class HypergraphAttributes.
	HypergraphAttributes(const Hypergraph &H)
	  : m_hypergraph(&H)
	{
		m_x.init(H, 0.0);
		m_y.init(H, 0.0);
		m_width .init(H,10.0);
		m_height.init(H,10.0);
		m_label.init(H);
		m_shape.init(H, shEllipse);
	}

	//! Desctructor.
	virtual ~HypergraphAttributes()
	{
	}

	const Hypergraph & constHypergraph() const
	{
		return *m_hypergraph;
	}

	//! Returns the x-coordinate of hypernode \a v.
	const double &x(hypernode v)
	{
		return m_x[v];
	}

	//! Sets the x-coordinate of hypernode \a v.
	void setX(hypernode v, double pX)
	{
		m_x[v] = pX;
	}

	//! Returns the y-coordinate of hypernode \a v.
	const double &y(hypernode v) {
		return m_y[v];
	}

	//! Sets the y-coordinate of hypernode \a v.
	void setY(hypernode v, double pY)
	{
		m_y[v] = pY;
	}

	//! Returns the width of the bounding box of hypernode \a v.
	const double &width(hypernode v)
	{
		return m_width[v];
	}

	//! Sets the the width of hypernode \a v.
	void setWidth(hypernode v, int pWidth)
	{
		m_width[v] = pWidth;
	}

	//! Returns the height of the bounding box of hypernode \a v.
	const double &height(hypernode v)
	{
		return m_height[v];
	}

	//! Sets the the height of hypernode \a v.
	void setHeight(hypernode v, int pHeight)
	{
		m_height[v] = pHeight;
	}

	//! Returns the shape of hypernode \a v.
	int shape(hypernode v)
	{
		return m_shape[v];
	}

	//! Returns the label of hypernode \ v.
	string &label(hypernode v)
	{
		return m_label[v];
	}

};

/**
 * \brief Stores additional attributes of edge standard representation of
 *        a hypergraph.
 *
 * Since edge standard representation is in fact just an ordinary graph,
 * all its attributes are stored in wrapped instance of GraphAttributes
 * class. Some nodes in the representation are yet specific since they
 * represent hypernodes, attributes of these are driven explicitly from
 * this class.
 *
 * Superclass is declared as pure virtual to make dynamic casting possible.
 */
class OGDF_EXPORT HypergraphAttributesES : virtual public HypergraphAttributes
{
private:

	//! Wrapped graph atrributes reference.
	GraphAttributes *m_repGA;

	//! Edge standard representation reference.
	EdgeStandardRep *m_repG;

	//! The type of of edge standard representation.
	EdgeStandardType::Type m_type;

public:

	//! Initializes new instance of class HypergraphAttributes.
	HypergraphAttributesES()
	  : m_repGA(0), m_repG(0)
	{
	}

	//! Initializes new instance of class HypergraphAttributes.
	HypergraphAttributesES(const Hypergraph &pH, EdgeStandardType::Type pType = EdgeStandardType::star)
	  : HypergraphAttributes(pH)
	{
		m_repG = new EdgeStandardRep(pH, pType);

		m_repGA = new  GraphAttributes(m_repG->constGraph(),
				GraphAttributes::nodeGraphics |
				GraphAttributes::edgeGraphics);

		m_repGA->setDirected(false);
	}

	//! Destructor.
	virtual ~HypergraphAttributesES()
	{
		delete m_repGA;
		delete m_repG;
	}

	EdgeStandardType::Type type() const
	{
		return m_type;
	}

	const Graph & repGraph() const
	{
		return m_repG->constGraph();
	}

	const GraphAttributes & repGA() const
	{
		return *m_repGA;
	}

	//! Returns the type of representation node \a v.
	HypernodeElement::Type type(hypernode v)
	{
		return v->type();
	}

	//! Returns the type of representation node \a v.
	HypernodeElement::Type type(node v)
	{
		if (m_repG->hypernodeMap(v))
			return m_repG->hypernodeMap(v)->type();
		else
			return HypernodeElement::dummy;
	}

	//! Returns the x-coordinate of representation node \a v.
	const double &x(node v)
	{
		return m_repGA->x(v);
	}

	//! Sets the x-coordinate of a representation node \a v.
	void setX(node v, double pX)
	{
		if (m_repG->hypernodeMap(v))
			setX(m_repG->hypernodeMap(v), pX);
		else
			m_repGA->x(v) = pX;
	}

	//! Sets the x-coordinate of hypernode \a v.
	void setX(hypernode v, double pX)
	{
		m_x[v] = pX;
		m_repGA->x(m_repG->nodeMap(v)) = pX;
	}

	//! Returns the y-coordinate of a representation node \a v.
	const double &y(node v)
	{
		return m_repGA->y(v);
	}

	//! Sets the x-coordinate of hypernode \a v.
	void setY(hypernode v, double pY)
	{
		m_y[v] = pY;
		m_repGA->y(m_repG->nodeMap(v)) = pY;
	}

	//! Sets the y-coordinate of a representation node \a v.
	void setY(node v, double pY)
	{
		if (m_repG->hypernodeMap(v))
			setY(m_repG->hypernodeMap(v), pY);
		else
			m_repGA->y(v) = pY;
	}

	//! Returns the width of a representation node \a v.
	const double &width(node v)
	{
		return m_repGA->width(v);
	}

	//! Sets the the width of hypernode \a v.
	void setWidth(hypernode v, double pWidth)
	{
		m_width[v] = pWidth;
		m_repGA->width(m_repG->nodeMap(v)) = pWidth;
	}

	//! Sets the the width of a representation node \a v.
	void setWidth(node v, double pWidth)
	{
		if (m_repG->hypernodeMap(v))
			setWidth(m_repG->hypernodeMap(v), pWidth);
		else
			m_repGA->width(v) = pWidth;
	}

	//! Returns the height of a representation node \a v.
	const double &height(node v)
	{
		return m_repGA->height(v);
	}

	//! Sets the the height of hypernode \a v.
	void setHeight(hypernode v, double pHeight)
	{
		m_height[v] = pHeight;
		m_repGA->height(m_repG->nodeMap(v)) = pHeight;
	}

	//! Sets the the height of a representation node \a v.
	void setHeight(node v, double pHeight)
	{
		if (m_repG->hypernodeMap(v))
			setHeight(m_repG->hypernodeMap(v), pHeight);
		else
			m_repGA->height(v) = pHeight;
	}

	//! Returns the list of bend points of edge \a e.
	DPolyline &bends(edge e)
	{
		return m_repGA->bends(e);
	}

	////! Writes the hypergraph (edge standard representation) into SVG format.
	//void writeSVG(ostream &os, int fontSize, const string &fontColor) const
	//{
	//    m_repGA->writeSVG(os, fontSize, fontColor);
	//}
	//
	////! Writes the hypergraph (edge standard representation) into SVG format.
	//void writeSVG(const char *fileName, int fontSize, const string &fontColor) const
	//{
	//    m_repGA->writeSVG(fileName, fontSize, fontColor);
	//}

	void clearAllBends()
	{
		m_repGA->clearAllBends();
	}

	//! Removes unnecessary bend points in orthogonal segements.
	void removeUnnecessaryBendsHV()
	{
		m_repGA->removeUnnecessaryBendsHV();
	}

	//! Returns the bounding box of the hypergraph.
	const DRect boundingBox() const
	{
		return m_repGA->boundingBox();
	}

};

} // end namespace ogdf

#endif