this repo has no description
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 34#include <gecode/gist/nodestats.hh> 35#include <gecode/gist/nodewidget.hh> 36#include <gecode/gist/nodecursor.hh> 37#include <gecode/gist/nodevisitor.hh> 38#include <gecode/gist/drawingcursor.hh> 39 40namespace Gecode { namespace Gist { 41 42 NodeStatInspector::NodeStatInspector(QWidget* parent) 43 : QWidget(parent) { 44 setWindowFlags(Qt::Tool); 45 QGraphicsScene* scene = new QGraphicsScene(); 46 47 scene->addEllipse(70,10,16,16,QPen(),QBrush(DrawingCursor::white)); 48 scene->addEllipse(70,60,16,16,QPen(),QBrush(DrawingCursor::blue)); 49 scene->addRect(32,100,12,12,QPen(),QBrush(DrawingCursor::red)); 50 51 QPolygonF poly; 52 poly << QPointF(78,100) << QPointF(78+8,100+8) 53 << QPointF(78,100+16) << QPointF(78-8,100+8); 54 scene->addPolygon(poly,QPen(),QBrush(DrawingCursor::green)); 55 56 scene->addEllipse(110,100,16,16,QPen(),QBrush(DrawingCursor::white)); 57 58 QPen pen; 59 pen.setStyle(Qt::DotLine); 60 pen.setWidth(0); 61 scene->addLine(78,26,78,60,pen); 62 scene->addLine(78,76,38,100,pen); 63 scene->addLine(78,76,78,100,pen); 64 scene->addLine(78,76,118,100,pen); 65 66 scene->addLine(135,10,145,10); 67 scene->addLine(145,10,145,110); 68 scene->addLine(145,60,135,60); 69 scene->addLine(145,110,135,110); 70 71 nodeDepthLabel = scene->addText("0"); 72 nodeDepthLabel->setPos(150,20); 73 subtreeDepthLabel = scene->addText("0"); 74 subtreeDepthLabel->setPos(150,75); 75 76 choicesLabel = scene->addText("0"); 77 choicesLabel->setPos(45,57); 78 79 solvedLabel = scene->addText("0"); 80 solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120); 81 failedLabel = scene->addText("0"); 82 failedLabel->setPos(30,120); 83 openLabel = scene->addText("0"); 84 openLabel->setPos(110,120); 85 86 QGraphicsView* view = new QGraphicsView(scene); 87 view->setRenderHints(view->renderHints() | QPainter::Antialiasing); 88 view->show(); 89 90 scene->setBackgroundBrush(Qt::white); 91 92 boxLayout = new QVBoxLayout(); 93 boxLayout->setContentsMargins(0,0,0,0); 94 boxLayout->addWidget(view); 95 setLayout(boxLayout); 96 97 setWindowTitle("Gist node statistics"); 98 setAttribute(Qt::WA_QuitOnClose, false); 99 setAttribute(Qt::WA_DeleteOnClose, false); 100 } 101 102 void 103 NodeStatInspector::node(const VisualNode::NodeAllocator& na, 104 VisualNode* n, const Statistics&, bool) { 105 if (isVisible()) { 106 int nd = -1; 107 for (VisualNode* p = n; p != nullptr; p = p->getParent(na)) 108 nd++; 109 nodeDepthLabel->setPlainText(QString("%1").arg(nd));; 110 StatCursor sc(n,na); 111 PreorderNodeVisitor<StatCursor> pnv(sc); 112 pnv.run(); 113 114 subtreeDepthLabel->setPlainText( 115 QString("%1").arg(pnv.getCursor().depth)); 116 solvedLabel->setPlainText(QString("%1").arg(pnv.getCursor().solved)); 117 solvedLabel->setPos(78-solvedLabel->document()->size().width()/2,120); 118 failedLabel->setPlainText(QString("%1").arg(pnv.getCursor().failed)); 119 failedLabel->setPos(44-failedLabel->document()->size().width(),120); 120 choicesLabel->setPlainText(QString("%1").arg(pnv.getCursor().choice)); 121 choicesLabel->setPos(66-choicesLabel->document()->size().width(),57); 122 openLabel->setPlainText(QString("%1").arg(pnv.getCursor().open)); 123 } 124 } 125 126 void 127 NodeStatInspector::showStats(void) { 128 show(); 129 activateWindow(); 130 } 131 132}} 133 134// STATISTICS: gist-any