OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
ToolsFile.h
1//
2// Created by Jandody on 08/26/2025.
3//
4#pragma once
5
6#include <string>
7#include <map>
8#include <filesystem>
9#include <memory>
10#include <EnumMap.h>
11
12#include "../../odbdesign_export.h"
13#include "../../IProtoBuffable.h"
14#include "toolsfile.pb.h"
15#include "../IStreamSaveable.h"
16
17namespace Odb::Lib::FileModel::Design
18{
19 class ODBDESIGN_EXPORT ToolsFile : public IProtoBuffable<Odb::Lib::Protobuf::ToolsFile>, public IStreamSaveable
20 {
21 public:
22 ToolsFile();
23 ~ToolsFile();
24
25 // ToolsRecord
26 struct ToolsRecord : public IProtoBuffable<Odb::Lib::Protobuf::ToolsFile::ToolsRecord>
27 {
28 enum class Type
29 {
30 Plated,
31 NonPlated,
32 Via,
33 };
34
35 enum class Type2
36 {
37 Standard,
38 PressFit,
39 Photo,
40 Laser,
41 };
42
43 // data members
44 unsigned int toolNum; // reference number of TOOLS in tools file
45 Type type;
46 Type2 type2;
47
48 // Allowed tolerances
49 double minTOL;
50 double maxTOL;
51
52 std::string drillBit;
53 double finishSize;
54 double drillSize;
55
56 inline static const char* RECORD_TOKEN = "TOOLS";
57
58 inline static const char* NUM_KEY = "NUM";
59 inline static const char* TYPE_KEY = "TYPE";
60 inline static const char* TYPE2_KEY = "TYPE2";
61 inline static const char* MIN_TOL_KEY = "MIN_TOL";
62 inline static const char* MAX_TOL_KEY = "MAX_TOL";
63 inline static const char* BIT_KEY = "BIT";
64 inline static const char* FINISH_SIZE_KEY = "FINISH_SIZE";
65 inline static const char* DRILL_SIZE_KEY = "DRILL_SIZE";
66
67 // Inherited via IProtoBuffable
68 std::unique_ptr<Odb::Lib::Protobuf::ToolsFile::ToolsRecord> to_protobuf() const override;
69 void from_protobuf(const Odb::Lib::Protobuf::ToolsFile::ToolsRecord& message) override;
70
71 inline static const Utils::EnumMap<Type> typeMap{
72 {
73 "PLATED",
74 "NON_PLATED",
75 "VIA"
76 }
77 };
78
79 inline static const Utils::EnumMap<Type2> type2Map{
80 {
81 "STANDARD",
82 "PRESS_FIT",
83 "PHOTO",
84 "LASER"
85 }
86 };
87
88 }; // ToolsRecord
89
90 // typedefs
91 typedef std::map<unsigned int, std::shared_ptr<ToolsRecord>> ToolsMap;
92
93 std::string GetUnits() const;
94 double GetThickness() const;
95 std::string GetUserParams() const;
96 const ToolsMap& GetTools() const;
97
98 bool Parse(std::filesystem::path directory);
99 // Inherited via IStreamSaveable
100 bool Save(std::ostream& os) override;
101
102 // Inherited via IProtoBuffable
103 std::unique_ptr<Odb::Lib::Protobuf::ToolsFile> to_protobuf() const override;
104 void from_protobuf(const Odb::Lib::Protobuf::ToolsFile& message) override;
105
106 private:
107 std::filesystem::path m_directory;
108 std::filesystem::path m_path;
109
110 std::string m_units;
111 double m_thickness;
112 std::string m_user_params;
113 ToolsMap m_toolsByNum;
114
115 inline static const auto TOOLS_FILENAMES = { "tools" };
116
117 inline static const char* UNITS_TOKEN = "UNITS";
118 inline static const char* THICKNESS_TOKEN = "THICKNESS";
119 inline static const char* USER_PARAMS_TOKEN = "USER_PARAMS";
120 };
121}
122
123