CustusX  22.04-rc2
An IGT application
cxTimedAlgorithm.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxTimedAlgorithm.h"
13 
14 //#include "itkImageFileReader.h"
15 #include "cxTypeConversions.h"
16 //#include "vtkMetaImageWriter.h"
17 #include "cxSettings.h"
18 #include "cxUtilHelpers.h"
19 #include "cxLogger.h"
20 //#include "cxImage.h"
21 
22 namespace cx
23 {
24 
25 TimedBaseAlgorithm::TimedBaseAlgorithm(QString product, int secondsBetweenAnnounce) :
26  QObject(),
27  mProduct(product),
28  mUseDefaultMessages(true)
29 {
30  mTimer = new QTimer(this);
31  connect(mTimer, SIGNAL(timeout()), this, SLOT(timeoutSlot()));
32  mTimer->setInterval(secondsBetweenAnnounce*1000);
33 }
34 
36 {}
37 
39 {
40  mStartTime = QDateTime::currentDateTime();
42  report(QString("Algorithm %1 started.").arg(mProduct));
43  mTimer->start();
44 }
45 
47 {
49  reportSuccess(QString("Algorithm %1 complete [%2s]").arg(mProduct).arg(this->getSecondsPassedAsString()));
50  //mStartTime = QDateTime(); we might need the timing after this call
51  mTimer->stop();
52 }
53 
54 QTime TimedBaseAlgorithm::getTimePassed()
55 {
56  QTime retval = QTime(0, 0);
57  retval = retval.addMSecs(mStartTime.time().msecsTo(QDateTime::currentDateTime().time()));
58  return retval;
59 }
60 
62 {
63  double secs = double(mStartTime.msecsTo(QDateTime::currentDateTime()))/1000;
64  return QString("%1").arg(secs, 0, 'f', 2);
65 }
66 
67 void TimedBaseAlgorithm::timeoutSlot()
68 {
69  report(QString("Still executing %1, [%2] ...").arg(mProduct).arg(this->getTimePassed().toString("m:ss")));
70 }
71 //---------------------------------------------------------------------------------------------------------------------
72 
73 
74 }//namespace cx
75 
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:755
void reportSuccess(QString msg)
Definition: cxLogger.cpp:72
void report(QString msg)
Definition: cxLogger.cpp:69
TimedBaseAlgorithm(QString product, int secondsBetweenAnnounce)
QString getSecondsPassedAsString() const
Namespace for all CustusX production code.