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 finished(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);
00108
00109 public Q_SLOTS:
00111 void scaleTree(int scale0);
00112
00114 void searchAll(void);
00116 void searchOne(void);
00118 void toggleHidden(void);
00120 void hideFailed(void);
00122 void unhideAll(void);
00124 void exportPDF(void);
00126 void exportWholeTreePDF(void);
00128 void print(void);
00130 void zoomToFit(void);
00132 void centerCurrentNode(void);
00134 void inspectCurrentNode(void);
00135
00137 void stopSearch(void);
00138
00140 void reset(void);
00141
00143 void navUp(void);
00145 void navDown(void);
00147 void navLeft(void);
00149 void navRight(void);
00151 void navRoot(void);
00153 void navNextSol(bool back = false);
00155 void navPrevSol(void);
00157 void markCurrentNode(int pit);
00158
00160 void setPath(void);
00162 void inspectPath(void);
00164 void emitStatusChanged(void);
00165
00167 void setRecompDistances(int c_d, int a_d);
00169 void setAutoHideFailed(bool b);
00171 void setAutoZoom(bool b);
00173 bool getAutoHideFailed(void);
00175 bool getAutoZoom(void);
00177 void setShowCopies(bool b);
00179 bool getShowCopies(void);
00181 void setRefresh(int i);
00183 bool getSmoothScrollAndZoom(void);
00185 void setSmoothScrollAndZoom(bool b);
00187 void resizeToOuter(void);
00188
00190 bool finish(void);
00191
00192 Q_SIGNALS:
00194 void scaleChanged(int);
00196 void autoZoomChanged(bool);
00198 void contextMenu(QContextMenuEvent*);
00200 void statusChanged(VisualNode*,const Statistics&, bool);
00202 void pointInTimeChanged(int pit);
00204 void solution(const Space*);
00206 void finished(void);
00207 protected:
00209 QMutex mutex;
00211 QMutex layoutMutex;
00213 SearcherThread searcher;
00215 bool stopSearchFlag;
00217 bool finishedFlag;
00219 Node::NodeAllocator* na;
00221 VisualNode* root;
00223 BestNode* curBest;
00225 VisualNode* currentNode;
00227 VisualNode* pathHead;
00229 QVector<VisualNode*> nodeMap;
00231 QVector<QPair<Inspector*,bool> > doubleClickInspectors;
00233 QVector<QPair<Inspector*,bool> > solutionInspectors;
00234
00236 QSlider* scaleBar;
00237
00239 Statistics stats;
00240
00242 double scale;
00244 int xtrans;
00245
00247 bool autoHideFailed;
00249 bool autoZoom;
00251 bool showCopies;
00253 int refresh;
00255 bool smoothScrollAndZoom;
00256
00258 int c_d;
00260 int a_d;
00261
00263 int nextPit;
00264
00266 VisualNode* eventNode(QEvent *event);
00268 bool event(QEvent *event);
00270 void paintEvent(QPaintEvent* event);
00272 void mousePressEvent(QMouseEvent* event);
00274 void mouseDoubleClickEvent(QMouseEvent* event);
00276 void contextMenuEvent(QContextMenuEvent* event);
00278 void setCurrentNode(VisualNode* n);
00280 void saveCurrentNode(void);
00281
00283 int targetZoom;
00285 double metaZoomCurrent;
00287 int zoomTimerId;
00288
00290 int targetScrollX;
00292 int targetScrollY;
00294 double metaScrollXCurrent;
00296 double metaScrollYCurrent;
00298 int scrollTimerId;
00299
00301 int targetW;
00303 int targetH;
00305 int targetScale;
00307 int layoutDoneTimerId;
00308
00310 virtual void timerEvent(QTimerEvent* e);
00311
00312 public Q_SLOTS:
00314 void update(void);
00316 void layoutDone(int w, int h, int scale0);
00317 private Q_SLOTS:
00319 void statusChanged(bool);
00321 void exportNodePDF(VisualNode* n);
00323 void inspectSolution(const Space* s);
00324 };
00325
00326 }}
00327
00328 #endif
00329
00330