예제 #1
0
파일: editor.cpp 프로젝트: drakargx/ADWIF
 void Editor::onMapReady()
 {
   myUi->graphicsView->scene()->setSceneRect(0, 0, myGame->generator()->width(), myGame->generator()->height());
   for (unsigned int i = 0; i < myGame->generator()->regions().size(); i++)
   {
     QPolygonF qring, sqring;
     auto ring = boost::geometry::exterior_ring(myGame->generator()->regions()[i].poly);
     boost::geometry::convert(ring, qring);
     boost::geometry::simplify(qring, sqring, 1);
     QPen pen;
     pen.setColor(QColor(0,0,0));
     pen.setStyle(Qt::PenStyle::DashLine);
     QBrush brush;
     brush.setStyle(Qt::BrushStyle::SolidPattern);
     std::string colour = myGame->biomes()[myGame->generator()->regions()[i].biome]->jsonValue["mapColour"].asString();
     pen.setColor(QColor(colour.c_str()));
     brush.setColor(QColor(colour.c_str()));
     QGraphicsPolygonItem * pi = new RegionPolygonItem(this);
     pi->setPen(pen);
     pi->setBrush(brush);
     pi->setPolygon(sqring);
     QPolygonF convex;
     boost::geometry::convex_hull(sqring, convex);
     double area = boost::geometry::area(convex);
     pi->setZValue(-area);
     pi->setData(0, i);
     pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsFocusable, true);
     pi->setFlag(QGraphicsItem::GraphicsItemFlag::ItemIsSelectable, true);
     myUi->graphicsView->scene()->addItem(pi);
   }
 }
