1 #include "MosaicControlNetTool.h"
8 #include "ControlList.h"
10 #include "ControlNetGraphicsItem.h"
12 #include "FileDialog.h"
17 #include "ImageList.h"
19 #include "MosaicControlNetToolMovementConfigDialog.h"
20 #include "MosaicSceneWidget.h"
35 m_controlNetGraphics = NULL;
36 m_loadControlNetButton = NULL;
37 m_displayControlNetButton = NULL;
38 m_displayConnectivity = NULL;
39 m_closeNetwork = NULL;
40 m_controlNetFileLabel = NULL;
41 m_randomizeColors = NULL;
49 m_displayControlNetButton =
new QPushButton(
"Display");
50 m_displayControlNetButton->setCheckable(
true);
51 m_displayControlNetButton->setEnabled(
false);
52 m_displayControlNetButton->setToolTip(
"Toggle the visibility of the "
53 "control points and movement arrows in the network.");
54 connect(m_displayControlNetButton, SIGNAL(clicked()),
this, SLOT(
displayControlNet()));
55 connect(m_displayControlNetButton, SIGNAL(destroyed(
QObject *)),
58 m_displayConnectivity =
new QPushButton(
"Color Islands");
59 m_displayConnectivity->setToolTip(
"Color cubes the same if the control "
60 "network has a connection between them");
62 connect(m_displayConnectivity, SIGNAL(destroyed(
QObject *)),
64 m_displayConnectivity->setEnabled(
false);
66 m_randomizeColors =
new QPushButton(
"Color Images");
67 m_randomizeColors->setToolTip(
"Color all cubes differently");
68 connect(m_randomizeColors, SIGNAL(clicked()),
this, SLOT(randomizeColors()));
69 connect(m_randomizeColors, SIGNAL(destroyed(
QObject *)),
72 m_configMovement =
new QPushButton(tr(
"Configure Movement Display"));
73 m_configMovement->setToolTip(tr(
"Show arrow from the apriori surface point to "
74 "the adjusted surface point for each control point with this "
76 connect(m_configMovement, SIGNAL(clicked()),
this, SLOT(
configMovement()));
77 connect(m_configMovement, SIGNAL(destroyed(
QObject *)),
80 m_closeNetwork =
new QPushButton(
"Close Network");
81 m_closeNetwork->setEnabled(
false);
82 m_closeNetwork->setVisible(
false);
83 m_closeNetwork->setToolTip(
"Close the currently open control network");
84 connect(m_closeNetwork, SIGNAL(clicked()),
this, SLOT(
closeNetwork()));
85 connect(m_closeNetwork, SIGNAL(destroyed(
QObject *)),
88 m_loadControlNetButton =
new QPushButton(
"Open Network");
89 m_loadControlNetButton->setToolTip(
"Open and load a control network");
90 connect(m_loadControlNetButton, SIGNAL(clicked()),
92 connect(m_loadControlNetButton, SIGNAL(destroyed(
QObject *)),
95 m_controlNetFileLabel =
new QLabel;
96 m_controlNetFileLabel->setToolTip(
"The filename of the currently open "
98 connect(m_controlNetFileLabel, SIGNAL(destroyed(
QObject *)),
103 MosaicControlNetTool::~MosaicControlNetTool() {
104 m_controlNetGraphics = NULL;
106 delete m_loadControlNetButton;
107 delete m_displayControlNetButton;
108 delete m_displayConnectivity;
109 delete m_configMovement;
110 delete m_closeNetwork;
111 delete m_controlNetFileLabel;
112 delete m_randomizeColors;
118 Image *MosaicControlNetTool::takeImage(
119 QString sn, ImageList &images) {
120 if (m_controlNet && m_controlNetGraphics) {
121 QString filename = m_controlNetGraphics->snToFileName(sn);
123 for(
int i = 0; i < images.size(); i++) {
124 Image *image = images[i];
126 if (image->fileName() == filename) {
127 return images.takeAt(i);
136 PvlObject MosaicControlNetTool::toPvl()
const {
137 PvlObject obj(projectPvlObjectName());
139 obj += PvlKeyword(
"FileName", m_controlNetFile);
140 obj += PvlKeyword(
"Visible",
141 Isis::toString((
int)(m_controlNetGraphics && m_controlNetGraphics->isVisible())));
149 obj += PvlKeyword(
"MovementColorMaxResidualMagnitude",
157 void MosaicControlNetTool::fromPvl(
const PvlObject &obj) {
158 m_controlNetFile = obj[
"FileName"][0];
159 if (m_controlNetFile ==
"Null")
160 m_controlNetFile =
"";
162 if (obj.hasKeyword(
"Movement")) {
166 if (obj.hasKeyword(
"MovementColorMaxMeasureCount")) {
170 if (obj.hasKeyword(
"MovementColorMaxResidualMagnitude")) {
176 if (m_controlNetGraphics && m_displayControlNetButton) {
177 m_displayControlNetButton->setChecked(
toBool(obj[
"Visible"][0]) );
183 QString MosaicControlNetTool::projectPvlObjectName()
const {
184 return "MosaicControlNetTool";
201 int maxMeasureCount,
double maxResidualMagnitude) {
206 if (m_controlNetGraphics) {
240 double result =
Null;
257 result =
"No movement arrows";
261 result =
"Black movement arrows";
265 result =
"Movement arrows colored by measure count";
269 result =
"Movement arrows colored by residual magnitude";
303 action->setIcon(
getIcon(
"HILLBLU_molecola.png"));
304 action->setToolTip(
"Control Net (c)");
305 action->setShortcut(Qt::Key_C);
307 "<b>Function:</b> Display and analyze a control network<br><br>"
308 "This tool shows you all of the control points in your network for "
309 "which a latitude/longitude can be calculated. The control points are "
310 "shown as color-coded '+' marks. The control points have a right-click "
311 "menu and information about them can be seen just by hovering over them."
312 "<p><b>Shortcut:</b> c</p> ";
313 action->setWhatsThis(text);
320 QHBoxLayout *actionLayout =
new QHBoxLayout();
322 if (m_displayControlNetButton)
323 actionLayout->addWidget(m_displayControlNetButton);
325 if (m_displayConnectivity)
326 actionLayout->addWidget(m_displayConnectivity);
328 if (m_randomizeColors)
329 actionLayout->addWidget(m_randomizeColors);
331 if (m_configMovement)
332 actionLayout->addWidget(m_configMovement);
335 actionLayout->addWidget(m_closeNetwork);
337 if (m_loadControlNetButton)
338 actionLayout->addWidget(m_loadControlNetButton);
340 if (m_controlNetFileLabel)
341 actionLayout->addWidget(m_controlNetFileLabel);
343 actionLayout->setMargin(0);
346 toolBarWidget->setLayout(actionLayout);
348 return toolBarWidget;
358 configDialog->setAttribute(Qt::WA_DeleteOnClose);
359 configDialog->show();
367 if (
isActive() && m_controlNetFile ==
"") {
379 ImageList images = getWidget()->images();
387 foreach(island, serialConns) {
391 foreach(cubeSn, island) {
392 Image *image = takeImage(cubeSn, images);
395 while(!color.isValid()) {
399 if (colorsUsed.indexOf(displayColor) == -1) {
400 colorsUsed.append(displayColor);
401 color = displayColor;
406 if (colorsUsed.indexOf(ranColor) == -1) {
407 colorsUsed.append(ranColor);
426 if (m_controlNetGraphics) {
427 getWidget()->getScene()->removeItem(m_controlNetGraphics);
429 delete m_controlNetGraphics;
437 if (m_displayControlNetButton)
438 m_displayControlNetButton->setChecked(
false);
440 if (m_displayControlNetButton)
441 m_displayControlNetButton->setEnabled(
false);
443 if (m_displayConnectivity)
444 m_displayConnectivity->setEnabled(
false);
446 if (m_closeNetwork) {
447 m_closeNetwork->setEnabled(
false);
448 m_closeNetwork->setVisible(
false);
451 if (m_loadControlNetButton) {
452 m_loadControlNetButton->setEnabled(
true);
453 m_loadControlNetButton->setVisible(
true);
456 if (m_controlNetFileLabel)
457 m_controlNetFileLabel->setText(
"");
459 m_controlNetFile =
"";
467 if (obj == m_loadControlNetButton)
468 m_loadControlNetButton = NULL;
469 else if (obj == m_displayControlNetButton)
470 m_displayControlNetButton = NULL;
471 else if (obj == m_displayConnectivity)
472 m_displayConnectivity = NULL;
473 else if (obj == m_closeNetwork)
474 m_closeNetwork = NULL;
475 else if (obj == m_controlNetGraphics)
476 m_controlNetGraphics = NULL;
477 else if (obj == m_configMovement)
478 m_configMovement = NULL;
479 else if (obj == m_controlNetFileLabel)
480 m_controlNetFileLabel = NULL;
481 else if (obj == m_randomizeColors)
482 m_randomizeColors = NULL;
491 if (!getWidget()->directory()) {
493 QString netFile = FileDialog::getOpenFileName(getWidget(),
494 "Select Control Net. File",
495 QDir::current().dirName() +
"/",
496 "Control Networks (*.net);;All Files (*.*)");
502 if (!netFile.isEmpty()) {
504 m_controlNetFile = controlNetFile.expanded();
507 if (m_displayControlNetButton)
508 m_displayControlNetButton->setChecked(
true);
514 if (controls.count() > 0) {
517 foreach (
Control *control, *list) {
518 cnetChoices[control] = tr(
"%1/%2").arg(list->
name())
526 QString selected = QInputDialog::getItem(NULL, tr(
"Select control network"),
527 tr(
"Select control network"), cnetNames, 0,
false,
529 if (ok && !selected.isEmpty()) {
530 m_controlNetFile = cnetChoices.key(selected)->fileName();
532 if (m_displayControlNetButton)
533 m_displayControlNetButton->setChecked(
true);
536 else if (controls.count() == 1 && controls.at(0)->count() == 1) {
537 m_controlNetFile = controls.first()->first()->fileName();
539 if (m_displayControlNetButton)
540 m_displayControlNetButton->setChecked(
true);
551 QString netFile = m_controlNetFile;
553 m_controlNetFile = netFile;
554 m_controlNetFileLabel->setText( QFileInfo(netFile).fileName() );
556 if (m_controlNetFile.size() > 0) {
566 connect(m_controlNetGraphics, SIGNAL(destroyed(
QObject *)),
570 QString message =
"Invalid control network.\n";
572 QMessageBox::information(getWidget(),
"Error", message);
576 if (m_displayControlNetButton)
577 m_displayControlNetButton->setEnabled(
true);
579 if (m_displayConnectivity)
580 m_displayConnectivity->setEnabled(
true);
582 if (m_closeNetwork) {
583 m_closeNetwork->setEnabled(
true);
584 m_closeNetwork->setVisible(
true);
587 if (m_loadControlNetButton) {
588 m_loadControlNetButton->setEnabled(
false);
589 m_loadControlNetButton->setVisible(
false);
595 void MosaicControlNetTool::randomizeColors() {
596 foreach (
Image *image, getWidget()->images()) {
607 if (m_controlNetGraphics && m_displayControlNetButton)
608 m_controlNetGraphics->setVisible(m_displayControlNetButton->isChecked());
612 void MosaicControlNetTool::mouseButtonRelease(QPointF point, Qt::MouseButton s) {
613 if (!
isActive() || !m_controlNet)
return;