OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::DevUtil Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DeviceCore/DevUtil.h>

Public Member Functions

 DevUtil ()=delete
 DevUtil (const DevUtil &)=delete
DevUtil & operator= (const DevUtil &)=delete

Static Public Member Functions

static int get_flag_bits (std::string str, int start, int count=1)
static int get_flag_bits (int num, int start, int count=1, int base=10)
static uint32_t get_flag_bits_no_border (std::string str, int start_idx, int count=1)
static int get_hex_bits (int num, int pos, int input_num_base=10)
static float string_to_float (const std::string &str_value)
static std::string convertToIp (long long ip)
static bool is_studio_cmd (int seq)
static bool is_cloud_cmd (int seq)

Detailed Description

Constructor & Destructor Documentation

◆ DevUtil() [1/2]

Slic3r::DevUtil::DevUtil ( )
delete

Referenced by DevUtil(), and operator=().

Here is the caller graph for this function:

◆ DevUtil() [2/2]

Slic3r::DevUtil::DevUtil ( const DevUtil & )
delete

References DevUtil().

Here is the call graph for this function:

Member Function Documentation

◆ convertToIp()

std::string Slic3r::DevUtil::convertToIp ( long long ip)
static
167{
168 std::stringstream ss;
169 ss << ((ip >> 0) & 0xFF) << "." << ((ip >> 8) & 0xFF) << "." << ((ip >> 16) & 0xFF) << "." << ((ip >> 24) & 0xFF);
170 return ss.str();
171}

Referenced by Slic3r::MachineObject::parse_json().

Here is the caller graph for this function:

◆ get_flag_bits() [1/2]

int Slic3r::DevUtil::get_flag_bits ( int num,
int start,
int count = 1,
int base = 10 )
static
113{
114 try
115 {
116 unsigned long long mask = (1ULL << count) - 1;
117 unsigned long long value;
118 if (base == 10)
119 {
120 value = static_cast<unsigned long long>(num);
121 }
122 else if (base == 16)
123 {
124 value = static_cast<unsigned long long>(std::stoul(std::to_string(num), nullptr, 16));
125 }
126 else
127 {
128 throw std::invalid_argument("Unsupported base");
129 }
130
131 int flag = (value >> start) & mask;
132 return flag;
133 }
134 catch (const std::exception& e)
135 {
136 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << e.what();
137 }
138 catch (...)
139 {
140 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed";
141 }
142
143 return 0;
144}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246

References count.

◆ get_flag_bits() [2/2]

int Slic3r::DevUtil::get_flag_bits ( std::string str,
int start,
int count = 1 )
static
19{
20 try
21 {
22 unsigned long long decimal_value = std::stoull(str, nullptr, 16);
23 unsigned long long mask = (1ULL << count) - 1;
24 int flag = (decimal_value >> start) & mask;
25 return flag;
26 }
27 catch (const std::exception& e)
28 {
29 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << e.what();
30 }
31 catch (...)
32 {
33 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed";
34 }
35
36 return 0;
37}

References count.

Referenced by get_hex_bits(), Slic3r::DevNozzle::IsAbnormal(), Slic3r::DevFilaSystem::IsAmsSettingUp(), Slic3r::DevNozzle::IsInfoReliable(), Slic3r::DevNozzle::IsNormal(), Slic3r::DevNozzle::IsUnknown(), Slic3r::DevPrintOptionsParser::Parse(), Slic3r::DevAxis::ParseAxis(), Slic3r::DevChamber::ParseChamberV2_0(), Slic3r::DevPrintOptionsParser::ParseDetectionV2_0(), Slic3r::DevPrintOptionsParser::ParseDetectionV2_1(), Slic3r::DevFilaSwitch::ParseFilaSwitchInfo(), Slic3r::DevUpgrade::ParseUpgrade_V1_0(), Slic3r::DevFilaSystemParser::ParseV1_0(), Slic3r::DevNozzleSystemParser::ParseV2_0(), and Slic3r::ExtderSystemParser::ParseV2_0().

Here is the caller graph for this function:

◆ get_flag_bits_no_border()

