Ported PlaceholderParser::update_timestamp() to XS
Note that Slic3r version number is now located in libslic3r.h
This commit is contained in:
parent
6135a9fb8b
commit
8b6a8e6307
7 changed files with 64 additions and 30 deletions
|
@ -1,18 +1,50 @@
|
|||
#include "PlaceholderParser.hpp"
|
||||
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
||||
PlaceholderParser::PlaceholderParser()
|
||||
{
|
||||
this->_single["version"] = SLIC3R_VERSION;
|
||||
// TODO: port these methods to C++, then call them here
|
||||
// this->apply_env_variables();
|
||||
// this->update_timestamp();
|
||||
this->update_timestamp();
|
||||
}
|
||||
|
||||
PlaceholderParser::~PlaceholderParser()
|
||||
void
|
||||
PlaceholderParser::update_timestamp()
|
||||
{
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
struct tm* timeinfo = localtime(&rawtime);
|
||||
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << (1900 + timeinfo->tm_year);
|
||||
ss << std::setw(2) << std::setfill('0') << (1 + timeinfo->tm_mon);
|
||||
ss << std::setw(2) << std::setfill('0') << timeinfo->tm_mday;
|
||||
ss << "-";
|
||||
ss << std::setw(2) << std::setfill('0') << timeinfo->tm_hour;
|
||||
ss << std::setw(2) << std::setfill('0') << timeinfo->tm_min;
|
||||
ss << std::setw(2) << std::setfill('0') << timeinfo->tm_sec;
|
||||
this->_single["timestamp"] = ss.str();
|
||||
}
|
||||
this->_single["year"] = this->_int_to_string(1900 + timeinfo->tm_year);
|
||||
this->_single["month"] = this->_int_to_string(1 + timeinfo->tm_mon);
|
||||
this->_single["day"] = this->_int_to_string(timeinfo->tm_mday);
|
||||
this->_single["hour"] = this->_int_to_string(timeinfo->tm_hour);
|
||||
this->_single["minute"] = this->_int_to_string(timeinfo->tm_min);
|
||||
this->_single["second"] = this->_int_to_string(timeinfo->tm_sec);
|
||||
}
|
||||
|
||||
std::string
|
||||
PlaceholderParser::_int_to_string(int value) const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void PlaceholderParser::apply_config(DynamicPrintConfig &config)
|
||||
|
@ -85,6 +117,12 @@ void PlaceholderParser::apply_config(DynamicPrintConfig &config)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
PlaceholderParser::set(const std::string &key, const std::string &value)
|
||||
{
|
||||
this->_single[key] = value;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &stm, const Pointf &pointf)
|
||||
{
|
||||
return stm << pointf.x << "," << pointf.y;
|
||||
|
|
|
@ -17,14 +17,15 @@ class PlaceholderParser
|
|||
std::map<std::string, std::string> _multiple;
|
||||
|
||||
PlaceholderParser();
|
||||
~PlaceholderParser();
|
||||
|
||||
void update_timestamp();
|
||||
void apply_config(DynamicPrintConfig &config);
|
||||
void set(const std::string &key, const std::string &value);
|
||||
|
||||
private:
|
||||
template<class T>
|
||||
void set_multiple_from_vector(
|
||||
const std::string &key, ConfigOptionVector<T> &opt);
|
||||
std::string _int_to_string(int value) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#define SLIC3R_VERSION "1.2.2-dev"
|
||||
|
||||
#define EPSILON 1e-4
|
||||
#define SCALING_FACTOR 0.000001
|
||||
#define PI 3.141592653589793238
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
%name{Slic3r::GCode::PlaceholderParser} class PlaceholderParser {
|
||||
%name{_new} PlaceholderParser();
|
||||
~PlaceholderParser();
|
||||
|
||||
|
||||
void update_timestamp();
|
||||
void apply_config(DynamicPrintConfig *config)
|
||||
%code%{ THIS->apply_config(*config); %};
|
||||
%code%{ THIS->apply_config(*config); %};
|
||||
void set(std::string key, std::string value);
|
||||
|
||||
void _single_set(std::string k, std::string v)
|
||||
%code%{ THIS->_single[k] = v; %};
|
||||
|
|
|
@ -6,3 +6,14 @@
|
|||
%{
|
||||
|
||||
%}
|
||||
|
||||
%package{Slic3r};
|
||||
%{
|
||||
|
||||
SV*
|
||||
VERSION()
|
||||
CODE:
|
||||
RETVAL = newSVpv(SLIC3R_VERSION, 0);
|
||||
OUTPUT: RETVAL
|
||||
|
||||
%}
|
Loading…
Add table
Add a link
Reference in a new issue