File: mainwindow.cpp

package info (click to toggle)
gecode-snapshot 6.2.0%2Bgit20240207-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 35,308 kB
  • sloc: cpp: 475,516; perl: 2,077; makefile: 1,816; sh: 198
file content (334 lines) | stat: -rw-r--r-- 11,503 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
 *  Main authors:
 *     Guido Tack <tack@gecode.org>
 *
 *  Copyright:
 *     Guido Tack, 2006
 *
 *  This file is part of Gecode, the generic constraint
 *  development environment:
 *     http://www.gecode.org
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include <gecode/gist/mainwindow.hh>
#include <gecode/gist/preferences.hh>
#include <gecode/gist/nodewidget.hh>
#include <gecode/gist/drawingcursor.hh>

#include <gecode/gist/gecodelogo.hh>

namespace Gecode { namespace Gist {

  AboutGist::AboutGist(QWidget* parent) : QDialog(parent) {

    Logos logos;
    QPixmap myPic;
    myPic.loadFromData(logos.logo, logos.logoSize);

    QPixmap myPic2;
    myPic2.loadFromData(logos.gistLogo, logos.gistLogoSize);
    setWindowIcon(myPic2);


    setMinimumSize(300, 240);
    setMaximumSize(300, 240);
    QVBoxLayout* layout = new QVBoxLayout();
    QLabel* logo = new QLabel();
    logo->setPixmap(myPic);
    layout->addWidget(logo, 0, Qt::AlignCenter);
    QLabel* aboutLabel =
      new QLabel(tr("<h2>Gist</h2>"
                     "<p><b>The Gecode Interactive Search Tool</b</p> "
                    "<p>You can find more information about Gecode and Gist "
                    "at</p>"
                    "<p><a href='http://www.gecode.org'>www.gecode.org</a>"
                    "</p"));
    aboutLabel->setOpenExternalLinks(true);
    aboutLabel->setWordWrap(true);
    aboutLabel->setAlignment(Qt::AlignCenter);
    layout->addWidget(aboutLabel);
    setLayout(layout);
    setWindowTitle(tr("About Gist"));
    setAttribute(Qt::WA_QuitOnClose, false);
    setAttribute(Qt::WA_DeleteOnClose, false);
  }

