Line data Source code
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 :
10 : namespace Odb::Lib::ProductModel
11 : {
12 : //PinConnection::~PinConnection()
13 : //{
14 : //}
15 :
16 157214 : PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin, unsigned int subnetNumber)
17 157214 : : PinConnection(pComponent, pPin, MakeName(*pComponent, *pPin), subnetNumber)
18 : {
19 157214 : }
20 :
21 173352 : PinConnection::PinConnection(std::shared_ptr<Component> pComponent, std::shared_ptr<Pin> pPin, const std::string& name, unsigned int subnetNumber)
22 173352 : : m_name(name)
23 173352 : , m_pComponent(pComponent)
24 173352 : , m_pPin(pPin)
25 173352 : , m_subnetNumber(subnetNumber)
26 : {
27 173352 : }
28 :
29 157214 : std::string PinConnection::MakeName(const Component& component, const Pin& pin)
30 : {
31 : //if (pComponent == nullptr || pPin == nullptr) return "Pin::MakeName() FAILED";
32 : //return pComponent->GetRefDes() + "-" + pPin->GetName();
33 157214 : return component.GetRefDes() + "-" + pin.GetName();
34 : }
35 :
36 232349 : std::shared_ptr<Pin> PinConnection::GetPin() const
37 : {
38 232349 : return m_pPin;
39 : }
40 :
41 232349 : std::shared_ptr<Component> PinConnection::GetComponent() const
42 : {
43 232349 : return m_pComponent;
44 : }
45 :
46 232349 : unsigned int PinConnection::GetSubnetNumber() const
47 : {
48 232349 : return m_subnetNumber;
49 : }
50 :
51 60386 : std::unique_ptr<Protobuf::ProductModel::PinConnection> PinConnection::to_protobuf() const
52 : {
53 60386 : auto pPinConnectionMsg = std::make_unique<Protobuf::ProductModel::PinConnection>();
54 120772 : pPinConnectionMsg->set_name(Odb::Lib::Text::ToUtf8(m_name));
55 60386 : pPinConnectionMsg->mutable_component()->CopyFrom(*m_pComponent->to_protobuf());
56 60386 : pPinConnectionMsg->mutable_pin()->CopyFrom(*m_pPin->to_protobuf());
57 60386 : return pPinConnectionMsg;
58 0 : }
59 :
60 16138 : void PinConnection::from_protobuf(const Protobuf::ProductModel::PinConnection& message)
61 : {
62 16138 : m_name = message.name();
63 16138 : m_pComponent = std::make_shared<Component>();
64 16138 : m_pComponent->from_protobuf(message.component());
65 16138 : m_pPin = std::make_shared<Pin>("", -1);
66 16138 : m_pPin->from_protobuf(message.pin());
67 16138 : }
68 :
69 : } // namespace Odb::Lib::ProductModel
|