-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvisualnode.hpp
253 lines (201 loc) · 6.65 KB
/
visualnode.hpp
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
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <[email protected]>
*
* Copyright:
* Guido Tack, 2007
*
* Last modified:
* $Date$ by $Author$
* $Revision$
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef VISUALNODE_HPP
#define VISUALNODE_HPP
#include <iostream>
#include <QString>
#ifdef MAXIM_DEBUG
#include <QDebug>
#endif
inline NodeAllocator::NodeAllocator() {
nodes.reserve(1000);
}
inline NodeAllocator::~NodeAllocator() {
for (auto &node : nodes) {
delete node;
}
}
inline int NodeAllocator::allocate(int p) {
nodes.push_back(new VisualNode{p});
return nodes.size() - 1;
}
inline int NodeAllocator::allocateRoot() {
#ifdef MAXIM_DEBUG
qDebug() << "allocated root";
#endif
nodes.push_back(new VisualNode{});
return nodes.size() - 1;
}
inline VisualNode* NodeAllocator::operator[](int i) const {
#ifdef MAXIM_DEBUG
// qDebug() << "nodes[" << i << "]";
#endif
if (nodes.size() <= static_cast<uint>(i)) {
return nullptr;
} else {
return nodes[i];
}
}
inline bool NodeAllocator::hasLabel(VisualNode* n) const {
return labels.contains(n);
}
inline void NodeAllocator::setLabel(VisualNode* n, const QString& l) {
labels[n] = l;
}
inline void NodeAllocator::clearLabel(VisualNode* n) { labels.remove(n); }
inline QString NodeAllocator::getLabel(VisualNode* n) const {
return labels.value(n);
}
inline int NodeAllocator::size() const {
return nodes.size();
}
inline Extent::Extent(void) : l(-1), r(-1) {}
inline Extent::Extent(int l0, int r0) : l(l0), r(r0) {}
inline Extent::Extent(int width) {
int halfWidth = width / 2;
l = 0 - halfWidth;
r = 0 + halfWidth;
}
inline void Extent::extend(int deltaL, int deltaR) {
l += deltaL;
r += deltaR;
}
inline void Extent::move(int delta) {
l += delta;
r += delta;
}
inline int Shape::depth(void) const { return _depth; }
inline void Shape::setDepth(int d) {
assert(d <= _depth);
_depth = d;
}
inline const Extent& Shape::operator[](int i) const {
assert(i < _depth);
return shape[i];
}
inline Extent& Shape::operator[](int i) {
assert(i < _depth);
return shape[i];
}
/// Allocate memory for a shape of depth \d
inline Shape* Shape::allocate(int d) {
assert(d >= 1);
Shape* ret;
ret = static_cast<Shape*>(
heap.ralloc(sizeof(Shape) + (d - 1) * sizeof(Extent)));
ret->_depth = d;
return ret;
}
inline void Shape::deallocate(Shape* shape) {
if (shape != hidden && shape != leaf) {
heap.rfree(shape);
}
}
inline bool Shape::getExtentAtDepth(int d, Extent& extent) {
if (d > depth()) return false;
extent = Extent(0, 0);
for (int i = 0; i <= d; i++) {
Extent currentExtent = (*this)[i];
extent.l += currentExtent.l;
extent.r += currentExtent.r;
}
return true;
}
inline void Shape::computeBoundingBox(void) {
int lastLeft = 0;
int lastRight = 0;
bb.left = 0;
bb.right = 0;
for (int i = 0; i < depth(); i++) {
lastLeft = lastLeft + (*this)[i].l;
lastRight = lastRight + (*this)[i].r;
bb.left = std::min(bb.left, lastLeft);
bb.right = std::max(bb.right, lastRight);
}
}
inline const BoundingBox& Shape::getBoundingBox(void) const { return bb; }
inline bool VisualNode::isHidden(void) const { return getFlag(HIDDEN); }
inline void VisualNode::setHidden(bool h) { setFlag(HIDDEN, h); }
inline int VisualNode::getOffset(void) { return offset; }
inline void VisualNode::setOffset(int n) { offset = n; }
inline bool VisualNode::isDirty(void) const { return getFlag(DIRTY); }
inline void VisualNode::setDirty(bool d) {
setFlag(DIRTY, d);
}
inline bool VisualNode::childrenLayoutIsDone(void) {
return getFlag(CHILDRENLAYOUTDONE);
}
inline void VisualNode::setChildrenLayoutDone(bool d) {
setFlag(CHILDRENLAYOUTDONE, d);
}
inline bool VisualNode::isMarked(void) const { return getFlag(MARKED); }
inline void VisualNode::setMarked(bool m) { setFlag(MARKED, m); }
inline bool VisualNode::isSelected(void) const { return getFlag(SELECTED); }
inline void VisualNode::setSelected(bool m) { setFlag(SELECTED, m); }
inline bool VisualNode::isHovered(void) const { return getFlag(HOVEREDOVER); }
inline void VisualNode::setHovered(bool m) { setFlag(HOVEREDOVER, m); }
inline bool VisualNode::isBookmarked(void) const { return getFlag(BOOKMARKED); }
inline void VisualNode::setBookmarked(bool m) { setFlag(BOOKMARKED, m); }
inline bool VisualNode::isHighlighted(void) const { return getFlag(HIGHLIGHTED); }
inline bool VisualNode::isInvisible(void) const { return getFlag(INVISIBLE); }
inline void VisualNode::setInvisible(bool m) { setFlag(INVISIBLE, m); }
inline bool VisualNode::isDeleted(void) const { return getFlag(DELETED); }
inline void VisualNode::setDeleted(bool m) { setFlag(DELETED, m); }
inline void VisualNode::setHighlighted(bool m) { setFlag(HIGHLIGHTED, m); }
inline bool VisualNode::isOnPath(void) const { return getFlag(ONPATH); }
inline void VisualNode::setOnPath(bool b) { setFlag(ONPATH, b); }
inline void VisualNode::setSubtreeSizeUnknown(void) {
setNumericFlag(SUBTREESIZE, 7, 0);
}
inline void VisualNode::setSubtreeSize(int size) {
setNumericFlag(SUBTREESIZE, 7, size);
}
inline int VisualNode::getSubtreeSize(void) const {
int size = getNumericFlag(SUBTREESIZE, 7);
if (size == 0) return -1;
return size;
}
inline Shape* VisualNode::getShape(void) const {
if (isHidden() && getSubtreeSize() == -1) {
return (getStatus() == MERGING) ? Shape::leaf : Shape::hidden;
}
return shape;
}
inline BoundingBox VisualNode::getBoundingBox(void) const {
return getShape()->getBoundingBox();
}
#endif // VISUALNODE_HPP