Generated on Mon Nov 30 23:53:19 2009 for Gecode by doxygen 1.6.1

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: 2009-05-14 10:44:50 +0200 (Thu, 14 May 2009) $ by $Author: tack $
00011  *     $Revision: 9107 $
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 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 // STATISTICS: gist-any