OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
ToolsFile.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <map>
5#include <memory>
6#include <vector>
7#include <filesystem>
8#include "../../odbdesign_export.h"
9#include "../../IProtoBuffable.h"
10#include "toolsfile.pb.h"
11#include "../IStreamSaveable.h"
12
14{
18 class ODBDESIGN_EXPORT ToolsFile : public IProtoBuffable<Odb::Lib::Protobuf::ToolsFile>, public IStreamSaveable
19 {
20 public:
21 ToolsFile();
22
23 struct ToolRecord : public IProtoBuffable<Odb::Lib::Protobuf::ToolsFile::Tool>
24 {
25 enum class Type
26 {
27 Unknown = 0,
28 Plated,
29 NonPlated,
30 Via
31 };
32
33 enum class SubType
34 {
35 Unknown = 0,
36 Standard,
37 PressFit,
38 Photo,
39 Laser
40 };
41
42 // spec: tool number
43 unsigned int num = 0;
44 // tracked for close-brace validation (NUM must be present)
45 bool hasNum = false;
46 // spec: PLATED | NON_PLATED | VIA
47 Type type = Type::Unknown;
48 // spec: legality depends on type; defaults to STANDARD when absent
49 SubType subType = SubType::Standard;
50 // spec: allowed tolerance (mils or microns per UNITS)
51 double minTol = 0.0;
52 double maxTol = 0.0;
53 // spec: drill bit string
54 std::string bit;
55 // spec: required finished drill size; -1 when not set
56 double finishSize = -1.0;
57 // spec: optional drill tool size
58 double drillSize = -1.0;
59
60 // constants
61 constexpr inline static const char* TYPE_PLATED = "PLATED";
62 constexpr inline static const char* TYPE_NON_PLATED = "NON_PLATED";
63 constexpr inline static const char* TYPE_VIA = "VIA";
64 constexpr inline static const char* SUB_TYPE_STANDARD = "STANDARD";
65 constexpr inline static const char* SUB_TYPE_PRESS_FIT = "PRESS_FIT";
66 constexpr inline static const char* SUB_TYPE_PHOTO = "PHOTO";
67 constexpr inline static const char* SUB_TYPE_LASER = "LASER";
68
69 // spec: legal sub-type per type (TYPE2 field); TYPE2 defaults to
70 // STANDARD when absent
71 bool subTypeIsLegal() const;
72
73 // names as they appear in the file grammar (used by Save)
74 static const char* typeName(Type type);
75 static const char* subTypeName(SubType subType);
76
77 // typedefs
78 typedef std::vector<std::shared_ptr<ToolRecord>> Vector;
79 typedef std::map<unsigned int, std::shared_ptr<ToolRecord>> NumMap;
80
81 // Inherited via IProtoBuffable
82 std::unique_ptr<Odb::Lib::Protobuf::ToolsFile::Tool> to_protobuf() const override;
83 void from_protobuf(const Odb::Lib::Protobuf::ToolsFile::Tool& message) override;
84 };
85
86 bool Parse(std::filesystem::path directory);
87 // Inherited via IStreamSaveable
88 bool Save(std::ostream& os) override;
89
90 std::string GetUnits() const;
91 double GetThickness() const;
92 const std::vector<std::string>& GetUserParams() const;
93 const ToolRecord::Vector& GetTools() const;
94 std::filesystem::path GetPath() const;
95
96 // Inherited via IProtoBuffable
97 std::unique_ptr<Odb::Lib::Protobuf::ToolsFile> to_protobuf() const override;
98 void from_protobuf(const Odb::Lib::Protobuf::ToolsFile& message) override;
99
100 constexpr inline static const char* TOOLS_FILENAME = "tools";
101 constexpr inline static const char* TOOLS_ARRAY_TOKEN = "TOOLS";
102 constexpr inline static const char* THICKNESS_KEY = "THICKNESS";
103 constexpr inline static const char* USER_PARAMS_KEY = "USER_PARAMS";
104 constexpr inline static const char* NUM_KEY = "NUM";
105 constexpr inline static const char* TYPE_KEY = "TYPE";
106 constexpr inline static const char* TYPE2_KEY = "TYPE2";
107 constexpr inline static const char* MIN_TOL_KEY = "MIN_TOL";
108 constexpr inline static const char* MAX_TOL_KEY = "MAX_TOL";
109 constexpr inline static const char* BIT_KEY = "BIT";
110 constexpr inline static const char* FINISH_SIZE_KEY = "FINISH_SIZE";
111 constexpr inline static const char* DRILL_SIZE_KEY = "DRILL_SIZE";
112
113 private:
114 std::filesystem::path m_path;
115 std::filesystem::path m_directory;
116 std::string m_units;
117 double m_thickness = 0.0;
118 std::vector<std::string> m_userParams;
119 ToolRecord::Vector m_tools;
120 };
121}
#define ODBDESIGN_EXPORT
std::map< unsigned int, std::shared_ptr< ToolRecord > > NumMap
Definition ToolsFile.h:79
std::vector< std::shared_ptr< ToolRecord > > Vector
Definition ToolsFile.h:78