Generated on Sat Apr 10 2021 00:00:00 for Gecode by doxygen 1.9.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  * 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 
38 
40 
41 namespace 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 
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()));
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
277  aboutGist.show();
278  }
279 
280  void
282  PreferencesDialog pd(opt, this);
283  if (setup) {
284  c->setAutoZoom(pd.zoom);
285  }
286  if (setup || pd.exec() == QDialog::Accepted) {
288  c->setRefresh(pd.refresh);
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
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
314  bookmarksMenu->clear();
315  bookmarksMenu->addAction(c->bookmarkNode);
316  bookmarksMenu->addSeparator();
317  bookmarksMenu->addActions(c->bookmarksGroup->actions());
318  }
319 
320  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
AboutGist(QWidget *parent=0)
Constructor.
Definition: mainwindow.cpp:43
AboutGist aboutGist
About dialog.
Definition: mainwindow.hh:95
QMenuBar * menuBar
A menu bar.
Definition: mainwindow.hh:93
GistMainWindow(Space *root, bool bab, const Options &opt)
Constructor.
Definition: mainwindow.cpp:77
void about(void)
Open the about dialog.
Definition: mainwindow.cpp:276
void populateBookmarks(void)
Populate the bookmarks menus from the actions found in Gist.
Definition: mainwindow.cpp:313
void populateInspectors(void)
Populate the inspector menus from the actions found in Gist.
Definition: mainwindow.cpp:321
void preferences(bool setup=false)
Open the preferences dialog.
Definition: mainwindow.cpp:281
void closeEvent(QCloseEvent *event)
Close Gist.
Definition: mainwindow.cpp:226
void populateInspectorSelection(void)
Populate the inspector menus from the actions found in Gist.
Definition: mainwindow.cpp:300
void statusChanged(const Statistics &stats, bool finished)
The status has changed (e.g., new solutions have been found)
Definition: mainwindow.cpp:234
Gist * c
The contained Gist object.
Definition: mainwindow.hh:91
Gecode Interactive Search Tool
Definition: qtgist.hh:81
QAction * toggleStop
Bookmark current node.
Definition: qtgist.hh:177
QAction * hideFailed
Hide failed subtrees under current node.
Definition: qtgist.hh:146
void setRefresh(int i)
Set refresh rate.
Definition: qtgist.cpp:782
QAction * navUp
Navigate to parent node.
Definition: qtgist.hh:126
void setShowCopies(bool b)
Set preference whether to show copies in the tree.
Definition: qtgist.cpp:816
QAction * compareNodeBeforeFP
Compare current node to other node before fixpoint.
Definition: qtgist.hh:169
QAction * inspectPath
Inspect all nodes on selected path.
Definition: qtgist.hh:173
QAction * exportPDF
Export PDF of current subtree.
Definition: qtgist.hh:158
QAction * bookmarkNode
Bookmark current node.
Definition: qtgist.hh:165
QAction * print
Print tree.
Definition: qtgist.hh:162
QAction * stop
Stop search.
Definition: qtgist.hh:122
QAction * unstopAll
Bookmark current node.
Definition: qtgist.hh:179
QAction * zoomToFit
Zoom tree to fit window.
Definition: qtgist.hh:154
QActionGroup * inspectBeforeFPGroup
Group of all actions for direct inspector selection.
Definition: qtgist.hh:194
QAction * navRight
Navigate to right sibling.
Definition: qtgist.hh:132
void setAutoHideFailed(bool b)
Set preference whether to automatically hide failed subtrees.
Definition: qtgist.cpp:774
void setAutoZoom(bool b)
Set preference whether to automatically zoom to fit.
Definition: qtgist.cpp:776
QAction * navNextSol
Navigate to next solution (to the left)
Definition: qtgist.hh:136
QAction * searchNext
Search next solution in current subtree.
Definition: qtgist.hh:140
QAction * setPath
Set path from current node to the root.
Definition: qtgist.hh:171
QAction * labelBranches
Label branches under current node.
Definition: qtgist.hh:150
QAction * navLeft
Navigate to left sibling.
Definition: qtgist.hh:130
void setSmoothScrollAndZoom(bool b)
Set preference whether to use smooth scrolling and zooming.
Definition: qtgist.cpp:790
QActionGroup * solutionInspectorGroup
Group of all actions for solution inspectors.
Definition: qtgist.hh:182
QAction * navDown
Navigate to leftmost child node.
Definition: qtgist.hh:128
QActionGroup * moveInspectorGroup
Group of all actions for move inspectors.
Definition: qtgist.hh:186
void setMoveDuringSearch(bool b)
Set preference whether to move cursor during search.
Definition: qtgist.cpp:798
QAction * navPrevSol
Navigate to previous solution (to the right)
Definition: qtgist.hh:138
QAction * center
Center on current node.
Definition: qtgist.hh:156
void setRefreshPause(int i)
Set refresh pause in msec.
Definition: qtgist.cpp:784
QAction * compareNode
Compare current node to other node.
Definition: qtgist.hh:167
QAction * reset
Reset Gist.
Definition: qtgist.hh:124
QAction * toggleHidden
Toggle whether current node is hidden.
Definition: qtgist.hh:144
bool finish(void)
Stop search and wait until finished.
Definition: qtgist.cpp:699
QAction * searchAll
Search all solutions in current subtree.
Definition: qtgist.hh:142
QAction * navRoot
Navigate to root node.
Definition: qtgist.hh:134
QActionGroup * inspectGroup
Group of all actions for direct inspector selection.
Definition: qtgist.hh:192
QAction * labelPath
Label branches on path to root.
Definition: qtgist.hh:152
QAction * showNodeStats
Open node statistics inspector.
Definition: qtgist.hh:175
QActionGroup * doubleClickInspectorGroup
Group of all actions for double click inspectors.
Definition: qtgist.hh:184
QAction * exportWholeTreePDF
Export PDF of whole tree.
Definition: qtgist.hh:160
QActionGroup * comparatorGroup
Group of all actions for comparators.
Definition: qtgist.hh:188
QAction * inspect
Inspect current node.
Definition: qtgist.hh:118
void setRecompDistances(int c_d, int a_d)
Set recomputation parameters c_d and a_d.
Definition: qtgist.cpp:802
QAction * unhideAll
Unhide all hidden subtrees under current node.
Definition: qtgist.hh:148
QActionGroup * bookmarksGroup
Group of all actions for bookmarks.
Definition: qtgist.hh:190
QAction * inspectBeforeFP
Inspect current node before fixpoint.
Definition: qtgist.hh:120
Class holding Gecode and Gist logo icons.
Definition: gecodelogo.hh:40
const unsigned int logoSize
Size of the Gecode logo.
Definition: gecodelogo.hh:45
const unsigned char * logo
The Gecode logo.
Definition: gecodelogo.hh:43
const unsigned int gistLogoSize
Size of the smaller logo.
Definition: gecodelogo.hh:50
const unsigned char * gistLogo
A smaller logo used as a window icon.
Definition: gecodelogo.hh:48
Small node drawings for the status bar.
Definition: nodewidget.hh:43
Options for Gist
Definition: gist.hh:234
Preferences dialog for Gist.
Definition: preferences.hh:48
bool hideFailed
Whether to automatically hide failed subtrees during search.
Definition: preferences.hh:73
int c_d
The copying distance.
Definition: preferences.hh:88
bool moveDuringSearch
Whether to move cursor during search.
Definition: preferences.hh:85
int a_d
The adaptive recomputation distance.
Definition: preferences.hh:90
bool smoothScrollAndZoom
Whether to use smooth scrolling and zooming.
Definition: preferences.hh:83
bool zoom
Whether to automatically zoom during search.
Definition: preferences.hh:75
bool copies
Whether to show where copies are in the tree.
Definition: preferences.hh:77
int refresh
How often to refresh the display during search.
Definition: preferences.hh:79
int refreshPause
Milliseconds to wait after each refresh (to slow down search)
Definition: preferences.hh:81
Statistics about the search tree
Definition: spacenode.hh:59
int choices
Number of choice nodes.
Definition: spacenode.hh:66
int failures
Number of failures.
Definition: spacenode.hh:64
int solutions
Number of solutions.
Definition: spacenode.hh:62
int undetermined
Number of open, undetermined nodes.
Definition: spacenode.hh:68
int maxDepth
Maximum depth of the tree.
Definition: spacenode.hh:70
unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:753
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance)
Definition: search.hh:755
Computation spaces.
Definition: core.hpp:1742
double stop(void)
Get time since start of timer.
Definition: timer.hpp:76
void start(void)
Start timer.
Definition: timer.hpp:66
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:208
@ UNDETERMINED
Node that has not been explored yet.
Definition: spacenode.hh:48
@ FAILED
Node representing failure.
Definition: spacenode.hh:46
@ SOLVED
Node representing a solution.
Definition: spacenode.hh:45
@ BRANCH
Node representing a branch.
Definition: spacenode.hh:47
Options opt
The options.
Definition: test.cpp:97