  GistMainWindow::GistMainWindow(Space* root, bool bab,
                                 const Options& opt0)
  : opt(opt0), aboutGist(this) {
    c = new Gist(root,bab,this,opt);
    setCentralWidget(c);
    setWindowTitle(tr("Gist"));

    Logos logos;
    QPixmap myPic;
    myPic.loadFromData(logos.gistLogo, logos.gistLogoSize);
    setWindowIcon(myPic);

    resize(500,500);
    setMinimumSize(400, 200);

    menuBar = new QMenuBar(0);

    QMenu* fileMenu = menuBar->addMenu(tr("&File"));
    fileMenu->addAction(c->print);
#if QT_VERSION >= 0x040400
    fileMenu->addAction(c->exportWholeTreePDF);
#endif
    QAction* quitAction = fileMenu->addAction(tr("Quit"));
    quitAction->setShortcut(QKeySequence("Ctrl+Q"));
    connect(quitAction, SIGNAL(triggered()),
            this, SLOT(close()));
    prefAction = fileMenu->addAction(tr("Preferences"));
    connect(prefAction, SIGNAL(triggered()), this, SLOT(preferences()));

    QMenu* nodeMenu = menuBar->addMenu(tr("&Node"));

    inspectNodeMenu = new QMenu("Inspect");
    inspectNodeMenu->addAction(c->inspect);
    connect(inspectNodeMenu, SIGNAL(aboutToShow()),
            this, SLOT(populateInspectors()));

    inspectNodeBeforeFPMenu = new QMenu("Inspect before fixpoint");
    inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
    connect(inspectNodeBeforeFPMenu, SIGNAL(aboutToShow()),
            this, SLOT(populateInspectors()));
    populateInspectors();

    nodeMenu->addMenu(inspectNodeMenu);
    nodeMenu->addMenu(inspectNodeBeforeFPMenu);
    nodeMenu->addAction(c->compareNode);
    nodeMenu->addAction(c->compareNodeBeforeFP);
    nodeMenu->addAction(c->setPath);
    nodeMenu->addAction(c->inspectPath);
    nodeMenu->addAction(c->showNodeStats);
    bookmarksMenu = new QMenu("Bookmarks");
    bookmarksMenu->addAction(c->bookmarkNode);
    connect(bookmarksMenu, SIGNAL(aboutToShow()),
            this, SLOT(populateBookmarks()));
    nodeMenu->addMenu(bookmarksMenu);
    nodeMenu->addSeparator();
    nodeMenu->addAction(c->navUp);
    nodeMenu->addAction(c->navDown);
    nodeMenu->addAction(c->navLeft);
    nodeMenu->addAction(c->navRight);
    nodeMenu->addAction(c->navRoot);
    nodeMenu->addAction(c->navNextSol);
    nodeMenu->addAction(c->navPrevSol);
    nodeMenu->addSeparator();
    nodeMenu->addAction(c->toggleHidden);
    nodeMenu->addAction(c->hideFailed);
    nodeMenu->addAction(c->unhideAll);
    nodeMenu->addAction(c->labelBranches);
    nodeMenu->addAction(c->labelPath);
    nodeMenu->addAction(c->toggleStop);
    nodeMenu->addAction(c->unstopAll);
    nodeMenu->addSeparator();
    nodeMenu->addAction(c->zoomToFit);
    nodeMenu->addAction(c->center);
#if QT_VERSION >= 0x040400
    nodeMenu->addAction(c->exportPDF);
#endif

    QMenu* searchMenu = menuBar->addMenu(tr("&Search"));
    searchMenu->addAction(c->searchNext);
    searchMenu->addAction(c->searchAll);
    searchMenu->addSeparator();
    searchMenu->addAction(c->stop);
    searchMenu->addSeparator();
    searchMenu->addAction(c->reset);

    QMenu* toolsMenu = menuBar->addMenu(tr("&Tools"));
    doubleClickInspectorsMenu = new QMenu("Double click Inspectors");
    connect(doubleClickInspectorsMenu, SIGNAL(aboutToShow()),
            this, SLOT(populateInspectorSelection()));
    toolsMenu->addMenu(doubleClickInspectorsMenu);
    solutionInspectorsMenu = new QMenu("Solution inspectors");
    connect(solutionInspectorsMenu, SIGNAL(aboutToShow()),
            this, SLOT(populateInspectorSelection()));
    toolsMenu->addMenu(solutionInspectorsMenu);
    moveInspectorsMenu = new QMenu("Move inspectors");
    connect(moveInspectorsMenu, SIGNAL(aboutToShow()),
            this, SLOT(populateInspectorSelection()));
    toolsMenu->addMenu(moveInspectorsMenu);
    comparatorsMenu = new QMenu("Comparators");
    connect(comparatorsMenu, SIGNAL(aboutToShow()),
            this, SLOT(populateInspectorSelection()));
    toolsMenu->addMenu(comparatorsMenu);

    QMenu* helpMenu = menuBar->addMenu(tr("&Help"));
    QAction* aboutAction = helpMenu->addAction(tr("About"));
    connect(aboutAction, SIGNAL(triggered()),
            this, SLOT(about()));

    // Don't add the menu bar on Mac OS X
#ifndef Q_WS_MAC
    setMenuBar(menuBar);
#endif

    // Set up status bar
    QWidget* stw = new QWidget();
    QHBoxLayout* hbl = new QHBoxLayout();
    hbl->setContentsMargins(0,0,0,0);
    hbl->addWidget(new QLabel("Depth:"));
    depthLabel = new QLabel("0");
    hbl->addWidget(depthLabel);
    hbl->addWidget(new NodeWidget(SOLVED));
    solvedLabel = new QLabel("0");
    hbl->addWidget(solvedLabel);
    hbl->addWidget(new NodeWidget(FAILED));
    failedLabel = new QLabel("0");
    hbl->addWidget(failedLabel);
    hbl->addWidget(new NodeWidget(BRANCH));
    choicesLabel = new QLabel("0");
    hbl->addWidget(choicesLabel);
    hbl->addWidget(new NodeWidget(UNDETERMINED));
    openLabel = new QLabel("     0");
    hbl->addWidget(openLabel);
    stw->setLayout(hbl);
    statusBar()->addPermanentWidget(stw);

    isSearching = false;
    statusBar()->showMessage("Ready");

    connect(c,SIGNAL(statusChanged(const Statistics&,bool)),
            this,SLOT(statusChanged(const Statistics&,bool)));

    connect(c,SIGNAL(searchFinished(void)),this,SLOT(close(void)));

    preferences(true);
    show();
    c->reset->trigger();
  }

