OdbDesignLib
OdbDesign ODB++ Parsing Library
 
Loading...
Searching...
No Matches
PinConnection.cpp
1#include "PinConnection.h"
2#include <memory>
3#include "Pin.h"
4#include "Component.h"
5#include <string>
6#include "pinconnection.pb.h"
7#include "../Text/Utf8Sanitizer.h"
8
9
10namespace Odb::Lib::ProductModel
11{
12 //PinConnection::~PinConnection()
13 //{
14 //}
15
16 PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin)
17 : PinConnection(pComponent, pPin, MakeName(*pComponent, *pPin))
18 {
19 }
20
21 PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin, const std::string& name)
22 : m_name(name)
23 , m_pComponent(pComponent)
24 , m_pPin(pPin)
25 {
26 }
27
28 std::string PinConnection::MakeName(const Component& component, const Pin& pin)
29 {
30 //if (pComponent == nullptr || pPin == nullptr) return "Pin::MakeName() FAILED";
31 //return pComponent->GetRefDes() + "-" + pPin->GetName();
32 return component.GetRefDes() + "-" + pin.GetName();
33 }
34
35 std::shared_ptr<Pin> PinConnection::GetPin() const
36 {
37 return m_pPin;
38 }
39
40 std::shared_ptr<Component> PinConnection::GetComponent() const
41 {
42 return m_pComponent;
43 }
44
45 std::unique_ptr<Protobuf::ProductModel::PinConnection> PinConnection::to_protobuf() const
46 {
47 auto pPinConnectionMsg = std::make_unique<Protobuf::ProductModel::PinConnection>();
48 pPinConnectionMsg->set_name(Odb::Lib::Text::ToUtf8(m_name));
49 pPinConnectionMsg->mutable_component()->CopyFrom(*m_pComponent->to_protobuf());
50 pPinConnectionMsg->mutable_pin()->CopyFrom(*m_pPin->to_protobuf());
51 return pPinConnectionMsg;
52 }
53
54 void PinConnection::from_protobuf(const Protobuf::ProductModel::PinConnection& message)
55 {
56 m_name = message.name();
57 m_pComponent = std::make_shared<Component>();
58 m_pComponent->from_protobuf(message.component());
59 m_pPin = std::make_shared<Pin>("", -1);
60 m_pPin->from_protobuf(message.pin());
61 }
62
63} // namespace Odb::Lib::ProductModel