Generated on Sat Feb 7 2015 02:01:19 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2013-05-06 09:02:17 +0200 (Mon, 06 May 2013) $ by $Author: tack $
11  * $Revision: 13613 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #ifndef GECODE_GIST_TREECANVAS_HH
39 #define GECODE_GIST_TREECANVAS_HH
40 
41 #include <QtGui>
42 #if QT_VERSION >= 0x050000
43 #include <QtWidgets>
44 #endif
45 
46 #include <gecode/kernel.hh>
47 #include <gecode/gist.hh>
48 
50 
51 namespace Gecode { namespace Gist {
52 
54  namespace LayoutConfig {
56  const int minScale = 10;
58  const int maxScale = 400;
60  const int defScale = 100;
63  }
64 
65  class TreeCanvas;
66 
68  class SearcherThread : public QThread {
69  Q_OBJECT
70  private:
71  VisualNode* node;
72  int depth;
73  bool a;
74  TreeCanvas* t;
75  void updateCanvas(void);
76  public:
77  void search(VisualNode* n, bool all, TreeCanvas* ti);
78 
79  Q_SIGNALS:
80  void update(int w, int h, int scale0);
81  void statusChanged(bool);
82  void scaleChanged(int);
83  void solution(const Space*);
84  void searchFinished(void);
85  void moveToNode(VisualNode* n,bool);
86  protected:
87  void run(void);
88  };
89 
91  class GECODE_GIST_EXPORT TreeCanvas : public QWidget {
92  Q_OBJECT
93 
94  friend class SearcherThread;
95  friend class Gist;
96 
97  public:
99  TreeCanvas(Space* rootSpace, bool bab, QWidget* parent,
100  const Options& opt);
102  ~TreeCanvas(void);
103 
105  void addDoubleClickInspector(Inspector* i);
107  void activateDoubleClickInspector(int i, bool active);
109  void addSolutionInspector(Inspector* i);
111  void activateSolutionInspector(int i, bool active);
113  void addMoveInspector(Inspector* i);
115  void activateMoveInspector(int i, bool active);
117  void addComparator(Comparator* c);
119  void activateComparator(int i, bool active);
120 
121  public Q_SLOTS:
123  void scaleTree(int scale0, int zoomx=-1, int zoomy=-1);
124 
126  void searchAll(void);
128  void searchOne(void);
130  void toggleHidden(void);
132  void hideFailed(void);
134  void unhideAll(void);
136  void toggleStop(void);
138  void unstopAll(void);
140  void exportPDF(void);
142  void exportWholeTreePDF(void);
144  void print(void);
146  void zoomToFit(void);
148  void centerCurrentNode(void);
156  void inspectCurrentNode(bool fix=true, int inspectorNo=-1);
158  void inspectBeforeFP(void);
160  void labelBranches(void);
162  void labelPath(void);
163 
165  void stopSearch(void);
166 
168  void reset(void);
169 
171  void navUp(void);
173  void navDown(void);
175  void navLeft(void);
177  void navRight(void);
179  void navRoot(void);
181  void navNextSol(bool back = false);
183  void navPrevSol(void);
184 
186  void bookmarkNode(void);
188  void setPath(void);
190  void inspectPath(void);
192  void startCompareNodes(void);
194  void startCompareNodesBeforeFP(void);
195 
197  void emitStatusChanged(void);
198 
200  void setRecompDistances(int c_d, int a_d);
202  void setAutoHideFailed(bool b);
204  void setAutoZoom(bool b);
206  bool getAutoHideFailed(void);
208  bool getAutoZoom(void);
210  void setShowCopies(bool b);
212  bool getShowCopies(void);
214  void setRefresh(int i);
216  void setRefreshPause(int i);
218  bool getSmoothScrollAndZoom(void);
220  void setSmoothScrollAndZoom(bool b);
222  bool getMoveDuringSearch(void);
224  void setMoveDuringSearch(bool b);
226  void resizeToOuter(void);
227 
229  bool finish(void);
230 
231  Q_SIGNALS:
233  void scaleChanged(int);
235  void autoZoomChanged(bool);
237  void contextMenu(QContextMenuEvent*);
239  void statusChanged(VisualNode*,const Statistics&, bool);
241  void solution(const Space*);
243  void searchFinished(void);
245  void addedBookmark(const QString& id);
247  void removedBookmark(int idx);
248  protected:
250  QMutex mutex;
252  QMutex layoutMutex;
270  QVector<QPair<Inspector*,bool> > doubleClickInspectors;
272  QVector<QPair<Inspector*,bool> > solutionInspectors;
274  QVector<QPair<Inspector*,bool> > moveInspectors;
276  QVector<QPair<Comparator*,bool> > comparators;
277 
279  QVector<VisualNode*> bookmarks;
280 
285 
287  QSlider* scaleBar;
288 
291 
293  double scale;
295  int xtrans;
296 
300  bool autoZoom;
304  int refresh;
311 
313  int c_d;
315  int a_d;
316 
318  VisualNode* eventNode(QEvent *event);
320  bool event(QEvent *event);
322  void paintEvent(QPaintEvent* event);
324  void mousePressEvent(QMouseEvent* event);
326  void mouseDoubleClickEvent(QMouseEvent* event);
328  void contextMenuEvent(QContextMenuEvent* event);
330  void resizeEvent(QResizeEvent* event);
332  void wheelEvent(QWheelEvent* event);
333 
335  QTimeLine zoomTimeLine;
337  QTimeLine scrollTimeLine;
339  int targetX;
341  int sourceX;
343  int targetY;
345  int sourceY;
346 
348  int targetW;
350  int targetH;
355 
357  virtual void timerEvent(QTimerEvent* e);
358 
359  public Q_SLOTS:
361  void update(void);
363  void scroll(void);
365  void layoutDone(int w, int h, int scale0);
367  void setCurrentNode(VisualNode* n, bool finished=true, bool update=true);
368  private Q_SLOTS:
370  void statusChanged(bool);
372  void exportNodePDF(VisualNode* n);
374  void inspectSolution(const Space* s);
376  void scroll(int i);
377  };
378 
379 }}
380 
381 #endif
382 
383 // STATISTICS: gist-any
void search(VisualNode *n, bool all, TreeCanvas *ti)
Definition: treecanvas.cpp:286
Static reference to the currently best space.
Definition: spacenode.hh:84
bool compareNodesBeforeFP
Whether node comparison action computes fixpoint.
Definition: treecanvas.hh:284
int refresh
Refresh rate.
Definition: treecanvas.hh:304
bool showCopies
Whether to show copies in the tree.
Definition: treecanvas.hh:302
Abstract base class for comparators.
Definition: gist.hh:123
QVector< VisualNode * > bookmarks
The bookmarks map.
Definition: treecanvas.hh:279
const int defScale
Default scale factor.
Definition: treecanvas.hh:60
int sourceX
Source x coordinate after smooth scrolling.
Definition: treecanvas.hh:341
QVector< QPair< Inspector *, bool > > moveInspectors
The registered move inspectors, and whether they are active.
Definition: treecanvas.hh:274
VisualNode * root
The root node of the tree.
Definition: treecanvas.hh:262
int targetScale
Target scale after layout.
Definition: treecanvas.hh:352
int targetW
Target width after layout.
Definition: treecanvas.hh:348
Node allocator.
Definition: node.hh:52
QSlider * scaleBar
The scale bar.
Definition: treecanvas.hh:287
Computation spaces.
Definition: core.hpp:1362
Abstract base class for inspectors.
Definition: gist.hh:103
int xtrans
Offset on the x axis so that the tree is centered.
Definition: treecanvas.hh:295
const int minScale
Minimum scale factor.
Definition: treecanvas.hh:56
bool finishedFlag
Flag signalling that Gist is ready to be closed.
Definition: treecanvas.hh:258
Gecode::FloatVal c(-8, 8)
int targetX
Target x coordinate after smooth scrolling.
Definition: treecanvas.hh:339
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Options opt
The options.
Definition: test.cpp:101
BestNode * curBest
The currently best solution (for branch-and-bound)
Definition: treecanvas.hh:264
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:99
double scale
Current scale factor.
Definition: treecanvas.hh:293
Gecode Interactive Search Tool
Definition: qtgist.hh:85
QMutex mutex
Mutex for synchronizing acccess to the tree.
Definition: treecanvas.hh:250
int a_d
The adaptive recomputation distance.
Definition: treecanvas.hh:315
QTimeLine scrollTimeLine
Timer for smooth scrolling.
Definition: treecanvas.hh:337
VisualNode * pathHead
The head of the currently selected path.
Definition: treecanvas.hh:268
int layoutDoneTimerId
Timer id for delaying the update.
Definition: treecanvas.hh:354
const int maxScale
Maximum scale factor.
Definition: treecanvas.hh:58
bool autoHideFailed
Whether to hide failed subtrees automatically.
Definition: treecanvas.hh:298
Statistics stats
Statistics about the search tree.
Definition: treecanvas.hh:290
QMutex layoutMutex
Mutex for synchronizing layout and drawing.
Definition: treecanvas.hh:252
bool moveDuringSearch
Whether to move cursor during search.
Definition: treecanvas.hh:310
void solution(const Space *)
QVector< QPair< Inspector *, bool > > doubleClickInspectors
The registered click inspectors, and whether they are active.
Definition: treecanvas.hh:270
int targetY
Target y coordinate after smooth scrolling.
Definition: treecanvas.hh:343
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition: print.hpp:67
#define GECODE_GIST_EXPORT
Definition: qtgist.hh:63
bool smoothScrollAndZoom
Whether to use smooth scrolling and zooming.
Definition: treecanvas.hh:308
int c_d
The recomputation distance.
Definition: treecanvas.hh:313
const int maxAutoZoomScale
Maximum scale factor for automatic zoom.
Definition: treecanvas.hh:62
Node class that supports visual layout
Definition: visualnode.hh:129
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:212
QVector< QPair< Inspector *, bool > > solutionInspectors
The registered solution inspectors, and whether they are active.
Definition: treecanvas.hh:272
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:97
SearcherThread searcher
Search engine thread.
Definition: treecanvas.hh:254
bool stopSearchFlag
Flag signalling the search to stop.
Definition: treecanvas.hh:256
bool autoZoom
Whether to zoom automatically.
Definition: treecanvas.hh:300
int refreshPause
Time (in msec) to pause after each refresh.
Definition: treecanvas.hh:306
bool compareNodes
Whether node comparison action is running.
Definition: treecanvas.hh:282
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
int sourceY
Target y coordinate after smooth scrolling.
Definition: treecanvas.hh:345
int targetH
Target height after layout.
Definition: treecanvas.hh:350
void moveToNode(VisualNode *n, bool)
Options for Gist
Definition: gist.hh:238
QTimeLine zoomTimeLine
Timer for smooth zooming.
Definition: treecanvas.hh:335
void update(int w, int h, int scale0)
A thread that concurrently explores the tree.
Definition: treecanvas.hh:68
Statistics about the search tree
Definition: spacenode.hh:63
Node::NodeAllocator * na
Allocator for nodes.
Definition: treecanvas.hh:260
A canvas that displays the search tree.
Definition: treecanvas.hh:91
QVector< QPair< Comparator *, bool > > comparators
The registered comparators, and whether they are active.
Definition: treecanvas.hh:276
VisualNode * currentNode
The currently selected node.
Definition: treecanvas.hh:266