00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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->labelBranches);
00148 nodeMenu->addAction(c->labelPath);
00149 nodeMenu->addAction(c->toggleStop);
00150 nodeMenu->addAction(c->unstopAll);
00151 nodeMenu->addSeparator();
00152 nodeMenu->addAction(c->zoomToFit);
00153 nodeMenu->addAction(c->center);
00154 #if QT_VERSION >= 0x040400
00155 nodeMenu->addAction(c->exportPDF);
00156 #endif
00157
00158 QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
00159 searchMenu->addAction(c->searchNext);
00160 searchMenu->addAction(c->searchAll);
00161 searchMenu->addSeparator();
00162 searchMenu->addAction(c->stop);
00163 searchMenu->addSeparator();
00164 searchMenu->addAction(c->reset);
00165
00166 QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
00167 doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
00168 connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
00169 this, SLOT(populateInspectorSelection()));
00170 toolsMenu->addMenu(doubleClickInspectorsMenu);
00171 solutionInspectorsMenu = new QMenu("Solution inspectors");
00172 connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
00173 this, SLOT(populateInspectorSelection()));
00174 toolsMenu->addMenu(solutionInspectorsMenu);
00175 moveInspectorsMenu = new QMenu("Move inspectors");
00176 connect(moveInspectorsMenu, SIGNAL(aboutToShow()),
00177 this, SLOT(populateInspectorSelection()));
00178 toolsMenu->addMenu(moveInspectorsMenu);
00179 comparatorsMenu = new QMenu("Comparators");
00180 connect(comparatorsMenu, SIGNAL(aboutToShow()),
00181 this, SLOT(populateInspectorSelection()));
00182 toolsMenu->addMenu(comparatorsMenu);
00183
00184 QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
00185 QAction* aboutAction = helpMenu->addAction(tr("About"));
00186 connect(aboutAction, SIGNAL(triggered()),
00187 this, SLOT(about()));
00188
00189
00190 #ifndef Q_WS_MAC
00191 setMenuBar(menuBar);
00192 #endif
00193
00194
00195 QWidget* stw = new QWidget();
00196 QHBoxLayout* hbl = new QHBoxLayout();
00197 hbl->setContentsMargins(0,0,0,0);
00198 wmpLabel = new QLabel("");
00199 hbl->addWidget(wmpLabel);
00200 hbl->addWidget(new QLabel("Depth:"));
00201 depthLabel = new QLabel("0");
00202 hbl->addWidget(depthLabel);
00203 hbl->addWidget(new NodeWidget(SOLVED));
00204 solvedLabel = new QLabel("0");
00205 hbl->addWidget(solvedLabel);
00206 hbl->addWidget(new NodeWidget(FAILED));
00207 failedLabel = new QLabel("0");
00208 hbl->addWidget(failedLabel);
00209 hbl->addWidget(new NodeWidget(BRANCH));
00210 choicesLabel = new QLabel("0");
00211 hbl->addWidget(choicesLabel);
00212 hbl->addWidget(new NodeWidget(UNDETERMINED));
00213 openLabel = new QLabel(" 0");
00214 hbl->addWidget(openLabel);
00215 stw->setLayout(hbl);
00216 statusBar()->addPermanentWidget(stw);
00217
00218 isSearching = false;
00219 statusBar()->showMessage("Ready");
00220
00221 connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
00222 this,SLOT(statusChanged(const Statistics&,bool)));
00223
00224 connect(c,SIGNAL(searchFinished(void)),this,SLOT(close(void)));
00225
00226 preferences(true);
00227 show();
00228 c->reset->trigger();
00229 }
00230
00231 void
00232 GistMainWindow::closeEvent(QCloseEvent* event) {
00233 if (c->finish())
00234 event->accept();
00235 else
00236 event->ignore();
00237 }
00238
00239 void
00240 GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
00241 if (stats.maxDepth==0) {
00242 isSearching = false;
00243 statusBar()->showMessage("Ready");
00244 prefAction->setEnabled(true);
00245 } else if (isSearching && finished) {
00246 isSearching = false;
00247 double ms = searchTimer.stop();
00248 double s = std::floor(ms / 1000.0);
00249 ms -= s*1000.0;
00250 double m = std::floor(s / 60.0);
00251 s -= m*60.0;
00252 double h = std::floor(m / 60.0);
00253 m -= h*60.0;
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 statusBar()->showMessage("Ready");
00267 prefAction->setEnabled(true);
00268 } else if (!isSearching && !finished) {
00269 prefAction->setEnabled(false);
00270 statusBar()->showMessage("Searching");
00271 isSearching = true;
00272 searchTimer.start();
00273 }
00274 depthLabel->setNum(stats.maxDepth);
00275 solvedLabel->setNum(stats.solutions);
00276 failedLabel->setNum(stats.failures);
00277 choicesLabel->setNum(stats.choices);
00278 openLabel->setNum(stats.undetermined);
00279 if (stats.wmp)
00280 wmpLabel->setText("WMP");
00281 else
00282 wmpLabel->setText("");
00283 }
00284
00285 void
00286 GistMainWindow::about(void) {
00287 aboutGist.show();
00288 }
00289
00290 void
00291 GistMainWindow::preferences(bool setup) {
00292 PreferencesDialog pd(opt, this);
00293 if (setup) {
00294 c->setAutoZoom(pd.zoom);
00295 }
00296 if (setup || pd.exec() == QDialog::Accepted) {
00297 c->setAutoHideFailed(pd.hideFailed);
00298 c->setRefresh(pd.refresh);
00299 c->setRefreshPause(pd.refreshPause);
00300 c->setSmoothScrollAndZoom(pd.smoothScrollAndZoom);
00301 c->setMoveDuringSearch(pd.moveDuringSearch);
00302 c->setRecompDistances(pd.c_d,pd.a_d);
00303 opt.c_d = pd.c_d;
00304 opt.a_d = pd.a_d;
00305 c->setShowCopies(pd.copies);
00306 }
00307 }
00308
00309 void
00310 GistMainWindow::populateInspectorSelection(void) {
00311 doubleClickInspectorsMenu->clear();
00312 doubleClickInspectorsMenu->addActions(
00313 c->doubleClickInspectorGroup->actions());
00314 solutionInspectorsMenu->clear();
00315 solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
00316 moveInspectorsMenu->clear();
00317 moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
00318 comparatorsMenu->clear();
00319 comparatorsMenu->addActions(c->comparatorGroup->actions());
00320 }
00321
00322 void
00323 GistMainWindow::populateBookmarks(void) {
00324 bookmarksMenu->clear();
00325 bookmarksMenu->addAction(c->bookmarkNode);
00326 bookmarksMenu->addSeparator();
00327 bookmarksMenu->addActions(c->bookmarksGroup->actions());
00328 }
00329
00330 void
00331 GistMainWindow::populateInspectors(void) {
00332 inspectNodeMenu->clear();
00333 inspectNodeMenu->addAction(c->inspect);
00334 inspectNodeMenu->addSeparator();
00335 inspectNodeMenu->addActions(c->inspectGroup->actions());
00336 inspectNodeBeforeFPMenu->clear();
00337 inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
00338 inspectNodeBeforeFPMenu->addSeparator();
00339 inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
00340 }
00341
00342 }}
00343
00344