1 #include "LayerDirectory.h"
4 namespace Odb::Lib::FileModel::Design
6 LayerDirectory::LayerDirectory(std::filesystem::path path)
11 LayerDirectory::~LayerDirectory()
15 std::string LayerDirectory::GetName()
const
20 std::filesystem::path LayerDirectory::GetPath()
const
25 bool LayerDirectory::Parse()
27 if (!std::filesystem::exists(m_path))
return false;
28 else if (!std::filesystem::is_directory(m_path))
return false;
30 m_name = std::filesystem::path(m_path).filename().string();
32 loginfo(
"Parsing layer directory: " + m_name +
"...");
34 if (!ParseComponentsFile(m_path))
return false;
35 if (!ParseFeaturesFile(m_path))
return false;
36 if (!ParseAttrListFile(m_path))
return false;
38 loginfo(
"Parsing layer directory: " + m_name +
" complete");
43 bool LayerDirectory::ParseAttrListFile(std::filesystem::path directory)
45 return m_attrListFile.Parse(directory);
48 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseComponentsFile(std::filesystem::path directory)
50 return m_componentsFile.Parse(directory);
53 bool Odb::Lib::FileModel::Design::LayerDirectory::ParseFeaturesFile(std::filesystem::path directory)
55 return m_featuresFile.Parse(directory);
58 const ComponentsFile& Odb::Lib::FileModel::Design::LayerDirectory::GetComponentsFile()
const
60 return m_componentsFile;
63 const FeaturesFile& LayerDirectory::GetFeaturesFile()
const
65 return m_featuresFile;
68 const AttrListFile& LayerDirectory::GetAttrListFile()
const
70 return m_attrListFile;
73 std::unique_ptr<Odb::Lib::Protobuf::LayerDirectory> Odb::Lib::FileModel::Design::LayerDirectory::to_protobuf()
const
75 std::unique_ptr<Odb::Lib::Protobuf::LayerDirectory> pLayerDirectoryMessage(
new Odb::Lib::Protobuf::LayerDirectory);
76 pLayerDirectoryMessage->set_name(m_name);
77 pLayerDirectoryMessage->set_path(m_path.string());
78 pLayerDirectoryMessage->mutable_components()->CopyFrom(*m_componentsFile.to_protobuf());
79 pLayerDirectoryMessage->mutable_featurefile()->CopyFrom(*m_featuresFile.to_protobuf());
80 pLayerDirectoryMessage->mutable_attrlistfile()->CopyFrom(*m_attrListFile.to_protobuf());
81 return pLayerDirectoryMessage;
84 void Odb::Lib::FileModel::Design::LayerDirectory::from_protobuf(
const Odb::Lib::Protobuf::LayerDirectory& message)
86 m_name = message.name();
87 m_path = message.path();
88 m_componentsFile.from_protobuf(message.components());
89 m_featuresFile.from_protobuf(message.featurefile());
90 m_attrListFile.from_protobuf(message.attrlistfile());
93 bool LayerDirectory::Save(
const std::filesystem::path& directory)
95 auto layerDir = directory / m_name;
96 if (!create_directory(layerDir))
return false;
99 std::ofstream componentsFile(layerDir /
"components");
100 if (!componentsFile.is_open())
return false;
101 if (!m_componentsFile.Save(componentsFile))
return false;
102 componentsFile.close();
105 std::ofstream featuresFile(layerDir /
"features");
106 if (!featuresFile.is_open())
return false;
107 if (!m_featuresFile.Save(featuresFile))
return false;
108 featuresFile.close();
111 std::ofstream attrlistFile(layerDir /
"attrlist");
112 if (!attrlistFile.is_open())
return false;
113 if (!m_attrListFile.Save(attrlistFile))
return false;
114 attrlistFile.close();