예제 #2
0
QGraphicsItem* CGraphicsDiamondItem::createItem()
{
	QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent);

	drawPen(pItem);
	drawBrush(pItem);

	qreal x;
	qreal y;
	qreal w;
	qreal h;

	x = GET_VALUE(x).toFloat();
	y = GET_VALUE(y).toFloat();
	w = GET_VALUE(w).toFloat();
	h = GET_VALUE(h).toFloat();

	QPolygonF d;
	d.append(QPointF(x + w/2,y));
	d.append(QPointF(x + w,y + h/2));
	d.append(QPointF(x + w/2,y + h));
	d.append(QPointF(x,y + h/2));
	pItem->setPolygon(d);

	return pItem;
}
예제 #3
0
QGraphicsItem* CGraphicsTriangleItem::createItem()
{
	QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent);

	drawPen(pItem);
	drawBrush(pItem);

	QPolygonF d;
	d.append(QPointF(-GET_VALUE(w).toDouble()/2,GET_VALUE(h).toDouble()/2));
	d.append(QPointF(GET_VALUE(w).toDouble()/2,GET_VALUE(h).toDouble()/2));
	d.append(QPointF(0,-GET_VALUE(h).toDouble()/2));
	pItem->setPolygon(d);

	return pItem;
}
예제 #4
0
QGraphicsItem* CGraphicsPolygonItem::createItem()
{
	QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent);

	drawPen(pItem);
	drawBrush(pItem);

	QPolygonF d;
	QStringList lstPath = GET_VALUE(d).split(' ');
	int iCount = lstPath.size();
	for (int j = 0; j < iCount; j++)
	{
		QStringList lstPoint = lstPath[j].split(',');
		d.append(QPointF(lstPoint[0].toDouble(), lstPoint[1].toDouble()));
		lstPoint.clear();
	}
	pItem->setPolygon(d);

	return pItem;
}
예제 #5
0
void KMapScene::updateObstacles() {

	QGraphicsPolygonItem *cell;
	QVector<QPoint> curve1(0);
	int colorValue = 0, cellNum = 0;
	int r, s;
	QPen penForBlackLine (Qt::black);
	penForBlackLine.setWidth (2);
	for (r = 0; r < cellsOfRadius; r++) {
		for (s = 0; s < cellsOfRing; s++) {
			int sPlusOne = s==cellsOfRing-1 ? 0 : s+1;
			QPoint x0 ( gridImgH[r][s], gridImgV[r][s]);
			QPoint x1 ( gridImgH[r+1][s], gridImgV[r+1][s]);
			QPoint x2 ( gridImgH[r+1][sPlusOne], gridImgV[r+1][sPlusOne]);
			QPoint x3 ( gridImgH[r][sPlusOne], gridImgV[r][sPlusOne]);
			
			curve1.clear();
			curve1.append (x0);
			curve1.append (x1);
			curve1.append (x2);
			curve1.append (x3);
			
			cell = cellsList.at (cellNum);
			cell->setPolygon (QPolygon (curve1) );
			cell->setPen(penForBlackLine);
			if(!smallMap){
				colorValue = ColorMax - PolarGrid[r][s] * ColorMax;
				cell->setBrush (QColor (colorValue, colorValue, colorValue) );
			}else{
				colorValue = ColorMax - PolarGrid[r][s] * ColorMax;
				cell->setBrush (QColor (0, 0, colorValue) );
			}

			cellNum++;
		}
	}
			cout << smallMap << endl;
}
예제 #6
0
void KMapScene::updateObstacles (bool initialization) {
	QGraphicsPolygonItem *cell;
	QVector<QPoint> curve1 (0);
	int colorValue = 0, cellNum = 0;
	int r, s;

	for (r = 0; r < TotalRings ; r++) {
		for (s = 0; s < N; s++) {
			QPoint x0 ( gridImgH[r][s], gridImgV[r][s]);
			QPoint x1 ( gridImgH[ (r+1) ][s], gridImgV[ (r+1) ][s]);
			QPoint x2 ( gridImgH[ (r+1) ][wrapTo (s+1, N) ], gridImgV[ (r+1) ][wrapTo (s+1, N) ]);
			QPoint x3 ( gridImgH[r][wrapTo (s+1, N) ], gridImgV[r][wrapTo (s+1, N) ]);
			curve1.clear();
			curve1.append (x0);
			curve1.append (x1);
			curve1.append (x2);
			curve1.append (x3);
			colorValue = ColorMax - PolarGrid[present][r][s] * ColorMax;

			if (initialization) {
				cell = staticCellsList.at (cellNum);
			} else {
				cell = cellsList.at (cellNum);
			}

			cell->setPolygon (QPolygon (curve1) );

			if (r == InnerRing ) {
				cell->setBrush (QBrush (Qt::white) );
			} else {
				cell->setBrush (QColor (colorValue, colorValue, colorValue) );
			}

			cellNum++;
		}
	}
}
예제 #7
0
void
MatrixElement::reconfigure(timeT time, timeT duration, int pitch, int velocity)
{
    const RulerScale *scale = m_scene->getRulerScale();
    int resolution = m_scene->getYResolution();

    double x0 = scale->getXForTime(time);
    double x1 = scale->getXForTime(time + duration);
    m_width = x1 - x0;

    m_velocity = velocity;

    // if the note has TIED_FORWARD or TIED_BACK properties, draw it with a
    // different fill pattern
    bool tiedNote = (event()->has(BaseProperties::TIED_FORWARD) ||
                     event()->has(BaseProperties::TIED_BACKWARD));
    Qt::BrushStyle brushPattern = (tiedNote ? Qt::Dense2Pattern : Qt::SolidPattern);

    QColor colour;
    if (event()->has(BaseProperties::TRIGGER_SEGMENT_ID)) {
        //!!! Using gray for trigger events and events from other, non-active
        // segments won't work.  This should be handled some other way, with a
        // color outside the range of possible velocity choices, which probably
        // leaves some kind of curious light blue or something
        colour = Qt::cyan;
    } else {
        colour = DefaultVelocityColour::getInstance()->getColour(velocity);
    }
    colour.setAlpha(160);

    double fres(resolution);

    if (m_drum) {
        fres = resolution + 1;
        QGraphicsPolygonItem *item = dynamic_cast<QGraphicsPolygonItem *>(m_item);
        if (!item) {
            delete m_item;
            item = new QGraphicsPolygonItem;
            m_item = item;
            m_scene->addItem(m_item);
        }
        QPolygonF polygon;
        polygon << QPointF(0, 0)
                << QPointF(fres/2, fres/2)
                << QPointF(0, fres)
                << QPointF(-fres/2, fres/2)
                << QPointF(0, 0);
        item->setPolygon(polygon);
        item->setPen
            (QPen(GUIPalette::getColour(GUIPalette::MatrixElementBorder), 0));
        item->setBrush(QBrush(colour, brushPattern));
    } else {
        QGraphicsRectItem *item = dynamic_cast<QGraphicsRectItem *>(m_item);
        if (!item) {
            delete m_item;
            item = new QGraphicsRectItem;
            m_item = item;
            m_scene->addItem(m_item);
        }
        float width = m_width;
        if (width < 1) width = 1;
        QRectF rect(0, 0, width, fres + 1);
        item->setRect(rect);
        item->setPen
            (QPen(GUIPalette::getColour(GUIPalette::MatrixElementBorder), 0));
        item->setBrush(QBrush(colour, brushPattern));
    }

    setLayoutX(x0);

    m_item->setData(MatrixElementData, QVariant::fromValue((void *)this));

    // set the Y position taking m_pitchOffset into account, subtracting the
    // opposite of whatever the originating segment transpose was

//    std::cout << "TRANSPOSITION TEST: event pitch: "
//              << (pitch ) << " m_pitchOffset: " << m_pitchOffset
//              << std::endl;

    m_item->setPos(x0, (127 - pitch - m_pitchOffset) * (resolution + 1));

    // set a tooltip explaining why this event is drawn in a different pattern
    if (tiedNote) m_item->setToolTip(QObject::tr("This event is tied to another event."));
}
예제 #8
0
void ProfileGraphicsView::plot_depth_profile()
{
    int i, incr;
    int sec, depth;
    struct plot_data *entry;
    int maxtime, maxdepth, marker, maxline;
    int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 };

    /* Get plot scaling limits */
    maxtime = get_maxtime(&gc.pi);
    maxdepth = get_maxdepth(&gc.pi);

    gc.maxtime = maxtime;

    /* Time markers: at most every 10 seconds, but no more than 12 markers.
     * We start out with 10 seconds and increment up to 30 minutes,
     * depending on the dive time.
     * This allows for 6h dives - enough (I hope) for even the craziest
     * divers - but just in case, for those 8h depth-record-breaking dives,
     * we double the interval if this still doesn't get us to 12 or fewer
     * time markers */
    i = 0;
    while (maxtime / increments[i] > 12 && i < 7)
        i++;
    incr = increments[i];
    while (maxtime / incr > 12)
        incr *= 2;

    gc.leftx = 0;
    gc.rightx = maxtime;
    gc.topy = 0;
    gc.bottomy = 1.0;

    last_gc = gc;

    QColor c = getColor(TIME_GRID);
    for (i = incr; i < maxtime; i += incr) {
        QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(i, 0), SCALEGC(i, 1));
        QPen pen(defaultPen);
        pen.setColor(c);
        item->setPen(pen);
        scene()->addItem(item);
    }

    timeMarkers = new QGraphicsRectItem();
    /* now the text on the time markers */
    struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, LINE_DOWN};
    if (maxtime < 600) {
        /* Be a bit more verbose with shorter dives */
        for (i = incr; i < maxtime; i += incr)
            plot_text(&tro, QPointF(i, 0), QString("%1:%2").arg(i/60).arg(i%60, 2, 10, QChar('0')), timeMarkers);
    } else {
        /* Only render the time on every second marker for normal dives */
        for (i = incr; i < maxtime; i += 2 * incr)
            plot_text(&tro, QPointF(i, 0), QString("%1").arg(QString::number(i/60)), timeMarkers);
    }
    timeMarkers->setPos(0,0);
    scene()->addItem(timeMarkers);

    /* Depth markers: every 30 ft or 10 m*/
    gc.leftx = 0;
    gc.rightx = 1.0;
    gc.topy = 0;
    gc.bottomy = maxdepth;
    switch (prefs.units.length) {
    case units::METERS:
        marker = 10000;
        break;
    case units::FEET:
        marker = 9144;
        break;	/* 30 ft */
    }
    maxline = qMax(gc.pi.maxdepth + marker, maxdepth * 2 / 3);

    c = getColor(DEPTH_GRID);

    for (i = marker; i < maxline; i += marker) {
        QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, i), SCALEGC(1, i));
        QPen pen(defaultPen);
        pen.setColor(c);
        item->setPen(pen);
        scene()->addItem(item);
    }

    gc.leftx = 0;
    gc.rightx = maxtime;
    c = getColor(MEAN_DEPTH);

    /* Show mean depth */
    if (! gc.printer) {
        QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(0, gc.pi.meandepth),
                SCALEGC(gc.pi.entry[gc.pi.nr - 1].sec, gc.pi.meandepth));
        QPen pen(defaultPen);
        pen.setColor(c);
        item->setPen(pen);
        scene()->addItem(item);
    }

