41#include <CPrintDuringExec.h>
56 static int LENGTH_OF_PROGRESS_BAR;
57 static double PERCENTAGE_BIN_SIZE;
59 static std::string generateProgressBar(
unsigned int percentage,
double currentTime)
61 const int progress =
static_cast<int>(std::ceil(percentage / (
double)PERCENTAGE_BIN_SIZE));
62 std::ostringstream ss;
63 ss << std::fixed << std::setprecision(3) <<
"T:" << currentTime <<
" " << std::setw(3) << std::right << percentage <<
"% ";
64 std::string bar(
"[" + std::string(LENGTH_OF_PROGRESS_BAR - 2,
' ') +
"]");
66 unsigned int numberOfSymbols = std::min(
67 std::max(0, progress - 1),
68 LENGTH_OF_PROGRESS_BAR - 2);
70 bar.replace(1, numberOfSymbols, std::string(numberOfSymbols,
'#'));
81 ProgressBar(
double totalTime,
const std::string& initialMessage =
"")
82 : mTotalTime(totalTime)
87 mCout = std::cout.rdbuf();
88 std::cout.rdbuf(mSs.rdbuf());
89 mOutStream.rdbuf(mCout);
90 mOutStream << initialMessage <<
"\n";
91 mLengthOfLastPrintedMessage = initialMessage.size();
92 mOutStream << generateProgressBar(0, 0) <<
"\r" << std::flush;
115 mOutStream << std::string(2,
'\n');
128 throw std::runtime_error(
"Attempted to use progress bar after having terminated it");
133 << std::setw(LENGTH_OF_PROGRESS_BAR + 6)
135 mLengthOfLastPrintedMessage = message.size();
136 const unsigned int percentage =
static_cast<unsigned int>(std::ceil(mCurrentTime / mTotalTime * 100));
138 mOutStream << generateProgressBar(percentage, mCurrentTime) <<
"\r" << std::flush;
165 throw std::runtime_error(
166 "Attempted to use progress bar after having terminated it");
168 mCurrentTime = currentTime;
170 const unsigned int percentage =
static_cast<unsigned int>(std::ceil(mCurrentTime / mTotalTime * 100));
172 if (mSs.str().length() > 0) {
173 printNewMessage(
"Message at time " + std::to_string(currentTime) +
": " + mSs.str());
177 mOutStream << generateProgressBar(percentage, mCurrentTime) <<
"\r" << std::flush;
184 size_t mLengthOfLastPrintedMessage;
185 std::stringstream mSs;
186 std::streambuf* mCout;
187 std::ostream mOutStream;
194 CProgressBar(
const std::string& name, ISimObjectCreator*
const creator);
195 void OdeFcn(
const double t,
const double*
const x,
double*
const xdot,
const bool isMajorTimeStep) { }
196 void PreOdeFcn(
const double T,
const double*
const X, IStateUpdater* updater);
197 void FinalSetup(
const double T,
const double*
const X, ISimObjectCreator*
const creator);
198#ifdef FH_VISUALIZATION
199 virtual void RenderInit(Ogre::Root*
const ogreRoot, ISimObjectCreator*
const creator)
201 virtual void RenderUpdate(
const double T,
const double*
const X) { }
207 CPrintDuringExec* mPrint;
Definition: CProgressBar.h:192
double m_end_time
Definition: CProgressBar.h:205
Definition: CProgressBar.h:54
ProgressBar(double totalTime, const std::string &initialMessage="")
Definition: CProgressBar.h:81
void printNewMessage(const std::string &message)
Definition: CProgressBar.h:125
~ProgressBar()
Definition: CProgressBar.h:98
void setTime(double currentTime)
Definition: CProgressBar.h:162
void endProgressBar()
Definition: CProgressBar.h:112