OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
LayerDirectory.cpp
1#include "LayerDirectory.h"
2#include "Logger.h"
3
4namespace Odb::Lib::FileModel::Design
5{
6 LayerDirectory::LayerDirectory(std::filesystem::path path)
7 : m_path(path)
8 {
9 }
10
11 LayerDirectory::~LayerDirectory()
12 {
13 }
14
15 std::string LayerDirectory::GetName() const
16 {
17 return m_name;
18 }
19
20 std::filesystem::path LayerDirectory::GetPath() const
21 {
22 return m_path;
23 }
24
25 bool LayerDirectory::Parse()
26 {
27 if (!std::filesystem::exists(m_path)) return false;
28 else if (!std::filesystem::is_directory(m_path)) return false;
29
30 m_name = std::filesystem::path(m_path).filename().string();
31
32 loginfo("Parsing layer directory: " + m_name + "...");
33
34 if (!ParseComponentsFile(m_path)) return false;
35 if (!ParseFeaturesFile(m_path)) return false;
36 if (!ParseAttrListFile(m_path)) return false;
37 if (!ParseToolsFile(m_path)) return false;
38
39 loginfo("Parsing layer directory: " + m_name + " complete");
40
41 return true;
42 }
43
44 bool LayerDirectory::ParseAttrListFile(std::filesystem::path directory)
45 {
46 return m_attrListFile.Parse(directory);
47 }
48
49 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseComponentsFile(std::filesystem::path directory)
50 {
51 return m_componentsFile.Parse(directory);
52 }
53
54 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseFeaturesFile(std::filesystem::path directory)
55 {
56 return m_featuresFile.Parse(directory);
57 }
58
59 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseToolsFile(std::filesystem::path directory)
60 {
61 return m_toolFile.Parse(directory);
62 }
63
64 const ComponentsFile& Odb::Lib::FileModel::Design::LayerDirectory::GetComponentsFile() const
65 {
66 return m_componentsFile;
67 }
68
69 const FeaturesFile& LayerDirectory::GetFeaturesFile() const
70 {
71 return m_featuresFile;
72 }
73
74 const AttrListFile& LayerDirectory::GetAttrListFile() const
75 {
76 return m_attrListFile;
77 }
78
79 const ToolsFile& LayerDirectory::GetToolsFile() const
80 {
81 return m_toolFile;
82 }
83
84 std::unique_ptr<Odb::Lib::Protobuf::LayerDirectory> Odb::Lib::FileModel::Design::LayerDirectory::to_protobuf() const
85 {
86 std::unique_ptr<Odb::Lib::Protobuf::LayerDirectory> pLayerDirectoryMessage(new Odb::Lib::Protobuf::LayerDirectory);
87 pLayerDirectoryMessage->set_name(m_name);
88 pLayerDirectoryMessage->set_path(m_path.string());
89 pLayerDirectoryMessage->mutable_components()->CopyFrom(*m_componentsFile.to_protobuf());
90 pLayerDirectoryMessage->mutable_featurefile()->CopyFrom(*m_featuresFile.to_protobuf());
91 pLayerDirectoryMessage->mutable_attrlistfile()->CopyFrom(*m_attrListFile.to_protobuf());
92 pLayerDirectoryMessage->mutable_toolfile()->CopyFrom(*m_toolFile.to_protobuf());
93 return pLayerDirectoryMessage;
94 }
95
96 void Odb::Lib::FileModel::Design::LayerDirectory::from_protobuf(const Odb::Lib::Protobuf::LayerDirectory& message)
97 {
98 m_name = message.name();
99 m_path = message.path();
100 m_componentsFile.from_protobuf(message.components());
101 m_featuresFile.from_protobuf(message.featurefile());
102 m_attrListFile.from_protobuf(message.attrlistfile());
103 m_toolFile.from_protobuf(message.toolfile());
104 }
105
106 bool LayerDirectory::Save(const std::filesystem::path& directory)
107 {
108 auto layerDir = directory / m_name;
109 if (!create_directory(layerDir)) return false;
110
111 //ComponentsFile m_componentsFile;
112 std::ofstream componentsFile(layerDir / "components");
113 if (!componentsFile.is_open()) return false;
114 if (!m_componentsFile.Save(componentsFile)) return false;
115 componentsFile.close();
116
117 //FeaturesFile m_featuresFile;
118 std::ofstream featuresFile(layerDir / "features");
119 if (!featuresFile.is_open()) return false;
120 if (!m_featuresFile.Save(featuresFile)) return false;
121 featuresFile.close();
122
123 //AttrListFile m_attrListFile;
124 std::ofstream attrlistFile(layerDir / "attrlist");
125 if (!attrlistFile.is_open()) return false;
126 if (!m_attrListFile.Save(attrlistFile)) return false;
127 attrlistFile.close();
128
129 //ToolsFile m_toolFile;
130 std::ofstream toolsFile(layerDir / "tools");
131 if (!toolsFile.is_open()) return false;
132 if (!m_toolFile.Save(toolsFile)) return false;
133 toolsFile.close();
134
135 return true;
136 }
137}