Generated on Tue Apr 18 10:21:46 2017 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  *  Last modified:
00010  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00011  *     $Revision: 14967 $
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 #if QT_VERSION >= 0x050000
00043 #include <QtWidgets>
00044 #endif
00045 
00046 #include <gecode/kernel.hh>
00047 #include <gecode/gist.hh>
00048 
00049 #include <gecode/gist/visualnode.hh>
00050 
00051 namespace Gecode {  namespace Gist {
00052 
00054   namespace LayoutConfig {
00056     const int minScale = 10;
00058     const int maxScale = 400;
00060     const int defScale = 100;
00062     const int maxAutoZoomScale = defScale;
00063   }
00064 
00065   class TreeCanvas;
00066 
00068   class SearcherThread : public QThread {
00069     Q_OBJECT
00070   private:
00071     VisualNode* node;
00072     int depth;
00073     bool a;
00074     TreeCanvas* t;
00075     void updateCanvas(void);
00076   public:
00077     void search(VisualNode* n, bool all, TreeCanvas* ti);
00078 
00079   Q_SIGNALS:
00080     void update(int w, int h, int scale0);
00081     void statusChanged(bool);
00082     void scaleChanged(int);
00083     void solution(const Space*);
00084     void searchFinished(void);
00085     void moveToNode(VisualNode* n,bool);
00086   protected:
00087     void run(void);
00088   };
00089 
00091   class GECODE_GIST_EXPORT TreeCanvas : public QWidget {
00092     Q_OBJECT
00093 
00094     friend class SearcherThread;
00095     friend class Gist;
00096 
00097   public:
00099     TreeCanvas(Space* rootSpace, bool bab, QWidget* parent,
00100                const Options& opt);
00102     ~TreeCanvas(void);
00103 
00105     void addDoubleClickInspector(Inspector* i);
00107     void activateDoubleClickInspector(int i, bool active);
00109     void addSolutionInspector(Inspector* i);
00111     void activateSolutionInspector(int i, bool active);
00113     void addMoveInspector(Inspector* i);
00115     void activateMoveInspector(int i, bool active);
00117     void addComparator(Comparator* c);
00119     void activateComparator(int i, bool active);
00120 
00121   public Q_SLOTS:
00123     void scaleTree(int scale0, int zoomx=-1, int zoomy=-1);
00124 
00126     void searchAll(void);
00128     void searchOne(void);
00130     void toggleHidden(void);
00132     void hideFailed(void);
00134     void unhideAll(void);
00136     void toggleStop(void);
00138     void unstopAll(void);
00140     void exportPDF(void);
00142     void exportWholeTreePDF(void);
00144     void print(void);
00146     void zoomToFit(void);
00148     void centerCurrentNode(void);
00156     void inspectCurrentNode(bool fix=true, int inspectorNo=-1);
00158     void inspectBeforeFP(void);
00160     void labelBranches(void);
00162     void labelPath(void);
00163 
00165     void stopSearch(void);
00166 
00168     void reset(void);
00169 
00171     void navUp(void);
00173     void navDown(void);
00175     void navLeft(void);
00177     void navRight(void);
00179     void navRoot(void);
00181     void navNextSol(bool back = false);
00183     void navPrevSol(void);
00184 
00186     void bookmarkNode(void);
00188     void setPath(void);
00190     void inspectPath(void);
00192     void startCompareNodes(void);
00194     void startCompareNodesBeforeFP(void);
00195 
00197     void emitStatusChanged(void);
00198 
00200     void setRecompDistances(int c_d, int a_d);
00202     void setAutoHideFailed(bool b);
00204     void setAutoZoom(bool b);
00206     bool getAutoHideFailed(void);
00208     bool getAutoZoom(void);
00210     void setShowCopies(bool b);
00212     bool getShowCopies(void);
00214     void setRefresh(int i);
00216     void setRefreshPause(int i);
00218     bool getSmoothScrollAndZoom(void);
00220     void setSmoothScrollAndZoom(bool b);
00222     bool getMoveDuringSearch(void);
00224     void setMoveDuringSearch(bool b);
00226     void resizeToOuter(void);
00227 
00229     bool finish(void);
00230 
00231   Q_SIGNALS:
00233     void scaleChanged(int);
00235     void autoZoomChanged(bool);
00237     void contextMenu(QContextMenuEvent*);
00239     void statusChanged(VisualNode*,const Statistics&, bool);
00241     void solution(const Space*);
00243     void searchFinished(void);
00245     void addedBookmark(const QString& id);
00247     void removedBookmark(int idx);
00248   protected:
00250     QMutex mutex;
00252     QMutex layoutMutex;
00254     SearcherThread searcher;
00256     bool stopSearchFlag;
00258     bool finishedFlag;
00260     Node::NodeAllocator* na;
00262     VisualNode* root;
00264     BestNode* curBest;
00266     VisualNode* currentNode;
00268     VisualNode* pathHead;
00270     QVector<QPair<Inspector*,bool> > doubleClickInspectors;
00272     QVector<QPair<Inspector*,bool> > solutionInspectors;
00274     QVector<QPair<Inspector*,bool> > moveInspectors;
00276     QVector<QPair<Comparator*,bool> > comparators;
00277 
00279     QVector<VisualNode*> bookmarks;
00280 
00282     bool compareNodes;
00284     bool compareNodesBeforeFP;
00285 
00287     QSlider* scaleBar;
00288 
00290     Statistics stats;
00291 
00293     double scale;
00295     int xtrans;
00296 
00298     bool autoHideFailed;
00300     bool autoZoom;
00302     bool showCopies;
00304     int refresh;
00306     int refreshPause;
00308     bool smoothScrollAndZoom;
00310     bool moveDuringSearch;
00311 
00313     int c_d;
00315     int a_d;
00316 
00318     VisualNode* eventNode(QEvent *event);
00320     bool event(QEvent *event);
00322     void paintEvent(QPaintEvent* event);
00324     void mousePressEvent(QMouseEvent* event);
00326     void mouseDoubleClickEvent(QMouseEvent* event);
00328     void contextMenuEvent(QContextMenuEvent* event);
00330     void resizeEvent(QResizeEvent* event);
00332     void wheelEvent(QWheelEvent* event);
00333 
00335     QTimeLine zoomTimeLine;
00337     QTimeLine scrollTimeLine;
00339     int targetX;
00341     int sourceX;
00343     int targetY;
00345     int sourceY;
00346 
00348     int targetW;
00350     int targetH;
00352     int targetScale;
00354     int layoutDoneTimerId;
00355 
00357     virtual void timerEvent(QTimerEvent* e);
00358 
00359   public Q_SLOTS:
00361     void update(void);
00363     void scroll(void);
00365     void layoutDone(int w, int h, int scale0);
00367     void setCurrentNode(VisualNode* n, bool finished=true, bool update=true);
00368   private Q_SLOTS:
00370     void statusChanged(bool);
00372     void exportNodePDF(VisualNode* n);
00374     void inspectSolution(const Space* s);
00376     void scroll(int i);
00377   };
00378 
00379 }}
00380 
00381 #endif
00382 
00383 // STATISTICS: gist-any