Esempio n. 1
0
inline void GraphPolygonClipper::addPoint(
    QPolygon &pa, uint pos, const QPoint &point) const
{
    if ( uint(pa.size()) <= pos ) 
        pa.resize(pos + 5);

    pa.setPoint(pos, point);
}
Esempio n. 2
0
void Storage::mouseMoveEvent(QMouseEvent *anEvent)
{
    QPoint pos = anEvent->pos() / scale_;
    if (anEvent->pos().x() < 0)
        pos.setX(0);

    if (width() < anEvent->pos().x())
        pos.setX(width() - 1);

    if (anEvent->pos().y() < 0)
        pos.setY(0);


    if (height() < anEvent->pos().y())
        pos.setY(height() - 1);

    /* изменяем прямоугольник  */
    if ((anEvent->buttons() & Qt::LeftButton) &&
        BoundingBoxTool == tool_ &&
        NewSelection == state_ &&
        Qt::NoModifier == keyboard_modifier_)
    {
        triggerBoundBox(pos, prev_cursor_pos_, rect);
    }

    /* изменяем эллипс  */
    if ((anEvent->buttons() & Qt::LeftButton) &&
        EllipseTool == tool_ &&
        NewSelection == state_ &&
        Qt::NoModifier == keyboard_modifier_)
    {
        triggerEllipse(pos, prev_cursor_pos_, ell);
    }

    /* изменяем стрелу  */
    if ((anEvent->buttons() & Qt::LeftButton) &&
        ArrowTool == tool_ &&
        NewSelection == state_ &&
        Qt::NoModifier == keyboard_modifier_)
    {
        triggerArrow(pos, prev_cursor_pos_, arrow);
    }

    /* перемещаем последнюю точку(курсор) многоугольника до создания(точка зафиксирется кликом) новой */
    if (PolygonTool == tool_ &&
        NewSelection == state_ &&
        (anEvent->buttons() & Qt::LeftButton))
    {
        QPolygon tmp = poly.getCoordinates();
        tmp.setPoint(tmp.count() - 1, pos);
        poly.setCoordinates(tmp);
        repaint_needed_ = 1;
    }

//    if (-1 != focused_selection_ &&
//        !(anEvent->buttons() & Qt::LeftButton)) {
//        checkForPoints(&pos);
//    }
//here now 2
    /* изменяем многоульник */
//    if (-1 != hovered_point_.figureID &&
//        !list_polygon_->isEmpty() &&
//        PolyFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton) &&
//        hovered_point_.figureID == focused_selection_)
//    {
//        polygon_.poly.clear();
//        polygon_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;
//        Polygon *poly = list_polygon_->at(hovered_point_.figureID);

//        poly->poly.setPoint(hovered_point_.pointID, pos);

//        for(int i=0;i< list_polygon_->at(hovered_point_.figureID)->poly.count();++i)
//        {
//            if(i!=hovered_point_.pointID)
//                polygon_.poly  << list_polygon_->at(hovered_point_.figureID)->poly.point(i);
//            else
//                polygon_.poly << pos;
//        }
//        qDebug() << "polygon_.poly =" << polygon_.poly;

//        repaint_needed_ = 1;
//    }

    /* изменяем прямоульник */
//    if (-1 != hovered_point_.figureID &&
//        !list_bounding_box_->isEmpty() &&
//        RectFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton))
//    {
//        bounding_box_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;

//        bounding_box_.rect.setTopLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.topLeft());
//        bounding_box_.rect.setTopRight(list_bounding_box_->at(hovered_point_.figureID)->rect.topRight());
//        bounding_box_.rect.setBottomRight(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomRight());
//        bounding_box_.rect.setBottomLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomLeft());
//        BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID);
//        if (0 == hovered_point_.pointID)
//        {
//            rect->rect.setTopLeft(pos);
//            bounding_box_.rect.setTopLeft(pos);
//            qDebug() << "rect->rect.topLeft" << rect->rect.topLeft();
//        }
//        else if (1 == hovered_point_.pointID)
//        {
//            rect->rect.setTopRight(pos);
//            bounding_box_.rect.setTopRight(pos);
//            qDebug() << "rect->rect.topRight" << rect->rect.topRight();
//        }
//        else if (2 == hovered_point_.pointID)
//        {
//            rect->rect.setBottomRight(pos);
//            bounding_box_.rect.setBottomRight(pos);
//            qDebug() << "rect->rect.bottomRight" << rect->rect.bottomRight();
//        }
//        else if (3 == hovered_point_.pointID)
//        {
//            rect->rect.setBottomLeft(pos);
//            bounding_box_.rect.setBottomLeft(pos);
//            qDebug() << "rect->rect.bottomLeft" << rect->rect.bottomLeft();
//        }
//        repaint_needed_ = 1;
//    }

//    /* изменяем эллипс */
//    if (-1 != hovered_point_.figureID &&
//        !list_ellipse_->isEmpty() &&
//        EllipseFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton))
//    {
//        ellipse_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;

//        ellipse_.rect.setTopLeft(list_ellipse_->at(hovered_point_.figureID)->rect.topLeft());
//        ellipse_.rect.setTopRight(list_ellipse_->at(hovered_point_.figureID)->rect.topRight());
//        ellipse_.rect.setBottomRight(list_ellipse_->at(hovered_point_.figureID)->rect.bottomRight());
//        ellipse_.rect.setBottomLeft(list_ellipse_->at(hovered_point_.figureID)->rect.bottomLeft());
//        Ellipse *ell = list_ellipse_->at(hovered_point_.figureID);
//        if (0 == hovered_point_.pointID)
//        {
//            ell->rect.setTopLeft(pos);
//            ellipse_.rect.setTopLeft(pos);
//            qDebug() << "rect->rect.topLeft" << ell->rect.topLeft();
//        }
//        else if (1 == hovered_point_.pointID)
//        {
//            ell->rect.setTopRight(pos);
//            ellipse_.rect.setTopRight(pos);
//            qDebug() << "rect->rect.topRight" << ell->rect.topRight();
//        }
//        else if (2 == hovered_point_.pointID)
//        {
//            ell->rect.setBottomRight(pos);
//            ellipse_.rect.setBottomRight(pos);
//            qDebug() << "rect->rect.bottomRight" << ell->rect.bottomRight();
//        }
//        else if (3 == hovered_point_.pointID)
//        {
//            ell->rect.setBottomLeft(pos);
//            ellipse_.rect.setBottomLeft(pos);
//            qDebug() << "rect->rect.bottomLeft" << ell->rect.bottomLeft();
//        }
//        repaint_needed_ = 1;
//    }

//    /* изменяем стрелу */
//    if (-1 != hovered_point_.figureID &&
//        !list_arrow_->isEmpty() &&
//        ArrowFigure == hovered_point_.figure &&
//        (anEvent->buttons() & Qt::LeftButton))
//    {
//        arrow_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/;

//        arrow_.line.setP1(list_arrow_->at(hovered_point_.figureID)->line.p1());
//        arrow_.line.setP2(list_arrow_->at(hovered_point_.figureID)->line.p2());
//        Arrow *arrow = list_arrow_->at(hovered_point_.figureID);
//        if (0 == hovered_point_.pointID)
//        {
//            arrow->line.setP1(pos);
//            arrow_.line.setP1(pos);
//            qDebug() << "arrow->line.p1" << arrow->line.p1();
//        }
//        else if (1 == hovered_point_.pointID)
//        {
//            arrow->line.setP2(pos);
//            arrow_.line.setP2(pos);
//            qDebug() << "arrow->line.p2" << arrow->line.p2();
//        }
//        repaint_needed_ = 1;
//    }

    /* когда изображение слишком большое(необходима прокрутка) */
    if ((anEvent->buttons() & Qt::MiddleButton) &&
        (scroll_area_->size().height() < size().height() ||
        scroll_area_->size().width() < size().width()))
    {
        QPoint globPos = mapToGlobal(pos);
        QPoint prev = mapToGlobal(prev_cursor_pos_);
        int horValue = scroll_area_->horizontalScrollBar()->value();
//        scroll_area_->horizontalScrollBar()
        int verValue = scroll_area_->verticalScrollBar()->value();


        QPoint delta = globPos - prev;
        prev_cursor_pos_ = pos;

        horValue += delta.x();
        verValue += delta.y();

        scroll_area_->horizontalScrollBar()->setValue(horValue);
        scroll_area_->verticalScrollBar()->setValue(verValue);
    }

    if (repaint_needed_) {
        update();
        repaint_needed_ = 0;
    }
}
Esempio n. 3
0
static void addPoint(QPolygon &a, const QPoint &p)
{
    uint n = a.size();
    a.resize(n + 1);
    a.setPoint(n, p);
}
Esempio n. 4
0
/**
 * Draws an arc which starts / ends exactly at the given coordinates.
 *
 * @param cx center in x
 * @param cy center in y
 * @param radius Radius
 * @param a1 Angle 1 in rad
 * @param a2 Angle 2 in rad
 * @param x1 startpoint x
 * @param y1 startpoint y
 * @param x2 endpoint x
 * @param y2 endpoint y
 * @param reversed true: clockwise, false: counterclockwise
 */
