treecanvas.hh
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Guido Tack <tack@gecode.org> 00005 * 00006 * Copyright: 00007 * Guido Tack, 2006 00008 * 00009 * Last modified: 00010 * $Date: 2010-04-06 14:58:53 +0200 (Tue, 06 Apr 2010) $ by $Author: tack $ 00011 * $Revision: 10649 $ 00012 * 00013 * This file is part of Gecode, the generic constraint 00014 * development environment: 00015 * http://www.gecode.org 00016 * 00017 * Permission is hereby granted, free of charge, to any person obtaining 00018 * a copy of this software and associated documentation files (the 00019 * "Software"), to deal in the Software without restriction, including 00020 * without limitation the rights to use, copy, modify, merge, publish, 00021 * distribute, sublicense, and/or sell copies of the Software, and to 00022 * permit persons to whom the Software is furnished to do so, subject to 00023 * the following conditions: 00024 * 00025 * The above copyright notice and this permission notice shall be 00026 * included in all copies or substantial portions of the Software. 00027 * 00028 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00029 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00030 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00031 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00032 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00033 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00034 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 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 // STATISTICS: gist-any