1#include "LayerDirectory.h"
3#include "../../Text/Utf8Sanitizer.h"
5namespace Odb::Lib::FileModel::Design
7 LayerDirectory::LayerDirectory(std::filesystem::path path)
12 LayerDirectory::~LayerDirectory()
16 std::string LayerDirectory::GetName()
const
21 std::filesystem::path LayerDirectory::GetPath()
const
26 bool LayerDirectory::Parse()
28 if (!std::filesystem::exists(m_path))
return false;
29 else if (!std::filesystem::is_directory(m_path))
return false;
31 m_name = std::filesystem::path(m_path).filename().string();
33 loginfo(
"Parsing layer directory: " + m_name +
"...");
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;
40 loginfo(
"Parsing layer directory: " + m_name +
" complete");
45 bool LayerDirectory::ParseAttrListFile(std::filesystem::path directory)
47 return m_attrListFile.Parse(directory);
50 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseComponentsFile(std::filesystem::path directory)
52 return m_componentsFile.Parse(directory);
55 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseFeaturesFile(std::filesystem::path directory)
57 return m_featuresFile.Parse(directory);
60 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseToolsFile(std::filesystem::path directory)
62 return m_toolFile.Parse(directory);
65 const ComponentsFile& Odb::Lib::FileModel::Design::LayerDirectory::GetComponentsFile()
const
67 return m_componentsFile;
70 const FeaturesFile& LayerDirectory::GetFeaturesFile()
const
72 return m_featuresFile;
75 const AttrListFile& LayerDirectory::GetAttrListFile()
const
77 return m_attrListFile;
80 const ToolsFile& LayerDirectory::GetToolsFile()
const
85 std::unique_ptr<Odb::Lib::Protobuf::LayerDirectory> Odb::Lib::FileModel::Design::LayerDirectory::to_protobuf()
const
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;
97 void Odb::Lib::FileModel::Design::LayerDirectory::from_protobuf(
const Odb::Lib::Protobuf::LayerDirectory& message)
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());
107 bool LayerDirectory::Save(
const std::filesystem::path& directory)
109 auto layerDir = directory / m_name;
110 if (!create_directory(layerDir))
return false;
113 std::ofstream componentsFile(layerDir /
"components");
114 if (!componentsFile.is_open())
return false;
115 if (!m_componentsFile.Save(componentsFile))
return false;
116 componentsFile.close();
119 std::ofstream featuresFile(layerDir /
"features");
120 if (!featuresFile.is_open())
return false;
121 if (!m_featuresFile.Save(featuresFile))
return false;
122 featuresFile.close();
125 std::ofstream attrlistFile(layerDir /
"attrlist");
126 if (!attrlistFile.is_open())
return false;
127 if (!m_attrListFile.Save(attrlistFile))
return false;
128 attrlistFile.close();
131 std::ofstream toolsFile(layerDir /
"tools");
132 if (!toolsFile.is_open())
return false;
133 if (!m_toolFile.Save(toolsFile))
return false;