void RS_PainterQt::drawArc(const RS_Vector& cp, double radius,
                           double a1, double a2,
                           const RS_Vector& p1, const RS_Vector& p2,
                           bool reversed) {
    /*
    QPainter::drawArc(cx-radius, cy-radius,
                      2*radius, 2*radius,
                      a1*16, (a2-a1)*16);
    */

    if(radius<=0.5) {
        drawGridPoint(cp);
    } else {
#ifdef __APPLE1__
                drawArcMac(cp, radius, a1, a2, reversed);
#else
        int   cix;            // Next point on circle
        int   ciy;            //
        double aStep;         // Angle Step (rad)
        double a;             // Current Angle (rad)
        double linStep;       // linear step (pixels)

        if (drawingMode==RS2::ModePreview) {
            linStep = 20.0;
        } else {
            linStep = 6.0;
        }

        if (fabs(linStep/radius)<=1.0) {
            aStep=asin(linStep/radius);
        } else {
            aStep=1.0;
        }

        if (aStep<0.05) {
            aStep = 0.05;
        }

        if(!reversed) {
            // Arc Counterclockwise:
            if(a1>a2-1.0e-10) {
                a2+=2*M_PI;
            }
            //moveTo(toScreenX(p1.x), toScreenY(p1.y));
            QPolygon pa;
            int i=0;
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));
            for(a=a1+aStep; a<=a2; a+=aStep) {
                cix = toScreenX(cp.x+cos(a)*radius);
                ciy = toScreenY(cp.y-sin(a)*radius);
                //lineTo(cix, ciy);
                pa.resize(i+1);
                pa.setPoint(i++, cix, ciy);
            }
            //lineTo(toScreenX(p2.x), toScreenY(p2.y));
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));
            drawPolyline(pa);
        } else {
            // Arc Clockwise:
            if(a1<a2+1.0e-10) {
                a2-=2*M_PI;
            }
            QPolygon pa;
            int i=0;
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p1.x), toScreenY(p1.y));
            //moveTo(toScreenX(p1.x), toScreenY(p1.y));
            for(a=a1-aStep; a>=a2; a-=aStep) {
                cix = toScreenX(cp.x+cos(a)*radius);
                ciy = toScreenY(cp.y-sin(a)*radius);
                //lineTo(cix, ciy);
                pa.resize(i+1);
                pa.setPoint(i++, cix, ciy);
            }
            //lineTo(toScreenX(p2.x), toScreenY(p2.y));
            pa.resize(i+1);
            pa.setPoint(i++, toScreenX(p2.x), toScreenY(p2.y));
            drawPolyline(pa);
        }
