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