  void
  GistMainWindow::closeEvent(QCloseEvent* event) {
    if (c->finish())
      event->accept();
    else
      event->ignore();
  }

  void
  GistMainWindow::statusChanged(const Statistics& stats, bool finished) {
    if (stats.maxDepth==0) {
      isSearching = false;
      statusBar()->showMessage("Ready");
      prefAction->setEnabled(true);
    } else if (isSearching && finished) {
      isSearching = false;
      double ms = searchTimer.stop();
      double s = std::floor(ms / 1000.0);
      ms -= s*1000.0;
      double m = std::floor(s / 60.0);
      s -= m*60.0;
      double h = std::floor(m / 60.0);
      m -= h*60.0;

      // QString t;
      // if (static_cast<int>(h) != 0)
      //   t += QString().setNum(static_cast<int>(h))+"h ";
      // if (static_cast<int>(m) != 0)
      //   t += QString().setNum(static_cast<int>(m))+"m ";
      // if (static_cast<int>(s) != 0)
      //   t += QString().setNum(static_cast<int>(s));
      // else
      //   t += "0";
      // t += "."+QString().setNum(static_cast<int>(ms))+"s";
      // statusBar()->showMessage(QString("Ready (search time ")+t+")");
      statusBar()->showMessage("Ready");
      prefAction->setEnabled(true);
    } else if (!isSearching && !finished) {
      prefAction->setEnabled(false);
      statusBar()->showMessage("Searching");
      isSearching = true;
      searchTimer.start();
    }
    depthLabel->setNum(stats.maxDepth);
    solvedLabel->setNum(stats.solutions);
    failedLabel->setNum(stats.failures);
    choicesLabel->setNum(stats.choices);
    openLabel->setNum(stats.undetermined);
  }

  void
  GistMainWindow::about(void) {
    aboutGist.show();
  }

  void
  GistMainWindow::preferences(bool setup) {
    PreferencesDialog pd(opt, this);
    if (setup) {
      c->setAutoZoom(pd.zoom);
    }
    if (setup || pd.exec() == QDialog::Accepted) {
      c->setAutoHideFailed(pd.hideFailed);
      c->setRefresh(pd.refresh);
      c->setRefreshPause(pd.refreshPause);
      c->setSmoothScrollAndZoom(pd.smoothScrollAndZoom);
      c->setMoveDuringSearch(pd.moveDuringSearch);
      c->setRecompDistances(pd.c_d,pd.a_d);
      opt.c_d = pd.c_d;
      opt.a_d = pd.a_d;
      c->setShowCopies(pd.copies);
    }
  }

  void
  GistMainWindow::populateInspectorSelection(void) {
    doubleClickInspectorsMenu->clear();
    doubleClickInspectorsMenu->addActions(
      c->doubleClickInspectorGroup->actions());
    solutionInspectorsMenu->clear();
    solutionInspectorsMenu->addActions(c->solutionInspectorGroup->actions());
    moveInspectorsMenu->clear();
    moveInspectorsMenu->addActions(c->moveInspectorGroup->actions());
    comparatorsMenu->clear();
    comparatorsMenu->addActions(c->comparatorGroup->actions());
  }

  void
  GistMainWindow::populateBookmarks(void) {
    bookmarksMenu->clear();
    bookmarksMenu->addAction(c->bookmarkNode);
    bookmarksMenu->addSeparator();
    bookmarksMenu->addActions(c->bookmarksGroup->actions());
  }

  void
  GistMainWindow::populateInspectors(void) {
    inspectNodeMenu->clear();
    inspectNodeMenu->addAction(c->inspect);
    inspectNodeMenu->addSeparator();
    inspectNodeMenu->addActions(c->inspectGroup->actions());
    inspectNodeBeforeFPMenu->clear();
    inspectNodeBeforeFPMenu->addAction(c->inspectBeforeFP);
    inspectNodeBeforeFPMenu->addSeparator();
    inspectNodeBeforeFPMenu->addActions(c->inspectBeforeFPGroup->actions());
  }

}}

// STATISTICS: gist-any