USGS

Isis 3.0 Object Programmers' Reference

Home

Footprint2DViewWorkOrder.cpp
Go to the documentation of this file.
1 
24 
25 #include <QtDebug>
26 
27 #include <QFileDialog>
28 #include <QInputDialog>
29 #include <QMessageBox>
30 
31 #include "Directory.h"
32 #include "MosaicSceneItem.h"
33 #include "MosaicSceneWidget.h"
34 #include "Project.h"
35 
36 namespace Isis {
37 
38  Footprint2DViewWorkOrder::Footprint2DViewWorkOrder(Project *project) :
39  WorkOrder(project) {
40  QAction::setText(tr("View &Footprints..."));
41  }
42 
43 
44  Footprint2DViewWorkOrder::Footprint2DViewWorkOrder(const Footprint2DViewWorkOrder &other) :
45  WorkOrder(other) {
46  }
47 
48 
49  Footprint2DViewWorkOrder::~Footprint2DViewWorkOrder() {
50  }
51 
52 
53  Footprint2DViewWorkOrder *Footprint2DViewWorkOrder::clone() const {
54 
55  return new Footprint2DViewWorkOrder(*this);
56 
57  }
58 
59 
61  bool result = false;
62 
63  foreach (Image *image, *images) {
64  result = result || image->isFootprintable();
65  }
66 
67  return result;
68  }
69 
70 
72  bool success = WorkOrder::execute();
73 
74  int maxRecommendedFootprints = 50000;
75  if (success && imageList()->count() > maxRecommendedFootprints) {
76  QMessageBox::StandardButton selectedOpt = QMessageBox::warning(NULL,
77  tr("Potentially Slow Operation"),
78  tr("You are asking to open %L1 images in a 2D footprint view at once. This is possible, "
79  "but will take a significant amount of time and cause overall slowness. Working with "
80  "more than %L2 footprints is not recommended. Are you sure you want to view these "
81  "%L1 footprints?").arg(imageList()->count()).arg(maxRecommendedFootprints),
82  QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
83 
84  if (selectedOpt == QMessageBox::No) {
85  success = false;
86  }
87  }
88 
89  if (success) {
90  QStringList viewOptions;
91 
92  QList<MosaicSceneWidget *> existingViews = project()->directory()->footprint2DViews();
93  int viewToUse = -1;
94 
95  if (existingViews.count()) {
96  for (int i = 0; i < existingViews.count(); i++) {
97  viewOptions.append(existingViews[i]->windowTitle());
98  }
99  }
100 
101  viewOptions.append(tr("New Footprint View"));
102 
103  if (viewOptions.count() > 1) {
104  QString selected = QInputDialog::getItem(NULL, tr("View to see footprints in"),
105  tr("Which view would you like your\nimage's footprints to be put into?"),
106  viewOptions, viewOptions.count() - 1, false, &success);
107 
108  viewToUse = viewOptions.indexOf(selected);
109  }
110  else {
111  viewToUse = viewOptions.count() - 1;
112  }
113 
114  bool newView = false;
115  if (viewToUse == viewOptions.count() - 1) {
116  newView = true;
117  if (!imageList()->name().isEmpty()) {
118  QUndoCommand::setText(tr("View image footprints of list [%1] in new 2D footprint view")
119  .arg(imageList()->name()));
120  }
121  else {
122  QUndoCommand::setText(tr("View [%1] image footprints in new footprint view")
123  .arg(imageList()->count()));
124  }
125  }
126  else if (viewToUse != -1) {
127  MosaicSceneWidget *footprintView = existingViews[viewToUse];
128 
129  // Remove extra images from the image list in order to make undo only undo the necessary
130  // ones... and not do extra work on redo.
131  ImageList list(*imageList());
132  QMutableListIterator<Image *> it(*imageList());
133 
134  while (it.hasNext()) {
135  Image *image = it.next();
136 
137  if (footprintView->cubeToMosaic(image)) {
138  it.remove();
139  }
140  }
141 
142  if (list.count() != imageList()->count()) {
143  setData(new ImageList(list));
144  }
145 
146  if (!imageList()->name().isEmpty()) {
147  QUndoCommand::setText(tr("View image footprints of list [%1] in footprint view [%2]")
148  .arg(imageList()->name()).arg(existingViews[viewToUse]->windowTitle()));
149  }
150  else {
151  QUndoCommand::setText(tr("View [%1] image footprints in footprint view [%2]")
152  .arg(imageList()->count()).arg(existingViews[viewToUse]->windowTitle()));
153  }
154  }
155 
156  QStringList internalData;
157  internalData.append(QString::number(viewToUse));
158  internalData.append(newView? "new view" : "existing view");
159  setInternalData(internalData);
160  }
161 
162  return success;
163  }
164 
165 
166  bool Footprint2DViewWorkOrder::dependsOn(WorkOrder *other) const {
167  // depend on types of ourselves.
168  return dynamic_cast<Footprint2DViewWorkOrder *>(other);
169  }
170 
171 
173  int viewToUse = internalData().first().toInt();
174 
175  MosaicSceneWidget *footprintViewToUse = NULL;
176  if (viewToUse == project()->directory()->footprint2DViews().count()) {
177  footprintViewToUse = project()->directory()->addFootprint2DView();
178  }
179  else {
180  footprintViewToUse = project()->directory()->footprint2DViews()[viewToUse];
181  }
182 
183  ImageList nonFootprintable = *imageList();
184  ImageList footprintable;
185 
186  QMutableListIterator<Image *> it(nonFootprintable);
187 
188  while (it.hasNext()) {
189  Image *unknownFootprintability = it.next();
190 
191  if (unknownFootprintability->isFootprintable()) {
192  footprintable.append(unknownFootprintability);
193  it.remove();
194  }
195  }
196 
197  footprintViewToUse->addImages(footprintable);
198 
199  foreach (Image *nonFootprintableImage, nonFootprintable) {
200  project()->warn(tr("Image [%1] does not have and cannot create an associated footprint")
201  .arg(nonFootprintableImage->displayProperties()->displayName()));
202 
203  }
204  }
205 
206 
208  int viewToUse = internalData().first().toInt();
209 
210  if (internalData()[1] == "new view") {
211  delete project()->directory()->footprint2DViews().last();
212  }
213  else {
214  MosaicSceneWidget *footprintView = project()->directory()->footprint2DViews()[viewToUse];
215 
216  QListIterator<Image *> it(*imageList());
217  while (it.hasNext()) {
218  Image *imageToRemoveFromView = it.next();
219  delete footprintView->cubeToMosaic(imageToRemoveFromView);
220  }
221  }
222  }
223 }
224