23 #include "IsisDebug.h"
28 #include <QFutureWatcher>
30 #include <QtConcurrentRun>
32 #include <QXmlStreamWriter>
34 #include "ControlList.h"
37 #include "ImageList.h"
39 #include "ProgressBar.h"
42 #include "ShapeList.h"
44 #include "XmlStackedHandlerReader.h"
58 m_context = NoContext;
68 m_status = WorkOrderNotStarted;
69 m_queuedAction = NoQueuedAction;
84 tr(
"Work orders cannot be created without a project."),
_FILEINFO_);
87 connect(
this, SIGNAL(triggered()),
120 QAction(other.icon(), ((
QAction &)other).text(), other.parentWidget()),
125 m_context = other.m_context;
127 m_imageList =
new ImageList(*other.m_imageList);
129 m_shapeList =
new ShapeList(*other.m_shapeList);
130 m_correlationMatrix = other.m_correlationMatrix;
131 m_controlList = other.m_controlList;
141 m_status = other.m_status;
142 m_queuedAction = other.m_queuedAction;
155 tr(
"Can not copy work order [%1] because it is currently running")
160 connect(
this, SIGNAL(triggered()),
291 m_controlList = controls;
412 imageList->deleteLater();
422 shapeList->deleteLater();
432 controlList->deleteLater();
455 xmlReader->pushContentHandler(
new XmlHandler(
this));
481 tr(
"Can not store an unstable work order. The work order [%1] is currently "
486 stream.writeStartElement(
"workOrder");
488 stream.writeAttribute(
"actionText", QAction::text());
489 stream.writeAttribute(
"undoText", QUndoCommand::text());
491 stream.writeAttribute(
"type", metaObject()->className());
492 stream.writeAttribute(
"status",
toString(m_status));
495 stream.writeStartElement(
"images");
498 stream.writeStartElement(
"image");
499 stream.writeAttribute(
"id", imageId);
500 stream.writeEndElement();
503 stream.writeEndElement();
507 stream.writeStartElement(
"shapes");
510 stream.writeStartElement(
"shape");
511 stream.writeAttribute(
"id", shapeId);
512 stream.writeEndElement();
515 stream.writeEndElement();
519 stream.writeStartElement(
"internalDataValues");
522 stream.writeStartElement(
"dataValue");
523 stream.writeAttribute(
"value", str);
524 stream.writeEndElement();
527 stream.writeEndElement();
530 if (m_context != NoContext) {
531 stream.writeStartElement(
"context");
533 QString contextStr =
"ProjectContext";
534 stream.writeAttribute(
"value", contextStr);
536 stream.writeEndElement();
539 stream.writeEndElement();
567 bool anyImagesAreNull =
false;
573 m_imageList->append(image);
576 anyImagesAreNull =
true;
580 if (anyImagesAreNull) {
598 bool anyShapesAreNull =
false;
604 m_shapeList->append(shape);
607 anyShapesAreNull =
true;
611 if (anyShapesAreNull) {
629 return m_correlationMatrix;
638 return m_controlList;
702 QString result = QUndoCommand::text().remove(
"&").remove(
"...");
705 if (result.isEmpty()) {
707 result = QString(metaObject()->className()).remove(
"Isis::").remove(
"WorkOrder")
708 .replace(QRegExp(
"([a-z0-9])([A-Z])"),
"\\1 \\2");
709 qWarning() << QString(
"WorkOrder::bestText(): Work order [%1] has no QUndoCommand text")
749 return m_status == WorkOrderRedoing;
758 return m_status == WorkOrderRedone;
767 return m_status == WorkOrderUndoing;
776 return m_status == WorkOrderUndone;
813 QString result =
toString(m_status);
821 result += tr(
" (elapsed: %1:%2)").arg(minutes).arg(seconds, 2, 10, QChar(
'0'));
845 statusString = statusString.toUpper();
849 possibleResult <= WorkOrderLastStatus;
851 if (statusString ==
toString(possibleResult).toUpper()) {
852 result = possibleResult;
869 case WorkOrderUnknownStatus:
870 result = tr(
"Unknown");
872 case WorkOrderNotStarted:
873 result = tr(
"Not Started");
875 case WorkOrderRedoing:
876 result = tr(
"In Progress");
878 case WorkOrderRedone:
879 result = tr(
"Completed");
881 case WorkOrderUndoing:
882 result = tr(
"Undoing");
884 case WorkOrderUndone:
885 result = tr(
"Undone");
888 result = tr(
"Finished");
902 m_queuedAction = RedoQueuedAction;
906 bool mustQueueThisRedo =
false;
910 while (current->
previous() && !dependency) {
915 connect(possibleDependency, SIGNAL(finished(
WorkOrder *)),
917 dependency = possibleDependency;
918 mustQueueThisRedo =
true;
928 mustQueueThisRedo =
true;
934 mustQueueThisRedo =
true;
938 m_queuedAction = RedoQueuedAction;
940 QString queueStatusText;
943 QString dependencyText = dependency->
bestText();
945 if (dependencyText.count() > 5) {
946 dependencyText = dependencyText.mid(0, 5) +
"...";
949 queueStatusText = tr(
"Wait for [%1]").arg(dependencyText);
952 queueStatusText = tr(
"Wait for images");
955 queueStatusText = tr(
"Wait for shapes");
964 if (m_queuedAction == NoQueuedAction) {
965 m_status = WorkOrderRedoing;
966 emit statusChanged(
this);
996 m_queuedAction = UndoQueuedAction;
999 if (!
isUndone() && m_status != WorkOrderNotStarted) {
1002 while (current->
next() && !dependency) {
1004 current->
next()->m_status != WorkOrderNotStarted) {
1007 m_queuedAction = UndoQueuedAction;
1008 dependency = current->
next();
1011 current = current->
next();
1015 QString prevText = dependency->
bestText();
1017 if (prevText.count() > 5) {
1018 prevText = prevText.mid(0, 5) +
"...";
1023 m_progressBar->setText(tr(
"Undo after [%1]").arg(prevText));
1027 if (m_queuedAction == NoQueuedAction) {
1028 m_status = WorkOrderUndoing;
1029 emit statusChanged(
this);
1084 emit statusChanged(
this);
1119 "This work order no longer has a project.",
_FILEINFO_);
1323 foreach (
Image *image, *m_imageList) {
1329 connect(image, SIGNAL(destroyed(
QObject *)),
1346 foreach (
Shape *shape, *m_shapeList) {
1352 connect(shape, SIGNAL(destroyed(
QObject *)),
1367 emit creatingProgress(
this);
1391 else if (
isUndone() || m_status == WorkOrderNotStarted) {
1421 m_queuedAction = NoQueuedAction;
1423 if (queued == RedoQueuedAction && m_status != WorkOrderRedone) {
1426 else if (queued == UndoQueuedAction && m_status != WorkOrderUndone) {
1443 finishedStatus = WorkOrderUndone;
1447 (this->*postSyncMethod)();
1449 m_status = finishedStatus;
1456 emit statusChanged(
this);
1458 emit finished(
this);
1488 emit deletingProgress(
this);
1560 const QString &qName,
const QXmlAttributes &atts) {
1561 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
1562 if (localName ==
"workOrder") {
1563 QString actionText = atts.value(
"actionText");
1564 QString undoText = atts.value(
"undoText");
1566 QString statusStr = atts.value(
"status");
1568 if (!actionText.isEmpty()) {
1569 ((
QAction *)m_workOrder)->setText(actionText);
1572 if (!undoText.isEmpty()) {
1576 if (!executionTime.isEmpty()) {
1577 m_workOrder->m_executionTime = QDateTime::fromString(executionTime);
1580 if (!statusStr.isEmpty()) {
1584 if (m_workOrder->createsCleanState()) {
1588 m_workOrder->m_status = WorkOrderRedone;
1592 else if (localName ==
"dataValue") {
1593 m_workOrder->m_internalData.append(atts.value(
"value"));
1595 else if (localName ==
"context") {
1596 if (atts.value(
"value") ==
"ProjectContext") {
1597 m_workOrder->m_context = ProjectContext;
Internalizes a list of shapes and allows for operations on the entire list.
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
Internalizes a list of images and allows for operations on the entire list.
bool m_modifiesDiskState
This is defaulted to false.
The main project for cnetsuite.
QString id() const
Get a unique, identifying string associated with this image.
void deleteProgress()
Deletes the progress bar.
XmlHandler(WorkOrder *workOrder)
Passes a pointer to a WorkOrder to the WorkOrder::XmlHandler class.
This is a container for the correlation matrix that comes from a bundle adjust.
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.
void attemptQueuedAction()
Attempts to execute an action on the action action queue.
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.
void updateProgress()
Updates the progress bar.
virtual void syncUndo()
This method is designed to be implemented by children work orders.
QPointer< QTimer > m_progressBarUpdateTimer
A pointer to the QTimer which updates the ProgressBar.
Maintains a list of Controls so that control nets can easily be copied from one Project to another...
bool isControl() const
Returns true if a Control is stored in the data of the item.
Project * project() const
Returns the Project this WorkOrder is attached to.
void read(XmlStackedHandlerReader *xmlReader)
Read this work order's data from disk.
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 createsCleanState() const
Returns the CleanState status (whether the Project has been saved to disk or not).
WorkOrder * previous() const
Gets the previous WorkOrder.
bool isImage() const
Returns true if an Image 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.
int m_progressRangeMinValue
The miniumum value of the Progess Bar.
int progressMin() const
Gets the minimum value of the progress range of the WorkOrder.
QPointer< WorkOrder > m_previousWorkOrder
A pointer to the previous WorkOrder in the queue.
QStringList internalData() const
Gets the internal data for this WorkOrder.
This error is for when a programmer made an API call that was illegal.
void asyncFinished()
Signals the Project that the WorkOrder is finished, deletes the update time for the Progress bar...
int progressMax() const
Gets the maximum value of the progress range of the WorkOrder.
bool isRedone() const
Returns the WorkOrder redone status.
TargetBodyQsp targetBody()
WorkOrder::targetBody.
bool isTargetBody() const
Returns true if a TargetBodyQsp is stored in the data of the item.
ShapeList * shapeList()
a pointer to the ShapeList for this WorkOrder.
virtual void redo()
Starts (or enqueues) a redo.
QPointer< ProgressBar > m_progressBar
A pointer to the ProgressBar.
virtual bool isExecutable(Context)
Re-implement this method if your work order utilizes controls for data in order to operate...
QTime * m_elapsedTimer
A QTime object holding the excecution time of the WorkOrder.
QDateTime m_executionTime
This is the date/time that execute() was called.
virtual void postSyncRedo()
This method is designed to be implemented by children work orders.
WorkOrder(Project *project)
Create a work order that will work with the given project.
virtual void undo()
Starts (or enqueues) an undo.
void listenForShapeDestruction()
Checks to see if we have lost any shapes in the ShapeList.
static QString toString(WorkOrderStatus)
Gets the current status of the WorkOrder.
QPointer< QTimer > m_progressBarDeletionTimer
A pointer to the ProgressBar deletion timer.
void addToProject(WorkOrder *)
Run the work order and stores it in the project.
Image * image() const
Returns the Image stored in the data of the item.
Parent class for anything that performs an action in Project.
ControlList * controlList() const
Returns the ControlList stored in the data of the item.
int m_progressValue
The current value of the Progress Bar.
int progressValue() const
Gets the current progress value of the WorkOrder.
QSharedPointer< TargetBody > TargetBodyQsp
Defines A smart pointer to a TargetBody obj.
bool isCorrelationMatrix() const
Returns true if a CorrelationMatrix is stored in the data of the item.
virtual void postSyncUndo()
This method is designed to be implemented by children work orders.
#define _FILEINFO_
Macro for the filename and line number.
bool isFinished() const
Returns the finished state of this WorkOrder.
void append(Shape *const &value)
Appends an shape to the shape list.
WorkOrderStatus
This enumeration is used by other functions to set and retrieve the current state of the WorkOrder...
GuiCameraQsp guiCamera() const
Returns the GuiCameraQsp stored in the data of the item.
Control * control() const
Returns the Control stored in the data of the item.
QStringList m_internalData
A QStringList of internal properties for this WorkOrder.
bool isGuiCamera() const
Returns true if a GuiCameraQsp is stored in the data of the item.
A type of error that cannot be classified as any of the other error types.
virtual void asyncUndo()
This method is designed to be implemented by children work orders.
void setPrevious(WorkOrder *previousWorkOrder)
Sets the previous WorkOrder in the sequence.
QPointer< WorkOrder > m_nextWorkOrder
A pointer to the next WorkOrder in the queue.
This represents a cube in a project-based GUI interface.
QString id() const
Get a unique, identifying string associated with this shape.
bool m_createsCleanState
This is defaulted to false.
Directory * directory() const
Returns the directory associated with this Project.
virtual void setData(Context)
Sets the context data for this WorkOrder.
void clearShapeList()
Clears the list of shapes.
void append(Image *const &value)
Appends an image to the image list.
int m_progressRangeMaxValue
The maximum value of the Progess Bar.
void resetProgressBar()
Resets the ProgressBar.
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
bool modifiesDiskState() const
Returns the modified disk state.
virtual ~WorkOrder()
The Destructor.
bool isShapeList() const
Returns true if an ShapeList is stored in the data of the item.
TargetBodyQsp m_targetBody
A QSharedPointer to the TargetBody (A Target object but encapsulated within a Gui framework...
void append(Control *const &value)
Appends a control pointer to the control list.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
double m_secondsElapsed
The seconds that have elapsed since the WorkOrder started executing.
void setModifiesDiskState(bool changesProjectOnDisk)
.
bool isInStableState() const
Determines if the WorkOrder is in a stable state, or if it's busy doing something.
QString statusText() const
WorkOrder::statusText.
QPointer< QFutureWatcher< void > > m_futureWatcher
A pointer to a QFutureWatcher object which monitors a QFuture object using signals and slots...
QSharedPointer< GuiCamera > GuiCameraQsp
GuiCameraQsp Represents a smart pointer to a GuiCamera object.
QueuedWorkOrderAction
This enum describes the current state of a Queued WorkOrder.
QMutex * m_transparentConstMutex
This is used to protect the integrity of data the WorkOrder is working on so that only one thread at ...
This represents a shape in a project-based GUI interface.
bool isUndone() const
Returns the WorkOrder undo status.
ShapeList * shapeList() const
Returns the ShapeList stored in the data of the item.
void listenForImageDestruction()
Checks to see if we have lost any images in the ImageList.
bool isRedoing() const
Returns the redoing status of this WorkOrder.
void setProgressToFinalText()
Sets the ProgressBar to display the final status of the operation.
bool isControlList() const
Returns true if a ControlList is stored in the data of the item.
QString bestText() const
We don't use action text anymore because Directory likes to rename our actions.
WorkOrder * next() const
Gets the next WorkOrder.
Context
This enumeration is for recording the context of the current Workorder (whether it is part of a proje...
static WorkOrderStatus fromStatusString(QString)
Attempts to query the current status of the WorkOrder.
Represents an item of a ProjectItemModel in Qt's model-view framework.
Directory * directory() const
Returns the Directory object of the Project this WorkOrder is attached to.
QDateTime executionTime() const
Gets the execution time of this WorkOrder.
bool isUndoing() const
Returns the WorkOrderUndoing state.
CorrelationMatrix correlationMatrix()
Returns the CorrleationMatrix for this WorkOrder.
void setNext(WorkOrder *nextWorkOrder)
Sets the next WorkOrder in the sequence.
This is used for work orders that will not undo or redo (See createsCleanState()) ...
QProgressBar with customizable text.
This class is used for processing an XML file containing information about a WorkOrder.
void save(QXmlStreamWriter &stream) const
: Saves a WorkOrder to a data stream.
GuiCameraQsp m_guiCamera
A QSharedPointer to the GuiCamera (the Camera object but encapsulated within a Gui framework...
GuiCameraQsp guiCamera()
WorkOrder::guiCamera.
virtual bool execute()
The (child) implementation of this method should prompt the user/gather state by any means necessary...
QPointer< ControlList > controlList()
Returns the Control List for this WorkOrder (a list of control networks).
ProgressBar * progressBar()
Returns the ProgressBar.
ImageList * imageList()
a pointer to the ImageList for this WorkOrder.
virtual void asyncRedo()
This method is designed to be implemented by children work orders.
his enables stack-based XML parsing of XML files.
void addCloneToProject()
Runs a copy of the current WorkOrder and stores it in the project.
QStringList m_shapeIds
A QStringList of unique shape identifiers for all of the shapes this WorkOrder is dealing with...
void clearImageList()
Clears the list of images.
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
void startRedo()
WorkOrder::startRedo This function is currently empty.
void setCreatesCleanState(bool createsCleanState)
Declare that this work order is saving the project.
QPointer< Project > m_project
A pointer to the Project this WorkOrder is attached to.
QStringList m_imageIds
A QStringList of unique image identifiers for all of the images this WorkOrder is dealing with...
WorkOrder * m_workOrder
This is a pointer to the WorkOrder the XmlHandler is filling with information it parses from an XML f...
virtual bool dependsOn(WorkOrder *other) const
This is a virtual function whose role in child classes is to determine if this WorkOrder deppends on ...
bool isProject() const
Returns true if a Project is stored in the data of the item.
virtual void syncRedo()
This method is designed to be implemented by children work orders.