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 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
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
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 }
00278
00279 void
00280 GistMainWindow::about(void) {
00281 aboutGist.show();
00282 }
00283
00284 void
00285 GistMainWindow::preferences(bool setup) {
00286 PreferencesDialog pd(opt, this);
00287 if (setup) {
00288 c->setAutoZoom(pd.zoom);
00289 }
00290 if (setup || pd.exec() == QDialog::Accepted) {
00291 c->setAutoHideFailed(pd.hideFailed);
00292 c->setRefresh(pd.refresh);
00293 c->setRefreshPause(pd.refreshPause);
00294 c->setSmoothScrollAndZoom(pd.smoothScrollAndZoom);
00295 c->setMoveDuringSearch(pd.moveDuringSearch);
00296 c->setRecompDistances(pd.c_d,pd.a_d);
00297 opt.c_d = pd.c_d;
00298 opt.a_d = pd.a_d;
00299 c->setShowCopies(pd.copies);
00300 }
00301 }
00302
00303 void
00304 GistMainWindow::populateInspectorSelection(void) {
00305 doubleClickInspectorsMenu->clear();
00306 doubleClickInspectorsMenu->addActions(
00307 c->doubleClickInspectorGroup->actions());
00308 solutionInspectorsMenu->clear();
00309 solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
00310 moveInspectorsMenu->clear();
00311 moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
00312 comparatorsMenu->clear();
00313 comparatorsMenu->addActions(c->comparatorGroup->actions());
00314 }
00315
00316 void
00317 GistMainWindow::populateBookmarks(void) {
00318 bookmarksMenu->clear();
00319 bookmarksMenu->addAction(c->bookmarkNode);
00320 bookmarksMenu->addSeparator();
00321 bookmarksMenu->addActions(c->bookmarksGroup->actions());
00322 }
00323
00324 void
00325 GistMainWindow::populateInspectors(void) {
00326 inspectNodeMenu->clear();
00327 inspectNodeMenu->addAction(c->inspect);
00328 inspectNodeMenu->addSeparator();
00329 inspectNodeMenu->addActions(c->inspectGroup->actions());
00330 inspectNodeBeforeFPMenu->clear();
00331 inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
00332 inspectNodeBeforeFPMenu->addSeparator();
00333 inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
00334 }
00335
00336 }}
00337
00338