ENH: fix the error time in gcode viewer

As title

Signed-off-by: salt.wei <salt.wei@bambulab.com>
Change-Id: I9322b119b68055baea0e6f63d179a0addf02307e
This commit is contained in:
salt.wei 2022-11-13 12:08:16 +08:00 committed by Lane.Wei
parent 65f2a063b6
commit f3c7953bdc
2 changed files with 12 additions and 7 deletions

View file

@ -457,7 +457,9 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename, st
//sprintf(buf, "; estimated printing time (%s mode) = %s\n", //sprintf(buf, "; estimated printing time (%s mode) = %s\n",
// (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent", // (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent",
// get_time_dhms(machine.time).c_str()); // get_time_dhms(machine.time).c_str());
sprintf(buf, "; total estimated time: %s\n", get_time_dhms(machine.time).c_str()); sprintf(buf, "; model printing time: %s\n; total estimated time: %s\n",
get_time_dhms(machine.time - machine.roles_time[ExtrusionRole::erCustom]).c_str(),
get_time_dhms(machine.time).c_str());
ret += buf; ret += buf;
} }
} }

View file

@ -346,17 +346,20 @@ inline std::string short_time(const std::string &time)
int days = 0; int days = 0;
int hours = 0; int hours = 0;
int minutes = 0; int minutes = 0;
float seconds = 0; int seconds = 0;
float f_seconds = 0.0;
if (time.find('d') != std::string::npos) if (time.find('d') != std::string::npos)
::sscanf(time.c_str(), "%dd %dh %dm %ds", &days, &hours, &minutes, &seconds); ::sscanf(time.c_str(), "%dd %dh %dm %ds", &days, &hours, &minutes, &seconds);
else if (time.find('h') != std::string::npos) else if (time.find('h') != std::string::npos)
::sscanf(time.c_str(), "%dh %dm %ds", &hours, &minutes, &seconds); ::sscanf(time.c_str(), "%dh %dm %ds", &hours, &minutes, &seconds);
else if (time.find('m') != std::string::npos) else if (time.find('m') != std::string::npos)
::sscanf(time.c_str(), "%dm %ds", &minutes, &seconds); ::sscanf(time.c_str(), "%dm %ds", &minutes, &seconds);
else if (time.find('s') != std::string::npos) else if (time.find('s') != std::string::npos) {
::sscanf(time.c_str(), "%fs", &seconds); ::sscanf(time.c_str(), "%fs", &f_seconds);
seconds = int(f_seconds);
}
// Round to full minutes. // Round to full minutes.
if (days + hours + minutes > 0 && seconds >= 30) { if (days + hours > 0 && seconds >= 30) {
if (++minutes == 60) { if (++minutes == 60) {
minutes = 0; minutes = 0;
if (++hours == 24) { if (++hours == 24) {
@ -373,9 +376,9 @@ inline std::string short_time(const std::string &time)
::sprintf(buffer, "%dh%dm", hours, minutes); ::sprintf(buffer, "%dh%dm", hours, minutes);
else if (minutes > 0) else if (minutes > 0)
::sprintf(buffer, "%dm%ds", minutes, (int)seconds); ::sprintf(buffer, "%dm%ds", minutes, (int)seconds);
else if (seconds > 1) else if (seconds >= 1)
::sprintf(buffer, "%ds", (int)seconds); ::sprintf(buffer, "%ds", (int)seconds);
else if (seconds > 0) else if (f_seconds > 0 && f_seconds < 1)
::sprintf(buffer, "<1s"); ::sprintf(buffer, "<1s");
else if (seconds == 0) else if (seconds == 0)
::sprintf(buffer, "0s"); ::sprintf(buffer, "0s");