OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
Component.cpp
Go to the documentation of this file.
1#include "Component.h"
2#include "component.pb.h"
3#include "enums.pb.h"
4#include <string>
5#include <memory>
6#include "../enums.h"
7#include "Part.h"
8#include "Package.h"
9#include "../Text/Utf8Sanitizer.h"
10
11
13{
15 : m_refDes("")
16 , m_partName("")
17 , m_pPackage(nullptr)
18 , m_index(static_cast<unsigned>(-1))
19 , m_side(BoardSide::BsNone)
20 , m_pPart(nullptr)
21 {
22 }
23
24 Component::Component(const std::string& refDes, const std::string& partName, std::shared_ptr<Package> pPackage, unsigned int index, BoardSide side, std::shared_ptr<Part> pPart, std::optional<unsigned int> id)
25 : m_refDes(refDes)
26 , m_partName(partName)
27 , m_pPackage(pPackage)
28 , m_index(index)
29 , m_side(side)
30 , m_pPart(pPart)
31 , m_id(std::move(id))
32 {
33 }
34
38
39 std::string Component::GetRefDes() const
40 {
41 return m_refDes;
42 }
43
44 std::string Component::GetPartName() const
45 {
46 return m_partName;
47 }
48
49 std::shared_ptr<Package> Component::GetPackage() const
50 {
51 return m_pPackage;
52 }
53
54 unsigned int Component::GetIndex() const
55 {
56 return m_index;
57 }
58
60 {
61 return m_side;
62 }
63
64 std::shared_ptr<Part> Component::GetPart() const
65 {
66 return m_pPart;
67 }
68
69 std::optional<unsigned int> Component::GetId() const
70 {
71 return m_id;
72 }
73
74 std::unique_ptr<Odb::Lib::Protobuf::ProductModel::Component> Component::to_protobuf() const
75 {
76 auto pComponentMsg = std::make_unique<Odb::Lib::Protobuf::ProductModel::Component>();
77 pComponentMsg->set_refdes(Odb::Lib::Text::ToUtf8(m_refDes));
78 pComponentMsg->set_partname(Odb::Lib::Text::ToUtf8(m_partName));
79 pComponentMsg->set_index(m_index);
80 pComponentMsg->set_side(static_cast<Odb::Lib::Protobuf::BoardSide>(m_side));
81 pComponentMsg->mutable_package()->CopyFrom(*m_pPackage->to_protobuf());
82 pComponentMsg->mutable_part()->CopyFrom(*m_pPart->to_protobuf());
83 if (m_id.has_value())
84 {
85 pComponentMsg->set_id(*m_id);
86 }
87 return pComponentMsg;
88 }
89
90 void Component::from_protobuf(const Odb::Lib::Protobuf::ProductModel::Component& message)
91 {
92 m_refDes = message.refdes();
93 m_partName = message.partname();
94 m_index = message.index();
95 m_side = static_cast<BoardSide>(message.side());
96 m_id = message.has_id() ? std::optional<unsigned int>(message.id()) : std::nullopt;
97 m_pPackage = std::make_shared<Package>("", -1);
98 m_pPackage->from_protobuf(message.package());
99 m_pPart = std::make_shared<Part>("");
100 m_pPart->from_protobuf(message.part());
101 }
102
103 //Component* Component::MakeEmpty()
104 //{
105 // return new Component();
106 //}
107
108} // namespace Odb::Lib::ProductModel
std::string GetPartName() const
Definition Component.cpp:44
std::shared_ptr< Part > GetPart() const
Definition Component.cpp:64
std::string GetRefDes() const
Definition Component.cpp:39
void from_protobuf(const Odb::Lib::Protobuf::ProductModel::Component &message) override
Definition Component.cpp:90
std::shared_ptr< Package > GetPackage() const
Definition Component.cpp:49
std::unique_ptr< Odb::Lib::Protobuf::ProductModel::Component > to_protobuf() const override
Definition Component.cpp:74
std::optional< unsigned int > GetId() const
Definition Component.cpp:69
unsigned int GetIndex() const
Definition Component.cpp:54
std::string ToUtf8(std::string_view input)
Converts input to valid UTF-8.
BoardSide
Definition enums.h:6