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_QTGIST_HH
35#define GECODE_GIST_QTGIST_HH
36
37#include <gecode/gist/treecanvas.hh>
38#include <gecode/gist/nodestats.hh>
39
40/*
41 * Configure linking
42 *
43 */
44
45#if !defined(GIST_STATIC_LIBS) && \
46 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
47
48#ifdef GECODE_BUILD_GIST
49#define GECODE_GIST_EXPORT __declspec( dllexport )
50#else
51#define GECODE_GIST_EXPORT __declspec( dllimport )
52#endif
53
54#else
55
56#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
57#define GECODE_GIST_EXPORT __attribute__ ((visibility("default")))
58#else
59#define GECODE_GIST_EXPORT
60#endif
61
62#endif
63
64// Configure auto-linking
65#ifndef GECODE_BUILD_GIST
66#define GECODE_LIBRARY_NAME "Gist"
67#include <gecode/support/auto-link.hpp>
68#endif
69
70namespace Gecode { namespace Gist {
71
72 /**
73 * \brief %Gecode Interactive %Search Tool
74 *
75 * This class provides an interactive search tree viewer and explorer as
76 * a Qt widget. You can embedd or inherit from this widget to use %Gist
77 * in your own project.
78 *
79 * \ingroup TaskGist
80 */
81 class GECODE_GIST_EXPORT Gist : public QWidget {
82 Q_OBJECT
83 private:
84 /// The canvas implementation
85 TreeCanvas* canvas;
86 /// The time slider
87 QSlider* timeBar;
88 /// Context menu
89 QMenu* contextMenu;
90 /// Action used when no solution inspector is registered
91 QAction* nullSolutionInspector;
92 /// Menu of solution inspectors
93 QMenu* solutionInspectorMenu;
94 /// Action used when no double click inspector is registered
95 QAction* nullDoubleClickInspector;
96 /// Menu of double click inspectors
97 QMenu* doubleClickInspectorMenu;
98 /// Action used when no double click inspector is registered
99 QAction* nullMoveInspector;
100 /// Menu of double click inspectors
101 QMenu* moveInspectorMenu;
102 /// Action used when no comparator is registered
103 QAction* nullComparator;
104 /// Menu of comparators
105 QMenu* comparatorMenu;
106 /// Action used when no bookmark exists
107 QAction* nullBookmark;
108 /// Bookmark menu
109 QMenu* bookmarksMenu;
110 /// Menu for direct node inspection
111 QMenu* inspectNodeMenu;
112 /// Menu for direct node inspection before fixpoint
113 QMenu* inspectNodeBeforeFPMenu;
114 /// Information about individual nodes
115 NodeStatInspector* nodeStatInspector;
116 public:
117 /// Inspect current node
118 QAction* inspect;
119 /// Inspect current node before fixpoint
120 QAction* inspectBeforeFP;
121 /// Stop search
122 QAction* stop;
123 /// Reset %Gist
124 QAction* reset;
125 /// Navigate to parent node
126 QAction* navUp;
127 /// Navigate to leftmost child node
128 QAction* navDown;
129 /// Navigate to left sibling
130 QAction* navLeft;
131 /// Navigate to right sibling
132 QAction* navRight;
133 /// Navigate to root node
134 QAction* navRoot;
135 /// Navigate to next solution (to the left)
136 QAction* navNextSol;
137 /// Navigate to previous solution (to the right)
138 QAction* navPrevSol;
139 /// Search next solution in current subtree
140 QAction* searchNext;
141 /// Search all solutions in current subtree
142 QAction* searchAll;
143 /// Toggle whether current node is hidden
144 QAction* toggleHidden;
145 /// Hide failed subtrees under current node
146 QAction* hideFailed;
147 /// Unhide all hidden subtrees under current node
148 QAction* unhideAll;
149 /// Label branches under current node
150 QAction* labelBranches;
151 /// Label branches on path to root
152 QAction* labelPath;
153 /// Zoom tree to fit window
154 QAction* zoomToFit;
155 /// Center on current node
156 QAction* center;
157 /// Export PDF of current subtree
158 QAction* exportPDF;
159 /// Export PDF of whole tree
160 QAction* exportWholeTreePDF;
161 /// Print tree
162 QAction* print;
163
164 /// Bookmark current node
165 QAction* bookmarkNode;
166 /// Compare current node to other node
167 QAction* compareNode;
168 /// Compare current node to other node before fixpoint
169 QAction* compareNodeBeforeFP;
170 /// Set path from current node to the root
171 QAction* setPath;
172 /// Inspect all nodes on selected path
173 QAction* inspectPath;
174 /// Open node statistics inspector
175 QAction* showNodeStats;
176 /// Bookmark current node
177 QAction* toggleStop;
178 /// Bookmark current node
179 QAction* unstopAll;
180
181 /// Group of all actions for solution inspectors
182 QActionGroup* solutionInspectorGroup;
183 /// Group of all actions for double click inspectors
184 QActionGroup* doubleClickInspectorGroup;
185 /// Group of all actions for move inspectors
186 QActionGroup* moveInspectorGroup;
187 /// Group of all actions for comparators
188 QActionGroup* comparatorGroup;
189 /// Group of all actions for bookmarks
190 QActionGroup* bookmarksGroup;
191 /// Group of all actions for direct inspector selection
192 QActionGroup* inspectGroup;
193 /// Group of all actions for direct inspector selection
194 QActionGroup* inspectBeforeFPGroup;
195 public:
196 /// Constructor
197 Gist(Space* root, bool bab, QWidget* parent, const Options& opt);
198 /// Destructor
199 ~Gist(void);
200
201 /// Add double click inspector \a i0
202 void addDoubleClickInspector(Inspector* i0);
203 /// Add solution inspector \a i0
204 void addSolutionInspector(Inspector* i0);
205 /// Add move inspector \a i0
206 void addMoveInspector(Inspector* i0);
207 /// Add comparator \a c0
208 void addComparator(Comparator* c0);
209
210 /// Set preference whether to automatically hide failed subtrees
211 void setAutoHideFailed(bool b);
212 /// Set preference whether to automatically zoom to fit
213 void setAutoZoom(bool b);
214 /// Return preference whether to automatically hide failed subtrees
215 bool getAutoHideFailed(void);
216 /// Return preference whether to automatically zoom to fit
217 bool getAutoZoom(void);
218 /// Set preference whether to show copies in the tree
219 void setShowCopies(bool b);
220 /// Return preference whether to show copies in the tree
221 bool getShowCopies(void);
222
223 /// Set refresh rate
224 void setRefresh(int i);
225 /// Set refresh pause in msec
226 void setRefreshPause(int i);
227 /// Return preference whether to use smooth scrolling and zooming
228 bool getSmoothScrollAndZoom(void);
229 /// Set preference whether to use smooth scrolling and zooming
230 void setSmoothScrollAndZoom(bool b);
231 /// Return preference whether to move cursor during search
232 bool getMoveDuringSearch(void);
233 /// Set preference whether to move cursor during search
234 void setMoveDuringSearch(bool b);
235
236 /// Set recomputation parameters \a c_d and \a a_d
237 void setRecompDistances(int c_d, int a_d);
238 /// Return recomputation distance
239 int getCd(void);
240 /// Return adaptive recomputation distance
241 int getAd(void);
242
243 /// Stop search and wait until finished
244 bool finish(void);
245
246 /// Handle resize event
247 void resizeEvent(QResizeEvent*);
248
249 Q_SIGNALS:
250 /// Signals that the tree has changed
251 void statusChanged(const Statistics&, bool);
252
253 /// Signals that a solution has been found
254 void solution(const Space*);
255
256 /// Signals that %Gist is ready to be closed
257 void searchFinished(void);
258
259 private Q_SLOTS:
260 /// Displays the context menu for a node
261 void on_canvas_contextMenu(QContextMenuEvent*);
262 /// Reacts on status changes
263 void on_canvas_statusChanged(VisualNode*, const Statistics&, bool);
264 /// Reacts on double click inspector selection
265 void selectDoubleClickInspector(QAction*);
266 /// Reacts on solution inspector selection
267 void selectSolutionInspector(QAction*);
268 /// Reacts on move inspector selection
269 void selectMoveInspector(QAction*);
270 /// Reacts on comparator selection
271 void selectComparator(QAction*);
272 /// Reacts on bookmark selection
273 void selectBookmark(QAction*);
274 /// Reacts on adding a bookmark
275 void addBookmark(const QString& id);
276 /// Reacts on removing a bookmark
277 void removeBookmark(int idx);
278 /// Populate the inspector menus from the actions found in Gist
279 void populateInspectors(void);
280 /// Populate the bookmarks menu
281 void populateBookmarksMenu(void);
282 /// Shows node status information
283 void showStats(void);
284 /// Inspect current node with inspector described by \a a
285 void inspectWithAction(QAction* a);
286 /// Inspect current node with inspector described by \a a
287 void inspectBeforeFPWithAction(QAction* a);
288 protected:
289 /// Add inspector \a i0
290 void addInspector(Inspector* i, QAction*& nas, QAction*& nad,
291 QAction*& nam);
292 };
293
294}}
295
296#endif
297
298// STATISTICS: gist-any