26 #include <QFileDialog>
28 #include <QMessageBox>
29 #include <QtConcurrentMap>
32 #include "ControlList.h"
40 ImportControlNetWorkOrder::ImportControlNetWorkOrder(Project *project) :
44 QAction::setText(tr(
"Import &Control Networks..."));
45 QUndoCommand::setText(tr(
"Import Control Networks"));
50 connect(m_watcher, SIGNAL(resultReadyAt(
int)),
this, SLOT(cnetReady(
int)));
54 ImportControlNetWorkOrder::ImportControlNetWorkOrder(
const ImportControlNetWorkOrder &other) :
59 connect(m_watcher, SIGNAL(resultReadyAt(
int)),
this, SLOT(cnetReady(
int)));
64 ImportControlNetWorkOrder::~ImportControlNetWorkOrder() {
70 ImportControlNetWorkOrder *ImportControlNetWorkOrder::clone()
const {
71 return new ImportControlNetWorkOrder(*
this);
78 QStringList cnetFileNames = QFileDialog::getOpenFileNames(
79 qobject_cast<QWidget *>(parent()),
80 tr(
"Import Control Networks"),
"",
81 tr(
"Isis control nets (*.net);;All Files (*)"));
83 if (!cnetFileNames.isEmpty()) {
84 QUndoCommand::setText(tr(
"Import %1 Control Networks").arg(cnetFileNames.count()));
100 foreach (
FileName fileName, cnetFileNames) {
102 cnetFileNamesAndProgress.append(qMakePair(fileName, readProgress));
104 m_readProgresses.append(readProgress);
107 m_watcher->setFuture(QtConcurrent::mapped(cnetFileNamesAndProgress,
113 while (!m_watcher->isFinished()) {
115 int totalProgress = 0;
117 for (
int i = 0; i < m_readProgresses.count(); i++) {
118 Progress *progress = m_readProgresses[i];
120 if (m_watcher->future().isResultReadyAt(i)) {
121 totalProgress += 100;
126 totalProgress += qRound(progressPercent * 90);
132 QThread::yieldCurrentThread();
139 foreach (
Progress *progress, m_readProgresses) {
142 m_readProgresses.clear();
147 if (m_watcher->isFinished()) {
150 foreach (
Control *control, *list) {
159 ImportControlNetWorkOrder::CreateControlsFunctor::CreateControlsFunctor(
160 Project *project, QDir destinationFolder) {
162 m_destinationFolder = destinationFolder;
166 Control *ImportControlNetWorkOrder::CreateControlsFunctor::operator()(
169 QString cnetFileName = cnetFileNameAndProgress.first.original();
170 ControlNet *cnet =
new ControlNet();
172 cnet->ReadControl(cnetFileName, cnetFileNameAndProgress.second);
174 QString baseFilename = FileName(cnetFileName).name();
175 QString destination = m_destinationFolder.canonicalPath() +
"/" + baseFilename;
177 cnet->Write(destination);
179 Control *control =
new Control(cnet, destination);
184 void ImportControlNetWorkOrder::cnetReady(
int ready) {
186 Control *control = m_watcher->resultAt(ready);
This represents an ISIS control net in a project-based GUI interface.
void syncUndo()
This method is designed to be implemented by children work orders.
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
The main project for cnetsuite.
File name manipulation and expansion.
void DisableAutomaticDisplay()
Turns off updating the Isis Gui when CheckStatus() is called.
Maintains a list of Controls so that control nets can easily be copied from one Project to another...
Project * project() const
Returns the Project this WorkOrder is attached to.
void addControl(Control *control)
Add the given Control's to the current project.
void postSyncRedo()
This method is designed to be implemented by children work orders.
QStringList internalData() const
Gets the internal data for this WorkOrder.
int CurrentStep() const
Returns the current step of the progress.
int MaximumSteps() const
Returns the maximum number of steps of the progress.
void asyncRedo()
This method is designed to be implemented by children work orders.
Program progress reporter.
bool execute()
The (child) implementation of this method should prompt the user/gather state by any means necessary...
void syncRedo()
This method is designed to be implemented by children work orders.
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
void setModifiesDiskState(bool changesProjectOnDisk)
.
virtual bool execute()
The (child) implementation of this method should prompt the user/gather state by any means necessary...
void deleteFromDisk(Project *project)
Delete all of the contained Controls from disk.
QDir addCnetFolder(QString prefix)
Create and return the name of a folder for placing control networks.
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
QPointer< Project > m_project
A pointer to the Project this WorkOrder is attached to.