this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 *
6 * Copyright:
7 * Guido Tack, 2006
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <gecode/gist/mainwindow.hh>
35#include <gecode/gist/preferences.hh>
36#include <gecode/gist/nodewidget.hh>
37#include <gecode/gist/drawingcursor.hh>
38
39#include <gecode/gist/gecodelogo.hh>
40
41namespace Gecode { namespace Gist {
42
43 AboutGist::AboutGist(QWidget* parent) : QDialog(parent) {
44
45 Logos logos;
46 QPixmap myPic;
47 myPic.loadFromData(logos.logo, logos.logoSize);
48
49 QPixmap myPic2;
50 myPic2.loadFromData(logos.gistLogo, logos.gistLogoSize);
51 setWindowIcon(myPic2);
52
53
54 setMinimumSize(300, 240);
55 setMaximumSize(300, 240);
56 QVBoxLayout* layout = new QVBoxLayout();
57 QLabel* logo = new QLabel();
58 logo->setPixmap(myPic);
59 layout->addWidget(logo, 0, Qt::AlignCenter);
60 QLabel* aboutLabel =
61 new QLabel(tr("<h2>Gist</h2>"
62 "<p><b>The Gecode Interactive Search Tool</b</p> "
63 "<p>You can find more information about Gecode and Gist "
64 "at</p>"
65 "<p><a href='http://www.gecode.org'>www.gecode.org</a>"
66 "</p"));
67 aboutLabel->setOpenExternalLinks(true);
68 aboutLabel->setWordWrap(true);
69 aboutLabel->setAlignment(Qt::AlignCenter);
70 layout->addWidget(aboutLabel);
71 setLayout(layout);
72 setWindowTitle(tr("About Gist"));
73 setAttribute(Qt::WA_QuitOnClose, false);
74 setAttribute(Qt::WA_DeleteOnClose, false);
75 }
76
77 GistMainWindow::GistMainWindow(Space* root, bool bab,
78 const Options& opt0)
79 : opt(opt0), aboutGist(this) {
80 c = new Gist(root,bab,this,opt);
81 setCentralWidget(c);
82 setWindowTitle(tr("Gist"));
83
84 Logos logos;
85 QPixmap myPic;
86 myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
87 setWindowIcon(myPic);
88
89 resize(500,500);
90 setMinimumSize(400, 200);
91
92 menuBar = new QMenuBar(0);
93
94 QMenu* fileMenu = menuBar->addMenu(tr("&File"));
95 fileMenu->addAction(c->print);
96#if QT_VERSION >= 0x040400
97 fileMenu->addAction(c->exportWholeTreePDF);
98#endif
99 QAction* quitAction = fileMenu->addAction(tr("Quit"));
100 quitAction->setShortcut(QKeySequence("Ctrl+Q"));
101 connect(quitAction, SIGNAL(triggered()),
102 this, SLOT(close()));
103 prefAction = fileMenu->addAction(tr("Preferences"));
104 connect(prefAction, SIGNAL(triggered()), this, SLOT(preferences()));
105
106 QMenu* nodeMenu = menuBar->addMenu(tr("&Node"));
107
108 inspectNodeMenu = new QMenu("Inspect");
109 inspectNodeMenu->addAction(c->inspect);
110 connect(inspectNodeMenu, SIGNAL(aboutToShow()),
111 this, SLOT(populateInspectors()));
112
113 inspectNodeBeforeFPMenu = new QMenu("Inspect before fixpoint");
114 inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
115 connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
116 this, SLOT(populateInspectors()));
117 populateInspectors();
118
119 nodeMenu->addMenu(inspectNodeMenu);
120 nodeMenu->addMenu(inspectNodeBeforeFPMenu);
121 nodeMenu->addAction(c->compareNode);
122 nodeMenu->addAction(c->compareNodeBeforeFP);
123 nodeMenu->addAction(c->setPath);
124 nodeMenu->addAction(c->inspectPath);
125 nodeMenu->addAction(c->showNodeStats);
126 bookmarksMenu = new QMenu("Bookmarks");
127 bookmarksMenu->addAction(c->bookmarkNode);
128 connect(bookmarksMenu, SIGNAL(aboutToShow()),
129 this, SLOT(populateBookmarks()));
130 nodeMenu->addMenu(bookmarksMenu);
131 nodeMenu->addSeparator();
132 nodeMenu->addAction(c->navUp);
133 nodeMenu->addAction(c->navDown);
134 nodeMenu->addAction(c->navLeft);
135 nodeMenu->addAction(c->navRight);
136 nodeMenu->addAction(c->navRoot);
137 nodeMenu->addAction(c->navNextSol);
138 nodeMenu->addAction(c->navPrevSol);
139 nodeMenu->addSeparator();
140 nodeMenu->addAction(c->toggleHidden);
141 nodeMenu->addAction(c->hideFailed);
142 nodeMenu->addAction(c->unhideAll);
143 nodeMenu->addAction(c->labelBranches);
144 nodeMenu->addAction(c->labelPath);
145 nodeMenu->addAction(c->toggleStop);
146 nodeMenu->addAction(c->unstopAll);
147 nodeMenu->addSeparator();
148 nodeMenu->addAction(c->zoomToFit);
149 nodeMenu->addAction(c->center);
150#if QT_VERSION >= 0x040400
151 nodeMenu->addAction(c->exportPDF);
152#endif
153
154 QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
155 searchMenu->addAction(c->searchNext);
156 searchMenu->addAction(c->searchAll);
157 searchMenu->addSeparator();
158 searchMenu->addAction(c->stop);
159 searchMenu->addSeparator();
160 searchMenu->addAction(c->reset);
161
162 QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
163 doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
164 connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
165 this, SLOT(populateInspectorSelection()));
166 toolsMenu->addMenu(doubleClickInspectorsMenu);
167 solutionInspectorsMenu = new QMenu("Solution inspectors");
168 connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
169 this, SLOT(populateInspectorSelection()));
170 toolsMenu->addMenu(solutionInspectorsMenu);
171 moveInspectorsMenu = new QMenu("Move inspectors");
172 connect(moveInspectorsMenu, SIGNAL(aboutToShow()),
173 this, SLOT(populateInspectorSelection()));
174 toolsMenu->addMenu(moveInspectorsMenu);
175 comparatorsMenu = new QMenu("Comparators");
176 connect(comparatorsMenu, SIGNAL(aboutToShow()),
177 this, SLOT(populateInspectorSelection()));
178 toolsMenu->addMenu(comparatorsMenu);
179
180 QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
181 QAction* aboutAction = helpMenu->addAction(tr("About"));
182 connect(aboutAction, SIGNAL(triggered()),
183 this, SLOT(about()));
184
185 // Don't add the menu bar on Mac OS X
186#ifndef Q_WS_MAC
187 setMenuBar(menuBar);
188#endif
189
190 // Set up status bar
191 QWidget* stw = new QWidget();
192 QHBoxLayout* hbl = new QHBoxLayout();
193 hbl->setContentsMargins(0,0,0,0);
194 hbl->addWidget(new QLabel("Depth:"));
195 depthLabel = new QLabel("0");
196 hbl->addWidget(depthLabel);
197 hbl->addWidget(new NodeWidget(SOLVED));
198 solvedLabel = new QLabel("0");
199 hbl->addWidget(solvedLabel);
200 hbl->addWidget(new NodeWidget(FAILED));
201 failedLabel = new QLabel("0");
202 hbl->addWidget(failedLabel);
203 hbl->addWidget(new NodeWidget(BRANCH));
204 choicesLabel = new QLabel("0");
205 hbl->addWidget(choicesLabel);
206 hbl->addWidget(new NodeWidget(UNDETERMINED));
207 openLabel = new QLabel(" 0");
208 hbl->addWidget(openLabel);
209 stw->setLayout(hbl);
210 statusBar()->addPermanentWidget(stw);
211
212 isSearching = false;
213 statusBar()->showMessage("Ready");
214
215 connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
216 this,SLOT(statusChanged(const Statistics&,bool)));
217
218 connect(c,SIGNAL(searchFinished(void)),this,SLOT(close(void)));
219
220 preferences(true);
221 show();
222 c->reset->trigger();
223 }
224
225 void
226 GistMainWindow::closeEvent(QCloseEvent* event) {
227 if (c->finish())
228 event->accept();
229 else
230 event->ignore();
231 }
232
233 void
234 GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
235 if (stats.maxDepth==0) {
236 isSearching = false;
237 statusBar()->showMessage("Ready");
238 prefAction->setEnabled(true);
239 } else if (isSearching && finished) {
240 isSearching = false;
241 double ms = searchTimer.stop();
242 double s = std::floor(ms / 1000.0);
243 ms -= s*1000.0;
244 double m = std::floor(s / 60.0);
245 s -= m*60.0;
246 double h = std::floor(m / 60.0);
247 m -= h*60.0;
248
249 // QString t;
250 // if (static_cast<int>(h) != 0)
251 // t += QString().setNum(static_cast<int>(h))+"h ";
252 // if (static_cast<int>(m) != 0)
253 // t += QString().setNum(static_cast<int>(m))+"m ";
254 // if (static_cast<int>(s) != 0)
255 // t += QString().setNum(static_cast<int>(s));
256 // else
257 // t += "0";
258 // t += "."+QString().setNum(static_cast<int>(ms))+"s";
259 // statusBar()->showMessage(QString("Ready (search time ")+t+")");
260 statusBar()->showMessage("Ready");
261 prefAction->setEnabled(true);
262 } else if (!isSearching && !finished) {
263 prefAction->setEnabled(false);
264 statusBar()->showMessage("Searching");
265 isSearching = true;
266 searchTimer.start();
267 }
268 depthLabel->setNum(stats.maxDepth);
269 solvedLabel->setNum(stats.solutions);
270 failedLabel->setNum(stats.failures);
271 choicesLabel->setNum(stats.choices);
272 openLabel->setNum(stats.undetermined);
273 }
274
275 void
276 GistMainWindow::about(void) {
277 aboutGist.show();
278 }
279
280 void
281 GistMainWindow::preferences(bool setup) {
282 PreferencesDialog pd(opt, this);
283 if (setup) {
284 c->setAutoZoom(pd.zoom);
285 }
286 if (setup || pd.exec() == QDialog::Accepted) {
287 c->setAutoHideFailed(pd.hideFailed);
288 c->setRefresh(pd.refresh);
289 c->setRefreshPause(pd.refreshPause);
290 c->setSmoothScrollAndZoom(pd.smoothScrollAndZoom);
291 c->setMoveDuringSearch(pd.moveDuringSearch);
292 c->setRecompDistances(pd.c_d,pd.a_d);
293 opt.c_d = pd.c_d;
294 opt.a_d = pd.a_d;
295 c->setShowCopies(pd.copies);
296 }
297 }
298
299 void
300 GistMainWindow::populateInspectorSelection(void) {
301 doubleClickInspectorsMenu->clear();
302 doubleClickInspectorsMenu->addActions(
303 c->doubleClickInspectorGroup->actions());
304 solutionInspectorsMenu->clear();
305 solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
306 moveInspectorsMenu->clear();
307 moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
308 comparatorsMenu->clear();
309 comparatorsMenu->addActions(c->comparatorGroup->actions());
310 }
311
312 void
313 GistMainWindow::populateBookmarks(void) {
314 bookmarksMenu->clear();
315 bookmarksMenu->addAction(c->bookmarkNode);
316 bookmarksMenu->addSeparator();
317 bookmarksMenu->addActions(c->bookmarksGroup->actions());
318 }
319
320 void
321 GistMainWindow::populateInspectors(void) {
322 inspectNodeMenu->clear();
323 inspectNodeMenu->addAction(c->inspect);
324 inspectNodeMenu->addSeparator();
325 inspectNodeMenu->addActions(c->inspectGroup->actions());
326 inspectNodeBeforeFPMenu->clear();
327 inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
328 inspectNodeBeforeFPMenu->addSeparator();
329 inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
330 }
331
332}}
333
334// STATISTICS: gist-any