this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 *
6 * Copyright:
7 * Guido Tack, 2006
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#ifndef GECODE_GIST_VISUALNODE_HH
35#define GECODE_GIST_VISUALNODE_HH
36
37#include <gecode/gist/spacenode.hh>
38#include <gecode/kernel.hh>
39#include <string>
40
41namespace Gecode { namespace Gist {
42
43 /// \brief %Layout parameters
44 class Layout {
45 public:
46 static const int dist_y = 38;
47 static const int extent = 20;
48 static const int minimalSeparation = 10;
49 };
50
51 /// \brief Bounding box
52 class BoundingBox {
53 public:
54 /// Left coordinate
55 int left;
56 /// Right coordinate
57 int right;
58 /// Default constructor
59 BoundingBox(void) {}
60 };
61
62 /// \brief %Extent representing shape of a tree at one depth level
63 class Extent {
64 public:
65 /// Left extent
66 int l;
67 /// Right extent
68 int r;
69 /// Default constructor
70 Extent(void);
71 /// Construct with \a l0 and \a r0
72 Extent(int l0, int r0);
73 /// Construct with width \a width
74 Extent(int width);
75
76 /// Extend extent by \a deltaL and \a deltaR
77 void extend(int deltaL, int deltaR);
78 /// Move extent by \a delta
79 void move(int delta);
80 };
81
82 /// \brief The shape of a subtree
83 class Shape {
84 private:
85 /// The depth of this shape
86 int _depth;
87 /// The bounding box of this shape
88 BoundingBox bb;
89 /// The shape is an array of extents, one for each depth level
90 Extent shape[1];
91 /// Copy construtor
92 Shape(const Shape&);
93 /// Assignment operator
94 Shape& operator =(const Shape&);
95 /// Constructor
96 Shape(void);
97 public:
98 /// Construct shape of depth \a d
99 static Shape* allocate(int d);
100 // Destruct
101 static void deallocate(Shape*);
102
103 /// Static shape for leaf nodes
104 static Shape* leaf;
105 /// Static shape for hidden nodes
106 static Shape* hidden;
107
108 /// Return depth of the shape
109 int depth(void) const;
110 /// Set depth of the shape to \a d (must be smaller than original depth)
111 void setDepth(int d);
112 /// Compute bounding box
113 void computeBoundingBox(void);
114 /// Return extent at depth \a i
115 const Extent& operator [](int i) const;
116 /// Return extent at depth \a i
117 Extent& operator [](int i);
118 /// Return if extent exists at \a depth, if yes return it in \a extent
119 bool getExtentAtDepth(int depth, Extent& extent);
120 /// Return bounding box
121 const BoundingBox& getBoundingBox(void) const;
122 };
123
124 /// \brief %Node class that supports visual layout
125 class VisualNode : public SpaceNode {
126 protected:
127 /// Flags for VisualNodes
128 enum VisualNodeFlags {
129 DIRTY = SpaceNode::LASTBIT+1,
130 CHILDRENLAYOUTDONE,
131 HIDDEN,
132 MARKED,
133 ONPATH,
134 BOOKMARKED
135 };
136
137 /// Relative offset from the parent node
138 int offset;
139 /// Shape of this node
140 Shape* shape;
141
142 /// Check if the \a x at depth \a depth lies in this subtree
143 bool containsCoordinateAtDepth(int x, int depth);
144 public:
145 /// Construct with parent \a p
146 VisualNode(int p);
147 /// Constructor for root node from \a root and \a b
148 VisualNode(Space* root);
149
150 /// Return if node is hidden
151 bool isHidden(void);
152 /// Set hidden state to \a h
153 void setHidden(bool h);
154 /// Set stop state to \a h
155 void setStop(bool h);
156 /// Mark all nodes up the path to the parent as dirty
157 void dirtyUp(const NodeAllocator& na);
158 /// Compute layout for the subtree of this node
159 void layout(const NodeAllocator& na);
160 /// Return offset off this node from its parent
161 int getOffset(void);
162 /// Set offset of this node, relative to its parent
163 void setOffset(int n);
164 /// Return whether node is marked as dirty
165 bool isDirty(void);
166 /// Mark node as dirty
167 void setDirty(bool d);
168 /// Return whether the layout of the node's children has been completed
169 bool childrenLayoutIsDone(void);
170 /// Mark node whether the layout of the node's children has been completed
171 void setChildrenLayoutDone(bool d);
172 /// Return whether node is marked
173 bool isMarked(void);
174 /// Set mark of this node
175 void setMarked(bool m);
176 /// Return whether node is bookmarked
177 bool isBookmarked(void);
178 /// Set bookmark of this node
179 void setBookmarked(bool m);
180 /// Set all nodes from the node to the root to be on the path
181 void pathUp(const NodeAllocator& na);
182 /// Set all nodes from the node to the root not to be on the path
183 void unPathUp(const NodeAllocator& na);
184 /// Return whether node is on the path
185 bool isOnPath(void);
186 /// Return the alternative of the child that is on the path (-1 if none)
187 int getPathAlternative(const NodeAllocator& na);
188 /// Set whether node is on the path
189 void setOnPath(bool onPath0);
190
191 /// Toggle whether this node is hidden
192 void toggleHidden(const NodeAllocator& na);
193 /// Hide all failed subtrees of this node
194 void hideFailed(const NodeAllocator& na, bool onlyDirty=false);
195 /// Unhide all nodes in the subtree of this node
196 void unhideAll(const NodeAllocator& na);
197 /// Do not stop at this node
198 void toggleStop(const NodeAllocator& na);
199 /// Do not stop at any stop node in the subtree of this node
200 void unstopAll(const NodeAllocator& na);
201
202 /// Return the shape of this node
203 Shape* getShape(void);
204 /// Set the shape of this node
205 void setShape(Shape* s);
206 /// Compute the shape according to the shapes of the children
207 void computeShape(const NodeAllocator& na);
208 /// Return the bounding box
209 BoundingBox getBoundingBox(void);
210 /// Signal that the status has changed
211 void changedStatus(const NodeAllocator& na);
212 /// Find a node in this subtree at coordinates \a x, \a y
213 VisualNode* findNode(const NodeAllocator& na, int x, int y);
214
215 /// Create or clear branch labels in subtree
216 void labelBranches(NodeAllocator& na,
217 BestNode* curBest, int c_d, int a_d);
218 /// Create or clear branch labels on path to root
219 void labelPath(NodeAllocator& na,
220 BestNode* curBest, int c_d, int a_d);
221 /// Return string that describes the branch
222 std::string getBranchLabel(NodeAllocator& na,
223 VisualNode* p, const Choice* c,
224 BestNode* curBest, int c_d, int a_d, int alt);
225
226 /// Return string that is used as a tool tip
227 std::string toolTip(NodeAllocator& na, BestNode* curBest,
228 int c_d, int a_d);
229
230 /// Free allocated memory
231 void dispose(void);
232 };
233
234}}
235
236#include <gecode/gist/node.hpp>
237#include <gecode/gist/spacenode.hpp>
238#include <gecode/gist/visualnode.hpp>
239
240#endif
241
242// STATISTICS: gist-any