158 std::ifstream toolsFile;
164 m_directory = directory;
166 loginfo(
"checking for extraction...");
169 if (std::filesystem::exists(toolsFilePath) && std::filesystem::is_regular_file(toolsFilePath))
171 loginfo(
"found tools file: [" + toolsFilePath.string() +
"]");
174 m_path = toolsFilePath;
176 if (!std::filesystem::exists(m_path))
180 logwarn(
"tools file does not exist: [" + m_directory.string() +
"]");
183 else if (!std::filesystem::is_regular_file(m_path))
185 auto message =
"tools is not a file: [" + m_path.string() +
"]";
189 toolsFile.open(m_path.string(), std::ios::in);
190 if (!toolsFile.is_open())
192 auto message =
"unable to open tools file: [" + m_path.string() +
"]";
196 auto parsingRecord =
false;
197 std::shared_ptr<ToolRecord> pCurrentRecord;
199 while (std::getline(toolsFile, line))
204 if (line.empty())
continue;
207 std::stringstream lineStream(line);
220 auto afterToken = line.substr(std::char_traits<char>::length(
TOOLS_ARRAY_TOKEN));
226 pCurrentRecord = std::make_shared<ToolRecord>();
227 parsingRecord =
true;
233 if (!std::getline(lineStream, key,
'='))
243 std::getline(lineStream, value);
251 std::getline(lineStream, value);
253 m_thickness = value.empty() ? 0.0 : parseDouble(m_path, line, lineNumber, key, value);
258 std::getline(lineStream, value);
262 m_userParams.push_back(value);
279 else if (!pCurrentRecord->hasNum)
285 else if (!pCurrentRecord->subTypeIsLegal())
290 m_tools.push_back(pCurrentRecord);
291 pCurrentRecord =
nullptr;
292 parsingRecord =
false;
297 if (!std::getline(lineStream, key,
'='))
304 if (line.find(
'=') == std::string::npos)
311 std::getline(lineStream, value);
316 pCurrentRecord->num = parseUnsigned(m_path, line, lineNumber, key, value);
317 pCurrentRecord->hasNum =
true;
336 pCurrentRecord->minTol = value.empty() ? 0.0 : parseDouble(m_path, line, lineNumber, key, value);
340 pCurrentRecord->maxTol = value.empty() ? 0.0 : parseDouble(m_path, line, lineNumber, key, value);
344 pCurrentRecord->bit = value;
349 pCurrentRecord->finishSize = value.empty() ? -1.0 : parseDouble(m_path, line, lineNumber, key, value);
353 pCurrentRecord->drillSize = value.empty() ? -1.0 : parseDouble(m_path, line, lineNumber, key, value);
371 auto m = pe.
toString(
"Parse Error:");
376 catch (std::exception& e)
394 os <<
THICKNESS_KEY <<
"=" << format_double(m_thickness) << std::endl;
395 for (
const auto& userParam : m_userParams)
400 for (
const auto& pTool : m_tools)
413 os <<
'\t' <<
NUM_KEY <<
"=" << pTool->num << std::endl;
416 os <<
'\t' <<
MIN_TOL_KEY <<
"=" << format_double(pTool->minTol) << std::endl;
417 os <<
'\t' <<
MAX_TOL_KEY <<
"=" << format_double(pTool->maxTol) << std::endl;
418 os <<
'\t' <<
BIT_KEY <<
"=" << pTool->bit << std::endl;
419 os <<
'\t' <<
FINISH_SIZE_KEY <<
"=" << format_double(pTool->finishSize) << std::endl;
420 os <<
'\t' <<
DRILL_SIZE_KEY <<
"=" << format_double(pTool->drillSize) << std::endl;
449 m_directory = message.directory();
450 m_path = message.path();
451 m_units = message.units();
452 m_thickness = message.thickness();
453 for (
const auto& userParam : message.userparams())
455 m_userParams.push_back(userParam);
457 for (
const auto& tool : message.tools())
459 auto pTool = std::make_shared<ToolRecord>();
460 pTool->from_protobuf(tool);
461 m_tools.push_back(pTool);
467 auto message = std::make_unique<Odb::Lib::Protobuf::ToolsFile::Tool>();
469 message->set_num(num);
470 message->set_type(
static_cast<Odb::Lib::Protobuf::ToolsFile::ToolType
>(type));
471 message->set_subtype(
static_cast<Odb::Lib::Protobuf::ToolsFile::ToolSubType
>(subType));
472 message->set_mintol(minTol);
473 message->set_maxtol(maxTol);
475 message->set_finishsize(finishSize);
476 message->set_drillsize(drillSize);
487 hasNum = message.has_num();
492 const auto typeValue = message.type();
493 type = Protobuf::ToolsFile::ToolType_IsValid(typeValue)
494 ?
static_cast<Type>(typeValue)
498 if (!message.has_subtype())
500 subType = SubType::Standard;
504 const auto subTypeValue = message.subtype();
505 subType = Protobuf::ToolsFile::ToolSubType_IsValid(subTypeValue)
506 ?
static_cast<SubType>(subTypeValue)
509 minTol = message.mintol();
510 maxTol = message.maxtol();
513 finishSize = message.has_finishsize() ? message.finishsize() : -1.0;
514 drillSize = message.has_drillsize() ? message.drillsize() : -1.0;
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.