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