1 #include "MosaicSceneItem.h"
6 #include <QApplication>
9 #include <QGraphicsItem>
13 #include <QStyleOptionGraphicsItem>
14 #include <QTreeWidgetItem>
17 #include "DisplayProperties.h"
18 #include "FileDialog.h"
21 #include "ImageList.h"
25 #include "MosaicGraphicsView.h"
26 #include "MosaicSceneWidget.h"
34 using namespace geos::geom;
45 if (parent->getProjection() == NULL) {
46 std::string msg =
"Parent does not have projection in MosaicWidget";
52 connect(m_image, SIGNAL(destroyed(
QObject *)),
53 this, SLOT(lostCubeDisplay()));
54 connect(m_image, SIGNAL(destroyed(
QObject *)),
55 this, SLOT(deleteLater()));
59 m_cubeDnStretch = NULL;
61 m_showingLabel =
false;
62 m_ignoreCubeDisplayChanged =
false;
72 setAcceptHoverEvents(
true);
84 if(parent->userHasTools()) {
102 scene()->removeItem(
this);
104 while(m_polygons->size()) {
105 delete m_polygons->takeAt(0);
110 QRectF MosaicSceneItem::boundingRect()
const {
113 QGraphicsPolygonItem *polygon;
114 foreach(polygon, *m_polygons) {
115 boundingRect = boundingRect.united(polygon->boundingRect());
118 foreach(polyChild, polygon->childItems()) {
119 if(polyChild->isVisible()) {
120 boundingRect = boundingRect.united(
121 mapFromItem(polyChild, polyChild->boundingRect()).boundingRect());
138 const QStyleOptionGraphicsItem *option,
QWidget *widget) {
146 if (!childItems().count()) {
147 foreach (QGraphicsPolygonItem *polyItem, *m_polygons) {
148 polyItem->paint(painter, option, widget);
157 void MosaicSceneItem::setupFootprint() {
163 tr(
"Cannot display footprints of images which have no footprints. "
171 catch(IException &e) {
172 m_image->deleteLater();
174 IString msg =
"Could not project the footprint from cube [" +
187 prepareGeometryChange();
193 while(m_polygons->size()) {
194 QGraphicsPolygonItem *polyItem = m_polygons->at(0);
196 if (polyItem->scene()) {
197 polyItem->scene()->removeItem(polyItem);
199 m_polygons->removeAll(polyItem);
221 bool useFullChildrenHierarchy = (mp->getNumGeometries() > 1) || m_showingLabel;
223 for (
unsigned int i = 0; i < mp->getNumGeometries(); i++) {
224 const Geometry *geom = mp->getGeometryN(i);
225 CoordinateSequence *pts;
227 pts = geom->getCoordinates();
235 for (
unsigned int j = 0; j < pts->getSize(); j++) {
239 double x = proj->
XCoord();
240 double y = -1 * (proj->
YCoord());
242 polyPoints.push_back(QPointF(x, y));
246 setFlag(QGraphicsItem::ItemIsSelectable);
248 QGraphicsPolygonItem *polyItem = NULL;
250 if (useFullChildrenHierarchy) {
251 polyItem =
new QGraphicsPolygonItem(
this);
254 polyItem =
new QGraphicsPolygonItem;
257 polyItem->setPolygon(QPolygonF(polyPoints));
259 if (m_showingLabel) {
260 QGraphicsSimpleTextItem *label = NULL;
262 label =
new QGraphicsSimpleTextItem(polyItem);
266 label->setFlag(QGraphicsItem::ItemIsMovable);
267 label->setFont(QFont(
"Helvetica", 10));
268 label->setPos(polyItem->polygon().boundingRect().center());
269 label->setFlag(QGraphicsItem::ItemIgnoresTransformations,
true);
271 QRectF boundingRect = polyItem->boundingRect();
272 if(boundingRect.width() < boundingRect.height())
276 m_polygons->append(polyItem);
295 double pixelValue = 0;
302 pixelValue = gryBrick[0];
303 if (pixelValue ==
Null) {
306 if (pixelValue < 0) pixelValue = 0;
307 if (pixelValue > 255) pixelValue = 255;
320 const QStyleOptionGraphicsItem *option) {
322 QApplication::setOverrideCursor(Qt::WaitCursor);
325 QGraphicsPolygonItem *polygon;
326 foreach(polygon, *m_polygons) {
327 QPolygonF polyBounding = polygon->polygon();
328 QRectF sceneRect = polyBounding.boundingRect();
329 QPolygon screenPoly = m_scene->getView()->mapFromScene(sceneRect);
330 QRect visibleBox = screenPoly.boundingRect();
332 int bbWidth = (int)visibleBox.width();
333 int bbHeight = (int)visibleBox.height();
335 int bbLeft = visibleBox.left();
336 int bbTop = visibleBox.top();
337 int bbRight = visibleBox.right();
338 int bbBottom = visibleBox.bottom();
340 QImage image(bbWidth, bbHeight, QImage::Format_ARGB32);
342 for (
int y = bbTop; y <= bbBottom; y++) {
343 QRgb *lineData = (QRgb *)image.scanLine(y - bbTop);
345 for (
int x = bbLeft; x <= bbRight; x++) {
346 lineData[x - bbLeft] = qRgba(0, 0, 0, 0);
350 QPointF scenePos = m_scene->getView()->mapToScene(
353 if(polygon->polygon().containsPoint(scenePos, Qt::OddEvenFill)) {
356 m_scene->getProjection()->SetCoordinate(scenePos.x(),
359 double lat = ((
TProjection *)(m_scene->getProjection()))->UniversalLatitude();
360 double lon = ((
TProjection *)(m_scene->getProjection()))->UniversalLongitude();
386 int stretched = (int)stretch->
Map(dn);
388 lineData[x - bbLeft] = qRgba(stretched, stretched,
398 painter->drawImage(polygon->boundingRect(), image);
405 QApplication::restoreOverrideCursor();
409 QColor MosaicSceneItem::color()
const {
420 if (!m_ignoreCubeDisplayChanged) {
421 bool wasBlocking = m_scene->blockSelectionChange(
true);
423 m_scene->blockSelectionChange(wasBlocking);
425 if (m_showingLabel !=
451 switch (event->type()) {
452 case QEvent::GraphicsSceneContextMenu:
453 scenePos = ((QGraphicsSceneContextMenuEvent *)event)->scenePos();
455 case QEvent::GraphicsSceneHoverEnter:
456 case QEvent::GraphicsSceneHoverMove:
457 case QEvent::GraphicsSceneHoverLeave:
458 scenePos = ((QGraphicsSceneHoverEvent *)event)->scenePos();
460 case QEvent::GraphicsSceneMouseMove:
461 case QEvent::GraphicsSceneMousePress:
462 case QEvent::GraphicsSceneMouseRelease:
463 case QEvent::GraphicsSceneMouseDoubleClick:
464 scenePos = ((QGraphicsSceneMouseEvent *)event)->scenePos();
470 bool ourEvent =
true;
471 if(!scenePos.isNull()) {
476 return QGraphicsObject::sceneEvent(event);
493 QGraphicsPolygonItem * polygon;
494 foreach(polygon, *m_polygons) {
495 if(polygon->contains(p)) {
512 QGraphicsPolygonItem * polygon;
514 m_ignoreCubeDisplayChanged =
true;
520 selected = isSelected();
523 foreach(polygon, *m_polygons) {
524 selected = selected || (polygon->scene() && polygon->isSelected());
530 if(selected != isSelected()) {
531 bool wasBlocking = m_scene->blockSelectionChange(
true);
532 setSelected(selected);
533 m_scene->blockSelectionChange(wasBlocking);
536 foreach(polygon, *m_polygons) {
537 if(polygon->isSelected() != selected) {
538 polygon->setSelected(selected);
542 m_ignoreCubeDisplayChanged =
false;
552 QGraphicsSceneContextMenuEvent *event) {
557 title->setEnabled(
false);
563 Directory *directory = m_scene->directory();
564 Project *project = directory ? directory->project() : NULL;
569 displayActs.append(NULL);
570 displayActs.append(directory->supportedActions(
new ImageList(images)));
574 foreach(displayAct, displayActs) {
575 if (displayAct == NULL) {
579 menu.addAction(displayAct);
584 QAction *removeAction = menu.addAction(
"Close Cube");
585 connect(removeAction, SIGNAL(triggered()),
586 m_image, SLOT(deleteLater()));
588 menu.exec(event->screenPos());
593 void MosaicSceneItem::lostCubeDisplay() {
604 if (childItems().count()) {
605 setFlag(QGraphicsItem::ItemIsSelectable,
false);
608 setFlag(QGraphicsItem::ItemIsSelectable, m_scene->cubesSelectable());
614 foreach(QAbstractGraphicsShapeItem *polygon, *m_polygons) {
617 polygon->setBrush(color());
620 polygon->setBrush(Qt::NoBrush);
624 QColor opaqueColor(color());
625 opaqueColor.setAlpha(255);
627 polygon->setPen(opaqueColor);
630 polygon->setPen(Qt::NoPen);
633 polygon->setFlag(QGraphicsItem::ItemIsSelectable,
634 m_scene->cubesSelectable());
638 polyChild->setVisible(
641 polyChild->setFlag(QGraphicsItem::ItemIsSelectable,
642 m_scene->cubesSelectable());
646 if(polyChild->type() == 9) {
647 QGraphicsSimpleTextItem * text =
648 (QGraphicsSimpleTextItem *)polyChild;
649 text->setBrush(opaqueColor);
655 emit changed(regionsChanged);
668 if (m_cubeDnStretch != NULL || !m_image)
return m_cubeDnStretch;
679 stats.
AddData(mgr.DoubleBuffer(), mgr.size());
681 for(
int i = 0; i < skip; i++)
685 m_cubeDnStretch =
new Stretch();
690 m_cubeDnStretch->
SetLis(0.0);
691 m_cubeDnStretch->
SetLrs(0.0);
692 m_cubeDnStretch->
SetHis(255.0);
693 m_cubeDnStretch->
SetHrs(255.0);
694 m_cubeDnStretch->SetMinimum(0.0);
695 m_cubeDnStretch->SetMaximum(255.0);
697 return m_cubeDnStretch;