#endif
    }
}
Esempio n. 5
0
void toBarChart::paintChart(QPainter *p, QRect &rect)
{
    QFontMetrics fm = p->fontMetrics();

    if (!Zooming)
    {
        if (MinAuto)
        {
            bool first = true;
            std::list<std::list<double> >::reverse_iterator i = Values.rbegin();
            if (i != Values.rend())
            {
                for (std::list<double>::iterator j = (*i).begin(); j != (*i).end(); j++)
                {
                    if (first)
                    {
                        first = false;
                        zMinValue = *j;
                    }
                    else if (zMinValue > *j)
                        zMinValue = *j;
                }
            }
        }
        if (MaxAuto)
        {
            bool first = true;
            std::list<double> total;
            std::list<bool>::iterator e = Enabled.begin();
            {
                for (std::list<std::list<double> >::iterator i = Values.begin(); i != Values.end(); i++)
                {
                    std::list<double>::iterator k = total.begin();
                    if (e == Enabled.end() || *e)
                    {
                        for (std::list<double>::iterator j = (*i).begin(); j != (*i).end(); j++)
                        {
                            if (k == total.end())
                            {
                                total.insert(total.end(), *j);
                                k = total.end();
                            }
                            else
                            {
                                *k += *j;
                                k++;
                            }
                        }
                    }
                    if (e != Enabled.end())
                        e++;
                }
            }
            for (std::list<double>::iterator i = total.begin(); i != total.end(); i++)
            {
                if (first)
                {
                    first = false;
                    zMaxValue = *i;
                }
                else if (zMaxValue < *i)
                    zMaxValue = *i;
            }
        }
        if (!MinAuto)
            zMinValue = MinValue;
        else
        {
            zMinValue = round(zMinValue, false);
            MinValue = zMinValue;
        }
        if (!MaxAuto)
            zMaxValue = MaxValue;
        else
        {
            zMaxValue = round(zMaxValue, true);
            MaxValue = zMaxValue;
        }
    }

    paintTitle(p, rect);
    paintLegend(p, rect);
    paintAxis(p, rect);

    std::list<QPolygon> Points;
    int cp = 0;
    int samples = countSamples();
    int zeroy = int(rect.height() - 2 - ( -zMinValue / (zMaxValue - zMinValue) * (rect.height() - 4)));
    if (samples > 1)
    {
        const QMatrix &mtx = p->worldMatrix();
        p->setClipRect(int(mtx.dx() + 2), int(mtx.dy() + 2), rect.width() - 3, rect.height() - 3);
        if (Zooming)
            p->drawText(2, 2, rect.width() - 4, rect.height() - 4,
                        Qt::AlignLeft | Qt::AlignTop, tr("Zoom"));
        std::list<bool>::reverse_iterator e = Enabled.rbegin();
        for (std::list<std::list<double> >::reverse_iterator i = Values.rbegin(); i != Values.rend(); i++)
        {
            if (e == Enabled.rend() || *e)
            {
                std::list<double> &val = *i;
                int count = 0;
                int skip = SkipSamples;
                QPolygon a(samples + 10);
                int x = rect.width() - 2;
                for (std::list<double>::reverse_iterator j = val.rbegin(); j != val.rend() && x >=
                        2;
                        j++)
                {
                    if (skip > 0)
                        skip--;
                    else
                    {
                        int val = int(rect.height() - 2 - ((*j - zMinValue) / (zMaxValue - zMinValue) * (rect.height() - 4)));
                        x = rect.width() - 2 - count * (rect.width() - 4) / (samples - 1);
                        a.setPoint(count, x, val);
                        count++;
                        if (count >= samples)
                            break;
                    }
                }
                a.resize(count * 2);
                Points.insert(Points.end(), a);
            }
            cp++;
            if (e != Enabled.rend())
                e++;
        }
    }

    std::map<int, int> Bottom;
    std::list<bool>::reverse_iterator e = Enabled.rbegin();
    for (std::list<QPolygon>::iterator i = Points.begin(); i != Points.end();)
    {
        while (e != Enabled.rend() && !*e)
        {
            cp--;
            e++;
        }
        if (e != Enabled.rend())
            e++;
        cp--;

        QPolygon a = *i;
        int lx = 0;
        int lb = 0;
        for (int j = 0; j < a.size() / 2; j++)
        {
            int x, y;
            a.point(j, &x, &y);
            if (Bottom.find(x) == Bottom.end())
                Bottom[x] = 0;
            if (lx != x)
                lb = Bottom[x];
            a.setPoint(a.size() - 1 - j, x, zeroy - lb);
            y -= lb;
            a.setPoint(j, x, y);
            Bottom[x] = zeroy - y;
            lx = x;
        }

        p->save();
        QBrush brush(Utils::toChartBrush(cp));
        p->setBrush(brush.color());
        p->drawPolygon(a);
        if (brush.style() != Qt::SolidPattern)
        {
            p->setBrush(QBrush(Qt::white, brush.style()));
            p->drawPolygon(a);
        }
        p->restore();
        i++;
    }
}
Esempio n. 6
0
// motif arrows look the same whether they are used or not
// is this correct?
static void qDrawMotifArrow(QPainter *p, Qt::ArrowType type, bool down,
                             int x, int y, int w, int h,
                             const QPalette &pal, bool)
{
    QPolygon bFill;                                // fill polygon
    QPolygon bTop;                                // top shadow.
    QPolygon bBot;                                // bottom shadow.
    QPolygon bLeft;                                // left shadow.
    QTransform matrix;                            // xform matrix
    bool vertical = type == Qt::UpArrow || type == Qt::DownArrow;
    bool horizontal = !vertical;
    int         dim = w < h ? w : h;
    int         colspec = 0x0000;                        // color specification array

    if (dim < 2)                                // too small arrow
        return;

    if (dim > 3) {
        if (dim > 6)
            bFill.resize(dim & 1 ? 3 : 4);
        bTop.resize((dim/2)*2);
        bBot.resize(dim & 1 ? dim + 1 : dim);
        bLeft.resize(dim > 4 ? 4 : 2);
        bLeft.putPoints(0, 2, 0,0, 0,dim-1);
        if (dim > 4)
            bLeft.putPoints(2, 2, 1,2, 1,dim-3);
        bTop.putPoints(0, 4, 1,0, 1,1, 2,1, 3,1);
        bBot.putPoints(0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2);

        for(int i=0; i<dim/2-2 ; i++) {
            bTop.putPoints(i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i);
            bBot.putPoints(i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i);
        }
        if (dim & 1)                                // odd number size: extra line
            bBot.putPoints(dim-1, 2, dim-3,dim/2, dim-1,dim/2);
        if (dim > 6) {                        // dim>6: must fill interior
            bFill.putPoints(0, 2, 1,dim-3, 1,2);
            if (dim & 1)                        // if size is an odd number
                bFill.setPoint(2, dim - 3, dim / 2);
            else
                bFill.putPoints(2, 2, dim-4,dim/2-1, dim-4,dim/2);
        }
    }
    else {
        if (dim == 3) {                        // 3x3 arrow pattern
            bLeft.setPoints(4, 0,0, 0,2, 1,1, 1,1);
            bTop .setPoints(2, 1,0, 1,0);
            bBot .setPoints(2, 1,2, 2,1);
        }
        else {                                        // 2x2 arrow pattern
            bLeft.setPoints(2, 0,0, 0,1);
            bTop .setPoints(2, 1,0, 1,0);
            bBot .setPoints(2, 1,1, 1,1);
        }
    }

    if (type == Qt::UpArrow || type == Qt::LeftArrow) {
        matrix.translate(x, y);
        if (vertical) {
            matrix.translate(0, h - 1);
            matrix.rotate(-90);
        } else {
            matrix.translate(w - 1, h - 1);
            matrix.rotate(180);
        }
        if (down)
            colspec = horizontal ? 0x2334 : 0x2343;
        else
            colspec = horizontal ? 0x1443 : 0x1434;
    }
    else if (type == Qt::DownArrow || type == Qt::RightArrow) {
        matrix.translate(x, y);
        if (vertical) {
            matrix.translate(w-1, 0);
            matrix.rotate(90);
        }
        if (down)
            colspec = horizontal ? 0x2443 : 0x2434;
        else
            colspec = horizontal ? 0x1334 : 0x1343;
    }

    const QColor *cols[5];
    cols[0] = 0;
    cols[1] = &pal.button().color();
    cols[2] = &pal.mid().color();
    cols[3] = &pal.light().color();
    cols[4] = &pal.dark().color();
#define CMID        *cols[(colspec>>12) & 0xf]
#define CLEFT        *cols[(colspec>>8) & 0xf]
#define CTOP        *cols[(colspec>>4) & 0xf]
#define CBOT        *cols[colspec & 0xf]

    QPen     savePen   = p->pen();                // save current pen
    QBrush   saveBrush = p->brush();                // save current brush
    QTransform wxm = p->transform();
    QPen     pen(Qt::NoPen);
    const QBrush &brush = pal.brush(QPalette::Button);

    p->setPen(pen);
    p->setBrush(brush);
    p->setTransform(matrix, true);                // set transformation matrix
    p->drawPolygon(bFill);                        // fill arrow
    p->setBrush(Qt::NoBrush);                        // don't fill

    p->setPen(CLEFT);
    p->drawLines(bLeft);
    p->setPen(CTOP);
    p->drawLines(bTop);
    p->setPen(CBOT);
    p->drawLines(bBot);

    p->setTransform(wxm);
    p->setBrush(saveBrush);                        // restore brush
    p->setPen(savePen);                        // restore pen

#undef CMID
#undef CLEFT
#undef CTOP
#undef CBOT
}
Esempio n. 7
0
void RS_Painter::createArc(QPolygon& pa,
                             const RS_Vector& cp, double radius,
                             double a1, double a2,
                             bool reversed) {

	if (radius<1.0e-6) {
        RS_DEBUG->print(RS_Debug::D_WARNING,
			"RS_Painter::createArc: invalid radius: %f", radius);
		return;
	}

    int   cix;            // Next point on circle
    int   ciy;            //
    double aStep;         // Angle Step (rad)
    double a;             // Current Angle (rad)

    if(fabs(2.0/radius)<=1.0) {
        aStep=asin(2.0/radius);
    } else {
        aStep=1.0;
    }

    aStep=aStep/2.0;
    //if (aStep<0.05) {
    //    aStep = 0.05;
    //}
	
	// less than a pixel long lines:
	//if (radius*aStep<1.0) {
	//	aStep = 
	//}

    //QPointArray pa;
    int i=0;
    pa.resize(i+1);
    pa.setPoint(i++, toScreenX(cp.x+cos(a1)*radius),
                toScreenY(cp.y-sin(a1)*radius));
    //moveTo(toScreenX(cp.x+cos(a1)*radius),
    //       toScreenY(cp.y-sin(a1)*radius));
    if(!reversed) {
        // Arc Counterclockwise:
        if(a1>a2-1.0e-10) {
            a2+=2*M_PI;
        }
        for(a=a1+aStep; a<=a2; a+=aStep) {
            cix = toScreenX(cp.x+cos(a)*radius);
            ciy = toScreenY(cp.y-sin(a)*radius);
            //lineTo(cix, ciy);
            pa.resize(i+1);
            pa.setPoint(i++, cix, ciy);
        }
    } else {
        // Arc Clockwise:
        if(a1<a2+1.0e-10) {
            a2-=2*M_PI;
        }
        for(a=a1-aStep; a>=a2; a-=aStep) {
            cix = toScreenX(cp.x+cos(a)*radius);
            ciy = toScreenY(cp.y-sin(a)*radius);
            //lineTo(cix, ciy);
            pa.resize(i+1);
            pa.setPoint(i++, cix, ciy);
        }
    }
    //lineTo(toScreenX(cp.x+cos(a2)*radius),
    //       toScreenY(cp.y-sin(a2)*radius));
    pa.resize(i+1);
    pa.setPoint(i++,
                toScreenX(cp.x+cos(a2)*radius),
                toScreenY(cp.y-sin(a2)*radius));
    //drawPolyline(pa);
}
Esempio n. 8
0
void cbSimulator::showGraph(int id)
{
    unsigned int w,c;
    QGraphicsPolygonItem *wallCanvas;
    QGraphicsRectItem *grCanvas;

	if(id<1 || id > (int)robots.size()) {
		cerr << "Cannot show graph of robot " << id << "\n";
		return;
	}

	labCanvasWidth=(int)(lab->Width()*30);
	labCanvasHeight=(int)(lab->Height()*30);

    labScene=new QGraphicsScene(0, 0, labCanvasWidth,labCanvasHeight);

    labView=new cbGraphView(labScene,this);
    labView->viewport()->setMouseTracking(true);

    QPolygon *pa;

    for(w=1; w<lab->nWalls();w++) {
        vector<cbPoint> &corners=lab->Wall(w)->Corners();
        //pa.resize(corners.size());
        pa = new QPolygon(corners.size());
        for(c=0; c<corners.size();c++)
            pa->setPoint(c,(int)(corners[c].X()*labCanvasWidth/lab->Width()),
                         (int)(labCanvasHeight-corners[c].Y()*labCanvasHeight/lab->Height()) );
        wallCanvas = new QGraphicsPolygonItem(0, labScene);
        wallCanvas->setPolygon(*pa);
        wallCanvas->setBrush(QBrush(Qt::black));
		wallCanvas->setVisible(true);
	}


	unsigned int x,y;
	double distMax=0.0;

	//grAux=graph;  Tentativa de optimizacao
	for(x = 0; x < GRIDSIZE; x++)
	    for(y = 0; y < GRIDSIZE; y++) {
		    *grAux=*graph;

		    //grAux->resetInitState();  Tentativa de optimizacao - testes indicam que fica muito mais lento!!
		    //grAux->writeGraph();

		    cbPoint p((0.5+x)*lab->Width()/GRIDSIZE, (GRIDSIZE-0.5-y)*lab->Height()/GRIDSIZE);
		    grAux->addFinalPoint(id,p);
		    distGrid[x][y]=grAux->dist(id);
		    if(distGrid[x][y] < 2000 && distGrid[x][y]>distMax)
			    distMax=distGrid[x][y];
	    }

//        fprintf(stderr,"distmax=%f labCanvasWidth=%d labCanvasHeight=%d\n",
//			 distMax,labCanvasWidth,labCanvasHeight);

	for(x = 0; x < GRIDSIZE; x++)
	    for(y = 0; y < GRIDSIZE; y++) {

            if(distGrid[x][y]<2000) {
                grCanvas = new QGraphicsRectItem(x*labCanvasWidth/GRIDSIZE,y*labCanvasHeight/GRIDSIZE,
                                                 (x+1)*labCanvasWidth/GRIDSIZE - x*labCanvasWidth/GRIDSIZE,
                                                 (y+1)*labCanvasHeight/GRIDSIZE -y*labCanvasHeight/GRIDSIZE,
                                                 0, labScene);
                QColor color((int)(0+distGrid[x][y]/distMax*250),
                             (int)(0+distGrid[x][y]/distMax*250),
                             (int)(0+distGrid[x][y]/distMax*250));
                grCanvas->setBrush(QBrush(color));
                grCanvas->setPen(QPen(color));
			    grCanvas->setVisible(true);
			    //debug
			    //distGrid[x][y]=(int)(0+distGrid[x][y]/distMax*250);
		    }

        }
    labScene->update();

}