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

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Format/STEP.hpp>

Public Member Functions

bool preprocess (const char *path, std::string &output_path)

Static Public Member Functions

static bool isUtf8File (const char *path)
static bool isUtf8 (const std::string str)

Private Types

enum class  EncodedType : unsigned char { UTF8 , GBK , OTHER }

Static Private Member Functions

static bool isGBK (const std::string str)
static int preNum (const unsigned char byte)

Private Attributes

EncodedType m_encode_type = EncodedType::UTF8

Detailed Description

Member Enumeration Documentation

◆ EncodedType

enum class Slic3r::StepPreProcessor::EncodedType : unsigned char
strongprivate
Enumerator
UTF8 
GBK 
OTHER 
65 {
66 UTF8,
67 GBK,
68 OTHER
69 };

Member Function Documentation

◆ isGBK()

bool Slic3r::StepPreProcessor::isGBK ( const std::string str)
staticprivate
162 {
163 size_t i = 0;
164 while (i < str.length()) {
165 // char is signed here, so every byte compares <= 0x7f unless widened first.
166 const unsigned char lead = static_cast<unsigned char>(str[i]);
167 if (lead <= 0x7f) {
168 i++;
169 continue;
170 } else {
171 if (i + 1 >= str.length())
172 return false;
173 const unsigned char trail = static_cast<unsigned char>(str[i + 1]);
174 if (lead >= 0x81 &&
175 lead <= 0xfe &&
176 trail >= 0x40 &&
177 trail <= 0xfe &&
178 trail != 0xf7) {
179 i += 2;
180 continue;
181 }
182 else {
183 return false;
184 }
185 }
186 }
187 return true;
188}

Referenced by preprocess().

Here is the caller graph for this function:

◆ isUtf8()

bool Slic3r::StepPreProcessor::isUtf8 ( const std::string str)
static
137{
138 size_t num = 0;
139 size_t i = 0;
140 while (i < str.length()) {
141 const unsigned char lead = static_cast<unsigned char>(str[i]);
142 if ((lead & 0x80) == 0x00) {
143 i++;
144 // preNum() counts the leading 1 bits, and a multi-byte sequence is 2 to 4
145 // bytes long, so anything outside that range is not a lead byte.
146 } else if ((num = preNum(lead)) >= 2 && num <= 4) {
147 if (i + num > str.length())
148 return false;
149 i++;
150 for (size_t j = 0; j < num - 1; j++) {
151 if ((static_cast<unsigned char>(str[i]) & 0xc0) != 0x80)
152 return false;
153 i++;
154 }
155 } else {
156 return false;
157 }
158 }
159 return true;
160}
static int preNum(const unsigned char byte)
Definition STEP.cpp:190

References preNum().

Referenced by Slic3r::getNamedSolids(), isUtf8File(), and preprocess().

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

◆ isUtf8File()

bool Slic3r::StepPreProcessor::isUtf8File ( const char * path)
static
117{
118 boost::nowide::ifstream infile(path);
119 if (!infile.good()) {
120 throw Slic3r::RuntimeError(_u8L("Load step file failed.\nCannot open file for reading.\n"));
121 return false;
122 }
123
124 std::string temp_line;
125 while (std::getline(infile, temp_line)) {
126 if (!isUtf8(temp_line)) {
127 infile.close();
128 return false;
129 }
130 }
131
132 infile.close();
133 return true;
134}
static bool isUtf8(const std::string str)
Definition STEP.cpp:136
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, and isUtf8().

Referenced by Slic3r::Step::load().

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

◆ preNum()

int Slic3r::StepPreProcessor::preNum ( const unsigned char byte)
staticprivate
190 {
191 unsigned char mask = 0x80;
192 int num = 0;
193 for (int i = 0; i < 8; i++) {
194 if ((byte & mask) == mask) {
195 mask = mask >> 1;
196 num++;
197 } else {
198 break;
199 }
200 }
201 return num;
202}

Referenced by isUtf8().

Here is the caller graph for this function:

◆ preprocess()

bool Slic3r::StepPreProcessor::preprocess ( const char * path,
std::string & output_path )
69{
70 boost::nowide::ifstream infile(path);
71 if (!infile.good()) {
72 throw Slic3r::RuntimeError(_u8L("Load step file failed.\nCannot open file for reading.\n"));
73 return false;
74 }
75
76 boost::filesystem::path temp_path(temporary_dir());
77 std::string temp_step_path = temp_path.string() + "/temp.step";
78 boost::nowide::remove(temp_step_path.c_str());
79 boost::nowide::ofstream temp_file(temp_step_path, std::ios::app);
80 std::string temp_line;
81 while (std::getline(infile, temp_line)) {
83 //BBS: continue to judge whether is other type
84 if (isUtf8(temp_line)) {
85 //BBS: do nothing, but must be checked before checking whether is GBK
86 }
87 //BBS: not utf8, then maybe GBK
88 else if (isGBK(temp_line)) {
90 }
91 //BBS: not UTF8 and not GBK, then maybe some kind of special encoded type which we can't handle
92 // Load the step as UTF and user will see garbage characters in slicer but we have no solution at the moment
93 else {
95 }
96 }
98 //BBS: transform to UTF8 format if is GBK
99 //todo: use gbkToUtf8 function to replace
100 temp_file << decode_path(temp_line.c_str()) << std::endl;
101 else
102 temp_file << temp_line.c_str() << std::endl;
103 }
104 temp_file.close();
105 infile.close();
107 output_path = temp_step_path;
108 } else {
109 boost::nowide::remove(temp_step_path.c_str());
110 output_path = std::string(path);
111 }
112
113 return true;
114}
EncodedType m_encode_type
Definition STEP.hpp:79
static bool isGBK(const std::string str)
Definition STEP.cpp:162
std::string decode_path(const char *src)
Definition utils.cpp:1401
const std::string & temporary_dir()
Definition utils.cpp:308

References _u8L, Slic3r::decode_path(), GBK, isGBK(), isUtf8(), m_encode_type, OTHER, Slic3r::temporary_dir(), and UTF8.

Here is the call graph for this function:

Member Data Documentation

◆ m_encode_type

EncodedType Slic3r::StepPreProcessor::m_encode_type = EncodedType::UTF8
private

Referenced by preprocess().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Format/STEP.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Format/STEP.cpp