Пример #1
0
void PainterThread::drawAttrib(QPainter *p, Attributes *attrib)
{
    if (attrib->getType() == TObsAgent)
        return;

    //---- Desenha o atributo
    p->begin(attrib->getImage());

    p->setPen(Qt::NoPen); //defaultPen);

	//@RAIAN: Desenhando a vizinhanca
	if (attrib->getType() == TObsNeighborhood)
	{
		QColor color(Qt::white);
                QVector<QMap<QString, QList<double> > > *neighborhoods = attrib->getNeighValues();
		QVector<ObsLegend> *vecLegend = attrib->getLegend();

		QPen pen = p->pen();
		pen.setStyle(Qt::SolidLine);
		pen.setWidth(attrib->getWidth());

        // int random = qrand() % 256;
		double xCell = -1.0, yCell = -1.0;

		for (int pos = 0; pos < neighborhoods->size(); pos++)
		{
            QMap<QString, QList<double> > neigh = neighborhoods->at(pos);

			xCell = attrib->getXsValue()->at(pos);
			yCell = attrib->getYsValue()->at(pos);

			if ((xCell >= 0) && (yCell >=0))
			{
                QMap<QString, QList<double> >::Iterator itNeigh = neigh.begin();

				while (itNeigh != neigh.end())
				{
					QString neighID = itNeigh.key();
					QList<double> neighbor = itNeigh.value();

					double xNeigh = neighbor.at(0);
					double yNeigh = neighbor.at(1);
					double weight = neighbor.at(2);

					if (vecLegend->isEmpty())
					{
						weight = weight - attrib->getMinValue();
						double c = weight * attrib->getVal2Color();
						if (c >= 0 && c <= 255)
						{
							color.setRgb(c, c, c);
						}
						else
						{
							color.setRgb(255, 255, 255);
						}

						pen.setColor(color);
					}
					else
					{
						for (int j = 0; j < vecLegend->size(); j++)
						{
							ObsLegend leg = vecLegend->at(j);
							if (attrib->getGroupMode() == 3)
							{
								if (weight == leg.getTo().toDouble())
								{
									pen.setColor(leg.getColor());
									break;
								}
							}
							else
							{
								if ((leg.getFrom().toDouble() <= weight) && (weight < leg.getTo().toDouble()))
								{
									pen.setColor(leg.getColor());
									break;
								}
							}
						}
					}
					p->setPen(pen);

					if ((xNeigh >= 0) && (yNeigh >= 0))
					{
						drawNeighborhood(p, xCell, yCell, xNeigh, yNeigh);
					}

					itNeigh++;
				}
			}
		}
	}
	//@RAIAN: FIM
	else
	{
		if (attrib->getDataType() == TObsNumber)
		{
			QColor color(Qt::white);
			QVector<double> *values = attrib->getNumericValues();
			QVector<ObsLegend> *vecLegend = attrib->getLegend();

			double x = -1.0, y = -1.0, v = 0.0;

			int vSize = values->size();
			int xSize = attrib->getXsValue()->size();
			int ySize = attrib->getYsValue()->size();

			for (int pos = 0; (pos < vSize && pos < xSize && pos < ySize); pos++)
			{
				v = values->at(pos);

				// Corrige o bug gerando quando um agente morre
				if (attrib->getXsValue()->isEmpty() || attrib->getXsValue()->size() == pos)
					break;

				x = attrib->getXsValue()->at(pos);
				y = attrib->getYsValue()->at(pos);

				if (vecLegend->isEmpty())
				{
					v = v - attrib->getMinValue();

					double c = v * attrib->getVal2Color();
					if ((c >= 0) && (c <= 255))
					{
						color.setRgb(c, c, c);
					}
					else
					{
						color.setRgb(255, 255, 255);
					}
					p->setBrush(color);
				}
				else
				{
					for (int j = 0; j < vecLegend->size(); j++)
					{
						p->setBrush(Qt::white);

						const ObsLegend &leg = vecLegend->at(j);
						if (attrib->getGroupMode() == TObsUniqueValue) // valor ?nico 3
						{
							if (v == leg.getToNumber())
							{
								p->setBrush(leg.getColor());
								break;
							}
						}
						else
						{
							if ((leg.getFromNumber() <= v) && (v < leg.getToNumber()))
							{
								p->setBrush(leg.getColor());
								break;
							}
						}
					}
				}
				if ((x >= 0) && (y >= 0))
					draw(p, attrib->getType(), x, y);
			}
		}
		else if (attrib->getDataType() == TObsText)
		{
			QVector<QString> *values = attrib->getTextValues();
			QVector<ObsLegend> *vecLegend = attrib->getLegend();

            int random = qrand() % 256;
			double x = -1.0, y = -1.0;

			int vSize = values->size();
			int xSize = attrib->getXsValue()->size();
			int ySize = attrib->getYsValue()->size();

			for (int pos = 0; (pos < vSize && pos < xSize && pos < ySize); pos++)
			{
				const QString & v = values->at(pos);

				// Corrige o bug gerando quando um agente morre
				if (attrib->getXsValue()->isEmpty() || attrib->getXsValue()->size() == pos)
					break;

				x = attrib->getXsValue()->at(pos);
				y = attrib->getYsValue()->at(pos);

				if (vecLegend->isEmpty())
				{
					p->setBrush(QColor(random, random, random));
				}
				else
				{
					p->setBrush(Qt::white);
					for (int j = 0; j < vecLegend->size(); j++)
					{
						const ObsLegend &leg = vecLegend->at(j);
						if (v == leg.getFrom())
						{
							p->setBrush(leg.getColor());
							break;
						}
					}
				}

				if ((x >= 0) && (y >= 0))
					draw(p, attrib->getType(), x, y);
			}
		}
	}
    p->end();
}
Пример #2
0
void PainterThread::drawAttrib(QPainter *p, Attributes *attrib)
{
    if (attrib->getType() == TObsAgent)
        return;

    //---- Desenha o atributo
    p->begin(attrib->getImage());

    p->setPen(Qt::NoPen); //defaultPen);

	//@RAIAN: Desenhando a vizinhanca
	if(attrib->getType() == TObsNeighborhood)
	{
		QColor color(Qt::white);
                QVector<QMap<QString, QList<double> > > *neighborhoods = attrib->getNeighValues();
		QVector<ObsLegend> *vecLegend = attrib->getLegend();

		QPen pen = p->pen();
		pen.setStyle(Qt::SolidLine);
		pen.setWidth(attrib->getWidth());

		// int random = rand() % 256;
		double xCell = -1.0, yCell = -1.0;

		for(int pos = 0; pos < neighborhoods->size(); pos++)
		{
            QMap<QString, QList<double> > neigh = neighborhoods->at(pos);
			
			xCell = attrib->getXsValue()->at(pos);
			yCell = attrib->getYsValue()->at(pos);

			if((xCell >= 0) && (yCell >=0))
			{
                QMap<QString, QList<double> >::Iterator itNeigh = neigh.begin();

				while(itNeigh != neigh.end())
				{
					QString neighID = itNeigh.key();
					QList<double> neighbor = itNeigh.value();

					double xNeigh = neighbor.at(0);
					double yNeigh = neighbor.at(1);
					double weight = neighbor.at(2);

					if(vecLegend->isEmpty())
					{
						weight = weight - attrib->getMinValue();
						double c = weight * attrib->getVal2Color();
						if(c >= 0 && c <= 255)
						{
							color.setRgb(c, c, c);
						}
						else
						{
							if( !reconfigMaxMin )
							{
								printf("C++ - Min value: %f\n", attrib->getMinValue());
								printf("C++ - Max value: %f\n", attrib->getMaxValue());
								printf("C++ - c value: %f\n", c);

								qWarning("Warning: Invalid color. You need to reconfigure the maximum "
									"and the minimum values of the \"%s\".", 
									qPrintable(attrib->getName()) );

								reconfigMaxMin = true;
							}
							color.setRgb(255, 255, 255);
						}

						pen.setColor(color);
					}
					else
					{
						for(int j = 0; j < vecLegend->size(); j++)
						{
							ObsLegend leg = vecLegend->at(j);
							if(attrib->getGroupMode() == 3)
							{
								if(weight == leg.getTo().toDouble())
								{
									pen.setColor(leg.getColor());
									break;
								}
							}
							else
							{
								if((leg.getFrom().toDouble() <= weight) && (weight < leg.getTo().toDouble()))
								{
									pen.setColor(leg.getColor());
									break;
								}
							}
						}
					}
					p->setPen(pen);

					if((xNeigh >= 0) && (yNeigh >= 0))
					{
						drawNeighborhood(p, xCell, yCell, xNeigh, yNeigh);
					}

					itNeigh++;
				}
			}
		}
	}
	//@RAIAN: FIM
	else
	{
		if (attrib->getDataType() == TObsNumber)
		{
			QColor color(Qt::white);
			QVector<double> *values = attrib->getNumericValues();
			QVector<ObsLegend> *vecLegend = attrib->getLegend();

			double x = -1.0, y = -1.0, v = 0.0;

#ifdef DEBUG_OBSERVER		
			// if (attrib->getType() != TObsCell)
			{
				qDebug() << "\n----TObsNumber\nattrib->getXsValue()->size(): " << attrib->getXsValue()->size();
				qDebug() << "values->size(): " << values->size() << "\n----\n";
			}
#endif

			int vSize = values->size();
			int xSize = attrib->getXsValue()->size();
			int ySize = attrib->getYsValue()->size();

			for(int pos = 0; (pos < vSize && pos < xSize && pos < ySize); pos++)
			{
				v = values->at(pos);

				// Corrige o bug gerando quando um agente morre
				if (attrib->getXsValue()->isEmpty() || attrib->getXsValue()->size() == pos)
					break;

				x = attrib->getXsValue()->at(pos);
				y = attrib->getYsValue()->at(pos);

				if (vecLegend->isEmpty())
				{
					v = v - attrib->getMinValue();

					double c = v * attrib->getVal2Color();
					if ((c >= 0) && (c <= 255))
					{
						color.setRgb(c, c, c);
					}
					else
					{
						if (! reconfigMaxMin)
						{
							if (! QUIET_MODE )
								qWarning("Warning: Invalid color. You need to reconfigure the "
										 "maximum and the minimum values of the attribute \"%s\".",
										 qPrintable(attrib->getName()) );

							reconfigMaxMin = true;
						}
						color.setRgb(255, 255, 255);
					}
					p->setBrush(color);
				}
				else
				{
					for(int j = 0; j < vecLegend->size(); j++)
					{
						p->setBrush(Qt::white);

						const ObsLegend &leg = vecLegend->at(j);
						if (attrib->getGroupMode() == TObsUniqueValue) // valor único 3
						{
							if (v == leg.getToNumber())
							{
								p->setBrush(leg.getColor());
								break;
							}
						}
						else
						{
							if ((leg.getFromNumber() <= v) && (v < leg.getToNumber()))
							{
								p->setBrush(leg.getColor());
								break;
							}
						}
					}
				}
				if ((x >= 0) && ( y >= 0))
					draw(p, attrib->getType(), x, y);
			}
		}
		else if (attrib->getDataType() == TObsText)
		{
			QVector<QString> *values = attrib->getTextValues();
			QVector<ObsLegend> *vecLegend = attrib->getLegend();

#ifdef DEBUG_OBSERVER		
			if (attrib->getType() != TObsCell)
			{
				qDebug() << "\n----TObsNumber\nattrib->getXsValue()->size(): " << attrib->getXsValue()->size();
				qDebug() << "values->size(): " << values->size() << "\n----\n";
			}
#endif

			int random = rand() % 256;
			double x = -1.0, y = -1.0;

			int vSize = values->size();
			int xSize = attrib->getXsValue()->size();
			int ySize = attrib->getYsValue()->size();

			for (int pos = 0; (pos < vSize && pos < xSize && pos < ySize); pos++)
			{
				const QString & v = values->at(pos);

				// Corrige o bug gerando quando um agente morre
				if (attrib->getXsValue()->isEmpty() || attrib->getXsValue()->size() == pos)
					break;

				x = attrib->getXsValue()->at(pos);
				y = attrib->getYsValue()->at(pos);

				if (vecLegend->isEmpty())
				{
					p->setBrush(QColor(random, random, random));
				}
				else
				{
					p->setBrush(Qt::white);
					for(int j = 0; j < vecLegend->size(); j++)
					{
						const ObsLegend &leg = vecLegend->at(j);
						if (v == leg.getFrom())
						{
							p->setBrush(leg.getColor());
							break;
						}
					}
				}

				if ((x >= 0) && ( y >= 0))
					draw(p, attrib->getType(), x, y);
			}
		}
	}
    p->end();
}