Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
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 
47 namespace 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 
101  void addDoubleClickInspector(Inspector* i);
103  void activateDoubleClickInspector(int i, bool active);
105  void addSolutionInspector(Inspector* i);
107  void activateSolutionInspector(int i, bool active);
109  void addMoveInspector(Inspector* i);
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*);
235  void statusChanged(VisualNode*,const Statistics&, bool);
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;
248  QMutex layoutMutex;
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;
291  int xtrans;
292 
296  bool autoZoom;
300  int refresh;
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;
335  int targetX;
337  int sourceX;
339  int targetY;
341  int sourceY;
342 
344  int targetW;
346  int targetH;
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
int refreshPause
Time (in msec) to pause after each refresh.
Definition: treecanvas.hh:302
const int maxAutoZoomScale
Maximum scale factor for automatic zoom.
Definition: treecanvas.hh:58
const int minScale
Minimum scale factor.
Definition: treecanvas.hh:52
int targetX
Target x coordinate after smooth scrolling.
Definition: treecanvas.hh:335
Gecode Interactive Search Tool
Definition: qtgist.hh:81
const int maxScale
Maximum scale factor.
Definition: treecanvas.hh:54
bool compareNodes
Whether node comparison action is running.
Definition: treecanvas.hh:278
void search(VisualNode *n, bool all, TreeCanvas *ti)
Definition: treecanvas.cpp:282
void statusChanged(VisualNode *, const Statistics &, bool)
Status bar update.
Abstract base class for comparators.
Definition: gist.hh:119
Node class that supports visual layout
Definition: visualnode.hh:125
void autoZoomChanged(bool)
The auto-zoom state was changed.
VisualNode * root
The root node of the tree.
Definition: treecanvas.hh:258
QSlider * scaleBar
The scale bar.
Definition: treecanvas.hh:283
QVector< QPair< Inspector *, bool > > solutionInspectors
The registered solution inspectors, and whether they are active.
Definition: treecanvas.hh:268
double scale
Current scale factor.
Definition: treecanvas.hh:289
Abstract base class for inspectors.
Definition: gist.hh:99
Computation spaces.
Definition: core.hpp:1742
int a_d
The adaptive recomputation distance.
Definition: treecanvas.hh:311
void scaleChanged(int)
int targetW
Target width after layout.
Definition: treecanvas.hh:344
bool autoHideFailed
Whether to hide failed subtrees automatically.
Definition: treecanvas.hh:294
void statusChanged(bool)
int refresh
Refresh rate.
Definition: treecanvas.hh:300
void searchFinished(void)
Signals that Gist is finished.
bool showCopies
Whether to show copies in the tree.
Definition: treecanvas.hh:298
Gecode toplevel namespace
bool autoZoom
Whether to zoom automatically.
Definition: treecanvas.hh:296
BestNode * curBest
The currently best solution (for branch-and-bound)
Definition: treecanvas.hh:260
SearcherThread searcher
Search engine thread.
Definition: treecanvas.hh:250
A thread that concurrently explores the tree.
Definition: treecanvas.hh:64
VisualNode * pathHead
The head of the currently selected path.
Definition: treecanvas.hh:264
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
Options opt
The options.
Definition: test.cpp:97
Options for Gist
Definition: gist.hh:234
bool moveDuringSearch
Whether to move cursor during search.
Definition: treecanvas.hh:306
int targetScale
Target scale after layout.
Definition: treecanvas.hh:348
VisualNode * currentNode
The currently selected node.
Definition: treecanvas.hh:262
Node allocator.
Definition: node.hh:48
int sourceY
Target y coordinate after smooth scrolling.
Definition: treecanvas.hh:341
QVector< QPair< Inspector *, bool > > doubleClickInspectors
The registered click inspectors, and whether they are active.
Definition: treecanvas.hh:266
int xtrans
Offset on the x axis so that the tree is centered.
Definition: treecanvas.hh:291
int targetH
Target height after layout.
Definition: treecanvas.hh:346
void contextMenu(QContextMenuEvent *)
Context menu triggered.
Statistics stats
Statistics about the search tree.
Definition: treecanvas.hh:286
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Static reference to the currently best space.
Definition: spacenode.hh:80
A canvas that displays the search tree.
Definition: treecanvas.hh:87
void scaleChanged(int)
The scale factor has changed.
QMutex layoutMutex
Mutex for synchronizing layout and drawing.
Definition: treecanvas.hh:248
int layoutDoneTimerId
Timer id for delaying the update.
Definition: treecanvas.hh:350
void searchFinished(void)
#define GECODE_GIST_EXPORT
Definition: qtgist.hh:59
void moveToNode(VisualNode *n, bool)
void solution(const Space *)
const int defScale
Default scale factor.
Definition: treecanvas.hh:56
void removedBookmark(int idx)
Signals that a bookmark has been removed.
Statistics about the search tree
Definition: spacenode.hh:59
void addedBookmark(const QString &id)
Signals that a bookmark has been added.
int targetY
Target y coordinate after smooth scrolling.
Definition: treecanvas.hh:339
QVector< QPair< Comparator *, bool > > comparators
The registered comparators, and whether they are active.
Definition: treecanvas.hh:272
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:208
void solution(const Space *)
Signals that a solution has been found.
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:113
QMutex mutex
Mutex for synchronizing acccess to the tree.
Definition: treecanvas.hh:246
void update(int w, int h, int scale0)
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance)
Definition: search.hh:115
QTimeLine zoomTimeLine
Timer for smooth zooming.
Definition: treecanvas.hh:331
bool smoothScrollAndZoom
Whether to use smooth scrolling and zooming.
Definition: treecanvas.hh:304
QTimeLine scrollTimeLine
Timer for smooth scrolling.
Definition: treecanvas.hh:333
Gecode::FloatVal c(-8, 8)
void run(void)
Definition: treecanvas.cpp:364
bool stopSearchFlag
Flag signalling the search to stop.
Definition: treecanvas.hh:252
QVector< QPair< Inspector *, bool > > moveInspectors
The registered move inspectors, and whether they are active.
Definition: treecanvas.hh:270
bool finishedFlag
Flag signalling that Gist is ready to be closed.
Definition: treecanvas.hh:254
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
QVector< VisualNode * > bookmarks
The bookmarks map.
Definition: treecanvas.hh:275
int sourceX
Source x coordinate after smooth scrolling.
Definition: treecanvas.hh:337
Gecode::IntArgs i({1, 2, 3, 4})
bool compareNodesBeforeFP
Whether node comparison action computes fixpoint.
Definition: treecanvas.hh:280
Node::NodeAllocator * na
Allocator for nodes.
Definition: treecanvas.hh:256
void print(const Search::Statistics &stat, bool restart)
Print statistics.
Definition: job-shop.cpp:606
int c_d
The recomputation distance.
Definition: treecanvas.hh:309