treecanvas.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef GECODE_GIST_TREECANVAS_HH
00039 #define GECODE_GIST_TREECANVAS_HH
00040
00041 #include <QtGui>
00042
00043 #include <gecode/kernel.hh>
00044 #include <gecode/gist.hh>
00045
00046 #include <gecode/gist/visualnode.hh>
00047
00048 namespace Gecode { namespace Gist {
00049
00051 namespace LayoutConfig {
00053 const int minScale = 10;
00055 const int maxScale = 400;
00057 const int defScale = 100;
00059 const int maxAutoZoomScale = defScale;
00060 }
00061
00062 class TreeCanvas;
00063
00065 class SearcherThread : public QThread {
00066 Q_OBJECT
00067 private:
00068 VisualNode* node;
00069 int depth;
00070 bool a;
00071 TreeCanvas* t;
00072 void updateCanvas(void);
00073 public:
00074 void search(VisualNode* n, bool all, TreeCanvas* ti);
00075
00076 Q_SIGNALS:
00077 void update(int w, int h, int scale0);
00078 void statusChanged(bool);
00079 void scaleChanged(int);
00080 void solution(const Space*);
00081 void searchFinished(void);
00082 protected:
00083 void run(void);
00084 };
00085
00087 class GECODE_GIST_EXPORT TreeCanvas : public QWidget {
00088 Q_OBJECT
00089
00090 friend class SearcherThread;
00091 friend class Gist;
00092
00093 public:
00095 TreeCanvas(Space* rootSpace, bool bab, QWidget* parent,
00096 const Options& opt);
00098 ~TreeCanvas(void);
00099
00101 void addDoubleClickInspector(Inspector* i);
00103 void activateDoubleClickInspector(int i, bool active);
00105 void addSolutionInspector(Inspector* i);
00107 void activateSolutionInspector(int i, bool active);
00109 void addMoveInspector(Inspector* i);
00111 void activateMoveInspector(int i, bool active);
00113 void addComparator(Comparator* c);
00115 void activateComparator(int i, bool active);
00116
00117 public Q_SLOTS:
00119 void scaleTree(int scale0, int zoomx=-1, int zoomy=-1);
00120
00122 void searchAll(void);
00124 void searchOne(void);
00126 void toggleHidden(void);
00128 void hideFailed(void);
00130 void unhideAll(void);
00132 void toggleStop(void);
00134 void unstopAll(void);
00136 void exportPDF(void);
00138 void exportWholeTreePDF(void);
00140 void print(void);
00142 void zoomToFit(void);
00144 void centerCurrentNode(void);
00152 void inspectCurrentNode(bool fix=true, int inspectorNo=-1);
00154 void inspectBeforeFP(void);
00155
00157 void stopSearch(void);
00158
00160 void reset(void);
00161
00163 void navUp(void);
00165 void navDown(void);
00167 void navLeft(void);
00169 void navRight(void);
00171 void navRoot(void);
00173 void navNextSol(bool back = false);
00175 void navPrevSol(void);
00176
00178 void bookmarkNode(void);
00180 void setPath(void);
00182 void inspectPath(void);
00184 void startCompareNodes(void);
00186 void startCompareNodesBeforeFP(void);
00187
00189 void emitStatusChanged(void);
00190
00192 void setRecompDistances(int c_d, int a_d);
00194 void setAutoHideFailed(bool b);
00196 void setAutoZoom(bool b);
00198 bool getAutoHideFailed(void);
00200 bool getAutoZoom(void);
00202 void setShowCopies(bool b);
00204 bool getShowCopies(void);
00206 void setRefresh(int i);
00208 void setRefreshPause(int i);
00210 bool getSmoothScrollAndZoom(void);
00212 void setSmoothScrollAndZoom(bool b);
00214 void resizeToOuter(void);
00215
00217 bool finish(void);
00218
00219 Q_SIGNALS:
00221 void scaleChanged(int);
00223 void autoZoomChanged(bool);
00225 void contextMenu(QContextMenuEvent*);
00227 void statusChanged(VisualNode*,const Statistics&, bool);
00229 void solution(const Space*);
00231 void searchFinished(void);
00233 void addedBookmark(const QString& id);
00235 void removedBookmark(int idx);
00236 protected:
00238 QMutex mutex;
00240 QMutex layoutMutex;
00242 SearcherThread searcher;
00244 bool stopSearchFlag;
00246 bool finishedFlag;
00248 Node::NodeAllocator* na;
00250 VisualNode* root;
00252 BestNode* curBest;
00254 VisualNode* currentNode;
00256 VisualNode* pathHead;
00258 QVector<QPair<Inspector*,bool> > doubleClickInspectors;
00260 QVector<QPair<Inspector*,bool> > solutionInspectors;
00262 QVector<QPair<Inspector*,bool> > moveInspectors;
00264 QVector<QPair<Comparator*,bool> > comparators;
00265
00267 QVector<VisualNode*> bookmarks;
00268
00270 bool compareNodes;
00272 bool compareNodesBeforeFP;
00273
00275 QSlider* scaleBar;
00276
00278 Statistics stats;
00279
00281 double scale;
00283 int xtrans;
00284
00286 bool autoHideFailed;
00288 bool autoZoom;
00290 bool showCopies;
00292 int refresh;
00294 int refreshPause;
00296 bool smoothScrollAndZoom;
00297
00299 int c_d;
00301 int a_d;
00302
00304 VisualNode* eventNode(QEvent *event);
00306 bool event(QEvent *event);
00308 void paintEvent(QPaintEvent* event);
00310 void mousePressEvent(QMouseEvent* event);
00312 void mouseDoubleClickEvent(QMouseEvent* event);
00314 void contextMenuEvent(QContextMenuEvent* event);
00316 void resizeEvent(QResizeEvent* event);
00318 void wheelEvent(QWheelEvent* event);
00320 void setCurrentNode(VisualNode* n, bool update=true);
00321
00323 QTimeLine zoomTimeLine;
00325 QTimeLine scrollTimeLine;
00327 int targetX;
00329 int sourceX;
00331 int targetY;
00333 int sourceY;
00334
00336 int targetW;
00338 int targetH;
00340 int targetScale;
00342 int layoutDoneTimerId;
00343
00345 virtual void timerEvent(QTimerEvent* e);
00346
00347 public Q_SLOTS:
00349 void update(void);
00351 void scroll(void);
00353 void layoutDone(int w, int h, int scale0);
00354 private Q_SLOTS:
00356 void statusChanged(bool);
00358 void exportNodePDF(VisualNode* n);
00360 void inspectSolution(const Space* s);
00362 void scroll(int i);
00363 };
00364
00365 }}
00366
00367 #endif
00368
00369