Generated on Sat May 25 2013 18:00:35 for Gecode by doxygen 1.8.3.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: 2012-12-21 01:48:30 +0100 (Fri, 21 Dec 2012) $ by $Author: tack $
11  * $Revision: 13214 $
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);
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