OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
Design.h
Go to the documentation of this file.
1#pragma once
2
3#include "../odbdesign_export.h"
4#include <string>
5#include <memory>
6#include <cstdint>
7#include "Net.h"
8#include "Component.h"
9#include "Package.h"
10#include "Part.h"
11#include "design.pb.h"
12#include "../IProtoBuffable.h"
13#include <map>
14#include <vector>
15#include "../FileModel/Design/StepDirectory.h"
16#include "../FileModel/Design/EdaDataFile.h"
17#include "../FileModel/Design/ComponentsFile.h"
18#include "../FileModel/Design/FileArchive.h"
19
20
22{
23 class ODBDESIGN_EXPORT Design : public IProtoBuffable<Protobuf::ProductModel::Design>
24 {
25 public:
26 Design();
27 ~Design();
28
29 const std::string& GetName() const;
30 const std::string& GetProductModel() const;
31
32 const Net::Vector& GetNets() const;
33 const Net::StringMap GetNetsByName() const;
34 std::shared_ptr<Net> GetNet(const std::string& name) const;
35
36 const Package::Vector& GetPackages() const;
37 const Package::StringMap& GetPackagesByName() const;
38
39 const Component::Vector& GetComponents() const;
40 const Component::StringMap& GetComponentsByName() const;
41 std::shared_ptr<Component> GetComponent(const std::string& refDes) const;
42
43 const Part::Vector& GetParts() const;
44 const Part::StringMap& GetPartsByName() const;
45
46 std::shared_ptr<Net> GetNoneNet() const;
47
48 bool Build(std::string path);
49 bool Build(std::shared_ptr<FileModel::Design::FileArchive> pFileModel);
50
51 std::shared_ptr<FileModel::Design::FileArchive> GetFileModel() const;
52 // Nulls the file model ON THIS INSTANCE. Only ever call this on a
53 // privately-owned Design (a copy made for serving a clipped view) —
54 // never on a cache-resident shared instance: the cached Design must
55 // keep its file model for the gRPC GetDesign path and for response
56 // pre-serialization (see DesignCache.h, M1.4).
57 void ClipFileModel();
58
59 // Inherited via IProtoBuffable
60 //
61 // The no-arg override produces the FULL wire flavor (normalized lists
62 // included) because REST (to_json), to_pbstring, to_stream, and the
63 // round-trip serialization tests all route through it and depend on the
64 // complete payload. The GetDesign gRPC response is served by the
65 // parameterized overload below: clients get the pruned flavor unless they
66 // set GetDesignRequest.include_normalized_lists (the normalized
67 // nets/components/packages/parts + ByName maps duplicate fileModel data
68 // and dominate the gRPC payload).
69 std::unique_ptr<Protobuf::ProductModel::Design> to_protobuf() const override;
70 std::unique_ptr<Protobuf::ProductModel::Design> to_protobuf(bool includeNormalizedLists) const;
71 void from_protobuf(const Protobuf::ProductModel::Design& message) override;
72
73 // ---- M6 streaming support ----
74
75 // Shared join state of the derived Connectivity view, computed once
76 // and consumed by the FillConnectivity* section fillers below. Public
77 // because the chunked GetDesignStream path builds the same sections
78 // batch-by-batch and must emit byte-identical entries from the SAME
79 // code (see FillConnectivityMessage).
81 {
82 struct Edge
83 {
84 unsigned int net;
85 unsigned int subnet;
86 };
87 std::map<std::string, std::map<unsigned int, Edge>> edgesByRefDes;
88 std::map<unsigned int, std::map<std::string, std::vector<unsigned int>>> membersByNet;
89 unsigned int noneNetOrdinal = 0;
90 bool hasNoneNet = false;
91
92 using MembersByNetConstIt = std::map<unsigned int, std::map<std::string, std::vector<unsigned int>>>::const_iterator;
93 };
94
95 // Builds the resolved-edge join state (identical to the local state
96 // FillConnectivityMessage computes) plus the $NONE$ net ordinal.
97 ConnectivityIndex BuildConnectivityIndex() const;
98
99 // Section fillers: each appends ONE repeated section of the
100 // Connectivity message in the same order FillConnectivityMessage
101 // emits it. A caller may pass any (fresh, batch-sized) Connectivity
102 // message; entries appended by these fillers are byte-identical to
103 // the monolithic sections.
104 void FillConnectivityNetEntries(Protobuf::ProductModel::Connectivity& connectivityMsg) const;
105 void FillConnectivityPackagePins(Protobuf::ProductModel::Connectivity& connectivityMsg) const;
106 void FillConnectivityPlacedComponents(const ConnectivityIndex& index, Protobuf::ProductModel::Connectivity& connectivityMsg) const;
107 void FillConnectivityNetMembers(const ConnectivityIndex& index, Protobuf::ProductModel::Connectivity& connectivityMsg) const;
108
109 // Single-entry emitters backing the section fillers above — the
110 // granularity the chunked GetDesignStream path needs (one entry per
111 // call, batched by the caller). AddConnectivityNetMemberEntry takes
112 // an iterator into index.membersByNet.
113 void AddConnectivityNetEntry(std::size_t netIndex, Protobuf::ProductModel::Connectivity& connectivityMsg) const;
114 void AddConnectivityPackagePinEntry(std::size_t packageIndex, Protobuf::ProductModel::Connectivity& connectivityMsg) const;
115 void AddConnectivityPlacedComponentEntry(const ConnectivityIndex& index, std::size_t componentIndex, Protobuf::ProductModel::Connectivity& connectivityMsg) const;
116 void AddConnectivityNetMemberEntry(const ConnectivityIndex& index, ConnectivityIndex::MembersByNetConstIt netMembersIt, Protobuf::ProductModel::Connectivity& connectivityMsg) const;
117
118 // Rough serialized-wire-size estimate from model counts (features,
119 // component records, net/package records). O(number of layers/nets),
120 // never O(records): it is the dispatch input for the monolithic-vs-
121 // streaming serve decision and the OOM guard on monolithic GetDesign,
122 // so it must stay cheap enough to run before any message is built.
123 // includeNormalizedLists scales the estimate for the full wire flavor.
124 std::uint64_t EstimateWireSizeBytes(bool includeNormalizedLists = false) const;
125
126 typedef std::vector<std::shared_ptr<Design>> Vector;
127 typedef std::map<std::string, std::shared_ptr<Design>> StringMap;
128
129 private:
130 std::string m_productModel;
131 std::string m_name;
132
133 std::shared_ptr<FileModel::Design::FileArchive> m_pFileModel;
134
135 Net::Vector m_nets;
136 Net::StringMap m_netsByName;
137
138 Package::Vector m_packages;
139 Package::StringMap m_packagesByName;
140
141 Component::Vector m_components;
142 Component::StringMap m_componentsByName;
143
144 Part::Vector m_parts;
145 Part::StringMap m_partsByName;
146
147 bool BuildNets();
148 bool BuildPackages();
149 bool BuildAllParts();
150 bool BuildParts(const FileModel::Design::ComponentsFile* pComponentsFile);
151 bool BuildAllComponents();
152 bool BuildComponents(const FileModel::Design::ComponentsFile* pComponentsFile);
153 bool BuildVias();
154
155 bool BuildPlacementsFromComponentsFiles();
156 bool BuildPlacementsFromComponentsFile(const FileModel::Design::ComponentsFile* pComponentsFile);
157
158 bool BuildNoneNet();
159 bool BreakSinglePinNets();
160
161 // helper convienience methods
162 bool CreatePinConnection(const std::string& refDes, unsigned int netNumber, unsigned int pinNumber, const std::string& pinName, unsigned int subnetNumber = 0);
163
164 // Serializes the derived Connectivity view (connectivity.proto) from the
165 // in-memory model — a serialization of the BuildPlacements result, not a
166 // second join. Called by to_protobuf in BOTH flavours (decision D4:
167 // always-on, never gated on includeNormalizedLists).
168 void FillConnectivityMessage(Protobuf::ProductModel::Connectivity* pConnectivityMsg) const;
169 bool CreateNetConnections(const std::shared_ptr<FileModel::Design::EdaDataFile::NetRecord>& pNetRecord, const std::shared_ptr<FileModel::Design::StepDirectory>& pStepDirectory);
170
171 constexpr inline static const char* NONE_NET_NAME = "$NONE$";
172
173 constexpr inline static bool CLIP_FILEMODEL_AFTER_BUILD = false;
174
175 };
176}
std::map< std::string, std::shared_ptr< Component > > StringMap
Definition Component.h:43
std::vector< std::shared_ptr< Component > > Vector
Definition Component.h:42
std::vector< std::shared_ptr< Design > > Vector
Definition Design.h:126
std::map< std::string, std::shared_ptr< Design > > StringMap
Definition Design.h:127
std::vector< std::shared_ptr< Net > > Vector
Definition Net.h:35
std::map< std::string, std::shared_ptr< Net > > StringMap
Definition Net.h:36
std::map< std::string, std::shared_ptr< Package > > StringMap
Definition Package.h:35
std::vector< std::shared_ptr< Package > > Vector
Definition Package.h:34
std::map< std::string, std::shared_ptr< Part > > StringMap
Definition Part.h:21
std::vector< std::shared_ptr< Part > > Vector
Definition Part.h:20
#define ODBDESIGN_EXPORT
std::map< unsigned int, std::map< std::string, std::vector< unsigned int > > >::const_iterator MembersByNetConstIt
Definition Design.h:92
std::map< unsigned int, std::map< std::string, std::vector< unsigned int > > > membersByNet
Definition Design.h:88
std::map< std::string, std::map< unsigned int, Edge > > edgesByRefDes
Definition Design.h:87