1 #include "MosaicControlNetTool.h"
5 #include <QGraphicsScene>
7 #include <QInputDialog>
11 #include <QMessageBox>
12 #include <QPushButton>
14 #include "ChipViewportsWidget.h"
16 #include "ControlList.h"
17 #include "ControlNet.h"
18 #include "ControlNetGraphicsItem.h"
19 #include "ControlPoint.h"
20 #include "ControlPointEditView.h"
21 #include "ControlPointEditWidget.h"
22 #include "Directory.h"
23 #include "FileDialog.h"
25 #include "IException.h"
30 #include "Longitude.h"
31 #include "MosaicControlNetToolMovementConfigDialog.h"
32 #include "MosaicSceneItem.h"
33 #include "MosaicSceneWidget.h"
34 #include "MosaicGraphicsView.h"
36 #include "Projection.h"
37 #include "PvlObject.h"
38 #include "SpecialPixel.h"
39 #include "TProjection.h"
51 m_controlNetGraphics = NULL;
52 m_loadControlNetButton = NULL;
53 m_displayControlNetButton = NULL;
54 m_displayConnectivity = NULL;
55 m_closeNetwork = NULL;
56 m_controlNetFileLabel = NULL;
58 m_randomizeColors = NULL;
66 m_displayControlNetButton =
new QPushButton(
"Display");
67 m_displayControlNetButton->setCheckable(
true);
68 m_displayControlNetButton->setEnabled(
false);
69 m_displayControlNetButton->setToolTip(
"Toggle the visibility of the "
70 "control points and movement arrows in the network.");
71 connect(m_displayControlNetButton, SIGNAL(clicked()),
this, SLOT(
displayControlNet()));
72 connect(m_displayControlNetButton, SIGNAL(destroyed(
QObject *)),
75 m_displayConnectivity =
new QPushButton(
"Color Islands");
76 m_displayConnectivity->setToolTip(
"Color cubes the same if the control "
77 "network has a connection between them");
79 connect(m_displayConnectivity, SIGNAL(destroyed(
QObject *)),
81 m_displayConnectivity->setEnabled(
false);
83 m_randomizeColors =
new QPushButton(
"Color Images");
84 m_randomizeColors->setToolTip(
"Color all cubes differently");
85 connect(m_randomizeColors, SIGNAL(clicked()),
this, SLOT(randomizeColors()));
86 connect(m_randomizeColors, SIGNAL(destroyed(
QObject *)),
89 m_configMovement =
new QPushButton(tr(
"Configure Movement Display"));
90 m_configMovement->setToolTip(tr(
"Show arrow from the apriori surface point to "
91 "the adjusted surface point for each control point with this "
93 connect(m_configMovement, SIGNAL(clicked()),
this, SLOT(
configMovement()));
94 connect(m_configMovement, SIGNAL(destroyed(
QObject *)),
100 if (getWidget() && !getWidget()->directory()) {
101 m_closeNetwork =
new QPushButton(
"Close Network");
102 m_closeNetwork->setEnabled(
false);
103 m_closeNetwork->setVisible(
false);
104 m_closeNetwork->setToolTip(
"Close the currently open control network");
105 connect(m_closeNetwork, SIGNAL(clicked()),
this, SLOT(
closeNetwork()));
106 connect(m_closeNetwork, SIGNAL(destroyed(
QObject *)),
109 m_loadControlNetButton =
new QPushButton(
"Open Network");
110 m_loadControlNetButton->setToolTip(
"Open and load a control network");
111 connect(m_loadControlNetButton, SIGNAL(clicked()),
113 connect(m_loadControlNetButton, SIGNAL(destroyed(
QObject *)),
116 connect(
this, SIGNAL(controlPointSelected(
ControlPoint *)),
117 getWidget(), SIGNAL(controlPointSelected(
ControlPoint *)));
120 m_controlNetFileLabel =
new QLabel;
121 m_controlNetFileLabel->setToolTip(
"The filename of the currently open "
123 connect(m_controlNetFileLabel, SIGNAL(destroyed(
QObject *)),
129 MosaicControlNetTool::~MosaicControlNetTool() {
130 m_controlNetGraphics = NULL;
132 delete m_loadControlNetButton;
133 delete m_displayControlNetButton;
134 delete m_displayConnectivity;
135 delete m_configMovement;
136 delete m_closeNetwork;
137 delete m_controlNetFileLabel;
138 delete m_randomizeColors;
144 Image *MosaicControlNetTool::takeImage(
145 QString sn, ImageList &images) {
146 if (m_controlNet && m_controlNetGraphics) {
147 QString filename = m_controlNetGraphics->snToFileName(sn);
149 for(
int i = 0; i < images.size(); i++) {
150 Image *image = images[i];
152 if (image->fileName() == filename) {
153 return images.takeAt(i);
162 PvlObject MosaicControlNetTool::toPvl()
const {
163 PvlObject obj(projectPvlObjectName());
165 obj += PvlKeyword(
"FileName", m_controlNetFile);
166 obj += PvlKeyword(
"Visible",
167 Isis::toString((
int)(m_controlNetGraphics && m_controlNetGraphics->isVisible())));
175 obj += PvlKeyword(
"MovementColorMaxResidualMagnitude",
183 void MosaicControlNetTool::fromPvl(
const PvlObject &obj) {
184 m_controlNetFile = obj[
"FileName"][0];
185 if (m_controlNetFile ==
"Null")
186 m_controlNetFile =
"";
188 if (obj.hasKeyword(
"Movement")) {
192 if (obj.hasKeyword(
"MovementColorMaxMeasureCount")) {
196 if (obj.hasKeyword(
"MovementColorMaxResidualMagnitude")) {
202 if (m_controlNetGraphics && m_displayControlNetButton) {
203 m_displayControlNetButton->setChecked(
toBool(obj[
"Visible"][0]) );
209 QString MosaicControlNetTool::projectPvlObjectName()
const {
210 return "MosaicControlNetTool";
227 int maxMeasureCount,
double maxResidualMagnitude) {
232 if (m_controlNetGraphics) {
266 double result =
Null;
283 result =
"No movement arrows";
287 result =
"Black movement arrows";
291 result =
"Movement arrows colored by measure count";
295 result =
"Movement arrows colored by residual magnitude";
329 action->setIcon(
getIcon(
"HILLBLU_molecola.png"));
330 action->setToolTip(
"Control Net (c)");
331 action->setShortcut(Qt::Key_C);
333 "<b>Function:</b> Display and analyze a control network<br><br>"
334 "This tool shows you all of the control points in your network for "
335 "which a latitude/longitude can be calculated. The control points are "
336 "shown as color-coded '+' marks. The control points have a right-click "
337 "menu and information about them can be seen just by hovering over them."
338 "<p><b>Shortcut:</b> c</p> ";
339 action->setWhatsThis(text);
346 QHBoxLayout *actionLayout =
new QHBoxLayout();
348 if (m_displayControlNetButton)
349 actionLayout->addWidget(m_displayControlNetButton);
351 if (m_displayConnectivity)
352 actionLayout->addWidget(m_displayConnectivity);
354 if (m_randomizeColors)
355 actionLayout->addWidget(m_randomizeColors);
357 if (m_configMovement)
358 actionLayout->addWidget(m_configMovement);
361 actionLayout->addWidget(m_closeNetwork);
363 if (m_loadControlNetButton)
364 actionLayout->addWidget(m_loadControlNetButton);
366 if (m_controlNetFileLabel)
367 actionLayout->addWidget(m_controlNetFileLabel);
369 actionLayout->setMargin(0);
372 toolBarWidget->setLayout(actionLayout);
374 return toolBarWidget;
384 configDialog->setAttribute(Qt::WA_DeleteOnClose);
385 configDialog->show();
394 getWidget()->setCubesSelectable(
true);
395 getWidget()->getView()->setContextMenuPolicy(Qt::NoContextMenu);
396 getWidget()->enableRubberBand(
false);
399 getWidget()->setCubesSelectable(
true);
400 getWidget()->getView()->setContextMenuPolicy(Qt::DefaultContextMenu);
401 getWidget()->enableRubberBand(
false);
403 if (
isActive() && m_controlNetFile ==
"") {
414 if (m_controlNetGraphics && m_displayControlNetButton)
415 m_controlNetGraphics->setVisible( m_displayControlNetButton->isChecked() );
425 ImageList images = getWidget()->images();
433 foreach(island, serialConns) {
437 foreach(cubeSn, island) {
438 Image *image = takeImage(cubeSn, images);
441 while(!color.isValid()) {
445 if (colorsUsed.indexOf(displayColor) == -1) {
446 colorsUsed.append(displayColor);
447 color = displayColor;
452 if (colorsUsed.indexOf(ranColor) == -1) {
453 colorsUsed.append(ranColor);
472 if (m_controlNetGraphics) {
478 void MosaicControlNetTool::displayChangedControlPoint(QString changedControlPoint) {
479 m_controlNetGraphics->clearControlPointGraphicsItem(changedControlPoint);
484 void MosaicControlNetTool::displayNewControlPoint(QString newControlPoint) {
493 void MosaicControlNetTool::displayUponControlPointDeletion() {
494 m_controlNetGraphics->clearControlPointGraphicsItem( QString(
"Point ID") );
504 if (m_controlNetGraphics) {
505 getWidget()->getScene()->removeItem(m_controlNetGraphics);
506 delete m_controlNetGraphics;
510 if (m_controlNet && !getWidget()->directory()) {
515 if (m_displayControlNetButton)
516 m_displayControlNetButton->setChecked(
false);
518 if (m_displayControlNetButton)
519 m_displayControlNetButton->setEnabled(
false);
521 if (m_displayConnectivity)
522 m_displayConnectivity->setEnabled(
false);
524 if (m_closeNetwork) {
525 m_closeNetwork->setEnabled(
false);
526 m_closeNetwork->setVisible(
false);
529 if (m_loadControlNetButton) {
530 m_loadControlNetButton->setEnabled(
true);
531 m_loadControlNetButton->setVisible(
true);
534 if (m_controlNetFileLabel)
535 m_controlNetFileLabel->setText(
"");
537 m_controlNetFile =
"";
545 if (obj == m_loadControlNetButton)
546 m_loadControlNetButton = NULL;
547 else if (obj == m_displayControlNetButton)
548 m_displayControlNetButton = NULL;
549 else if (obj == m_displayConnectivity)
550 m_displayConnectivity = NULL;
551 else if (obj == m_closeNetwork)
552 m_closeNetwork = NULL;
553 else if (obj == m_controlNetGraphics)
554 m_controlNetGraphics = NULL;
555 else if (obj == m_configMovement)
556 m_configMovement = NULL;
557 else if (obj == m_controlNetFileLabel)
558 m_controlNetFileLabel = NULL;
559 else if (obj == m_randomizeColors)
560 m_randomizeColors = NULL;
571 if (!getWidget()->directory()) {
573 QString netFile = FileDialog::getOpenFileName(getWidget(),
574 "Select Control Net. File",
575 QDir::current().dirName() +
"/",
576 "Control Networks (*.net);;All Files (*.*)");
582 if (!netFile.isEmpty()) {
584 m_controlNetFile = controlNetFile.
expanded();
589 if (!getWidget()->directory()->project()->activeControl()) {
591 QString message =
"No active control network chosen. Choose an active image list then an"
592 "active control network on the project tree.\n";
593 QMessageBox::critical(getWidget(),
"Error", message);
599 if (!m_controlNetFile.isEmpty()) {
601 if (m_displayControlNetButton) m_displayControlNetButton->setChecked(
true);
611 QString netFile = m_controlNetFile;
613 m_controlNetFile = netFile;
615 if (m_controlNetFile.size() > 0) {
618 if (!getWidget()->directory()) {
619 m_controlNetFileLabel->setText( QFileInfo(netFile).fileName() );
620 m_controlNet =
new ControlNet(m_controlNetFile);
626 m_controlNetFileLabel->setText( QFileInfo(
627 getWidget()->directory()->project()->activeControl()->fileName()).fileName() );
635 connect(m_controlNetGraphics, SIGNAL(destroyed(
QObject *)),
640 QString message =
"Invalid control network.\n";
642 QMessageBox::information(getWidget(),
"Error", message);
646 if (m_displayControlNetButton)
647 m_displayControlNetButton->setEnabled(
true);
649 if (m_displayConnectivity)
650 m_displayConnectivity->setEnabled(
true);
652 if (m_closeNetwork) {
653 m_closeNetwork->setEnabled(
true);
654 m_closeNetwork->setVisible(
true);
657 if (m_loadControlNetButton) {
658 m_loadControlNetButton->setEnabled(
false);
659 m_loadControlNetButton->setVisible(
false);
665 void MosaicControlNetTool::randomizeColors() {
666 foreach (
Image *image, getWidget()->images()) {
673 void MosaicControlNetTool::mouseButtonRelease(QPointF point, Qt::MouseButton mouseButton) {
674 if (!
isActive() || !m_controlNet)
return;
677 if (!getWidget()->directory())
return;
679 ControlPoint *cp = NULL;
682 if (mouseButton == Qt::LeftButton) {
692 emit modifyControlPoint(cp);
694 else if (mouseButton == Qt::MidButton) {
700 QString message =
"No points exist for deleting. Create points "
701 "using the right mouse button.";
702 QMessageBox::warning(getWidget(),
"Warning", message);
706 emit deleteControlPoint(cp);
711 else if (mouseButton == Qt::RightButton) {
716 ImageList imagesAtMousePosition;
718 foreach (
QGraphicsItem *graphicsItem, itemsAtMousePosition) {
719 MosaicSceneItem *sceneImageItem =
dynamic_cast<MosaicSceneItem *
>(graphicsItem);
721 if (!sceneImageItem) {
722 sceneImageItem =
dynamic_cast<MosaicSceneItem *
>(graphicsItem->parentItem());
725 if (sceneImageItem && sceneImageItem->image()) {
726 imagesAtMousePosition.append(sceneImageItem->image());
730 if (imagesAtMousePosition.count()) {
732 Projection *proj = getWidget()->getProjection();
736 TProjection *tproj = (TProjection *) proj;
737 if (tproj && getWidget()->getView()->sceneRect().contains(point)) {
738 if ( tproj->SetCoordinate( point.x(), -1 * point.y() ) ) {
743 emit createControlPoint(lat.degrees(), lon.degrees());