Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
WorkOrder.cpp
1
6
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "WorkOrder.h"
10
11#include <QDebug>
12#include <QFutureWatcher>
13#include <QMutex>
14#include <QMutexLocker>
15#include <QRegularExpression>
16#include <QtConcurrentRun>
17#include <QTimer>
18#include <QXmlStreamWriter>
19
20#include "ControlList.h"
21#include "IException.h"
22#include "ImageList.h"
23#include "IString.h"
24#include "ProgressBar.h"
25#include "Project.h"
26#include "ProjectItem.h"
27#include "ShapeList.h"
28#include "Template.h"
29
30
31namespace Isis {
41
42 m_context = NoContext;
43 m_data = "";
44 m_imageList = new ImageList;
45 m_shapeList = new ShapeList;
46 m_controlList = NULL;
47 m_correlationMatrix = CorrelationMatrix();
50 m_template = NULL;
52
53 m_isUndoable = true;
54 m_isSavedToHistory = true;
55 m_isSynchronous = true;
56
57 m_createsCleanState = false;
58 m_modifiesDiskState = false;
59 m_status = WorkOrderNotStarted;
60 m_queuedAction = NoQueuedAction;
62 m_elapsedTimer = NULL;
63
65 m_transparentConstMutex = new QMutex;
66
70
71 m_secondsElapsed = 0.0;
72
73 if (!m_project) {
74 throw IException(IException::Programmer,
75 tr("Work orders cannot be created without a project."), _FILEINFO_);
76 }
77
78 connect(this, SIGNAL(triggered()),
79 this, SLOT(addCloneToProject()));
80 connect(m_futureWatcher, SIGNAL(finished()),
81 this, SLOT(executionFinished()));
82 }
83
84
92 QAction(other.icon(), ((QAction &)other).text(), other.parentWidget()),
93 QUndoCommand(((QUndoCommand &)other).text()) {
94 // Copy the action's what's this and tool tip (hover text).
95 QAction::setWhatsThis(other.whatsThis());
96 QAction::setToolTip(other.toolTip());
97
99 m_elapsedTimer = NULL;
100 m_project = other.project();
101 m_context = other.m_context;
102 m_imageIds = other.m_imageIds;
103 m_imageList = new ImageList(*other.m_imageList);
104 m_shapeIds = other.m_shapeIds;
105 m_shapeList = new ShapeList(*other.m_shapeList);
106 m_correlationMatrix = other.m_correlationMatrix;
107 m_controlList = other.m_controlList;
108 m_guiCamera = other.m_guiCamera;
110 m_fileItem = other.m_fileItem;
112 m_template = other.m_template;
113
117
120
122
123 m_status = other.m_status;
124 m_queuedAction = other.m_queuedAction;
125
127
131
133 m_transparentConstMutex = new QMutex;
134
135 if (!other.isInStableState()) {
136 throw IException(IException::Unknown,
137 tr("Can not copy work order [%1] because it is currently running")
138 .arg(((QUndoCommand &)other).text()),
139 _FILEINFO_);
140 }
141
142 connect(this, SIGNAL(triggered()),
143 this, SLOT(addCloneToProject()));
144 connect(m_futureWatcher, SIGNAL(finished()),
145 this, SLOT(executionFinished()));
146
149 }
150
151
156
157 delete m_imageList;
158 delete m_shapeList;
159 delete m_futureWatcher;
163
164 m_nextWorkOrder = NULL;
165 m_previousWorkOrder = NULL;
166 m_project = NULL;
168 }
169
170
181 return false;
182 }
183
184
195 return false;
196 }
197
198
209 return false;
210 }
211
212
220//bool WorkOrder::isExecutable(Control *control) {
221// return false;
222//}
223
224
233 return false;
234 }
235
236
237 bool WorkOrder::isExecutable(CorrelationMatrix correlationMatrix) {
238 return false;
239 }
240
241
247 m_context = context;
248 }
249
250 void WorkOrder::setData(QString data) {
251 m_data = data;
252 }
253
254
260 m_imageIds.clear();
261 delete m_imageList;
262
263 m_imageList = new ImageList(*images);
265 }
266
267
273 m_shapeIds.clear();
274 delete m_shapeList;
275
276 m_shapeList = new ShapeList(*shapes);
278 }
279
280
285//void WorkOrder::setData(Control *control) {
286// m_control = control;
287//}
288
289
296 m_controlList = controls;
297 }
298
299
307
308
309
310
318
319
324 void WorkOrder::setData(Template *currentTemplate) {
325 m_template = currentTemplate;
326 }
327
328
336
337
345
346
352 if ( item->isProject() ) {
353 setData( ProjectContext );
354 }
355 else if ( item->isImageList() ) {
356 setData( item->imageList() );
357 }
358 else if ( item->isImage() ) {
359 ImageList *imageList = new ImageList(this);
360 imageList->append( item->image() );
362 }
363 else if ( item->isShapeList() ) {
364 setData( item->shapeList() );
365 }
366 else if ( item->isShape() ) {
367 ShapeList *shapeList = new ShapeList(this);
368 shapeList->append( item->shape() );
370 }
371 else if (item->isControlList()) {
372 setData( item->controlList() );
373 }
374 else if ( item->isControl() ) {
376 controlList->append( item->control() );
378// //setData(*controlList);
379 }
380 else if ( item->isCorrelationMatrix() ) {
381 setData( item->correlationMatrix() );
382 }
383 else if ( item->isTargetBody() ) {
384 setData( item->targetBody() );
385 }
386 else if ( item->isGuiCamera() ) {
387 setData( item->guiCamera() );
388 }
389 else if ( item->isFileItem() ) {
390 setData( item->fileItem() );
391 }
392 else if ( item->isTemplate() ) {
393 setData( item->getTemplate() );
394 }
395 }
396
397
398
399
400
409 return false;
410 }
411
412
420 bool WorkOrder::isExecutable(Template *currentTemplate) {
421 return false;
422 }
423
424
433 return false;
434 }
435
436
445 return false;
446 }
447
448
457 if ( !item ) {
458 return false;
459 }
460 else if ( item->isProject() ) {
461 return isExecutable( ProjectContext );
462 }
463 else if ( item->isImageList() ) {
464 return isExecutable( item->imageList() );
465 }
466 else if ( item->isImage() ) {
468 imageList->append( item->image() );
469 bool ret = isExecutable(imageList);
470 imageList->deleteLater();
471 return ret;
472 }
473 else if ( item->isShapeList() ) {
474 return isExecutable( item->shapeList() );
475 }
476 else if ( item->isShape() ) {
478 shapeList->append( item->shape() );
479 bool ret = isExecutable(shapeList);
480 shapeList->deleteLater();
481 return ret;
482 }
483 else if ( item->isControlList() ) {
484 return isExecutable (item -> controlList() );
485 }
486 else if ( item->isControl() ) {
488 controlList->append( item->control() );
489 bool ret = isExecutable(controlList);
490 controlList->deleteLater();
491 return ret;
492 }
493 else if ( item->isCorrelationMatrix() ) {
494 return isExecutable( item->correlationMatrix() );
495 }
496 else if ( item->isTargetBody() ) {
497 //return isExecutable( item->targetBody() ) || isExecutable( item->targetBody().data() );
498 return isExecutable(item->targetBody());
499 }
500 else if ( item->isGuiCamera() ) {
501 //return isExecutable( item->guiCamera() ) || isExecutable( item->guiCamera().data() );
502 return isExecutable( item->guiCamera() );
503 }
504 else if ( item->isFileItem() ) {
505 return isExecutable( item->fileItem() );
506 }
507 else if ( item->isTemplate() ) {
508 return isExecutable( item->getTemplate() );
509 }
510
511 return false;
512 }
513
533 void WorkOrder::save(QXmlStreamWriter &stream) const {
534 if (!isInStableState()) {
535 throw IException(IException::Programmer,
536 tr("Can not store an unstable work order. The work order [%1] is currently "
537 "working").arg(bestText()),
538 _FILEINFO_);
539 }
540
541 stream.writeStartElement("workOrder");
542
543 stream.writeAttribute("actionText", QAction::text());
544 stream.writeAttribute("undoText", QUndoCommand::text());
545 stream.writeAttribute("executionTime", m_executionTime.toString());
546 stream.writeAttribute("type", metaObject()->className());
547 stream.writeAttribute("status", toString(m_status));
548
549 if (m_imageIds.count()) {
550 stream.writeStartElement("images");
551
552 foreach (QString imageId, m_imageIds) {
553 stream.writeStartElement("image");
554 stream.writeAttribute("id", imageId);
555 stream.writeEndElement();
556 }
557
558 stream.writeEndElement();
559 }
560
561 if (m_shapeIds.count()) {
562 stream.writeStartElement("shapes");
563
564 foreach (QString shapeId, m_shapeIds) {
565 stream.writeStartElement("shape");
566 stream.writeAttribute("id", shapeId);
567 stream.writeEndElement();
568 }
569
570 stream.writeEndElement();
571 }
572
573 if (m_internalData.count()) {
574 stream.writeStartElement("internalDataValues");
575
576 foreach (QString str, m_internalData) {
577 stream.writeStartElement("dataValue");
578 stream.writeAttribute("value", str);
579 stream.writeEndElement();
580 }
581
582 stream.writeEndElement();
583 }
584
585 if (m_context != NoContext) {
586 stream.writeStartElement("context");
587
588 QString contextStr = "ProjectContext";
589 stream.writeAttribute("value", contextStr);
590
591 stream.writeEndElement();
592 }
593
594 stream.writeEndElement();
595 }
596
597
602 void WorkOrder::setNext(WorkOrder *nextWorkOrder) {
603 m_nextWorkOrder = nextWorkOrder;
604 }
605
606
611 void WorkOrder::setPrevious(WorkOrder *previousWorkOrder) {
612 m_previousWorkOrder = previousWorkOrder;
613 }
614
615
621 QMutexLocker locker(project()->workOrderMutex());
622 if (!m_imageList) {
623 bool anyImagesAreNull = false;
624
625 m_imageList = new ImageList;
626
627 foreach (QString id, m_imageIds) {
628 Image *image = project()->image(id);
629 m_imageList->append(image);
630
631 if (!image) {
632 anyImagesAreNull = true;
633 }
634 }
635
636 if (anyImagesAreNull) {
637 delete m_imageList;
638 }
639 else {
641 }
642 }
643
644 return m_imageList;
645 }
646
647
653 QMutexLocker locker(project()->workOrderMutex());
654 if (!m_shapeList) {
655 bool anyShapesAreNull = false;
656
657 m_shapeList = new ShapeList;
658
659 foreach (QString id, m_shapeIds) {
660 Shape *shape = project()->shape(id);
661 m_shapeList->append(shape);
662
663 if (!shape) {
664 anyShapesAreNull = true;
665 }
666 }
667
668 if (anyShapesAreNull) {
669 delete m_shapeList;
670 }
671 else {
673 }
674 }
675
676 return
677 m_shapeList;
678 }
679
680
686 QMutexLocker locker(project()->workOrderMutex());
687 return m_correlationMatrix;
688 }
689
690
695 QPointer<ControlList> WorkOrder::controlList() {
696 QMutexLocker locker(project()->workOrderMutex());
697 return m_controlList;
698 }
699
700
706 QMutexLocker lock(m_transparentConstMutex);
707 return const_cast<WorkOrder *>(this)->imageList();
708 }
709
710
716 QMutexLocker lock(m_transparentConstMutex);
717 return const_cast<WorkOrder *>(this)->shapeList();
718 }
719
720
726 QMutexLocker locker(project()->workOrderMutex());
727 return m_template;
728 }
729
730
736 QMutexLocker locker(project()->workOrderMutex());
737 return m_targetBody;
738 }
739
740
746 QMutexLocker locker(project()->workOrderMutex());
747 return m_guiCamera;
748 }
749
750
756 QMutexLocker locker(project()->workOrderMutex());
757 return m_fileItem;
758 }
759
760
771 return true;
772 }
773
774
784 QString WorkOrder::bestText() const {
785 QString result = QUndoCommand::text().remove("&").remove("...");
786
787 // if the QUndoCommand has no text, create a warning
788 if (result.isEmpty()) {
789 // get the name of the work order
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")
793 .arg(result);
794 }
795
796 return result;
797 }
798
799
809 QMutexLocker locker(project()->workOrderMutex());
810 return m_isUndoable;
811 }
812
813
820 QMutexLocker locker(project()->workOrderMutex());
821 return m_isSavedToHistory;
822 }
823
824
831 QMutexLocker locker(project()->workOrderMutex());
832 return m_isSynchronous;
833 }
834
835
844 QMutexLocker locker(project()->workOrderMutex());
845 return m_createsCleanState;
846 }
847
848
853 QDateTime WorkOrder::executionTime() const {
854 QMutexLocker locker(project()->workOrderMutex());
855 return m_executionTime;
856 }
857
858
864 return m_status == WorkOrderFinished;
865 }
866
867
872 bool WorkOrder::isRedoing() const {
873 QMutexLocker locker(project()->workOrderMutex());
874 return m_status == WorkOrderRedoing;
875 }
876
877
882 bool WorkOrder::isRedone() const {
883 QMutexLocker locker(project()->workOrderMutex());
884 return m_status == WorkOrderRedone;
885 }
886
887
892 bool WorkOrder::isUndoing() const {
893 QMutexLocker locker(project()->workOrderMutex());
894 return m_status == WorkOrderUndoing;
895 }
896
897
902 bool WorkOrder::isUndone() const {
903 QMutexLocker locker(project()->workOrderMutex());
904 return m_status == WorkOrderUndone;
905 }
906
907
914 QMutexLocker locker(project()->workOrderMutex());
915 return m_modifiesDiskState;
916 }
917
918
924 QMutexLocker locker(project()->workOrderMutex());
925 return m_nextWorkOrder;
926 }
927
928
934 QMutexLocker locker(project()->workOrderMutex());
935 return m_previousWorkOrder;
936 }
937
938
943 QString WorkOrder::statusText() const {
944 QMutexLocker locker(project()->workOrderMutex());
945 QString result = toString(m_status);
946
947 if (m_secondsElapsed) {
948 // QTime can't format in the way that I want (0-n minutes, 00-59 seconds, no hours
949 // displayed)... so do it manually.
950 // Expected output format examples: 0:01, 0:55, 1:30, 55:55, 90:00, 100:12
951 int seconds = qRound(m_secondsElapsed) % 60;
952 int minutes = qRound(m_secondsElapsed) / 60;
953 result += tr(" (elapsed: %1:%2)").arg(minutes).arg(seconds, 2, 10, QChar('0'));
954 }
955
956 return result;
957 }
958
959
965 QMutexLocker locker(project()->workOrderMutex());
966 return m_progressBar;
967 }
968
969
978 statusString = statusString.toUpper();
979 WorkOrderStatus result = WorkOrderUnknownStatus;
980
981 for (WorkOrderStatus possibleResult = WorkOrderUnknownStatus;
982 possibleResult <= WorkOrderLastStatus;
983 possibleResult = (WorkOrderStatus)(possibleResult + 1)) {
984 if (statusString == toString(possibleResult).toUpper()) {
985 result = possibleResult;
986 }
987 }
988
989 return result;
990 }
991
992
999 QString result;
1000
1001 switch (status) {
1002 case WorkOrderUnknownStatus:
1003 result = tr("Unknown");
1004 break;
1005 case WorkOrderNotStarted:
1006 result = tr("Not Started");
1007 break;
1008 case WorkOrderRedoing:
1009 result = tr("In Progress");
1010 break;
1011 case WorkOrderRedone:
1012 result = tr("Completed");
1013 break;
1014 case WorkOrderUndoing:
1015 result = tr("Undoing");
1016 break;
1017 case WorkOrderUndone:
1018 result = tr("Undone");
1019 break;
1020 case WorkOrderFinished:
1021 result = tr("Finished");
1022 break;
1023 }
1024
1025 return result;
1026 }
1027
1028
1033 if (!isInStableState()) {
1034 m_queuedAction = RedoQueuedAction;
1035 }
1036
1037 if (!isRedone()) {
1038 bool mustQueueThisRedo = false;
1039
1040 WorkOrder *dependency = NULL;
1041 WorkOrder *current = this;
1042 while (current->previous() && !dependency) {
1043 if (!current->previous()->isRedone() && !current->previous()->isFinished()) {
1044 WorkOrder *possibleDependency = current->previous();
1045
1046 if (dependsOn(possibleDependency)) {
1047 connect(possibleDependency, SIGNAL(finished(WorkOrder *)),
1048 this, SLOT(attemptQueuedAction()));
1049 dependency = possibleDependency;
1050 mustQueueThisRedo = true;
1051 }
1052 }
1053
1054 current = current->previous();
1055 }
1056
1057 if (!imageList()) {
1058 connect(project(), SIGNAL(imagesAdded(ImageList *)),
1059 this, SLOT(attemptQueuedAction()));
1060 mustQueueThisRedo = true;
1061 }
1062
1063 if (!shapeList()) {
1064 connect(project(), SIGNAL(shapesAdded(ShapeList *)),
1065 this, SLOT(attemptQueuedAction()));
1066 mustQueueThisRedo = true;
1067 }
1068
1069 if (mustQueueThisRedo && !isUndoing() && !isRedoing()) {
1070
1071 m_queuedAction = RedoQueuedAction;
1072
1073 QString queueStatusText;
1074
1075 if (dependency) {
1076 QString dependencyText = dependency->bestText();
1077
1078 if (dependencyText.count() > 5) {
1079 dependencyText = dependencyText.mid(0, 5) + "...";
1080 }
1081
1082 queueStatusText = tr("Wait for [%1]").arg(dependencyText);
1083 }
1084 else if (!imageList()) {
1085 queueStatusText = tr("Wait for images");
1086 }
1087 else if (!shapeList()) {
1088 queueStatusText = tr("Wait for shapes");
1089 }
1090
1092 m_progressBar->setValue(m_progressBar->minimum());
1093 m_progressBar->setText(queueStatusText);
1094 m_progressBar->update();
1095 }
1096
1097 if (m_queuedAction == NoQueuedAction) {
1098 m_status = WorkOrderRedoing;
1099 emit statusChanged(this);
1100
1102 m_progressBar->setText("Starting...");
1103 m_progressBar->update();
1104
1105 delete m_elapsedTimer;
1106 m_elapsedTimer = new QElapsedTimer;
1107 m_elapsedTimer->start();
1108
1109 if (isSynchronous()) {
1110 execute();
1112 }
1113 else {
1114 m_progressBar->setText("Running...");
1115 m_progressBar->update();
1116 // queue the workorder for asynchronous execution
1117 QFuture<void> future = QtConcurrent::run(&WorkOrder::execute, this);
1118 // executionFinished() is called via the finished signal. The
1119 // connection is setup in the constructor.
1120 m_futureWatcher->setFuture(future);
1121 }
1122 }
1123 }
1124 else {
1126 }
1127 }
1128
1129
1136 if (!isInStableState()) {
1137 m_queuedAction = UndoQueuedAction;
1138 }
1139
1140 if (!isUndone() && m_status != WorkOrderNotStarted) {
1141 WorkOrder *dependency = NULL;
1142 WorkOrder *current = this;
1143 while (current->next() && !dependency) {
1144 if (!current->next()->isUndone() && !current->next()->isFinished() &&
1145 current->next()->m_status != WorkOrderNotStarted) {
1146 connect(current->next(), SIGNAL(finished(WorkOrder *)),
1147 this, SLOT(attemptQueuedAction()));
1148 m_queuedAction = UndoQueuedAction;
1149 dependency = current->next();
1150 }
1151
1152 current = current->next();
1153 }
1154
1155 if (dependency && !isUndoing() && !isRedoing()) {
1156 QString prevText = dependency->bestText();
1157
1158 if (prevText.count() > 5) {
1159 prevText = prevText.mid(0, 5) + "...";
1160 }
1161
1163 m_progressBar->setValue(m_progressBar->minimum());
1164 m_progressBar->setText(tr("Undo after [%1]").arg(prevText));
1165 m_progressBar->update();
1166 }
1167
1168 if (m_queuedAction == NoQueuedAction) {
1169 m_status = WorkOrderUndoing;
1170 emit statusChanged(this);
1171
1173 m_progressBar->setText("Starting Undo...");
1174 m_progressBar->update();
1175
1176 delete m_elapsedTimer;
1177 m_elapsedTimer = new QElapsedTimer;
1178 m_elapsedTimer->start();
1179
1180 if (isSynchronous()) {
1181 undoExecution();
1183 }
1184 else {
1185 m_progressBar->setText("Undoing...");
1186 m_progressBar->update();
1187 // queue the workorder for asynchronous execution
1188 QFuture<void> future = QtConcurrent::run(&WorkOrder::undoExecution, this);
1189 // executionFinished() is called via the finished signal. The
1190 // connection is setup in the constructor.
1191 m_futureWatcher->setFuture(future);
1192 }
1193 }
1194 }
1195 else {
1197 }
1198 }
1199
1208 setEnabled(true);
1209 }
1210
1211
1220 setEnabled(false);
1221 }
1222
1223
1251 // We're finished at this point if we save/open a project, we're not finished if we need to do
1252 // redo()
1253 if (createsCleanState() || !isUndoable()) {
1254 m_status = WorkOrderFinished;
1255
1256 emit statusChanged(this);
1257 }
1258
1259 m_executionTime = QDateTime::currentDateTime();
1260
1262
1263 if (createsCleanState() || !isUndoable()) {
1265 }
1266 else {
1267 m_progressBar->setText("Initializing...");
1268 }
1269
1270 return true;
1271 }
1272
1273
1280 return project()->directory();
1281 }
1282
1283
1290 if (!m_project) {
1291 throw IException(IException::Programmer,
1292 "This work order no longer has a project.", _FILEINFO_);
1293 }
1294
1295 return m_project;
1296 }
1297
1298
1310
1311
1317 QMutexLocker locker(project()->workOrderMutex());
1319 }
1320
1321
1327 QMutexLocker locker(project()->workOrderMutex());
1329 }
1330
1331
1337 QMutexLocker locker(project()->workOrderMutex());
1338 return m_progressValue;
1339 }
1340
1341
1347 void WorkOrder::setProgressRange(int minValue, int maxValue) {
1348 m_progressRangeMinValue = minValue;
1349 m_progressRangeMaxValue = maxValue;
1350 }
1351
1352
1358 m_progressValue = value;
1359 }
1360
1361
1367 QMutexLocker locker(project()->workOrderMutex());
1368 return m_internalData;
1369 }
1370
1371
1393 }
1394
1395
1405
1406
1425
1426
1436
1437
1442 if (project()) {
1443 project()->addToProject(clone());
1444 }
1445 }
1446
1447
1453 bool result = true;
1454
1455 if (isRedoing() || isUndoing() || m_queuedAction != NoQueuedAction) {
1456 result = false;
1457 }
1458
1459 return result;
1460 }
1461
1462
1469 m_imageIds.clear();
1470 foreach (Image *image, *m_imageList) {
1471 if (image) {
1472 m_imageIds.append(image->id());
1473
1474 // If we lose any images, destroy the entire list. This will let us know that we need to
1475 // rebuild it, if needed, when requested.
1476 connect(image, SIGNAL(destroyed(QObject *)),
1477 this, SLOT(clearImageList()));
1478 }
1479 }
1480 }
1481
1482
1492 m_shapeIds.clear();
1493 foreach (Shape *shape, *m_shapeList) {
1494 if (shape) {
1495 m_shapeIds.append(shape->id());
1496
1497 // If we lose any shapes, destroy the entire list. This will let us know that we need to
1498 // rebuild it, if needed, when requested.
1499 connect(shape, SIGNAL(destroyed(QObject *)),
1500 this, SLOT(clearShapeList()));
1501 }
1502 }
1503 }
1504
1505
1511
1512 if (!m_progressBar) {
1514 emit creatingProgress(this);
1515 }
1516
1518 m_progressBarUpdateTimer = new QTimer;
1519 connect(m_progressBarUpdateTimer, SIGNAL(timeout()),
1520 this, SLOT(updateProgress()));
1521 m_progressBarUpdateTimer->start(100);
1522 }
1523
1526 m_progressValue = 0;
1527 }
1528
1529
1534 if (m_progressBar) {
1535 if (isRedone()) {
1536 m_progressBar->setText(tr("Finished"));
1537 }
1538 else if (isUndone() || m_status == WorkOrderNotStarted) {
1539 m_progressBar->setText(tr("Undone"));
1540 }
1541
1542 if (m_progressBar->minimum() != 0 || m_progressBar->maximum() != 0) {
1543 m_progressBar->setValue(m_progressBar->maximum());
1544 }
1545 else {
1546 m_progressBar->setRange(0, 100);
1547 m_progressBar->setValue(100);
1548 }
1549
1551 m_progressBarDeletionTimer = new QTimer;
1552 m_progressBarDeletionTimer->setSingleShot(true);
1553
1554 m_progressBarDeletionTimer->start(5 * 1000); // 5 seconds
1555
1556 m_progressBar->update();
1557 }
1558 }
1559
1560
1565 QueuedWorkOrderAction queued = m_queuedAction;
1566 m_queuedAction = NoQueuedAction;
1567
1568 if (queued == RedoQueuedAction && m_status != WorkOrderRedone) {
1569 redo();
1570 }
1571 else if (queued == UndoQueuedAction && m_status != WorkOrderUndone) {
1572 undo();
1573 }
1574 }
1575
1576
1583
1584 WorkOrderStatus finishedStatus = WorkOrderRedone;
1585 void (WorkOrder::*postMethod)() = &WorkOrder::postExecution;
1586
1587 if (isUndoing()) {
1588 finishedStatus = WorkOrderUndone;
1589 postMethod = &WorkOrder::postUndoExecution;
1590 }
1591
1592 (this->*postMethod)();
1593
1594 m_status = finishedStatus;
1595
1596 m_secondsElapsed = m_elapsedTimer->elapsed() / 1000.0;
1597
1598 delete m_elapsedTimer;
1599 m_elapsedTimer = NULL;
1600
1601 emit statusChanged(this);
1603 emit finished(this);
1604
1606 }
1607
1608
1613 delete m_imageList;
1614 }
1615
1616
1621 delete m_shapeList;
1622 }
1623
1624
1634
1635
1640 }
1641
1642
1655
1656
1663 void WorkOrder::setModifiesDiskState(bool changesProjectOnDisk) {
1664 m_modifiesDiskState = changesProjectOnDisk;
1665 }
1666}
Maintains a list of Controls so that control nets can easily be copied from one Project to another,...
Definition ControlList.h:41
This is a container for the correlation matrix that comes from a bundle adjust.
This represents a cube in a project-based GUI interface.
Definition Image.h:105
QString id() const
Get a unique, identifying string associated with this image.
Definition Image.cpp:421
Internalizes a list of images and allows for operations on the entire list.
Definition ImageList.h:52
The main project for ipce.
Definition Project.h:287
Shape * shape(QString id)
Return a shape given its id.
Definition Project.cpp:1601
void addToProject(WorkOrder *)
This executes the WorkOrder and stores it in the project.
Definition Project.cpp:2660
Directory * directory() const
Returns the directory associated with this Project.
Definition Project.cpp:1227
Image * image(QString id)
Return an image given its id.
Definition Project.cpp:1571
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.
Definition Shape.h:66
QString id() const
Get a unique, identifying string associated with this shape.
Definition Shape.cpp:444
Internalizes a list of shapes and allows for operations on the entire list.
Definition ShapeList.h:30
void enableWorkOrder()
Enables the work order.
QPointer< QTimer > m_progressBarUpdateTimer
A pointer to the QTimer which updates the ProgressBar.
Definition WorkOrder.h:640
QStringList m_imageIds
A QStringList of unique image identifiers for all of the images this WorkOrder is dealing with.
Definition WorkOrder.h:584
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.
Definition WorkOrder.h:511
QueuedWorkOrderAction
This enum describes the current state of a Queued WorkOrder.
Definition WorkOrder.h:482
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.
Definition WorkOrder.h:590
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.
Definition WorkOrder.h:504
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.
Definition WorkOrder.h:564
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.
Definition WorkOrder.h:321
@ WorkOrderFinished
This is used for work orders that will not undo or redo (See createsCleanState())
Definition WorkOrder.h:331
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...
Definition WorkOrder.h:497
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.
Definition WorkOrder.h:621
bool m_createsCleanState
This is defaulted to false.
Definition WorkOrder.h:523
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.
Definition WorkOrder.h:557
QPointer< WorkOrder > m_previousWorkOrder
A pointer to the previous WorkOrder in the queue.
Definition WorkOrder.h:605
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.
Definition WorkOrder.h:541
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.
Definition WorkOrder.h:545
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.
Definition WorkOrder.h:635
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.
Definition WorkOrder.h:656
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
int m_progressRangeMinValue
The miniumum value of the Progess Bar.
Definition WorkOrder.h:537
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.
Definition WorkOrder.h:651
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.
Definition WorkOrder.h:610
virtual ~WorkOrder()
The Destructor.
ProgressBar * progressBar()
Returns the ProgressBar.
QStringList m_internalData
A QStringList of internal properties for this WorkOrder.
Definition WorkOrder.h:595
bool m_modifiesDiskState
This is defaulted to false.
Definition WorkOrder.h:530
QMutex * m_transparentConstMutex
This is used to protect the integrity of data the WorkOrder is working on so that only one thread at ...
Definition WorkOrder.h:616
QPointer< WorkOrder > m_nextWorkOrder
A pointer to the next WorkOrder in the queue.
Definition WorkOrder.h:600
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.
Definition WorkOrder.h:577
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...
Definition WorkOrder.h:339
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.
Definition WorkOrder.h:628
CorrelationMatrix correlationMatrix()
Returns the CorrleationMatrix for this WorkOrder.
QPointer< QTimer > m_progressBarDeletionTimer
A pointer to the ProgressBar deletion timer.
Definition WorkOrder.h:645
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.
Definition WorkOrder.cpp:39
TargetBodyQsp m_targetBody
A QSharedPointer to the TargetBody (A Target object but encapsulated within a Gui framework.
Definition WorkOrder.h:571
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QSharedPointer< GuiCamera > GuiCameraQsp
GuiCameraQsp Represents a smart pointer to a GuiCamera object.
Definition GuiCamera.h:156
QSharedPointer< TargetBody > TargetBodyQsp
Defines A smart pointer to a TargetBody obj.
Definition TargetBody.h:182
QSharedPointer< FileItem > FileItemQsp
A FileItem smart pointer.
Definition FileItem.h:36