Isis 3 Programmer Reference
ExportControlNetWorkOrder.cpp
Go to the documentation of this file.
1 
23 #include "ExportControlNetWorkOrder.h"
24 
25 #include <QDebug>
26 #include <QFileDialog>
27 #include <QInputDialog>
28 
29 #include "Control.h"
30 #include "ControlList.h"
31 #include "ControlNet.h"
32 #include "FileName.h"
33 #include "IException.h"
34 #include "IString.h"
35 #include "Project.h"
36 
37 namespace Isis {
38 
47  WorkOrder(project) {
48  m_isSynchronous = false;
49  m_isUndoable = false;
50  QAction::setText(tr("&Export Control Network..."));
51  QUndoCommand::setText(tr("Export Control Network..."));
52  }
53 
54 
63  WorkOrder(other) {
64  }
65 
66 
73 
74  }
75 
76 
85  return new ExportControlNetWorkOrder(*this);
86  }
87 
88 
101 
102  if (controls) {
103  return (controls->count() == 1);
104  }
105  return false;
106  }
107 
108 
120  bool success = WorkOrder::setupExecution();
121 
122  if (success) {
124 
125  Control *control = NULL;
126 
127  // See if there are any other control lists in the project and give these to the user as
128  // choices for control nets they can export.
129  if (project()) {
130 
131  Project *proj = project();
132 
133  QList<ControlList *> controls = proj->controls();
134  if (controls.count() > 0) {
135  ControlList *l = controls.first();
137  control = controlList()->first();
138  }
139  else {
140 
141  QMap<Control *, QString> cnetChoices;
142  foreach (ControlList *list, project()->controls()) {
143  foreach (Control *control, *list) {
144  cnetChoices[control] = tr("%1/%2").arg(list->name())
145  .arg(control->displayProperties()->displayName());
146  }
147  }
148 
149  QStringList cnetNames = cnetChoices.values();
150  qSort(cnetNames);
151 
152  QString choice = QInputDialog::getItem(NULL, tr("Select Control"),
153  tr("Please choose a control to export."), cnetNames, 0, false, &success);
154 
155  control = cnetChoices.key(choice);
156  internalData.append(control->id());
157  }
158  }
159 
160 
161  QString destination =
162  QFileDialog::getSaveFileName(NULL, QString("Export Control Network"),
163  "./" + FileName(control->fileName()).name());
164 
165  if (destination.isEmpty()) {
166  success = false;
167  }
168  internalData.append(destination);
169 
171  }
172 
173  return success;
174  }
175 
176 
186  QString destination;
187  Control *control = NULL;
188 
189  if (controlList()->isEmpty()) {
190  destination = internalData()[1];
191 
192  QString controlId = internalData()[0];
193  control = project()->control(controlId);
194  }
195  else {
196  destination = internalData()[0];
197  control = controlList()->first();
198  }
199 
200  QString currentLocation = control->fileName();
201  if (!QFile::copy(currentLocation, destination) ) {
202  m_warning = "Error saving control net.";
203  }
204  }
205 
206 
215  if (!m_warning.isEmpty()) {
216  project()->warn(m_warning);
217  m_warning.clear();
218  }
219  }
220 }
This represents an ISIS control net in a project-based GUI interface.
Definition: Control.h:79
bool isExecutable(ControlList *controls)
Determines if we can export a control net.
The main project for ipce.
Definition: Project.h:289
File name manipulation and expansion.
Definition: FileName.h:116
Write a project control network to a user-specified location.
Control * control(QString id)
Accessor for if the project is clearing or not.
Definition: Project.cpp:1163
Maintains a list of Controls so that control nets can easily be copied from one Project to another...
Definition: ControlList.h:36
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1275
QString displayName() const
Returns the display name.
virtual bool setupExecution()
Prepares for exporting a control net by soliciting information from the user.
virtual void postExecution()
Display any warnings that occurred during the asynchronous computations.
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:322
bool m_isSynchronous
This is defaulted to true.
Definition: WorkOrder.h:541
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
Definition: WorkOrder.h:534
virtual void setData(Context)
Sets the context data for this WorkOrder.
Definition: WorkOrder.cpp:262
QList< ControlList * > controls()
Return controls in project.
Definition: Project.cpp:2038
virtual ExportControlNetWorkOrder * clone() const
Clones this work order.
ControlDisplayProperties * displayProperties()
Access a pointer to the display properties for the control network.
Definition: Control.cpp:244
ExportControlNetWorkOrder(Project *project)
Creates a work order for exporting a control network from the project.
QString name() const
Get the human-readable name of this control list.
virtual void execute()
Executes the work order.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QString m_warning
Stores any errors that may have occurred during export.
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1314
QString id() const
Access the unique ID associated with this Control.
Definition: Control.cpp:274
QPointer< ControlList > controlList()
Returns the Control List for this WorkOrder (a list of control networks).
Definition: WorkOrder.cpp:720
QString fileName() const
Access the name of the control network file associated with this Control.
Definition: Control.cpp:264
QStringList internalData() const
Gets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1391
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1332