Generated on Mon Sep 17 2012 22:20:33 for Gecode by doxygen 1.8.1.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: 2010-08-12 18:29:27 +1000 (Thu, 12 Aug 2010) $ by $Author: tack $
11  * $Revision: 11346 $
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 
43 #include <gecode/kernel.hh>
44 #include <gecode/gist.hh>
45 
47 
48 namespace Gecode { namespace Gist {
49 
51  namespace LayoutConfig {
53  const int minScale = 10;
55  const int maxScale = 400;
57  const int defScale = 100;
60  }
61 
62  class TreeCanvas;
63 
65  class SearcherThread : public QThread {
66  Q_OBJECT
67  private:
68  VisualNode* node;
69  int depth;
70  bool a;
71  TreeCanvas* t;
72  void updateCanvas(void);
73  public:
74  void search(VisualNode* n, bool all, TreeCanvas* ti);
75 
76  Q_SIGNALS:
77  void update(int w, int h, int scale0);
78  void statusChanged(bool);
79  void scaleChanged(int);
80  void solution(const Space*);
81  void searchFinished(void);
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);
155 
157  void stopSearch(void);
158 
160  void reset(void);
161 
163  void navUp(void);
165  void navDown(void);
167  void navLeft(void);
169  void navRight(void);
171  void navRoot(void);
173  void navNextSol(bool back = false);
175  void navPrevSol(void);
176 
178  void bookmarkNode(void);
180  void setPath(void);
182  void inspectPath(void);
184  void startCompareNodes(void);
186  void startCompareNodesBeforeFP(void);
187 
189  void emitStatusChanged(void);
190 
192  void setRecompDistances(int c_d, int a_d);
194  void setAutoHideFailed(bool b);
196  void setAutoZoom(bool b);
198  bool getAutoHideFailed(void);
200  bool getAutoZoom(void);
202  void setShowCopies(bool b);
204  bool getShowCopies(void);
206  void setRefresh(int i);
208  void setRefreshPause(int i);
210  bool getSmoothScrollAndZoom(void);
212  void setSmoothScrollAndZoom(bool b);
214  void resizeToOuter(void);
215 
217  bool finish(void);
218 
219  Q_SIGNALS:
221  void scaleChanged(int);
223  void autoZoomChanged(bool);
225  void contextMenu(QContextMenuEvent*);
227  void statusChanged(VisualNode*,const Statistics&, bool);
229  void solution(const Space*);
231  void searchFinished(void);
233  void addedBookmark(const QString& id);
235  void removedBookmark(int idx);
236  protected:
238  QMutex mutex;
240  QMutex layoutMutex;
258  QVector<QPair<Inspector*,bool> > doubleClickInspectors;
260  QVector<QPair<Inspector*,bool> > solutionInspectors;
262  QVector<QPair<Inspector*,bool> > moveInspectors;
264  QVector<QPair<Comparator*,bool> > comparators;
265 
267  QVector<VisualNode*> bookmarks;
268 
273 
275  QSlider* scaleBar;
276 
279 
281  double scale;
283  int xtrans;
284 
288  bool autoZoom;
292  int refresh;
297 
299  int c_d;
301  int a_d;
302 
304  VisualNode* eventNode(QEvent *event);
306  bool event(QEvent *event);
308  void paintEvent(QPaintEvent* event);
310  void mousePressEvent(QMouseEvent* event);
312  void mouseDoubleClickEvent(QMouseEvent* event);
314  void contextMenuEvent(QContextMenuEvent* event);
316  void resizeEvent(QResizeEvent* event);
318  void wheelEvent(QWheelEvent* event);
320  void setCurrentNode(VisualNode* n, bool update=true);
321 
323  QTimeLine zoomTimeLine;
325  QTimeLine scrollTimeLine;
327  int targetX;
329  int sourceX;
331  int targetY;
333  int sourceY;
334 
336  int targetW;
338  int targetH;
343 
345  virtual void timerEvent(QTimerEvent* e);
346 
347  public Q_SLOTS:
349  void update(void);
351  void scroll(void);
353  void layoutDone(int w, int h, int scale0);
354  private Q_SLOTS:
356  void statusChanged(bool);
358  void exportNodePDF(VisualNode* n);
360  void inspectSolution(const Space* s);
362  void scroll(int i);
363  };
364 
365 }}
366 
367 #endif
368 
369 // STATISTICS: gist-any