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

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: 2009-09-29 12:55:58 +0200 (Tue, 29 Sep 2009) $ by $Author: tack $
00011  *     $Revision: 9768 $
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     {
00086       unsigned int i = 0;
00087       while (opt.inspect.solution(i)) {
00088         c->addSolutionInspector(opt.inspect.solution(i++));
00089       }
00090       i = 0;
00091       while (opt.inspect.click(i)) {
00092         c->addDoubleClickInspector(opt.inspect.click(i++));
00093       }
00094     }
00095     setCentralWidget(c);
00096     setWindowTitle(tr("Gist"));
00097 
00098     Logos logos;
00099     QPixmap myPic;
00100     myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
00101     setWindowIcon(myPic);
00102 
00103     resize(500,500);
00104     setMinimumSize(400, 200);
00105 
00106     menuBar = new QMenuBar(0);
00107 
00108     QMenu* fileMenu = menuBar->addMenu(tr("&File"));
00109     fileMenu->addAction(c->print);
00110 #if QT_VERSION >= 0x040400
00111     fileMenu->addAction(c->exportWholeTreePDF);
00112 #endif
00113     QAction* quitAction = fileMenu->addAction(tr("Quit"));
00114     quitAction->setShortcut(QKeySequence("Ctrl+Q"));
00115     connect(quitAction, SIGNAL(triggered()),
00116             this, SLOT(close()));
00117     QAction* prefAction = fileMenu->addAction(tr("Preferences"));
00118     connect(prefAction, SIGNAL(triggered()), this, SLOT(preferences()));
00119 
00120     QMenu* nodeMenu = menuBar->addMenu(tr("&Node"));
00121     nodeMenu->addAction(c->inspect);
00122     nodeMenu->addAction(c->setPath);
00123     nodeMenu->addAction(c->inspectPath);
00124     nodeMenu->addAction(c->showNodeStats);
00125     nodeMenu->addSeparator();
00126     nodeMenu->addAction(c->navUp);
00127     nodeMenu->addAction(c->navDown);
00128     nodeMenu->addAction(c->navLeft);
00129     nodeMenu->addAction(c->navRight);
00130     nodeMenu->addAction(c->navRoot);
00131     nodeMenu->addAction(c->navNextSol);
00132     nodeMenu->addAction(c->navPrevSol);
00133     nodeMenu->addSeparator();
00134     nodeMenu->addAction(c->toggleHidden);
00135     nodeMenu->addAction(c->hideFailed);
00136     nodeMenu->addAction(c->unhideAll);
00137     nodeMenu->addSeparator();
00138     nodeMenu->addAction(c->zoomToFit);
00139     nodeMenu->addAction(c->center);
00140 #if QT_VERSION >= 0x040400
00141     nodeMenu->addAction(c->exportPDF);
00142 #endif
00143 
00144     QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
00145     searchMenu->addAction(c->searchNext);
00146     searchMenu->addAction(c->searchAll);
00147     searchMenu->addSeparator();
00148     searchMenu->addAction(c->stop);
00149     searchMenu->addSeparator();
00150     searchMenu->addAction(c->reset);
00151 
00152     QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
00153     doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
00154     connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
00155             this, SLOT(populateInspectors()));
00156     toolsMenu->addMenu(doubleClickInspectorsMenu);
00157     solutionInspectorsMenu = new QMenu("Solution inspectors");
00158     connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
00159             this, SLOT(populateInspectors()));
00160     toolsMenu->addMenu(solutionInspectorsMenu);
00161 
00162     QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
00163     QAction* aboutAction = helpMenu->addAction(tr("About"));
00164     connect(aboutAction, SIGNAL(triggered()),
00165             this, SLOT(about()));
00166 
00167     // Don't add the menu bar on Mac OS X
00168 #ifndef Q_WS_MAC
00169     setMenuBar(menuBar);
00170 #endif
00171 
00172     // Set up status bar
00173     QWidget* stw = new QWidget();
00174     QHBoxLayout* hbl = new QHBoxLayout();
00175     hbl->setContentsMargins(0,0,0,0);
00176     wmpLabel = new QLabel("");
00177     hbl->addWidget(wmpLabel);
00178     hbl->addWidget(new QLabel("Depth:"));
00179     depthLabel = new QLabel("0");
00180     hbl->addWidget(depthLabel);
00181     hbl->addWidget(new NodeWidget(SOLVED));
00182     solvedLabel = new QLabel("0");
00183     hbl->addWidget(solvedLabel);
00184     hbl->addWidget(new NodeWidget(FAILED));
00185     failedLabel = new QLabel("0");
00186     hbl->addWidget(failedLabel);
00187     hbl->addWidget(new NodeWidget(BRANCH));
00188     choicesLabel = new QLabel("0");
00189     hbl->addWidget(choicesLabel);
00190     hbl->addWidget(new NodeWidget(UNDETERMINED));
00191     openLabel = new QLabel("     0");
00192     hbl->addWidget(openLabel);
00193     stw->setLayout(hbl);
00194     statusBar()->addPermanentWidget(stw);
00195 
00196     isSearching = false;
00197     statusBar()->showMessage("Ready");
00198 
00199     connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
00200             this,SLOT(statusChanged(const Statistics&,bool)));
00201 
00202     connect(c,SIGNAL(finished(void)),this,SLOT(close(void)));
00203 
00204     preferences(true);
00205     show();
00206     c->reset->trigger();
00207   }
00208 
00209   void
00210   GistMainWindow::closeEvent(QCloseEvent* event) {
00211     if (c->finish())
00212       event->accept();
00213     else
00214       event->ignore();
00215   }
00216 
00217   void
00218   GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
00219     if (isSearching && finished) {
00220       statusBar()->showMessage("Ready");
00221       isSearching = false;
00222     } else if (!isSearching && !finished) {
00223       statusBar()->showMessage("Searching");
00224       isSearching = true;
00225     }
00226     depthLabel->setNum(stats.maxDepth);
00227     solvedLabel->setNum(stats.solutions);
00228     failedLabel->setNum(stats.failures);
00229     choicesLabel->setNum(stats.choices);
00230     openLabel->setNum(stats.undetermined);
00231     if (stats.wmp)
00232       wmpLabel->setText("WMP");
00233     else
00234       wmpLabel->setText("");
00235   }
00236 
00237   void
00238   GistMainWindow::about(void) {
00239     aboutGist.show();
00240   }
00241 
00242   void
00243   GistMainWindow::preferences(bool setup) {
00244     PreferencesDialog pd(opt, this);
00245     if (setup) {
00246       c->setAutoZoom(pd.zoom);
00247     }
00248     if (setup || pd.exec() == QDialog::Accepted) {
00249       c->setAutoHideFailed(pd.hideFailed);
00250       c->setRefresh(pd.refresh);
00251       c->setSmoothScrollAndZoom(pd.smoothScrollAndZoom);
00252       c->setRecompDistances(pd.c_d,pd.a_d);
00253       opt.c_d = pd.c_d;
00254       opt.a_d = pd.a_d;
00255       c->setShowCopies(pd.copies);
00256     }
00257   }
00258 
00259   void
00260   GistMainWindow::populateInspectors(void) {
00261     doubleClickInspectorsMenu->clear();
00262     doubleClickInspectorsMenu->addActions(
00263       c->doubleClickInspectorGroup->actions());
00264     solutionInspectorsMenu->clear();
00265     solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
00266   }
00267 
00268 }}
00269 
00270 // STATISTICS: gist-any