Generated on Thu Mar 7 2013 10:21:17 for Gecode by doxygen 1.8.3.1
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: 2010-08-12 23:30:33 +1000 (Thu, 12 Aug 2010) $ by $Author: tack $
11  * $Revision: 11351 $
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->toggleStop);
148  nodeMenu->addAction(c->unstopAll);
149  nodeMenu->addSeparator();
150  nodeMenu->addAction(c->zoomToFit);
151  nodeMenu->addAction(c->center);
152 #if QT_VERSION >= 0x040400
153  nodeMenu->addAction(c->exportPDF);
154 #endif
155 
156  QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
157  searchMenu->addAction(c->searchNext);
158  searchMenu->addAction(c->searchAll);
159  searchMenu->addSeparator();
160  searchMenu->addAction(c->stop);
161  searchMenu->addSeparator();
162  searchMenu->addAction(c->reset);
163 
164  QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
165  doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
166  connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
167  this, SLOT(populateInspectorSelection()));
168  toolsMenu->addMenu(doubleClickInspectorsMenu);
169  solutionInspectorsMenu = new QMenu("Solution inspectors");
170  connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
171  this, SLOT(populateInspectorSelection()));
172  toolsMenu->addMenu(solutionInspectorsMenu);
173  moveInspectorsMenu = new QMenu("Move inspectors");
174  connect(moveInspectorsMenu, SIGNAL(aboutToShow()),
175  this, SLOT(populateInspectorSelection()));
176  toolsMenu->addMenu(moveInspectorsMenu);
177  comparatorsMenu = new QMenu("Comparators");
178  connect(comparatorsMenu, SIGNAL(aboutToShow()),
179  this, SLOT(populateInspectorSelection()));
180  toolsMenu->addMenu(comparatorsMenu);
181 
182  QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
183  QAction* aboutAction = helpMenu->addAction(tr("About"));
184  connect(aboutAction, SIGNAL(triggered()),
185  this, SLOT(about()));
186 
187  // Don't add the menu bar on Mac OS X
188 #ifndef Q_WS_MAC
189  setMenuBar(menuBar);
190 #endif
191 
192  // Set up status bar
193  QWidget* stw = new QWidget();
194  QHBoxLayout* hbl = new QHBoxLayout();
195  hbl->setContentsMargins(0,0,0,0);
196  wmpLabel = new QLabel("");
197  hbl->addWidget(wmpLabel);
198  hbl->addWidget(new QLabel("Depth:"));
199  depthLabel = new QLabel("0");
200  hbl->addWidget(depthLabel);
201  hbl->addWidget(new NodeWidget(SOLVED));
202  solvedLabel = new QLabel("0");
203  hbl->addWidget(solvedLabel);
204  hbl->addWidget(new NodeWidget(FAILED));
205  failedLabel = new QLabel("0");
206  hbl->addWidget(failedLabel);
207  hbl->addWidget(new NodeWidget(BRANCH));
208  choicesLabel = new QLabel("0");
209  hbl->addWidget(choicesLabel);
210  hbl->addWidget(new NodeWidget(UNDETERMINED));
211  openLabel = new QLabel(" 0");
212  hbl->addWidget(openLabel);
213  stw->setLayout(hbl);
214  statusBar()->addPermanentWidget(stw);
215 
216  isSearching = false;
217  statusBar()->showMessage("Ready");
218 
219  connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
220  this,SLOT(statusChanged(const Statistics&,bool)));
221 
222  connect(c,SIGNAL(searchFinished(void)),this,SLOT(close(void)));
223 
224  preferences(true);
225  show();
226  c->reset->trigger();
227  }
228 
229  void
230  GistMainWindow::closeEvent(QCloseEvent* event) {
231  if (c->finish())
232  event->accept();
233  else
234  event->ignore();
235  }
236 
237  void
238  GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
239  if (stats.maxDepth==0) {
240  isSearching = false;
241  statusBar()->showMessage("Ready");
242  prefAction->setEnabled(true);
243  } else if (isSearching && finished) {
244  isSearching = false;
245  double ms = searchTimer.stop();
246  double s = std::floor(ms / 1000.0);
247  ms -= s*1000.0;
248  double m = std::floor(s / 60.0);
249  s -= m*60.0;
250  double h = std::floor(m / 60.0);
251  m -= h*60.0;
252 
253  // QString t;
254  // if (static_cast<int>(h) != 0)
255  // t += QString().setNum(static_cast<int>(h))+"h ";
256  // if (static_cast<int>(m) != 0)
257  // t += QString().setNum(static_cast<int>(m))+"m ";
258  // if (static_cast<int>(s) != 0)
259  // t += QString().setNum(static_cast<int>(s));
260  // else
261  // t += "0";
262  // t += "."+QString().setNum(static_cast<int>(ms))+"s";
263  // statusBar()->showMessage(QString("Ready (search time ")+t+")");
264  statusBar()->showMessage("Ready");
265  prefAction->setEnabled(true);
266  } else if (!isSearching && !finished) {
267  prefAction->setEnabled(false);
268  statusBar()->showMessage("Searching");
269  isSearching = true;
270  searchTimer.start();
271  }
272  depthLabel->setNum(stats.maxDepth);
273  solvedLabel->setNum(stats.solutions);
274  failedLabel->setNum(stats.failures);
275  choicesLabel->setNum(stats.choices);
276  openLabel->setNum(stats.undetermined);
277  if (stats.wmp)
278  wmpLabel->setText("WMP");
279  else
280  wmpLabel->setText("");
281  }
282 
283  void
285  aboutGist.show();
286  }
287 
288  void
290  PreferencesDialog pd(opt, this);
291  if (setup) {
292  c->setAutoZoom(pd.zoom);
293  }
294  if (setup || pd.exec() == QDialog::Accepted) {
296  c->setRefresh(pd.refresh);
299  c->setRecompDistances(pd.c_d,pd.a_d);
300  opt.c_d = pd.c_d;
301  opt.a_d = pd.a_d;
302  c->setShowCopies(pd.copies);
303  }
304  }
305 
306  void
308  doubleClickInspectorsMenu->clear();
309  doubleClickInspectorsMenu->addActions(
310  c->doubleClickInspectorGroup->actions());
311  solutionInspectorsMenu->clear();
312  solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
313  moveInspectorsMenu->clear();
314  moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
315  comparatorsMenu->clear();
316  comparatorsMenu->addActions(c->comparatorGroup->actions());
317  }
318 
319  void
321  bookmarksMenu->clear();
322  bookmarksMenu->addAction(c->bookmarkNode);
323  bookmarksMenu->addSeparator();
324  bookmarksMenu->addActions(c->bookmarksGroup->actions());
325  }
326 
327  void
329  inspectNodeMenu->clear();
330  inspectNodeMenu->addAction(c->inspect);
331  inspectNodeMenu->addSeparator();
332  inspectNodeMenu->addActions(c->inspectGroup->actions());
333  inspectNodeBeforeFPMenu->clear();
334  inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
335  inspectNodeBeforeFPMenu->addSeparator();
336  inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
337  }
338 
339 }}
340 
341 // STATISTICS: gist-any