OdbDesignLib
OdbDesign ODB++ Parsing Library
MatrixFile.h
1 #pragma once
2 
3 //
4 // Created by nmill on 10/13/2023.
5 //
6 
7 #include "../OdbFile.h"
8 #include <filesystem>
9 #include <vector>
10 #include <memory>
11 #include "RgbColor.h"
12 #include "../../enums.h"
13 #include "../../IProtoBuffable.h"
14 #include "../../ProtoBuf/matrixfile.pb.h"
15 
16 
17 namespace Odb::Lib::FileModel::Design
18 {
19  class MatrixFile : public OdbFile, public IProtoBuffable<Odb::Lib::Protobuf::MatrixFile>
20  {
21  public:
22  ~MatrixFile();
23 
24  struct StepRecord : public IProtoBuffable<Odb::Lib::Protobuf::MatrixFile::StepRecord>
25  {
26  unsigned int column;
27  unsigned int id = (unsigned int) -1;
28  std::string name;
29 
30  typedef std::vector<std::shared_ptr<StepRecord>> Vector;
31 
32  inline static const char* RECORD_TOKEN = "STEP";
33 
34  // Inherited via IProtoBuffable
35  std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::StepRecord> to_protobuf() const override;
36  void from_protobuf(const Odb::Lib::Protobuf::MatrixFile::StepRecord& message) override;
37  };
38 
39  struct LayerRecord : public IProtoBuffable<Odb::Lib::Protobuf::MatrixFile::LayerRecord>
40  {
41  enum class Type
42  {
43  Signal,
44  PowerGround,
45  Dielectric,
46  Mixed,
47  SolderMask,
48  SolderPaste,
49  SilkScreen,
50  Drill,
51  Rout,
52  Document,
53  Component,
54  Mask,
55  ConductivePaste,
56  };
57 
58  enum class Context
59  {
60  Board,
61  Misc
62  };
63 
64  enum class DielectricType
65  {
66  None,
67  Prepreg,
68  Core
69  };
70 
71  enum class Form
72  {
73  Rigid,
74  Flex
75  };
76 
77  typedef std::vector<std::shared_ptr<LayerRecord>> Vector;
78 
79  int row;
80  Context context;
81  Type type;
82  std::string name;
83  Polarity polarity;
84  DielectricType dielectricType = DielectricType::None;
85  std::string dielectricName;
86  Form form = Form::Rigid;
87  unsigned int cuTop = (unsigned int) -1;
88  unsigned int cuBottom = (unsigned int) -1;
89  unsigned int ref = (unsigned int) -1;
90  std::string startName;
91  std::string endName;
92  std::string oldName;
93  std::string addType;
94  RgbColor color{"0"};
95  unsigned int id = (unsigned int) -1;
96 
97  inline static const char* RECORD_TOKEN = "LAYER";
98 
99  // Inherited via IProtoBuffable
100  std::unique_ptr<Odb::Lib::Protobuf::MatrixFile::LayerRecord> to_protobuf() const override;
101  void from_protobuf(const Odb::Lib::Protobuf::MatrixFile::LayerRecord& message) override;
102  };
103 
104  const LayerRecord::Vector& GetLayerRecords() const;
105  const StepRecord::Vector& GetStepRecords() const;
106 
107  // Inherited via OdbFile
108  bool Parse(std::filesystem::path path) override;
109 
110  static inline bool attributeValueIsOptional(const std::string& attribute);
111 
112  // Inherited via IProtoBuffable
113  std::unique_ptr<Odb::Lib::Protobuf::MatrixFile> to_protobuf() const override;
114  void from_protobuf(const Odb::Lib::Protobuf::MatrixFile& message) override;
115 
116  private:
117  LayerRecord::Vector m_layerRecords;
118  StepRecord::Vector m_stepRecords;
119 
120  constexpr inline static const char* OPTIONAL_ATTRIBUTES[] =
121  {
122  "OLD_NAME",
123  "old_name",
124  "START_NAME",
125  "start_name",
126  "END_NAME",
127  "end_name",
128  "ADD_TYPE",
129  "ID",
130  "DIELECTRIC_TYPE",
131  "DIELECTRIC_NAME",
132  "FORM",
133  "CU_TOP",
134  "CU_BOTTOM",
135  "REF",
136  "COLOR",
137  };
138  };
139 }