Generated on Thu Mar 22 10:39:32 2012 for Gecode by doxygen 1.6.3

mainwindow.cpp

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-08-12 15:30:33 +0200 (Thu, 12 Aug 2010) $ by $Author: tack $
00011  *     $Revision: 11351 $
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 #include <gecode/gist/mainwindow.hh>
00039 #include <gecode/gist/preferences.hh>
00040 #include <gecode/gist/nodewidget.hh>
00041 #include <gecode/gist/drawingcursor.hh>
00042 
00043 #include <gecode/gist/gecodelogo.hh>
00044 
00045 namespace Gecode { namespace Gist {
00046 
00047   AboutGist::AboutGist(QWidget* parent) : QDialog(parent) {
00048 
00049     Logos logos;
00050     QPixmap myPic;
00051     myPic.loadFromData(logos.logo, logos.logoSize);
00052 
00053     QPixmap myPic2;
00054     myPic2.loadFromData(logos.gistLogo, logos.gistLogoSize);
00055     setWindowIcon(myPic2);
00056 
00057 
00058     setMinimumSize(300, 240);
00059     setMaximumSize(300, 240);
00060     QVBoxLayout* layout = new QVBoxLayout();
00061     QLabel* logo = new QLabel();
00062     logo->setPixmap(myPic);
00063     layout->addWidget(logo, 0, Qt::AlignCenter);
00064     QLabel* aboutLabel =
00065       new QLabel(tr("<h2>Gist</h2>"
00066                      "<p><b>The Gecode Interactive Search Tool</b</p> "
00067                     "<p>You can find more information about Gecode and Gist "
00068                     "at</p>"
00069                     "<p><a href='http://www.gecode.org'>www.gecode.org</a>"
00070                     "</p"));
00071     aboutLabel->setOpenExternalLinks(true);
00072     aboutLabel->setWordWrap(true);
00073     aboutLabel->setAlignment(Qt::AlignCenter);
00074     layout->addWidget(aboutLabel);
00075     setLayout(layout);
00076     setWindowTitle(tr("About Gist"));
00077     setAttribute(Qt::WA_QuitOnClose, false);
00078     setAttribute(Qt::WA_DeleteOnClose, false);
00079   }
00080 
00081   GistMainWindow::GistMainWindow(Space* root, bool bab,
00082                                  const Options& opt0)
00083   : opt(opt0), aboutGist(this) {
00084     c = new Gist(root,bab,this,opt);
00085     setCentralWidget(c);
00086     setWindowTitle(tr("Gist"));
00087 
00088     Logos logos;
00089     QPixmap myPic;
00090     myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
00091     setWindowIcon(myPic);
00092 
00093     resize(500,500);
00094     setMinimumSize(400, 200);
00095 
00096     menuBar = new QMenuBar(0);
00097 
00098     QMenu* fileMenu = menuBar->addMenu(tr("&File"));
00099     fileMenu->addAction(c->print);
00100 #if QT_VERSION >= 0x040400
00101     fileMenu->addAction(c->exportWholeTreePDF);
00102 #endif
00103     QAction* quitAction = fileMenu->addAction(tr("Quit"));
00104     quitAction->setShortcut(QKeySequence("Ctrl+Q"));
00105     connect(quitAction, SIGNAL(triggered()),
00106             this, SLOT(close()));
00107     prefAction = fileMenu->addAction(tr("Preferences"));
00108     connect(prefAction, SIGNAL(triggered()), this, SLOT(preferences()));
00109 
00110     QMenu* nodeMenu = menuBar->addMenu(tr("&Node"));
00111     
00112     inspectNodeMenu = new QMenu("Inspect");
00113     inspectNodeMenu->addAction(c->inspect);
00114     connect(inspectNodeMenu, SIGNAL(aboutToShow()),
00115             this, SLOT(populateInspectors()));
00116 
00117     inspectNodeBeforeFPMenu = new QMenu("Inspect before fixpoint");
00118     inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
00119     connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
00120             this, SLOT(populateInspectors()));
00121     populateInspectors();
00122     
00123     nodeMenu->addMenu(inspectNodeMenu);
00124     nodeMenu->addMenu(inspectNodeBeforeFPMenu);
00125     nodeMenu->addAction(c->compareNode);
00126     nodeMenu->addAction(c->compareNodeBeforeFP);
00127     nodeMenu->addAction(c->setPath);
00128     nodeMenu->addAction(c->inspectPath);
00129     nodeMenu->addAction(c->showNodeStats);
00130     bookmarksMenu = new QMenu("Bookmarks");
00131     bookmarksMenu->addAction(c->bookmarkNode);
00132     connect(bookmarksMenu, SIGNAL(aboutToShow()),
00133             this, SLOT(populateBookmarks()));
00134     nodeMenu->addMenu(bookmarksMenu);
00135     nodeMenu->addSeparator();
00136     nodeMenu->addAction(c->navUp);
00137     nodeMenu->addAction(c->navDown);
00138     nodeMenu->addAction(c->navLeft);
00139     nodeMenu->addAction(c->navRight);
00140     nodeMenu->addAction(c->navRoot);
00141     nodeMenu->addAction(c->navNextSol);
00142     nodeMenu->addAction(c->navPrevSol);
00143     nodeMenu->addSeparator();
00144     nodeMenu->addAction(c->toggleHidden);
00145     nodeMenu->addAction(c->hideFailed);
00146     nodeMenu->addAction(c->unhideAll);
00147     nodeMenu->addAction(c->toggleStop);
00148     nodeMenu->addAction(c->unstopAll);
00149     nodeMenu->addSeparator();
00150     nodeMenu->addAction(c->zoomToFit);
00151     nodeMenu->addAction(c->center);
00152 #if QT_VERSION >= 0x040400
00153     nodeMenu->addAction(c->exportPDF);
00154 #endif
00155 
00156     QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
00157     searchMenu->addAction(c->searchNext);
00158     searchMenu->addAction(c->searchAll);
00159     searchMenu->addSeparator();
00160     searchMenu->addAction(c->stop);
00161     searchMenu->addSeparator();
00162     searchMenu->addAction(c->reset);
00163 
00164     QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
00165     doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
00166     connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
00167             this, SLOT(populateInspectorSelection()));
00168     toolsMenu->addMenu(doubleClickInspectorsMenu);
00169     solutionInspectorsMenu = new QMenu("Solution inspectors");
00170     connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
00171             this, SLOT(populateInspectorSelection()));
00172     toolsMenu->addMenu(solutionInspectorsMenu);
00173     moveInspectorsMenu = new QMenu("Move inspectors");
00174     connect(moveInspectorsMenu, SIGNAL(aboutToShow()),
00175             this, SLOT(populateInspectorSelection()));
00176     toolsMenu->addMenu(moveInspectorsMenu);
00177     comparatorsMenu = new QMenu("Comparators");
00178     connect(comparatorsMenu, SIGNAL(aboutToShow()),
00179             this, SLOT(populateInspectorSelection()));
00180     toolsMenu->addMenu(comparatorsMenu);
00181 
00182     QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
00183     QAction* aboutAction = helpMenu->addAction(tr("About"));
00184     connect(aboutAction, SIGNAL(triggered()),
00185             this, SLOT(about()));
00186 
00187     // Don't add the menu bar on Mac OS X
00188 #ifndef Q_WS_MAC
00189     setMenuBar(menuBar);
00190 #endif
00191 
00192     // Set up status bar
00193     QWidget* stw = new QWidget();
00194     QHBoxLayout* hbl = new QHBoxLayout();
00195     hbl->setContentsMargins(0,0,0,0);
00196     wmpLabel = new QLabel("");
00197     hbl->addWidget(wmpLabel);
00198     hbl->addWidget(new QLabel("Depth:"));
00199     depthLabel = new QLabel("0");
00200     hbl->addWidget(depthLabel);
00201     hbl->addWidget(new NodeWidget(SOLVED));
00202     solvedLabel = new QLabel("0");
00203     hbl->addWidget(solvedLabel);
00204     hbl->addWidget(new NodeWidget(FAILED));
00205     failedLabel = new QLabel("0");
00206     hbl->addWidget(failedLabel);
00207     hbl->addWidget(new NodeWidget(BRANCH));
00208     choicesLabel = new QLabel("0");
00209     hbl->addWidget(choicesLabel);
00210     hbl->addWidget(new NodeWidget(UNDETERMINED));
00211     openLabel = new QLabel("     0");
00212     hbl->addWidget(openLabel);
00213     stw->setLayout(hbl);
00214     statusBar()->addPermanentWidget(stw);
00215 
00216     isSearching = false;
00217     statusBar()->showMessage("Ready");
00218 
00219     connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
00220             this,SLOT(statusChanged(const Statistics&,bool)));
00221 
00222     connect(c,SIGNAL(searchFinished(void)),this,SLOT(close(void)));
00223 
00224     preferences(true);
00225     show();
00226     c->reset->trigger();
00227   }
00228 
00229   void
00230   GistMainWindow::closeEvent(QCloseEvent* event) {
00231     if (c->finish())
00232       event->accept();
00233     else
00234       event->ignore();
00235   }
00236 
00237   void
00238   GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
00239     if (stats.maxDepth==0) {
00240       isSearching = false;
00241       statusBar()->showMessage("Ready");
00242       prefAction->setEnabled(true);
00243     } else if (isSearching && finished) {
00244       isSearching = false;
00245       double ms = searchTimer.stop();
00246       double s = std::floor(ms / 1000.0);
00247       ms -= s*1000.0;
00248       double m = std::floor(s / 60.0);
00249       s -= m*60.0;
00250       double h = std::floor(m / 60.0);
00251       m -= h*60.0;
00252 
00253       // QString t;
00254       // if (static_cast<int>(h) != 0)
00255       //   t += QString().setNum(static_cast<int>(h))+"h ";
00256       // if (static_cast<int>(m) != 0)
00257       //   t += QString().setNum(static_cast<int>(m))+"m ";
00258       // if (static_cast<int>(s) != 0)
00259       //   t += QString().setNum(static_cast<int>(s));
00260       // else
00261       //   t += "0";
00262       // t += "."+QString().setNum(static_cast<int>(ms))+"s";
00263       // statusBar()->showMessage(QString("Ready (search time ")+t+")");
00264       statusBar()->showMessage("Ready");
00265       prefAction->setEnabled(true);
00266     } else if (!isSearching && !finished) {
00267       prefAction->setEnabled(false);
00268       statusBar()->showMessage("Searching");
00269       isSearching = true;
00270       searchTimer.start();
00271     }
00272     depthLabel->setNum(stats.maxDepth);
00273     solvedLabel->setNum(stats.solutions);
00274     failedLabel->setNum(stats.failures);
00275     choicesLabel->setNum(stats.choices);
00276     openLabel->setNum(stats.undetermined);
00277     if (stats.wmp)
00278       wmpLabel->setText("WMP");
00279     else
00280       wmpLabel->setText("");
00281   }
00282 
00283   void
00284   GistMainWindow::about(void) {
00285     aboutGist.show();
00286   }
00287 
00288   void
00289   GistMainWindow::preferences(bool setup) {
00290     PreferencesDialog pd(opt, this);
00291     if (setup) {
00292       c->setAutoZoom(pd.zoom);
00293     }
00294     if (setup || pd.exec() == QDialog::Accepted) {
00295       c->setAutoHideFailed(pd.hideFailed);
00296       c->setRefresh(pd.refresh);
00297       c->setRefreshPause(pd.refreshPause);
00298       c->setSmoothScrollAndZoom(pd.smoothScrollAndZoom);
00299       c->setRecompDistances(pd.c_d,pd.a_d);
00300       opt.c_d = pd.c_d;
00301       opt.a_d = pd.a_d;
00302       c->setShowCopies(pd.copies);
00303     }
00304   }
00305 
00306   void
00307   GistMainWindow::populateInspectorSelection(void) {
00308     doubleClickInspectorsMenu->clear();
00309     doubleClickInspectorsMenu->addActions(
00310       c->doubleClickInspectorGroup->actions());
00311     solutionInspectorsMenu->clear();
00312     solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
00313     moveInspectorsMenu->clear();
00314     moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
00315     comparatorsMenu->clear();
00316     comparatorsMenu->addActions(c->comparatorGroup->actions());
00317   }
00318 
00319   void
00320   GistMainWindow::populateBookmarks(void) {
00321     bookmarksMenu->clear();
00322     bookmarksMenu->addAction(c->bookmarkNode);
00323     bookmarksMenu->addSeparator();
00324     bookmarksMenu->addActions(c->bookmarksGroup->actions());
00325   }
00326 
00327   void
00328   GistMainWindow::populateInspectors(void) {
00329     inspectNodeMenu->clear();
00330     inspectNodeMenu->addAction(c->inspect);
00331     inspectNodeMenu->addSeparator();
00332     inspectNodeMenu->addActions(c->inspectGroup->actions());
00333     inspectNodeBeforeFPMenu->clear();
00334     inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
00335     inspectNodeBeforeFPMenu->addSeparator();
00336     inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
00337   }
00338 
00339 }}
00340 
00341 // STATISTICS: gist-any