Generated on Sat Nov 9 2013 19:18:27 for Gecode by doxygen 1.8.4
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