12#include <QFutureWatcher>
14#include <QMutexLocker>
15#include <QRegularExpression>
16#include <QtConcurrentRun>
18#include <QXmlStreamWriter>
20#include "ControlList.h"
21#include "IException.h"
24#include "ProgressBar.h"
26#include "ProjectItem.h"
42 m_context = NoContext;
59 m_status = WorkOrderNotStarted;
60 m_queuedAction = NoQueuedAction;
74 throw IException(IException::Programmer,
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;
136 throw IException(IException::Unknown,
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() ) {
535 throw IException(IException::Programmer,
536 tr(
"Can not store an unstable work order. The work order [%1] is currently "
541 stream.writeStartElement(
"workOrder");
543 stream.writeAttribute(
"actionText", QAction::text());
544 stream.writeAttribute(
"undoText", QUndoCommand::text());
546 stream.writeAttribute(
"type", metaObject()->className());
547 stream.writeAttribute(
"status",
toString(m_status));
550 stream.writeStartElement(
"images");
553 stream.writeStartElement(
"image");
554 stream.writeAttribute(
"id", imageId);
555 stream.writeEndElement();
558 stream.writeEndElement();
562 stream.writeStartElement(
"shapes");
565 stream.writeStartElement(
"shape");
566 stream.writeAttribute(
"id", shapeId);
567 stream.writeEndElement();
570 stream.writeEndElement();
574 stream.writeStartElement(
"internalDataValues");
577 stream.writeStartElement(
"dataValue");
578 stream.writeAttribute(
"value", str);
579 stream.writeEndElement();
582 stream.writeEndElement();
585 if (m_context != NoContext) {
586 stream.writeStartElement(
"context");
588 QString contextStr =
"ProjectContext";
589 stream.writeAttribute(
"value", contextStr);
591 stream.writeEndElement();
594 stream.writeEndElement();
621 QMutexLocker locker(
project()->workOrderMutex());
623 bool anyImagesAreNull =
false;
629 m_imageList->append(image);
632 anyImagesAreNull =
true;
636 if (anyImagesAreNull) {
653 QMutexLocker locker(
project()->workOrderMutex());
655 bool anyShapesAreNull =
false;
661 m_shapeList->append(shape);
664 anyShapesAreNull =
true;
668 if (anyShapesAreNull) {
686 QMutexLocker locker(
project()->workOrderMutex());
687 return m_correlationMatrix;
696 QMutexLocker locker(
project()->workOrderMutex());
697 return m_controlList;
726 QMutexLocker locker(
project()->workOrderMutex());
736 QMutexLocker locker(
project()->workOrderMutex());
746 QMutexLocker locker(
project()->workOrderMutex());
756 QMutexLocker locker(
project()->workOrderMutex());
785 QString result = QUndoCommand::text().remove(
"&").remove(
"...");
788 if (result.isEmpty()) {
790 result = QString(metaObject()->className()).remove(
"Isis::").remove(
"WorkOrder")
791 .replace(QRegularExpression(
"([a-z0-9])([A-Z])"),
"\\1 \\2");
792 qWarning() << QString(
"WorkOrder::bestText(): Work order [%1] has no QUndoCommand text")
809 QMutexLocker locker(
project()->workOrderMutex());
820 QMutexLocker locker(
project()->workOrderMutex());
831 QMutexLocker locker(
project()->workOrderMutex());
844 QMutexLocker locker(
project()->workOrderMutex());
854 QMutexLocker locker(
project()->workOrderMutex());
873 QMutexLocker locker(
project()->workOrderMutex());
874 return m_status == WorkOrderRedoing;
883 QMutexLocker locker(
project()->workOrderMutex());
884 return m_status == WorkOrderRedone;
893 QMutexLocker locker(
project()->workOrderMutex());
894 return m_status == WorkOrderUndoing;
903 QMutexLocker locker(
project()->workOrderMutex());
904 return m_status == WorkOrderUndone;
914 QMutexLocker locker(
project()->workOrderMutex());
924 QMutexLocker locker(
project()->workOrderMutex());
934 QMutexLocker locker(
project()->workOrderMutex());
944 QMutexLocker locker(
project()->workOrderMutex());
945 QString result =
toString(m_status);
953 result += tr(
" (elapsed: %1:%2)").arg(minutes).arg(seconds, 2, 10, QChar(
'0'));
965 QMutexLocker locker(
project()->workOrderMutex());
978 statusString = statusString.toUpper();
982 possibleResult <= WorkOrderLastStatus;
984 if (statusString ==
toString(possibleResult).toUpper()) {
985 result = possibleResult;
1002 case WorkOrderUnknownStatus:
1003 result = tr(
"Unknown");
1005 case WorkOrderNotStarted:
1006 result = tr(
"Not Started");
1008 case WorkOrderRedoing:
1009 result = tr(
"In Progress");
1011 case WorkOrderRedone:
1012 result = tr(
"Completed");
1014 case WorkOrderUndoing:
1015 result = tr(
"Undoing");
1017 case WorkOrderUndone:
1018 result = tr(
"Undone");
1021 result = tr(
"Finished");
1034 m_queuedAction = RedoQueuedAction;
1038 bool mustQueueThisRedo =
false;
1042 while (current->
previous() && !dependency) {
1047 connect(possibleDependency, SIGNAL(finished(
WorkOrder *)),
1049 dependency = possibleDependency;
1050 mustQueueThisRedo =
true;
1060 mustQueueThisRedo =
true;
1066 mustQueueThisRedo =
true;
1071 m_queuedAction = RedoQueuedAction;
1073 QString queueStatusText;
1076 QString dependencyText = dependency->
bestText();
1078 if (dependencyText.count() > 5) {
1079 dependencyText = dependencyText.mid(0, 5) +
"...";
1082 queueStatusText = tr(
"Wait for [%1]").arg(dependencyText);
1085 queueStatusText = tr(
"Wait for images");
1088 queueStatusText = tr(
"Wait for shapes");
1097 if (m_queuedAction == NoQueuedAction) {
1098 m_status = WorkOrderRedoing;
1099 emit statusChanged(
this);
1137 m_queuedAction = UndoQueuedAction;
1140 if (!
isUndone() && m_status != WorkOrderNotStarted) {
1143 while (current->
next() && !dependency) {
1145 current->
next()->m_status != WorkOrderNotStarted) {
1148 m_queuedAction = UndoQueuedAction;
1149 dependency = current->
next();
1152 current = current->
next();
1156 QString prevText = dependency->
bestText();
1158 if (prevText.count() > 5) {
1159 prevText = prevText.mid(0, 5) +
"...";
1164 m_progressBar->setText(tr(
"Undo after [%1]").arg(prevText));
1168 if (m_queuedAction == NoQueuedAction) {
1169 m_status = WorkOrderUndoing;
1170 emit statusChanged(
this);
1256 emit statusChanged(
this);
1291 throw IException(IException::Programmer,
1292 "This work order no longer has a project.", _FILEINFO_);
1317 QMutexLocker locker(
project()->workOrderMutex());
1327 QMutexLocker locker(
project()->workOrderMutex());
1337 QMutexLocker locker(
project()->workOrderMutex());
1367 QMutexLocker locker(
project()->workOrderMutex());
1470 foreach (
Image *image, *m_imageList) {
1476 connect(image, SIGNAL(destroyed(
QObject *)),
1493 foreach (
Shape *shape, *m_shapeList) {
1499 connect(shape, SIGNAL(destroyed(
QObject *)),
1514 emit creatingProgress(
this);
1538 else if (
isUndone() || m_status == WorkOrderNotStarted) {
1566 m_queuedAction = NoQueuedAction;
1568 if (queued == RedoQueuedAction && m_status != WorkOrderRedone) {
1571 else if (queued == UndoQueuedAction && m_status != WorkOrderUndone) {
1588 finishedStatus = WorkOrderUndone;
1592 (this->*postMethod)();
1594 m_status = finishedStatus;
1601 emit statusChanged(
this);
1603 emit finished(
this);
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.
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.
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 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.
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.
virtual void setData(ProjectItem *item)
Sets the internal data to the data stored in a ProjectItem.
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 ...
QElapsedTimer * m_elapsedTimer
A QElapsedTimer object holding the excecution time of the WorkOrder.
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.
This is free and unencumbered software released into the public domain.
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.