OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
FileArchive.h
Go to the documentation of this file.
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 "filearchive.pb.h"
14#include "SymbolsDirectory.h"
15#include "AttrListFile.h"
16#include "../ISaveable.h"
17#include <memory>
18
19
21{
22 class ODBDESIGN_EXPORT FileArchive : public IProtoBuffable<Odb::Lib::Protobuf::FileArchive>, public ISaveable
23 {
24 public:
26 explicit FileArchive(const std::string& path);
27 ~FileArchive() override;
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 // M6 streaming: same message minus the stepsByName map (delivered via
55 // StepSkeleton chunks). All bounded fields are produced by the
56 // identical code path, so skeleton + re-inserted steps serializes to
57 // the exact to_protobuf() bytes.
58 std::unique_ptr<Odb::Lib::Protobuf::FileArchive> to_protobuf_skeleton() const;
59 void from_protobuf(const Odb::Lib::Protobuf::FileArchive& message) override;
60
61 typedef std::vector<std::shared_ptr<FileArchive>> Vector;
62 typedef std::map<std::string, std::shared_ptr<FileArchive>> StringMap;
63
64 private:
65 std::string m_rootDir;
66 std::string m_productName;
67 std::string m_filename;
68 std::string m_filePath;
69
70 MiscInfoFile m_miscInfoFile;
71 MatrixFile m_matrixFile;
72 StandardFontsFile m_standardFontsFile;
73 AttrListFile m_miscAttrListFile;
74
75 StepDirectory::StringMap m_stepsByName;
76 SymbolsDirectory::StringMap m_symbolsDirectoriesByName;
77
78 bool ParseDesignDirectory(const std::filesystem::path& path);
79 bool ParseStepDirectories(const std::filesystem::path& path);
80 bool ParseMiscInfoFile(const std::filesystem::path& path);
81 bool ParseMatrixFile(const std::filesystem::path& path);
82 bool ParseStandardFontsFile(const std::filesystem::path& path);
83 bool ParseSymbolsDirectories(const std::filesystem::path& path);
84 bool ParseMiscAttrListFile(const std::filesystem::path& path);
85
86 bool Save(const std::filesystem::path& directory) override;
87
88 // Shared body of to_protobuf() / to_protobuf_skeleton(); only the
89 // stepsByName map differs, keeping the skeleton byte-compatible with
90 // the full serialization.
91 void FillProtobufMessage(Odb::Lib::Protobuf::FileArchive& fileArchiveMessage, bool includeSteps) const;
92
93 bool ExtractDesignArchive(const std::filesystem::path& path, std::filesystem::path& extractedPath);
94
95 static std::string findRootDir(const std::filesystem::path& extractedPath);
96 static bool pathContainsTopLevelDesignDirs(const std::filesystem::path& path);
97
98 static inline constexpr const char* TOPLEVEL_DESIGN_DIR_NAMES[] =
99 {
100 "fonts",
101 "misc",
102 "matrix",
103 "steps"
104 };
105
106 // REQUIRED (spec pg. 23):
107 //� <product_model_name> / matrix / matrix
108 //� <product_model_name> / misc / info
109 //� <product_model_name> / fonts / standard
110 //� <product_model_name> / steps / <step_name> / stephdr
111 //� <product_model_name> / steps / <step_name> / layers / <layer_name> / features(or features.Z)
112
113 //� The length of an entity name must not exceed 64 characters.
114 //� An entity name may contain only these characters :
115 // o Lower case letters(a through z).
116 // o Digits(0 through 9).
117 // o Punctuation�dash(-), underscore(_), dot(.) and plus(+).
118 //� Entity names must not start with a dot(.), hyphen(-), or plus(+).
119 // The exception is system attribute names, which start with a dot.Names of user - defined
120 // attributes must not start with a dot.
121 //� Entity names must not end with a dot(.).
122
123 //The default units of measurement for the product model are as defined in the UNITS directive in
124 //the file misc / info of the product model.If the default is not defined for the product model, the
125 //default is imperial.
126
127
128 // Attriubute Lookup Tables spec pg. 30
129 //
130 //Symbol Feature / symbols / <symbol_name> / features
131 // �<symbol_name> / features (Symbol Features)� on page 97
132
133 //Net / steps / <step_name> / eda / data
134 // �eda / data(EDA Data)� on page 111
135
136 //Feature / steps / <step_name> / layers / <layer_name> / features
137 // �<layer_name> / features(Graphic Features)� on page 172
138
139 //Component / steps / <step_name> / layers / //<layer_name> / components
140 // �<layer_name> / components (Components)� on page 155
141
142 };
143}
144
bool SaveFileModel(const std::filesystem::path &directory, const std::string &archiveName)
std::map< std::string, std::shared_ptr< FileArchive > > StringMap
Definition FileArchive.h:62
bool SaveFileModel(const std::filesystem::path &directory)
std::vector< std::shared_ptr< FileArchive > > Vector
Definition FileArchive.h:61
std::map< std::string, std::shared_ptr< StepDirectory > > StringMap
std::map< std::string, std::shared_ptr< SymbolsDirectory > > StringMap
#define ODBDESIGN_EXPORT