#if 0
    /*
     * These are good for debugging text placement etc,
     * but not for actual display..
     */
    if (0) {
        plot_smoothed_profile(gc, pi);
        plot_minmax_profile(gc, pi);
    }
#endif

    /* Do the depth profile for the neat fill */
    gc.topy = 0;
    gc.bottomy = maxdepth;

    entry = gc.pi.entry;

    QPolygonF p;
    QLinearGradient pat(0.0,0.0,0.0,scene()->height());
    QGraphicsPolygonItem *neatFill = NULL;

    p.append(QPointF(SCALEGC(0, 0)));
    for (i = 0; i < gc.pi.nr; i++, entry++)
        p.append(QPointF(SCALEGC(entry->sec, entry->depth)));

    /* Show any ceiling we may have encountered */
    if (prefs.profile_dc_ceiling) {
        for (i = gc.pi.nr - 1; i >= 0; i--, entry--) {
            if (!entry->in_deco) {
                /* not in deco implies this is a safety stop, no ceiling */
                p.append(QPointF(SCALEGC(entry->sec, 0)));
            } else if (entry->stopdepth < entry->depth) {
                p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth)));
            } else {
                p.append(QPointF(SCALEGC(entry->sec, entry->depth)));
            }
        }
    }
    pat.setColorAt(1, getColor(DEPTH_BOTTOM));
    pat.setColorAt(0, getColor(DEPTH_TOP));

    neatFill = new QGraphicsPolygonItem();
    neatFill->setPolygon(p);
    neatFill->setBrush(QBrush(pat));
    neatFill->setPen(QPen(QBrush(Qt::transparent),0));
    scene()->addItem(neatFill);


    /* if the user wants the deco ceiling more visible, do that here (this
     * basically draws over the background that we had allowed to shine
     * through so far) */
    if (prefs.profile_dc_ceiling && prefs.profile_red_ceiling) {
        p.clear();
        pat.setColorAt(0, getColor(CEILING_SHALLOW));
        pat.setColorAt(1, getColor(CEILING_DEEP));

        entry = gc.pi.entry;
        p.append(QPointF(SCALEGC(0, 0)));
        for (i = 0; i < gc.pi.nr; i++, entry++) {
            if (entry->in_deco && entry->stopdepth) {
                if (entry->stopdepth < entry->depth) {
                    p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth)));
                } else {
                    p.append(QPointF(SCALEGC(entry->sec, entry->depth)));
                }
            } else {
                p.append(QPointF(SCALEGC(entry->sec, 0)));
            }
        }

        neatFill = new QGraphicsPolygonItem();
        neatFill->setBrush(QBrush(pat));
        neatFill->setPolygon(p);
        neatFill->setPen(QPen(QBrush(Qt::NoBrush),0));
        scene()->addItem(neatFill);
    }

    /* finally, plot the calculated ceiling over all this */
    if (prefs.profile_calc_ceiling) {
        pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
        pat.setColorAt(1, getColor(CALC_CEILING_DEEP));

        entry = gc.pi.entry;
        p.clear();
        p.append(QPointF(SCALEGC(0, 0)));
        for (i = 0; i < gc.pi.nr; i++, entry++) {
            if (entry->ceiling)
                p.append(QPointF(SCALEGC(entry->sec, entry->ceiling)));
            else
                p.append(QPointF(SCALEGC(entry->sec, 0)));
        }
        p.append(QPointF(SCALEGC((entry-1)->sec, 0)));
        neatFill = new QGraphicsPolygonItem();
        neatFill->setPolygon(p);
        neatFill->setPen(QPen(QBrush(Qt::NoBrush),0));
        neatFill->setBrush(pat);
        scene()->addItem(neatFill);
    }

    /* plot the calculated ceiling for all tissues */
    if (prefs.profile_calc_ceiling && prefs.calc_all_tissues) {
        int k;
        for (k=0; k<16; k++) {
            pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
            pat.setColorAt(1, QColor(100, 100, 100, 50));

            entry = gc.pi.entry;
            p.clear();
            p.append(QPointF(SCALEGC(0, 0)));
            for (i = 0; i < gc.pi.nr; i++, entry++) {
                if ((entry->ceilings)[k])
                    p.append(QPointF(SCALEGC(entry->sec, (entry->ceilings)[k])));
                else
                    p.append(QPointF(SCALEGC(entry->sec, 0)));
            }
            p.append(QPointF(SCALEGC((entry-1)->sec, 0)));
            neatFill = new QGraphicsPolygonItem();
            neatFill->setPolygon(p);
            neatFill->setBrush(pat);
            scene()->addItem(neatFill);
        }
    }
    /* next show where we have been bad and crossed the dc's ceiling */
    if (prefs.profile_dc_ceiling) {
        pat.setColorAt(0, getColor(CEILING_SHALLOW));
        pat.setColorAt(1, getColor(CEILING_DEEP));

        entry = gc.pi.entry;
        p.clear();
        p.append(QPointF(SCALEGC(0, 0)));
        for (i = 0; i < gc.pi.nr; i++, entry++)
            p.append(QPointF(SCALEGC(entry->sec, entry->depth)));

        for (i-- , entry--; i >= 0; i--, entry--) {
            if (entry->in_deco && entry->stopdepth > entry->depth) {
                p.append(QPointF(SCALEGC(entry->sec, entry->stopdepth)));
            } else {
                p.append(QPointF(SCALEGC(entry->sec, entry->depth)));
            }
        }
    }
    neatFill = new QGraphicsPolygonItem();
    neatFill->setPolygon(p);
    neatFill->setPen(QPen(QBrush(Qt::NoBrush),0));
    neatFill->setBrush(QBrush(pat));
    scene()->addItem(neatFill);

    /* Now do it again for the velocity colors */
    entry = gc.pi.entry;
    for (i = 1; i < gc.pi.nr; i++) {
        entry++;
        sec = entry->sec;
        /* we want to draw the segments in different colors
         * representing the vertical velocity, so we need to
         * chop this into short segments */
        depth = entry->depth;
        QGraphicsLineItem *item = new QGraphicsLineItem(SCALEGC(entry[-1].sec, entry[-1].depth), SCALEGC(sec, depth));
        QPen pen(defaultPen);
        pen.setColor(getColor((color_indice_t)(VELOCITY_COLORS_START_IDX + entry->velocity)));
        item->setPen(pen);
        scene()->addItem(item);
    }
}
예제 #9
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();

}