uint32_t Slic3r::DevUtil::get_flag_bits_no_border ( std::string str,
int start_idx,
int count = 1 )
static
39{
40 if (start_idx < 0 || count <= 0) return 0;
41
42 try {
43 // --- 1) trim ---
44 auto ltrim = [](std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); };
45 auto rtrim = [](std::string &s) { s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); };
46 ltrim(str);
47 rtrim(str);
48
49 // --- 2) remove 0x/0X prefix ---
50 if (str.size() >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) { str.erase(0, 2); }
51
52 // --- 3) keep only hex digits ---
53 std::string hex;
54 hex.reserve(str.size());
55 for (char c : str) {
56 if (std::isxdigit(static_cast<unsigned char>(c))) hex.push_back(c);
57 }
58 if (hex.empty()) return 0;
59
60 // --- 4) use size_t for all index/bit math ---
61 const size_t total_bits = hex.size() * 4ULL;
62
63 const size_t ustart = static_cast<size_t>(start_idx);
64 if (ustart >= total_bits) return 0;
65
66 const int int_bits = std::numeric_limits<uint32_t>::digits; // typically 32
67 const size_t need_bits = static_cast<size_t>(std::min(count, int_bits));
68
69 // [first_bit, last_bit]
70 const size_t first_bit = ustart;
71 const size_t last_bit = std::min(ustart + need_bits, total_bits) - 1ULL;
72 if (last_bit < first_bit) return 0;
73
74 const size_t right_index = hex.size() - 1ULL;
75
76 const size_t first_nibble = first_bit / 4ULL;
77 const size_t last_nibble = last_bit / 4ULL;
78
79 const size_t start_idx = right_index - last_nibble;
80 const size_t end_idx = right_index - first_nibble;
81 if (end_idx < start_idx) return 0;
82
83 const size_t sub_len = end_idx - start_idx + 1ULL;
84 if (end_idx >= hex.size()) return 0;
85
86 const std::string sub_hex = hex.substr(start_idx, sub_len);
87
88 unsigned long long chunk = std::stoull(sub_hex, nullptr, 16);
89
90 const unsigned nibble_offset = static_cast<unsigned>(first_bit % 4ULL);
91 const unsigned long long shifted = (nibble_offset == 0U) ? chunk : (chunk >> nibble_offset);
92
93 uint32_t mask;
94 if (need_bits >= static_cast<size_t>(std::numeric_limits<uint32_t>::digits)) {
95 mask = std::numeric_limits<uint32_t>::max();
96 } else {
97 mask = static_cast<uint32_t>((1ULL << need_bits) - 1ULL);
98 }
99
100 const uint32_t val = static_cast<uint32_t>(shifted & mask);
101 return val;
102 } catch (const std::invalid_argument &) {
103 return 0;
104 } catch (const std::out_of_range &) {
105 return 0;
106 } catch (...) {
107 return 0;
108 }
109}

References count.

◆ get_hex_bits()

int Slic3r::DevUtil::get_hex_bits ( int num,
int pos,
int input_num_base = 10 )
inlinestatic
44{ return get_flag_bits(num, pos * 4, 4, input_num_base);};
static int get_flag_bits(std::string str, int start, int count=1)
Definition DevUtil.cpp:18

References get_flag_bits().

Referenced by Slic3r::DevNozzleSystemParser::ParseV2_0().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_cloud_cmd()

bool Slic3r::DevUtil::is_cloud_cmd ( int seq)
inlinestatic
52{ return seq == CLOUD_SEQ_ID;};
#define CLOUD_SEQ_ID
Definition DevUtil.h:26

References CLOUD_SEQ_ID.

◆ is_studio_cmd()

bool Slic3r::DevUtil::is_studio_cmd ( int seq)
inlinestatic
51{ return seq >= STUDIO_START_SEQ_ID && seq < STUDIO_END_SEQ_ID;};
#define STUDIO_END_SEQ_ID
Definition DevUtil.h:25
#define STUDIO_START_SEQ_ID
Definition DevUtil.h:24

References STUDIO_END_SEQ_ID, and STUDIO_START_SEQ_ID.

◆ operator=()

DevUtil & Slic3r::DevUtil::operator= ( const DevUtil & )
delete

References DevUtil(), and count.

Here is the call graph for this function:

◆ string_to_float()

float Slic3r::DevUtil::string_to_float ( const std::string & str_value)
static
147{
148 float value = 0.0f;
149
150 try
151 {
152 fast_float::from_chars(str_value.c_str(), str_value.c_str() + str_value.size(), value);
153 }
154 catch (const std::exception& e)
155 {
156 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": " << e.what();
157 }
158 catch (...)
159 {
160 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed";
161 }
162
163 return value;
164}

Referenced by Slic3r::DevFilaSystemParser::ParseV1_0(), and Slic3r::DevNozzleSystemParser::ParseV1_0().

Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DeviceCore/DevUtil.h
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DeviceCore/DevUtil.cpp