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