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 bool getSmoothScrollAndZoom(void);
00210 void setSmoothScrollAndZoom(bool b);
00212 void resizeToOuter(void);
00213
00215 bool finish(void);
00216
00217 Q_SIGNALS:
00219 void scaleChanged(int);
00221 void autoZoomChanged(bool);
00223 void contextMenu(QContextMenuEvent*);
00225 void statusChanged(VisualNode*,const Statistics&, bool);
00227 void solution(const Space*);
00229 void searchFinished(void);
00231 void addedBookmark(const QString& id);
00233 void removedBookmark(int idx);
00234 protected:
00236 QMutex mutex;
00238 QMutex layoutMutex;
00240 SearcherThread searcher;
00242 bool stopSearchFlag;
00244 bool finishedFlag;
00246 Node::NodeAllocator* na;
00248 VisualNode* root;
00250 BestNode* curBest;
00252 VisualNode* currentNode;
00254 VisualNode* pathHead;
00256 QVector<QPair<Inspector*,bool> > doubleClickInspectors;
00258 QVector<QPair<Inspector*,bool> > solutionInspectors;
00260 QVector<QPair<Inspector*,bool> > moveInspectors;
00262 QVector<QPair<Comparator*,bool> > comparators;
00263
00265 QVector<VisualNode*> bookmarks;
00266
00268 bool compareNodes;
00270 bool compareNodesBeforeFP;
00271
00273 QSlider* scaleBar;
00274
00276 Statistics stats;
00277
00279 double scale;
00281 int xtrans;
00282
00284 bool autoHideFailed;
00286 bool autoZoom;
00288 bool showCopies;
00290 int refresh;
00292 bool smoothScrollAndZoom;
00293
00295 int c_d;
00297 int a_d;
00298
00300 VisualNode* eventNode(QEvent *event);
00302 bool event(QEvent *event);
00304 void paintEvent(QPaintEvent* event);
00306 void mousePressEvent(QMouseEvent* event);
00308 void mouseDoubleClickEvent(QMouseEvent* event);
00310 void contextMenuEvent(QContextMenuEvent* event);
00312 void resizeEvent(QResizeEvent* event);
00314 void wheelEvent(QWheelEvent* event);
00316 void setCurrentNode(VisualNode* n, bool update=true);
00317
00319 QTimeLine zoomTimeLine;
00321 QTimeLine scrollTimeLine;
00323 int targetX;
00325 int sourceX;
00327 int targetY;
00329 int sourceY;
00330
00332 int targetW;
00334 int targetH;
00336 int targetScale;
00338 int layoutDoneTimerId;
00339
00341 virtual void timerEvent(QTimerEvent* e);
00342
00343 public Q_SLOTS:
00345 void update(void);
00347 void scroll(void);
00349 void layoutDone(int w, int h, int scale0);
00350 private Q_SLOTS:
00352 void statusChanged(bool);
00354 void exportNodePDF(VisualNode* n);
00356 void inspectSolution(const Space* s);
00358 void scroll(int i);
00359 };
00360
00361 }}
00362
00363 #endif
00364
00365