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