3#include "../../Text/Utf8Sanitizer.h"
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 +
"...");
40 loginfo(
"Parsing layer directory: " + m_name +
" complete");
47 return m_attrListFile.
Parse(directory);
52 return m_componentsFile.Parse(directory);
57 return m_featuresFile.Parse(directory);
62 return m_toolsFile.Parse(directory);
67 return m_componentsFile;
72 return m_featuresFile;
77 return m_attrListFile;
87 std::unique_ptr<Odb::Lib::Protobuf::LayerDirectory> pLayerDirectoryMessage(
new Odb::Lib::Protobuf::LayerDirectory);
88 FillProtobufMessage(*pLayerDirectoryMessage,
true);
89 return pLayerDirectoryMessage;
94 std::unique_ptr<Odb::Lib::Protobuf::LayerDirectory> pLayerDirectoryMessage(
new Odb::Lib::Protobuf::LayerDirectory);
95 FillProtobufMessage(*pLayerDirectoryMessage,
false);
96 return pLayerDirectoryMessage;
99 void Odb::Lib::FileModel::Design::LayerDirectory::FillProtobufMessage(Odb::Lib::Protobuf::LayerDirectory& layerDirectoryMessage,
bool includeFeatureRecords)
const
103 layerDirectoryMessage.mutable_components()->CopyFrom(*m_componentsFile.to_protobuf());
104 if (includeFeatureRecords)
106 layerDirectoryMessage.mutable_featurefile()->CopyFrom(*m_featuresFile.to_protobuf());
110 layerDirectoryMessage.mutable_featurefile()->CopyFrom(*m_featuresFile.to_protobuf_skeleton());
112 layerDirectoryMessage.mutable_attrlistfile()->CopyFrom(*m_attrListFile.to_protobuf());
113 layerDirectoryMessage.mutable_tools()->CopyFrom(*m_toolsFile.to_protobuf());
118 m_name = message.name();
119 m_path = message.path();
120 m_componentsFile.from_protobuf(message.components());
121 m_featuresFile.from_protobuf(message.featurefile());
122 m_attrListFile.from_protobuf(message.attrlistfile());
123 m_toolsFile.from_protobuf(message.tools());
128 auto layerDir = directory / m_name;
129 if (!create_directory(layerDir))
return false;
132 std::ofstream componentsFile(layerDir /
"components");
133 if (!componentsFile.is_open())
return false;
134 if (!m_componentsFile.
Save(componentsFile))
return false;
135 componentsFile.close();
138 std::ofstream featuresFile(layerDir /
"features");
139 if (!featuresFile.is_open())
return false;
140 if (!m_featuresFile.
Save(featuresFile))
return false;
141 featuresFile.close();
144 std::ofstream attrlistFile(layerDir /
"attrlist");
145 if (!attrlistFile.is_open())
return false;
146 if (!m_attrListFile.
Save(attrlistFile))
return false;
147 attrlistFile.close();
151 if (!toolsFile.is_open())
return false;
152 if (!m_toolsFile.
Save(toolsFile))
return false;
bool Parse(std::filesystem::path directory)
bool Save(std::ostream &os) override
bool Save(std::ostream &os) override
bool Save(std::ostream &os) override
LayerDirectory(std::filesystem::path path)
bool ParseAttrListFile(std::filesystem::path directory)
std::string GetName() const
bool Save(const std::filesystem::path &directory) override
bool ParseToolsFile(std::filesystem::path directory)
virtual ~LayerDirectory()
std::unique_ptr< Odb::Lib::Protobuf::LayerDirectory > to_protobuf_skeleton() const
const ComponentsFile & GetComponentsFile() const
const ToolsFile & GetToolsFile() const
void from_protobuf(const Odb::Lib::Protobuf::LayerDirectory &message) override
std::unique_ptr< Odb::Lib::Protobuf::LayerDirectory > to_protobuf() const override
const FeaturesFile & GetFeaturesFile() const
std::filesystem::path GetPath() const
const AttrListFile & GetAttrListFile() const
bool ParseComponentsFile(std::filesystem::path directory)
bool ParseFeaturesFile(std::filesystem::path directory)
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.