1#include "PinConnection.h"
6#include "pinconnection.pb.h"
7#include "../Text/Utf8Sanitizer.h"
10namespace Odb::Lib::ProductModel
16 PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin)
17 : PinConnection(pComponent, pPin, MakeName(*pComponent, *pPin))
21 PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin,
const std::string& name)
23 , m_pComponent(pComponent)
28 std::string PinConnection::MakeName(
const Component& component,
const Pin& pin)
32 return component.GetRefDes() +
"-" + pin.GetName();
35 std::shared_ptr<Pin> PinConnection::GetPin()
const
40 std::shared_ptr<Component> PinConnection::GetComponent()
const
45 std::unique_ptr<Protobuf::ProductModel::PinConnection> PinConnection::to_protobuf()
const
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;
54 void PinConnection::from_protobuf(
const Protobuf::ProductModel::PinConnection& message)
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());