Generated on Fri Oct 19 11:25:00 2018 for Gecode by doxygen 1.6.3

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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  * Permission is hereby granted, free of charge, to any person obtaining
00014  * a copy of this software and associated documentation files (the
00015  * "Software"), to deal in the Software without restriction, including
00016  * without limitation the rights to use, copy, modify, merge, publish,
00017  * distribute, sublicense, and/or sell copies of the Software, and to
00018  * permit persons to whom the Software is furnished to do so, subject to
00019  * the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #ifndef GECODE_GIST_TREECANVAS_HH
00035 #define GECODE_GIST_TREECANVAS_HH
00036 
00037 #include <QtGui>
00038 #if QT_VERSION >= 0x050000
00039 #include <QtWidgets>
00040 #endif
00041 
00042 #include <gecode/kernel.hh>
00043 #include <gecode/gist.hh>
00044 
00045 #include <gecode/gist/visualnode.hh>
00046 
00047 namespace Gecode {  namespace Gist {
00048 
00050   namespace LayoutConfig {
00052     const int minScale = 10;
00054     const int maxScale = 400;
00056     const int defScale = 100;
00058     const int maxAutoZoomScale = defScale;
00059   }
00060 
00061   class TreeCanvas;
00062 
00064   class SearcherThread : public QThread {
00065     Q_OBJECT
00066   private:
00067     VisualNode* node;
00068     int depth;
00069     bool a;
00070     TreeCanvas* t;
00071     void updateCanvas(void);
00072   public:
00073     void search(VisualNode* n, bool all, TreeCanvas* ti);
00074 
00075   Q_SIGNALS:
00076     void update(int w, int h, int scale0);
00077     void statusChanged(bool);
00078     void scaleChanged(int);
00079     void solution(const Space*);
00080     void searchFinished(void);
00081     void moveToNode(VisualNode* n,bool);
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);
00156     void labelBranches(void);
00158     void labelPath(void);
00159 
00161     void stopSearch(void);
00162 
00164     void reset(void);
00165 
00167     void navUp(void);
00169     void navDown(void);
00171     void navLeft(void);
00173     void navRight(void);
00175     void navRoot(void);
00177     void navNextSol(bool back = false);
00179     void navPrevSol(void);
00180 
00182     void bookmarkNode(void);
00184     void setPath(void);
00186     void inspectPath(void);
00188     void startCompareNodes(void);
00190     void startCompareNodesBeforeFP(void);
00191 
00193     void emitStatusChanged(void);
00194 
00196     void setRecompDistances(int c_d, int a_d);
00198     void setAutoHideFailed(bool b);
00200     void setAutoZoom(bool b);
00202     bool getAutoHideFailed(void);
00204     bool getAutoZoom(void);
00206     void setShowCopies(bool b);
00208     bool getShowCopies(void);
00210     void setRefresh(int i);
00212     void setRefreshPause(int i);
00214     bool getSmoothScrollAndZoom(void);
00216     void setSmoothScrollAndZoom(bool b);
00218     bool getMoveDuringSearch(void);
00220     void setMoveDuringSearch(bool b);
00222     void resizeToOuter(void);
00223 
00225     bool finish(void);
00226 
00227   Q_SIGNALS:
00229     void scaleChanged(int);
00231     void autoZoomChanged(bool);
00233     void contextMenu(QContextMenuEvent*);
00235     void statusChanged(VisualNode*,const Statistics&, bool);
00237     void solution(const Space*);
00239     void searchFinished(void);
00241     void addedBookmark(const QString& id);
00243     void removedBookmark(int idx);
00244   protected:
00246     QMutex mutex;
00248     QMutex layoutMutex;
00250     SearcherThread searcher;
00252     bool stopSearchFlag;
00254     bool finishedFlag;
00256     Node::NodeAllocator* na;
00258     VisualNode* root;
00260     BestNode* curBest;
00262     VisualNode* currentNode;
00264     VisualNode* pathHead;
00266     QVector<QPair<Inspector*,bool> > doubleClickInspectors;
00268     QVector<QPair<Inspector*,bool> > solutionInspectors;
00270     QVector<QPair<Inspector*,bool> > moveInspectors;
00272     QVector<QPair<Comparator*,bool> > comparators;
00273 
00275     QVector<VisualNode*> bookmarks;
00276 
00278     bool compareNodes;
00280     bool compareNodesBeforeFP;
00281 
00283     QSlider* scaleBar;
00284 
00286     Statistics stats;
00287 
00289     double scale;
00291     int xtrans;
00292 
00294     bool autoHideFailed;
00296     bool autoZoom;
00298     bool showCopies;
00300     int refresh;
00302     int refreshPause;
00304     bool smoothScrollAndZoom;
00306     bool moveDuringSearch;
00307 
00309     int c_d;
00311     int a_d;
00312 
00314     VisualNode* eventNode(QEvent *event);
00316     bool event(QEvent *event);
00318     void paintEvent(QPaintEvent* event);
00320     void mousePressEvent(QMouseEvent* event);
00322     void mouseDoubleClickEvent(QMouseEvent* event);
00324     void contextMenuEvent(QContextMenuEvent* event);
00326     void resizeEvent(QResizeEvent* event);
00328     void wheelEvent(QWheelEvent* event);
00329 
00331     QTimeLine zoomTimeLine;
00333     QTimeLine scrollTimeLine;
00335     int targetX;
00337     int sourceX;
00339     int targetY;
00341     int sourceY;
00342 
00344     int targetW;
00346     int targetH;
00348     int targetScale;
00350     int layoutDoneTimerId;
00351 
00353     virtual void timerEvent(QTimerEvent* e);
00354 
00355   public Q_SLOTS:
00357     void update(void);
00359     void scroll(void);
00361     void layoutDone(int w, int h, int scale0);
00363     void setCurrentNode(VisualNode* n, bool finished=true, bool update=true);
00364   private Q_SLOTS:
00366     void statusChanged(bool);
00368     void exportNodePDF(VisualNode* n);
00370     void inspectSolution(const Space* s);
00372     void scroll(int i);
00373   };
00374 
00375 }}
00376 
00377 #endif
00378 
00379 // STATISTICS: gist-any