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