12#include <QFutureWatcher>
14#include <QMutexLocker>
15#include <QtConcurrentRun>
17#include <QXmlStreamWriter>
19#include "ControlList.h"
20#include "IException.h"
23#include "ProgressBar.h"
25#include "ProjectItem.h"
28#include "XmlStackedHandlerReader.h"
42 m_context = NoContext;
59 m_status = WorkOrderNotStarted;
60 m_queuedAction = NoQueuedAction;
75 tr(
"Work orders cannot be created without a project."), _FILEINFO_);
78 connect(
this, SIGNAL(triggered()),
92 QAction(other.icon(), ((
QAction &)other).text(), other.parentWidget()),
95 QAction::setWhatsThis(other.whatsThis());
96 QAction::setToolTip(other.toolTip());
101 m_context = other.m_context;
103 m_imageList =
new ImageList(*other.m_imageList);
105 m_shapeList =
new ShapeList(*other.m_shapeList);
106 m_correlationMatrix = other.m_correlationMatrix;
107 m_controlList = other.m_controlList;
123 m_status = other.m_status;
124 m_queuedAction = other.m_queuedAction;
135 if (!other.isInStableState()) {
137 tr(
"Can not copy work order [%1] because it is currently running")
142 connect(
this, SIGNAL(triggered()),
296 m_controlList = controls;
392 else if ( item->isTemplate() ) {
507 else if ( item->isTemplate() ) {
519 xmlReader->pushContentHandler(
new XmlHandler(
this));
545 tr(
"Can not store an unstable work order. The work order [%1] is currently "
550 stream.writeStartElement(
"workOrder");
552 stream.writeAttribute(
"actionText", QAction::text());
553 stream.writeAttribute(
"undoText", QUndoCommand::text());
555 stream.writeAttribute(
"type", metaObject()->className());
556 stream.writeAttribute(
"status",
toString(m_status));
559 stream.writeStartElement(
"images");
562 stream.writeStartElement(
"image");
563 stream.writeAttribute(
"id", imageId);
564 stream.writeEndElement();
567 stream.writeEndElement();
571 stream.writeStartElement(
"shapes");
574 stream.writeStartElement(
"shape");
575 stream.writeAttribute(
"id", shapeId);
576 stream.writeEndElement();
579 stream.writeEndElement();
583 stream.writeStartElement(
"internalDataValues");
586 stream.writeStartElement(
"dataValue");
587 stream.writeAttribute(
"value", str);
588 stream.writeEndElement();
591 stream.writeEndElement();
594 if (m_context != NoContext) {
595 stream.writeStartElement(
"context");
597 QString contextStr =
"ProjectContext";
598 stream.writeAttribute(
"value", contextStr);
600 stream.writeEndElement();
603 stream.writeEndElement();
630 QMutexLocker locker(
project()->workOrderMutex());
632 bool anyImagesAreNull =
false;
638 m_imageList->append(image);
641 anyImagesAreNull =
true;
645 if (anyImagesAreNull) {
662 QMutexLocker locker(
project()->workOrderMutex());
664 bool anyShapesAreNull =
false;
670 m_shapeList->append(shape);
673 anyShapesAreNull =
true;
677 if (anyShapesAreNull) {
695 QMutexLocker locker(
project()->workOrderMutex());
696 return m_correlationMatrix;
705 QMutexLocker locker(
project()->workOrderMutex());
706 return m_controlList;
735 QMutexLocker locker(
project()->workOrderMutex());
745 QMutexLocker locker(
project()->workOrderMutex());
755 QMutexLocker locker(
project()->workOrderMutex());
765 QMutexLocker locker(
project()->workOrderMutex());
794 QString result = QUndoCommand::text().remove(
"&").remove(
"...");
797 if (result.isEmpty()) {
799 result = QString(metaObject()->className()).remove(
"Isis::").remove(
"WorkOrder")
800 .replace(QRegExp(
"([a-z0-9])([A-Z])"),
"\\1 \\2");
801 qWarning() << QString(
"WorkOrder::bestText(): Work order [%1] has no QUndoCommand text")
818 QMutexLocker locker(
project()->workOrderMutex());
829 QMutexLocker locker(
project()->workOrderMutex());
840 QMutexLocker locker(
project()->workOrderMutex());
853 QMutexLocker locker(
project()->workOrderMutex());
863 QMutexLocker locker(
project()->workOrderMutex());
882 QMutexLocker locker(
project()->workOrderMutex());
883 return m_status == WorkOrderRedoing;
892 QMutexLocker locker(
project()->workOrderMutex());
893 return m_status == WorkOrderRedone;
902 QMutexLocker locker(
project()->workOrderMutex());
903 return m_status == WorkOrderUndoing;
912 QMutexLocker locker(
project()->workOrderMutex());
913 return m_status == WorkOrderUndone;
923 QMutexLocker locker(
project()->workOrderMutex());
933 QMutexLocker locker(
project()->workOrderMutex());
943 QMutexLocker locker(
project()->workOrderMutex());
953 QMutexLocker locker(
project()->workOrderMutex());
954 QString result =
toString(m_status);
962 result += tr(
" (elapsed: %1:%2)").arg(minutes).arg(seconds, 2, 10, QChar(
'0'));
974 QMutexLocker locker(
project()->workOrderMutex());
987 statusString = statusString.toUpper();
991 possibleResult <= WorkOrderLastStatus;
993 if (statusString ==
toString(possibleResult).toUpper()) {
994 result = possibleResult;
1011 case WorkOrderUnknownStatus:
1012 result = tr(
"Unknown");
1014 case WorkOrderNotStarted:
1015 result = tr(
"Not Started");
1017 case WorkOrderRedoing:
1018 result = tr(
"In Progress");
1020 case WorkOrderRedone:
1021 result = tr(
"Completed");
1023 case WorkOrderUndoing:
1024 result = tr(
"Undoing");
1026 case WorkOrderUndone:
1027 result = tr(
"Undone");
1030 result = tr(
"Finished");
1043 m_queuedAction = RedoQueuedAction;
1047 bool mustQueueThisRedo =
false;
1051 while (current->previous() && !dependency) {
1052 if (!current->previous()->isRedone() && !current->previous()->isFinished()) {
1056 connect(possibleDependency, SIGNAL(finished(
WorkOrder *)),
1058 dependency = possibleDependency;
1059 mustQueueThisRedo =
true;
1063 current = current->previous();
1069 mustQueueThisRedo =
true;
1075 mustQueueThisRedo =
true;
1080 m_queuedAction = RedoQueuedAction;
1082 QString queueStatusText;
1085 QString dependencyText = dependency->bestText();
1087 if (dependencyText.count() > 5) {
1088 dependencyText = dependencyText.mid(0, 5) +
"...";
1091 queueStatusText = tr(
"Wait for [%1]").arg(dependencyText);
1094 queueStatusText = tr(
"Wait for images");
1097 queueStatusText = tr(
"Wait for shapes");
1106 if (m_queuedAction == NoQueuedAction) {
1107 m_status = WorkOrderRedoing;
1108 emit statusChanged(
this);
1146 m_queuedAction = UndoQueuedAction;
1149 if (!
isUndone() && m_status != WorkOrderNotStarted) {
1152 while (current->next() && !dependency) {
1153 if (!current->next()->isUndone() && !current->next()->isFinished() &&
1154 current->next()->m_status != WorkOrderNotStarted) {
1155 connect(current->next(), SIGNAL(finished(
WorkOrder *)),
1157 m_queuedAction = UndoQueuedAction;
1158 dependency = current->next();
1161 current = current->next();
1165 QString prevText = dependency->bestText();
1167 if (prevText.count() > 5) {
1168 prevText = prevText.mid(0, 5) +
"...";
1173 m_progressBar->setText(tr(
"Undo after [%1]").arg(prevText));
1177 if (m_queuedAction == NoQueuedAction) {
1178 m_status = WorkOrderUndoing;
1179 emit statusChanged(
this);
1265 emit statusChanged(
this);
1301 "This work order no longer has a project.", _FILEINFO_);
1326 QMutexLocker locker(
project()->workOrderMutex());
1336 QMutexLocker locker(
project()->workOrderMutex());
1346 QMutexLocker locker(
project()->workOrderMutex());
1376 QMutexLocker locker(
project()->workOrderMutex());
1479 foreach (
Image *image, *m_imageList) {
1485 connect(image, SIGNAL(destroyed(
QObject *)),
1502 foreach (
Shape *shape, *m_shapeList) {
1508 connect(shape, SIGNAL(destroyed(
QObject *)),
1523 emit creatingProgress(
this);
1547 else if (
isUndone() || m_status == WorkOrderNotStarted) {
1575 m_queuedAction = NoQueuedAction;
1577 if (queued == RedoQueuedAction && m_status != WorkOrderRedone) {
1580 else if (queued == UndoQueuedAction && m_status != WorkOrderUndone) {
1597 finishedStatus = WorkOrderUndone;
1601 (this->*postMethod)();
1603 m_status = finishedStatus;
1610 emit statusChanged(
this);
1612 emit finished(
this);
1701 const QString &qName,
const QXmlAttributes &atts) {
1702 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
1703 if (localName ==
"workOrder") {
1704 QString actionText = atts.value(
"actionText");
1705 QString undoText = atts.value(
"undoText");
1707 QString statusStr = atts.value(
"status");
1709 if (!actionText.isEmpty()) {
1710 ((
QAction *)m_workOrder)->setText(actionText);
1713 if (!undoText.isEmpty()) {
1718 m_workOrder->m_executionTime = QDateTime::fromString(
executionTime);
1721 if (!statusStr.isEmpty()) {
1725 if (m_workOrder->createsCleanState()) {
1729 m_workOrder->m_status = WorkOrderRedone;
1733 else if (localName ==
"dataValue") {
1734 m_workOrder->m_internalData.append(atts.value(
"value"));
1736 else if (localName ==
"context") {
1737 if (atts.value(
"value") ==
"ProjectContext") {
1738 m_workOrder->m_context = ProjectContext;
Maintains a list of Controls so that control nets can easily be copied from one Project to another,...
This is a container for the correlation matrix that comes from a bundle adjust.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
This represents a cube in a project-based GUI interface.
QString id() const
Get a unique, identifying string associated with this image.
Internalizes a list of images and allows for operations on the entire list.
void append(Image *const &value)
Appends an image to the image list.
The main project for ipce.
Shape * shape(QString id)
Return a shape given its id.
void addToProject(WorkOrder *)
This executes the WorkOrder and stores it in the project.
Directory * directory() const
Returns the directory associated with this Project.
Image * image(QString id)
Return an image given its id.
Represents an item of a ProjectItemModel in Qt's model-view framework.
TargetBodyQsp targetBody() const
Returns the TargetBodyQsp stored in the data of the item.
bool isShape() const
Returns true if an Shape is stored in the data of the item.
Template * getTemplate() const
Returns the Template stored in the data of the item.
bool isProject() const
Returns true if a Project is stored in the data of the item.
FileItemQsp fileItem() const
Returns the FileItemQsp stored in the data of the item.
ShapeList * shapeList() const
Returns the ShapeList stored in the data of the item.
bool isControl() const
Returns true if a Control is stored in the data of the item.
bool isControlList() const
Returns true if a ControlList is stored in the data of the item.
bool isShapeList() const
Returns true if an ShapeList is stored in the data of the item.
CorrelationMatrix correlationMatrix() const
Returns the CorrelationMatrix stored the item.
Shape * shape() const
Returns the Shape stored in the data of the item.
bool isImageList() const
Returns true if an ImageList is stored in the data of the item.
ImageList * imageList() const
Returns the ImageList stored in the data of the item.
bool isFileItem() const
Returns true if a FileItemQsp is stored in the data of the item.
Control * control() const
Returns the Control stored in the data of the item.
Image * image() const
Returns the Image stored in the data of the item.
ControlList * controlList() const
Returns the ControlList stored in the data of the item.
bool isImage() const
Returns true if an Image is stored in the data of the item.
GuiCameraQsp guiCamera() const
Returns the GuiCameraQsp stored in the data of the item.
bool isGuiCamera() const
Returns true if a GuiCameraQsp is stored in the data of the item.
bool isCorrelationMatrix() const
Returns true if a CorrelationMatrix is stored in the data of the item.
bool isTargetBody() const
Returns true if a TargetBodyQsp is stored in the data of the item.
This represents a shape in a project-based GUI interface.
QString id() const
Get a unique, identifying string associated with this shape.
Internalizes a list of shapes and allows for operations on the entire list.
void append(Shape *const &value)
Appends an shape to the shape list.
This class is used for processing an XML file containing information about a WorkOrder.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
The XML reader invokes this method at the start of every element in the XML document.
XmlHandler(WorkOrder *workOrder)
Passes a pointer to a WorkOrder to the WorkOrder::XmlHandler class.
WorkOrder * m_workOrder
This is a pointer to the WorkOrder the XmlHandler is filling with information it parses from an XML f...
Provide Undo/redo abilities, serialization, and history for an operation.
QTime * m_elapsedTimer
A QTime object holding the excecution time of the WorkOrder.
void enableWorkOrder()
Enables the work order.
QPointer< QTimer > m_progressBarUpdateTimer
A pointer to the QTimer which updates the ProgressBar.
QStringList m_imageIds
A QStringList of unique image identifiers for all of the images this WorkOrder is dealing with.
void setNext(WorkOrder *nextWorkOrder)
Sets the next WorkOrder in the sequence.
void updateProgress()
Updates the progress bar.
ShapeList * shapeList()
@briefReturns a pointer to the ShapeList for this WorkOrder.
bool m_isSavedToHistory
Set the work order to be shown in the HistoryTreeWidget.
QueuedWorkOrderAction
This enum describes the current state of a Queued WorkOrder.
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
int progressMax() const
Gets the maximum value of the progress range of the WorkOrder.
QStringList m_shapeIds
A QStringList of unique shape identifiers for all of the shapes this WorkOrder is dealing with.
virtual void setData(Context)
Sets the context data for this WorkOrder.
WorkOrder * next() const
Gets the next WorkOrder.
bool modifiesDiskState() const
Returns the modified disk state.
void read(XmlStackedHandlerReader *xmlReader)
Read this work order's data from disk.
bool m_isSynchronous
This is defaulted to true.
bool isUndoing() const
Returns the WorkOrderUndoing state.
void attemptQueuedAction()
Attempts to execute an action on the action queue.
virtual void undoExecution()
Execute the steps necessary to undo this workorder.
virtual void postUndoExecution()
Perform any steps necessary after an undo of a workorder.
Template * getTemplate()
WorkOrder::getTemplate.
Template * m_template
A QSharedPointer to the Template (A Template object but encapsulated within a Gui framework.
void save(QXmlStreamWriter &stream) const
: Saves a WorkOrder to a data stream.
void clearShapeList()
Clears the list of shapes.
bool isRedone() const
Returns the WorkOrder redone status.
void executionFinished()
Signals the Project that the WorkOrder is finished, deletes the update time for the Progress bar,...
virtual void redo()
Starts (or enqueues) a redo.
WorkOrderStatus
This enumeration is used by other functions to set and retrieve the current state of the WorkOrder.
@ WorkOrderFinished
This is used for work orders that will not undo or redo (See createsCleanState())
virtual void undo()
Starts (or enqueues) an undo.
int progressMin() const
Gets the minimum value of the progress range of the WorkOrder.
bool isUndoable() const
Returns true if this work order is undoable, otherwise false.
WorkOrder * previous() const
Gets the previous WorkOrder.
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
static QString toString(WorkOrderStatus)
Gets the current status of the WorkOrder.
bool isUndone() const
Returns the WorkOrder undo status.
virtual bool setupExecution()
This sets up the state for the work order.
void setProgressToFinalText()
Sets the ProgressBar to display the final status of the operation.
QDateTime m_executionTime
This is the date/time that setupExecution() was called.
bool m_createsCleanState
This is defaulted to false.
bool isSavedToHistory() const
Returns true if this work order is to be shown in History, otherwise false.
bool isInStableState() const
Determines if the WorkOrder is in a stable state, or if it's busy doing something.
GuiCameraQsp m_guiCamera
A QSharedPointer to the GuiCamera (the Camera object but encapsulated within a Gui framework.
QPointer< WorkOrder > m_previousWorkOrder
A pointer to the previous WorkOrder in the queue.
static WorkOrderStatus fromStatusString(QString)
Attempts to query the current status of the WorkOrder.
bool isRedoing() const
Returns the redoing status of this WorkOrder.
int m_progressRangeMaxValue
The maximum value of the Progess Bar.
QStringList internalData() const
Gets the internal data for this WorkOrder.
QPointer< ControlList > controlList()
Returns the Control List for this WorkOrder (a list of control networks).
Directory * directory() const
return the workorder project directory Returns the Directory object of the Project this WorkOrder is ...
int m_progressValue
The current value of the Progress Bar.
GuiCameraQsp guiCamera()
WorkOrder::guiCamera.
void setCreatesCleanState(bool createsCleanState)
Declare that this work order is saving the project.
QString statusText() const
WorkOrder::statusText.
QDateTime executionTime() const
Gets the execution time of this WorkOrder.
virtual void execute()
Execute the workorder.
void setModifiesDiskState(bool changesProjectOnDisk)
QPointer< ProgressBar > m_progressBar
A pointer to the ProgressBar.
void setPrevious(WorkOrder *previousWorkOrder)
Sets the previous WorkOrder in the sequence.
void listenForShapeDestruction()
Checks to see if we have lost any shapes in the ShapeList.
virtual bool isExecutable(Context)
Re-implement this method if your work order utilizes controls for data in order to operate.
void disableWorkOrder()
Disables the work order.
bool createsCleanState() const
Returns the CleanState status (whether the Project has been saved to disk or not).
TargetBodyQsp targetBody()
WorkOrder::targetBody.
double m_secondsElapsed
The seconds that have elapsed since the WorkOrder started executing.
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
int m_progressRangeMinValue
The miniumum value of the Progess Bar.
virtual bool dependsOn(WorkOrder *other) const
Indicate workorder dependency This is a virtual function whose role in child classes is to determine ...
Project * project() const
Returns the Project this WorkOrder is attached to.
void clearImageList()
Clears the list of images.
QPointer< Project > m_project
A pointer to the Project this WorkOrder is attached to.
virtual ~WorkOrder()
The Destructor.
ProgressBar * progressBar()
Returns the ProgressBar.
QStringList m_internalData
A QStringList of internal properties for this WorkOrder.
bool m_modifiesDiskState
This is defaulted to false.
QMutex * m_transparentConstMutex
This is used to protect the integrity of data the WorkOrder is working on so that only one thread at ...
QPointer< WorkOrder > m_nextWorkOrder
A pointer to the next WorkOrder in the queue.
void addCloneToProject()
Runs a copy of the current WorkOrder and stores it in the project.
void startRedo()
WorkOrder::startRedo This function is currently empty.
void resetProgressBar()
Resets the ProgressBar.
FileItemQsp m_fileItem
A QSharedPointer to the FileItem.
ImageList * imageList()
Returns a pointer to the ImageList for this WorkOrder.
bool isSynchronous() const
Returns true if this work order is run synchronously, otherwise false.
Context
This enumeration is for recording the context of the current Workorder (whether it is part of a proje...
QString bestText() const
Generate unique action names We don't use action text anymore because Directory likes to rename our a...
int progressValue() const
Gets the current progress value of the WorkOrder.
bool isFinished() const
Returns the finished state of this WorkOrder.
virtual void postExecution()
Perform any necessary actions after execution of a workorder.
QPointer< QFutureWatcher< void > > m_futureWatcher
A pointer to a QFutureWatcher object which monitors a QFuture object using signals and slots.
CorrelationMatrix correlationMatrix()
Returns the CorrleationMatrix for this WorkOrder.
QPointer< QTimer > m_progressBarDeletionTimer
A pointer to the ProgressBar deletion timer.
void listenForImageDestruction()
Checks to see if we have lost any images in the ImageList.
FileItemQsp fileItem()
WorkOrder::fileItem.
WorkOrder(Project *project)
Create a work order that will work with the given project.
TargetBodyQsp m_targetBody
A QSharedPointer to the TargetBody (A Target object but encapsulated within a Gui framework.
Manage a stack of content handlers for reading XML files.
This is free and unencumbered software released into the public domain.
QSharedPointer< GuiCamera > GuiCameraQsp
GuiCameraQsp Represents a smart pointer to a GuiCamera object.
QSharedPointer< TargetBody > TargetBodyQsp
Defines A smart pointer to a TargetBody obj.
QSharedPointer< FileItem > FileItemQsp
A FileItem smart pointer.