OdbDesignLib
OdbDesign ODB++ Parsing Library
FeaturesFile.h
1 #pragma once
2 
3 #include "ContourPolygon.h"
4 #include <filesystem>
5 #include <vector>
6 #include <string>
7 #include "../../enums.h"
8 #include "../../IProtoBuffable.h"
9 #include "../../ProtoBuf/featuresfile.pb.h"
10 #include "SymbolName.h"
11 #include "AttributeLookupTable.h"
12 
13 
14 namespace Odb::Lib::FileModel::Design
15 {
16  class FeaturesFile : public IProtoBuffable<Odb::Lib::Protobuf::FeaturesFile>
17  {
18  public:
19  FeaturesFile();
20  ~FeaturesFile();
21 
22  struct FeatureRecord : public IProtoBuffable<Odb::Lib::Protobuf::FeaturesFile::FeatureRecord>, public AttributeLookupTable
23  {
24  ~FeatureRecord();
25 
26  enum class Type
27  {
28  Arc,
29  Pad,
30  Surface,
31  Barcode,
32  Text,
33  Line
34  };
35 
36  Type type;
37 
38  // Line
39  float xs, ys;
40  float xe, ye;
41 
42  // Pad / Text
43  float x, y;
44  int apt_def_symbol_num;
45  float apt_def_resize_factor;
46 
47  // Arc
48  float xc, yc;
49  bool cw;
50 
51  // Text
52  std::string font;
53  float xsize, ysize;
54  float width_factor;
55  std::string text;
56  int version;
57 
58  //TODO: Barcode
59 
60  // common
61  int sym_num;
62  Polarity polarity;
63  int dcode;
64  unsigned int id;
65 
66  int orient_def;
67  float orient_def_rotation;
68 
69  ContourPolygon::Vector m_contourPolygons;
70 
71  const ContourPolygon::Vector& GetContourPolygons() const;
72 
73  typedef std::vector<std::shared_ptr<FeatureRecord>> Vector;
74 
75  // Inherited via IProtoBuffable
76  std::unique_ptr<Odb::Lib::Protobuf::FeaturesFile::FeatureRecord> to_protobuf() const override;
77  void from_protobuf(const Odb::Lib::Protobuf::FeaturesFile::FeatureRecord& message) override;
78 
79  constexpr inline static const char* LINE_TOKEN = "L";
80  constexpr inline static const char* PAD_TOKEN = "P";
81  constexpr inline static const char* TEXT_TOKEN = "T";
82  constexpr inline static const char* ARC_TOKEN = "A";
83  constexpr inline static const char* BARCODE_TOKEN = "B";
84  constexpr inline static const char* SURFACE_START_TOKEN = "S";
85  constexpr inline static const char* SURFACE_END_TOKEN = "SE";
86  };
87 
88  bool Parse(std::filesystem::path directory, const std::string& alternateFilename = "");
89 
90  std::string GetUnits() const;
91  std::filesystem::path GetPath();
92  std::filesystem::path GetDirectory();
93  int GetNumFeatures() const;
94  unsigned int GetId() const;
95 
96  const SymbolName::StringMap& GetSymbolNamesByName() const;
97  const FeatureRecord::Vector& GetFeatureRecords() const;
98 
99  // Inherited via IProtoBuffable
100  std::unique_ptr<Odb::Lib::Protobuf::FeaturesFile> to_protobuf() const override;
101  void from_protobuf(const Odb::Lib::Protobuf::FeaturesFile& message) override;
102 
103  private:
104  std::string m_units;
105  std::filesystem::path m_path;
106  std::filesystem::path m_directory;
107  int m_numFeatures; // from field in file
108  unsigned int m_id;
109 
110  FeatureRecord::Vector m_featureRecords;
111  SymbolName::StringMap m_symbolNamesByName;
112 
113  std::vector<std::string> m_attributeNames;
114  std::vector<std::string> m_attributeTextValues;
115 
116  constexpr inline static const char* FEATURES_FILENAMES[] =
117  {
118  "features",
119  "features2",
120  "features3"
121  };
122 
123  constexpr inline static const char* UNITS_TOKEN = "UNITS";
124  constexpr inline static const char* ID_TOKEN = "ID";
125  constexpr inline static const char* ATTRIBUTE_NAME_TOKEN = "@";
126  constexpr inline static const char* ATTRIBUTE_VALUE_TOKEN = "&";
127  constexpr inline static const char* SYMBOL_NAME_TOKEN = "$";
128  constexpr inline static const char* COMMENT_TOKEN = "#";
129  constexpr inline static const char* NUM_FEATURES_TOKEN = "F";
130 
131  };
132 }
133