Generated on Sat Jul 29 2017 12:41:24 for Gecode by doxygen 1.8.13
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: 2017-02-23 06:38:42 +0100 (Thu, 23 Feb 2017) $ by $Author: schulte $
11  * $Revision: 15477 $
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  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  }
278 
279  void
281  aboutGist.show();
282  }
283 
284  void
286  PreferencesDialog pd(opt, this);
287  if (setup) {
288  c->setAutoZoom(pd.zoom);
289  }
290  if (setup || pd.exec() == QDialog::Accepted) {
292  c->setRefresh(pd.refresh);
296  c->setRecompDistances(pd.c_d,pd.a_d);
297  opt.c_d = pd.c_d;
298  opt.a_d = pd.a_d;
299  c->setShowCopies(pd.copies);
300  }
301  }
302 
303  void
305  doubleClickInspectorsMenu->clear();
306  doubleClickInspectorsMenu->addActions(
307  c->doubleClickInspectorGroup->actions());
308  solutionInspectorsMenu->clear();
309  solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
310  moveInspectorsMenu->clear();
311  moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
312  comparatorsMenu->clear();
313  comparatorsMenu->addActions(c->comparatorGroup->actions());
314  }
315 
316  void
318  bookmarksMenu->clear();
319  bookmarksMenu->addAction(c->bookmarkNode);
320  bookmarksMenu->addSeparator();
321  bookmarksMenu->addActions(c->bookmarksGroup->actions());
322  }
323 
324  void
326  inspectNodeMenu->clear();
327  inspectNodeMenu->addAction(c->inspect);
328  inspectNodeMenu->addSeparator();
329  inspectNodeMenu->addActions(c->inspectGroup->actions());
330  inspectNodeBeforeFPMenu->clear();
331  inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
332  inspectNodeBeforeFPMenu->addSeparator();
333  inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
334  }
335 
336 }}
337 
338 // STATISTICS: gist-any
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:455
QAction * navNextSol
Navigate to next solution (to the left)
Definition: qtgist.hh:140
QActionGroup * doubleClickInspectorGroup
Group of all actions for double click inspectors.
Definition: qtgist.hh:188
void populateInspectors(void)
Populate the inspector menus from the actions found in Gist.
Definition: mainwindow.cpp:325
bool zoom
Whether to automatically zoom during search.
Definition: preferences.hh:79
Small node drawings for the status bar.
Definition: nodewidget.hh:47
QAction * toggleHidden
Toggle whether current node is hidden.
Definition: qtgist.hh:148
void setAutoHideFailed(bool b)
Set preference whether to automatically hide failed subtrees.
Definition: qtgist.cpp:778
int solutions
Number of solutions.
Definition: spacenode.hh:66
QAction * navDown
Navigate to leftmost child node.
Definition: qtgist.hh:132
QAction * navRoot
Navigate to root node.
Definition: qtgist.hh:138
QAction * bookmarkNode
Bookmark current node.
Definition: qtgist.hh:169
QAction * navUp
Navigate to parent node.
Definition: qtgist.hh:130
QAction * setPath
Set path from current node to the root.
Definition: qtgist.hh:175
Gist * c
The contained Gist object.
Definition: mainwindow.hh:95
Node representing a branch.
Definition: spacenode.hh:51
QAction * inspect
Inspect current node.
Definition: qtgist.hh:122
unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:453
void populateBookmarks(void)
Populate the bookmarks menus from the actions found in Gist.
Definition: mainwindow.cpp:317
GistMainWindow(Space *root, bool bab, const Options &opt)
Constructor.
Definition: mainwindow.cpp:81
QAction * compareNode
Compare current node to other node.
Definition: qtgist.hh:171
QAction * unstopAll
Bookmark current node.
Definition: qtgist.hh:183
QActionGroup * inspectBeforeFPGroup
Group of all actions for direct inspector selection.
Definition: qtgist.hh:198
int choices
Number of choice nodes.
Definition: spacenode.hh:70
QAction * hideFailed
Hide failed subtrees under current node.
Definition: qtgist.hh:150
Node representing failure.
Definition: spacenode.hh:50
void closeEvent(QCloseEvent *event)
Close Gist.
Definition: mainwindow.cpp:230
void setShowCopies(bool b)
Set preference whether to show copies in the tree.
Definition: qtgist.cpp:820
const unsigned char * logo
The Gecode logo.
Definition: gecodelogo.hh:47
QAction * navPrevSol
Navigate to previous solution (to the right)
Definition: qtgist.hh:142
QAction * navLeft
Navigate to left sibling.
Definition: qtgist.hh:134
bool finish(void)
Stop search and wait until finished.
Definition: qtgist.cpp:703
void setSmoothScrollAndZoom(bool b)
Set preference whether to use smooth scrolling and zooming.
Definition: qtgist.cpp:794
void statusChanged(const Statistics &stats, bool finished)
The status has changed (e.g., new solutions have been found)
Definition: mainwindow.cpp:238
bool hideFailed
Whether to automatically hide failed subtrees during search.
Definition: preferences.hh:77
void about(void)
Open the about dialog.
Definition: mainwindow.cpp:280
Computation spaces.
Definition: core.hpp:1748
QAction * toggleStop
Bookmark current node.
Definition: qtgist.hh:181
Node that has not been explored yet.
Definition: spacenode.hh:52
QAction * navRight
Navigate to right sibling.
Definition: qtgist.hh:136
void start(void)
Start timer.
Definition: timer.hpp:70
QActionGroup * bookmarksGroup
Group of all actions for bookmarks.
Definition: qtgist.hh:194
QAction * inspectBeforeFP
Inspect current node before fixpoint.
Definition: qtgist.hh:124
QAction * unhideAll
Unhide all hidden subtrees under current node.
Definition: qtgist.hh:152
Options opt
The options.
Definition: test.cpp:101
bool copies
Whether to show where copies are in the tree.
Definition: preferences.hh:81
QAction * center
Center on current node.
Definition: qtgist.hh:160
Node representing a solution.
Definition: spacenode.hh:49
QAction * exportPDF
Export PDF of current subtree.
Definition: qtgist.hh:162
Class holding Gecode and Gist logo icons.
Definition: gecodelogo.hh:44
int undetermined
Number of open, undetermined nodes.
Definition: spacenode.hh:72
Gecode Interactive Search Tool
Definition: qtgist.hh:85
void populateInspectorSelection(void)
Populate the inspector menus from the actions found in Gist.
Definition: mainwindow.cpp:304
AboutGist(QWidget *parent=0)
Constructor.
Definition: mainwindow.cpp:47
const unsigned char * gistLogo
A smaller logo used as a window icon.
Definition: gecodelogo.hh:52
void preferences(bool setup=false)
Open the preferences dialog.
Definition: mainwindow.cpp:285
double stop(void)
Get time since start of timer.
Definition: timer.hpp:80
int c_d
The copying distance.
Definition: preferences.hh:92
void setAutoZoom(bool b)
Set preference whether to automatically zoom to fit.
Definition: qtgist.cpp:780
Preferences dialog for Gist.
Definition: preferences.hh:52
const unsigned int logoSize
Size of the Gecode logo.
Definition: gecodelogo.hh:49
QActionGroup * moveInspectorGroup
Group of all actions for move inspectors.
Definition: qtgist.hh:190
QAction * labelPath
Label branches on path to root.
Definition: qtgist.hh:156
void setRecompDistances(int c_d, int a_d)
Set recomputation parameters c_d and a_d.
Definition: qtgist.cpp:806
QAction * stop
Stop search.
Definition: qtgist.hh:126
QAction * compareNodeBeforeFP
Compare current node to other node before fixpoint.
Definition: qtgist.hh:173
QMenuBar * menuBar
A menu bar.
Definition: mainwindow.hh:97
QAction * showNodeStats
Open node statistics inspector.
Definition: qtgist.hh:179
void setMoveDuringSearch(bool b)
Set preference whether to move cursor during search.
Definition: qtgist.cpp:802
int maxDepth
Maximum depth of the tree.
Definition: spacenode.hh:74
void setRefresh(int i)
Set refresh rate.
Definition: qtgist.cpp:786
bool smoothScrollAndZoom
Whether to use smooth scrolling and zooming.
Definition: preferences.hh:87
QActionGroup * solutionInspectorGroup
Group of all actions for solution inspectors.
Definition: qtgist.hh:186
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:212
QAction * searchNext
Search next solution in current subtree.
Definition: qtgist.hh:144
int refresh
How often to refresh the display during search.
Definition: preferences.hh:83
AboutGist aboutGist
About dialog.
Definition: mainwindow.hh:99
int refreshPause
Milliseconds to wait after each refresh (to slow down search)
Definition: preferences.hh:85
QActionGroup * inspectGroup
Group of all actions for direct inspector selection.
Definition: qtgist.hh:196
Gecode toplevel namespace
QAction * searchAll
Search all solutions in current subtree.
Definition: qtgist.hh:146
QAction * print
Print tree.
Definition: qtgist.hh:166
QAction * labelBranches
Label branches under current node.
Definition: qtgist.hh:154
QAction * reset
Reset Gist.
Definition: qtgist.hh:128
QAction * zoomToFit
Zoom tree to fit window.
Definition: qtgist.hh:158
QAction * exportWholeTreePDF
Export PDF of whole tree.
Definition: qtgist.hh:164
QAction * inspectPath
Inspect all nodes on selected path.
Definition: qtgist.hh:177
Options for Gist
Definition: gist.hh:238
bool moveDuringSearch
Whether to move cursor during search.
Definition: preferences.hh:89
int failures
Number of failures.
Definition: spacenode.hh:68
const unsigned int gistLogoSize
Size of the smaller logo.
Definition: gecodelogo.hh:54
QActionGroup * comparatorGroup
Group of all actions for comparators.
Definition: qtgist.hh:192
Statistics about the search tree
Definition: spacenode.hh:63
void setRefreshPause(int i)
Set refresh pause in msec.
Definition: qtgist.cpp:788
int a_d
The adaptive recomputation distance.
Definition: preferences.hh:94