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