Generated on for Gecode by doxygen 1.17.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.dev>
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.dev
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
47#if QT_VERSION >= 0x060000
48typedef QRecursiveMutex GecodeQMutex;
49#else
50typedef QMutex GecodeQMutex;
51#endif
52
53namespace Gecode { namespace Gist {
54
56 namespace LayoutConfig {
58 const int minScale = 10;
60 const int maxScale = 400;
62 const int defScale = 100;
65 }
66
67 class TreeCanvas;
68
70 class SearcherThread : public QThread {
71 Q_OBJECT
72 private:
73 VisualNode* node;
74 int depth;
75 bool a;
76 TreeCanvas* t;
77 void updateCanvas(void);
78 public:
79 void search(VisualNode* n, bool all, TreeCanvas* ti);
80
81 Q_SIGNALS:
82 void update(int w, int h, int scale0);
83 void statusChanged(bool);
84 void scaleChanged(int);
85 void solution(const Space*);
86 void searchFinished(void);
87 void moveToNode(VisualNode* n,bool);
88 protected:
89 void run(void);
90 };
91
93 class GECODE_GIST_EXPORT TreeCanvas : public QWidget {
94 Q_OBJECT
95
96 friend class SearcherThread;
97 friend class Gist;
98
99 public:
101 TreeCanvas(Space* rootSpace, bool bab, QWidget* parent,
102 const Options& opt);
105
109 void activateDoubleClickInspector(int i, bool active);
113 void activateSolutionInspector(int i, bool active);
117 void activateMoveInspector(int i, bool active);
121 void activateComparator(int i, bool active);
122
123 public Q_SLOTS:
125 void scaleTree(int scale0, int zoomx=-1, int zoomy=-1);
126
128 void searchAll(void);
130 void searchOne(void);
132 void toggleHidden(void);
134 void hideFailed(void);
136 void unhideAll(void);
138 void toggleStop(void);
140 void unstopAll(void);
142 void exportPDF(void);
146 void print(void);
148 void zoomToFit(void);
158 void inspectCurrentNode(bool fix=true, int inspectorNo=-1);
160 void inspectBeforeFP(void);
162 void labelBranches(void);
164 void labelPath(void);
165
167 void stopSearch(void);
168
170 void reset(void);
171
173 void navUp(void);
175 void navDown(void);
177 void navLeft(void);
179 void navRight(void);
181 void navRoot(void);
183 void navNextSol(bool back = false);
185 void navPrevSol(void);
186
188 void bookmarkNode(void);
190 void setPath(void);
192 void inspectPath(void);
197
200
202 void setRecompDistances(int c_d, int a_d);
204 void setAutoHideFailed(bool b);
206 void setAutoZoom(bool b);
210 bool getAutoZoom(void);
212 void setShowCopies(bool b);
214 bool getShowCopies(void);
216 void setRefresh(int i);
218 void setRefreshPause(int i);
228 void resizeToOuter(void);
229
231 bool finish(void);
232
233 Q_SIGNALS:
235 void scaleChanged(int);
237 void autoZoomChanged(bool);
239 void contextMenu(QContextMenuEvent*);
243 void solution(const Space*);
245 void searchFinished(void);
247 void addedBookmark(const QString& id);
249 void removedBookmark(int idx);
250 protected:
272 QVector<QPair<Inspector*,bool> > doubleClickInspectors;
274 QVector<QPair<Inspector*,bool> > solutionInspectors;
276 QVector<QPair<Inspector*,bool> > moveInspectors;
278 QVector<QPair<Comparator*,bool> > comparators;
279
281 QVector<VisualNode*> bookmarks;
282
287
289 QSlider* scaleBar;
290
293
295 double scale;
298
313
315 int c_d;
317 int a_d;
318
322 bool event(QEvent *event);
324 void paintEvent(QPaintEvent* event);
326 void mousePressEvent(QMouseEvent* event);
328 void mouseDoubleClickEvent(QMouseEvent* event);
330 void contextMenuEvent(QContextMenuEvent* event);
332 void resizeEvent(QResizeEvent* event);
334 void wheelEvent(QWheelEvent* event);
335
337 QTimeLine zoomTimeLine;
339 QTimeLine scrollTimeLine;
348
357
359 virtual void timerEvent(QTimerEvent* e);
360
361 public Q_SLOTS:
363 void update(void);
365 void scroll(void);
367 void layoutDone(int w, int h, int scale0);
369 void setCurrentNode(VisualNode* n, bool finished=true, bool update=true);
370 private Q_SLOTS:
372 void statusChanged(bool);
374 void exportNodePDF(VisualNode* n);
376 void inspectSolution(const Space* s);
378 void scroll(int i);
379 };
380
381}}
382
383#endif
384
385// 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:70
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:93
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.
virtual void timerEvent(QTimerEvent *e)
Timer invoked for smooth zooming and 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.
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 print(void)
Print the tree.
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.
~TreeCanvas(void)
Destructor.
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:96
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.
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.
GecodeQMutex mutex
Mutex for synchronizing access to 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.
GecodeQMutex layoutMutex
Mutex for synchronizing layout and drawing.
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.
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:1775
#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
Parameters for the tree layout.
Definition treecanvas.hh:56
const int maxScale
Maximum scale factor.
Definition treecanvas.hh:60
const int defScale
Default scale factor.
Definition treecanvas.hh:62
const int minScale
Minimum scale factor.
Definition treecanvas.hh:58
const int maxAutoZoomScale
Maximum scale factor for automatic zoom.
Definition treecanvas.hh:64
Gecode toplevel namespace
QMutex GecodeQMutex
Definition treecanvas.hh:50