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 }
Isis::ExportControlNetWorkOrder::isExecutable
bool isExecutable(ControlList *controls)
Determines if we can export a control net.
Definition: ExportControlNetWorkOrder.cpp:100
Isis::ExportControlNetWorkOrder::postExecution
virtual void postExecution()
Display any warnings that occurred during the asynchronous computations.
Definition: ExportControlNetWorkOrder.cpp:214
Isis::WorkOrder::setupExecution
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1261
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::WorkOrder
Provide Undo/redo abilities, serialization, and history for an operation.
Definition: WorkOrder.h:311
Project.h
Isis::ExportControlNetWorkOrder::m_warning
QString m_warning
Stores any errors that may have occurred during export.
Definition: ExportControlNetWorkOrder.h:56
Isis::FileName::name
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:162
Isis::WorkOrder::controlList
QPointer< ControlList > controlList()
Returns the Control List for this WorkOrder (a list of control networks).
Definition: WorkOrder.cpp:706
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::Project::control
Control * control(QString id)
Accessor for if the project is clearing or not.
Definition: Project.cpp:1163
Isis::ControlList
Maintains a list of Controls so that control nets can easily be copied from one Project to another,...
Definition: ControlList.h:44
Isis::WorkOrder::setInternalData
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1318
Isis::ExportControlNetWorkOrder::execute
virtual void execute()
Executes the work order.
Definition: ExportControlNetWorkOrder.cpp:185
Isis::Control
This represents an ISIS control net in a project-based GUI interface.
Definition: Control.h:66
Isis::WorkOrder::m_isSynchronous
bool m_isSynchronous
This is defaulted to true.
Definition: WorkOrder.h:530
QStringList
Isis::ExportControlNetWorkOrder
Write a project control network to a user-specified location.
Definition: ExportControlNetWorkOrder.h:36
Isis::Project
The main project for ipce.
Definition: Project.h:289
Isis::ExportControlNetWorkOrder::ExportControlNetWorkOrder
ExportControlNetWorkOrder(Project *project)
Creates a work order for exporting a control network from the project.
Definition: ExportControlNetWorkOrder.cpp:46
Isis::ExportControlNetWorkOrder::~ExportControlNetWorkOrder
~ExportControlNetWorkOrder()
Destructor.
Definition: ExportControlNetWorkOrder.cpp:72
Isis::WorkOrder::m_isUndoable
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
Definition: WorkOrder.h:523
Isis::WorkOrder::setData
virtual void setData(Context)
Sets the context data for this WorkOrder.
Definition: WorkOrder.cpp:248
Isis::ExportControlNetWorkOrder::clone
virtual ExportControlNetWorkOrder * clone() const
Clones this work order.
Definition: ExportControlNetWorkOrder.cpp:84
Isis::DisplayProperties::displayName
QString displayName() const
Returns the display name.
Definition: DisplayProperties.cpp:88
Isis::WorkOrder::project
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1300
Isis::Project::controls
QList< ControlList * > controls()
Return controls in project.
Definition: Project.cpp:2038
Isis::ExportControlNetWorkOrder::setupExecution
virtual bool setupExecution()
Prepares for exporting a control net by soliciting information from the user.
Definition: ExportControlNetWorkOrder.cpp:119
Isis::ControlList::name
QString name() const
Get the human-readable name of this control list.
Definition: ControlList.cpp:539
Isis::WorkOrder::internalData
QStringList internalData() const
Gets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1377
QMap
This is free and unencumbered software released into the public domain.
Definition: CubeIoHandler.h:22
Isis::Control::displayProperties
ControlDisplayProperties * displayProperties()
Access a pointer to the display properties for the control network.
Definition: Control.cpp:252
Isis::Control::id
QString id() const
Access the unique ID associated with this Control.
Definition: Control.cpp:282
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::Control::fileName
QString fileName() const
Access the name of the control network file associated with this Control.
Definition: Control.cpp:272