Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
treecanvas.hh
Go to the documentation of this file.
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_TREECANVAS_HH
35#define GECODE_GIST_TREECANVAS_HH
36
37#include <QtGui>
38#if QT_VERSION >= 0x050000
39#include <QtWidgets>
40#endif
41
42#include <gecode/kernel.hh>
43#include <gecode/gist.hh>
44
46
47namespace Gecode { namespace Gist {
48
50 namespace LayoutConfig {
52 const int minScale = 10;
54 const int maxScale = 400;
56 const int defScale = 100;
59 }
60
61 class TreeCanvas;
62
64 class SearcherThread : public QThread {
65 Q_OBJECT
66 private:
67 VisualNode* node;
68 int depth;
69 bool a;
70 TreeCanvas* t;
71 void updateCanvas(void);
72 public:
73 void search(VisualNode* n, bool all, TreeCanvas* ti);
74
75 Q_SIGNALS:
76 void update(int w, int h, int scale0);
77 void statusChanged(bool);
78 void scaleChanged(int);
79 void solution(const Space*);
80 void searchFinished(void);
81 void moveToNode(VisualNode* n,bool);
82 protected:
83 void run(void);
84 };
85
87 class GECODE_GIST_EXPORT TreeCanvas : public QWidget {
88 Q_OBJECT
89
90 friend class SearcherThread;
91 friend class Gist;
92
93 public:
95 TreeCanvas(Space* rootSpace, bool bab, QWidget* parent,
96 const Options& opt);
98 ~TreeCanvas(void);
99
103 void activateDoubleClickInspector(int i, bool active);
107 void activateSolutionInspector(int i, bool active);
111 void activateMoveInspector(int i, bool active);
113 void addComparator(Comparator* c);
115 void activateComparator(int i, bool active);
116
117 public Q_SLOTS:
119 void scaleTree(int scale0, int zoomx=-1, int zoomy=-1);
120
122 void searchAll(void);
124 void searchOne(void);
126 void toggleHidden(void);
128 void hideFailed(void);
130 void unhideAll(void);
132 void toggleStop(void);
134 void unstopAll(void);
136 void exportPDF(void);
138 void exportWholeTreePDF(void);
140 void print(void);
142 void zoomToFit(void);
144 void centerCurrentNode(void);
152 void inspectCurrentNode(bool fix=true, int inspectorNo=-1);
154 void inspectBeforeFP(void);
156 void labelBranches(void);
158 void labelPath(void);
159
161 void stopSearch(void);
162
164 void reset(void);
165
167 void navUp(void);
169 void navDown(void);
171 void navLeft(void);
173 void navRight(void);
175 void navRoot(void);
177 void navNextSol(bool back = false);
179 void navPrevSol(void);
180
182 void bookmarkNode(void);
184 void setPath(void);
186 void inspectPath(void);
188 void startCompareNodes(void);
190 void startCompareNodesBeforeFP(void);
191
193 void emitStatusChanged(void);
194
196 void setRecompDistances(int c_d, int a_d);
198 void setAutoHideFailed(bool b);
200 void setAutoZoom(bool b);
202 bool getAutoHideFailed(void);
204 bool getAutoZoom(void);
206 void setShowCopies(bool b);
208 bool getShowCopies(void);
210 void setRefresh(int i);
212 void setRefreshPause(int i);
214 bool getSmoothScrollAndZoom(void);
216 void setSmoothScrollAndZoom(bool b);
218 bool getMoveDuringSearch(void);
220 void setMoveDuringSearch(bool b);
222 void resizeToOuter(void);
223
225 bool finish(void);
226
227 Q_SIGNALS:
229 void scaleChanged(int);
231 void autoZoomChanged(bool);
233 void contextMenu(QContextMenuEvent*);
237 void solution(const Space*);
239 void searchFinished(void);
241 void addedBookmark(const QString& id);
243 void removedBookmark(int idx);
244 protected:
246 QMutex mutex;
266 QVector<QPair<Inspector*,bool> > doubleClickInspectors;
268 QVector<QPair<Inspector*,bool> > solutionInspectors;
270 QVector<QPair<Inspector*,bool> > moveInspectors;
272 QVector<QPair<Comparator*,bool> > comparators;
273
275 QVector<VisualNode*> bookmarks;
276
281
283 QSlider* scaleBar;
284
287
289 double scale;
292
307
309 int c_d;
311 int a_d;
312
314 VisualNode* eventNode(QEvent *event);
316 bool event(QEvent *event);
318 void paintEvent(QPaintEvent* event);
320 void mousePressEvent(QMouseEvent* event);
322 void mouseDoubleClickEvent(QMouseEvent* event);
324 void contextMenuEvent(QContextMenuEvent* event);
326 void resizeEvent(QResizeEvent* event);
328 void wheelEvent(QWheelEvent* event);
329
331 QTimeLine zoomTimeLine;
333 QTimeLine scrollTimeLine;
342
351
353 virtual void timerEvent(QTimerEvent* e);
354
355 public Q_SLOTS:
357 void update(void);
359 void scroll(void);
361 void layoutDone(int w, int h, int scale0);
363 void setCurrentNode(VisualNode* n, bool finished=true, bool update=true);
364 private Q_SLOTS:
366 void statusChanged(bool);
368 void exportNodePDF(VisualNode* n);
370 void inspectSolution(const Space* s);
372 void scroll(int i);
373 };
374
375}}
376
377#endif
378
379// STATISTICS: gist-any
Static reference to the currently best space.
Definition spacenode.hh:80
Abstract base class for comparators.
Definition gist.hh:119
Abstract base class for inspectors.
Definition gist.hh:99
NodeAllocatorBase< VisualNode > NodeAllocator
Definition node.hh:143
Options for Gist
Definition gist.hh:234
A thread that concurrently explores the tree.
Definition treecanvas.hh:64
void update(int w, int h, int scale0)
void solution(const Space *)
void search(VisualNode *n, bool all, TreeCanvas *ti)
void moveToNode(VisualNode *n, bool)
Statistics about the search tree
Definition spacenode.hh:59
A canvas that displays the search tree.
Definition treecanvas.hh:87
double scale
Current scale factor.
void navNextSol(bool back=false)
Move selection to next solution (in DFS order)
void update(void)
Update display.
void zoomToFit(void)
Zoom the canvas so that the whole tree fits.
void resizeToOuter(void)
Resize to the outer widget size if auto zoom is enabled.
void activateComparator(int i, bool active)
Set active comparator.
void exportPDF(void)
Export pdf of the current subtree.
int targetX
Target x coordinate after smooth scrolling.
void wheelEvent(QWheelEvent *event)
Handle mouse wheel events.
Statistics stats
Statistics about the search tree.
void resizeEvent(QResizeEvent *event)
Handle resize event.
int targetScale
Target scale after layout.
QVector< VisualNode * > bookmarks
The bookmarks map.
SearcherThread searcher
Search engine thread.
VisualNode * currentNode
The currently selected node.
bool finish(void)
Stop search and wait for it to finish.
void exportWholeTreePDF(void)
Export pdf of the whole tree.
int xtrans
Offset on the x axis so that the tree is centered.
void activateDoubleClickInspector(int i, bool active)
Set active inspector.
void navUp(void)
Move selection to the parent of the selected node.
bool autoHideFailed
Whether to hide failed subtrees automatically.
void labelBranches(void)
Label all branches in subtree under current node.
VisualNode * eventNode(QEvent *event)
Return the node corresponding to the event position.
void contextMenuEvent(QContextMenuEvent *event)
Handle context menu event.
void startCompareNodesBeforeFP(void)
Wait for click on node to compare with current node before fixpoint.
void startCompareNodes(void)
Wait for click on node to compare with current node.
void addComparator(Comparator *c)
Add comparator c.
QMutex mutex
Mutex for synchronizing acccess to the tree.
void inspectBeforeFP(void)
Calls inspectCurrentNode(false)
void hideFailed(void)
Hide failed subtrees of selected node.
bool getAutoZoom(void)
Return preference whether to automatically zoom to fit.
void setRefreshPause(int i)
Set refresh pause in msec.
void bookmarkNode(void)
Bookmark current node.
void searchAll(void)
Explore complete subtree of selected node.
int refresh
Refresh rate.
QTimeLine scrollTimeLine
Timer for smooth scrolling.
int layoutDoneTimerId
Timer id for delaying the update.
void addSolutionInspector(Inspector *i)
Add inspector i.
int targetH
Target height after layout.
bool smoothScrollAndZoom
Whether to use smooth scrolling and zooming.
QTimeLine zoomTimeLine
Timer for smooth zooming.
void setPath(void)
Set the current node to be the head of the path.
void navRoot(void)
Move selection to the root node.
void statusChanged(VisualNode *, const Statistics &, bool)
Status bar update.
TreeCanvas(Space *rootSpace, bool bab, QWidget *parent, const Options &opt)
Constructor.
bool event(QEvent *event)
General event handler, used for displaying tool tips.
void setMoveDuringSearch(bool b)
Set preference whether to move cursor during search.
void searchOne(void)
Find next solution below selected node.
void scroll(void)
React to scroll events.
void navDown(void)
Move selection to the first child of the selected node.
QVector< QPair< Comparator *, bool > > comparators
The registered comparators, and whether they are active.
friend class SearcherThread
Definition treecanvas.hh:90
bool compareNodes
Whether node comparison action is running.
void scaleTree(int scale0, int zoomx=-1, int zoomy=-1)
Set scale factor to scale0.
void activateSolutionInspector(int i, bool active)
Set active inspector.
int c_d
The recomputation distance.
void mousePressEvent(QMouseEvent *event)
Handle mouse press event.
void navLeft(void)
Move selection to the left sibling of the selected node.
QSlider * scaleBar
The scale bar.
QMutex layoutMutex
Mutex for synchronizing layout and drawing.
int targetY
Target y coordinate after smooth scrolling.
QVector< QPair< Inspector *, bool > > doubleClickInspectors
The registered click inspectors, and whether they are active.
void autoZoomChanged(bool)
The auto-zoom state was changed.
void setRefresh(int i)
Set refresh rate.
Node::NodeAllocator * na
Allocator for nodes.
BestNode * curBest
The currently best solution (for branch-and-bound)
void paintEvent(QPaintEvent *event)
Paint the tree.
void unstopAll(void)
Do not stop at any stop node.
bool moveDuringSearch
Whether to move cursor during search.
bool getSmoothScrollAndZoom(void)
Return preference whether to use smooth scrolling and zooming.
void mouseDoubleClickEvent(QMouseEvent *event)
Handle mouse double click event.
int a_d
The adaptive recomputation distance.
void unhideAll(void)
Unhide all nodes below selected node.
void reset(void)
Reset.
void searchFinished(void)
Signals that Gist is finished.
int sourceX
Source x coordinate after smooth scrolling.
void scaleChanged(int)
The scale factor has changed.
bool getAutoHideFailed(void)
Return preference whether to automatically hide failed subtrees.
void solution(const Space *)
Signals that a solution has been found.
int targetW
Target width after layout.
void setRecompDistances(int c_d, int a_d)
Set recomputation distances.
void addMoveInspector(Inspector *i)
Add inspector i.
bool autoZoom
Whether to zoom automatically.
void emitStatusChanged(void)
Re-emit status change information for current node.
void setAutoZoom(bool b)
Set preference whether to automatically zoom to fit.
void centerCurrentNode(void)
Center the view on the currently selected node.
void setSmoothScrollAndZoom(bool b)
Set preference whether to use smooth scrolling and zooming.
bool finishedFlag
Flag signalling that Gist is ready to be closed.
void removedBookmark(int idx)
Signals that a bookmark has been removed.
VisualNode * pathHead
The head of the currently selected path.
void activateMoveInspector(int i, bool active)
Set active inspector.
void setCurrentNode(VisualNode *n, bool finished=true, bool update=true)
Set the selected node to n.
void contextMenu(QContextMenuEvent *)
Context menu triggered.
bool stopSearchFlag
Flag signalling the search to stop.
void setShowCopies(bool b)
Set preference whether to show copies in the tree.
void labelPath(void)
Label all branches on path to root node.
void layoutDone(int w, int h, int scale0)
Layout done.
virtual void timerEvent(QTimerEvent *e)
Timer invoked for smooth zooming and scrolling.
bool getMoveDuringSearch(void)
Return preference whether to move cursor during search.
bool compareNodesBeforeFP
Whether node comparison action computes fixpoint.
void toggleStop(void)
Do not stop at selected stop node.
void toggleHidden(void)
Toggle hidden state of selected node.
void navRight(void)
Move selection to the right sibling of the selected node.
void navPrevSol(void)
Move selection to previous solution (in DFS order)
bool showCopies
Whether to show copies in the tree.
void inspectPath(void)
Call the double click inspector for all nodes on the path from root to head of the path.
bool getShowCopies(void)
Return preference whether to show copies in the tree.
VisualNode * root
The root node of the tree.
void stopSearch(void)
Stop current search.
void inspectCurrentNode(bool fix=true, int inspectorNo=-1)
Call the double click inspector for the currently selected node.
int sourceY
Target y coordinate after smooth scrolling.
void setAutoHideFailed(bool b)
Set preference whether to automatically hide failed subtrees.
void addDoubleClickInspector(Inspector *i)
Add inspector i.
int refreshPause
Time (in msec) to pause after each refresh.
QVector< QPair< Inspector *, bool > > moveInspectors
The registered move inspectors, and whether they are active.
QVector< QPair< Inspector *, bool > > solutionInspectors
The registered solution inspectors, and whether they are active.
void addedBookmark(const QString &id)
Signals that a bookmark has been added.
Node class that supports visual layout
Computation spaces.
Definition core.hpp:1744
#define GECODE_GIST_EXPORT
Definition gist.hh:65
int bab(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition gist.hpp:208
void print(const Search::Statistics &stat, bool restart)
Print statistics.
Definition job-shop.cpp:606
Parameters for the tree layout.
Definition treecanvas.hh:50
const int maxScale
Maximum scale factor.
Definition treecanvas.hh:54
const int defScale
Default scale factor.
Definition treecanvas.hh:56
const int minScale
Minimum scale factor.
Definition treecanvas.hh:52
const int maxAutoZoomScale
Maximum scale factor for automatic zoom.
Definition treecanvas.hh:58
The Gecode Interactive Search Tool.
Gecode toplevel namespace