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