OdbDesignLib
OdbDesign ODB++ Parsing Library
FileArchive.h
1 #pragma once
2 
3 #include "../../odbdesign_export.h"
4 #include <string>
5 #include "StepDirectory.h"
6 #include "EdaDataFile.h"
7 #include <map>
8 #include <vector>
9 #include "MiscInfoFile.h"
10 #include "MatrixFile.h"
11 #include "StandardFontsFile.h"
12 #include <filesystem>
13 #include "../../IProtoBuffable.h"
14 #include "../../ProtoBuf/filearchive.pb.h"
15 #include "SymbolsDirectory.h"
16 #include "AttrListFile.h"
17 
18 
19 namespace Odb::Lib::FileModel::Design
20 {
21  class ODBDESIGN_EXPORT FileArchive : public IProtoBuffable<Odb::Lib::Protobuf::FileArchive>
22  {
23  public:
24  FileArchive(std::string path);
25  ~FileArchive();
26 
27  std::string GetRootDir() const;
28  std::string GetProductName() const;
29  std::string GetFilename() const;
30  std::string GetFilePath() const;
31 
32  const StepDirectory::StringMap& GetStepsByName() const;
33  const SymbolsDirectory::StringMap& GetSymbolsDirectoriesByName() const;
34  const MiscInfoFile& GetMiscInfoFile() const;
35  const MatrixFile& GetMatrixFile() const;
36  const StandardFontsFile& GetStandardFontsFile() const;
37  const AttrListFile& GetMiscAttrListFile() const;
38 
39  std::shared_ptr<StepDirectory> GetStepDirectory(const std::string& stepName = "") const;
40 
41  // TODO: fix these to use pointer return types
42  //const EdaDataFile& GetStepEdaDataFile(std::string stepName) const;
43  //const EdaDataFile& GetFirstStepEdaDataFile() const;
44 
45  bool ParseFileModel();
46 
47  // Inherited via IProtoBuffable
48  std::unique_ptr<Odb::Lib::Protobuf::FileArchive> to_protobuf() const override;
49  void from_protobuf(const Odb::Lib::Protobuf::FileArchive& message) override;
50 
51  typedef std::vector<std::shared_ptr<FileArchive>> Vector;
52  typedef std::map<std::string, std::shared_ptr<FileArchive>> StringMap;
53 
54  private:
55  std::string m_rootDir;
56  std::string m_productName;
57  std::string m_filename;
58  std::string m_filePath;
59 
60  StepDirectory::StringMap m_stepsByName;
61  MiscInfoFile m_miscInfoFile;
62  MatrixFile m_matrixFile;
63  StandardFontsFile m_standardFontsFile;
64  SymbolsDirectory::StringMap m_symbolsDirectoriesByName;
65  AttrListFile m_miscAttrListFile;
66 
67  bool ParseDesignDirectory(const std::filesystem::path& path);
68  bool ParseStepDirectories(const std::filesystem::path& path);
69  bool ParseMiscInfoFile(const std::filesystem::path& path);
70  bool ParseMatrixFile(const std::filesystem::path& path);
71  bool ParseStandardFontsFile(const std::filesystem::path& path);
72  bool ParseSymbolsDirectories(const std::filesystem::path& path);
73  bool ParseMiscAttrListFile(const std::filesystem::path& path);
74 
75  bool ExtractDesignArchive(const std::filesystem::path& path, std::filesystem::path& extractedPath);
76 
77  static std::string findRootDir(const std::filesystem::path& extractedPath);
78  static bool pathContainsTopLevelDesignDirs(const std::filesystem::path& path);
79 
80  static inline constexpr const char* TOPLEVEL_DESIGN_DIR_NAMES[] =
81  {
82  "fonts",
83  "misc",
84  "matrix",
85  "steps"
86  };
87 
88  // REQUIRED (spec pg. 23):
89  //• <product_model_name> / matrix / matrix
90  //• <product_model_name> / misc / info
91  //• <product_model_name> / fonts / standard
92  //• <product_model_name> / steps / <step_name> / stephdr
93  //• <product_model_name> / steps / <step_name> / layers / <layer_name> / features(or features.Z)
94 
95  //• The length of an entity name must not exceed 64 characters.
96  //• An entity name may contain only these characters :
97  // o Lower case letters(a through z).
98  // o Digits(0 through 9).
99  // o Punctuation—dash(-), underscore(_), dot(.) and plus(+).
100  //• Entity names must not start with a dot(.), hyphen(-), or plus(+).
101  // The exception is system attribute names, which start with a dot.Names of user - defined
102  // attributes must not start with a dot.
103  //• Entity names must not end with a dot(.).
104 
105  //The default units of measurement for the product model are as defined in the UNITS directive in
106  //the file misc / info of the product model.If the default is not defined for the product model, the
107  //default is imperial.
108 
109 
110  // Attriubute Lookup Tables spec pg. 30
111  //
112  //Symbol Feature / symbols / <symbol_name> / features
113  // “<symbol_name> / features (Symbol Features)” on page 97
114 
115  //Net / steps / <step_name> / eda / data
116  // “eda / data(EDA Data)” on page 111
117 
118  //Feature / steps / <step_name> / layers / <layer_name> / features
119  // “<layer_name> / features(Graphic Features)” on page 172
120 
121  //Component / steps / <step_name> / layers / //<layer_name> / components
122  // “<layer_name> / components (Components)” on page 155
123 
124  };
125 }